14#ifndef RooFit_Detail_AnalyticalIntegrals_h
15#define RooFit_Detail_AnalyticalIntegrals_h
26namespace AnalyticalIntegrals {
44 double scaledMin = 0.;
45 double scaledMax = 0.;
46 scaledMin = (xMin - mean) / xscale;
47 scaledMax = (xMax - mean) / xscale;
59 double prd = scaledMin * scaledMax;
61 cond = 2.0 - (ecmin + ecmax);
62 else if (scaledMax <= 0.0)
66 return resultScale * 0.5 * cond;
71 if (constant == 0.0) {
75 return (std::exp(constant * xMax) - std::exp(constant * xMin)) / constant;
79template <
bool pdfMode = false>
80inline double polynomialIntegral(
double const *coeffs,
int nCoeffs,
int lowestOrder,
double xMin,
double xMax)
82 int denom = lowestOrder + nCoeffs;
83 double min = coeffs[nCoeffs - 1] /
double(denom);
84 double max = coeffs[nCoeffs - 1] /
double(denom);
86 for (
int i = nCoeffs - 2; i >= 0; i--) {
92 max =
max * std::pow(xMax, 1 + lowestOrder);
93 min =
min * std::pow(xMin, 1 + lowestOrder);
95 return max -
min + (pdfMode && lowestOrder > 0.0 ? xMax - xMin : 0.0);
99inline double fast_fma(
double x,
double y,
double z)
noexcept
101#if defined(FP_FAST_FMA)
102 return std::fma(
x,
y, z);
105#if defined(__clang__)
106#pragma STDC FP_CONTRACT ON
112inline double chebychevIntegral(
double const *coeffs,
unsigned int nCoeffs,
double xMin,
double xMax,
double xMinFull,
115 const double halfrange = .5 * (xMax - xMin);
116 const double mid = .5 * (xMax + xMin);
119 const double b = (xMaxFull - mid) / halfrange;
120 const double a = (xMinFull - mid) / halfrange;
127 const unsigned int iend = nCoeffs;
131 const double c = coeffs[0];
136 double btwox = 2 *
b;
140 double atwox = 2 *
a;
143 double newval = atwox * acurr - alast;
147 newval = btwox * bcurr - blast;
151 for (
unsigned int i = 1; iend != i; ++i) {
153 const double c = coeffs[i];
154 const double term2 = (blast - alast) / nminus1;
156 newval = atwox * acurr - alast;
160 newval = btwox * bcurr - blast;
165 const double term1 = (bcurr - acurr) / (nminus1 + 1.);
166 const double intTn = 0.5 * (term1 - term2);
174 return halfrange *
sum;
178inline double max(
double x,
double y)
180 return x >=
y ?
x :
y;
183inline double min(
double x,
double y)
185 return x <=
y ?
x :
y;
190poissonIntegral(
int code,
double mu,
double x,
double integrandMin,
double integrandMax,
unsigned int protectNegative)
192 if (protectNegative && mu < 0.0) {
193 return std::exp(-2.0 * mu);
199 integrandMin =
max(0, integrandMin);
201 if (integrandMax < 0. || integrandMax < integrandMin) {
204 const double delta = 100.0 * std::sqrt(mu);
208 if (integrandMin <
max(mu - delta, 0.0) && integrandMax > mu + delta) {
213 const unsigned int ixMin = integrandMin;
214 const unsigned int ixMax =
min(integrandMax + 1, (
double)std::numeric_limits<unsigned int>::max());
232 const double ix = 1 +
x;
239 const double root2 = std::sqrt(2.);
243 0.5 * (
TMath::Erf(std::log(xMax / m0) / (root2 * ln_k)) -
TMath::Erf(std::log(xMin / m0) / (root2 * ln_k)));
250 const double root2 = std::sqrt(2.);
252 double ln_k = std::abs(
sigma);
254 0.5 * (
TMath::Erf((std::log(xMax) - mu) / (root2 * ln_k)) -
TMath::Erf((std::log(xMin) - mu) / (root2 * ln_k)));
double gamma_cdf_c(double x, double alpha, double theta, double x0=0)
Complement of the cumulative distribution function of the gamma distribution (upper tail).
double gamma_cdf(double x, double alpha, double theta, double x0=0)
Cumulative distribution function of the gamma distribution (lower tail).
double logNormalIntegral(double xMin, double xMax, double m0, double k)
double chebychevIntegral(double const *coeffs, unsigned int nCoeffs, double xMin, double xMax, double xMinFull, double xMaxFull)
double poissonIntegral(int code, double mu, double x, double integrandMin, double integrandMax, unsigned int protectNegative)
double fast_fma(double x, double y, double z) noexcept
use fast FMA if available, fall back to normal arithmetic if not
double min(double x, double y)
double max(double x, double y)
double gaussianIntegral(double xMin, double xMax, double mean, double sigma)
Function to calculate the integral of an un-normalized RooGaussian over x.
double exponentialIntegral(double xMin, double xMax, double constant)
double logNormalIntegralStandard(double xMin, double xMax, double mu, double sigma)
double polynomialIntegral(double const *coeffs, int nCoeffs, int lowestOrder, double xMin, double xMax)
In pdfMode, a coefficient for the constant term of 1.0 is implied if lowestOrder > 0.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Double_t Erf(Double_t x)
Computation of the error function erf(x).
constexpr Double_t Sqrt2()
Double_t Erfc(Double_t x)
Computes the complementary error function erfc(x).
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
constexpr Double_t TwoPi()
static uint64_t sum(uint64_t i)