56using std::endl, std::ostream;
63 : _refCoefNorm(
"!refCoefNorm",
"Reference coefficient normalization set", this, false, false),
64 _projCacheMgr(this, 10),
65 _intCacheMgr(this, 10),
66 _coefErrCount(_errorCount)
82 _refCoefNorm(
"!refCoefNorm",
"Reference coefficient normalization set",this,false,false),
83 _projCacheMgr(this,10),
84 _intCacheMgr(this,10),
85 _pdfList(
"!pdfs",
"List of PDFs",this),
86 _coefList(
"!coefficients",
"List of coefficients",this)
89 if (inPdfList.
size() > inCoefList.
size() + 1 || inPdfList.
size() < inCoefList.
size()) {
90 std::stringstream msgSs;
91 msgSs <<
"RooAddModel::RooAddModel(" << ownName
92 <<
") number of pdfs and coefficients inconsistent, must have Npdf=Ncoef or Npdf=Ncoef+1";
93 const std::string msgStr = msgSs.str();
94 coutE(InputArguments) << msgStr <<
"\n";
95 throw std::runtime_error(msgStr);
100 for (
auto const &coef : inCoefList) {
101 auto pdf = inPdfList.
at(i);
103 std::stringstream msgSs;
104 msgSs <<
"RooAddModel::RooAddModel(" << ownName
105 <<
") number of pdfs and coefficients inconsistent, must have Npdf=Ncoef or Npdf=Ncoef+1";
106 const std::string msgStr = msgSs.str();
107 coutE(InputArguments) << msgStr <<
"\n";
108 throw std::runtime_error(msgStr);
111 coutE(InputArguments) <<
"RooAddModel::RooAddModel(" << ownName
112 <<
") encountered and undefined coefficient, ignored\n";
116 auto coefName = coef->GetName();
117 coutE(InputArguments) <<
"RooAddModel::RooAddModel(" << ownName <<
") coefficient "
118 << (coefName !=
nullptr ? coefName :
"") <<
" is not of type RooAbsReal, ignored\n";
122 coutE(InputArguments) <<
"RooAddModel::RooAddModel(" << ownName <<
") pdf "
123 << (pdf->GetName() ? pdf->GetName() :
"") <<
" is not of type RooAbsPdf, ignored\n";
131 if (i < inPdfList.
size()) {
132 auto pdf = inPdfList.
at(i);
134 std::stringstream msgSs;
135 msgSs <<
"RooAddModel::RooAddModel(" << ownName <<
") last pdf " << (pdf->GetName() ? pdf->GetName() :
"")
136 <<
" is not of type RooAbsPdf, fatal error";
137 const std::string msgStr = msgSs.str();
138 coutE(InputArguments) << msgStr <<
"\n";
139 throw std::runtime_error(msgStr);
158 _refCoefNorm(
"!refCoefNorm", this, other._refCoefNorm),
159 _refCoefRangeName((
TNamed *)other._refCoefRangeName),
160 _projCacheMgr(other._projCacheMgr, this),
161 _intCacheMgr(other._intCacheMgr, this),
162 _pdfList(
"!pdfs", this, other._pdfList),
163 _coefList(
"!coefficients", this, other._coefList),
164 _haveLastCoef(other._haveLastCoef),
165 _allExtendable(other._allExtendable),
166 _coefErrCount(_errorCount)
184 if (refCoefNorm.
empty()) {
225 coutE(InputArguments) <<
"RooAddModel::convolution(" <<
GetName()
226 <<
") convolution parameter of basis function and PDF don't match" << std::endl ;
229 inBasis->
Print(
"v") ;
234 newName.
Append(
"_conv_") ;
241 newTitle.
Append(
" convoluted with basis function ") ;
245 for (
auto *model : static_range_cast<RooResolutionModel*>(
_pdfList)) {
248 modelList.
add(*conv) ;
253 theCoefList.
add(*coef) ;
257 for (std::set<std::string>::const_iterator attrIt =
_boolAttrib.begin();
261 for (std::map<std::string,std::string>::const_iterator attrIt =
_stringAttrib.begin();
281 for (
auto *model : static_range_cast<RooResolutionModel*>(
_pdfList)) {
286 }
else if (subCode==0) {
361 for (
auto *pdf : static_range_cast<RooAbsPdf*>(
_pdfList)) {
364 snormVal = nset ? cache->suppNormVal(i) : 1.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 << std::endl ;
391 if (coefVals.size() > 1) {
393 throw std::runtime_error(
"The RooAddPdf doesn't support per-event coefficients in CUDA mode yet!");
401 std::vector<std::span<const double>> pdfs;
402 std::vector<double> coefs;
406 for (
unsigned int pdfNo = 0; pdfNo <
_pdfList.
size(); ++pdfNo) {
408 if (pdf->isSelectedComp()) {
409 pdfs.push_back(ctx.
at(pdf));
410 coefs.push_back(
_coefCache[pdfNo] / cache->suppNormVal(pdfNo));
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" << std::endl ;
457 const RooArgSet* normSet,
const char* rangeName)
const
462 analVars.
add(allVars) ;
480 Int_t sterileIdx(-1) ;
494 for (
auto *model : static_range_cast<RooResolutionModel*>(
_pdfList)) {
496 cache->
_intList.
addOwned(std::unique_ptr<RooAbsReal>{model->createIntegral(*iset,nset,
nullptr,isetRangeName)});
524 if (cache==
nullptr) {
547 for (
auto *pdfInt : static_range_cast<const RooAbsReal*>(*compIntList)) {
549 snormVal = nset ? pcache->suppNormVal(i) : 1.0 ;
550 double intVal = pdfInt->getVal(nset) ;
552 cxcoutD(Eval) <<
"RooAddModel::evaluate(" <<
GetName() <<
") value += ["
553 << pdfInt->GetName() <<
"] " << intVal <<
" * " <<
_coefCache[i] <<
" / " << snormVal << std::endl ;
570 double expectedTotal(0.0);
575 for (
auto *pdf : static_range_cast<RooAbsPdf*>(
_pdfList)) {
576 expectedTotal += pdf->expectedEvents(nset) ;
582 for (
auto *coef : static_range_cast<RooAbsReal*>(
_coefList)) {
583 expectedTotal += coef->getVal() ;
587 return expectedTotal;
633 const RooArgSet* auxProto,
bool verbose)
const
645 for (
auto *pdf : static_range_cast<RooAbsPdf*>(
_pdfList)) {
647 if (!pdf->isDirectGenSafe(arg)) {
661 for (
auto *pdf : static_range_cast<RooAbsPdf*>(
_pdfList)) {
664 if (pdf->getGenerator(directVars,tmp)==0) {
710 os << coef->GetName() <<
" * " << pdf->GetName() ;
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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().
std::map< std::string, std::string > _stringAttrib
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.
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 set with for above integral
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.
friend class AddCacheElem
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...
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.
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={})