37using std::endl, std::ostream;
50 cxcoutI(Generation) <<
"RooProdGenContext::ctor() setting up event special generator context for product p.d.f. " << model.GetName()
51 <<
" for generation of observable(s) " << vars ;
52 if (prototype)
ccxcoutI(Generation) <<
" with prototype data for " << *prototype->
get() ;
53 if (auxProto && !auxProto->
empty())
ccxcoutI(Generation) <<
" with auxiliary prototypes " << *auxProto ;
59 deps.
remove(*std::unique_ptr<RooArgSet>{model.getObservables(*prototype->
get())},
true,
true) ;
64 model.factorizeProduct(deps,
RooArgSet(),factorized);
67 cxcoutD(Generation) <<
"RooProdGenContext::ctor() factorizing product expression in irriducible terms " ;
68 for(
auto * t : static_range_cast<RooArgSet*>(factorized.
terms)) {
77 bool anyAction = true ;
84 bool anyPrevAction=anyAction ;
96 if (impDeps==
nullptr || termDeps==
nullptr) {
100 cxcoutD(Generation) <<
"RooProdGenContext::ctor() analyzing product term " << *term <<
" with observable(s) " << *termDeps ;
101 if (!impDeps->empty()) {
102 ccxcoutD(Generation) <<
" which has dependence of external observable(s) " << *impDeps <<
" that to be generated first by other terms" ;
108 neededDeps.
remove(genDeps,
true,
true) ;
110 if (!neededDeps.
empty()) {
111 if (!anyPrevAction) {
112 cxcoutD(Generation) <<
"RooProdGenContext::ctor() no convergence in single term analysis loop, terminating loop and process remainder of terms as single unit " << std::endl ;
116 cxcoutD(Generation) <<
"RooProdGenContext::ctor() skipping this term for now because it needs imported dependents that are not generated yet" << std::endl ;
123 if (termDeps->empty()) {
124 cxcoutD(Generation) <<
"RooProdGenContext::ctor() term has no observables requested to be generated, removing it" << std::endl ;
137 if (term->size()==1) {
140 auto pdf =
static_cast<RooAbsPdf*
>((*term)[0]);
142 if (!pdfDep->empty()) {
143 coutI(Generation) <<
"RooProdGenContext::ctor() creating subcontext for generation of observables " << *pdfDep <<
" from model " << pdf->GetName() << std::endl ;
144 std::unique_ptr<RooArgSet> auxProto2{pdf->getObservables(impDeps)};
145 _gcList.emplace_back(pdf->genContext(*pdfDep,prototype,auxProto2.
get(),verbose)) ;
149 genDeps.
add(*pdfDep) ;
154 if (!termDeps->empty()) {
162 for(
auto * pdf : static_range_cast<RooAbsPdf*>(*term)) {
164 RooArgSet* pdfnset = model.findPdfNSet(*pdf) ;
166 pdfSetList.
Add(pdfSet) ;
168 if (pdfnset && !pdfnset->
empty()) {
173 fullPdfSet.
add(*pdfSet) ;
177 auto multiPdf = std::make_unique<RooProdPdf>(
name.c_str(),
name.c_str(),fullPdfSet,cmdList) ;
182 multiPdf->useDefaultGen(
true) ;
184 coutI(Generation) <<
"RooProdGenContext()::ctor creating subcontext for generation of observables " << *termDeps
185 <<
"for irriducuble composite term using sub-product object " << multiPdf->GetName() ;
186 _gcList.emplace_back(multiPdf->genContext(*termDeps,prototype,auxProto,verbose));
189 genDeps.
add(*termDeps) ;
208 cxcoutD(Generation) <<
"RooProdGenContext::ctor() there are left-over terms that need to be generated separately" << std::endl ;
214 for(
auto * term : static_range_cast<RooArgSet*>(factorized.
terms)) {
215 auto* termDeps =
static_cast<RooArgSet*
>(*normIter);
216 trailerTerm.
add(*term) ;
217 trailerTermDeps.
add(*termDeps) ;
229 for(
auto * pdf : static_range_cast<RooAbsPdf*>(trailerTerm)) {
231 RooArgSet* pdfnset = model.findPdfNSet(*pdf) ;
233 pdfSetList.
Add(pdfSet) ;
235 if (pdfnset && !pdfnset->
empty()) {
239 fullPdfSet.
add(*pdfSet) ;
244 auto multiPdf = std::make_unique<RooProdPdf>(
name.c_str(),
name.c_str(),fullPdfSet,cmdList);
249 multiPdf->useDefaultGen(
true) ;
251 cxcoutD(Generation) <<
"RooProdGenContext(" << model.GetName() <<
"): creating context for irreducible composite trailer term "
252 << multiPdf->GetName() <<
" that generates observables " << trailerTermDeps << std::endl ;
253 _gcList.emplace_back(multiPdf->genContext(trailerTermDeps,prototype,auxProto,verbose));
263 coutI(Generation) <<
"RooProdGenContext(" << model.GetName() <<
"): generating uniform distribution for non-dependent observable(s) " <<
_uniObs << std::endl;
281 for (
auto const& elem :
_gcList) {
293 for (
auto const& elem :
_gcList) {
294 elem->initGenerator(theEvent) ;
310 for (
auto const& elem :
_gcList) {
311 elem->generateEvent(theEvent,remaining) ;
316 for(
auto * arglv : dynamic_range_cast<RooAbsLValue*>(
_uniObs)) {
336 for (
auto const& elem :
_gcList) {
337 elem->setProtoDataOrder(lut) ;
349 os <<
indent <<
"--- RooProdGenContext ---" << std::endl ;
350 os <<
indent <<
"Using PDF ";
352 os <<
indent <<
"List of component generators" << std::endl ;
357 for (
auto const& elem :
_gcList) {
358 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 TObject pointers in a vector.
TObject * At(int index) const
Return object stored in sequential position given by index.
virtual void Add(TObject *arg)
Insert object into collection.
void Delete(Option_t *o=nullptr) override
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
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,...
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.
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 attach(const RooArgSet &args) override
Attach generator to given event buffer.
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)
RooArgSet * termNormDeps(int i) const
RooArgSet * termImpDeps(int i) const