43using std::endl, std::cout;
71 _lowSet(
"!lowSet",
"low-side variation", this),
72 _highSet(
"!highSet",
"high-side variation", this),
73 _paramSet(
"!paramSet",
"high-side variation", this),
78 if (lowSet.
size() != highSet.
size()) {
79 coutE(InputArguments) <<
"PiecewiseInterpolation::ctor(" << GetName() <<
") ERROR: input lists should be of equal length" << endl ;
80 RooErrorHandler::softAbort() ;
83 for (
auto *comp : lowSet) {
85 coutE(InputArguments) <<
"PiecewiseInterpolation::ctor(" <<
GetName() <<
") ERROR: component " << comp->GetName()
86 <<
" in first list is not of type RooAbsReal" << endl ;
93 for (
auto *comp : highSet) {
95 coutE(InputArguments) <<
"PiecewiseInterpolation::ctor(" <<
GetName() <<
") ERROR: component " << comp->GetName()
96 <<
" in first list is not of type RooAbsReal" << endl ;
103 for (
auto *comp : paramSet) {
105 coutE(InputArguments) <<
"PiecewiseInterpolation::ctor(" <<
GetName() <<
") ERROR: component " << comp->GetName()
106 <<
" in first list is not of type RooAbsReal" << endl ;
158 double sum(nominal) ;
166 if(icode < 0 || icode > 5) {
167 coutE(InputArguments) <<
"PiecewiseInterpolation::evaluate ERROR: " << param->GetName()
168 <<
" with unknown interpolation code" << icode << endl ;
171 sum += flexibleInterpSingle(icode, low->getVal(), high->getVal(), 1.0, nominal, param->getVal(),
sum);
181 cxcoutD(Tracing) <<
"PiecewiseInterpolation::evaluate - sum < 0, not forcing positive definite"<<endl;
192 for (std::size_t
i = 0;
i <
n; ++
i) {
194 coutE(InputArguments) <<
"PiecewiseInterpolation::evaluate ERROR: " <<
_paramSet[
i].GetName()
195 <<
" with unknown interpolation code" <<
_interpCode[
i] << endl;
198 coutE(InputArguments) <<
"FlexibleInterpVar::evaluate ERROR: Code Squashing AD does not yet support having "
199 "different interpolation codes for the same class object "
215 std::vector<double> valsNominal;
216 std::vector<double> valsLow;
217 std::vector<double> valsHigh;
218 for (
int i = 0;
i < nBins; ++
i) {
219 valsNominal.push_back(nomHist.
weight(
i));
221 for (
int i = 0;
i < nBins; ++
i) {
222 for (std::size_t iParam = 0; iParam <
n; ++iParam) {
223 valsLow.push_back(
dynamic_cast<RooHistFunc const &
>(
_lowSet[iParam]).dataHist().weight(
i));
228 std::string valsNominalStr = ctx.
buildArg(valsNominal);
229 std::string valsLowStr = ctx.
buildArg(valsLow);
230 std::string valsHighStr = ctx.
buildArg(valsHigh);
231 std::string nStr = std::to_string(
n);
238 code +=
"double const* " + lowName +
" = " + valsLowStr +
" + " + nStr +
" * " + idxName +
";\n";
239 code +=
"double const* " + highName +
" = " + valsHighStr +
" + " + nStr +
" * " + idxName +
";\n";
240 code +=
"double " + nominalName +
" = *(" + valsNominalStr +
" + " + idxName +
");\n";
243 lowName, highName, 1.0, nominalName, 0.0);
244 code +=
"double " + resName +
" = " + funcCall +
";\n";
247 code += resName +
" = " + resName +
" < 0 ? 0 : " + resName +
";\n";
262 for(
unsigned int j=0; j < nominal.size(); ++j) {
272 if (icode < 0 || icode > 5) {
273 coutE(InputArguments) <<
"PiecewiseInterpolation::doEval(): " <<
_paramSet[
i].GetName()
274 <<
" with unknown interpolation code" << icode << std::endl;
275 throw std::invalid_argument(
"PiecewiseInterpolation::doEval() got invalid interpolation code " + std::to_string(icode));
278 for (
unsigned int j=0; j < nominal.size(); ++j) {
280 sum[j] += flexibleInterpSingle(icode, low[j], high[j], 1.0, nominal[j], param,
sum[j]);
285 for(
unsigned int j=0; j < nominal.size(); ++j) {
296 if(allVars.
size()==1){
303 cout <<
"Currently BinIntegrator only knows how to deal with 1-d "<<endl;
313 const RooArgSet* normSet,
const char* )
const
328 if (allVars.
empty())
return 0 ;
341 cout <<
"can't factorize integral" << endl;
347 analVars.
add(allVars) ;
350 Int_t sterileIdx(-1) ;
459 if( cache==
nullptr ) {
460 std::cout <<
"Error: Cache Element is nullptr" << std::endl;
461 throw std::exception();
474 value += funcInt->getVal() ;
478 if(
i==0 ||
i>1) { cout <<
"problem, wrong number of nominal functions"<<endl; }
488 if(param->getVal() > 0) {
489 value += param->getVal()*(high->
getVal() - nominal);
491 value += param->getVal()*(nominal - low->
getVal());
570 coutE(InputArguments) <<
"PiecewiseInterpolation::setInterpCode ERROR: " << param.
GetName()
571 <<
" is not in list" << endl ;
574 coutW(InputArguments) <<
"PiecewiseInterpolation::setInterpCode : " << param.
GetName()
575 <<
" is now " << code << endl ;
605 return _nominal.arg().binBoundaries(obs,xlo,xhi) ;
614 return _nominal.arg().isBinnedDistribution(obs) ;
623 return _nominal.arg().plotSamplingHint(obs,xlo,xhi) ;
646void PiecewiseInterpolation::printMetaArgs(ostream& os) const
655 RooAbsArg* arg1, *arg2 ;
656 if (_highSet.size()!=0) {
658 while((arg1=(RooAbsArg*)_lowIter->Next())) {
664 arg2=(RooAbsArg*)_highIter->Next() ;
665 os << arg1->GetName() << " * " << arg2->GetName() ;
670 while((arg1=(RooAbsArg*)_lowIter->Next())) {
676 os << arg1->GetName() ;
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
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 Streamer(TBuffer &) override
Stream an object of class PiecewiseInterpolation.
void setAllInterpCodes(int code)
void translate(RooFit::Detail::CodeSquashContext &ctx) const override
This function defines a translation for each RooAbsReal based object that can be used to express the ...
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.
RooRealProxy _nominal
The nominal value.
double evaluate() const override
Calculate and return current value of self.
void doEval(RooFit::EvalContext &) const override
Interpolate between input distributions for all values of the observable in evalData.
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()
Abstract base class for objects to be stored in RooAbsCache cache manager objects.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
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 RooAbsRealLValue stored in set with given name to newVal No error messages are printed...
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
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.
RooAbsReal()
coverity[UNINIT_CTOR] Default constructor
bool _forceNumInt
Force numerical integration if flag set.
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
RooFit::OwningPtr< RooAbsReal > createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Create an object that represents the integral of the function over one or more observables listed in ...
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.
bool setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
Container class to hold N-dimensional binned data.
std::string calculateTreeIndexForCodeSquash(RooAbsArg const *klass, RooFit::Detail::CodeSquashContext &ctx, const RooAbsCollection &coords, bool reverse=false) const
double weight(std::size_t i) const
Return weight of i-th bin.
static void softAbort()
Soft abort function that interrupts macro execution but doesn't kill ROOT.
A class to maintain the context for squashing of RooFit models into code.
std::string buildCall(std::string const &funcname, Args_t const &...args)
Build the code to call the function with name funcname, passing some arguments.
void addResult(RooAbsArg const *key, std::string const &value)
A function to save an expression that includes/depends on the result of the input node.
void addToCodeBody(RooAbsArg const *klass, std::string const &in)
Adds the input string to the squashed code body.
std::string getTmpVarName() const
Get a unique variable name to be used in the generated code.
std::string buildArg(RooAbsCollection const &x)
Function to save a RooListProxy as an array in the squashed code.
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::span< double > output()
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
Variable that can be changed from the outside.
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.
double flexibleInterpSingle(unsigned int code, double low, double high, double boundary, double nominal, double paramVal, double res)
static uint64_t sum(uint64_t i)