71#ifndef ROOFIT_MEMORY_SAFE_INTERFACES
77 _nominal(
"!nominal",
"nominal value", this, (
RooAbsReal&)nominal),
78 _lowSet(
"!lowSet",
"low-side variation",this),
79 _highSet(
"!highSet",
"high-side variation",this),
80 _paramSet(
"!paramSet",
"high-side variation",this),
81 _positiveDefinite(false)
86 coutE(InputArguments) <<
"PiecewiseInterpolation::ctor(" <<
GetName() <<
") ERROR: input lists should be of equal length" << endl ;
90 for (
auto *comp : lowSet) {
92 coutE(InputArguments) <<
"PiecewiseInterpolation::ctor(" <<
GetName() <<
") ERROR: component " << comp->GetName()
93 <<
" in first list is not of type RooAbsReal" << endl ;
97#ifndef ROOFIT_MEMORY_SAFE_INTERFACES
105 for (
auto *comp : highSet) {
107 coutE(InputArguments) <<
"PiecewiseInterpolation::ctor(" <<
GetName() <<
") ERROR: component " << comp->GetName()
108 <<
" in first list is not of type RooAbsReal" << endl ;
112#ifndef ROOFIT_MEMORY_SAFE_INTERFACES
120 for (
auto *comp : paramSet) {
122 coutE(InputArguments) <<
"PiecewiseInterpolation::ctor(" <<
GetName() <<
") ERROR: component " << comp->GetName()
123 <<
" in first list is not of type RooAbsReal" << endl ;
127#ifndef ROOFIT_MEMORY_SAFE_INTERFACES
148 _normIntMgr(other._normIntMgr, this),
149 _nominal(
"!nominal",this,other._nominal),
150 _lowSet(
"!lowSet",this,other._lowSet),
151 _highSet(
"!highSet",this,other._highSet),
152 _paramSet(
"!paramSet",this,other._paramSet),
153 _positiveDefinite(other._positiveDefinite),
154 _interpCode(other._interpCode)
180 double sum(nominal) ;
191 if(param->getVal()>0)
192 sum += param->getVal()*(high->getVal() - nominal );
194 sum += param->getVal()*(nominal - low->getVal());
199 if(param->getVal()>=0)
200 sum *= pow(high->getVal()/nominal, +param->getVal());
202 sum *= pow(low->getVal()/nominal, -param->getVal());
207 double a = 0.5*(high->getVal()+low->getVal())-nominal;
208 double b = 0.5*(high->getVal()-low->getVal());
210 if(param->getVal()>1 ){
211 sum += (2*
a+
b)*(param->getVal()-1)+high->getVal()-nominal;
212 }
else if(param->getVal()<-1 ) {
213 sum += -1*(2*
a-
b)*(param->getVal()+1)+low->getVal()-nominal;
215 sum +=
a*pow(param->getVal(),2) +
b*param->getVal()+
c;
221 double a = 0.5*(high->getVal()+low->getVal())-nominal;
222 double b = 0.5*(high->getVal()-low->getVal());
224 if(param->getVal()>1 ){
225 sum += (2*
a+
b)*(param->getVal()-1)+high->getVal()-nominal;
226 }
else if(param->getVal()<-1 ) {
227 sum += -1*(2*
a-
b)*(param->getVal()+1)+low->getVal()-nominal;
229 sum +=
a*pow(param->getVal(),2) +
b*param->getVal()+
c;
240 double x = param->getVal();
242 sum +=
x*(high->getVal() - nominal );
244 sum +=
x*(nominal - low->getVal());
246 double eps_plus = high->getVal() - nominal;
247 double eps_minus = nominal - low->getVal();
248 double S = 0.5 * (eps_plus + eps_minus);
249 double A = 0.0625 * (eps_plus - eps_minus);
253 double val = nominal +
x * (S +
x * A * ( 15 +
x *
x * (-10 +
x *
x * 3 ) ) );
256 if (val < 0) val = 0;
266 double x = param->getVal();
268 if (
x > x0 ||
x < -x0)
271 sum +=
x*(high->getVal() - nominal );
273 sum +=
x*(nominal - low->getVal());
275 else if (nominal != 0)
277 double eps_plus = high->getVal() - nominal;
278 double eps_minus = nominal - low->getVal();
279 double S = (eps_plus + eps_minus)/2;
280 double A = (eps_plus - eps_minus)/2;
284 double b = 3*A/(2*x0);
286 double d = -A/(2*x0*x0*x0);
288 double val = nominal +
a*
x +
b*pow(
x, 2) + 0 +
d*pow(
x, 4);
289 if (val < 0) val = 0;
298 coutE(InputArguments) <<
"PiecewiseInterpolation::evaluate ERROR: " << param->GetName()
299 <<
" with unknown interpolation code" << icode << endl ;
312 cxcoutD(Tracing) <<
"PiecewiseInterpolation::evaluate - sum < 0, not forcing positive definite"<<endl;
325 for(
unsigned int j=0; j < nominal.size(); ++j) {
338 for (
unsigned int j=0; j < nominal.size(); ++j) {
340 sum[j] += param * (high[j] - nominal[j]);
342 sum[j] += param * (nominal[j] - low[j] );
348 for (
unsigned int j=0; j < nominal.size(); ++j) {
350 sum[j] *= pow(high[j]/ nominal[j], +param);
352 sum[j] *= pow(low[j] / nominal[j], -param);
358 for (
unsigned int j=0; j < nominal.size(); ++j) {
359 const double a = 0.5*(high[j]+low[j])-nominal[j];
360 const double b = 0.5*(high[j]-low[j]);
363 sum[j] += (2*
a+
b)*(param -1)+high[j]-nominal[j];
364 }
else if (param < -1.) {
365 sum[j] += -1*(2*
a-
b)*(param +1)+low[j]-nominal[j];
367 sum[j] +=
a*pow(param ,2) +
b*param +
c;
373 for (
unsigned int j=0; j < nominal.size(); ++j) {
374 const double a = 0.5*(high[j]+low[j])-nominal[j];
375 const double b = 0.5*(high[j]-low[j]);
378 sum[j] += (2*
a+
b)*(param -1)+high[j]-nominal[j];
379 }
else if (param < -1.) {
380 sum[j] += -1*(2*
a-
b)*(param +1)+low[j]-nominal[j];
382 sum[j] +=
a*pow(param ,2) +
b*param +
c;
388 for (
unsigned int j=0; j < nominal.size(); ++j) {
389 const double x = param;
391 sum[j] +=
x * (high[j] - nominal[j]);
392 }
else if (
x < -1.) {
393 sum[j] +=
x * (nominal[j] - low[j]);
395 const double eps_plus = high[j] - nominal[j];
396 const double eps_minus = nominal[j] - low[j];
397 const double S = 0.5 * (eps_plus + eps_minus);
398 const double A = 0.0625 * (eps_plus - eps_minus);
400 double val = nominal[j] +
x * (S +
x * A * ( 15. +
x *
x * (-10. +
x *
x * 3. ) ) );
402 if (val < 0.) val = 0.;
403 sum[j] += val - nominal[j];
408 for (
unsigned int j=0; j < nominal.size(); ++j) {
409 if (param > 1. || param < -1.) {
411 sum[j] += param * (high[j] - nominal[j]);
413 sum[j] += param * (nominal[j] - low[j] );
414 }
else if (nominal[j] != 0) {
415 const double eps_plus = high[j] - nominal[j];
416 const double eps_minus = nominal[j] - low[j];
417 const double S = (eps_plus + eps_minus)/2;
418 const double A = (eps_plus - eps_minus)/2;
422 const double b = 3*A/(2*1.);
424 const double d = -A/(2*1.*1.*1.);
426 double val = nominal[j] +
a * param +
b * pow(param, 2) +
d * pow(param, 4);
427 if (val < 0.) val = 0.;
429 sum[j] += val - nominal[j];
435 <<
" with unknown interpolation code" << icode << std::endl;
436 throw std::invalid_argument(
"PiecewiseInterpolation::evaluateSpan() got invalid interpolation code " + std::to_string(icode));
442 for(
unsigned int j=0; j < nominal.size(); ++j) {
460 cout <<
"Currently BinIntegrator only knows how to deal with 1-d "<<endl;
470 const RooArgSet* normSet,
const char* )
const
485 if (allVars.
empty())
return 0 ;
498 cout <<
"can't factorize integral" << endl;
504 analVars.
add(allVars) ;
507 Int_t sterileIdx(-1) ;
616 if( cache==
nullptr ) {
617 std::cout <<
"Error: Cache Element is nullptr" << std::endl;
618 throw std::exception();
629 for (
auto funcInt : static_range_cast<RooAbsReal*>(cache->
_funcIntList)) {
630 value += funcInt->getVal() ;
634 if(i==0 || i>1) { cout <<
"problem, wrong number of nominal functions"<<endl; }
640 for (
auto const *param : static_range_cast<RooAbsReal *>(
_paramSet)) {
644 if(param->getVal() > 0) {
645 value += param->getVal()*(high->
getVal() - nominal);
647 value += param->getVal()*(nominal - low->
getVal());
726 coutE(InputArguments) <<
"PiecewiseInterpolation::setInterpCode ERROR: " << param.
GetName()
727 <<
" is not in list" << endl ;
730 coutW(InputArguments) <<
"PiecewiseInterpolation::setInterpCode : " << param.
GetName()
731 <<
" is now " << code << endl ;
802void PiecewiseInterpolation::printMetaArgs(ostream& os) const
811 RooAbsArg* arg1, *arg2 ;
812 if (_highSet.getSize()!=0) {
814 while((arg1=(RooAbsArg*)_lowIter->Next())) {
820 arg2=(RooAbsArg*)_highIter->Next() ;
821 os << arg1->GetName() << " * " << arg2->GetName() ;
826 while((arg1=(RooAbsArg*)_lowIter->Next())) {
832 os << arg1->GetName() ;
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
The PiecewiseInterpolation is a class that can morph distributions into each other,...
bool _positiveDefinite
protect against negative and 0 bins.
RooListProxy _lowSet
Low-side variation.
std::vector< int > _interpCode
RooListProxy _highSet
High-side variation.
bool isBinnedDistribution(const RooArgSet &obs) const override
WVE note: assumes nominal and alternates have identical structure, must add explicit check.
void setInterpCode(RooAbsReal ¶m, int code, bool silent=false)
~PiecewiseInterpolation() override
Destructor.
void setAllInterpCodes(int code)
RooObjCacheManager _normIntMgr
! The integration cache manager
bool setBinIntegrator(RooArgSet &allVars)
std::list< double > * plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const override
Interface for returning an optional hint for initial sampling points when constructing a curve projec...
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Advertise that all integrals can be handled internally.
RooListProxy _paramSet
interpolation parameters
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
WVE note: assumes nominal and alternates have identical structure, must add explicit check.
RooArgList _ownedList
List of owned components.
RooRealProxy _nominal
The nominal value.
double evaluate() const override
Calculate and return current value of self.
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Implement analytical integrations by doing appropriate weighting from component integrals functions t...
void printAllInterpCodes()
void computeBatch(cudaStream_t *, double *output, size_t size, RooFit::Detail::DataMap const &) const override
Interpolate between input distributions for all values of the observable in evalData.
friend void RooRefArray::Streamer(TBuffer &)
RooAbsCacheElement is the abstract base class for objects to be stored in RooAbsCache cache manager o...
Int_t getSize() const
Return the number of elements in the collection.
const char * GetName() const override
Returns name of object.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
const_iterator end() const
Storage_t::size_type size() const
RooAbsArg * first() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
bool setRealValue(const char *name, double newVal=0.0, bool verbose=false)
Set value of a RooAbsRealLValye stored in set with given name to newVal No error messages are printed...
const_iterator begin() const
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
virtual std::list< double > * binBoundaries(RooAbsRealLValue &obs, double xlo, double xhi) const
Retrieve bin boundaries if this distribution is binned in obs.
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooFit::OwningPtr< RooAbsReal > createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Create an object that represents the integral of the function over one or more observables std::liste...
bool _forceNumInt
Force numerical integration if flag set.
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
virtual bool isBinnedDistribution(const RooArgSet &) const
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
virtual std::list< double > * plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const
Interface for returning an optional hint for initial sampling points when constructing a curve projec...
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Int_t setObj(const RooArgSet *nset, T *obj, const TNamed *isetRangeName=nullptr)
Setter function without integration set.
T * getObjByIndex(Int_t index) const
Retrieve payload object by slot index.
Int_t lastIndex() const
Return index of slot used in last get or set operation.
T * getObj(const RooArgSet *nset, Int_t *sterileIndex=nullptr, const TNamed *isetRangeName=nullptr)
Getter function without integration set.
bool setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
static void softAbort()
Soft abort function that interrupts macro execution but doesn't kill ROOT.
RooSpan< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
RooRealVar represents a variable that can be changed from the outside.
const T & arg() const
Return reference to object held in proxy.
Buffer base class used for serializing objects.
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
const char * GetName() const override
Returns name of object.
static uint64_t sum(uint64_t i)