80enum BasisSign { Both = 0, Plus = +1, Minus = -1 };
101 std::string str =
name;
104 str.erase(remove(str.begin(),str.end(),
' '),str.end());
107 if (str ==
"exp(-@0/@1)")
return expBasisPlus ;
108 if (str ==
"exp(@0/@1)")
return expBasisMinus ;
109 if (str ==
"exp(-abs(@0)/@1)")
return expBasisSum ;
110 if (str ==
"exp(-@0/@1)*sin(@0*@2)")
return sinBasisPlus ;
111 if (str ==
"exp(@0/@1)*sin(@0*@2)")
return sinBasisMinus ;
112 if (str ==
"exp(-abs(@0)/@1)*sin(@0*@2)")
return sinBasisSum ;
113 if (str ==
"exp(-@0/@1)*cos(@0*@2)")
return cosBasisPlus ;
114 if (str ==
"exp(@0/@1)*cos(@0*@2)")
return cosBasisMinus ;
115 if (str ==
"exp(-abs(@0)/@1)*cos(@0*@2)")
return cosBasisSum ;
116 if (str ==
"(@0/@1)*exp(-@0/@1)")
return linBasisPlus ;
117 if (str ==
"(@0/@1)*(@0/@1)*exp(-@0/@1)")
return quadBasisPlus ;
118 if (str ==
"exp(-@0/@1)*cosh(@0*@2/2)")
return coshBasisPlus;
119 if (str ==
"exp(@0/@1)*cosh(@0*@2/2)")
return coshBasisMinus;
120 if (str ==
"exp(-abs(@0)/@1)*cosh(@0*@2/2)")
return coshBasisSum;
121 if (str ==
"exp(-@0/@1)*sinh(@0*@2/2)")
return sinhBasisPlus;
122 if (str ==
"exp(@0/@1)*sinh(@0*@2/2)")
return sinhBasisMinus;
123 if (str ==
"exp(-abs(@0)/@1)*sinh(@0*@2/2)")
return sinhBasisSum;
127 return genericBasis ;
193 BasisSign basisSign = (BasisSign)(
_basisCode - 10*(basisType-1) - 2 ) ;
196 if ((basisSign==Minus &&
x>0) ||
197 (basisSign==Plus &&
x<0))
return 0 ;
204 return std::exp(-std::abs((
double)
x)/tau) ;
208 return std::exp(-std::abs((
double)
x)/tau)*std::sin(
x*dm) ;
212 return std::exp(-std::abs((
double)
x)/tau)*std::cos(
x*dm) ;
215 double tscaled = std::abs((
double)
x)/tau;
216 return std::exp(-tscaled)*tscaled ;
219 double tscaled = std::abs((
double)
x)/tau;
220 return std::exp(-tscaled)*tscaled*tscaled;
224 return std::exp(-std::abs((
double)
x)/tau)*std::sinh(
x*dg/2) ;
228 return std::exp(-std::abs((
double)
x)/tau)*std::cosh(
x*dg/2) ;
240 auto config = ctx.
config(
this);
241 auto xVals = ctx.
at(
x);
256 const BasisType basisType =
static_cast<BasisType
>((
_basisCode == 0) ? 0 : (
_basisCode / 10) + 1);
260 const double basisSign =
static_cast<double>((BasisSign)(
_basisCode - 10 * (basisType - 1) - 2));
264 auto param1Vals = param1 ? ctx.
at(param1) : std::span<const double>{};
265 auto param2Vals = param2 ? ctx.
at(param2) : std::span<const double>{};
268 std::array<double, 1> extraArgs{basisSign};
277 {xVals, param1Vals, param2Vals}, extraArgs);
282 {xVals, param1Vals, param2Vals}, extraArgs);
297 {xVals, param1Vals, param2Vals}, extraArgs);
302 {xVals, param1Vals, param2Vals}, extraArgs);
352inline double indefiniteIntegralExpBasisPlus(
double x,
double tau,
double )
355 x = std::max(
x, 0.0);
356 return -tau * std::exp(-
x / tau);
360inline double indefiniteIntegralLinBasisPlus(
double x,
double tau,
double )
363 x = std::max(
x, 0.0);
364 return -(tau +
x) * std::exp(-
x / tau);
368inline double indefiniteIntegralQuadBasisPlus(
double x,
double tau,
double )
371 x = std::max(
x, 0.0);
372 return -(std::exp(-
x / tau) * (2 * tau * tau +
x *
x + 2 * tau *
x)) / tau;
377inline double commonFactorPlus(
double x,
double tau,
double dm)
379 const double num = tau * std::exp(-
x / tau);
380 const double den = dm * dm * tau * tau + 1.0;
386inline double commonFactorHyperbolicPlus(
double x,
double tau,
double dm)
388 const double num = 2 * tau * std::exp(-
x / tau);
389 const double den = dm * dm * tau * tau - 4.0;
394inline double indefiniteIntegralSinBasisPlus(
double x,
double tau,
double dm)
397 x = std::max(
x, 0.0);
398 const double fac = commonFactorPlus(
x, tau, dm);
402 return fac != 0.0 ? fac * (-tau * dm * std::cos(dm *
x) - std::sin(dm *
x)) : 0.0;
406inline double indefiniteIntegralCosBasisPlus(
double x,
double tau,
double dm)
409 x = std::max(
x, 0.0);
410 const double fac = commonFactorPlus(
x, tau, dm);
411 return fac != 0.0 ? fac * (tau * dm * std::sin(dm *
x) - std::cos(dm *
x)) : 0.0;
415inline double indefiniteIntegralSinhBasisPlus(
double x,
double tau,
double dm)
418 x = std::max(
x, 0.0);
419 const double fac = commonFactorHyperbolicPlus(
x, tau, dm);
420 const double arg = 0.5 * dm *
x;
421 return fac != 0.0 ? fac * (tau * dm * std::cosh(arg) - 2. * std::sinh(arg)) : 0.0;
425inline double indefiniteIntegralCoshBasisPlus(
double x,
double tau,
double dm)
428 x = std::max(
x, 0.0);
429 const double fac = commonFactorHyperbolicPlus(
x, tau, dm);
430 const double arg = 0.5 * dm *
x;
431 return fac != 0.0 ? fac * (tau * dm * std::sinh(arg) + 2. * std::cosh(arg)) : 0.0;
438template <
class Function>
439double definiteIntegral(
Function indefiniteIntegral,
double xmin,
double xmax,
double tau,
double dm,
440 BasisSign basisSign,
bool isSymmetric)
444 return isSymmetric ? 1.0 : 0.0;
446 if (basisSign != Minus) {
447 result += indefiniteIntegral(
xmax, tau, dm) - indefiniteIntegral(
xmin, tau, dm);
449 if (basisSign != Plus) {
450 const double resultMinus = indefiniteIntegral(-
xmax, tau, dm) - indefiniteIntegral(-
xmin, tau, dm);
451 result += isSymmetric ? -resultMinus : resultMinus;
473 BasisSign basisSign = (BasisSign)(
_basisCode - 10 * (basisType - 1) - 2);
476 basisType == sinBasis || basisType == cosBasis || basisType == sinhBasis || basisType == coshBasis;
482 const double xmin =
x.min(rangeName);
483 const double xmax =
x.max(rangeName);
485 auto integrate = [&](
auto indefiniteIntegral,
bool isSymmetric) {
486 return definiteIntegral(indefiniteIntegral,
xmin,
xmax, tau, dm, basisSign, isSymmetric);
490 case expBasis:
return integrate(indefiniteIntegralExpBasisPlus,
true);
491 case sinBasis:
return integrate(indefiniteIntegralSinBasisPlus,
false);
492 case cosBasis:
return integrate(indefiniteIntegralCosBasisPlus,
true);
493 case linBasis:
return integrate(indefiniteIntegralLinBasisPlus,
false);
494 case quadBasis:
return integrate(indefiniteIntegralQuadBasisPlus,
true);
495 case sinhBasis:
return integrate(indefiniteIntegralSinhBasisPlus,
false);
496 case coshBasis:
return integrate(indefiniteIntegralCoshBasisPlus,
true);
509 const RooArgSet* auxProto,
bool verbose)
const
512 return new RooGenContext(convPdf, vars, prototype, auxProto, verbose, &forceDirect);
522 if (
matchArgs(directVars,generateVars,
x))
return 1 ;
int Int_t
Signed integer 4 bytes (int).
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Double_t(* Function)(Double_t)
Common abstract base class for objects that represent a value and a "shape" in RooFit.
void removeServer(RooAbsArg &server, bool force=false)
Unregister another RooAbsArg as a server to us, ie, declare that we no longer depend on its value and...
void addServer(RooAbsArg &server, bool valueProp=true, bool shapeProp=false, std::size_t refCount=1)
Register another RooAbsArg as a server to us, ie, declare that we depend on it.
Abstract base class for generator contexts of RooAbsPdf objects.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
bool matchArgs(const RooArgSet &allDeps, RooArgSet &analDeps, const RooArgProxy &a, const Proxies &... proxies) const
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Container class to hold unbinned data.
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::span< double > output()
RooBatchCompute::Config config(RooAbsArg const *arg) const
Implements a universal generator context for all RooAbsPdf classes that do not have or need a special...
bool _ownBasis
Flag indicating ownership of _basis.
friend class RooAbsAnaConvPdf
Int_t _basisCode
Identifier code for selected basis function.
RooAbsRealLValue & convVar() const
Return the convolution variable of the resolution model.
RooResolutionModel()=default
RooFormulaVar * _basis
Basis function convolved with this resolution model.
const RooFormulaVar & basis() const
RooTemplateProxy< RooAbsRealLValue > x
Dependent/convolution variable.
void doEval(RooFit::EvalContext &) const override
Base function for computing multiple values of a RooAbsReal.
void generateEvent(Int_t code) override
Implement internal generator for observable x, x=0 for all events following definition of delta funct...
double evaluate() const override
Evaluate the truth model: a delta function when used as PDF, the basis function itself,...
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
Advertise analytical integrals for compiled basis functions and when used as p.d.f without basis func...
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const override
Advertise internal generator for observable x.
RooAbsGenContext * modelGenContext(const RooAbsAnaConvPdf &convPdf, const RooArgSet &vars, const RooDataSet *prototype=nullptr, const RooArgSet *auxProto=nullptr, bool verbose=false) const override
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Implement analytical integrals when used as p.d.f and for compiled basis functions.
Int_t basisCode(const char *name) const override
Return basis code for given basis definition string.
void changeBasis(RooFormulaVar *basis) override
Changes associated bases function to 'inBasis'.
const char * GetTitle() const override
Returns title of object.
void compute(Config cfg, Computer comp, std::span< double > output, VarSpan vars, ArgSpan extraArgs={})