// RooProdGenContext is an efficient implementation of the generator context
// specific for RooProdPdf PDFs. The sim-context owns a list of
// component generator contexts that are used to generate the dependents
// for each component PDF sequentially.
// END_HTML
#include "RooFit.h"
#include "Riostream.h"
#include "RooMsgService.h"
#include "RooProdGenContext.h"
#include "RooProdGenContext.h"
#include "RooProdPdf.h"
#include "RooDataSet.h"
#include "RooRealVar.h"
#include "RooGlobalFunc.h"
ClassImp(RooProdGenContext)
;
RooProdGenContext::RooProdGenContext(const RooProdPdf &model, const RooArgSet &vars,
const RooDataSet *prototype, const RooArgSet* auxProto, Bool_t verbose) :
RooAbsGenContext(model,vars,prototype,auxProto,verbose), _uniIter(0), _pdf(&model)
{
cxcoutI(Generation) << "RooProdGenContext::ctor() setting up event special generator context for product p.d.f. " << model.GetName()
<< " for generation of observable(s) " << vars ;
if (prototype) ccxcoutI(Generation) << " with prototype data for " << *prototype->get() ;
if (auxProto && auxProto->getSize()>0) ccxcoutI(Generation) << " with auxiliary prototypes " << *auxProto ;
ccxcoutI(Generation) << endl ;
RooArgSet deps(vars) ;
if (prototype) {
RooArgSet* protoDeps = model.getObservables(*prototype->get()) ;
deps.remove(*protoDeps,kTRUE,kTRUE) ;
delete protoDeps ;
}
RooLinkedList termList,depsList,impDepList,crossDepList,intList ;
model.factorizeProduct(deps,RooArgSet(),termList,depsList,impDepList,crossDepList,intList) ;
TIterator* termIter = termList.MakeIterator() ;
TIterator* normIter = depsList.MakeIterator() ;
TIterator* impIter = impDepList.MakeIterator() ;
if (dologD(Generation)) {
cxcoutD(Generation) << "RooProdGenContext::ctor() factorizing product expression in irriducible terms " ;
while(RooArgSet* t=(RooArgSet*)termIter->Next()) {
ccxcoutD(Generation) << *t ;
}
ccxcoutD(Generation) << endl ;
}
RooArgSet genDeps ;
Bool_t anyAction = kTRUE ;
Bool_t go=kTRUE ;
while(go) {
RooAbsPdf* pdf ;
RooArgSet* term ;
RooArgSet* impDeps ;
RooArgSet* termDeps ;
termIter->Reset() ;
impIter->Reset() ;
normIter->Reset() ;
Bool_t anyPrevAction=anyAction ;
anyAction=kFALSE ;
if (termList.GetSize()==0) {
break ;
}
while((term=(RooArgSet*)termIter->Next())) {
impDeps = (RooArgSet*)impIter->Next() ;
termDeps = (RooArgSet*)normIter->Next() ;
if (impDeps==0 || termDeps==0) {
break ;
}
cxcoutD(Generation) << "RooProdGenContext::ctor() analyzing product term " << *term << " with observable(s) " << *termDeps ;
if (impDeps->getSize()>0) {
ccxcoutD(Generation) << " which has dependence of external observable(s) " << *impDeps << " that to be generated first by other terms" ;
}
ccxcoutD(Generation) << endl ;
RooArgSet neededDeps(*impDeps) ;
neededDeps.remove(genDeps,kTRUE,kTRUE) ;
if (neededDeps.getSize()>0) {
if (!anyPrevAction) {
cxcoutD(Generation) << "RooProdGenContext::ctor() no convergence in single term analysis loop, terminating loop and process remainder of terms as single unit " << endl ;
go=kFALSE ;
break ;
}
cxcoutD(Generation) << "RooProdGenContext::ctor() skipping this term for now because it needs imported dependents that are not generated yet" << endl ;
continue ;
}
if (termDeps->getSize()==0) {
cxcoutD(Generation) << "RooProdGenContext::ctor() term has no observables requested to be generated, removing it" << endl ;
termList.Remove(term) ;
depsList.Remove(termDeps) ;
impDepList.Remove(impDeps) ;
delete term ;
delete termDeps ;
delete impDeps ;
anyAction=kTRUE ;
continue ;
}
TIterator* pdfIter = term->createIterator() ;
if (term->getSize()==1) {
pdf = (RooAbsPdf*) pdfIter->Next() ;
RooArgSet* pdfDep = pdf->getObservables(termDeps) ;
if (pdfDep->getSize()>0) {
coutI(Generation) << "RooProdGenContext::ctor() creating subcontext for generation of observables " << *pdfDep << " from model " << pdf->GetName() << endl ;
RooArgSet* auxProto2 = pdf->getObservables(impDeps) ;
RooAbsGenContext* cx = pdf->genContext(*pdfDep,prototype,auxProto2,verbose) ;
delete auxProto2 ;
_gcList.Add(cx) ;
}
genDeps.add(*pdfDep) ;
delete pdfDep ;
} else {
if (termDeps->getSize()>0) {
const char* name = model.makeRGPPName("PRODGEN_",*term,RooArgSet(),RooArgSet(),0) ;
RooLinkedList cmdList ;
RooLinkedList pdfSetList ;
pdfIter->Reset() ;
RooArgSet fullPdfSet ;
while((pdf=(RooAbsPdf*)pdfIter->Next())) {
RooArgSet* pdfnset = model.findPdfNSet(*pdf) ;
RooArgSet* pdfSet = new RooArgSet(*pdf) ;
pdfSetList.Add(pdfSet) ;
if (pdfnset && pdfnset->getSize()>0) {
cmdList.Add(RooFit::Conditional(*pdfSet,*pdfnset).Clone()) ;
} else {
fullPdfSet.add(*pdfSet) ;
}
}
RooProdPdf* multiPdf = new RooProdPdf(name,name,fullPdfSet,cmdList) ;
cmdList.Delete() ;
pdfSetList.Delete() ;
multiPdf->useDefaultGen(kTRUE) ;
_ownedMultiProds.addOwned(*multiPdf) ;
coutI(Generation) << "RooProdGenContext()::ctor creating subcontext for generation of observables " << *termDeps
<< "for irriducuble composite term using sub-product object " << multiPdf->GetName() ;
RooAbsGenContext* cx = multiPdf->genContext(*termDeps,prototype,auxProto,verbose) ;
_gcList.Add(cx) ;
genDeps.add(*termDeps) ;
}
}
delete pdfIter ;
termList.Remove(term) ;
depsList.Remove(termDeps) ;
impDepList.Remove(impDeps) ;
delete term ;
delete termDeps ;
delete impDeps ;
anyAction=kTRUE ;
}
}
if (termList.GetSize()>0) {
cxcoutD(Generation) << "RooProdGenContext::ctor() there are left-over terms that need to be generated separately" << endl ;
RooAbsPdf* pdf ;
RooArgSet* term ;
termIter->Reset() ;
normIter->Reset() ;
RooArgSet trailerTerm ;
RooArgSet trailerTermDeps ;
while((term=(RooArgSet*)termIter->Next())) {
RooArgSet* termDeps = (RooArgSet*)normIter->Next() ;
trailerTerm.add(*term) ;
trailerTermDeps.add(*termDeps) ;
}
const char* name = model.makeRGPPName("PRODGEN_",trailerTerm,RooArgSet(),RooArgSet(),0) ;
RooLinkedList cmdList ;
RooLinkedList pdfSetList ;
RooArgSet fullPdfSet ;
TIterator* pdfIter = trailerTerm.createIterator() ;
while((pdf=(RooAbsPdf*)pdfIter->Next())) {
RooArgSet* pdfnset = model.findPdfNSet(*pdf) ;
RooArgSet* pdfSet = new RooArgSet(*pdf) ;
pdfSetList.Add(pdfSet) ;
if (pdfnset && pdfnset->getSize()>0) {
cmdList.Add(RooFit::Conditional(*pdfSet,*pdfnset).Clone()) ;
} else {
fullPdfSet.add(*pdfSet) ;
}
}
RooProdPdf* multiPdf = new RooProdPdf(name,name,fullPdfSet,cmdList) ;
cmdList.Delete() ;
pdfSetList.Delete() ;
multiPdf->useDefaultGen(kTRUE) ;
_ownedMultiProds.addOwned(*multiPdf) ;
cxcoutD(Generation) << "RooProdGenContext(" << model.GetName() << "): creating context for irreducible composite trailer term "
<< multiPdf->GetName() << " that generates observables " << trailerTermDeps << endl ;
RooAbsGenContext* cx = multiPdf->genContext(trailerTermDeps,prototype,auxProto,verbose) ;
_gcList.Add(cx) ;
}
_uniObs.add(vars) ;
_uniObs.remove(genDeps,kTRUE,kTRUE) ;
if (_uniObs.getSize()>0) {
_uniIter = _uniObs.createIterator() ;
coutI(Generation) << "RooProdGenContext(" << model.GetName() << "): generating uniform distribution for non-dependent observable(s) " << _uniObs << endl ;
}
delete termIter ;
delete impIter ;
delete normIter ;
_gcIter = _gcList.MakeIterator() ;
termList.Delete() ;
depsList.Delete() ;
impDepList.Delete() ;
crossDepList.Delete() ;
intList.Delete() ;
}
RooProdGenContext::~RooProdGenContext()
{
delete _gcIter ;
delete _uniIter ;
_gcList.Delete() ;
}
void RooProdGenContext::attach(const RooArgSet& args)
{
RooAbsGenContext* gc ;
_gcIter->Reset() ;
while((gc=(RooAbsGenContext*)_gcIter->Next())){
gc->attach(args) ;
}
}
void RooProdGenContext::initGenerator(const RooArgSet &theEvent)
{
RooAbsGenContext* gc ;
_gcIter->Reset() ;
while((gc=(RooAbsGenContext*)_gcIter->Next())){
gc->initGenerator(theEvent) ;
}
}
void RooProdGenContext::generateEvent(RooArgSet &theEvent, Int_t remaining)
{
TList compData ;
RooAbsGenContext* gc ;
_gcIter->Reset() ;
while((gc=(RooAbsGenContext*)_gcIter->Next())) {
gc->generateEvent(theEvent,remaining) ;
}
if (_uniIter) {
_uniIter->Reset() ;
RooAbsArg* uniVar ;
while((uniVar=(RooAbsArg*)_uniIter->Next())) {
RooAbsLValue* arglv = dynamic_cast<RooAbsLValue*>(uniVar) ;
if (arglv) {
arglv->randomize() ;
}
}
theEvent = _uniObs ;
}
}
void RooProdGenContext::setProtoDataOrder(Int_t* lut)
{
RooAbsGenContext::setProtoDataOrder(lut) ;
_gcIter->Reset() ;
RooAbsGenContext* gc ;
while((gc=(RooAbsGenContext*)_gcIter->Next())) {
gc->setProtoDataOrder(lut) ;
}
}
void RooProdGenContext::printMultiline(ostream &os, Int_t content, Bool_t verbose, TString indent) const
{
RooAbsGenContext::printMultiline(os,content,verbose,indent) ;
os << indent << "--- RooProdGenContext ---" << endl ;
os << indent << "Using PDF ";
_pdf->printStream(os,kName|kArgs|kClassName,kSingleLine,indent);
os << indent << "List of component generators" << endl ;
TString indent2(indent) ;
indent2.Append(" ") ;
RooAbsGenContext* gc ;
_gcIter->Reset() ;
while((gc=(RooAbsGenContext*)_gcIter->Next())) {
gc->printMultiline(os,content,verbose,indent2) ;
}
}
RooProdGenContext.cxx:100 RooProdGenContext.cxx:101 RooProdGenContext.cxx:102 RooProdGenContext.cxx:103 RooProdGenContext.cxx:104 RooProdGenContext.cxx:105 RooProdGenContext.cxx:106 RooProdGenContext.cxx:107 RooProdGenContext.cxx:108 RooProdGenContext.cxx:109 RooProdGenContext.cxx:110 RooProdGenContext.cxx:111 RooProdGenContext.cxx:112 RooProdGenContext.cxx:113 RooProdGenContext.cxx:114 RooProdGenContext.cxx:115 RooProdGenContext.cxx:116 RooProdGenContext.cxx:117 RooProdGenContext.cxx:118 RooProdGenContext.cxx:119 RooProdGenContext.cxx:120 RooProdGenContext.cxx:121 RooProdGenContext.cxx:122 RooProdGenContext.cxx:123 RooProdGenContext.cxx:124 RooProdGenContext.cxx:125 RooProdGenContext.cxx:126 RooProdGenContext.cxx:127 RooProdGenContext.cxx:128 RooProdGenContext.cxx:129 RooProdGenContext.cxx:130 RooProdGenContext.cxx:131 RooProdGenContext.cxx:132 RooProdGenContext.cxx:133 RooProdGenContext.cxx:134 RooProdGenContext.cxx:135 RooProdGenContext.cxx:136 RooProdGenContext.cxx:137 RooProdGenContext.cxx:138 RooProdGenContext.cxx:139 RooProdGenContext.cxx:140 RooProdGenContext.cxx:141 RooProdGenContext.cxx:142 RooProdGenContext.cxx:143 RooProdGenContext.cxx:144 RooProdGenContext.cxx:145 RooProdGenContext.cxx:146 RooProdGenContext.cxx:147 RooProdGenContext.cxx:148 RooProdGenContext.cxx:149 RooProdGenContext.cxx:150 RooProdGenContext.cxx:151 RooProdGenContext.cxx:152 RooProdGenContext.cxx:153 RooProdGenContext.cxx:154 RooProdGenContext.cxx:155 RooProdGenContext.cxx:156 RooProdGenContext.cxx:157 RooProdGenContext.cxx:158 RooProdGenContext.cxx:159 RooProdGenContext.cxx:160 RooProdGenContext.cxx:161 RooProdGenContext.cxx:162 RooProdGenContext.cxx:163 RooProdGenContext.cxx:164 RooProdGenContext.cxx:165 RooProdGenContext.cxx:166 RooProdGenContext.cxx:167 RooProdGenContext.cxx:168 RooProdGenContext.cxx:169 RooProdGenContext.cxx:170 RooProdGenContext.cxx:171 RooProdGenContext.cxx:172 RooProdGenContext.cxx:173 RooProdGenContext.cxx:174 RooProdGenContext.cxx:175 RooProdGenContext.cxx:176 RooProdGenContext.cxx:177 RooProdGenContext.cxx:178 RooProdGenContext.cxx:179 RooProdGenContext.cxx:180 RooProdGenContext.cxx:181 RooProdGenContext.cxx:182 RooProdGenContext.cxx:183 RooProdGenContext.cxx:184 RooProdGenContext.cxx:185 RooProdGenContext.cxx:186 RooProdGenContext.cxx:187 RooProdGenContext.cxx:188 RooProdGenContext.cxx:189 RooProdGenContext.cxx:190 RooProdGenContext.cxx:191 RooProdGenContext.cxx:192 RooProdGenContext.cxx:193 RooProdGenContext.cxx:194 RooProdGenContext.cxx:195 RooProdGenContext.cxx:196 RooProdGenContext.cxx:197 RooProdGenContext.cxx:198 RooProdGenContext.cxx:199 RooProdGenContext.cxx:200 RooProdGenContext.cxx:201 RooProdGenContext.cxx:202 RooProdGenContext.cxx:203 RooProdGenContext.cxx:204 RooProdGenContext.cxx:205 RooProdGenContext.cxx:206 RooProdGenContext.cxx:207 RooProdGenContext.cxx:208 RooProdGenContext.cxx:209 RooProdGenContext.cxx:210 RooProdGenContext.cxx:211 RooProdGenContext.cxx:212 RooProdGenContext.cxx:213 RooProdGenContext.cxx:214 RooProdGenContext.cxx:215 RooProdGenContext.cxx:216 RooProdGenContext.cxx:217 RooProdGenContext.cxx:218 RooProdGenContext.cxx:219 RooProdGenContext.cxx:220 RooProdGenContext.cxx:221 RooProdGenContext.cxx:222 RooProdGenContext.cxx:223 RooProdGenContext.cxx:224 RooProdGenContext.cxx:225 RooProdGenContext.cxx:226 RooProdGenContext.cxx:227 RooProdGenContext.cxx:228 RooProdGenContext.cxx:229 RooProdGenContext.cxx:230 RooProdGenContext.cxx:231 RooProdGenContext.cxx:232 RooProdGenContext.cxx:233 RooProdGenContext.cxx:234 RooProdGenContext.cxx:235 RooProdGenContext.cxx:236 RooProdGenContext.cxx:237 RooProdGenContext.cxx:238 RooProdGenContext.cxx:239 RooProdGenContext.cxx:240 RooProdGenContext.cxx:241 RooProdGenContext.cxx:242 RooProdGenContext.cxx:243 RooProdGenContext.cxx:244 RooProdGenContext.cxx:245 RooProdGenContext.cxx:246 RooProdGenContext.cxx:247 RooProdGenContext.cxx:248 RooProdGenContext.cxx:249 RooProdGenContext.cxx:250 RooProdGenContext.cxx:251 RooProdGenContext.cxx:252 RooProdGenContext.cxx:253 RooProdGenContext.cxx:254 RooProdGenContext.cxx:255 RooProdGenContext.cxx:256 RooProdGenContext.cxx:257 RooProdGenContext.cxx:258 RooProdGenContext.cxx:259 RooProdGenContext.cxx:260 RooProdGenContext.cxx:261 RooProdGenContext.cxx:262 RooProdGenContext.cxx:263 RooProdGenContext.cxx:264 RooProdGenContext.cxx:265 RooProdGenContext.cxx:266 RooProdGenContext.cxx:267 RooProdGenContext.cxx:268 RooProdGenContext.cxx:269 RooProdGenContext.cxx:270 RooProdGenContext.cxx:271 RooProdGenContext.cxx:272 RooProdGenContext.cxx:273 RooProdGenContext.cxx:274 RooProdGenContext.cxx:275 RooProdGenContext.cxx:276 RooProdGenContext.cxx:277 RooProdGenContext.cxx:278 RooProdGenContext.cxx:279 RooProdGenContext.cxx:280 RooProdGenContext.cxx:281 RooProdGenContext.cxx:282 RooProdGenContext.cxx:283 RooProdGenContext.cxx:284 RooProdGenContext.cxx:285 RooProdGenContext.cxx:286 RooProdGenContext.cxx:287 RooProdGenContext.cxx:288 RooProdGenContext.cxx:289 RooProdGenContext.cxx:290 RooProdGenContext.cxx:291 RooProdGenContext.cxx:292 RooProdGenContext.cxx:293 RooProdGenContext.cxx:294 RooProdGenContext.cxx:295 RooProdGenContext.cxx:296 RooProdGenContext.cxx:297 RooProdGenContext.cxx:298 RooProdGenContext.cxx:299 RooProdGenContext.cxx:300 RooProdGenContext.cxx:301 RooProdGenContext.cxx:302 RooProdGenContext.cxx:303 RooProdGenContext.cxx:304 RooProdGenContext.cxx:305 RooProdGenContext.cxx:306 RooProdGenContext.cxx:307 RooProdGenContext.cxx:308 RooProdGenContext.cxx:309 RooProdGenContext.cxx:310 RooProdGenContext.cxx:311 RooProdGenContext.cxx:312 RooProdGenContext.cxx:313 RooProdGenContext.cxx:314 RooProdGenContext.cxx:315 RooProdGenContext.cxx:316 RooProdGenContext.cxx:317 RooProdGenContext.cxx:318 RooProdGenContext.cxx:319 RooProdGenContext.cxx:320 RooProdGenContext.cxx:321 RooProdGenContext.cxx:322 RooProdGenContext.cxx:323 RooProdGenContext.cxx:324 RooProdGenContext.cxx:325 RooProdGenContext.cxx:326 RooProdGenContext.cxx:327 RooProdGenContext.cxx:328 RooProdGenContext.cxx:329 RooProdGenContext.cxx:330 RooProdGenContext.cxx:331 RooProdGenContext.cxx:332 RooProdGenContext.cxx:333 RooProdGenContext.cxx:334 RooProdGenContext.cxx:335 RooProdGenContext.cxx:336 RooProdGenContext.cxx:337 RooProdGenContext.cxx:338 RooProdGenContext.cxx:339 RooProdGenContext.cxx:340 RooProdGenContext.cxx:341 RooProdGenContext.cxx:342 RooProdGenContext.cxx:343 RooProdGenContext.cxx:344 RooProdGenContext.cxx:345 RooProdGenContext.cxx:346 RooProdGenContext.cxx:347 RooProdGenContext.cxx:348 RooProdGenContext.cxx:349 RooProdGenContext.cxx:350 RooProdGenContext.cxx:351 RooProdGenContext.cxx:352 RooProdGenContext.cxx:353 RooProdGenContext.cxx:354 RooProdGenContext.cxx:355 RooProdGenContext.cxx:356 RooProdGenContext.cxx:357 RooProdGenContext.cxx:358 RooProdGenContext.cxx:359 RooProdGenContext.cxx:360 RooProdGenContext.cxx:361 RooProdGenContext.cxx:362 RooProdGenContext.cxx:363 RooProdGenContext.cxx:364 RooProdGenContext.cxx:365 RooProdGenContext.cxx:366 RooProdGenContext.cxx:367 RooProdGenContext.cxx:368 RooProdGenContext.cxx:369 RooProdGenContext.cxx:370 RooProdGenContext.cxx:371 RooProdGenContext.cxx:372 RooProdGenContext.cxx:373 RooProdGenContext.cxx:374 RooProdGenContext.cxx:375 RooProdGenContext.cxx:376 RooProdGenContext.cxx:377 RooProdGenContext.cxx:378 RooProdGenContext.cxx:379 RooProdGenContext.cxx:380 RooProdGenContext.cxx:381 RooProdGenContext.cxx:382 RooProdGenContext.cxx:383 RooProdGenContext.cxx:384 RooProdGenContext.cxx:385 RooProdGenContext.cxx:386 RooProdGenContext.cxx:387 RooProdGenContext.cxx:388 RooProdGenContext.cxx:389 RooProdGenContext.cxx:390 RooProdGenContext.cxx:391 RooProdGenContext.cxx:392 RooProdGenContext.cxx:393 RooProdGenContext.cxx:394 RooProdGenContext.cxx:395 RooProdGenContext.cxx:396 RooProdGenContext.cxx:397 RooProdGenContext.cxx:398 RooProdGenContext.cxx:399 RooProdGenContext.cxx:400 RooProdGenContext.cxx:401 RooProdGenContext.cxx:402 RooProdGenContext.cxx:403 RooProdGenContext.cxx:404 RooProdGenContext.cxx:405 RooProdGenContext.cxx:406 RooProdGenContext.cxx:407 RooProdGenContext.cxx:408 RooProdGenContext.cxx:409 RooProdGenContext.cxx:410 RooProdGenContext.cxx:411 RooProdGenContext.cxx:412 RooProdGenContext.cxx:413 RooProdGenContext.cxx:414 RooProdGenContext.cxx:415 RooProdGenContext.cxx:416 RooProdGenContext.cxx:417 RooProdGenContext.cxx:418 RooProdGenContext.cxx:419 RooProdGenContext.cxx:420