39using std::endl, std::ostream;
52 cxcoutI(Generation) <<
"RooProdGenContext::ctor() setting up event special generator context for product p.d.f. " << model.GetName()
53 <<
" for generation of observable(s) " << vars ;
54 if (prototype)
ccxcoutI(Generation) <<
" with prototype data for " << *prototype->
get() ;
55 if (auxProto && !auxProto->
empty())
ccxcoutI(Generation) <<
" with auxiliary prototypes " << *auxProto ;
61 deps.
remove(*std::unique_ptr<RooArgSet>{model.getObservables(*prototype->
get())},
true,
true) ;
66 model.factorizeProduct(deps,
RooArgSet(),factorized);
69 cxcoutD(Generation) <<
"RooProdGenContext::ctor() factorizing product expression in irriducible terms " ;
79 bool anyAction = true ;
87 bool anyPrevAction=anyAction ;
94 while(termIter != factorized.
terms.
end()) {
96 auto * term =
static_cast<RooArgSet*
>(*termIter);
97 auto * impDeps =
static_cast<RooArgSet*
>(*impIter);
98 auto * termDeps =
static_cast<RooArgSet*
>(*normIter);
99 if (impDeps==
nullptr || termDeps==
nullptr) {
103 cxcoutD(Generation) <<
"RooProdGenContext::ctor() analyzing product term " << *term <<
" with observable(s) " << *termDeps ;
104 if (!impDeps->empty()) {
105 ccxcoutD(Generation) <<
" which has dependence of external observable(s) " << *impDeps <<
" that to be generated first by other terms" ;
111 neededDeps.
remove(genDeps,
true,
true) ;
113 if (!neededDeps.
empty()) {
114 if (!anyPrevAction) {
115 cxcoutD(Generation) <<
"RooProdGenContext::ctor() no convergence in single term analysis loop, terminating loop and process remainder of terms as single unit " << std::endl ;
119 cxcoutD(Generation) <<
"RooProdGenContext::ctor() skipping this term for now because it needs imported dependents that are not generated yet" << std::endl ;
128 if (termDeps->empty()) {
129 cxcoutD(Generation) <<
"RooProdGenContext::ctor() term has no observables requested to be generated, removing it" << std::endl ;
147 if (term->size()==1) {
150 auto pdf =
static_cast<RooAbsPdf*
>((*term)[0]);
151 std::unique_ptr<RooArgSet> pdfDep{pdf->getObservables(termDeps)};
152 if (!pdfDep->empty()) {
153 coutI(Generation) <<
"RooProdGenContext::ctor() creating subcontext for generation of observables " << *pdfDep <<
" from model " << pdf->GetName() << std::endl ;
154 std::unique_ptr<RooArgSet> auxProto2{pdf->getObservables(impDeps)};
155 _gcList.emplace_back(pdf->genContext(*pdfDep,prototype,auxProto2.get(),verbose)) ;
159 genDeps.
add(*pdfDep) ;
164 if (!termDeps->empty()) {
174 RooArgSet* pdfnset = model.findPdfNSet(*pdf) ;
176 pdfSetList.
Add(pdfSet) ;
178 if (pdfnset && !pdfnset->
empty()) {
183 fullPdfSet.
add(*pdfSet) ;
187 auto multiPdf = std::make_unique<RooProdPdf>(
name.c_str(),
name.c_str(),fullPdfSet,cmdList) ;
192 multiPdf->useDefaultGen(
true) ;
194 coutI(Generation) <<
"RooProdGenContext()::ctor creating subcontext for generation of observables " << *termDeps
195 <<
"for irriducuble composite term using sub-product object " << multiPdf->GetName() ;
196 _gcList.emplace_back(multiPdf->genContext(*termDeps,prototype,auxProto,verbose));
199 genDeps.
add(*termDeps) ;
223 cxcoutD(Generation) <<
"RooProdGenContext::ctor() there are left-over terms that need to be generated separately" << std::endl ;
230 auto* termDeps =
static_cast<RooArgSet*
>(*normIter);
231 trailerTerm.
add(*term) ;
232 trailerTermDeps.
add(*termDeps) ;
246 RooArgSet* pdfnset = model.findPdfNSet(*pdf) ;
248 pdfSetList.
Add(pdfSet) ;
250 if (pdfnset && !pdfnset->
empty()) {
254 fullPdfSet.
add(*pdfSet) ;
259 auto multiPdf = std::make_unique<RooProdPdf>(
name.c_str(),
name.c_str(),fullPdfSet,cmdList);
264 multiPdf->useDefaultGen(
true) ;
266 cxcoutD(Generation) <<
"RooProdGenContext(" << model.GetName() <<
"): creating context for irreducible composite trailer term "
267 << multiPdf->GetName() <<
" that generates observables " << trailerTermDeps << std::endl ;
268 _gcList.emplace_back(multiPdf->genContext(trailerTermDeps,prototype,auxProto,verbose));
276 _uniObs.remove(genDeps,
true,
true) ;
278 coutI(Generation) <<
"RooProdGenContext(" << model.GetName() <<
"): generating uniform distribution for non-dependent observable(s) " <<
_uniObs << std::endl;
296 for (
auto const& elem :
_gcList) {
308 for (
auto const& elem :
_gcList) {
309 elem->initGenerator(theEvent) ;
325 for (
auto const& elem :
_gcList) {
326 elem->generateEvent(theEvent,remaining) ;
351 for (
auto const& elem :
_gcList) {
352 elem->setProtoDataOrder(lut) ;
364 os <<
indent <<
"--- RooProdGenContext ---" << std::endl ;
365 os <<
indent <<
"Using PDF ";
367 os <<
indent <<
"List of component generators" << std::endl ;
372 for (
auto const& elem :
_gcList) {
373 elem->printMultiline(os,content,verbose,indent2) ;
ROOT::RRangeCast< T, true, Range_t > dynamic_range_cast(Range_t &&coll)
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
int Int_t
Signed integer 4 bytes (int).
static void indent(ostringstream &buf, int indent_level)
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...
RooAbsGenContext(const RooAbsPdf &model, const RooArgSet &vars, const RooDataSet *prototype=nullptr, const RooArgSet *auxProto=nullptr, bool _verbose=false)
Constructor.
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.
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.
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
TString & Append(const char *cs)
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, bool depsAreCond=false)