Skip to content

Commit b464b36

Browse files
committed
[RF] Fix ROOT::Math::crystalball_integral near n = 1
1 parent ba957cc commit b464b36

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

math/mathcore/src/ProbFuncMathCore.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ namespace Math {
107107
MATH_ERROR_MSG("crystalball_integral", "CrystalBall function not defined at alpha=0");
108108
return 0.;
109109
}
110-
bool useLog = (n == 1.0);
110+
bool useLog = (std::abs(n - 1.) < 1.0e-5);
111111
if (n <= 0)
112112
MATH_WARN_MSG("crystalball_integral", "No physical meaning when n<=0");
113113

@@ -132,11 +132,13 @@ namespace Math {
132132
double B = r - abs_alpha;
133133

134134
if (!useLog) {
135-
intpow = A * (1 - std::pow(r / (B - z), n - 1)) / (n - 1);
135+
intpow = A * (1. - std::pow(r / (B - z), n - 1.)) / (n - 1.);
136136
}
137137
else {
138138
// for n=1 the primitive of 1/x is log(x)
139-
intpow = A * std::pow(r, n - 1) * (std::log(B - z) - std::log(r));
139+
double log_B_z = std::log(B - z);
140+
double log_r = std::log(r);
141+
intpow = A * std::pow(r, n - 1.) * (log_B_z - log_r + 0.5 * (1. - n) * (log_B_z * log_B_z - log_r * log_r));
140142
}
141143
intgaus = sqrtpiover2 * (1. + ROOT::Math::erf(abs_alpha * oneoversqrt2));
142144
}

0 commit comments

Comments
 (0)