76using std::endl, std::string, std::vector, std::list, std::ostream, std::map, std::ostringstream;
114 _pdfList(
"!pdfs",
"List of PDFs",this)
117 _pdfNSetList.emplace_back(std::make_unique<RooArgSet>(
"nset")) ;
119 _extendedIndex = _pdfList.index(&pdf1) ;
123 _pdfNSetList.emplace_back(std::make_unique<RooArgSet>(
"nset")) ;
126 if (_extendedIndex>=0) {
128 coutW(InputArguments) <<
"RooProdPdf::RooProdPdf(" << GetName()
129 <<
") multiple components with extended terms detected,"
130 <<
" product will not be extendable." << std::endl ;
133 _extendedIndex=_pdfList.index(&pdf2) ;
162 _pdfList(
"!pdfs",
"List of PDFs",this)
210 _pdfList(
"!pdfs",
"List of PDFs",this)
234 _pdfList(
"!pdfList",
"List of PDFs",this)
254 _pdfList(
"!pdfs",
"List of PDFs",this)
279 _pdfNSetList.emplace_back(std::make_unique<RooArgSet>(nset->GetName()));
280 nset->snapshot(*_pdfNSetList.back());
293 Int_t numExtended(0) ;
298 _pdfNSetList.emplace_back(std::make_unique<RooArgSet>(
"nset")) ;
300 if (pdf->canBeExtended()) {
310 if (0 == strcmp(carg->GetName(),
"Conditional")) {
312 Int_t argType = carg->getInt(0) ;
313 auto pdfSet =
static_cast<RooArgSet const*
>(carg->getSet(0));
314 auto normSet =
static_cast<RooArgSet const*
>(carg->getSet(1));
319 _pdfNSetList.emplace_back(std::make_unique<RooArgSet>(0 == argType ?
"nset" :
"cset"));
322 if (thePdf->canBeExtended()) {
329 }
else if (0 != strlen(carg->GetName())) {
330 coutW(InputArguments) <<
"Unknown arg: " << carg->GetName() << std::endl ;
336 coutW(InputArguments) <<
"RooProdPdf::RooProdPdf(" <<
GetName()
337 <<
") WARNING: multiple components with extended terms detected,"
338 <<
" product will not be extendable." << std::endl ;
387 cxcoutD(Eval) <<
"RooProdPdf::calculate(" <<
GetName() <<
") rearranged product calculation"
401 const auto normSet = cache.
_normList[i].get();
403 const double piVal = partInt.getVal(!normSet->empty() ? normSet :
nullptr);
415void eraseNullptrs(std::vector<T*>&
v) {
416 v.erase(std::remove_if(
v.begin(),
v.end(), [](T*
x){ return x == nullptr; } ),
v.end());
419void removeCommon(std::vector<RooAbsArg*> &
v, std::span<RooAbsArg * const> other) {
421 for (
auto const& arg : other) {
422 auto namePtrMatch = [&arg](
const RooAbsArg* elm) {
423 return elm !=
nullptr && elm->namePtr() == arg->namePtr();
426 auto found = std::find_if(
v.begin(),
v.end(), namePtrMatch);
427 if(found !=
v.end()) {
434void addCommon(std::vector<RooAbsArg*> &
v, std::vector<RooAbsArg*>
const& o1, std::vector<RooAbsArg*>
const& o2) {
436 for (
auto const& arg : o1) {
437 auto namePtrMatch = [&arg](
const RooAbsArg* elm) {
438 return elm->namePtr() == arg->namePtr();
441 if(std::find_if(o2.begin(), o2.end(), namePtrMatch) != o2.end()) {
450 const char *range = normRange.
Length() > 0 ? normRange.
Data() :
nullptr;
453 if (normObs->getMin(range) != normObs->getMin(refRange) || normObs->getMax(range) != normObs->getMax(refRange))
468 std::vector<RooArgSet> depAllList;
469 std::vector<RooArgSet> depIntNoNormList;
476 std::vector<RooAbsArg*> pdfIntNoNormDeps;
477 std::vector<RooAbsArg*> pdfIntSet;
478 std::vector<RooAbsArg*> pdfNSet;
479 std::vector<RooAbsArg*> pdfCSet;
480 std::vector<RooAbsArg*> pdfNormDeps;
481 std::vector<RooAbsArg*> pdfAllDeps;
484 for(std::size_t iPdf = 0; iPdf <
_pdfList.size(); ++iPdf) {
495 RooArgSet pdfLeafList(
"leafNodeServerList") ;
497 auto getObservablesOfCurrentPdf = [&pdfLeafList](
498 std::vector<RooAbsArg*> & out,
500 for (
const auto arg : pdfLeafList) {
501 if (arg->dependsOnValue(dataList) && arg->isLValue()) {
508 if (0 == strcmp(
"cset", pdfNSetOrig.
GetName())) {
509 getObservablesOfCurrentPdf(pdfNSet, normSet);
510 removeCommon(pdfNSet, pdfNSetOrig.
get());
511 pdfCSet = pdfNSetOrig.
get();
514 getObservablesOfCurrentPdf(pdfNSet, pdfNSetOrig);
522 getObservablesOfCurrentPdf(pdfAllDeps, normSet);
528 if (!pdfNSet.empty()) {
530 addCommon(pdfNormDeps, pdfAllDeps, pdfNSet);
533 pdfNormDeps = pdfAllDeps;
539 getObservablesOfCurrentPdf(pdfIntSet, intSet) ;
542 if (pdfNormDeps.empty() && !pdfCSet.empty()) {
543 removeCommon(pdfIntSet, pdfCSet);
547 pdfIntNoNormDeps.clear();
548 pdfIntNoNormDeps = pdfIntSet;
549 removeCommon(pdfIntNoNormDeps, pdfNormDeps);
558 for(;lIter != factorized.
terms.
end(); (++lIter, ++ldIter, ++j)) {
567 bool normOverlap = termNormDeps->
overlaps(pdfNormDeps.begin(), pdfNormDeps.end());
574 termNormDeps->
add(pdfNormDeps.begin(), pdfNormDeps.end(),
false);
575 depAllList[j].add(pdfAllDeps.begin(), pdfAllDeps.end(),
false);
577 termIntDeps->
add(pdfIntSet.begin(), pdfIntSet.end(),
false);
579 if (termIntNoNormDeps) {
580 termIntNoNormDeps->
add(pdfIntNoNormDeps.begin(), pdfIntNoNormDeps.end(),
false);
582 termIntNoNormDeps->
add(pdfIntNoNormDeps.begin(), pdfIntNoNormDeps.end(),
false);
589 if (!(pdfNormDeps.empty() && pdfAllDeps.empty() &&
590 pdfIntSet.empty()) || normSet.
empty()) {
593 depAllList.emplace_back(pdfAllDeps.begin(), pdfAllDeps.end(),
"termAllDeps");
594 termIntDeps =
new RooArgSet(pdfIntSet.begin(), pdfIntSet.end(),
"termIntDeps");
595 depIntNoNormList.emplace_back(pdfIntNoNormDeps.begin(), pdfIntNoNormDeps.end(),
"termIntNoNormDeps");
596 termIntNoNormDeps = &depIntNoNormList.back();
599 termNormDeps->
add(pdfNormDeps.begin(), pdfNormDeps.end(),
false);
603 factorized.
ints.
Add(termIntDeps);
614 for(;lIter != factorized.
terms.
end(); (++lIter, ++ldIter, ++i)) {
615 normDeps =
static_cast<RooArgSet*
>(*ldIter);
619 impDeps.
remove(*normDeps,
true,
true);
627 auto crossDeps = std::unique_ptr<RooAbsCollection>{depIntNoNormList[i].selectCommon(*normDeps)};
647 Int_t sterileIdx(-1);
653 std::unique_ptr<CacheElem> cache =
createCacheElem(nset, iset, isetRangeName);
663 const char* isetRangeName)
const
671 auto cache = std::make_unique<CacheElem>();
682 std::list<std::vector<RooArgSet*>> groupedList;
689 std::map<std::string, RooArgSet> ratioTerms;
690 for (
auto const&
group : groupedList) {
691 if (1 ==
group.size()) {
712 std::ostringstream str; termImpSet.
printValue(str);
714 ratioTerms[str.str()].addOwned(std::move(ratio));
721 for (
auto const& term :
group) {
735 std::ostringstream str; termImpSet.
printValue(str);
736 ratioTerms[str.str()].addOwned(std::move(ratio));
746 for (
auto const&
group : groupedList) {
747 for (
auto const& term :
group) {
756 if (!ratioTerms[str.str()].empty()) {
758 term->add(ratioTerms[str.str()]);
759 cache->_ownedList.addOwned(std::move(ratioTerms[str.str()]));
764 for (
auto const&
group : groupedList) {
768 if (1 ==
group.size()) {
788 cache->_partList.add(*func.x0);
789 if (func.isOwned) cache->_ownedList.addOwned(std::unique_ptr<RooAbsArg>{func.x0});
791 cache->_normList.emplace_back(std::make_unique<RooArgSet>());
792 norm->
snapshot(*cache->_normList.back(),
false);
794 cache->_numList.
addOwned(std::move(func.x1));
795 cache->_denList.addOwned(std::move(func.x2));
803 for (
auto const &term :
group) {
817 termISet.
remove(outerIntDeps,
true,
true);
819 auto func =
processProductTerm(nset, iset, isetRangeName, term, termNSet, termISet,
true);
822 compTermSet.
add(*func.x0);
823 if (func.isOwned) cache->_ownedList.addOwned(std::unique_ptr<RooAbsArg>{func.x0});
824 compTermNorm.
add(*norm,
false);
826 compTermNum.
add(*func.x1.release());
827 compTermDen.
add(*func.x2.release());
843 const std::string prodname =
makeRGPPName(
"SPECPROD", compTermSet, outerIntDeps,
RooArgSet(), isetRangeName);
844 auto prodtmp = std::make_unique<RooProduct>(prodname.c_str(), prodname.c_str(), compTermSet);
846 const std::string intname =
makeRGPPName(
"SPECINT", compTermSet, outerIntDeps,
RooArgSet(), isetRangeName);
847 auto inttmp = std::make_unique<RooRealIntegral>(intname.c_str(), intname.c_str(), *prodtmp, outerIntDeps,
nullptr,
nullptr, isetRangeName);
848 inttmp->setStringAttribute(
"PROD_TERM_TYPE",
"SPECINT");
850 cache->_partList.add(*inttmp);
854 auto prodtmp_num = std::make_unique<RooProduct>(prodname_num.c_str(), prodname_num.c_str(), compTermNum);
855 prodtmp_num->addOwnedComponents(compTermNum);
859 auto prodtmp_den = std::make_unique<RooProduct>(prodname_den.c_str(), prodname_den.c_str(), compTermDen);
860 prodtmp_den->addOwnedComponents(compTermDen);
863 std::string
name =
Form(
"SPEC_RATIO(%s,%s)", prodname_num.c_str(), prodname_den.c_str());
864 auto ndr = std::make_unique<RooFormulaVar>(
name.c_str(),
"@0/@1",
RooArgList(*prodtmp_num, *prodtmp_den));
867 std::unique_ptr<RooAbsReal> numtmp{ndr->createIntegral(outerIntDeps,isetRangeName)};
868 numtmp->addOwnedComponents(std::move(ndr));
870 cache->_ownedList.addOwned(std::move(prodtmp));
871 cache->_ownedList.addOwned(std::move(inttmp));
872 cache->_ownedList.addOwned(std::move(prodtmp_num));
873 cache->_ownedList.addOwned(std::move(prodtmp_den));
874 cache->_numList.addOwned(std::move(numtmp));
876 cache->_normList.emplace_back(std::make_unique<RooArgSet>());
877 compTermNorm.
snapshot(*cache->_normList.back(),
false);
906 std::unique_ptr<RooAbsReal> ratio_num{pdf.
createIntegral(termNset,normRangeTmp)};
907 std::unique_ptr<RooAbsReal> ratio_den{pdf.
createIntegral(termNset,refRange)};
908 auto ratio = std::make_unique<RooFormulaVar>(
Form(
"ratio(%s,%s)",ratio_num->GetName(),ratio_den->GetName()),
"@0/@1",
911 ratio->addOwnedComponents(std::move(ratio_num));
912 ratio->addOwnedComponents(std::move(ratio_den));
913 ratio->setAttribute(
"RATIO_TERM") ;
928 std::map<std::string,RooArgSet> denListList ;
930 string specIntRange ;
955 std::unique_ptr<RooArgSet> components{orig->
getComponents()};
957 if (carg->getAttribute(
"RATIO_TERM")) {
983 if (arg->getAttribute(
"RATIO_TERM")) {
986 origNumTerm.
add(*arg) ;
994 nomList.
add(origNumTerm) ;
1001 for (
auto iter = rangeComps.begin() ; iter != rangeComps.end() ; ++iter) {
1025 if (ratio && parg->dependsOn(*ratio)) {
1044 partCust = cust.
build() ;
1049 partCust = cust.
build();
1059 string name =
Form(
"%s_divided_by_ratio",specializedPartCust->GetName()) ;
1060 auto specIntFinal = std::make_unique<RooFormulaVar>(
name.c_str(),
"@0/@1",
RooArgList(*specializedPartCust,*specializedRatio)) ;
1061 specIntFinal->addOwnedComponents(std::move(specializedPartCust));
1062 specIntFinal->addOwnedComponents(std::move(specializedRatio));
1064 denListList[*iter].addOwned(std::move(specIntFinal));
1085 tmp.
add(*specRatio) ;
1087 auto specDenProd = std::make_unique<RooProduct>(pname.c_str(),pname.c_str(),tmp) ;
1088 std::unique_ptr<RooAbsReal> specInt;
1091 specInt = std::unique_ptr<RooAbsReal>{specDenProd->createIntegral((
static_cast<RooRealIntegral*
>(den))->intVars(),iter->c_str())};
1092 specInt->addOwnedComponents(std::move(specDenProd));
1096 specInt = std::unique_ptr<RooAbsReal>{specDenProd->createIntegral(origInt->
intVars(),iter->c_str())};
1097 specInt->addOwnedComponents(std::move(specDenProd));
1099 throw string(
"this should not happen") ;
1103 string name =
Form(
"%s_divided_by_ratio",specInt->GetName()) ;
1104 auto specIntFinal = std::make_unique<RooFormulaVar>(
name.c_str(),
"@0/@1",
RooArgList(*specInt,*specRatio)) ;
1105 specIntFinal->addOwnedComponents(std::move(specInt));
1106 specIntFinal->addOwnedComponents(std::move(specRatio));
1107 denListList[*iter].addOwned(std::move(specIntFinal));
1118 if (nomList.
empty()) {
1122 string name = std::string{
GetName()} +
"_numerator";
1125 std::unique_ptr<RooAbsReal> numerator = std::make_unique<RooProduct>(
name.c_str(),
name.c_str(),nomList) ;
1129 for (map<string,RooArgSet>::iterator iter = denListList.begin() ; iter != denListList.end() ; ++iter) {
1135 products.
add(*prod_comp) ;
1141 if (!specIntDeps.
empty()) {
1144 string namesr =
Form(
"SPEC_RATIO(%s,%s)",numerator->GetName(),norm->
GetName()) ;
1149 numerator = std::unique_ptr<RooAbsReal>{ndr->
createIntegral(specIntDeps,specIntRange.c_str())};
1178 std::unique_ptr<RooAbsReal> numint_spec{
specializeIntegral(*numint,targetRangeName)};
1180 std::unique_ptr<RooAbsReal>
ret = std::make_unique<RooFormulaVar>(
Form(
"ratio(%s,%s)",numint_spec->GetName(),denint->
GetName()),
"@0/@1",
RooArgList(*numint_spec,*denint)) ;
1181 ret->addOwnedComponents(std::move(numint_spec));
1208 std::stringstream errMsg;
1209 errMsg <<
"specializeIntegral: unknown input type " << input.
ClassName() <<
"::" << input.
GetName();
1210 throw std::runtime_error(errMsg.str());
1222 groupedTerms.emplace_back();
1223 groupedTerms.back().emplace_back(term) ;
1229 allImpDeps.
add(*impDeps,
false) ;
1235 allIntDeps.
add(*intDeps,
false) ;
1239 outerIntDeps.
add(*std::unique_ptr<RooArgSet>{allIntDeps.
selectCommon(allImpDeps)});
1242 for(
RooAbsArg * outerIntDep : outerIntDeps) {
1245 std::vector<RooArgSet*>* newGroup = nullptr ;
1248 bool needMerge = false ;
1249 auto group = groupedTerms.begin();
1250 auto nGroups = groupedTerms.size();
1251 for (
size_t iGroup = 0; iGroup < nGroups; ++iGroup) {
1254 for (
auto const& term2 : *
group) {
1267 if (newGroup==
nullptr) {
1268 groupedTerms.emplace_back() ;
1269 newGroup = &groupedTerms.back() ;
1273 for (
auto& term2 : *
group) {
1274 newGroup->emplace_back(term2) ;
1295 bool forceWrap)
const
1302 if (!termNSet.
empty() && termNSet.
size()==termISet.
size() && isetRangeName==
nullptr) {
1309 if (nset && termNSet.
empty()) {
1314 if (iset && !termISet.
empty()) {
1315 if (term->
size()==1) {
1322 ret.x0 = std::unique_ptr<RooAbsReal>{pdf->
createIntegral(termISet,termNSet,isetRangeName)}.release();
1324 ret.x0->setStringAttribute(
"PROD_TERM_TYPE",
"IIIa") ;
1329 ret.x1 = std::unique_ptr<RooAbsReal>{pdf->
createIntegral(termISet,isetRangeName)};
1340 const std::string
name =
makeRGPPName(
"GENPROJ_",*term,termISet,termNSet,isetRangeName) ;
1341 ret.x0 =
new RooGenProdProj(
name.c_str(),
name.c_str(),*term,termISet,termNSet,isetRangeName) ;
1342 ret.x0->setStringAttribute(
"PROD_TERM_TYPE",
"IIIb") ;
1352 ret.x1 = std::unique_ptr<RooAbsReal>{tmp_prod->
createIntegral(termISet,isetRangeName)};
1361 if (nset && !nset->
empty() && term->
size()>1) {
1364 const std::string
name =
makeRGPPName(
"GENPROJ_",*term,termISet,termNSet,isetRangeName) ;
1365 ret.x0 =
new RooGenProdProj(
name.c_str(),
name.c_str(),*term,termISet,termNSet,isetRangeName,
normRange()) ;
1368 ret.x0->setStringAttribute(
"PROD_TERM_TYPE",
"IVa") ;
1378 ret.x1 = std::unique_ptr<RooAbsReal>{tmp_prod->
createIntegral(termISet,isetRangeName)};
1388 ret.isOwned =
false;
1401 ret.x1 = std::unique_ptr<RooAbsReal>{pdf->createIntegral(
RooArgSet())};
1402 ret.x2 = std::unique_ptr<RooAbsReal>{pdf->createIntegral(termNSet,
normRange())};
1406 coutE(Eval) <<
"RooProdPdf::processProductTerm(" <<
GetName() <<
") unidentified term!!!" << std::endl ;
1417 const RooArgSet& nset,
const char* isetRangeName)
const
1421 std::ostringstream os;
1428 if (!first) os <<
"_X_";
1430 os << pdf->GetName();
1465 const RooArgSet* normSet,
const char* rangeName)
const
1470 analVars.
add(allVars) ;
1498 if (cache==
nullptr) {
1536 coutF(Generation) <<
"Requesting expected number of events from a RooProdPdf that does not contain an extended p.d.f" << std::endl ;
1537 throw std::logic_error(std::string(
"RooProdPdf ") +
GetName() +
" could not be extended.");
1546 coutF(Generation) <<
"Requesting expected number of events from a RooProdPdf that does not contain an extended p.d.f" << std::endl ;
1547 throw std::logic_error(std::string(
"RooProdPdf ") +
GetName() +
" could not be extended.");
1558 const RooArgSet* auxProto,
bool verbose)
const
1576 for (
auto const* arg : directVars) {
1582 std::vector<Int_t> code;
1586 Int_t pdfCode = pdf->getGenerator(directSafe,pdfDirect,staticInitOK);
1587 code.push_back(pdfCode);
1589 generateVars.
add(pdfDirect) ;
1594 if (!generateVars.
empty()) {
1596 return masterCode+1 ;
1612 const std::vector<Int_t>& codeList =
_genCode.retrieve(code-1) ;
1615 if (codeList[i]!=0) {
1616 pdf->initGenerator(codeList[i]) ;
1633 const std::vector<Int_t>& codeList =
_genCode.retrieve(code-1) ;
1636 if (codeList[i]!=0) {
1637 pdf->generateEvent(codeList[i]) ;
1668 os <<
indent <<
"RooProdPdf begin partial integral cache" << std::endl ;
1671 auto indent2 = std::string(
indent) +
"[" + std::to_string(curElem) +
"]";
1673 arg->printCompactTree(os,indent2.c_str()) ;
1676 if (curElem==maxElem) {
1677 os <<
indent <<
"RooProdPdf end partial integral cache" << std::endl ;
1696 if (pdf->dependsOn(arg)) {
1700 if (thePdf)
return false ;
1727 for(
auto arg : pdfs) {
1730 coutW(InputArguments) <<
"RooProdPdf::addPdfs(" <<
GetName() <<
") list arg "
1731 << arg->GetName() <<
" is not a PDF, ignored" << std::endl ;
1742 _pdfNSetList.emplace_back(std::make_unique<RooArgSet>(
"nset"));
1746 if (numExtended>1) {
1747 coutW(InputArguments) <<
"RooProdPdf::addPdfs(" <<
GetName()
1748 <<
") WARNING: multiple components with extended terms detected,"
1749 <<
" product will not be extendable." << std::endl ;
1765 for(
size_t i=0;i <
_pdfList.size(); i++) {
1789 std::vector<TNamed const*> ptrs;
1790 ptrs.reserve(col.
size());
1792 ptrs.push_back(arg->namePtr());
1794 std::sort(ptrs.begin(), ptrs.end());
1798bool sortedNamePtrsOverlap(std::vector<TNamed const*>
const& ptrsA, std::vector<TNamed const*>
const& ptrsB)
1800 auto pA = ptrsA.begin();
1801 auto pB = ptrsB.begin();
1802 while (pA != ptrsA.end() && pB != ptrsB.end()) {
1805 }
else if (*pB < *pA) {
1825std::unique_ptr<RooArgSet>
1828 auto constraints = std::make_unique<RooArgSet>(
"constraints");
1831 auto observablesNamePtrs = sortedNamePtrs(observables);
1832 auto constrainedParamsNamePtrs = sortedNamePtrs(constrainedParams);
1835 for (std::size_t iPdf = 0; iPdf <
_pdfList.size(); ++iPdf) {
1839 pdf->getParameters(
nullptr, tmp);
1844 bool isConstraint =
false;
1847 auto tmpNamePtrs = sortedNamePtrs(tmp);
1859 isConstraint = !sortedNamePtrsOverlap(tmpNamePtrs, observablesNamePtrs) &&
1860 sortedNamePtrsOverlap(tmpNamePtrs, constrainedParamsNamePtrs);
1863 constraints->add(*pdf) ;
1870 tmp.
remove(observables,
false,
true);
1871 pdfParams.
add(tmp,
true) ;
1890 for (std::size_t iPdf = 0; iPdf <
_pdfList.size(); ++iPdf) {
1895 if (
static_cast<int>(iPdf) ==
_extendedIndex || pdf->dependsOn(observables)) {
1897 pdf->getParameters(&observables, tmp);
1898 connectedPars->
add(tmp) ;
1901 return connectedPars ;
1935 if (std::list<double>* hint = pdf->plotSamplingHint(obs,xlo,xhi)) {
1951 if (pdf->dependsOn(obs) && !pdf->isBinnedDistribution(obs)) {
1970 if (std::list<double>* hint = pdf->binBoundaries(obs,xlo,xhi)) {
1988 if (parg->canNodeBeCached()==
Always) {
1989 trackNodes.
add(*parg) ;
1996 if (
string(
"nset")==pdf_nset->GetName() && !pdf_nset->empty()) {
1999 if (
string(
"cset")==pdf_nset->GetName()) {
2003 coutW(Optimization) <<
"RooProdPdf::setCacheAndTrackHints(" <<
GetName() <<
") WARNING product pdf does not specify a normalization set for component " << parg->GetName() << std::endl ;
2017 for (std::size_t i=0 ; i<
_pdfList.size() ; i++) {
2018 if (i>0) os <<
" * " ;
2021 if (!ncset->
empty()) {
2022 if (
string(
"nset")==ncset->
GetName()) {
2027 for (
auto const* arg : *ncset) {
2033 os << arg->GetName() ;
2048 if (nameChange &&
_pdfList.find(
"REMOVAL_DUMMY")) {
2050 cxcoutD(LinkStateMgmt) <<
"RooProdPdf::redirectServersHook(" <<
GetName() <<
"): removing REMOVAL_DUMMY" << std::endl ;
2065 for(std::unique_ptr<RooArgSet>
const& normSet :
_pdfNSetList) {
2067 if(
RooAbsArg * newArg = arg->findNewServer(newServerList, nameChange)) {
2069 normSet->replace(arg, std::unique_ptr<RooAbsArg>{newArg->cloneTree()});
2079 os <<
"_partList\n";
2085 os <<
"_ownedList\n";
2087 os <<
"_normList\n";
2091 os <<
"_isRearranged" <<
"\n";
2093 os <<
"_rearrangedNum" <<
"\n";
2097 os <<
"nullptr" <<
"\n";
2099 os <<
"_rearrangedDen" <<
"\n";
2103 os <<
"nullptr" <<
"\n";
2109 if (normSet.
empty())
2112 if (pdfNset && !pdfNset->empty()) {
2113 std::unique_ptr<RooArgSet> out;
2114 if (0 == strcmp(
"cset", pdfNset->GetName())) {
2118 out = std::make_unique<RooArgSet>(normSet);
2120 out->selectCommon(*pdfNset, common);
2121 out->remove(common);
2123 out = std::make_unique<RooArgSet>(*pdfNset);
2128 if (!arg->getStringAttribute(
"__prefix__")) {
2129 arg->SetName((std::string(prefix) + arg->GetName()).c_str());
2130 arg->setStringAttribute(
"__prefix__", prefix);
2140std::unique_ptr<RooAbsArg>
2145 if (binnedInfo.binnedPdf && binnedInfo.binnedPdf !=
this) {
2146 return binnedInfo.binnedPdf->compileForNormSet(normSet, ctx);
2150 std::unique_ptr<RooProdPdf> prodPdfClone{
static_cast<RooProdPdf *
>(this->
Clone())};
2153 for (
const auto server : prodPdfClone->servers()) {
2155 RooArgSet const &nset = nsetForServer ? *nsetForServer : normSet;
2158 server->getObservables(&nset, depList);
2163 auto fixedProdPdf = std::make_unique<RooFit::Detail::RooFixedProdPdf>(std::move(prodPdfClone), normSet);
2166 return fixedProdPdf;
2174 _servers(
"!servers",
"List of servers", this),
2182 cache->_ownedList.releaseOwnership();
2183 cache->_numList.releaseOwnership();
2184 cache->_denList.releaseOwnership();
2193 _servers.add(*cache->_rearrangedNum);
2194 _servers.add(*cache->_rearrangedDen);
2199 for (
RooAbsArg *arg : cache->_partList) {
2224 std::vector<std::span<const double>> factors;
2227 auto span = ctx.
at(arg);
2228 factors.push_back(span);
2230 std::array<double, 1> special{
static_cast<double>(factors.size())};
2242 value *= arg->getVal();
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
std::string getColonSeparatedNameString(RooArgSet const &argSet, char delim=':')
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
static void indent(ostringstream &buf, int indent_level)
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
RooExpensiveObjectCache & expensiveObjectCache() const
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
friend class RooRealIntegral
RooFit::OwningPtr< RooArgSet > getComponents() const
Create a RooArgSet with all components (branch nodes) of the expression tree headed by this object.
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
RooAbsArg()
Default constructor.
friend class RooAbsCollection
void treeNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=nullptr, bool doBranch=true, bool doLeaf=true, bool valueOnly=false, bool recurseNonDerived=false) const
Fill supplied list with nodes of the arg tree, following all server links, starting with ourself as t...
OperMode operMode() const
Query the operation mode of this node.
Abstract container object that can hold multiple RooAbsArg objects.
bool contains(const char *name) const
Check if collection contains an argument with a specific name.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
Storage_t const & get() const
Const access to the underlying stl container.
void printValue(std::ostream &os) const override
Print value of collection, i.e.
const char * GetName() const override
Returns name of object.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
bool overlaps(Iterator_t otherCollBegin, Iterator_t otherCollEnd) const
Storage_t::size_type size() const
RooAbsArg * first() const
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.
TString _normRange
Normalization range.
virtual bool isDirectGenSafe(const RooAbsArg &arg) const
Check if given observable can be safely generated using the pdfs internal generator mechanism (if tha...
RooArgSet const * _normSet
! Normalization set with for above integral
bool canBeExtended() const
If true, PDF can provide extended likelihood term.
const char * normRange() const
RooAbsPdf()
Default constructor.
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursiveStep) override
Hook function intercepting redirectServer calls.
virtual RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype=nullptr, const RooArgSet *auxProto=nullptr, bool verbose=false) const
Interface function to create a generator context from a p.d.f.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
bool _forceNumInt
Force numerical integration if flag set.
TString integralNameSuffix(const RooArgSet &iset, const RooArgSet *nset=nullptr, const char *rangeName=nullptr, bool omitEmpty=false) const
Construct string with unique suffix name to give to integral object that encodes integrated observabl...
RooFit::OwningPtr< RooAbsReal > createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Create an object that represents the integral of the function over one or more observables listed in ...
Calculates the sum of a set of RooAbsReal terms, or when constructed with two sets,...
const RooArgList & list1() const
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
RooArgSet * selectCommon(const RooAbsCollection &refColl) const
Use RooAbsCollection::selecCommon(), but return as RooArgSet.
Named container for two doubles, two integers two object points and three string pointers that can be...
TObject * clone(const char *newname=nullptr) const override
RooCustomizer is a factory class to produce clones of a prototype composite PDF object with the same ...
void replaceArg(const RooAbsArg &orig, const RooAbsArg &subst)
Replace any occurrence of arg 'orig' with arg 'subst'.
RooAbsArg * build(const char *masterCatState, bool verbose=false)
Build a clone of the prototype executing all registered 'replace' rules and 'split' rules for the mas...
void markAsCompiled(RooAbsArg &arg) const
bool likelihoodMode() const
void compileServer(RooAbsArg &server, RooAbsArg &arg, RooArgSet const &normSet)
RooFixedProdPdf(std::unique_ptr< RooProdPdf > &&prodPdf, RooArgSet const &normSet)
RooArgSet const * partList() const
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
void doEval(RooFit::EvalContext &ctx) const override
Evaluate product of PDFs in batch mode.
std::unique_ptr< RooProdPdf > _prodPdf
RooAbsReal const * rearrangedDen() const
RooAbsReal const * rearrangedNum() const
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::span< double > output()
RooBatchCompute::Config config(RooAbsArg const *arg) const
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
TObject * At(int index) const
Return object stored in sequential position given by index.
RooLinkedListIterImpl end() const
virtual void Add(TObject *arg)
RooLinkedListIterImpl begin() const
Int_t IndexOf(const char *name) const
Return position of given object in list.
static const char * str(const TNamed *ptr)
Return C++ string corresponding to given TNamed pointer.
static const TNamed * ptr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
RooArgList containedArgs(Action) override
Return RooAbsArg components contained in the cache.
std::unique_ptr< RooAbsReal > _rearrangedNum
void printCompactTreeHook(std::ostream &, const char *, Int_t, Int_t) override
Hook function to print cache contents in tree printing of RooProdPdf.
std::vector< std::unique_ptr< RooArgSet > > _normList
std::unique_ptr< RooAbsReal > _rearrangedDen
void writeToStream(std::ostream &os) const
Efficient implementation of a product of PDFs of the form.
std::unique_ptr< RooArgSet > getConstraints(const RooArgSet &observables, RooArgSet const &constrainedParams, RooArgSet &pdfParams) const override
Return all parameter constraint p.d.f.s on parameters listed in constrainedParams.
void setCacheAndTrackHints(RooArgSet &) override
Label OK'ed components of a RooProdPdf with cache-and-track, and label all RooProdPdf descendants wit...
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const override
Query internal generation capabilities of component p.d.f.s and aggregate capabilities into master co...
void rearrangeProduct(CacheElem &) const
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Return analytical integral defined by given scenario code.
~RooProdPdf() override
Destructor.
Int_t _extendedIndex
Index of extended PDF (if any).
std::unique_ptr< RooAbsReal > specializeRatio(RooFormulaVar &input, const char *targetRangeName) const
RooProdPdf()
Default constructor.
void removePdfs(RooAbsCollection const &pdfs)
Remove some PDFs from the factors of this RooProdPdf.
bool _useDefaultGen
Use default or distributed event generator.
std::vector< std::unique_ptr< RooArgSet > > _pdfNSetList
List of PDF component normalization sets.
std::unique_ptr< RooArgSet > fillNormSetForServer(RooArgSet const &normSet, RooAbsArg const &server) const
std::unique_ptr< RooAbsReal > specializeIntegral(RooAbsReal &orig, const char *targetRangeName) const
void factorizeProduct(const RooArgSet &normSet, const RooArgSet &intSet, Factorized &factorized) const
Factorize product in irreducible terms for given choice of integration/normalization.
bool forceAnalyticalInt(const RooAbsArg &dep) const override
Force RooRealIntegral to offer all observables for internal integration.
std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const override
RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype=nullptr, const RooArgSet *auxProto=nullptr, bool verbose=false) const override
Return generator context optimized for generating events from product p.d.f.s.
TNamed * _refRangeName
Reference range name for interpretation of conditional products.
RooAICRegistry _genCode
! Registry of composite direct generator codes
void addPdfs(RooAbsCollection const &pdfs)
Add some full PDFs to the factors of this RooProdPdf.
RooListProxy _pdfList
List of PDF components.
Int_t getPartIntList(const RooArgSet *nset, const RooArgSet *iset, const char *isetRangeName=nullptr) const
Return list of (partial) integrals of product terms for integration of p.d.f over observables iset wh...
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooProdPdf to more intuitively reflect the contents of the prod...
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Forward the plot sampling hint from the p.d.f. that defines the observable obs.
RooObjCacheManager _cacheMgr
! The cache manager
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().
bool isDirectGenSafe(const RooAbsArg &arg) const override
Forward determination of safety of internal generator code to component p.d.f that would generate the...
ProcessProductTermOutput processProductTerm(const RooArgSet *nset, const RooArgSet *iset, const char *isetRangeName, const RooArgSet *term, const RooArgSet &termNSet, const RooArgSet &termISet, bool forceWrap=false) const
Calculate integrals of factorized product terms over observables iset while normalized to observables...
std::unique_ptr< RooAbsReal > makeCondPdfRatioCorr(RooAbsReal &term, const RooArgSet &termNset, const RooArgSet &termImpSet, const char *normRange, const char *refRange) const
For single normalization ranges.
RooArgSet * findPdfNSet(RooAbsPdf const &pdf) const
Look up user specified normalization set for given input PDF component.
ExtendMode extendMode() const override
If this product contains exactly one extendable p.d.f return the extension abilities of that p....
std::list< double > * plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const override
Forward the plot sampling hint from the p.d.f. that defines the observable obs.
double expectedEvents(const RooArgSet *nset) const override
Return the expected number of events associated with the extendable input PDF in the product.
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Determine which part (if any) of given integral can be performed analytically.
bool isBinnedDistribution(const RooArgSet &obs) const override
If all components that depend on obs are binned that so is the product.
friend class RooProdGenContext
RooArgSet * getConnectedParameters(const RooArgSet &observables) const
Return all parameter constraint p.d.f.s on parameters listed in constrainedParams.
double calculate(const RooProdPdf::CacheElem &cache, bool verbose=false) const
Calculate running product of pdfs terms, using the supplied normalization set in 'normSetList' for ea...
RooArgSet _defNormSet
Default normalization set.
std::unique_ptr< RooAbsReal > createExpectedEventsFunc(const RooArgSet *nset) const override
Returns an object that represents the expected number of events for a given normalization set,...
CacheElem * getCacheElem(RooArgSet const *nset) const
bool redirectServersHook(const RooAbsCollection &, bool, bool, bool) override
Implement support for node removal.
void groupProductTerms(std::list< std::vector< RooArgSet * > > &groupedTerms, RooArgSet &outerIntDeps, Factorized const &factorized) const
Group product into terms that can be calculated independently.
void initGenerator(Int_t code) override
Forward one-time initialization call to component generation initialization methods.
void generateEvent(Int_t code) override
Generate a single event with configuration specified by 'code' Defer internal generation to component...
void fixRefRange(const char *rangeName)
std::unique_ptr< CacheElem > createCacheElem(const RooArgSet *nset, const RooArgSet *iset, const char *isetRangeName=nullptr) const
double evaluate() const override
Calculate current value of object.
void initializeFromCmdArgList(const RooArgSet &fullPdfSet, const RooLinkedList &l)
Initialize RooProdPdf configuration from given list of RooCmdArg configuration arguments and set of '...
void selectNormalizationRange(const char *rangeName=nullptr, bool force=false) override
Interface function used by test statistics to freeze choice of range for interpretation of conditiona...
bool _selfNorm
Is self-normalized.
double _cutOff
Cutoff parameter for running product.
Represents the product of a given set of RooAbsReal objects.
RooArgSet intVars() const
const RooAbsReal & integrand() const
const char * intRange() const
The TNamed class is the base class for all named ROOT classes.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
Mother of all ROOT objects.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
const char * Data() const
RooConstVar & RooConst(double val)
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
void compute(Config cfg, Computer comp, std::span< double > output, VarSpan vars, ArgSpan extraArgs={})
BinnedLOutput getBinnedL(RooAbsPdf const &pdf)
std::string getColonSeparatedNameString(RooArgSet const &argSet, char delim=':')
RooArgSet * termNormDeps(int i) const
RooArgSet * termImpDeps(int i) const
RooArgSet * termIntDeps(int i) const
RooArgSet * termCrossDeps(int i) const