Skip to content

Commit

Permalink
Merge pull request #369 from tudo-astroparticlephysics/fpe_moliere_in…
Browse files Browse the repository at this point in the history
…terpol

Protect Moliere evaluation from negative x
  • Loading branch information
Jean1995 authored Jun 12, 2023
2 parents d89c447 + dcc0325 commit f84f112
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ double Moliere::F1M(double x)
for (int p = 68; p >= 0; p--)
sum = sum * x + c1[p] / (2. * p + 1.);

return sum * std::sqrt(x);
return sum * std::sqrt(std::max(x, 0.));
}

//----------------------------------------------------------------------------//
Expand Down Expand Up @@ -321,7 +321,7 @@ double Moliere::F2M(double x)
for (int p = 68; p >= 0; p--)
sum = sum * x + c2[p] / (2. * p + 1.);

return sum * std::sqrt(x);
return sum * std::sqrt(std::max(x, 0.));
}

//----------------------------------------------------------------------------//
Expand All @@ -334,7 +334,7 @@ double Moliere::F(double theta)
double x = theta * theta / (chiCSq_ * B_[i]);

y1 += weight_ZZ_[i]
* (0.5 * std::erf(std::sqrt(x))
* (0.5 * std::erf(std::sqrt(std::max(x, 0.)))
+ std::sqrt(1. / PI)
* (F1M(x) / B_[i] + F2M(x) / (B_[i] * B_[i])));
}
Expand Down

0 comments on commit f84f112

Please sign in to comment.