39using std::endl, std::ostream;
53 cxcoutI(Generation) <<
"RooProdGenContext::ctor() setting up event special generator context for product p.d.f. " << model.
GetName()
54 <<
" for generation of observable(s) " << vars ;
55 if (prototype)
ccxcoutI(Generation) <<
" with prototype data for " << *prototype->
get() ;
56 if (auxProto && !auxProto->
empty())
ccxcoutI(Generation) <<
" with auxiliary prototypes " << *auxProto ;
74 cxcoutD(Generation) <<
"RooProdGenContext::ctor() factorizing product expression in irriducible terms " ;
75 for(
auto * t : static_range_cast<RooArgSet*>(termList)) {
84 bool anyAction = true ;
88 auto termIter = termList.
begin();
89 auto impIter = impDepList.
begin();
90 auto normIter = depsList.
begin();
92 bool anyPrevAction=anyAction ;
95 if (termList.
empty()) {
99 while(termIter != termList.
end()) {
101 auto * term =
static_cast<RooArgSet*
>(*termIter);
102 auto * impDeps =
static_cast<RooArgSet*
>(*impIter);
103 auto * termDeps =
static_cast<RooArgSet*
>(*normIter);
104 if (impDeps==
nullptr || termDeps==
nullptr) {
108 cxcoutD(Generation) <<
"RooProdGenContext::ctor() analyzing product term " << *term <<
" with observable(s) " << *termDeps ;
109 if (!impDeps->empty()) {
110 ccxcoutD(Generation) <<
" which has dependence of external observable(s) " << *impDeps <<
" that to be generated first by other terms" ;
116 neededDeps.
remove(genDeps,
true,
true) ;
118 if (!neededDeps.
empty()) {
119 if (!anyPrevAction) {
120 cxcoutD(Generation) <<
"RooProdGenContext::ctor() no convergence in single term analysis loop, terminating loop and process remainder of terms as single unit " << endl ;
124 cxcoutD(Generation) <<
"RooProdGenContext::ctor() skipping this term for now because it needs imported dependents that are not generated yet" << endl ;
133 if (termDeps->empty()) {
134 cxcoutD(Generation) <<
"RooProdGenContext::ctor() term has no observables requested to be generated, removing it" << endl ;
142 depsList.
Remove(termDeps);
143 impDepList.
Remove(impDeps);
152 if (term->size()==1) {
155 auto pdf =
static_cast<RooAbsPdf*
>((*term)[0]);
157 if (!pdfDep->empty()) {
158 coutI(Generation) <<
"RooProdGenContext::ctor() creating subcontext for generation of observables " << *pdfDep <<
" from model " << pdf->GetName() << endl ;
159 std::unique_ptr<RooArgSet> auxProto2{pdf->getObservables(impDeps)};
160 _gcList.emplace_back(pdf->genContext(*pdfDep,prototype,auxProto2.
get(),verbose)) ;
164 genDeps.
add(*pdfDep) ;
169 if (!termDeps->empty()) {
177 for(
auto * pdf : static_range_cast<RooAbsPdf*>(*term)) {
181 pdfSetList.
Add(pdfSet) ;
183 if (pdfnset && !pdfnset->
empty()) {
188 fullPdfSet.
add(*pdfSet) ;
192 auto multiPdf = std::make_unique<RooProdPdf>(
name.c_str(),
name.c_str(),fullPdfSet,cmdList) ;
197 multiPdf->useDefaultGen(
true) ;
199 coutI(Generation) <<
"RooProdGenContext()::ctor creating subcontext for generation of observables " << *termDeps
200 <<
"for irriducuble composite term using sub-product object " << multiPdf->GetName() ;
201 _gcList.emplace_back(multiPdf->genContext(*termDeps,prototype,auxProto,verbose));
204 genDeps.
add(*termDeps) ;
215 depsList.
Remove(termDeps);
216 impDepList.
Remove(impDeps);
226 if (!termList.
empty()) {
228 cxcoutD(Generation) <<
"RooProdGenContext::ctor() there are left-over terms that need to be generated separately" << endl ;
231 auto normIter = depsList.
begin();
234 for(
auto * term : static_range_cast<RooArgSet*>(termList)) {
235 auto* termDeps =
static_cast<RooArgSet*
>(*normIter);
236 trailerTerm.
add(*term) ;
237 trailerTermDeps.
add(*termDeps) ;
249 for(
auto * pdf : static_range_cast<RooAbsPdf*>(trailerTerm)) {
253 pdfSetList.
Add(pdfSet) ;
255 if (pdfnset && !pdfnset->
empty()) {
259 fullPdfSet.
add(*pdfSet) ;
264 auto multiPdf = std::make_unique<RooProdPdf>(
name.c_str(),
name.c_str(),fullPdfSet,cmdList);
269 multiPdf->useDefaultGen(
true) ;
271 cxcoutD(Generation) <<
"RooProdGenContext(" << model.
GetName() <<
"): creating context for irreducible composite trailer term "
272 << multiPdf->GetName() <<
" that generates observables " << trailerTermDeps << endl ;
273 _gcList.emplace_back(multiPdf->genContext(trailerTermDeps,prototype,auxProto,verbose));
283 coutI(Generation) <<
"RooProdGenContext(" << model.
GetName() <<
"): generating uniform distribution for non-dependent observable(s) " <<
_uniObs << std::endl;
310 for (
auto const& elem :
_gcList) {
322 for (
auto const& elem :
_gcList) {
323 elem->initGenerator(theEvent) ;
339 for (
auto const& elem :
_gcList) {
340 elem->generateEvent(theEvent,remaining) ;
345 for(
auto * arglv : dynamic_range_cast<RooAbsLValue*>(
_uniObs)) {
365 for (
auto const& elem :
_gcList) {
366 elem->setProtoDataOrder(lut) ;
378 os <<
indent <<
"--- RooProdGenContext ---" << endl ;
379 os <<
indent <<
"Using PDF ";
381 os <<
indent <<
"List of component generators" << endl ;
386 for (
auto const& elem :
_gcList) {
387 elem->printMultiline(os,content,verbose,indent2) ;
static void indent(ostringstream &buf, int indent_level)
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.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
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.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Interface for multi-line printing.
virtual void setProtoDataOrder(Int_t *lut)
Set the traversal order of prototype data to that in the lookup tables passed as argument.
Abstract interface for all probability density functions.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Container class to hold unbinned data.
const RooArgSet * get(Int_t index) const override
Return RooArgSet with coordinates of event 'index'.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
RooLinkedListIterImpl end() const
void Delete(Option_t *o=nullptr) override
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
virtual void Add(TObject *arg)
RooLinkedListIterImpl begin() const
virtual bool Remove(TObject *arg)
Remove object from collection.
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,...
Efficient implementation of the generator context specific for RooProdPdf PDFs.
std::list< std::unique_ptr< RooAbsGenContext > > _gcList
List of component generator contexts.
void setProtoDataOrder(Int_t *lut) override
Set the traversal order of the prototype dataset by the given lookup table.
void attach(const RooArgSet ¶ms) override
Attach generator to given event buffer.
RooArgSet _ownedMultiProds
Owned auxiliary multi-term product PDFs.
const RooProdPdf * _pdf
Original PDF.
void initGenerator(const RooArgSet &theEvent) override
One-time initialization of generator context, forward to component generators.
RooArgSet _uniObs
Observable to be generated with flat distribution.
~RooProdGenContext() override
Destructor. Delete all owned subgenerator contexts.
void generateEvent(RooArgSet &theEvent, Int_t remaining) override
Generate a single event of the product by generating the components of the products sequentially.
RooProdGenContext(const RooProdPdf &model, const RooArgSet &vars, const RooDataSet *prototype=nullptr, const RooArgSet *auxProto=nullptr, bool _verbose=false)
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override
Detailed printing interface.
Efficient implementation of a product of PDFs of the form.
void factorizeProduct(const RooArgSet &normSet, const RooArgSet &intSet, RooLinkedList &termList, RooLinkedList &normList, RooLinkedList &impDepList, RooLinkedList &crossDepList, RooLinkedList &intList) const
Factorize product in irreducible terms for given choice of integration/normalization.
std::string makeRGPPName(const char *pfx, const RooArgSet &term, const RooArgSet &iset, const RooArgSet &nset, const char *isetRangeName) const
Make an appropriate automatic name for a RooGenProdProj object in getPartIntList()
RooArgSet * findPdfNSet(RooAbsPdf const &pdf) const
Look up user specified normalization set for given input PDF component.
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
const char * GetName() const override
Returns name of object.
TString & Append(const char *cs)
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, bool depsAreCond=false)