78 _funcList(
"!funcList",
"List of functions",this),
79 _coefList(
"!coefList",
"List of coefficients",this),
141 const std::string className = caller.
ClassName();
142 const std::string constructorName = className +
"::" + className;
144 if (!(inFuncList.
size()==inCoefList.
size()+1 || inFuncList.
size()==inCoefList.
size())) {
145 oocoutE(&caller, InputArguments) << constructorName <<
"(" << caller.
GetName()
146 <<
") number of pdfs and coefficients inconsistent, must have Nfunc=Ncoef or Nfunc=Ncoef+1" << std::endl;
147 throw std::invalid_argument(className +
": Number of PDFs and coefficients is inconsistent.");
151 for (
unsigned int i = 0; i < inCoefList.
size(); ++i) {
152 const auto& func = inFuncList[i];
153 const auto& coef = inCoefList[i];
155 if (!
dynamic_cast<const RooAbsReal*
>(&coef)) {
156 oocoutW(&caller, InputArguments) << constructorName <<
"(" << caller.
GetName() <<
") coefficient " << coef.GetName() <<
" is not of type RooAbsReal, ignored" << std::endl ;
159 if (!
dynamic_cast<const RooAbsReal*
>(&func)) {
160 oocoutW(&caller, InputArguments) << constructorName <<
"(" << caller.
GetName() <<
") func " << func.GetName() <<
" is not of type RooAbsReal, ignored" << std::endl ;
167 if (inFuncList.
size() == inCoefList.
size() + 1) {
168 const auto& func = inFuncList[inFuncList.
size()-1];
169 if (!
dynamic_cast<const RooAbsReal*
>(&func)) {
170 oocoutE(&caller, InputArguments) << constructorName <<
"(" << caller.
GetName() <<
") last func " << func.GetName() <<
" is not of type RooAbsReal, fatal error" << std::endl ;
171 throw std::invalid_argument(className +
": Function passed as is not of type RooAbsReal.");
186 _normIntMgr(other._normIntMgr,this),
187 _funcList(
"!funcList",this,other._funcList),
188 _coefList(
"!coefList",this,other._coefList),
189 _extended(other._extended),
190 _doFloor(other._doFloor)
204 Int_t code,
const char *rangeName)
222 bool & hasWarnedBefore)
226 double sumCoeff = 0.;
230 const double coefVal = coef !=
nullptr ? coef->
getVal() : (1. - sumCoeff);
233 if (coef ==
nullptr && (coefVal < 0 || coefVal > 1.)) {
234 if (!hasWarnedBefore) {
236 <<
") WARNING: sum of FUNC coefficients not in range [0-1], value="
237 << sumCoeff <<
". This means that the PDF is not properly normalised."
238 <<
" If the PDF was meant to be extended, provide as many coefficients as functions." << std::endl;
239 hasWarnedBefore =
true;
245 if (func->isSelectedComp()) {
246 value += func->getVal() * coefVal;
268 std::size_t nEvents =
output.size();
273 double sumCoeff = 0.;
277 const double coefVal = coef !=
nullptr ? ctx.
at(coef)[0] : (1. - sumCoeff);
279 if (func->isSelectedComp()) {
280 auto funcValues = ctx.
at(func);
281 if(funcValues.size() == 1) {
282 for (
unsigned int j = 0; j < nEvents; ++j) {
283 output[j] += funcValues[0] * coefVal;
286 for (
unsigned int j = 0; j < nEvents; ++j) {
287 output[j] += funcValues[j] * coefVal;
293 if (coef ==
nullptr && (coefVal < 0 || coefVal > 1.)) {
296 <<
") WARNING: sum of FUNC coefficients not in range [0-1], value="
297 << 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;
309 for (
unsigned int j = 0; j < nEvents; ++j) {
324 if (func.observableOverlaps(nset, coef)) {
326 <<
"): ERROR: coefficient " << coef.GetName()
327 <<
" and FUNC " << func.GetName() <<
" have one or more observables in common" << std::endl;
330 if (coef.dependsOn(*nset)) {
332 <<
"): ERROR coefficient " << coef.GetName()
333 <<
" depends on one or more of the following observables" ; nset->
Print(
"1") ;
360 const RooArgSet* normSet2,
const char* rangeName)
const
369 const RooArgSet* normSet2,
const char* rangeName)
372 if (allVars.
empty())
return 0 ;
376 analVars.
add(allVars) ;
377 std::unique_ptr<RooArgSet> normSet;
379 normSet = std::make_unique<RooArgSet>();
385 Int_t sterileIdx(-1) ;
397 const auto func =
static_cast<RooAbsReal*
>(elm);
399 std::unique_ptr<RooAbsReal> funcInt{func->
createIntegral(analVars,rangeName)};
400 if(
auto funcRealInt =
dynamic_cast<RooRealIntegral*
>(funcInt.get())) funcRealInt->setAllowComponentSelection(
true);
401 cache->_funcIntList.addOwned(std::move(funcInt));
402 if (normSet && !normSet->empty()) {
403 cache->_funcNormList.addOwned(std::unique_ptr<RooAbsReal>{func->createIntegral(*normSet)});
422 if (cache ==
nullptr) {
452 bool hasWarnedBefore)
455 if (code==0)
return caller.
getVal(normSet2) ;
466 for (
const auto coefArg :
coefList) {
468 const auto coef =
static_cast<const RooAbsReal*
>(coefArg);
469 const auto func =
static_cast<const RooAbsReal*
>(*funcIt++);
470 const auto funcInt =
static_cast<RooAbsReal*
>(*funcIntIt++);
472 double coefVal = coef->
getVal(normSet2) ;
475 if (normSet2 ==
nullptr || func->isSelectedComp()) {
477 value += funcInt->getVal()*coefVal ;
479 lastCoef -= coef->getVal(normSet2) ;
487 const auto func =
static_cast<const RooAbsReal*
>(*funcIt);
488 const auto funcInt =
static_cast<RooAbsReal*
>(*funcIntIt);
491 if (normSet2 ==
nullptr || func->isSelectedComp()) {
493 value += funcInt->getVal()*lastCoef ;
497 if (!hasWarnedBefore && (lastCoef<0 || lastCoef>1)) {
499 <<
" WARNING: sum of FUNC coefficients not in range [0-1], value="
500 << 1-lastCoef << std::endl;
505 if (normSet2 && !normSet2->
empty()) {
510 for (
const auto coefAsArg :
coefList) {
511 auto coef =
static_cast<RooAbsReal*
>(coefAsArg);
512 auto funcNorm =
static_cast<RooAbsReal*
>(*funcNormIter++);
514 double coefVal = coef->
getVal(normSet2);
517 normVal += funcNorm->getVal()*coefVal ;
523 auto funcNorm =
static_cast<RooAbsReal*
>(*funcNormIter);
526 normVal += funcNorm->getVal()*lastCoef;
530 return value / normVal;
557 std::unique_ptr<std::list<double>> sumBinB;
558 bool needClean(
false);
561 for (
auto *func : static_range_cast<RooAbsReal *>(
funcList)) {
563 std::unique_ptr<std::list<double>> funcBinB{func->binBoundaries(obs, xlo, xhi)};
569 sumBinB = std::move(funcBinB);
573 auto newSumBinB = std::make_unique<std::list<double>>(sumBinB->size() + funcBinB->size());
576 std::merge(funcBinB->begin(), funcBinB->end(), sumBinB->begin(), sumBinB->end(), newSumBinB->begin());
578 sumBinB = std::move(newSumBinB);
585 sumBinB->erase(std::unique(sumBinB->begin(), sumBinB->end()), sumBinB->end());
588 return sumBinB.release();
602 for (
auto* func : static_range_cast<RooAbsReal*>(
funcList)) {
604 if (func->dependsOn(obs) && !func->isBinnedDistribution(obs)) {
624 std::unique_ptr<std::list<double>> sumHint;
625 bool needClean(
false);
631 std::unique_ptr<std::list<double>> funcHint{func->
plotSamplingHint(obs, xlo, xhi)};
638 sumHint = std::move(funcHint);
642 auto newSumHint = std::make_unique<std::list<double>>(sumHint->size() + funcHint->size());
648 std::merge(funcHint->begin(), funcHint->end(), sumHint->begin(), sumHint->end(), newSumHint->begin());
650 sumHint = std::move(newSumHint);
657 sumHint->erase(std::unique(sumHint->begin(), sumHint->end()), sumHint->end());
660 return sumHint.release();
678 if (sarg->canNodeBeCached()==
Always) {
679 trackNodes.
add(*sarg) ;
709 const auto func = *(funcIter++);
710 os << coef->GetName() <<
" * " << func->GetName();
714 os <<
" + [%] * " << (*funcIter)->GetName() ;
724 os << func->GetName() ;
731std::unique_ptr<RooAbsArg>
737 std::unique_ptr<RooAbsPdf> pdfClone(
static_cast<RooAbsPdf *
>(this->
Clone()));
739 if (ctx.
likelihoodMode() && pdfClone->getAttribute(
"BinnedLikelihood")) {
748 pdfClone->setAttribute(
"BinnedLikelihoodActive");
759 pdfClone->setAttribute(
"BinnedLikelihoodActiveYields");
767 pdfClone->getObservables(&normSet, depList);
769 auto newArg = std::make_unique<RooFit::Detail::RooNormalizedPdf>(*pdfClone, depList);
773 for (
RooAbsArg *server : newArg->servers()) {
777 newArg->addOwnedComponents(std::move(pdfClone));
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Common abstract base class for objects that represent a value and a "shape" in RooFit.
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.
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.
const_iterator end() const
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.
Abstract interface for all probability density functions.
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
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
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.
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...
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.
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...
void setBinnedLikelihoodMode(bool flag)
void markAsCompiled(RooAbsArg &arg) const
void compileServers(RooAbsArg &arg, RooArgSet const &normSet)
bool likelihoodMode() const
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...
Performs hybrid numerical/analytical integrals of RooAbsReal objects.
Implements a PDF constructed from a sum of functions:
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.
__roodevice__ static __roohost__ double packFloatIntoNaN(float payload)
Pack float into mantissa of a NaN.