38#define BEGIN blockDim.x *blockIdx.x + threadIdx.x
39#define STEP blockDim.x *gridDim.x
50 const int nPdfs = batches.
nExtra;
54 for (
int pdf = 1; pdf < nPdfs; pdf++) {
68 const double t =
m[i] / m0[i];
69 const double u = 1 - t * t;
92 coef0[i] * (1.0 - tagFlav[i] * delMistag[0]) + coef1[i] * (mixState[i] * (1.0 - 2.0 * mistag[0]));
98 const int nCoef = batches.
nExtra - 2;
99 const int degree = nCoef - 1;
100 const double xmin = batches.
extra[nCoef];
101 const double xmax = batches.
extra[nCoef + 1];
105 double binomial = 1.0;
106 for (
int k = 0; k < nCoef; k++) {
107 batches.
extra[k] = batches.
extra[k] * binomial;
108 binomial = (binomial * (degree - k)) / (k + 1);
117 powX[i] = pow_1_X[i] = 1.0;
124 for (
int k = 2; k <= degree; k += 2) {
126 pow_1_X[i] *= _1_X[i] * _1_X[i];
129 if (degree % 2 == 1) {
131 pow_1_X[i] *= _1_X[i];
136 _1_X[i] = 1 / _1_X[i];
138 for (
int k = 0; k < nCoef; k++) {
140 batches.
output[i] += batches.
extra[k] * powX[i] * pow_1_X[i];
144 pow_1_X[i] *= _1_X[i];
152 double pow_1_X = 1.0;
153 for (
int k = 1; k <= degree; k++)
155 const double _1_X = 1 / (1 -
X);
156 for (
int k = 0; k < nCoef; k++) {
157 batches.
output[i] += batches.
extra[k] * powX * pow_1_X;
166 for (
int k = 0; k < nCoef; k++) {
167 batches.
extra[k] = batches.
extra[k] / binomial;
168 binomial = (binomial * (degree - k)) / (k + 1);
179 double arg =
X[i] - M[i];
195 const double arg =
X[i] - M[i];
196 batches.
output[i] = 1 / (arg * arg + 0.25 * W[i] * W[i]);
208 const double r3 = log(2.0);
209 const double r6 = exp(-6.0);
210 const double r7 = 2 * sqrt(2 * log(2.0));
213 const double r1 = XI[i] *
fast_isqrt(XI[i] * XI[i] + 1);
214 const double r4 = 1 /
fast_isqrt(XI[i] * XI[i] + 1);
215 const double hp = 1 / (SP[i] * r7);
216 const double x1 = XP[i] + 0.5 * SP[i] * r7 * (r1 - 1);
217 const double x2 = XP[i] + 0.5 * SP[i] * r7 * (r1 + 1);
220 if (XI[i] > r6 || XI[i] < -r6)
224 double y =
X[i] -
x1;
225 double Yp = XP[i] -
x1;
226 double yi = r4 - XI[i];
236 batches.
output[i] = rho *
y *
y / Yp / Yp - r3 + factor * 4 * r3 *
y * hp * r5 * r4 / yi / yi;
237 if (
X[i] >=
x1 &&
X[i] <
x2) {
239 fast_log(1 + 4 * XI[i] * r4 * (
X[i] - XP[i]) * hp) /
fast_log(1 + 2 * XI[i] * (XI[i] - r4));
242 if (
X[i] >=
x1 &&
X[i] <
x2 && XI[i] < r6 && XI[i] > -r6)
243 batches.
output[i] = -4 * r3 * (
X[i] - XP[i]) * (
X[i] - XP[i]) * hp * hp;
257 const double t = (M[i] - M0[i]) / S[i];
258 if ((A[i] > 0 && t >= -A[i]) || (A[i] < 0 && -t >= A[i])) {
259 batches.
output[i] = -0.5 * t * t;
261 batches.
output[i] =
N[i] / (
N[i] - A[i] * A[i] - A[i] * t);
264 batches.
output[i] -= 0.5 * A[i] * A[i];
274 const int nCoef = batches.
nExtra - 2;
275 const double xmin = batches.
extra[nCoef];
276 const double xmax = batches.
extra[nCoef + 1];
285 prev[i][0] = batches.
output[i] = 1.0;
288 for (
int k = 0; k < nCoef; k++) {
290 batches.
output[i] += prev[i][1] * batches.
extra[k];
293 const double next = 2 *
X[i] * prev[i][1] - prev[i][0];
294 prev[i][0] = prev[i][1];
304 for (
int k = 0; k < nCoef; k++) {
308 const double next = 2 *
X * prev1 - prev0;
319 const double ndof = batches.
extra[0];
320 const double gamma = 1 / std::tgamma(ndof / 2.0);
322 batches.
output[i] = gamma;
324 constexpr double ln2 = 0.693147180559945309417232121458;
326 double arg = (ndof - 2) *
fast_log(
X[i]) -
X[i] - ndof * ln2;
334 batches.
output[i] = 0.0 + (batches.
args[0][i] == 1.0);
346 const double ratio = DM[i] / DM0[i];
347 const double arg1 = (DM0[i] - DM[i]) / C[i];
348 const double arg2 = A[i] *
fast_log(ratio);
353 if (batches.
output[i] < 0)
360 int lowestOrder = batches.
extra[0];
361 int nTerms = batches.
extra[1];
362 auto x = batches.
args[0];
366 double xTmp = std::pow(
x[i], lowestOrder);
367 for (
int k = 0; k < nTerms; ++k) {
368 batches.
output[i] += batches.
args[k + 1][i] * xTmp;
399 double gamma = -std::lgamma(
G[0]);
402 batches.
output[i] = (
G[i] == 1.0) / B[i];
403 }
else if (
G._isVector) {
404 batches.
output[i] = -std::lgamma(
G[i]);
406 batches.
output[i] = gamma;
412 const double invBeta = 1 / B[i];
413 double arg = (
X[i] - M[i]) * invBeta;
416 batches.
output[i] += arg * (
G[i] - 1);
418 batches.
output[i] *= invBeta;
425 const double root2 = std::sqrt(2.);
426 const double root2pi = std::sqrt(2. * std::atan2(0., -1.));
428 const bool isMinus = batches.
extra[0] < 0.0;
429 const bool isPlus = batches.
extra[0] > 0.0;
433 const double x = batches.
args[0][i];
434 const double mean = batches.
args[1][i] * batches.
args[2][i];
435 const double sigma = batches.
args[3][i] * batches.
args[4][i];
436 const double tau = batches.
args[5][i];
440 double xprime = (
x - mean) /
sigma;
441 double result = std::exp(-0.5 * xprime * xprime) / (
sigma * root2pi);
442 if (!isMinus && !isPlus)
447 const double xprime = (
x - mean) / tau;
448 const double c =
sigma / (root2 * tau);
449 const double u = xprime / (2 *
c);
463 auto x = batches.
args[0];
464 auto mean = batches.
args[1];
467 const double arg =
x[i] - mean[i];
468 const double halfBySigmaSq = -0.5 / (
sigma[i] *
sigma[i]);
485 if (batches.
extra[0]) {
499 const double massThreshold = batches.
extra[0];
502 const double arg = (mass[i] - mu[i]) / lambda[i];
506 const double asinh_arg = asinh(arg);
508 const double expo = gamma[i] + delta[i] * asinh_arg;
510 delta[i] *
fast_exp(-0.5 * expo * expo) *
fast_isqrt(1. + arg * arg) / (sqrtTwoPi * lambda[i]);
512 const double passThrough = mass[i] >= massThreshold;
523 auto case0 = [](
double x) {
524 const double a1[3] = {0.04166666667, -0.01996527778, 0.02709538966};
526 return 0.3989422803 *
fast_exp(-1 / u - 0.5 * (
x + 1)) * (1 + (a1[0] + (a1[1] + a1[2] * u) * u) * u);
528 auto case1 = [](
double x) {
529 constexpr double p1[5] = {0.4259894875, -0.1249762550, 0.03984243700, -0.006298287635, 0.001511162253};
530 constexpr double q1[5] = {1.0, -0.3388260629, 0.09594393323, -0.01608042283, 0.003778942063};
532 return fast_exp(-u - 0.5 * (
x + 1)) * (p1[0] + (p1[1] + (p1[2] + (p1[3] + p1[4] *
x) *
x) *
x) *
x) /
533 (q1[0] + (q1[1] + (q1[2] + (q1[3] + q1[4] *
x) *
x) *
x) *
x);
535 auto case2 = [](
double x) {
536 constexpr double p2[5] = {0.1788541609, 0.1173957403, 0.01488850518, -0.001394989411, 0.0001283617211};
537 constexpr double q2[5] = {1.0, 0.7428795082, 0.3153932961, 0.06694219548, 0.008790609714};
538 return (p2[0] + (p2[1] + (p2[2] + (p2[3] + p2[4] *
x) *
x) *
x) *
x) /
539 (q2[0] + (q2[1] + (q2[2] + (q2[3] + q2[4] *
x) *
x) *
x) *
x);
541 auto case3 = [](
double x) {
542 constexpr double p3[5] = {0.1788544503, 0.09359161662, 0.006325387654, 0.00006611667319, -0.000002031049101};
543 constexpr double q3[5] = {1.0, 0.6097809921, 0.2560616665, 0.04746722384, 0.006957301675};
544 return (p3[0] + (p3[1] + (p3[2] + (p3[3] + p3[4] *
x) *
x) *
x) *
x) /
545 (q3[0] + (q3[1] + (q3[2] + (q3[3] + q3[4] *
x) *
x) *
x) *
x);
547 auto case4 = [](
double x) {
548 constexpr double p4[5] = {0.9874054407, 118.6723273, 849.2794360, -743.7792444, 427.0262186};
549 constexpr double q4[5] = {1.0, 106.8615961, 337.6496214, 2016.712389, 1597.063511};
550 const double u = 1 /
x;
551 return u * u * (p4[0] + (p4[1] + (p4[2] + (p4[3] + p4[4] * u) * u) * u) * u) /
552 (q4[0] + (q4[1] + (q4[2] + (q4[3] + q4[4] * u) * u) * u) * u);
554 auto case5 = [](
double x) {
555 constexpr double p5[5] = {1.003675074, 167.5702434, 4789.711289, 21217.86767, -22324.94910};
556 constexpr double q5[5] = {1.0, 156.9424537, 3745.310488, 9834.698876, 66924.28357};
557 const double u = 1 /
x;
558 return u * u * (p5[0] + (p5[1] + (p5[2] + (p5[3] + p5[4] * u) * u) * u) * u) /
559 (q5[0] + (q5[1] + (q5[2] + (q5[3] + q5[4] * u) * u) * u) * u);
561 auto case6 = [](
double x) {
562 constexpr double p6[5] = {1.000827619, 664.9143136, 62972.92665, 475554.6998, -5743609.109};
563 constexpr double q6[5] = {1.0, 651.4101098, 56974.73333, 165917.4725, -2815759.939};
564 const double u = 1 /
x;
565 return u * u * (p6[0] + (p6[1] + (p6[2] + (p6[3] + p6[4] * u) * u) * u) * u) /
566 (q6[0] + (q6[1] + (q6[2] + (q6[3] + q6[4] * u) * u) * u) * u);
568 auto case7 = [](
double x) {
569 const double a2[2] = {-1.845568670, -4.284640743};
571 return u * u * (1 + (a2[0] + a2[1] * u) * u);
579 batches.
output[i] = (
X[i] - M[i]) / S[i];
584 }
else if (batches.
output[i] < -5.5) {
586 }
else if (batches.
output[i] < -1.0) {
588 }
else if (batches.
output[i] < 1.0) {
590 }
else if (batches.
output[i] < 5.0) {
592 }
else if (batches.
output[i] < 12.0) {
594 }
else if (batches.
output[i] < 50.0) {
596 }
else if (batches.
output[i] < 300.) {
609 constexpr double rootOf2pi = 2.506628274631000502415765284811;
611 double lnxOverM0 =
fast_log(
X[i] / M0[i]);
615 double arg = lnxOverM0 / lnk;
626 constexpr double rootOf2pi = 2.506628274631000502415765284811;
628 double lnxOverM0 =
fast_log(
X[i]) - M0[i];
632 double arg = lnxOverM0 / lnk;
640 auto rawVal = batches.
args[0];
641 auto normVal = batches.
args[1];
643 int nEvalErrorsType0 = 0;
644 int nEvalErrorsType1 = 0;
645 int nEvalErrorsType2 = 0;
650 if (normVal[i] < 0. || (normVal[i] == 0. && rawVal[i] != 0)) {
654 }
else if (rawVal[i] < 0.) {
658 }
else if (std::isnan(rawVal[i])) {
663 out = (rawVal[i] == 0. && normVal[i] == 0.) ? 0. : rawVal[i] / normVal[i];
668 if (nEvalErrorsType0 > 0)
669 batches.
extra[0] = batches.
extra[0] + nEvalErrorsType0;
670 if (nEvalErrorsType1 > 1)
671 batches.
extra[1] = batches.
extra[1] + nEvalErrorsType1;
672 if (nEvalErrorsType2 > 2)
673 batches.
extra[2] = batches.
extra[2] + nEvalErrorsType2;
690 constexpr double xi = 2.3548200450309494;
692 double argasinh = 0.5 * xi * T[i];
693 double argln = argasinh + 1 /
fast_isqrt(argasinh * argasinh + 1);
696 double argln2 = 1 - (
X[i] - P[i]) * T[i] / W[i];
698 batches.
output[i] = ln / asinh;
699 batches.
output[i] *= -0.125 * xi * xi * batches.
output[i];
700 batches.
output[i] -= 2.0 / xi / xi * asinh * asinh;
712 bool protectNegative = batches.
extra[0];
713 bool noRounding = batches.
extra[1];
715 const double x_i = noRounding ?
x[i] : floor(
x[i]);
716 batches.
output[i] = std::lgamma(x_i + 1.);
720 const double x_i = noRounding ?
x[i] : floor(
x[i]);
721 const double logMean =
fast_log(mean[i]);
722 const double logPoisson = x_i * logMean - mean[i] - batches.
output[i];
728 }
else if (x_i == 0) {
732 if (protectNegative && mean[i] < 0)
733 batches.
output[i] = 1.E-3;
739 const int nCoef = batches.
extra[0];
740 const std::size_t nEvents = batches.
nEvents;
743 for (
size_t i =
BEGIN; i < nEvents; i +=
STEP) {
744 batches.
output[i] = batches.
args[nCoef - 1][i];
749 for (
int k = nCoef - 2; k >= 0; k--) {
750 for (
size_t i =
BEGIN; i < nEvents; i +=
STEP) {
758 const int nCoef = batches.
extra[0];
763 for (
int k = 0; k < nCoef; ++k) {
764 batches.
output[i] += batches.
args[2 * k + 1][i] * std::pow(
x[i], batches.
args[2 * k + 2][i]);
771 const int nPdfs = batches.
extra[0];
775 for (
int pdf = 0; pdf < nPdfs; pdf++) {
792 const bool isMinus = batches.
extra[0] < 0.0;
793 const bool isPlus = batches.
extra[0] > 0.0;
795 double x = batches.
args[0][i];
797 const bool isOutOfSign = (isMinus &&
x > 0.0) || (isPlus &&
x < 0.0);
804 const bool isMinus = batches.
extra[0] < 0.0;
805 const bool isPlus = batches.
extra[0] > 0.0;
807 double x = batches.
args[0][i];
809 const bool isOutOfSign = (isMinus &&
x > 0.0) || (isPlus &&
x < 0.0);
817 const bool isMinus = batches.
extra[0] < 0.0;
818 const bool isPlus = batches.
extra[0] > 0.0;
820 double x = batches.
args[0][i];
822 const bool isOutOfSign = (isMinus &&
x > 0.0) || (isPlus &&
x < 0.0);
830 const bool isMinus = batches.
extra[0] < 0.0;
831 const bool isPlus = batches.
extra[0] > 0.0;
833 double x = batches.
args[0][i];
835 const bool isOutOfSign = (isMinus &&
x > 0.0) || (isPlus &&
x < 0.0);
839 const double tscaled = std::abs(
x) / batches.
args[1][i];
847 const bool isMinus = batches.
extra[0] < 0.0;
848 const bool isPlus = batches.
extra[0] > 0.0;
850 double x = batches.
args[0][i];
852 const bool isOutOfSign = (isMinus &&
x > 0.0) || (isPlus &&
x < 0.0);
856 const double tscaled = std::abs(
x) / batches.
args[1][i];
864 const bool isMinus = batches.
extra[0] < 0.0;
865 const bool isPlus = batches.
extra[0] > 0.0;
867 double x = batches.
args[0][i];
869 const bool isOutOfSign = (isMinus &&
x > 0.0) || (isPlus &&
x < 0.0);
871 isOutOfSign ? 0.0 :
fast_exp(-std::abs(
x) / batches.
args[1][i]) * sinh(
x * batches.
args[2][i] * 0.5);
877 const bool isMinus = batches.
extra[0] < 0.0;
878 const bool isPlus = batches.
extra[0] > 0.0;
880 double x = batches.
args[0][i];
882 const bool isOutOfSign = (isMinus &&
x > 0.0) || (isPlus &&
x < 0.0);
884 isOutOfSign ? 0.0 :
fast_exp(-std::abs(
x) / batches.
args[1][i]) * cosh(
x * batches.
args[2][i] * .5);
894 const double invSqrt2 = 0.707106781186547524400844362105;
896 const double arg = (
X[i] - M[i]) * (
X[i] - M[i]);
897 if (S[i] == 0.0 && W[i] == 0.0) {
899 }
else if (S[i] == 0.0) {
900 batches.
output[i] = 1 / (arg + 0.25 * W[i] * W[i]);
901 }
else if (W[i] == 0.0) {
904 batches.
output[i] = invSqrt2 / S[i];
909 if (S[i] != 0.0 && W[i] != 0.0) {
910 if (batches.
output[i] < 0)
912 const double factor = W[i] > 0.0 ? 0.5 : -0.5;
913 RooHeterogeneousMath::STD::complex<double> z(batches.
output[i] * (
X[i] - M[i]),
914 factor * batches.
output[i] * W[i]);
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
double *__restrict output
__rooglobal__ void computeBreitWigner(Batches &batches)
std::vector< void(*)(Batches &)> getFunctions()
Returns a std::vector of pointers to the compute functions in this file.
__rooglobal__ void computeNovosibirsk(Batches &batches)
__rooglobal__ void computeExpPoly(Batches &batches)
__rooglobal__ void computeChiSquare(Batches &batches)
__rooglobal__ void computeDeltaFunction(Batches &batches)
__rooglobal__ void computeGamma(Batches &batches)
__rooglobal__ void computeTruthModelQuadBasis(Batches &batches)
__rooglobal__ void computeTruthModelExpBasis(Batches &batches)
__rooglobal__ void computeTruthModelLinBasis(Batches &batches)
__rooglobal__ void computeLognormalStandard(Batches &batches)
__rooglobal__ void computeTruthModelCoshBasis(Batches &batches)
__rooglobal__ void computeAddPdf(Batches &batches)
__rooglobal__ void computeBifurGauss(Batches &batches)
__rooglobal__ void computeTruthModelSinhBasis(Batches &batches)
__rooglobal__ void computeLognormal(Batches &batches)
__rooglobal__ void computeArgusBG(Batches &batches)
__rooglobal__ void computeGaussian(Batches &batches)
__rooglobal__ void computeLandau(Batches &batches)
__rooglobal__ void computeTruthModelSinBasis(Batches &batches)
__rooglobal__ void computePower(Batches &batches)
__rooglobal__ void computeExponentialNeg(Batches &batches)
__rooglobal__ void computePoisson(Batches &batches)
__rooglobal__ void computeJohnson(Batches &batches)
__rooglobal__ void computeBMixDecay(Batches &batches)
__rooglobal__ void computeChebychev(Batches &batches)
__rooglobal__ void computeNormalizedPdf(Batches &batches)
__rooglobal__ void computeBernstein(Batches &batches)
__rooglobal__ void computeRatio(Batches &batches)
__rooglobal__ void computePolynomial(Batches &batches)
__rooglobal__ void computeExponential(Batches &batches)
__rooglobal__ void computeTruthModelCosBasis(Batches &batches)
__rooglobal__ void computeGaussModelExpBasis(Batches &batches)
__rooglobal__ void computeBukin(Batches &batches)
__rooglobal__ void computeDstD0BG(Batches &batches)
__rooglobal__ void computeNegativeLogarithms(Batches &batches)
__rooglobal__ void computeIdentity(Batches &batches)
__rooglobal__ void computeCBShape(Batches &batches)
__rooglobal__ void computeProdPdf(Batches &batches)
__rooglobal__ void computeVoigtian(Batches &batches)
Namespace for dispatching RooFit computations to various backends.
__roodevice__ double fast_exp(double x)
__roodevice__ double fast_sin(double x)
constexpr std::size_t bufferSize
__roodevice__ double fast_log(double x)
__roodevice__ double fast_cos(double x)
__roodevice__ double fast_isqrt(double x)
__roodevice__ __roohost__ STD::complex< double > faddeeva(STD::complex< double > z)
__roohost__ __roodevice__ STD::complex< double > evalCerf(double swt, double u, double c)
constexpr Double_t TwoPi()
#define R1(v, w, x, y, z, i)
#define R2(v, w, x, y, z, i)
__roodevice__ static __roohost__ double packFloatIntoNaN(float payload)
Pack float into mantissa of a NaN.