// RooProdPdf is an efficient implementation of a product of PDFs of the form
//
// PDF_1 * PDF_2 * ... * PDF_N
//
// PDFs may share observables. If that is the case any irreducable subset
// of PDFS that share observables will be normalized with explicit numeric
// integration as any built-in normalization will no longer be valid.
//
// Alternatively, products using conditional PDFs can be defined, e.g.
//
// F(x|y) * G(y)
//
// meaning a pdf F(x) _given_ y and a PDF G(y). In this contruction F is only
// normalized w.r.t x and G is normalized w.r.t y. The product in this construction
// is properly normalized.
//
// If exactly one of the component PDFs supports extended likelihood fits, the
// product will also be usable in extended mode, returning the number of expected
// events from the extendable component PDF. The extendable component does not
// have to appear in any specific place in the list.
//
// END_HTML
#include "RooFit.h"
#include "Riostream.h"
#include "TIterator.h"
#include "RooProdPdf.h"
#include "RooRealProxy.h"
#include "RooProdGenContext.h"
#include "RooGenProdProj.h"
#include "RooProduct.h"
#include "RooNameReg.h"
#include "RooMsgService.h"
ClassImp(RooProdPdf)
;
RooProdPdf::RooProdPdf() :
_curNormSet(0),
_cutOff(0),
_extendedIndex(-1),
_useDefaultGen(kFALSE)
{
_pdfIter = _pdfList.createIterator() ;
}
RooProdPdf::RooProdPdf(const char *name, const char *title, Double_t cutOff) :
RooAbsPdf(name,title),
_cacheMgr(this,10),
_genCode(10),
_cutOff(cutOff),
_pdfList("pdfs","List of PDFs",this),
_extendedIndex(-1),
_useDefaultGen(kFALSE)
{
_pdfIter = _pdfList.createIterator() ;
}
RooProdPdf::RooProdPdf(const char *name, const char *title,
RooAbsPdf& pdf1, RooAbsPdf& pdf2, Double_t cutOff) :
RooAbsPdf(name,title),
_cacheMgr(this,10),
_genCode(10),
_cutOff(cutOff),
_pdfList("pdfs","List of PDFs",this),
_pdfIter(_pdfList.createIterator()),
_extendedIndex(-1),
_useDefaultGen(kFALSE)
{
_pdfList.add(pdf1) ;
RooArgSet* nset1 = new RooArgSet("nset1") ;
_pdfNSetList.Add(nset1) ;
if (pdf1.canBeExtended()) {
_extendedIndex = _pdfList.index(&pdf1) ;
}
_pdfList.add(pdf2) ;
RooArgSet* nset2 = new RooArgSet("nset2") ;
_pdfNSetList.Add(nset2) ;
if (pdf2.canBeExtended()) {
if (_extendedIndex>=0) {
coutW(InputArguments) << "RooProdPdf::RooProdPdf(" << GetName()
<< ") multiple components with extended terms detected,"
<< " product will not be extendible." << endl ;
_extendedIndex=-1 ;
} else {
_extendedIndex=_pdfList.index(&pdf2) ;
}
}
}
RooProdPdf::RooProdPdf(const char* name, const char* title, const RooArgList& inPdfList, Double_t cutOff) :
RooAbsPdf(name,title),
_cacheMgr(this,10),
_genCode(10),
_cutOff(cutOff),
_pdfList("pdfs","List of PDFs",this),
_pdfIter(_pdfList.createIterator()),
_extendedIndex(-1),
_useDefaultGen(kFALSE)
{
TIterator* iter = inPdfList.createIterator() ;
RooAbsArg* arg ;
Int_t numExtended(0) ;
while((arg=(RooAbsArg*)iter->Next())) {
RooAbsPdf* pdf = dynamic_cast<RooAbsPdf*>(arg) ;
if (!pdf) {
coutW(InputArguments) << "RooProdPdf::RooProdPdf(" << GetName() << ") list arg "
<< pdf->GetName() << " is not a PDF, ignored" << endl ;
continue ;
}
_pdfList.add(*pdf) ;
RooArgSet* nset = new RooArgSet("nset") ;
_pdfNSetList.Add(nset) ;
if (pdf->canBeExtended()) {
_extendedIndex = _pdfList.index(pdf) ;
numExtended++ ;
}
}
if (numExtended>1) {
coutW(InputArguments) << "RooProdPdf::RooProdPdf(" << GetName()
<< ") WARNING: multiple components with extended terms detected,"
<< " product will not be extendible." << endl ;
_extendedIndex = -1 ;
}
delete iter ;
}
RooProdPdf::RooProdPdf(const char* name, const char* title, const RooArgSet& fullPdfSet,
const RooCmdArg& arg1, const RooCmdArg& arg2,
const RooCmdArg& arg3, const RooCmdArg& arg4,
const RooCmdArg& arg5, const RooCmdArg& arg6,
const RooCmdArg& arg7, const RooCmdArg& arg8) :
RooAbsPdf(name,title),
_cacheMgr(this,10),
_genCode(10),
_cutOff(0),
_pdfList("pdfs","List of PDFs",this),
_pdfIter(_pdfList.createIterator()),
_extendedIndex(-1),
_useDefaultGen(kFALSE)
{
RooLinkedList l ;
l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
l.Add((TObject*)&arg7) ; l.Add((TObject*)&arg8) ;
initializeFromCmdArgList(fullPdfSet,l) ;
}
RooProdPdf::RooProdPdf(const char* name, const char* title,
const RooCmdArg& arg1, const RooCmdArg& arg2,
const RooCmdArg& arg3, const RooCmdArg& arg4,
const RooCmdArg& arg5, const RooCmdArg& arg6,
const RooCmdArg& arg7, const RooCmdArg& arg8) :
RooAbsPdf(name,title),
_cacheMgr(this,10),
_genCode(10),
_cutOff(0),
_pdfList("_pdfList","List of PDFs",this),
_pdfIter(_pdfList.createIterator()),
_extendedIndex(-1),
_useDefaultGen(kFALSE)
{
RooLinkedList l ;
l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
l.Add((TObject*)&arg7) ; l.Add((TObject*)&arg8) ;
initializeFromCmdArgList(RooArgSet(),l) ;
}
RooProdPdf::RooProdPdf(const char* name, const char* title, const RooArgSet& fullPdfSet, const RooLinkedList& cmdArgList) :
RooAbsPdf(name,title),
_cacheMgr(this,10),
_genCode(10),
_cutOff(0),
_pdfList("pdfs","List of PDFs",this),
_pdfIter(_pdfList.createIterator()),
_extendedIndex(-1),
_useDefaultGen(kFALSE)
{
initializeFromCmdArgList(fullPdfSet, cmdArgList) ;
}
RooProdPdf::RooProdPdf(const RooProdPdf& other, const char* name) :
RooAbsPdf(other,name),
_cacheMgr(other._cacheMgr,this),
_genCode(other._genCode),
_cutOff(other._cutOff),
_pdfList("pdfs",this,other._pdfList),
_pdfIter(_pdfList.createIterator()),
_extendedIndex(other._extendedIndex),
_useDefaultGen(other._useDefaultGen)
{
TIterator* iter = other._pdfNSetList.MakeIterator() ;
RooArgSet* nset ;
while((nset=(RooArgSet*)iter->Next())) {
_pdfNSetList.Add(nset->snapshot()) ;
}
delete iter ;
}
void RooProdPdf::initializeFromCmdArgList(const RooArgSet& fullPdfSet, const RooLinkedList& l)
{
Int_t numExtended(0) ;
TIterator* siter = fullPdfSet.createIterator() ;
RooAbsPdf* pdf ;
while((pdf=(RooAbsPdf*)siter->Next())) {
_pdfList.add(*pdf) ;
RooArgSet* nset1 = new RooArgSet("nset1") ;
_pdfNSetList.Add(nset1) ;
if (pdf->canBeExtended()) {
_extendedIndex = _pdfList.index(pdf) ;
numExtended++ ;
}
}
delete siter ;
TIterator* iter = l.MakeIterator() ;
RooCmdArg* carg ;
while((carg=(RooCmdArg*)iter->Next())) {
if (!TString(carg->GetName()).CompareTo("Conditional")) {
RooArgSet* pdfSet = (RooArgSet*) carg->getObject(0) ;
RooArgSet* normSet = (RooArgSet*) carg->getObject(1) ;
TIterator* siter2 = pdfSet->createIterator() ;
RooAbsPdf* thePdf ;
while((thePdf=(RooAbsPdf*)siter2->Next())) {
_pdfList.add(*thePdf) ;
_pdfNSetList.Add(normSet->snapshot()) ;
if (thePdf->canBeExtended()) {
_extendedIndex = _pdfList.index(thePdf) ;
numExtended++ ;
}
}
delete siter2 ;
} else if (TString(carg->GetName()).CompareTo("")) {
coutW(InputArguments) << "Unknown arg: " << carg->GetName() << endl ;
}
}
if (numExtended>1) {
coutW(InputArguments) << "RooProdPdf::RooProdPdf(" << GetName()
<< ") WARNING: multiple components with extended terms detected,"
<< " product will not be extendible." << endl ;
_extendedIndex = -1 ;
}
delete iter ;
}
RooProdPdf::~RooProdPdf()
{
_pdfNSetList.Delete() ;
delete _pdfIter ;
}
Double_t RooProdPdf::getVal(const RooArgSet* set) const
{
_curNormSet = (RooArgSet*)set ;
return RooAbsPdf::getVal(set) ;
}
Double_t RooProdPdf::evaluate() const
{
Int_t code ;
RooArgList *plist ;
RooLinkedList *nlist ;
getPartIntList(_curNormSet,0,plist,nlist,code) ;
return calculate(plist,nlist) ;
}
Double_t RooProdPdf::calculate(const RooArgList* partIntList, const RooLinkedList* normSetList) const
{
RooAbsReal* partInt ;
RooArgSet* normSet ;
Double_t value(1.0) ;
Int_t n = partIntList->getSize() ;
Int_t i ;
for (i=0 ; i<n ; i++) {
partInt = ((RooAbsReal*)partIntList->at(i)) ;
normSet = ((RooArgSet*)normSetList->At(i)) ;
Double_t piVal = partInt->getVal(normSet->getSize()>0 ? normSet : 0) ;
value *= piVal ;
if (value<_cutOff) {
break ;
}
}
return value ;
}
void RooProdPdf::factorizeProduct(const RooArgSet& normSet, const RooArgSet& intSet,
RooLinkedList& termList, RooLinkedList& normList,
RooLinkedList& impDepList, RooLinkedList& crossDepList,
RooLinkedList& intList) const
{
_pdfIter->Reset() ;
RooAbsPdf* pdf ;
RooLinkedList depAllList ;
RooLinkedList depIntNoNormList ;
RooArgSet* term(0) ;
RooArgSet* termNormDeps(0) ;
RooArgSet* termAllDeps(0) ;
RooArgSet* termIntDeps(0) ;
RooArgSet* termIntNoNormDeps(0) ;
TIterator* lIter = termList.MakeIterator() ;
TIterator* ldIter = normList.MakeIterator() ;
TIterator* laIter = depAllList.MakeIterator() ;
TIterator* nIter = _pdfNSetList.MakeIterator() ;
RooArgSet* pdfNSet ;
while((pdf=(RooAbsPdf*)_pdfIter->Next())) {
pdfNSet = (RooArgSet*) nIter->Next() ;
lIter->Reset() ;
ldIter->Reset() ;
laIter->Reset() ;
pdfNSet = pdf->getObservables(*pdfNSet) ;
RooArgSet pdfNormDeps ;
RooArgSet pdfAllDeps ;
RooArgSet* tmp = pdf->getObservables(normSet) ;
pdfAllDeps.add(*tmp) ;
delete tmp ;
if (pdfNSet->getSize()>0) {
RooArgSet* tmp2 = (RooArgSet*) pdfAllDeps.selectCommon(*pdfNSet) ;
pdfNormDeps.add(*tmp2) ;
delete tmp2 ;
} else {
pdfNormDeps.add(pdfAllDeps) ;
}
RooArgSet* pdfIntSet = pdf->getObservables(intSet) ;
RooArgSet pdfIntNoNormDeps(*pdfIntSet) ;
pdfIntNoNormDeps.remove(pdfNormDeps,kTRUE,kTRUE) ;
Bool_t done(kFALSE) ;
while((term=(RooArgSet*)lIter->Next())) {
termNormDeps=(RooArgSet*)ldIter->Next() ;
termAllDeps=(RooArgSet*)laIter->Next() ;
Bool_t normOverlap = pdfNormDeps.overlaps(*termNormDeps) ;
if (normOverlap) {
term->add(*pdf) ;
termNormDeps->add(pdfNormDeps,kFALSE) ;
termAllDeps->add(pdfAllDeps,kFALSE) ;
termIntDeps->add(*pdfIntSet,kFALSE) ;
termIntNoNormDeps->add(pdfIntNoNormDeps,kFALSE) ;
done = kTRUE ;
}
}
if (!done) {
term = new RooArgSet("term") ;
termNormDeps = new RooArgSet("termNormDeps") ;
termAllDeps = new RooArgSet("termAllDeps") ;
termIntDeps = new RooArgSet("termIntDeps") ;
termIntNoNormDeps = new RooArgSet("termIntNoNormDeps") ;
term->add(*pdf) ;
termNormDeps->add(pdfNormDeps,kFALSE) ;
termAllDeps->add(pdfAllDeps,kFALSE) ;
termIntDeps->add(*pdfIntSet,kFALSE) ;
termIntNoNormDeps->add(pdfIntNoNormDeps,kFALSE) ;
termList.Add(term) ;
normList.Add(termNormDeps) ;
depAllList.Add(termAllDeps) ;
intList.Add(termIntDeps) ;
depIntNoNormList.Add(termIntNoNormDeps) ;
}
delete pdfNSet ;
delete pdfIntSet ;
}
lIter->Reset() ;
ldIter->Reset() ;
laIter->Reset() ;
TIterator* innIter = depIntNoNormList.MakeIterator() ;
while((term=(RooArgSet*)lIter->Next())) {
RooArgSet* normDeps = (RooArgSet*) ldIter->Next() ;
RooArgSet* allDeps = (RooArgSet*) laIter->Next() ;
RooArgSet* intNoNormDeps = (RooArgSet*) innIter->Next() ;
RooArgSet impDeps(*allDeps) ;
impDeps.remove(*normDeps,kTRUE,kTRUE) ;
impDepList.Add(impDeps.snapshot()) ;
RooArgSet* crossDeps = (RooArgSet*) intNoNormDeps->selectCommon(*normDeps) ;
crossDepList.Add(crossDeps->snapshot()) ;
delete crossDeps ;
}
depAllList.Delete() ;
depIntNoNormList.Delete() ;
delete nIter ;
delete lIter ;
delete ldIter ;
delete laIter ;
delete innIter ;
return ;
}
void RooProdPdf::getPartIntList(const RooArgSet* nset, const RooArgSet* iset,
pRooArgList& partList, pRooLinkedList& nsetList,
Int_t& code, const char* isetRangeName) const
{
Int_t sterileIdx(-1) ;
CacheElem* cache = (CacheElem*) _cacheMgr.getObj(nset,iset,&sterileIdx,RooNameReg::ptr(isetRangeName)) ;
if (cache) {
code = _cacheMgr.lastIndex() ;
partList = &cache->_partList ;
nsetList = &cache->_normList ;
return ;
}
cache = new CacheElem ;
RooLinkedList terms, norms, imp, ints, cross ;
factorizeProduct(nset?(*nset):RooArgSet(),iset?(*iset):RooArgSet(),terms,norms,imp,cross,ints) ;
RooArgSet *norm, *integ, *xdeps ;
RooLinkedList groupedList ;
RooArgSet outerIntDeps ;
groupProductTerms(groupedList,outerIntDeps,terms,norms,imp,ints,cross) ;
TIterator* gIter = groupedList.MakeIterator() ;
RooLinkedList* group ;
while((group=(RooLinkedList*)gIter->Next())) {
if (group->GetSize()==1) {
RooArgSet* term = (RooArgSet*) group->At(0) ;
Int_t termIdx = terms.IndexOf(term) ;
norm=(RooArgSet*) norms.At(termIdx) ;
integ=(RooArgSet*) ints.At(termIdx) ;
xdeps=(RooArgSet*)cross.At(termIdx) ;
RooArgSet termNSet, termISet, termXSet ;
termISet.add(*integ) ;
termNSet.add(*norm) ;
termXSet.add(*xdeps) ;
Bool_t isOwned ;
RooAbsReal* func = processProductTerm(nset,iset,isetRangeName,term,termNSet,termISet,isOwned) ;
if (func) {
cache->_partList.add(*func) ;
if (isOwned) cache->_ownedList.addOwned(*func) ;
cache->_normList.Add(norm->snapshot()) ;
}
} else {
RooArgSet compTermSet, compTermNorm ;
TIterator* tIter = group->MakeIterator() ;
RooArgSet* term ;
while((term=(RooArgSet*)tIter->Next())) {
Int_t termIdx = terms.IndexOf(term) ;
norm=(RooArgSet*) norms.At(termIdx) ;
integ=(RooArgSet*) ints.At(termIdx) ;
xdeps=(RooArgSet*)cross.At(termIdx) ;
RooArgSet termNSet, termISet, termXSet ;
termISet.add(*integ) ;
termNSet.add(*norm) ;
termXSet.add(*xdeps) ;
termISet.remove(outerIntDeps,kTRUE,kTRUE) ;
Bool_t isOwned ;
RooAbsReal* func = processProductTerm(nset,iset,isetRangeName,term,termNSet,termISet,isOwned,kTRUE) ;
if (func) {
compTermSet.add(*func) ;
if (isOwned) cache->_ownedList.addOwned(*func) ;
compTermNorm.add(*norm,kFALSE) ;
}
}
const char* prodname = makeRGPPName("SPECPROD_",compTermSet,outerIntDeps,RooArgSet(),isetRangeName) ;
RooProduct* prodtmp = new RooProduct(prodname,prodname,compTermSet) ;
cache->_ownedList.addOwned(*prodtmp) ;
const char* intname = makeRGPPName("SPECINT_",compTermSet,outerIntDeps,RooArgSet(),isetRangeName) ;
RooRealIntegral* inttmp = new RooRealIntegral(intname,intname,*prodtmp,outerIntDeps,0,0,isetRangeName) ;
cache->_ownedList.addOwned(*inttmp) ;
cache->_partList.add(*inttmp);
cache->_normList.Add(compTermNorm.snapshot()) ;
delete tIter ;
}
}
delete gIter ;
code = _cacheMgr.setObj(nset,iset,(RooAbsCacheElement*)cache,RooNameReg::ptr(isetRangeName)) ;
partList = &cache->_partList ;
nsetList = &cache->_normList;
groupedList.Delete() ;
terms.Delete() ;
ints.Delete() ;
imp.Delete() ;
norms.Delete() ;
cross.Delete() ;
}
void RooProdPdf::groupProductTerms(RooLinkedList& groupedTerms, RooArgSet& outerIntDeps,
const RooLinkedList& terms, const RooLinkedList& norms,
const RooLinkedList& imps, const RooLinkedList& ints, const RooLinkedList& ) const
{
TIterator* tIter = terms.MakeIterator() ;
RooArgSet* term ;
while((term=(RooArgSet*)tIter->Next())) {
RooLinkedList* group = new RooLinkedList ;
group->Add(term) ;
groupedTerms.Add(group) ;
}
delete tIter ;
RooArgSet allImpDeps ;
TIterator* iIter = imps.MakeIterator() ;
RooArgSet *impDeps ;
while((impDeps=(RooArgSet*)iIter->Next())) {
allImpDeps.add(*impDeps,kFALSE) ;
}
delete iIter ;
RooArgSet allIntDeps ;
iIter = ints.MakeIterator() ;
RooArgSet *intDeps ;
while((intDeps=(RooArgSet*)iIter->Next())) {
allIntDeps.add(*intDeps,kFALSE) ;
}
delete iIter ;
RooArgSet* tmp = (RooArgSet*) allIntDeps.selectCommon(allImpDeps) ;
outerIntDeps.removeAll() ;
outerIntDeps.add(*tmp) ;
delete tmp ;
TIterator* oidIter = outerIntDeps.createIterator() ;
TIterator* glIter = groupedTerms.MakeIterator() ;
RooAbsArg* outerIntDep ;
while ((outerIntDep =(RooAbsArg*)oidIter->Next())) {
RooLinkedList* newGroup = 0 ;
RooLinkedList* group ;
glIter->Reset() ;
Bool_t needMerge = kFALSE ;
while((group=(RooLinkedList*)glIter->Next())) {
RooArgSet* term2 ;
TIterator* tIter2 = group->MakeIterator() ;
while((term2=(RooArgSet*)tIter2->Next())) {
Int_t termIdx = terms.IndexOf(term2) ;
RooArgSet* termNormDeps = (RooArgSet*) norms.At(termIdx) ;
RooArgSet* termIntDeps = (RooArgSet*) ints.At(termIdx) ;
RooArgSet* termImpDeps = (RooArgSet*) imps.At(termIdx) ;
if (termNormDeps->contains(*outerIntDep) ||
termIntDeps->contains(*outerIntDep) ||
termImpDeps->contains(*outerIntDep)) {
needMerge = kTRUE ;
}
}
if (needMerge) {
if (newGroup==0) {
newGroup = new RooLinkedList ;
}
tIter2->Reset() ;
while((term2=(RooArgSet*)tIter2->Next())) {
newGroup->Add(term2) ;
}
groupedTerms.Remove(group) ;
delete group ;
}
delete tIter2 ;
}
if (newGroup) {
groupedTerms.Add(newGroup) ;
}
}
delete glIter ;
delete oidIter ;
}
RooAbsReal* RooProdPdf::processProductTerm(const RooArgSet* nset, const RooArgSet* iset, const char* isetRangeName,
const RooArgSet* term,const RooArgSet& termNSet, const RooArgSet& termISet,
Bool_t& isOwned, Bool_t forceWrap) const
{
if (termNSet.getSize()>0 && termNSet.getSize()==termISet.getSize() && isetRangeName==0) {
return 0 ;
}
if (nset && termNSet.getSize()==0) {
return 0 ;
}
if (iset && termISet.getSize()>0) {
if (term->getSize()==1) {
TIterator* pIter = term->createIterator() ;
RooAbsPdf* pdf = (RooAbsPdf*) pIter->Next() ;
delete pIter ;
RooAbsReal* partInt = pdf->createIntegral(termISet,termNSet,isetRangeName) ;
isOwned=kTRUE ;
return partInt ;
} else {
const char* name = makeRGPPName("GENPROJ_",*term,termISet,termNSet,isetRangeName) ;
RooAbsReal* partInt = new RooGenProdProj(name,name,*term,termISet,termNSet,isetRangeName) ;
isOwned=kTRUE ;
return partInt ;
}
}
if (nset && nset->getSize()>0 && term->getSize()>1) {
const char* name = makeRGPPName("GENPROJ_",*term,termISet,termNSet,isetRangeName) ;
RooAbsReal* partInt = new RooGenProdProj(name,name,*term,termISet,termNSet,isetRangeName) ;
isOwned=kTRUE ;
return partInt ;
}
TIterator* pIter = term->createIterator() ;
RooAbsPdf* pdf ;
while((pdf=(RooAbsPdf*)pIter->Next())) {
if (forceWrap) {
TString name(pdf->GetName()) ;
name.Append("_NORM[") ;
TIterator* nIter = termNSet.createIterator() ;
RooAbsArg* arg ;
Bool_t first(kTRUE) ;
while((arg=(RooAbsArg*)nIter->Next())) {
if (!first) {
name.Append(",") ;
} else {
first=kFALSE ;
}
name.Append(arg->GetName()) ;
}
name.Append("]") ;
delete nIter ;
RooAbsReal* partInt = new RooRealIntegral(name.Data(),name.Data(),*pdf,RooArgSet(),&termNSet) ;
isOwned=kTRUE ;
delete pIter ;
return partInt ;
} else {
isOwned=kFALSE ;
delete pIter ;
return pdf ;
}
}
delete pIter ;
coutE(Eval) << "RooProdPdf::processProductTerm(" << GetName() << ") unidentified term!!!" << endl ;
return 0;
}
const char* RooProdPdf::makeRGPPName(const char* pfx, const RooArgSet& term, const RooArgSet& iset,
const RooArgSet& nset, const char* isetRangeName) const
{
static TString pname ;
pname = pfx ;
TIterator* pIter = term.createIterator() ;
Bool_t first(kTRUE) ;
RooAbsPdf* pdf ;
while((pdf=(RooAbsPdf*)pIter->Next())) {
if (first) {
first = kFALSE ;
} else {
pname.Append("_X_") ;
}
pname.Append(pdf->GetName()) ;
}
delete pIter ;
pname.Append(integralNameSuffix(iset,&nset,isetRangeName)) ;
return pname.Data() ;
}
Bool_t RooProdPdf::forceAnalyticalInt(const RooAbsArg& ) const
{
return kTRUE ;
}
Int_t RooProdPdf::getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& analVars,
const RooArgSet* normSet, const char* rangeName) const
{
if (_forceNumInt) return 0 ;
analVars.add(allVars) ;
Int_t code ;
RooArgList *plist ;
RooLinkedList *nlist ;
getPartIntList(normSet,&allVars,plist,nlist,code,rangeName) ;
return code+1 ;
}
Double_t RooProdPdf::analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName) const
{
if (code==0) {
return getVal(normSet) ;
}
CacheElem* cache = (CacheElem*) _cacheMgr.getObjByIndex(code-1) ;
RooArgList* partIntList ;
RooLinkedList* normList ;
if (cache==0) {
RooArgSet* vars = getParameters(RooArgSet()) ;
RooArgSet* nset = _cacheMgr.nameSet1ByIndex(code-1)->select(*vars) ;
RooArgSet* iset = _cacheMgr.nameSet2ByIndex(code-1)->select(*vars) ;
Int_t code2(-1) ;
getPartIntList(nset,iset,partIntList,normList,code2,rangeName) ;
delete vars ;
delete nset ;
delete iset ;
} else {
partIntList = &cache->_partList ;
normList = &cache->_normList ;
}
Double_t val = calculate(partIntList,normList) ;
return val ;
}
Bool_t RooProdPdf::checkObservables(const RooArgSet* ) const
{
return kFALSE ;
}
RooAbsPdf::ExtendMode RooProdPdf::extendMode() const
{
return (_extendedIndex>=0) ? ((RooAbsPdf*)_pdfList.at(_extendedIndex))->extendMode() : CanNotBeExtended ;
}
Double_t RooProdPdf::expectedEvents(const RooArgSet* nset) const
{
if (_extendedIndex<0) {
coutE(Generation) << "ERROR: Requesting expected number of events from a RooProdPdf that does not contain an extended p.d.f" << endl ;
}
assert(_extendedIndex>=0) ;
return ((RooAbsPdf*)_pdfList.at(_extendedIndex))->expectedEvents(nset) ;
}
RooAbsGenContext* RooProdPdf::genContext(const RooArgSet &vars, const RooDataSet *prototype,
const RooArgSet* auxProto, Bool_t verbose) const
{
if (_useDefaultGen) return RooAbsPdf::genContext(vars,prototype,auxProto,verbose) ;
return new RooProdGenContext(*this,vars,prototype,auxProto,verbose) ;
}
Int_t RooProdPdf::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t staticInitOK) const
{
if (!_useDefaultGen) return 0 ;
RooArgSet directSafe ;
TIterator* dIter = directVars.createIterator() ;
RooAbsArg* arg ;
while((arg=(RooAbsArg*)dIter->Next())) {
if (isDirectGenSafe(*arg)) directSafe.add(*arg) ;
}
delete dIter ;
_pdfIter->Reset() ;
RooAbsPdf* pdf ;
Int_t code[64], n(0) ;
while((pdf=(RooAbsPdf*)_pdfIter->Next())) {
RooArgSet pdfDirect ;
code[n] = pdf->getGenerator(directSafe,pdfDirect,staticInitOK) ;
if (code[n]!=0) {
generateVars.add(pdfDirect) ;
}
n++ ;
}
if (generateVars.getSize()>0) {
Int_t masterCode = _genCode.store(code,n) ;
return masterCode+1 ;
} else {
return 0 ;
}
}
void RooProdPdf::initGenerator(Int_t code)
{
if (!_useDefaultGen) return ;
const Int_t* codeList = _genCode.retrieve(code-1) ;
_pdfIter->Reset() ;
RooAbsPdf* pdf ;
Int_t i(0) ;
while((pdf=(RooAbsPdf*)_pdfIter->Next())) {
if (codeList[i]!=0) {
pdf->initGenerator(codeList[i]) ;
}
i++ ;
}
}
void RooProdPdf::generateEvent(Int_t code)
{
if (!_useDefaultGen) return ;
const Int_t* codeList = _genCode.retrieve(code-1) ;
_pdfIter->Reset() ;
RooAbsPdf* pdf ;
Int_t i(0) ;
while((pdf=(RooAbsPdf*)_pdfIter->Next())) {
if (codeList[i]!=0) {
pdf->generateEvent(codeList[i]) ;
}
i++ ;
}
}
RooProdPdf::CacheElem::~CacheElem()
{
_normList.Delete() ;
}
RooArgList RooProdPdf::CacheElem::containedArgs(Action)
{
RooArgList ret ;
ret.add(_partList) ;
return ret ;
}
void RooProdPdf::CacheElem::printCompactTreeHook(ostream& os, const char* indent, Int_t curElem, Int_t maxElem)
{
if (curElem==0) {
os << indent << "RooProdPdf begin partial integral cache" << endl ;
}
TIterator* iter = _partList.createIterator() ;
RooAbsArg* arg ;
TString indent2(indent) ;
indent2 += Form("[%d] ",curElem) ;
while((arg=(RooAbsArg*)iter->Next())) {
arg->printCompactTree(os,indent2) ;
}
delete iter ;
if (curElem==maxElem) {
os << indent << "RooProdPdf end partial integral cache" << endl ;
}
}
Bool_t RooProdPdf::isDirectGenSafe(const RooAbsArg& arg) const
{
if (!_useDefaultGen) return RooAbsPdf::isDirectGenSafe(arg) ;
_pdfIter->Reset() ;
RooAbsPdf* pdf, *thePdf(0) ;
while((pdf=(RooAbsPdf*)_pdfIter->Next())) {
if (pdf->dependsOn(arg)) {
if (thePdf) return kFALSE ;
thePdf = pdf ;
}
}
return thePdf?(thePdf->isDirectGenSafe(arg)):kFALSE ;
}
RooArgSet* RooProdPdf::findPdfNSet(RooAbsPdf& pdf) const
{
Int_t idx = _pdfList.index(&pdf) ;
if (idx<0) return 0 ;
return (RooArgSet*) _pdfNSetList.At(idx) ;
}
RooArgSet* RooProdPdf::getConstraints(const RooArgSet& observables, const RooArgSet& constrainedParams) const
{
RooArgSet* ret = new RooArgSet("constraints") ;
TIterator* piter = _pdfList.createIterator() ;
RooAbsPdf* pdf ;
while((pdf=(RooAbsPdf*)piter->Next())) {
if (!pdf->dependsOnValue(observables) && pdf->dependsOnValue(constrainedParams)) {
ret->add(*pdf) ;
}
}
delete piter ;
return ret ;
}
std::list<Double_t>* RooProdPdf::plotSamplingHint(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi) const
{
_pdfIter->Reset() ;
RooAbsPdf* pdf ;
while((pdf=(RooAbsPdf*)_pdfIter->Next())) {
list<Double_t>* hint = pdf->plotSamplingHint(obs,xlo,xhi) ;
if (hint) {
return hint ;
}
}
return 0 ;
}
Last change: Tue Nov 11 12:36:58 2008
Last generated: 2008-11-11 12:36
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.