11 #include <tracking/calibration/InvariantMassMuMuIntegrator.h>
12 #include <tracking/calibration/InvariantMassMuMuStandAlone.h>
17 #include <Math/SpecFuncMathCore.h>
18 #include <Math/DistFunc.h>
22 namespace Belle2::InvariantMassMuMuCalib {
24 void InvariantMassMuMuIntegrator::init(
double Mean,
62 double CoreC = gausExpConv(m_mean, m_sigma, m_bMean, m_bDelta, m_tauL, m_tauR, m_sigmaK, m_x + t - m_m0);
63 double CoreE = 1. / (sqrt(2 * M_PI) * m_sigmaE) * exp(-1. / 2 * pow((m_x + t - m_m0 - m_mean) / m_sigmaE, 2));
64 double Core = (1 - m_frac) * CoreC + m_frac * CoreE;
72 K = (1 + (m_C - 1) * (m_eps - t) / m_eps) * pow(m_eps, -m_slope);
80 double InvariantMassMuMuIntegrator::integralTrap(
double a,
double b)
82 const int N = 14500000;
83 double step = (b - a) / N;
85 for (
int i = 0; i <= N; ++i) {
86 double K = (i == 0 || i == N) ? 0.5 : 1;
87 double t = a + i * step;
88 s +=
eval(t) * step * K;
96 double InvariantMassMuMuIntegrator::integralTrapImp(
double Eps,
double a)
98 double tMin = m_slope * m_tauL;
101 if (m_x - m_m0 >= 0) {
103 double r1 = ROOT::Math::inc_gamma_c(1 - m_slope, a / m_tauL);
104 double r2 = ROOT::Math::inc_gamma_c(1 - m_slope, Eps / m_tauL);
108 double step = (r2 - r1) / N;
110 for (
int i = 0; i <= N; ++i) {
111 double r = r1 + step * i;
112 double t = m_tauL * ROOT::Math::gamma_quantile_c(r, 1 - m_slope, 1);
113 double K = (i == 0 || i == N) ? 0.5 : 1;
115 double est = pow(t, -m_slope) * exp(- (m_x - m_m0 + t) / m_tauL);
117 s +=
eval(t) / est * step * K;
120 s *= exp((m_m0 - m_x) / m_tauL) * pow(m_tauL, -m_slope + 1) * ROOT::Math::tgamma(1 - m_slope);
126 else if (m_x - m_m0 >= -tMin) {
132 double r1 = ROOT::Math::inc_gamma_c(1 - m_slope, a / m_tauL);
133 double r2 = ROOT::Math::inc_gamma_c(1 - m_slope, (m_m0 - m_x) / m_tauL);
136 const int N = 150000;
137 double step = (r2 - r1) / N;
138 for (
int i = 0; i <= N; ++i) {
139 double r = r1 + step * i;
140 double t = m_tauL * ROOT::Math::gamma_quantile_c(r, 1 - m_slope, 1);
141 double K = (i == 0 || i == N) ? 0.5 : 1;
143 double est = pow(t, -m_slope) * exp(- (m_x - m_m0 + t) / m_tauL);
145 s1 +=
eval(t) / est * step * K;
148 s1 *= exp((m_m0 - m_x) / m_tauL) * pow(m_tauL, -m_slope + 1) * ROOT::Math::tgamma(1 - m_slope);
156 double r1 = pow(Eps, -m_slope + 1) / (1 - m_slope);
157 double r2 = pow(m_m0 - m_x, -m_slope + 1) / (1 - m_slope);
160 const int N = 150000;
161 double step = (r2 - r1) / N;
162 for (
int i = 0; i <= N; ++i) {
163 double r = r1 + step * i;
164 double t = pow(r * (1 - m_slope), 1. / (1 - m_slope));
165 double K = (i == 0 || i == N) ? 0.5 : 1;
167 double est = pow(t, -m_slope);
169 s2 +=
eval(t) / est * step * K;
182 double r1 = ROOT::Math::inc_gamma_c(1 - m_slope, a / m_tauL);
183 double r2 = ROOT::Math::inc_gamma_c(1 - m_slope, (m_m0 - m_x) / m_tauL);
186 const int N = 150000;
187 double step = (r2 - r1) / N;
188 for (
int i = 0; i <= N; ++i) {
189 double r = r1 + step * i;
190 double t = m_tauL * ROOT::Math::gamma_quantile_c(r, 1 - m_slope, 1);
191 double K = (i == 0 || i == N) ? 0.5 : 1;
193 double est = pow(t, -m_slope) * exp(- (m_x - m_m0 + t) / m_tauL);
195 s1 +=
eval(t) / est * step * K;
198 s1 *= exp((m_m0 - m_x) / m_tauL) * pow(m_tauL, -m_slope + 1) * ROOT::Math::tgamma(1 - m_slope);
206 double r1 = pow(Eps, -m_slope + 1) / (1 - m_slope);
207 double r2 = pow(tMin, -m_slope + 1) / (1 - m_slope);
210 const int N = 150000;
211 double step = (r2 - r1) / N;
212 for (
int i = 0; i <= N; ++i) {
213 double r = r1 + step * i;
214 double t = pow(r * (1 - m_slope), 1. / (1 - m_slope));
215 double K = (i == 0 || i == N) ? 0.5 : 1;
217 double est = pow(t, -m_slope);
219 s2 +=
eval(t) / est * step * K;
228 double r1 = exp(tMin / m_tauR) * m_tauR;
229 double r2 = exp((m_m0 - m_x) / m_tauR) * m_tauR;
232 const int N = 150000;
233 double step = (r2 - r1) / N;
234 for (
int i = 0; i <= N; ++i) {
235 double r = r1 + step * i;
236 double t = log(r / m_tauR) * m_tauR;
237 double K = (i == 0 || i == N) ? 0.5 : 1;
239 double est = exp(t / m_tauR);
241 s3 +=
eval(t) / est * step * K;
247 return (s1 + s2 + s3);
257 double InvariantMassMuMuIntegrator::integralKronrod(
double a)
260 double s0 = integrate([&](
double t) {
265 double tMin = m_slope * m_tauL;
268 if (m_x - m_m0 >= 0) {
272 double r1 = ROOT::Math::inc_gamma_c(1 - m_slope, a / m_tauL);
273 double r2 = ROOT::Math::inc_gamma_c(1 - m_slope, m_eps / m_tauL);
275 double s = integrate([&](
double r) {
277 double t = m_tauL * ROOT::Math::gamma_quantile_c(r, 1 - m_slope, 1);
278 double est = pow(t, -m_slope) * exp(- (m_x - m_m0 + t) / m_tauL);
279 return eval(t) / est;
284 s *= exp((m_m0 - m_x) / m_tauL) * pow(m_tauL, -m_slope + 1) * ROOT::Math::tgamma(1 - m_slope);
291 else if (m_x - m_m0 >= -m_eps) {
293 assert(0 <= m_m0 - m_x);
294 assert(m_m0 - m_x <= m_eps);
298 double s01 = integrate([&](
double t) {
303 double s02 = integrate([&](
double t) {
305 } , m_m0 - m_x, m_eps);
308 double r1 = ROOT::Math::inc_gamma_c(1 - m_slope, a / m_tauL);
309 double r2 = ROOT::Math::inc_gamma_c(1 - m_slope, m_eps / m_tauL);
311 double s = integrate([&](
double r) {
313 double t = m_tauL * ROOT::Math::gamma_quantile_c(r, 1 - m_slope, 1);
314 double est = pow(t, -m_slope) * exp(- (m_x - m_m0 + t) / m_tauL);
315 return eval(t) / est;
320 s *= exp((m_m0 - m_x) / m_tauL) * pow(m_tauL, -m_slope + 1) * ROOT::Math::tgamma(1 - m_slope);
322 return (s01 + s02 + s);
328 else if (m_x - m_m0 >= -tMin) {
330 assert(m_eps <= m_m0 - m_x);
331 assert(m_m0 - m_x <= a);
337 double r1 = ROOT::Math::inc_gamma_c(1 - m_slope, a / m_tauL);
338 double r2 = ROOT::Math::inc_gamma_c(1 - m_slope, (m_m0 - m_x) / m_tauL);
341 s1 = integrate([&](
double r) {
343 double t = m_tauL * ROOT::Math::gamma_quantile_c(r, 1 - m_slope, 1);
344 double est = pow(t, -m_slope) * exp(- (m_x - m_m0 + t) / m_tauL);
345 return eval(t) / est;
350 s1 *= exp((m_m0 - m_x) / m_tauL) * pow(m_tauL, -m_slope + 1) * ROOT::Math::tgamma(1 - m_slope);
359 double r1 = pow(m_eps, -m_slope + 1) / (1 - m_slope);
360 double r2 = pow(m_m0 - m_x, -m_slope + 1) / (1 - m_slope);
364 s2 = integrate([&](
double r) {
365 double t = pow(r * (1 - m_slope), 1. / (1 - m_slope));
366 double est = pow(t, -m_slope);
367 return eval(t) / est;
371 return (s0 + s1 + s2);
375 assert(m_eps <= tMin);
376 assert(tMin <= m_m0 - m_x);
377 assert(m_m0 - m_x <= a);
383 double r1 = ROOT::Math::inc_gamma_c(1 - m_slope, a / m_tauL);
384 double r2 = ROOT::Math::inc_gamma_c(1 - m_slope, (m_m0 - m_x) / m_tauL);
387 s1 = integrate([&](
double r) {
389 double t = m_tauL * ROOT::Math::gamma_quantile_c(r, 1 - m_slope, 1);
390 double est = pow(t, -m_slope) * exp(- (m_x - m_m0 + t) / m_tauL);
391 return eval(t) / est;
396 s1 *= exp((m_m0 - m_x) / m_tauL) * pow(m_tauL, -m_slope + 1) * ROOT::Math::tgamma(1 - m_slope);
405 double r1 = pow(m_eps, -m_slope + 1) / (1 - m_slope);
406 double r2 = pow(tMin, -m_slope + 1) / (1 - m_slope);
408 s2 = integrate([&](
double r) {
409 double t = pow(r * (1 - m_slope), 1. / (1 - m_slope));
410 double est = pow(t, -m_slope);
411 return eval(t) / est;
420 double r1 = exp(tMin / m_tauR) * m_tauR;
421 double r2 = exp((m_m0 - m_x) / m_tauR) * m_tauR;
424 s3 = integrate([&](
double r) {
425 double t = log(r / m_tauR) * m_tauR;
426 double est = exp(t / m_tauR);
427 return eval(t) / est;
432 return (s0 + s1 + s2 + s3);
double eval(const std::vector< double > &spl, const std::vector< double > &vals, double x)
Evaluate spline (zero order or first order) in point x.