86 _funcList(
"!funcList",
"List of functions",this),
87 _coefList(
"!coefList",
"List of coefficients",this),
152 const std::string className = caller.
ClassName();
153 const std::string constructorName = className +
"::" + className;
155 if (!(inFuncList.
size()==inCoefList.
size()+1 || inFuncList.
size()==inCoefList.
size())) {
157 <<
") number of pdfs and coefficients inconsistent, must have Nfunc=Ncoef or Nfunc=Ncoef+1" << std::endl;
158 throw std::invalid_argument(className +
": Number of PDFs and coefficients is inconsistent.");
162 for (
unsigned int i = 0; i < inCoefList.
size(); ++i) {
163 const auto& func = inFuncList[i];
164 const auto& coef = inCoefList[i];
166 if (!
dynamic_cast<const RooAbsReal*
>(&coef)) {
167 oocoutW(&caller,
InputArguments) << constructorName <<
"(" << caller.
GetName() <<
") coefficient " << coef.GetName() <<
" is not of type RooAbsReal, ignored" << std::endl ;
170 if (!
dynamic_cast<const RooAbsReal*
>(&func)) {
171 oocoutW(&caller,
InputArguments) << constructorName <<
"(" << caller.
GetName() <<
") func " << func.GetName() <<
" is not of type RooAbsReal, ignored" << std::endl ;
178 if (inFuncList.
size() == inCoefList.
size() + 1) {
179 const auto& func = inFuncList[inFuncList.
size()-1];
180 if (!
dynamic_cast<const RooAbsReal*
>(&func)) {
181 oocoutE(&caller,
InputArguments) << constructorName <<
"(" << caller.
GetName() <<
") last func " << func.GetName() <<
" is not of type RooAbsReal, fatal error" << std::endl ;
182 throw std::invalid_argument(className +
": Function passed as is not of type RooAbsReal.");
197 _normIntMgr(other._normIntMgr,this),
198 _funcList(
"!funcList",this,other._funcList),
199 _coefList(
"!coefList",this,other._coefList),
200 _extended(other._extended),
201 _doFloor(other._doFloor)
232 bool & hasWarnedBefore)
236 double sumCoeff = 0.;
240 const double coefVal = coef !=
nullptr ? coef->
getVal() : (1. - sumCoeff);
243 if (coef ==
nullptr && (coefVal < 0 || coefVal > 1.)) {
244 if (!hasWarnedBefore) {
246 <<
") WARNING: sum of FUNC coefficients not in range [0-1], value="
247 << sumCoeff <<
". This means that the PDF is not properly normalised."
248 <<
" If the PDF was meant to be extended, provide as many coefficients as functions." << std::endl;
249 hasWarnedBefore =
true;
255 if (func->isSelectedComp()) {
256 value += func->getVal() * coefVal;
278 for (
unsigned int j = 0; j < nEvents; ++j) {
282 double sumCoeff = 0.;
286 const double coefVal = coef !=
nullptr ? dataMap.
at(coef)[0] : (1. - sumCoeff);
288 if (func->isSelectedComp()) {
289 auto funcValues = dataMap.
at(func);
290 if(funcValues.size() == 1) {
291 for (
unsigned int j = 0; j < nEvents; ++j) {
292 output[j] += funcValues[0] * coefVal;
295 for (
unsigned int j = 0; j < nEvents; ++j) {
296 output[j] += funcValues[j] * coefVal;
302 if (coef ==
nullptr && (coefVal < 0 || coefVal > 1.)) {
305 <<
") WARNING: sum of FUNC coefficients not in range [0-1], value="
306 << sumCoeff <<
". This means that the PDF is not properly normalised. If the PDF was meant to be extended, provide as many coefficients as functions." << endl ;
318 for (
unsigned int j = 0; j < nEvents; ++j) {
334 if (func.observableOverlaps(nset, coef)) {
336 <<
"): ERROR: coefficient " << coef.GetName()
337 <<
" and FUNC " << func.GetName() <<
" have one or more observables in common" << std::endl;
340 if (coef.dependsOn(*nset)) {
342 <<
"): ERROR coefficient " << coef.GetName()
343 <<
" depends on one or more of the following observables" ; nset->
Print(
"1") ;
370 const RooArgSet* normSet2,
const char* rangeName)
const
379 const RooArgSet* normSet2,
const char* rangeName)
382 if (allVars.
empty())
return 0 ;
386 analVars.
add(allVars) ;
387 std::unique_ptr<RooArgSet> normSet;
389 normSet = std::make_unique<RooArgSet>();
395 Int_t sterileIdx(-1) ;
407 const auto func =
static_cast<RooAbsReal*
>(elm);
411 cache->_funcIntList.addOwned(*funcInt) ;
412 if (normSet && !normSet->empty()) {
414 cache->_funcNormList.addOwned(*funcNorm) ;
440 bool hasWarnedBefore)
443 if (code==0)
return caller.
getVal(normSet2) ;
466 auto funcIntIt = cache->_funcIntList.begin();
467 for (
const auto coefArg :
coefList) {
469 const auto coef =
static_cast<const RooAbsReal*
>(coefArg);
470 const auto func =
static_cast<const RooAbsReal*
>(*funcIt++);
471 const auto funcInt =
static_cast<RooAbsReal*
>(*funcIntIt++);
473 double coefVal = coef->
getVal(normSet2) ;
476 if (normSet2 ==0 || func->isSelectedComp()) {
478 value += funcInt->getVal()*coefVal ;
480 lastCoef -= coef->getVal(normSet2) ;
488 const auto func =
static_cast<const RooAbsReal*
>(*funcIt);
489 const auto funcInt =
static_cast<RooAbsReal*
>(*funcIntIt);
492 if (normSet2 ==0 || func->isSelectedComp()) {
494 value += funcInt->getVal()*lastCoef ;
498 if (!hasWarnedBefore && (lastCoef<0 || lastCoef>1)) {
500 <<
" WARNING: sum of FUNC coefficients not in range [0-1], value="
501 << 1-lastCoef << endl ;
506 if (normSet2 && normSet2->
getSize()>0) {
510 auto funcNormIter = cache->_funcNormList.begin();
511 for (
const auto coefAsArg :
coefList) {
512 auto coef =
static_cast<RooAbsReal*
>(coefAsArg);
513 auto funcNorm =
static_cast<RooAbsReal*
>(*funcNormIter++);
515 double coefVal = coef->
getVal(normSet2);
518 normVal += funcNorm->getVal()*coefVal ;
524 auto funcNorm =
static_cast<RooAbsReal*
>(*funcNormIter);
527 normVal += funcNorm->getVal()*lastCoef;
531 return value / normVal;
557 std::list<double>* sumBinB =
nullptr;
558 bool needClean(
false) ;
561 for (
auto * func : static_range_cast<RooAbsReal*>(
funcList)) {
563 list<double>* funcBinB = func->binBoundaries(obs,xlo,xhi) ;
572 std::list<double>* newSumBinB =
new list<double>(sumBinB->size()+funcBinB->size()) ;
575 merge(funcBinB->begin(),funcBinB->end(),sumBinB->begin(),sumBinB->end(),newSumBinB->begin()) ;
580 sumBinB = newSumBinB ;
588 list<double>::iterator new_end = unique(sumBinB->begin(),sumBinB->end()) ;
589 sumBinB->erase(new_end,sumBinB->end()) ;
606 for (
auto* func : static_range_cast<RooAbsReal*>(
funcList)) {
608 if (func->dependsOn(obs) && !func->isBinnedDistribution(obs)) {
627 std::list<double>* sumHint =
nullptr;
628 bool needClean(
false) ;
645 auto* newSumHint =
new std::list<double>(sumHint->size()+funcHint->size()) ;
648 merge(funcHint->begin(),funcHint->end(),sumHint->begin(),sumHint->end(),newSumHint->begin()) ;
652 sumHint = newSumHint ;
660 sumHint->erase(std::unique(sumHint->begin(),sumHint->end()), sumHint->end()) ;
681 if (sarg->canNodeBeCached()==
Always) {
682 trackNodes.
add(*sarg) ;
713 const auto func = *(funcIter++);
714 os << coef->GetName() <<
" * " << func->GetName();
718 os <<
" + [%] * " << (*funcIter)->GetName() ;
728 os << func->GetName() ;
740 std::unique_ptr<RooAbsPdf> pdfClone(
static_cast<RooAbsPdf*
>(this->
Clone()));
744 pdfClone->getObservables(&normSet, *depList);
746 auto newArg = std::make_unique<RooNormalizedPdf>(*pdfClone, *depList);
751 server->setAttribute(
"_COMPILED");
753 newArg->setAttribute(
"_COMPILED");
754 newArg->addOwnedComponents(std::move(pdfClone));
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
RooArgSet * getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
const RefCountList_t & servers() const
List of all servers of this object.
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
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...
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.
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.
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
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...
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 ...
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 getForceNumInt() const
void logEvalError(const char *message, const char *serverValueString=nullptr) const
Log evaluation error message.
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.
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 contatining the objects that are both in the cached set 1.
T * getObjByIndex(Int_t index) const
Retrieve payload object by slot index.
RooArgSet selectFromSet2(RooArgSet const &argSet, int index) const
Create RooArgSet contatining the objects that are both in the cached set 2.
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 compileServers(RooAbsArg &arg, RooArgSet const &normSet)
auto & at(RooAbsArg const *arg, RooAbsArg const *=nullptr)
static const TNamed * ptr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
Class RooObjCacheManager is an implementation of class RooCacheManager<RooAbsCacheElement> and specia...
RooRealIntegral performs hybrid numerical/analytical integrals of RooAbsReal objects.
The class RooRealSumPdf 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.
bool checkObservables(const RooArgSet *nset) const override
Check if FUNC is valid for given normalization set.
const RooArgList & funcList() const
~RooRealSumPdf() override
Destructor.
RooObjCacheManager _normIntMgr
! The integration cache manager
void computeBatch(cudaStream_t *, double *output, size_t size, RooFit::Detail::DataMap const &) const override
Base function for computing multiple values of a RooAbsReal.
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.
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...
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 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.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
static double packFloatIntoNaN(float payload)
Pack float into mantissa of a NaN.