14#ifndef RooFit_Detail_EvaluateFuncs_h
15#define RooFit_Detail_EvaluateFuncs_h
26namespace EvaluateFuncs {
31 const double arg =
x - mean;
32 const double sig =
sigma;
33 return std::exp(-0.5 * arg * arg / (sig * sig));
38 return numerator / denominator;
52 effFuncVal = std::clamp(effFuncVal, 0.0, 1.0);
54 if (catIndex == sigCatIndex)
57 return 1 - effFuncVal;
61template <
bool pdfMode = false>
64 double retVal = coeffs[nCoeffs - 1];
65 for (
int i = nCoeffs - 2; i >= 0; i--)
66 retVal = coeffs[i] +
x * retVal;
67 retVal = retVal * std::pow(
x, lowestOrder);
68 return retVal + (pdfMode && lowestOrder > 0 ? 1.0 : 0.0);
71inline double chebychevEvaluate(
double *coeffs,
unsigned int nCoeffs,
double x_in,
double xMin,
double xMax)
74 const double xPrime = (x_in - 0.5 * (xMax + xMin)) / (0.5 * (xMax - xMin));
80 double twox = 2 * xPrime;
82 double newval = twox * curr - last;
85 for (
unsigned int i = 0; nCoeffs != i; ++i) {
86 sum += last * coeffs[i];
87 newval = twox * curr - last;
98 for (
unsigned int i = 0; i < compSize; i++) {
99 sum -= std::log(comp[i]);
106 double binWidth = (high - low) / numBins;
107 return val >= high ? numBins - 1 : std::abs((val - low) / binWidth);
117 }
else if (
x == 0.0) {
118 return std::exp(-par);
121 return std::exp(out);
127 double t =
x / boundary;
128 double eps_plus = high - nominal;
129 double eps_minus = nominal - low;
130 double S = 0.5 * (eps_plus + eps_minus);
131 double A = 0.0625 * (eps_plus - eps_minus);
133 return x * (S + t * A * (15 + t * t * (-10 + t * t * 3)));
138 double x0 = boundary;
141 double powUp = std::pow(high / nominal, x0);
142 double powDown = std::pow(low / nominal, x0);
143 double logHi = std::log(high);
144 double logLo = std::log(low);
145 double powUpLog = high <= 0.0 ? 0.0 : powUp * logHi;
146 double powDownLog = low <= 0.0 ? 0.0 : -powDown * logLo;
147 double powUpLog2 = high <= 0.0 ? 0.0 : powUpLog * logHi;
148 double powDownLog2 = low <= 0.0 ? 0.0 : -powDownLog * logLo;
150 double S0 = 0.5 * (powUp + powDown);
151 double A0 = 0.5 * (powUp - powDown);
152 double S1 = 0.5 * (powUpLog + powDownLog);
153 double A1 = 0.5 * (powUpLog - powDownLog);
154 double S2 = 0.5 * (powUpLog2 + powDownLog2);
155 double A2 = 0.5 * (powUpLog2 - powDownLog2);
159 double a = 1. / (8 * x0) * (15 * A0 - 7 * x0 *
S1 + x0 * x0 * A2);
160 double b = 1. / (8 * x0 * x0) * (-24 + 24 *
S0 - 9 * x0 * A1 + x0 * x0 * S2);
161 double c = 1. / (4 * std::pow(x0, 3)) * (-5 * A0 + 5 * x0 *
S1 - x0 * x0 * A2);
162 double d = 1. / (4 * std::pow(x0, 4)) * (12 - 12 *
S0 + 7 * x0 * A1 - x0 * x0 * S2);
163 double e = 1. / (8 * std::pow(x0, 5)) * (+3 * A0 - 3 * x0 *
S1 + x0 * x0 * A2);
164 double f = 1. / (8 * std::pow(x0, 6)) * (-8 + 8 *
S0 - 5 * x0 * A1 + x0 * x0 * S2);
172flexibleInterp(
unsigned int code,
double low,
double high,
double boundary,
double nominal,
double paramVal,
double res)
177 return paramVal * (high - nominal);
179 return paramVal * (nominal - low);
181 }
else if (code == 1) {
184 return res * (std::pow(high / nominal, +paramVal) - 1);
186 return res * (std::pow(low / nominal, -paramVal) - 1);
188 }
else if (code == 2) {
190 double a = 0.5 * (high + low) - nominal;
191 double b = 0.5 * (high - low);
194 return (2 *
a +
b) * (paramVal - 1) + high - nominal;
195 }
else if (paramVal < -1) {
196 return -1 * (2 *
a -
b) * (paramVal + 1) + low - nominal;
198 return a * std::pow(paramVal, 2) +
b * paramVal +
c;
200 }
else if (code == 3) {
202 double a = 0.5 * (high + low) - nominal;
203 double b = 0.5 * (high - low);
206 return (2 *
a +
b) * (paramVal - 1) + high - nominal;
207 }
else if (paramVal < -1) {
208 return -1 * (2 *
a -
b) * (paramVal + 1) + low - nominal;
210 return a * std::pow(paramVal, 2) +
b * paramVal +
c;
212 }
else if (code == 4) {
215 return x * (high - nominal);
216 }
else if (
x <= -boundary) {
217 return x * (nominal - low);
221 }
else if (code == 5) {
225 mod = std::pow(high / nominal, +paramVal);
226 }
else if (
x <= -boundary) {
227 mod = std::pow(low / nominal, -paramVal);
231 return res * (mod - 1.0);
238 double boundary,
double nominal)
240 double total = nominal;
241 for (std::size_t i = 0; i <
n; ++i) {
245 return total <= 0 ? TMath::Limits<double>::Min() :
total;
249 double *params,
unsigned int n)
251 double total = nominal;
252 for (std::size_t i = 0; i <
n; ++i) {
273inline double nllEvaluate(
double pdf,
double weight,
int binnedL,
int doBinOffset)
279 if (std::abs(pdf) < 1
e-10 && std::abs(weight) < 1
e-10) {
283 return pdf - weight - weight * (std::log(pdf) - std::log(weight));
287 return -weight * std::log(pdf);
static unsigned int total
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 poissonEvaluate(double x, double par)
double bifurGaussEvaluate(double x, double mean, double sigmaL, double sigmaR)
double constraintSumEvaluate(double const *comp, unsigned int compSize)
double gaussianEvaluate(double x, double mean, double sigma)
Function to evaluate an un-normalized RooGaussian.
double piecewiseInterpolationEvaluate(unsigned int code, double *low, double *high, double nominal, double *params, unsigned int n)
double flexibleInterp(unsigned int code, double low, double high, double boundary, double nominal, double paramVal, double res)
double effProdEvaluate(double eff, double pdf)
double polynomialEvaluate(double const *coeffs, int nCoeffs, int lowestOrder, double x)
In pdfMode, a coefficient for the constant term of 1.0 is implied if lowestOrder > 0.
double flexibleInterpEvaluate(unsigned int code, double *params, unsigned int n, double *low, double *high, double boundary, double nominal)
double logNormalEvaluate(double x, double k, double m0)
double logNormalEvaluateStandard(double x, double sigma, double mu)
double efficiencyEvaluate(double effFuncVal, int catIndex, int sigCatIndex)
double interpolate6thDegreeExp(double x, double low, double high, double nominal, double boundary)
unsigned int getUniformBinning(double low, double high, double val, unsigned int numBins)
double ratioEvaluate(double numerator, double denominator)
double interpolate6thDegree(double x, double low, double high, double nominal, double boundary)
double nllEvaluate(double pdf, double weight, int binnedL, int doBinOffset)
double chebychevEvaluate(double *coeffs, unsigned int nCoeffs, double x_in, double xMin, double xMax)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Double_t QuietNaN()
Returns a quiet NaN as defined by IEEE 754.
Double_t LnGamma(Double_t z)
Computation of ln[gamma(z)] for all z.
static uint64_t sum(uint64_t i)