64 _refCoefNorm(
"!refCoefNorm",
"Reference coefficient normalization set",this,false,false),
65 _projCacheMgr(this,10),
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),
93 if (inPdfList.
size() > inCoefList.
size() + 1 || inPdfList.
size() < inCoefList.
size()) {
94 std::stringstream msgSs;
95 msgSs <<
"RooAddModel::RooAddModel(" << ownName
96 <<
") number of pdfs and coefficients inconsistent, must have Npdf=Ncoef or Npdf=Ncoef+1";
97 const std::string msgStr = msgSs.str();
98 coutE(InputArguments) << msgStr <<
"\n";
99 throw std::runtime_error(msgStr);
104 for (
auto const &coef : inCoefList) {
105 auto pdf = inPdfList.
at(i);
107 std::stringstream msgSs;
108 msgSs <<
"RooAddModel::RooAddModel(" << ownName
109 <<
") number of pdfs and coefficients inconsistent, must have Npdf=Ncoef or Npdf=Ncoef+1";
110 const std::string msgStr = msgSs.str();
111 coutE(InputArguments) << msgStr <<
"\n";
112 throw std::runtime_error(msgStr);
115 coutE(InputArguments) <<
"RooAddModel::RooAddModel(" << ownName
116 <<
") encountered and undefined coefficient, ignored\n";
120 auto coefName = coef->GetName();
121 coutE(InputArguments) <<
"RooAddModel::RooAddModel(" << ownName <<
") coefficient "
122 << (coefName !=
nullptr ? coefName :
"") <<
" is not of type RooAbsReal, ignored\n";
126 coutE(InputArguments) <<
"RooAddModel::RooAddModel(" << ownName <<
") pdf "
127 << (pdf->GetName() ? pdf->GetName() :
"") <<
" is not of type RooAbsPdf, ignored\n";
135 if (i < inPdfList.
size()) {
136 auto pdf = inPdfList.
at(i);
138 std::stringstream msgSs;
139 msgSs <<
"RooAddModel::RooAddModel(" << ownName <<
") last pdf " << (pdf->GetName() ? pdf->GetName() :
"")
140 <<
" is not of type RooAbsPdf, fatal error";
141 const std::string msgStr = msgSs.str();
142 coutE(InputArguments) << msgStr <<
"\n";
143 throw std::runtime_error(msgStr);
162 _refCoefNorm(
"!refCoefNorm",this,other._refCoefNorm),
163 _refCoefRangeName((
TNamed*)other._refCoefRangeName),
164 _projCacheMgr(other._projCacheMgr,this),
165 _intCacheMgr(other._intCacheMgr,this),
166 _codeReg(other._codeReg),
167 _pdfList(
"!pdfs",this,other._pdfList),
168 _coefList(
"!coefficients",this,other._coefList),
169 _haveLastCoef(other._haveLastCoef),
170 _allExtendable(other._allExtendable)
189 if (refCoefNorm.
empty()) {
230 coutE(InputArguments) <<
"RooAddModel::convolution(" <<
GetName()
231 <<
") convolution parameter of basis function and PDF don't match" << endl ;
234 inBasis->
Print(
"v") ;
239 newName.
Append(
"_conv_") ;
246 newTitle.
Append(
" convoluted with basis function ") ;
254 modelList.
add(*conv) ;
259 theCoefList.
add(*coef) ;
263 for (std::set<std::string>::const_iterator attrIt =
_boolAttrib.begin();
267 for (std::map<std::string,std::string>::const_iterator attrIt =
_stringAttrib.begin();
285 bool first(
true), code(
false) ;
292 }
else if (subCode==0) {
365 double pdfVal = pdf->getVal(nset) ;
367 if (pdf->isSelectedComp()) {
369 cxcoutD(Eval) <<
"RooAddModel::evaluate(" <<
GetName() <<
") value += ["
370 << pdf->GetName() <<
"] " << pdfVal <<
" * " <<
_coefCache[i] <<
" / " << snormVal << endl ;
391 if (coefVals.size() > 1) {
393 throw std::runtime_error(
"The RooAddPdf doesn't support per-event coefficients in CUDA mode yet!");
406 for (
unsigned int pdfNo = 0; pdfNo <
_pdfList.
size(); ++pdfNo) {
408 if (pdf->isSelectedComp()) {
409 pdfs.push_back(dataMap.
at(pdf));
442 if (pdf->observableOverlaps(nset,*coef)) {
443 coutE(InputArguments) <<
"RooAddModel::checkObservables(" <<
GetName() <<
"): ERROR: coefficient " << coef->
GetName()
444 <<
" and PDF " << pdf->GetName() <<
" have one or more dependents in common" << endl ;
457 const RooArgSet* normSet,
const char* rangeName)
const
462 analVars.
add(allVars) ;
480 Int_t sterileIdx(-1) ;
497 cache->
_intList.
addOwned(std::unique_ptr<RooAbsReal>{model->createIntegral(*iset,nset,
nullptr,isetRangeName)});
525 if (cache==
nullptr) {
548 for (
const auto obj : *compIntList) {
549 auto pdfInt =
static_cast<const RooAbsReal*
>(obj);
552 double intVal = pdfInt->getVal(nset) ;
554 cxcoutD(Eval) <<
"RooAddModel::evaluate(" <<
GetName() <<
") value += ["
555 << pdfInt->GetName() <<
"] " << intVal <<
" * " <<
_coefCache[i] <<
" / " << snormVal << endl ;
572 double expectedTotal(0.0);
579 expectedTotal += pdf->expectedEvents(nset) ;
587 expectedTotal += coef->getVal() ;
591 return expectedTotal;
637 const RooArgSet* auxProto,
bool verbose)
const
652 if (!pdf->isDirectGenSafe(arg)) {
670 if (pdf->getGenerator(directVars,tmp)==0) {
716 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.
Int_t getSize() const
Return the number of elements in the collection.
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 computeBatch(double *output, size_t size, RooFit::Detail::DataMap const &) 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.
void computeBatch(double *output, size_t nEvents, RooFit::Detail::DataMap const &) const override
Base function for computing multiple values of a RooAbsReal.
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.
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 ctor.
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...
RooDataSet is a container class to hold unbinned data.
RooBatchCompute::Config config(RooAbsArg const *arg) const
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
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)
std::vector< std::span< const double > > VarVector
std::vector< double > ArgVector
void compute(Config cfg, Computer comp, RestrictArr output, size_t size, const VarVector &vars, ArgVector &extraArgs)