64 _refCoefNorm(
"!refCoefNorm",
"Reference coefficient normalization set",this,false,false),
65 _projCacheMgr(this,10),
83 _refCoefNorm(
"!refCoefNorm",
"Reference coefficient normalization set",this,false,false),
85 _projCacheMgr(this,10),
86 _intCacheMgr(this,10),
88 _pdfList(
"!pdfs",
"List of PDFs",this),
89 _coefList(
"!coefficients",
"List of coefficients",this),
94 if (inPdfList.
size() > inCoefList.
size() + 1 || inPdfList.
size() < inCoefList.
size()) {
95 std::stringstream msgSs;
96 msgSs <<
"RooAddModel::RooAddModel(" << ownName
97 <<
") number of pdfs and coefficients inconsistent, must have Npdf=Ncoef or Npdf=Ncoef+1";
98 const std::string msgStr = msgSs.str();
99 coutE(InputArguments) << msgStr <<
"\n";
100 throw std::runtime_error(msgStr);
105 for (
auto const &coef : inCoefList) {
106 auto pdf = inPdfList.
at(i);
108 std::stringstream msgSs;
109 msgSs <<
"RooAddModel::RooAddModel(" << ownName
110 <<
") number of pdfs and coefficients inconsistent, must have Npdf=Ncoef or Npdf=Ncoef+1";
111 const std::string msgStr = msgSs.str();
112 coutE(InputArguments) << msgStr <<
"\n";
113 throw std::runtime_error(msgStr);
116 coutE(InputArguments) <<
"RooAddModel::RooAddModel(" << ownName
117 <<
") encountered and undefined coefficient, ignored\n";
121 auto coefName = coef->GetName();
122 coutE(InputArguments) <<
"RooAddModel::RooAddModel(" << ownName <<
") coefficient "
123 << (coefName !=
nullptr ? coefName :
"") <<
" is not of type RooAbsReal, ignored\n";
127 coutE(InputArguments) <<
"RooAddModel::RooAddModel(" << ownName <<
") pdf "
128 << (pdf->GetName() ? pdf->GetName() :
"") <<
" is not of type RooAbsPdf, ignored\n";
136 if (i < inPdfList.
size()) {
137 auto pdf = inPdfList.
at(i);
139 std::stringstream msgSs;
140 msgSs <<
"RooAddModel::RooAddModel(" << ownName <<
") last pdf " << (pdf->GetName() ? pdf->GetName() :
"")
141 <<
" is not of type RooAbsPdf, fatal error";
142 const std::string msgStr = msgSs.str();
143 coutE(InputArguments) << msgStr <<
"\n";
144 throw std::runtime_error(msgStr);
163 _refCoefNorm(
"!refCoefNorm",this,other._refCoefNorm),
164 _refCoefRangeName((
TNamed*)other._refCoefRangeName),
165 _projCacheMgr(other._projCacheMgr,this),
166 _intCacheMgr(other._intCacheMgr,this),
167 _codeReg(other._codeReg),
168 _pdfList(
"!pdfs",this,other._pdfList),
169 _coefList(
"!coefficients",this,other._coefList),
170 _haveLastCoef(other._haveLastCoef),
171 _allExtendable(other._allExtendable)
190 if (refCoefNorm.
empty()) {
231 coutE(InputArguments) <<
"RooAddModel::convolution(" <<
GetName()
232 <<
") convolution parameter of basis function and PDF don't match" << endl ;
235 inBasis->
Print(
"v") ;
240 newName.
Append(
"_conv_") ;
247 newTitle.
Append(
" convoluted with basis function ") ;
255 modelList.
add(*conv) ;
260 theCoefList.
add(*coef) ;
264 for (std::set<std::string>::const_iterator attrIt =
_boolAttrib.begin();
268 for (std::map<std::string,std::string>::const_iterator attrIt =
_stringAttrib.begin();
286 bool first(
true), code(0) ;
293 }
else if (subCode==0) {
366 double pdfVal = pdf->getVal(nset) ;
368 if (pdf->isSelectedComp()) {
370 cxcoutD(Eval) <<
"RooAddModel::evaluate(" <<
GetName() <<
") value += ["
371 << pdf->GetName() <<
"] " << pdfVal <<
" * " <<
_coefCache[i] <<
" / " << snormVal << endl ;
392 if (coefVals.size() > 1) {
394 throw std::runtime_error(
"The RooAddPdf doesn't support per-event coefficients in CUDA mode yet!");
410 for (
unsigned int pdfNo = 0; pdfNo <
_pdfList.
size(); ++pdfNo) {
412 if (pdf->isSelectedComp()) {
413 pdfs.push_back(dataMap.
at(pdf));
447 if (pdf->observableOverlaps(nset,*coef)) {
448 coutE(InputArguments) <<
"RooAddModel::checkObservables(" <<
GetName() <<
"): ERROR: coefficient " << coef->
GetName()
449 <<
" and PDF " << pdf->GetName() <<
" have one or more dependents in common" << endl ;
462 const RooArgSet* normSet,
const char* rangeName)
const
467 analVars.
add(allVars) ;
485 Int_t sterileIdx(-1) ;
502 cache->
_intList.
addOwned(std::unique_ptr<RooAbsReal>{model->createIntegral(*iset,nset,0,isetRangeName)});
553 for (
const auto obj : *compIntList) {
554 auto pdfInt =
static_cast<const RooAbsReal*
>(obj);
557 double intVal = pdfInt->getVal(nset) ;
559 cxcoutD(Eval) <<
"RooAddModel::evaluate(" <<
GetName() <<
") value += ["
560 << pdfInt->GetName() <<
"] " << intVal <<
" * " <<
_coefCache[i] <<
" / " << snormVal << endl ;
577 double expectedTotal(0.0);
584 expectedTotal += pdf->expectedEvents(nset) ;
592 expectedTotal += coef->getVal() ;
596 return expectedTotal;
642 const RooArgSet* auxProto,
bool verbose)
const
657 if (!pdf->isDirectGenSafe(arg)) {
675 if (pdf->getGenerator(directVars,tmp)==0) {
721 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
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
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.
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.
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.
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)
Int_t _errorCount
Number of errors remaining to print.
const char * normRange() const
static Int_t _verboseEval
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.
bool _forceNumInt
Force numerical integration if flag set.
virtual void computeBatch(cudaStream_t *, 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.
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
void computeBatch(cudaStream_t *, double *output, size_t nEvents, RooFit::Detail::DataMap const &) const override
Base function for computing multiple values of a RooAbsReal.
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
! Transiet 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.
virtual void compute(cudaStream_t *, Computer, RestrictArr, size_t, const VarVector &, ArgVector &)=0
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.
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.
RooSpan< 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< RooSpan< const double > > VarVector
R__EXTERN RooBatchComputeInterface * dispatchCUDA
R__EXTERN RooBatchComputeInterface * dispatchCPU
This dispatch pointer points to an implementation of the compute library, provided one has been loade...
std::vector< double > ArgVector