56using std::endl, std::ostream;
64 : _refCoefNorm(
"!refCoefNorm",
"Reference coefficient normalization set", this, false, false),
65 _projCacheMgr(this, 10),
66 _intCacheMgr(this, 10),
67 _coefErrCount(_errorCount)
83 _refCoefNorm(
"!refCoefNorm",
"Reference coefficient normalization set",this,false,false),
84 _projCacheMgr(this,10),
85 _intCacheMgr(this,10),
87 _pdfList(
"!pdfs",
"List of PDFs",this),
88 _coefList(
"!coefficients",
"List of coefficients",this)
91 if (inPdfList.
size() > inCoefList.
size() + 1 || inPdfList.
size() < inCoefList.
size()) {
92 std::stringstream msgSs;
93 msgSs <<
"RooAddModel::RooAddModel(" << ownName
94 <<
") number of pdfs and coefficients inconsistent, must have Npdf=Ncoef or Npdf=Ncoef+1";
95 const std::string msgStr = msgSs.str();
96 coutE(InputArguments) << msgStr <<
"\n";
97 throw std::runtime_error(msgStr);
102 for (
auto const &coef : inCoefList) {
103 auto pdf = inPdfList.
at(i);
105 std::stringstream msgSs;
106 msgSs <<
"RooAddModel::RooAddModel(" << ownName
107 <<
") number of pdfs and coefficients inconsistent, must have Npdf=Ncoef or Npdf=Ncoef+1";
108 const std::string msgStr = msgSs.str();
109 coutE(InputArguments) << msgStr <<
"\n";
110 throw std::runtime_error(msgStr);
113 coutE(InputArguments) <<
"RooAddModel::RooAddModel(" << ownName
114 <<
") encountered and undefined coefficient, ignored\n";
118 auto coefName = coef->GetName();
119 coutE(InputArguments) <<
"RooAddModel::RooAddModel(" << ownName <<
") coefficient "
120 << (coefName !=
nullptr ? coefName :
"") <<
" is not of type RooAbsReal, ignored\n";
124 coutE(InputArguments) <<
"RooAddModel::RooAddModel(" << ownName <<
") pdf "
125 << (pdf->GetName() ? pdf->GetName() :
"") <<
" is not of type RooAbsPdf, ignored\n";
133 if (i < inPdfList.
size()) {
134 auto pdf = inPdfList.
at(i);
136 std::stringstream msgSs;
137 msgSs <<
"RooAddModel::RooAddModel(" << ownName <<
") last pdf " << (pdf->GetName() ? pdf->GetName() :
"")
138 <<
" is not of type RooAbsPdf, fatal error";
139 const std::string msgStr = msgSs.str();
140 coutE(InputArguments) << msgStr <<
"\n";
141 throw std::runtime_error(msgStr);
160 _refCoefNorm(
"!refCoefNorm", this, other._refCoefNorm),
161 _refCoefRangeName((
TNamed *)other._refCoefRangeName),
162 _projCacheMgr(other._projCacheMgr, this),
163 _intCacheMgr(other._intCacheMgr, this),
164 _codeReg(other._codeReg),
165 _pdfList(
"!pdfs", this, other._pdfList),
166 _coefList(
"!coefficients", this, other._coefList),
167 _haveLastCoef(other._haveLastCoef),
168 _allExtendable(other._allExtendable),
169 _coefErrCount(_errorCount)
187 if (refCoefNorm.
empty()) {
228 coutE(InputArguments) <<
"RooAddModel::convolution(" <<
GetName()
229 <<
") convolution parameter of basis function and PDF don't match" << endl ;
232 inBasis->
Print(
"v") ;
237 newName.
Append(
"_conv_") ;
244 newTitle.
Append(
" convoluted with basis function ") ;
252 modelList.
add(*conv) ;
257 theCoefList.
add(*coef) ;
261 for (std::set<std::string>::const_iterator attrIt =
_boolAttrib.begin();
265 for (std::map<std::string,std::string>::const_iterator attrIt =
_stringAttrib.begin();
291 }
else if (subCode==0) {
364 double pdfVal = pdf->getVal(nset) ;
366 if (pdf->isSelectedComp()) {
368 cxcoutD(Eval) <<
"RooAddModel::evaluate(" <<
GetName() <<
") value += ["
369 << pdf->GetName() <<
"] " << pdfVal <<
" * " <<
_coefCache[i] <<
" / " << snormVal << endl ;
390 if (coefVals.size() > 1) {
392 throw std::runtime_error(
"The RooAddPdf doesn't support per-event coefficients in CUDA mode yet!");
400 std::vector<std::span<const double>> pdfs;
401 std::vector<double> coefs;
405 for (
unsigned int pdfNo = 0; pdfNo <
_pdfList.
size(); ++pdfNo) {
407 if (pdf->isSelectedComp()) {
408 pdfs.push_back(ctx.
at(pdf));
441 if (pdf->observableOverlaps(nset,*coef)) {
442 coutE(InputArguments) <<
"RooAddModel::checkObservables(" <<
GetName() <<
"): ERROR: coefficient " << coef->
GetName()
443 <<
" and PDF " << pdf->GetName() <<
" have one or more dependents in common" << endl ;
456 const RooArgSet* normSet,
const char* rangeName)
const
461 analVars.
add(allVars) ;
479 Int_t sterileIdx(-1) ;
496 cache->
_intList.
addOwned(std::unique_ptr<RooAbsReal>{model->createIntegral(*iset,nset,
nullptr,isetRangeName)});
524 if (cache==
nullptr) {
547 for (
const auto obj : *compIntList) {
548 auto pdfInt =
static_cast<const RooAbsReal*
>(obj);
551 double intVal = pdfInt->getVal(nset) ;
553 cxcoutD(Eval) <<
"RooAddModel::evaluate(" <<
GetName() <<
") value += ["
554 << pdfInt->GetName() <<
"] " << intVal <<
" * " <<
_coefCache[i] <<
" / " << snormVal << endl ;
571 double expectedTotal(0.0);
578 expectedTotal += pdf->expectedEvents(nset) ;
586 expectedTotal += coef->getVal() ;
590 return expectedTotal;
636 const RooArgSet* auxProto,
bool verbose)
const
651 if (!pdf->isDirectGenSafe(arg)) {
669 if (pdf->getGenerator(directVars,tmp)==0) {
715 os << coef->GetName() <<
" * " << pdf->GetName() ;
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
double suppNormVal(std::size_t idx) const
Common abstract base class for objects that represent a value and a "shape" in RooFit.
void Print(Option_t *options=nullptr) const override
Print the object to the defaultPrintStream().
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
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.
std::set< std::string > _boolAttrib
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
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.
Abstract base class for objects to be stored in RooAbsCache cache manager objects.
const char * GetName() const override
Returns name of object.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
Abstract base class for generator contexts of RooAbsPdf objects.
Abstract interface for all probability density functions.
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)
Int_t _errorCount
Number of errors remaining to print.
const char * normRange() const
static Int_t _verboseEval
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.
bool _forceNumInt
Force numerical integration if flag set.
virtual void doEval(RooFit::EvalContext &) const
Base function for computing multiple values of a RooAbsReal.
static std::unique_ptr< RooAbsGenContext > create(const Pdf_t &pdf, const RooArgSet &vars, const RooDataSet *prototype, const RooArgSet *auxProto, bool verbose)
Returns a RooAddGenContext if possible, or, if the RooAddGenContext doesn't support this particular R...
static void updateCoefficients(RooAbsPdf const &addPdf, std::vector< double > &coefCache, RooArgList const &pdfList, bool haveLastCoef, AddCacheElem &cache, const RooArgSet *nset, RooArgSet const &refCoefNormSet, bool allExtendable, int &coefErrCount)
Update the RooAddPdf coefficients for a given normalization set and projection configuration.
RooArgList containedArgs(Action) override
List all RooAbsArg derived contents in this cache element.
RooArgList _intList
List of component integrals.
RooAddModel is an efficient implementation of a sum of PDFs of the form.
RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype=nullptr, const RooArgSet *auxProto=nullptr, bool verbose=false) const override
Return specialized context to efficiently generate toy events from RooAddModels.
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooAddModel to more intuitively reflect the contents of the pro...
RooObjCacheManager _projCacheMgr
! Manager of cache with coefficient projections and transformations
void getCompIntList(const RooArgSet *nset, const RooArgSet *iset, pRooArgList &compIntList, Int_t &code, const char *isetRangeName) const
Check if this configuration was created before.
void selectNormalization(const RooArgSet *depSet=nullptr, bool force=false) override
Interface function used by test statistics to freeze choice of observables for interpretation of frac...
RooSetProxy _refCoefNorm
! Reference observable set for coefficient interpretation
bool _allExtendable
Flag indicating if all PDF components are extendable.
Int_t _coefErrCount
! Coefficient error counter
RooArgSet _ownedComps
! Owned components
RooListProxy _coefList
List of coefficients.
void selectNormalizationRange(const char *rangeName=nullptr, bool force=false) override
Interface function used by test statistics to freeze choice of range for interpretation of fraction c...
Int_t basisCode(const char *name) const override
Return code for basis function representing by 'name' string.
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Return analytical integral defined by given scenario code.
RooResolutionModel * convolution(RooFormulaVar *basis, RooAbsArg *owner) const override
Instantiate a clone of this resolution model representing a convolution with given basis function.
void doEval(RooFit::EvalContext &) const override
Base function for computing multiple values of a RooAbsReal.
bool checkObservables(const RooArgSet *nset) const override
Check if PDF is valid for given normalization set.
void generateEvent(Int_t code) override
This function should never be called as RooAddModel implements a custom generator context.
bool _haveLastCoef
Flag indicating if last PDFs coefficient was supplied in the constructor.
double expectedEvents(const RooArgSet *nset) const override
Return expected number of events for extended likelihood calculation, which is the sum of all coeffic...
RooListProxy _pdfList
List of component PDFs.
RooObjCacheManager _intCacheMgr
! Manager of cache with integrals
void resetErrorCounters(Int_t resetValue=10) override
Reset error counter to given value, limiting the number of future error messages for this pdf to 'res...
void fixCoefNormalization(const RooArgSet &refCoefNorm)
By default the interpretation of the fraction coefficients is performed in the contextual choice of o...
void fixCoefRange(const char *rangeName)
By default the interpretation of the fraction coefficients is performed in the default range.
TNamed * _refCoefRangeName
! Reference range name for coefficient interpretation
std::vector< double > _coefCache
! Transient cache with transformed values of coefficients
double evaluate() const override
Calculate the current value.
void updateCoefficients(AddCacheElem &cache, const RooArgSet *nset) const
Update the coefficient values in the given cache element: calculate new remainder fraction,...
bool isDirectGenSafe(const RooAbsArg &arg) const override
Direct generation is safe if all components say so.
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const override
Return pseud-code that indicates if all components can do internal generation (1) or not (0)
AddCacheElem * getProjCache(const RooArgSet *nset, const RooArgSet *iset=nullptr) const
Retrieve cache element with for calculation of p.d.f value with normalization set nset and integrated...
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Variant of getAnalyticalIntegral that is also passed the normalization set that should be applied to ...
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
Return pointer to contained argument.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Minimal configuration struct to steer the evaluation of a single node with the RooBatchCompute librar...
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...
void reset()
Clear the cache.
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 removeAll() override
Remove all argument inset using remove(const RooAbsArg&).
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...
Container class to hold unbinned data.
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::span< double > output()
RooBatchCompute::Config config(RooAbsArg const *arg) const
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.
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
Dependent/convolution variable.
The TNamed class is the base class for all named ROOT classes.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
TString & Append(const char *cs)
void compute(Config cfg, Computer comp, std::span< double > output, VarSpan vars, ArgSpan extraArgs={})