85 _funcList(
"!funcList",
"List of functions",this),
86 _coefList(
"!coefList",
"List of coefficients",this),
151 const std::string className = caller.
ClassName();
152 const std::string constructorName = className +
"::" + className;
154 if (!(inFuncList.
size()==inCoefList.
size()+1 || inFuncList.
size()==inCoefList.
size())) {
155 oocoutE(&caller, InputArguments) << constructorName <<
"(" << caller.
GetName()
156 <<
") number of pdfs and coefficients inconsistent, must have Nfunc=Ncoef or Nfunc=Ncoef+1" << std::endl;
157 throw std::invalid_argument(className +
": Number of PDFs and coefficients is inconsistent.");
161 for (
unsigned int i = 0; i < inCoefList.
size(); ++i) {
162 const auto& func = inFuncList[i];
163 const auto& coef = inCoefList[i];
165 if (!
dynamic_cast<const RooAbsReal*
>(&coef)) {
166 oocoutW(&caller, InputArguments) << constructorName <<
"(" << caller.
GetName() <<
") coefficient " << coef.GetName() <<
" is not of type RooAbsReal, ignored" << std::endl ;
169 if (!
dynamic_cast<const RooAbsReal*
>(&func)) {
170 oocoutW(&caller, InputArguments) << constructorName <<
"(" << caller.
GetName() <<
") func " << func.GetName() <<
" is not of type RooAbsReal, ignored" << std::endl ;
177 if (inFuncList.
size() == inCoefList.
size() + 1) {
178 const auto& func = inFuncList[inFuncList.
size()-1];
179 if (!
dynamic_cast<const RooAbsReal*
>(&func)) {
180 oocoutE(&caller, InputArguments) << constructorName <<
"(" << caller.
GetName() <<
") last func " << func.GetName() <<
" is not of type RooAbsReal, fatal error" << std::endl ;
181 throw std::invalid_argument(className +
": Function passed as is not of type RooAbsReal.");
196 _normIntMgr(other._normIntMgr,this),
197 _funcList(
"!funcList",this,other._funcList),
198 _coefList(
"!coefList",this,other._coefList),
199 _extended(other._extended),
200 _doFloor(other._doFloor)
231 bool & hasWarnedBefore)
235 double sumCoeff = 0.;
239 const double coefVal = coef !=
nullptr ? coef->
getVal() : (1. - sumCoeff);
242 if (coef ==
nullptr && (coefVal < 0 || coefVal > 1.)) {
243 if (!hasWarnedBefore) {
245 <<
") WARNING: sum of FUNC coefficients not in range [0-1], value="
246 << sumCoeff <<
". This means that the PDF is not properly normalised."
247 <<
" If the PDF was meant to be extended, provide as many coefficients as functions." << std::endl;
248 hasWarnedBefore =
true;
254 if (func->isSelectedComp()) {
255 value += func->getVal() * coefVal;
277 for (
unsigned int j = 0; j < nEvents; ++j) {
281 double sumCoeff = 0.;
285 const double coefVal = coef !=
nullptr ? dataMap.
at(coef)[0] : (1. - sumCoeff);
287 if (func->isSelectedComp()) {
288 auto funcValues = dataMap.
at(func);
289 if(funcValues.size() == 1) {
290 for (
unsigned int j = 0; j < nEvents; ++j) {
291 output[j] += funcValues[0] * coefVal;
294 for (
unsigned int j = 0; j < nEvents; ++j) {
295 output[j] += funcValues[j] * coefVal;
301 if (coef ==
nullptr && (coefVal < 0 || coefVal > 1.)) {
303 coutW(Eval) <<
"RooRealSumPdf::evaluateSpan(" <<
GetName()
304 <<
") WARNING: sum of FUNC coefficients not in range [0-1], value="
305 << 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 ;
317 for (
unsigned int j = 0; j < nEvents; ++j) {
333 if (func.observableOverlaps(nset, coef)) {
335 <<
"): ERROR: coefficient " << coef.GetName()
336 <<
" and FUNC " << func.GetName() <<
" have one or more observables in common" << std::endl;
339 if (coef.dependsOn(*nset)) {
341 <<
"): ERROR coefficient " << coef.GetName()
342 <<
" depends on one or more of the following observables" ; nset->
Print(
"1") ;
369 const RooArgSet* normSet2,
const char* rangeName)
const
378 const RooArgSet* normSet2,
const char* rangeName)
381 if (allVars.
empty())
return 0 ;
385 analVars.
add(allVars) ;
386 std::unique_ptr<RooArgSet> normSet;
388 normSet = std::make_unique<RooArgSet>();
394 Int_t sterileIdx(-1) ;
406 const auto func =
static_cast<RooAbsReal*
>(elm);
408 std::unique_ptr<RooAbsReal> funcInt{func->
createIntegral(analVars,rangeName)};
409 if(
auto funcRealInt =
dynamic_cast<RooRealIntegral*
>(funcInt.get())) funcRealInt->setAllowComponentSelection(
true);
410 cache->_funcIntList.addOwned(std::move(funcInt));
411 if (normSet && !normSet->empty()) {
412 cache->_funcNormList.addOwned(std::unique_ptr<RooAbsReal>{func->createIntegral(*normSet)});
438 bool hasWarnedBefore)
441 if (code==0)
return caller.
getVal(normSet2) ;
464 auto funcIntIt = cache->_funcIntList.begin();
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 ==0 || 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 ==0 || 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 << endl ;
504 if (normSet2 && normSet2->
getSize()>0) {
508 auto funcNormIter = cache->_funcNormList.begin();
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;
555 std::list<double>* sumBinB =
nullptr;
556 bool needClean(
false) ;
559 for (
auto * func : static_range_cast<RooAbsReal*>(
funcList)) {
561 list<double>* funcBinB = func->binBoundaries(obs,xlo,xhi) ;
570 std::list<double>* newSumBinB =
new list<double>(sumBinB->size()+funcBinB->size()) ;
573 merge(funcBinB->begin(),funcBinB->end(),sumBinB->begin(),sumBinB->end(),newSumBinB->begin()) ;
578 sumBinB = newSumBinB ;
586 list<double>::iterator new_end = unique(sumBinB->begin(),sumBinB->end()) ;
587 sumBinB->erase(new_end,sumBinB->end()) ;
604 for (
auto* func : static_range_cast<RooAbsReal*>(
funcList)) {
606 if (func->dependsOn(obs) && !func->isBinnedDistribution(obs)) {
625 std::list<double>* sumHint =
nullptr;
626 bool needClean(
false) ;
643 auto* newSumHint =
new std::list<double>(sumHint->size()+funcHint->size()) ;
649 merge(funcHint->begin(),funcHint->end(),sumHint->begin(),sumHint->end(),newSumHint->begin()) ;
653 sumHint = newSumHint ;
661 sumHint->erase(std::unique(sumHint->begin(),sumHint->end()), sumHint->end()) ;
682 if (sarg->canNodeBeCached()==
Always) {
683 trackNodes.
add(*sarg) ;
714 const auto func = *(funcIter++);
715 os << coef->GetName() <<
" * " << func->GetName();
719 os <<
" + [%] * " << (*funcIter)->GetName() ;
729 os << func->GetName() ;
736std::unique_ptr<RooAbsArg>
742 std::unique_ptr<RooAbsPdf> pdfClone(
static_cast<RooAbsPdf *
>(this->
Clone()));
744 if (ctx.
likelihoodMode() && pdfClone->getAttribute(
"BinnedLikelihood")) {
753 pdfClone->setAttribute(
"BinnedLikelihoodActive");
764 pdfClone->setAttribute(
"BinnedLikelihoodActiveYields");
772 pdfClone->getObservables(&normSet, depList);
774 auto newArg = std::make_unique<RooNormalizedPdf>(*pdfClone, depList);
778 for (
RooAbsArg *server : newArg->servers()) {
782 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...
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.
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
const char * normRange() 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...
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 ...
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 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...
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 setBinnedLikelihoodMode(bool flag)
void markAsCompiled(RooAbsArg &arg) const
void compileServers(RooAbsArg &arg, RooArgSet const &normSet)
bool likelihoodMode() const
bool binWidthFuncFlag() const
RooSpan< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=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.
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.
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.
__roodevice__ static __roohost__ double packFloatIntoNaN(float payload)
Pack float into mantissa of a NaN.