Commit 7aee2824485c0bb1da526b71edb70f8ef0de3535

Authored by Jürgen Knödlseder
1 parent f9cdd633

Limit delta in mc() method to r_max.

Showing 1 changed file with 15 additions and 3 deletions
inst/cta/src/GCTAPsfKing.cpp
... ... @@ -317,13 +317,25 @@ double GCTAPsfKing::mc(GRan& ran,
317 317 // Update the parameter cache
318 318 update(logE, theta);
319 319  
  320 + // Compute exponent
  321 + double exponent = 1.0 / (1.0-m_par_gamma);
  322 +
  323 + // Compile option: sample until delta <= r_max
  324 + #if defined(G_FIX_DELTA_MAX)
  325 + do {
  326 + #endif
  327 +
320 328 // Get uniform random number
321 329 double u = ran.uniform();
322 330  
323 331 // Draw random offset using inversion sampling
324   - //delta = std::sqrt( ( pow(1.0 - u, 1.0 / (1.0 - m_par_gamma) ) - 1.0 ) * 2.0 * pow(m_par_sigma, 2.0) * m_par_gamma);
325   - delta = std::sqrt( ( std::pow(1.0 - u, 1.0 / (1.0 - m_par_gamma) ) - 1.0 ) *
326   - 2.0 * m_par_sigma2 * m_par_gamma);
  332 + double u_max = (std::pow((1.0 - u), exponent) - 1.0) * m_par_gamma;
  333 + delta = m_par_sigma * std::sqrt(2.0 * u_max);
  334 +
  335 + // Compile option: sample until delta <= r_max
  336 + #if defined(G_FIX_DELTA_MAX)
  337 + } while (delta > r_max);
  338 + #endif
327 339  
328 340 // Return PSF offset
329 341 return delta;
... ...