77 _funcList(
"!funcList",
"List of functions",this),
78 _coefList(
"!coefList",
"List of coefficients",this),
140 const std::string className = caller.
ClassName();
141 const std::string constructorName = className +
"::" + className;
143 if (!(inFuncList.
size()==inCoefList.
size()+1 || inFuncList.
size()==inCoefList.
size())) {
144 oocoutE(&caller, InputArguments) << constructorName <<
"(" << caller.
GetName()
145 <<
") number of pdfs and coefficients inconsistent, must have Nfunc=Ncoef or Nfunc=Ncoef+1" << std::endl;
146 throw std::invalid_argument(className +
": Number of PDFs and coefficients is inconsistent.");
150 for (
unsigned int i = 0; i < inCoefList.
size(); ++i) {
151 const auto& func = inFuncList[i];
152 const auto& coef = inCoefList[i];
154 if (!
dynamic_cast<const RooAbsReal*
>(&coef)) {
155 oocoutW(&caller, InputArguments) << constructorName <<
"(" << caller.
GetName() <<
") coefficient " << coef.GetName() <<
" is not of type RooAbsReal, ignored" << std::endl ;
158 if (!
dynamic_cast<const RooAbsReal*
>(&func)) {
159 oocoutW(&caller, InputArguments) << constructorName <<
"(" << caller.
GetName() <<
") func " << func.GetName() <<
" is not of type RooAbsReal, ignored" << std::endl ;
166 if (inFuncList.
size() == inCoefList.
size() + 1) {
167 const auto& func = inFuncList[inFuncList.
size()-1];
168 if (!
dynamic_cast<const RooAbsReal*
>(&func)) {
169 oocoutE(&caller, InputArguments) << constructorName <<
"(" << caller.
GetName() <<
") last func " << func.GetName() <<
" is not of type RooAbsReal, fatal error" << std::endl ;
170 throw std::invalid_argument(className +
": Function passed as is not of type RooAbsReal.");
203 Int_t code,
const char *rangeName)
221 bool & hasWarnedBefore)
225 double sumCoeff = 0.;
226 for (
unsigned int i = 0; i <
funcList.size(); ++i) {
229 const double coefVal = coef !=
nullptr ? coef->getVal() : (1. - sumCoeff);
232 if (coef ==
nullptr && (coefVal < 0 || coefVal > 1.)) {
233 if (!hasWarnedBefore) {
235 <<
") WARNING: sum of FUNC coefficients not in range [0-1], value="
236 << sumCoeff <<
". This means that the PDF is not properly normalised."
237 <<
" If the PDF was meant to be extended, provide as many coefficients as functions." << std::endl;
238 hasWarnedBefore =
true;
244 if (func->isSelectedComp()) {
245 value += func->getVal() * coefVal;
252 return value < 0 && doFloor ? 0.0 : value;
266 std::span<double> output = ctx.
output();
267 std::size_t nEvents = output.size();
270 std::fill(output.begin(), output.end(), 0.);
272 double sumCoeff = 0.;
273 for (
unsigned int i = 0; i <
_funcList.size(); ++i) {
276 const double coefVal = coef !=
nullptr ? ctx.
at(coef)[0] : (1. - sumCoeff);
278 if (func->isSelectedComp()) {
279 auto funcValues = ctx.
at(func);
280 if(funcValues.size() == 1) {
281 for (
unsigned int j = 0; j < nEvents; ++j) {
282 output[j] += funcValues[0] * coefVal;
285 for (
unsigned int j = 0; j < nEvents; ++j) {
286 output[j] += funcValues[j] * coefVal;
292 if (coef ==
nullptr && (coefVal < 0 || coefVal > 1.)) {
295 <<
") WARNING: sum of FUNC coefficients not in range [0-1], value="
296 << sumCoeff <<
". This means that the PDF is not properly normalised. If the PDF was meant to be extended, provide as many coefficients as functions." << std::endl;
308 for (
unsigned int j = 0; j < nEvents; ++j) {
309 output[j] = std::max(0., output[j]);
319 for (
unsigned int i=0; i <
coefList.size(); ++i) {
323 if (func.observableOverlaps(nset, coef)) {
325 <<
"): ERROR: coefficient " << coef.GetName()
326 <<
" and FUNC " << func.GetName() <<
" have one or more observables in common" << std::endl;
329 if (coef.dependsOn(*nset)) {
331 <<
"): ERROR coefficient " << coef.GetName()
332 <<
" depends on one or more of the following observables" ; nset->
Print(
"1") ;
359 const RooArgSet* normSet2,
const char* rangeName)
const
368 const RooArgSet* normSet2,
const char* rangeName)
371 if (allVars.
empty())
return 0 ;
375 analVars.
add(allVars) ;
376 std::unique_ptr<RooArgSet> normSet;
378 normSet = std::make_unique<RooArgSet>();
384 Int_t sterileIdx(-1) ;
396 const auto func =
static_cast<RooAbsReal*
>(elm);
398 std::unique_ptr<RooAbsReal> funcInt{func->createIntegral(analVars,rangeName)};
399 if(
auto funcRealInt =
dynamic_cast<RooRealIntegral*
>(funcInt.get())) funcRealInt->setAllowComponentSelection(
true);
400 cache->_funcIntList.addOwned(std::move(funcInt));
401 if (normSet && !normSet->empty()) {
402 cache->_funcNormList.addOwned(std::unique_ptr<RooAbsReal>{func->createIntegral(*normSet)});
421 if (cache ==
nullptr) {
451 bool hasWarnedBefore)
454 if (code==0)
return caller.
getVal(normSet2) ;
465 for (
const auto coefArg :
coefList) {
467 const auto coef =
static_cast<const RooAbsReal*
>(coefArg);
468 const auto func =
static_cast<const RooAbsReal*
>(*funcIt++);
469 const auto funcInt =
static_cast<RooAbsReal*
>(*funcIntIt++);
471 double coefVal = coef->getVal(normSet2) ;
474 if (normSet2 ==
nullptr || func->isSelectedComp()) {
476 value += funcInt->getVal()*coefVal ;
478 lastCoef -= coef->getVal(normSet2) ;
486 const auto func =
static_cast<const RooAbsReal*
>(*funcIt);
487 const auto funcInt =
static_cast<RooAbsReal*
>(*funcIntIt);
490 if (normSet2 ==
nullptr || func->isSelectedComp()) {
492 value += funcInt->getVal()*lastCoef ;
496 if (!hasWarnedBefore && (lastCoef<0 || lastCoef>1)) {
498 <<
" WARNING: sum of FUNC coefficients not in range [0-1], value="
499 << 1-lastCoef << std::endl;
504 if (normSet2 && !normSet2->
empty()) {
509 for (
const auto coefAsArg :
coefList) {
510 auto coef =
static_cast<RooAbsReal*
>(coefAsArg);
511 auto funcNorm =
static_cast<RooAbsReal*
>(*funcNormIter++);
513 double coefVal = coef->getVal(normSet2);
516 normVal += funcNorm->getVal()*coefVal ;
522 auto funcNorm =
static_cast<RooAbsReal*
>(*funcNormIter);
525 normVal += funcNorm->getVal()*lastCoef;
529 return value / normVal;
556 std::unique_ptr<std::list<double>> sumBinB;
557 bool needClean(
false);
562 std::unique_ptr<std::list<double>> funcBinB{func->binBoundaries(obs, xlo, xhi)};
568 sumBinB = std::move(funcBinB);
572 auto newSumBinB = std::make_unique<std::list<double>>(sumBinB->size() + funcBinB->size());
575 std::merge(funcBinB->begin(), funcBinB->end(), sumBinB->begin(), sumBinB->end(), newSumBinB->begin());
577 sumBinB = std::move(newSumBinB);
584 sumBinB->erase(std::unique(sumBinB->begin(), sumBinB->end()), sumBinB->end());
587 return sumBinB.release();
603 if (func->dependsOn(obs) && !func->isBinnedDistribution(obs)) {
623 std::unique_ptr<std::list<double>> sumHint;
624 bool needClean(
false);
630 std::unique_ptr<std::list<double>> funcHint{func->plotSamplingHint(obs, xlo, xhi)};
637 sumHint = std::move(funcHint);
641 auto newSumHint = std::make_unique<std::list<double>>(sumHint->size() + funcHint->size());
647 std::merge(funcHint->begin(), funcHint->end(), sumHint->begin(), sumHint->end(), newSumHint->begin());
649 sumHint = std::move(newSumHint);
656 sumHint->erase(std::unique(sumHint->begin(), sumHint->end()), sumHint->end());
659 return sumHint.release();
677 if (sarg->canNodeBeCached()==
Always) {
678 trackNodes.
add(*sarg) ;
708 const auto func = *(funcIter++);
709 os << coef->GetName() <<
" * " << func->GetName();
713 os <<
" + [%] * " << (*funcIter)->GetName() ;
723 os << func->GetName() ;
730std::unique_ptr<RooAbsArg>
736 std::unique_ptr<RooAbsPdf> pdfClone(
static_cast<RooAbsPdf *
>(this->
Clone()));
738 if (ctx.
likelihoodMode() && pdfClone->getAttribute(
"BinnedLikelihood")) {
747 pdfClone->setAttribute(
"BinnedLikelihoodActive");
758 pdfClone->setAttribute(
"BinnedLikelihoodActiveYields");
766 pdfClone->getObservables(&normSet, depList);
768 auto newArg = std::make_unique<RooFit::Detail::RooNormalizedPdf>(*pdfClone, depList);
773 newArg->addOwnedComponents(std::move(pdfClone));
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
int Int_t
Signed integer 4 bytes (int).
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
friend class RooRealIntegral
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
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
const_iterator begin() const
void Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
double getNorm(const RooArgSet &nset) const
Get normalisation term needed to normalise the raw values returned by getVal().
std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const override
const char * normRange() const
RooAbsPdf()
Default constructor.
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.
virtual Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet *normSet, const char *rangeName=nullptr) const
Variant of getAnalyticalIntegral that is also passed the normalization set that should be applied to ...
bool getForceNumInt() const
void logEvalError(const char *message, const char *serverValueString=nullptr) const
Log evaluation error message.
const RooNumIntConfig * getIntegratorConfig() const
Return the numeric integration configuration used for this object.
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.
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.
RooArgSet selectFromSet1(RooArgSet const &argSet, int index) const
Create RooArgSet containing the objects that are both in the cached set 1 with a given index and an i...
T * getObjByIndex(Int_t index) const
Retrieve payload object by slot index.
RooArgSet selectFromSet2(RooArgSet const &argSet, int index) const
Create RooArgSet containing the objects that are both in the cached set 2 with a given index and an i...
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.
void setBinnedLikelihoodMode(bool flag)
void markAsCompiled(RooAbsArg &arg) const
void compileServers(RooAbsArg &arg, RooArgSet const &normSet)
bool likelihoodMode() const
void markSubtreeAsCompiled(RooAbsArg &arg) const
Mark arg and every branch node reachable through its server tree as already compiled.
bool binWidthFuncFlag() const
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::span< double > output()
static const TNamed * ptr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
Implementation of a RooCacheManager<RooAbsCacheElement> that specializes in the storage of cache elem...
void setCacheAndTrackHints(RooArgSet &) override
Label OK'ed components of a RooRealSumPdf with cache-and-track.
static bool _doFloorGlobal
Global flag for introducing floor at zero in pdf.
bool _doFloor
Introduce floor at zero in pdf.
std::unique_ptr< RooAbsReal > createExpectedEventsFunc(const RooArgSet *nset) const override
Returns an object that represents the expected number of events for a given normalization set,...
bool checkObservables(const RooArgSet *nset) const override
Check if FUNC is valid for given normalization set.
void setExtended(bool extended)
const RooArgList & funcList() const
RooObjCacheManager _normIntMgr
! The integration cache manager
std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const override
std::list< double > * plotSamplingHint(RooAbsRealLValue &, double, double) const override
Interface for returning an optional hint for initial sampling points when constructing a curve projec...
double evaluate() const override
Calculate the current value.
ExtendMode extendMode() const override
Returns ability of PDF to provide extended likelihood terms.
const RooArgList & funcIntListFromCache(Int_t code, const char *rangeName=nullptr) const
Collect the list of functions to be integrated from the cache.
RooListProxy _coefList
List of coefficients.
bool selfNormalized() const override
Shows if a PDF is self-normalized, which means that no attempt is made to add a normalization term.
RooListProxy _funcList
List of component FUNCs.
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Retrieve bin boundaries if this distribution is binned in obs.
RooRealSumPdf()
Default constructor coverity[UNINIT_CTOR].
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooRealSumPdf to more intuitively reflect the contents of the p...
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Advertise that all integrals can be handled internally.
double expectedEvents(const RooArgSet *nset) const override
Return expected number of events for extended likelihood calculation, which is the sum of all coeffic...
void doEval(RooFit::EvalContext &) const override
Base function for computing multiple values of a RooAbsReal.
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Implement analytical integrations by deferring integration of component functions to integrators of c...
static const CacheElem * getCacheElem(RooAbsReal const &caller, RooObjCacheManager &normIntMgr, Int_t code, const char *rangeName)
Collect cache elements for given code to use in codegen.
static void initializeFuncsAndCoefs(RooAbsReal const &caller, const RooArgList &inFuncList, const RooArgList &inCoefList, RooArgList &funcList, RooArgList &coefList)
const RooArgList & coefList() const
bool _extended
Allow use as extended p.d.f.
bool isBinnedDistribution(const RooArgSet &obs) const override
Check if all components that depend on obs are binned.
const char * GetName() const override
Returns name of object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
static double packFloatIntoNaN(float payload)
Pack float into mantissa of a NaN.