66 _refCoefNorm(
"!refCoefNorm",
"Reference coefficient normalization set",this,
kFALSE,
kFALSE),
69 _projCacheMgr(this,10),
70 _intCacheMgr(this,10),
92 _refCoefNorm(
"!refCoefNorm",
"Reference coefficient normalization set",this,
kFALSE,
kFALSE),
95 _projCacheMgr(this,10),
96 _intCacheMgr(this,10),
98 _pdfList(
"!pdfs",
"List of PDFs",this),
99 _coefList(
"!coefficients",
"List of coefficients",this),
104 std::stringstream msgSs;
105 msgSs <<
"RooAddModel::RooAddModel(" <<
GetName()
106 <<
") number of pdfs and coefficients inconsistent, must have Npdf=Ncoef or Npdf=Ncoef+1";
107 const std::string msgStr = msgSs.str();
108 coutE(InputArguments) << msgStr << endl;
109 throw std::runtime_error(msgStr);
115 for(
auto const& coef : inCoefList) {
116 auto pdf = pdfIter.
next() ;
118 std::stringstream msgSs;
119 msgSs <<
"RooAddModel::RooAddModel(" <<
GetName()
120 <<
") number of pdfs and coefficients inconsistent, must have Npdf=Ncoef or Npdf=Ncoef+1";
121 const std::string msgStr = msgSs.str();
122 coutE(InputArguments) << msgStr << endl;
123 throw std::runtime_error(msgStr);
126 coutE(InputArguments) <<
"RooAddModel::RooAddModel(" <<
GetName() <<
") coefficient " << coef->GetName() <<
" is not of type RooAbsReal, ignored" << endl ;
130 coutE(InputArguments) <<
"RooAddModel::RooAddModel(" <<
GetName() <<
") pdf " << pdf->GetName() <<
" is not of type RooAbsPdf, ignored" << endl ;
137 if (
auto pdf = pdfIter.next()) {
139 std::stringstream msgSs;
140 msgSs <<
"RooAddModel::RooAddModel(" <<
GetName() <<
") last pdf " << pdf->GetName() <<
" is not of type RooAbsPdf, fatal error";
141 const std::string msgStr = msgSs.str();
142 coutE(InputArguments) << msgStr << endl;
143 throw std::runtime_error(msgStr);
166 _refCoefNorm(
"!refCoefNorm",this,other._refCoefNorm),
167 _refCoefRangeName((
TNamed*)other._refCoefRangeName),
168 _projectCoefs(other._projectCoefs),
169 _projCacheMgr(other._projCacheMgr,this),
170 _intCacheMgr(other._intCacheMgr,this),
171 _codeReg(other._codeReg),
172 _pdfList(
"!pdfs",this,other._pdfList),
173 _coefList(
"!coefficients",this,other._coefList),
174 _haveLastCoef(other._haveLastCoef),
175 _allExtendable(other._allExtendable)
205 if (refCoefNorm.
getSize()==0) {
249 coutE(InputArguments) <<
"RooAddModel::convolution(" <<
GetName()
250 <<
") convolution parameter of basis function and PDF don't match" << endl ;
253 inBasis->
Print(
"v") ;
258 newName.
Append(
"_conv_") ;
265 newTitle.
Append(
" convoluted with basis function ") ;
273 modelList.
add(*conv) ;
278 theCoefList.
add(*coef) ;
282 for (std::set<std::string>::const_iterator attrIt =
_boolAttrib.begin();
286 for (std::map<std::string,std::string>::const_iterator attrIt =
_stringAttrib.begin();
311 }
else if (subCode==0) {
356 RooArgSet* pdfDeps = pdf->getObservables(nset) ;
364 RooArgSet* coefDeps = coef->getObservables(nset);
372 name.Append(pdf->GetName()) ;
373 name.Append(
"_SupNorm") ;
377 snorm =
new RooRealVar(
name,
"Unit Supplemental normalization integral",1.0) ;
385 cxcoutD(Caching) <<
"RooAddModel::syncSuppNormList(" <<
GetName() <<
") synching supplemental normalization list for norm" << (nset?*nset:
RooArgSet()) << endl ;
407 coutI(Caching) <<
"RooAddModel::syncCoefProjList(" <<
GetName() <<
") creating coefficient projection integrals" << endl ;
408 ccoutI(Caching) <<
" from current normalization: " ; nset2->
Print(
"1") ;
409 ccoutI(Caching) <<
" with current range: " << (rangeName?rangeName:
"<none>") << endl ;
415 const auto thePdf =
static_cast<RooAbsPdf*
>(obj);
425 name.Append(thePdf->GetName()) ;
426 name.Append(
"_ProjectNorm") ;
427 pdfProj =
new RooRealVar(
name,
"Unit Projection normalization integral",1.0) ;
441 name.Append(thePdf->GetName()) ;
442 name.Append(
"_ProjSupNorm") ;
447 snorm =
new RooRealVar(
name,
"Unit Projection Supplemental normalization integral",1.0) ;
459 theName.
Append(thePdf->GetName()) ;
460 theName.
Append(
"_RangeNorm1") ;
461 rangeProj1 =
new RooRealVar(theName,
"Unit range normalization integral",1.0) ;
474 theName.
Append(thePdf->GetName()) ;
475 theName.
Append(
"_RangeNorm2") ;
476 rangeProj2 =
new RooRealVar(theName,
"Unit range normalization integral",1.0) ;
515 coutW(Eval) <<
"RooAddModel::updateCoefCache(" <<
GetName() <<
") WARNING: total number of expected events is 0" << endl ;
549 coutW(Eval) <<
"RooAddModel::updateCoefCache(" <<
GetName()
550 <<
" WARNING: sum of PDF coefficients not in range [0-1], value="
551 << 1-lastCoef << endl ;
553 coutW(Eval) <<
" (no more will be printed)" << endl ;
579 <<
"sn = " << sn->
GetName() << endl
580 <<
"r1 = " << r1->
GetName() << endl
581 <<
"r2 = " << r2->
GetName() << endl ;
622 Double_t pdfVal = pdf->getVal(nset) ;
624 if (pdf->isSelectedComp()) {
626 cxcoutD(Eval) <<
"RooAddModel::evaluate(" <<
GetName() <<
") value += ["
627 << pdf->GetName() <<
"] " << pdfVal <<
" * " <<
_coefCache[i] <<
" / " << snormVal << endl ;
663 if (pdf->observableOverlaps(nset,*coef)) {
664 coutE(InputArguments) <<
"RooAddModel::checkObservables(" <<
GetName() <<
"): ERROR: coefficient " << coef->
GetName()
665 <<
" and PDF " << pdf->GetName() <<
" have one or more dependents in common" << endl ;
678 const RooArgSet* normSet,
const char* rangeName)
const
683 analVars.
add(allVars) ;
701 Int_t sterileIdx(-1) ;
770 for (
const auto obj : *compIntList) {
771 auto pdfInt =
static_cast<const RooAbsReal*
>(obj);
774 Double_t intVal = pdfInt->getVal(nset) ;
776 cxcoutD(Eval) <<
"RooAddModel::evaluate(" <<
GetName() <<
") value += ["
777 << pdfInt->GetName() <<
"] " << intVal <<
" * " <<
_coefCache[i] <<
" / " << snormVal << endl ;
801 expectedTotal += pdf->expectedEvents(nset) ;
809 expectedTotal += coef->getVal() ;
813 return expectedTotal;
874 if (!pdf->isDirectGenSafe(arg)) {
892 if (pdf->getGenerator(directVars,tmp)==0) {
956 os << coef->GetName() <<
" * " << pdf->GetName() ;
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Given a set of possible observables, return the observables that this PDF depends on.
void printCompactTree(const char *indent="", const char *fileName=0, const char *namePat=0, RooAbsArg *client=0)
Print tree structure of expression tree on stdout, or to file if filename is specified.
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
std::set< std::string > _boolAttrib
virtual void Print(Option_t *options=0) const
Print the object to the defaultPrintStream().
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
void setOperMode(OperMode mode, Bool_t recurseADirty=kTRUE)
Set the operation mode of this node.
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...
std::map< std::string, std::string > _stringAttrib
RooAbsArg * findServer(const char *name) const
Return server of this with name name. Returns nullptr if not found.
OperMode operMode() const
Query the operation mode of this node.
RooAbsCacheElement is the abstract base class for objects to be stored in RooAbsCache cache manager o...
RooFIter fwdIterator() const
One-time forward iterator.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Add an argument and transfer the ownership to the collection.
Storage_t::size_type size() const
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
Bool_t equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically-named contents.
const char * GetName() const
Returns name of object.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
RooAbsGenContext is the abstract base class for generator contexts of RooAbsPdf objects.
virtual void resetErrorCounters(Int_t resetValue=10)
Reset error counter to given value, limiting the number of future error messages for this pdf to 'res...
RooArgSet const * _normSet
Normalization integral (owned by _normMgr)
friend class RooRealIntegral
static Int_t _verboseEval
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
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 listed in ...
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Transiet cache with transformed values of coefficients.
RooArgList _rangeProjList
RooArgList _refRangeProjList
virtual RooArgList containedArgs(Action)
List all RooAbsArg derived contents in this cache element.
virtual RooArgList containedArgs(Action)
List all RooAbsArg derived contents in this cache element.
RooAddModel is an efficient implementation of a sum of PDFs of the form.
Double_t evaluate() const
Calculate the current value.
friend class RooAddGenContext
RooObjCacheManager _projCacheMgr
Double_t analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=0) const
Return analytical integral defined by given scenario code.
CacheElem * getProjCache(const RooArgSet *nset, const RooArgSet *iset=0, const char *rangeName=0) const
Manager of cache with coefficient projections and transformations.
virtual RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype=0, const RooArgSet *auxProto=0, Bool_t verbose=kFALSE) const
Return specialized context to efficiently generate toy events from RooAddModels.
void getCompIntList(const RooArgSet *nset, const RooArgSet *iset, pRooArgList &compIntList, Int_t &code, const char *isetRangeName) const
Check if this configuration was created before.
virtual RooResolutionModel * convolution(RooFormulaVar *basis, RooAbsArg *owner) const
Instantiate a clone of this resolution model representing a convolution with given basis function.
virtual void selectNormalizationRange(const char *rangeName=0, Bool_t force=kFALSE)
Interface function used by test statistics to freeze choice of range for interpretation of fraction c...
void updateCoefficients(CacheElem &cache, const RooArgSet *nset) const
Update the coefficient values in the given cache element: calculate new remainder fraction,...
RooArgSet _ownedComps
Coefficient error counter.
virtual ~RooAddModel()
Destructor.
virtual void resetErrorCounters(Int_t resetValue=10)
Reset error counter to given value, limiting the number of future error messages for this pdf to 'res...
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=0) const
Variant of getAnalyticalIntegral that is also passed the normalization set that should be applied to ...
virtual Double_t expectedEvents(const RooArgSet *nset) const
Return expected number of events for extended likelihood calculation, which is the sum of all coeffic...
RooListProxy _pdfList
Registry of component analytical integration codes.
RooObjCacheManager _intCacheMgr
void fixCoefNormalization(const RooArgSet &refCoefNorm)
By default the interpretation of the fraction coefficients is performed in the contextual choice of o...
virtual void selectNormalization(const RooArgSet *depSet=0, Bool_t force=kFALSE)
Interface function used by test statistics to freeze choice of observables for interpretation of frac...
void generateEvent(Int_t code)
This function should never be called as RooAddModel implements a custom generator context.
Bool_t _projectCoefs
Reference range name for coefficient interpreation.
void fixCoefRange(const char *rangeName)
By default the interpretation of the fraction coefficients is performed in the default range.
TNamed * _refCoefRangeName
Reference observable set for coefficient interpretation.
virtual Bool_t checkObservables(const RooArgSet *nset) const
Check if PDF is valid for given normalization set.
void printMetaArgs(std::ostream &os) const
Customized printing of arguments of a RooAddModel to more intuitively reflect the contents of the pro...
Bool_t _haveLastCoef
List of supplemental normalization factors.
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const
Return pseud-code that indicates if all components can do internal generation (1) or not (0)
Bool_t isDirectGenSafe(const RooAbsArg &arg) const
Direct generation is safe if all components say so.
virtual Int_t basisCode(const char *name) const
Return code for basis function representing by 'name' string.
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.
RooAbsArg * absArg() const
RooArgSet is a container object that can hold multiple RooAbsArg objects.
T * getObj(const RooArgSet *nset, Int_t *sterileIndex=0, const TNamed *isetRangeName=0)
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.
void reset()
Clear the cache.
Int_t setObj(const RooArgSet *nset, T *obj, const TNamed *isetRangeName=0)
RooDataSet is a container class to hold unbinned data.
RooAbsArg * next()
Return next element or nullptr if at end.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Reimplementation of standard RooArgList::add()
static const char * str(const TNamed *ptr)
Return C++ string corresponding to given TNamed pointer.
static const TNamed * ptr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer,...
static RooConstVar & value(Double_t value)
Return a constant value object with given value.
RooRealVar represents a variable that can be changed from the outside.
RooResolutionModel is the base class for PDFs that represent a resolution model that can be convolute...
virtual void changeBasis(RooFormulaVar *basis)
Change the basis function we convolute with.
virtual RooResolutionModel * convolution(RooFormulaVar *basis, RooAbsArg *owner) const
Instantiate a clone of this resolution model representing a convolution with given basis function.
RooTemplateProxy< RooAbsRealLValue > x
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...
virtual void removeAll() override
Remove all argument inset using remove(const RooAbsArg&).
The TNamed class is the base class for all named ROOT classes.
virtual const char * GetTitle() const
Returns title of object.
virtual const char * GetName() const
Returns name of object.
TString & Append(const char *cs)