14#ifndef RooFit_Detail_MathFuncs_h
15#define RooFit_Detail_MathFuncs_h
33 if (
n < 0 || k < 0 ||
n < k)
38 int k1 = std::min(k,
n - k);
41 for (
double i =
k1; i > 1.; --i) {
48template <
typename DoubleArray>
57 }
else if (degree == 0) {
59 }
else if (degree == 1) {
62 double a1 = coefs[1] -
a0;
65 }
else if (degree == 2) {
68 double a1 = 2 * (coefs[1] -
a0);
69 double a2 = coefs[2] -
a1 -
a0;
76 double result = coefs[0] * s;
77 for (
int i = 1; i < degree; i++) {
81 result += t * coefs[degree];
89 const double arg =
x - mean;
90 const double sig =
sigma;
91 return std::exp(-0.5 * arg * arg / (sig * sig));
94template <
typename DoubleArray>
98 for (std::size_t i = 0; i <
nFactors; ++i) {
105inline double ratio(
double numerator,
double denominator)
107 return numerator / denominator;
110inline double bifurGauss(
double x,
double mean,
double sigmaL,
double sigmaR)
131template <
bool pdfMode = false,
typename DoubleArray>
135 for (
int i =
nCoeffs - 2; i >= 0; i--) {
142template <
typename DoubleArray>
157 for (
unsigned int i = 0;
nCoeffs != i; ++i) {
167template <
typename DoubleArray>
178template <
typename DoubleArray>
182#if defined(__CLING__) && defined(R__HAS_CLAD)
183#pragma clad checkpoint loop
185 for (
unsigned int i = 0; i <
compSize; i++) {
191inline unsigned int uniformBinNumber(
double low,
double high,
double val,
unsigned int numBins,
double coef)
193 double binWidth = (high - low) / numBins;
194 return coef * (val >= high ? numBins - 1 : std::abs((val - low) / binWidth));
197template <
typename DoubleArray>
203 while (boundaries != it && (end == it || end == it + 1 ||
x < *it)) {
206 return it - boundaries;
209template <
typename DoubleArray>
214 return coef * std::max(0, tmp);
217template <
typename DoubleArray>
220 double binWidth = (high - low) / numBins;
221 int idx = val >= high ? numBins - 1 : std::abs((val - low) / binWidth);
224 double central = low + (idx + 0.5) * binWidth;
225 if (val > low + 0.5 * binWidth && val < high - 0.5 * binWidth) {
228 slope = vals[idx] - vals[idx - 1];
230 slope = vals[idx + 1] - vals[idx];
232 return vals[idx] +
slope * (val - central) / binWidth;
245 }
else if (
x == 0.0) {
246 return std::exp(-par);
249 return std::exp(out);
263 }
else if (code == 1) {
266 return res * (std::pow(high / nominal, +
paramVal) - 1);
268 return res * (std::pow(low / nominal, -
paramVal) - 1);
270 }
else if (code == 2) {
272 double a = 0.5 * (high + low) - nominal;
273 double b = 0.5 * (high - low);
276 return (2 *
a +
b) * (
paramVal - 1) + high - nominal;
278 return -1 * (2 *
a -
b) * (
paramVal + 1) + low - nominal;
286 }
else if (code == 4 || code == 6) {
295 mod =
x * (high - nominal);
297 mod =
x * (nominal - low);
306 mod =
x * (S + t * A * (15 + t * t * (-10 + t * t * 3)));
315 }
else if (code == 5) {
330 double logHi = std::log(high);
331 double logLo = std::log(low);
348 double x0Sq = x0 * x0;
350 double a = 1. / (8 * x0) * (15 *
A0 - 7 * x0 *
S1 + x0 * x0 *
A2);
351 double b = 1. / (8 *
x0Sq) * (-24 + 24 *
S0 - 9 * x0 *
A1 + x0 * x0 *
S2);
352 double c = 1. / (4 *
x0Sq * x0) * (-5 *
A0 + 5 * x0 *
S1 - x0 * x0 *
A2);
353 double d = 1. / (4 *
x0Sq *
x0Sq) * (12 - 12 *
S0 + 7 * x0 *
A1 - x0 * x0 *
S2);
354 double e = 1. / (8 *
x0Sq *
x0Sq * x0) * (+3 *
A0 - 3 * x0 *
S1 + x0 * x0 *
A2);
361 return res * (
mod - 1.0);
367template <
typename ParamsArray,
typename DoubleArray>
371 double total = nominal;
372#if defined(__CLING__) && defined(R__HAS_CLAD)
373#pragma clad checkpoint loop
375 for (std::size_t i = 0; i <
n; ++i) {
410 if (std::abs(pdf) < 1
e-10 && std::abs(weight) < 1
e-10) {
414 return pdf - weight - weight * (std::log(pdf) - std::log(weight));
418 return -weight * std::log(pdf);
422template <
typename DoubleArray>
427 for (
unsigned int i = 1; i <
n; ++i) {
436 double t = (
m - m0) /
sigma;
443 return std::exp(-0.5 * t * t);
449 return a * std::pow(
r / (
b - t),
n);
461 return std::erf(arg);
515 }
else if (
xMin > mean) {
532template <
bool pdfMode = false,
typename DoubleArray>
539 for (
int i =
nCoeffs - 2; i >= 0; i--) {
545 max = max * std::pow(
xMax, 1 + lowestOrder);
546 min = min * std::pow(
xMin, 1 + lowestOrder);
554#if defined(FP_FAST_FMA)
555 return std::fma(
x,
y, z);
558#if defined(__clang__)
559#pragma STDC FP_CONTRACT ON
565template <
typename DoubleArray>
605 for (
unsigned int i = 1;
iend != i; ++i) {
636 return std::exp(-2.0 * mu);
647 const double delta = 100.0 * std::sqrt(mu);
657 const unsigned int ixMax = std::min(
integrandMax + 1, (
double)std::numeric_limits<unsigned int>::max());
675 const double ix = 1 +
x;
682 const double root2 = std::sqrt(2.);
684 double ln_k = std::abs(std::log(k));
692 const double root2 = std::sqrt(2.);
704 const double sqrt2 = 1.4142135624;
709 if (std::abs(
n - 1.0) < 1.0e-05)
712 double sig = std::abs(
sigma);
714 double tmin = (
mMin - m0) / sig;
715 double tmax = (
mMax - m0) / sig;
738 result +=
a * sig / (1.0 -
n) * (std::pow(
r / (
b - tmin),
n - 1.0) - std::pow(
r / (
b - tmax),
n - 1.0));
748 double log_r = std::log(
r);
749 term1 =
a * std::pow(
r,
n - 1) * sig *
752 term1 =
a * sig / (1.0 -
n) * (std::pow(
r / (
b - tmin),
n - 1.0) - 1.0);
765template <
typename DoubleArray>
774 for (
int i = 0; i <= degree; ++i) {
779 for (
int j = i;
j <= degree; ++
j) {
792template <
typename XArray,
typename MuArray,
typename CovArray>
798 for (
int i = 0; i <
n; ++i) {
799 for (
int j = 0;
j <
n; ++
j) {
803 return std::exp(-0.5 *
result);
809template <
typename DoubleArray>
813 for (std::size_t i = 0; i < nBins; ++i) {
814 double a = boundaries[i];
815 double b = boundaries[i + 1];
816 out += coefs[i] * std::max(0.0, std::min(
b,
xmax) - std::max(
a,
xmin));
831template <
class... Types>
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
static unsigned int total
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 r
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 GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
double lognormal_pdf(double x, double m, double s, double x0=0)
Probability density function of the lognormal distribution.
double landau_pdf(double x, double xi=1, double x0=0)
Probability density function of the Landau distribution:
double inc_gamma_c(double a, double x)
Calculates the normalized (regularized) upper incomplete gamma function (upper integral)
double inc_gamma(double a, double x)
Calculates the normalized (regularized) lower incomplete gamma function (lower integral)
double polynomialIntegral(DoubleArray 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.
double logNormalIntegral(double xMin, double xMax, double m0, double k)
double gaussianIntegral(double xMin, double xMax, double mean, double sigma)
Function to calculate the integral of an un-normalized RooGaussian over x.
double flexibleInterp(unsigned int code, ParamsArray params, unsigned int n, DoubleArray low, DoubleArray high, double boundary, double nominal, int doCutoff)
double bifurGaussIntegral(double xMin, double xMax, double mean, double sigmaL, double sigmaR)
double bernstein(double x, double xmin, double xmax, DoubleArray coefs, int nCoefs)
The caller needs to make sure that there is at least one coefficient.
double constraintSum(DoubleArray comp, unsigned int compSize)
double cbShape(double m, double m0, double sigma, double alpha, double n)
double multipdf(int idx, DoubleArray pdfs)
double chebychevIntegral(DoubleArray coeffs, unsigned int nCoeffs, double xMin, double xMax, double xMinFull, double xMaxFull)
double recursiveFraction(DoubleArray a, unsigned int n)
double cbShapeIntegral(double mMin, double mMax, double m0, double sigma, double alpha, double n)
double polynomial(DoubleArray coeffs, int nCoeffs, int lowestOrder, double x)
In pdfMode, a coefficient for the constant term of 1.0 is implied if lowestOrder > 0.
double fast_fma(double x, double y, double z) noexcept
use fast FMA if available, fall back to normal arithmetic if not
double logNormalIntegralStandard(double xMin, double xMax, double mu, double sigma)
double interpolate1d(double low, double high, double val, unsigned int numBins, DoubleArray vals)
double landau(double x, double mu, double sigma)
double gaussian(double x, double mean, double sigma)
Function to evaluate an un-normalized RooGaussian.
double poisson(double x, double par)
double binomial(int n, int k)
Calculates the binomial coefficient n over k.
unsigned int uniformBinNumber(double low, double high, double val, unsigned int numBins, double coef)
double multiVarGaussian(int n, XArray x, MuArray mu, CovArray covI)
double flexibleInterpSingle(unsigned int code, double low, double high, double boundary, double nominal, double paramVal, double res)
double bernsteinIntegral(double xlo, double xhi, double xmin, double xmax, DoubleArray coefs, int nCoefs)
double chebychev(DoubleArray coeffs, unsigned int nCoeffs, double x_in, double xMin, double xMax)
double product(DoubleArray factors, std::size_t nFactors)
unsigned int rawBinNumber(double x, DoubleArray boundaries, std::size_t nBoundaries)
unsigned int binNumber(double x, double coef, DoubleArray boundaries, unsigned int nBoundaries, int nbins, int blo)
double logNormalStandard(double x, double sigma, double mu)
double bifurGauss(double x, double mean, double sigmaL, double sigmaR)
double ratio(double numerator, double denominator)
double approxErf(double arg)
double effProd(double eff, double pdf)
double poissonIntegral(int code, double mu, double x, double integrandMin, double integrandMax, unsigned int protectNegative)
double logNormal(double x, double k, double m0)
double stepFunctionIntegral(double xmin, double xmax, std::size_t nBins, DoubleArray boundaries, DoubleArray coefs)
double nll(double pdf, double weight, int binnedL, int doBinOffset)
double efficiency(double effFuncVal, int catIndex, int sigCatIndex)
double exponentialIntegral(double xMin, double xMax, double constant)
Double_t QuietNaN()
Returns a quiet NaN as defined by IEEE 754.
constexpr Double_t Sqrt2()
Double_t LnGamma(Double_t z)
Computation of ln[gamma(z)] for all z.
Double_t SignalingNaN()
Returns a signaling NaN as defined by IEEE 754](http://en.wikipedia.org/wiki/NaN#Signaling_NaN).
constexpr Double_t TwoPi()
void binNumber_pullback(Types...)
static uint64_t sum(uint64_t i)