106#include <sys/types.h>
112class ScaledDataWeightedAverage :
public RooAbsFunc {
115 :
RooAbsFunc{1}, _var{var}, _dataWeights{
data.getWeightBatch(0,
data.numEntries())}, _scaleFactor{scaleFactor}
118 _arg->recursiveRedirectServers(
RooArgList{var});
119 _evaluator = std::make_unique<RooFit::Evaluator>(*_arg);
120 std::stack<std::vector<double>>{}.swap(_vectorBuffers);
124 for (
auto const& item : dataSpans) {
125 _evaluator->setInput(item.first->GetName(), item.second,
false);
129 double operator()(
const double xvector[])
const override
131 double oldVal = _var.getVal();
132 _var.setVal(xvector[0]);
135 std::span<const double> pdfValues = _evaluator->run();
136 if (_dataWeights.empty()) {
137 out = std::accumulate(pdfValues.begin(), pdfValues.end(), 0.0) / pdfValues.size();
139 double weightsSum = 0.0;
140 for (std::size_t i = 0; i < pdfValues.size(); ++i) {
141 out += pdfValues[i] * _dataWeights[i];
142 weightsSum += _dataWeights[i];
156 std::unique_ptr<RooAbsReal> _arg;
157 std::span<const double> _dataWeights;
159 std::unique_ptr<RooFit::Evaluator> _evaluator;
160 std::stack<std::vector<double>> _vectorBuffers;
202 double inMaxVal,
const char *unit) :
203 RooAbsArg(
name,title), _plotMin(inMinVal), _plotMax(inMaxVal), _unit(unit)
213 RooAbsArg(other,
name), _plotMin(other._plotMin), _plotMax(other._plotMax),
214 _plotBins(other._plotBins), _value(other._value), _unit(other._unit), _label(other._label),
215 _forceNumInt(other._forceNumInt), _selectComp(other._selectComp)
254 if (!assumeSameType) {
270 if(appendUnit && 0 != strlen(
getUnit())) {
334 <<
"): validation failed: " <<
value << std::endl ;
354 const RooArgSet* ,
const char* rangeName)
const
385 if (code==0)
return getVal(normSet) ;
399 coutF(Eval) <<
"RooAbsReal::analyticalIntegral(" <<
GetName() <<
") code " << code <<
" not implemented" << std::endl ;
460 os <<
indent <<
"--- RooAbsReal ---" << std::endl;
478 for (
auto const& arg : paramsOfInterest) {
489 auto out = std::make_unique<RooProfileLL>(
name.c_str(),(std::string(
"Profile of ") +
GetTitle()).c_str(),*
this,paramsOfInterest);
524 pc.
defineString(
"rangeName",
"RangeWithName",0,
"",
true) ;
525 pc.
defineSet(
"normSet",
"NormSet",0,
nullptr) ;
526 pc.
defineObject(
"numIntConfig",
"NumIntConfig",0,
nullptr) ;
529 pc.
process(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) ;
535 const char* rangeName = pc.
getString(
"rangeName",
nullptr,
true) ;
560 if (!rangeName || strchr(rangeName,
',')==
nullptr) {
566 std::vector<std::string> tokens =
ROOT::Split(rangeName,
",");
569 std::stringstream errMsg;
570 errMsg <<
GetName() <<
" : integrating with respect to the variables " << iset <<
" on the ranges \"" << rangeName
571 <<
"\" is not possible because the ranges are overlapping";
572 const std::string errMsgString = errMsg.str();
573 coutE(Integration) << errMsgString << std::endl;
574 throw std::invalid_argument(errMsgString);
578 for (
const std::string& token : tokens) {
582 const std::string title = std::string(
"Integral of ") +
GetTitle();
585 auto out = std::make_unique<RooAddition>(fullName.c_str(), title.c_str(), components);
586 out->addOwnedComponents(std::move(components));
587 return RooFit::Detail::owningPtr<RooAbsReal>(std::move(out));
605 std::unique_ptr<RooAbsReal> integral;
610 const std::string title = std::string(
"Integral of ") +
GetTitle();
613 auto out = std::make_unique<RooRealIntegral>(
name.c_str(), title.c_str(), *
this, iset, nset, cfg, rangeName);
614 return RooFit::Detail::owningPtr<RooAbsReal>(std::move(out));
618 while(!iset.
empty()) {
627 if (innerSet.
empty()) {
633 const std::string title = std::string(
"Integral of ") + integrand->
GetTitle();
636 std::unique_ptr<RooAbsReal> innerIntegral = std::move(integral);
639 integral = std::make_unique<RooRealIntegral>(
name.c_str(),title.c_str(),*integrand,innerSet,nset,cfg,rangeName);
643 integral->addOwnedComponents(std::move(innerIntegral));
650 if (integrand ==
this && !iset.
empty()) {
651 coutI(Integration) <<
GetName() <<
" : multidimensional integration over observables with parameterized ranges in terms of other integrated observables detected, using recursive integration strategy to construct final integral" << std::endl ;
655 integrand = integral.get();
663 coutE(Integration) <<
GetName() <<
" : ERROR while defining recursive integral over observables with parameterized integration ranges, please check that integration rangs specify uniquely defined integral " << std::endl;
670 if (cacheParamsStr && strlen(cacheParamsStr)) {
672 std::unique_ptr<RooArgSet> intParams{integral->getVariables()};
676 if (!cacheParams.
empty()) {
677 cxcoutD(Caching) <<
"RooAbsReal::createIntObj(" <<
GetName() <<
") INFO: constructing " << cacheParams.
size()
678 <<
"-dim value cache for integral over " << iset2 <<
" as a function of " << cacheParams <<
" in range " << (rangeName?rangeName:
"<none>") << std::endl ;
680 auto cachedIntegral = std::make_unique<RooCachedReal>(
name.c_str(),
name.c_str(),*integral,cacheParams);
681 cachedIntegral->setInterpolationOrder(2) ;
682 cachedIntegral->addOwnedComponents(std::move(integral));
683 cachedIntegral->setCacheSource(
true) ;
684 if (integral->operMode()==
ADirty) {
685 cachedIntegral->setOperMode(
ADirty) ;
688 return RooFit::Detail::owningPtr<RooAbsReal>(std::move(cachedIntegral));
716 for (
const auto aarg : allObs) {
721 RooAbsBinning& binning = arglv->getBinning(rangeName,
false,
true) ;
730 obsWithParamRange.
add(*aarg) ;
731 obsWithFixedRange.
remove(*aarg) ;
732 obsServingAsRangeParams.
add(loBoundObs,
false) ;
733 obsServingAsRangeParams.
add(hiBoundObs,
false) ;
740 RooArgSet obsWithFixedRangeNP(obsWithFixedRange) ;
741 obsWithFixedRangeNP.
remove(obsServingAsRangeParams) ;
744 RooArgSet obsWithParamRangeNP(obsWithParamRange) ;
745 obsWithParamRangeNP.
remove(obsServingAsRangeParams) ;
749 innerObs.
add(obsWithFixedRangeNP) ;
750 innerObs.
add(obsWithParamRangeNP) ;
767 name.Append(
"_Int[") ;
779 name.Append(rangeName) ;
782 }
else if (!omitEmpty) {
783 name.Append(
"_Int[]") ;
786 if (nset && !nset->
empty()) {
791 name.Append(
"_Norm[") ;
861 for (
const auto arg : dependentVars) {
864 <<
"\" of wrong type: " << arg->
ClassName() << std::endl;
871 <<
"\" is not a dependent and will be ignored." << std::endl;
876 leafNodes.
replace(*found,*arg);
878 leafNodes.
add(*arg) ;
883 for (
const auto lvs : lvDep) {
887 leafNodes.
add(*lvs) ;
894 if(
nullptr != projectedVars && projectedVars->
find(arg->
GetName())) {
896 <<
"\" cannot be both a dependent and a projected variable." << std::endl;
902 if(
nullptr != projectedVars) leafNodes.
remove(*projectedVars,
true);
907 coutE(Plotting) <<
"RooAbsPdf::createPlotProjection(" <<
GetName() <<
") Couldn't deep-clone PDF, abort," << std::endl ;
918 std::unique_ptr<RooArgSet> plotLeafNodes{
static_cast<RooArgSet*
>(leafNodes.
selectCommon(dependentVars))};
923 if(
nullptr != projectedVars) normSet.
add(*projectedVars);
924 if(
nullptr != condObs) {
925 normSet.
remove(*condObs,
true,
true) ;
932 if(
nullptr == projectedVars) projectedVars= ∅
938 title.
Prepend(
"Projection of ");
941 std::unique_ptr<RooAbsReal> projected{theClone->
createIntegral(*projectedVars,normSet,rangeName)};
943 if(
nullptr == projected || !projected->isValid()) {
944 coutE(Plotting) <<
ClassName() <<
"::" <<
GetName() <<
":createPlotProjection: cannot integrate out ";
953 projected->SetName(
name.Data()) ;
954 projected->SetTitle(title.
Data()) ;
958 cloneSet->
addOwned(std::move(projected));
982 double scaleFactor,
const RooArgSet *projectedVars,
bool scaleForDensity,
983 const RooArgSet* condObs,
bool setError)
const
986 if(
nullptr == hist) {
987 coutE(InputArguments) <<
ClassName() <<
"::" <<
GetName() <<
":fillHistogram: no valid histogram to fill" << std::endl;
993 if(hdim != plotVars.
getSize()) {
994 coutE(InputArguments) <<
ClassName() <<
"::" <<
GetName() <<
":fillHistogram: plotVars has the wrong dimension" << std::endl;
1005 if(
nullptr == realVar) {
1007 <<
"\" of type " << var->
ClassName() << std::endl;
1012 <<
":fillHistogram: WARNING: variable is not an explicit dependent: " << realVar->
GetName() << std::endl;
1014 plotClones.
addClone(*realVar,
true);
1024 if (projectedVars) {
1025 allDeps.
add(*projectedVars) ;
1028 coutE(InputArguments) <<
"RooAbsReal::fillHistogram(" <<
GetName() <<
") error in checkObservables, abort" << std::endl ;
1036 cxcoutD(Plotting) <<
"RooAbsReal::fillHistogram(" <<
GetName() <<
") plot projection object is " << projected->
GetName() << std::endl ;
1039 Int_t xbins(0),ybins(1),zbins(1);
1043 TAxis *xaxis =
nullptr;
1044 TAxis *yaxis =
nullptr;
1045 TAxis *zaxis =
nullptr;
1051 assert(
nullptr != zvar &&
nullptr != zaxis);
1052 if (scaleForDensity) {
1060 assert(
nullptr != yvar &&
nullptr != yaxis);
1061 if (scaleForDensity) {
1069 assert(
nullptr != xvar &&
nullptr != xaxis);
1070 if (scaleForDensity) {
1075 coutE(InputArguments) <<
ClassName() <<
"::" <<
GetName() <<
":fillHistogram: cannot fill histogram with "
1076 << hdim <<
" dimensions" << std::endl;
1083 Int_t xbin(0),ybin(0),zbin(0);
1084 Int_t bins= xbins*ybins*zbins;
1085 for(
Int_t bin= 0; bin < bins; bin++) {
1088 if(bin % (xbins*ybins) == 0) {
1094 if(bin % xbins == 0) {
1095 ybin= (ybin%ybins) + 1;
1100 xbin= (xbin%xbins) + 1;
1104 coutE(InputArguments) <<
"RooAbsReal::fillHistogram: Internal Error!" << std::endl;
1110 coutW(Plotting) <<
"WARNING: Function evaluation error(s) at coordinates [x]=" << xvar->
getVal() ;
1111 if (hdim==2)
ccoutW(Plotting) <<
" [y]=" << yvar->
getVal() ;
1112 if (hdim==3)
ccoutW(Plotting) <<
" [z]=" << zvar->
getVal() ;
1113 ccoutW(Plotting) << std::endl ;
1155 bool correctForBinSize,
bool showProgress)
const
1158 if(
nullptr == hist) {
1159 coutE(InputArguments) <<
ClassName() <<
"::" <<
GetName() <<
":fillDataHist: no valid RooDataHist to fill" << std::endl;
1166 coutE(InputArguments) <<
"RooAbsReal::fillDataHist(" <<
GetName() <<
") error in checkObservables, abort" << std::endl ;
1184 if (showProgress && (i%onePct==0)) {
1185 ccoutP(Eval) <<
"." << std::flush ;
1188 double binVal = theClone->
getVal(normSet?normSet:obs)*scaleFactor ;
1189 if (correctForBinSize) {
1192 hist->
set(i, binVal, 0.);
1218 std::vector<RooRealVar*> histVars(3,
nullptr);
1220 for(std::size_t iVar = 0; iVar < varNames.size(); ++iVar) {
1221 if(varNames[iVar].empty())
continue;
1223 std::stringstream errMsg;
1224 errMsg <<
"RooAbsPdf::createHistogram(" <<
GetName() <<
") ERROR more than three variable names passed, but maximum number of supported variables is three";
1225 coutE(Plotting) << errMsg.str() << std::endl;
1226 throw std::invalid_argument(errMsg.str());
1228 auto var =
static_cast<RooRealVar*
>(vars->find(varNames[iVar].c_str()));
1230 std::stringstream errMsg;
1231 errMsg <<
"RooAbsPdf::createHistogram(" <<
GetName() <<
") ERROR variable " << varNames[iVar] <<
" does not exist in argset: " << *vars;
1232 coutE(Plotting) << errMsg.str() << std::endl;
1233 throw std::runtime_error(errMsg.str());
1235 histVars[iVar] = var;
1317 pc.
defineInt(
"intBinning",
"IntrinsicBinning",0,2) ;
1318 pc.
defineInt(
"extended",
"Extended",0,2) ;
1320 pc.
defineSet(
"compSet",
"SelectCompSet",0);
1322 pc.
defineSet(
"projObs",
"ProjectedObservables",0,
nullptr) ;
1325 pc.
defineMutex(
"SelectCompSet",
"SelectCompSpec") ;
1327 pc.
defineMutex(
"IntrinsicBinning",
"BinningName") ;
1328 pc.
defineMutex(
"IntrinsicBinning",
"BinningSpec") ;
1347 auto projObs = pc.
getSet(
"projObs");
1350 bool doScaling = pc.
getInt(
"scaling") ;
1356 if (!pdfSelf && doExtended == 1) {
1357 coutW(InputArguments) <<
"RooAbsReal::createHistogram(" <<
GetName() <<
") WARNING extended mode requested for a non-pdf object, ignored" << std::endl ;
1361 coutW(InputArguments) <<
"RooAbsReal::createHistogram(" <<
GetName() <<
") WARNING extended mode requested for a non-extendable pdf, ignored" << std::endl ;
1364 if (pdfSelf && doExtended==2) {
1366 }
else if(!pdfSelf) {
1370 const char* compSpec = pc.
getString(
"compSpec") ;
1372 bool haveCompSel = ( (compSpec && strlen(compSpec)>0) || compSet) ;
1374 std::unique_ptr<RooBinning> intBinning;
1375 if (doIntBinning>0) {
1380 if (doIntBinning==1) {
1381 coutW(InputArguments) <<
"RooAbsReal::createHistogram(" <<
GetName()
1382 <<
") WARNING, intrinsic model binning requested for histogram, but model does not define bin boundaries, reverting to default binning"<< std::endl ;
1385 if (doIntBinning==2) {
1386 coutI(InputArguments) <<
"RooAbsReal::createHistogram(" <<
GetName()
1387 <<
") INFO: Model has intrinsic binning definition, selecting that binning for the histogram"<< std::endl ;
1389 std::vector<double> edges(bl->size());
1391 for (
auto const& elem : *bl) { edges[i++] = elem ; }
1392 intBinning = std::make_unique<RooBinning>(bl->size()-1,edges.data()) ;
1397 RooCmdConfig::stripCmdList(argListCreate,
"Scaling,ProjectedObservables,IntrinsicBinning,SelectCompSet,SelectCompSpec,Extended") ;
1399 TH1* histo(
nullptr) ;
1402 argListCreate.
Add(&tmp) ;
1418 branchNodeSet.
remove(*arg) ;
1422 std::unique_ptr<RooArgSet> dirSelNodes;
1428 if (!dirSelNodes->empty()) {
1429 coutI(Plotting) <<
"RooAbsPdf::createHistogram(" <<
GetName() <<
") directly selected PDF components: " << *dirSelNodes << std::endl ;
1435 coutE(Plotting) <<
"RooAbsPdf::createHistogram(" <<
GetName() <<
") ERROR: component selection set " << *compSet <<
" does not match any components of p.d.f." << std::endl ;
1437 coutE(Plotting) <<
"RooAbsPdf::createHistogram(" <<
GetName() <<
") ERROR: component selection expression '" << compSpec <<
"' does not select any components of p.d.f." << std::endl ;
1443 double scaleFactor(1.0) ;
1449 fillHistogram(histo,vars,scaleFactor,intObs,doScaling,projObs,
false) ;
1476 for (
unsigned int i = 0; i < branchNodeSet.
size(); ++i) {
1477 const auto arg = branchNodeSet[i];
1479 branchNodeSet.
remove(*arg) ;
1486 for (
const auto arg : branchNodeSet) {
1495 for (
const auto arg : branchNodeSet) {
1496 for (
const auto selNode : *selNodes) {
1497 if (selNode->dependsOn(*arg,
nullptr,
true)) {
1504 for (
const auto arg : branchNodeSet) {
1505 if (arg->
dependsOn(*selNodes,
nullptr,
true)) {
1510 tmp.
remove(*selNodes,
true);
1513 coutI(Plotting) <<
"RooAbsPdf::plotOn(" <<
GetName() <<
") indirectly selected PDF components: " << tmp << std::endl ;
1516 for (
const auto arg : branchNodeSet) {
1517 bool select = selNodes->
find(arg->
GetName()) !=
nullptr;
1671 argList.
Add(&rnorm) ;
1673 std::vector<std::string> rlist;
1677 rlist.emplace_back(rangeNameToken);
1680 for (
const auto& rangeString : rlist) {
1682 rcmd->
setString(0, rangeString.c_str());
1692 pc.
defineString(
"projectionRangeName",
"ProjectionRange",0,
"",
true) ;
1693 pc.
defineString(
"curveNameSuffix",
"CurveNameSuffix",0,
"") ;
1694 pc.
defineString(
"sliceCatState",
"SliceCat",0,
"",
true) ;
1697 pc.
defineSet(
"sliceSet",
"SliceVars",0) ;
1698 pc.
defineObject(
"sliceCatList",
"SliceCat",0,
nullptr,
true) ;
1707 pc.
defineInt(
"doEvalError",
"EvalErrorValue",0,0) ;
1708 pc.
defineInt(
"shiftToZero",
"ShiftToZero",0,0) ;
1709 pc.
defineSet(
"projDataSet",
"ProjData",0) ;
1713 pc.
defineSet(
"errorPars",
"VisualizeError",0) ;
1714 pc.
defineInt(
"linearMethod",
"VisualizeError",0,0) ;
1715 pc.
defineInt(
"binProjData",
"ProjData",0,0) ;
1718 pc.
defineInt(
"numee",
"PrintEvalErrors",0,10) ;
1719 pc.
defineInt(
"rangeAdjustNorm",
"Range",0,0) ;
1720 pc.
defineInt(
"rangeWNAdjustNorm",
"RangeWithName",0,0) ;
1724 pc.
defineInt(
"markerColor",
"MarkerColor",0,-999) ;
1725 pc.
defineInt(
"markerStyle",
"MarkerStyle",0,-999) ;
1727 pc.
defineInt(
"lineColor",
"LineColor",0,-999) ;
1728 pc.
defineInt(
"lineStyle",
"LineStyle",0,-999) ;
1729 pc.
defineInt(
"lineWidth",
"LineWidth",0,-999) ;
1730 pc.
defineInt(
"fillColor",
"FillColor",0,-999) ;
1731 pc.
defineInt(
"fillStyle",
"FillStyle",0,-999) ;
1733 pc.
defineInt(
"curveInvisible",
"Invisible",0,0) ;
1734 pc.
defineInt(
"showProg",
"ShowProgress",0,0) ;
1736 pc.
defineInt(
"interleave",
"NumCPU",1,0) ;
1740 pc.
defineInt(
"moveToBack",
"MoveToBack",0,0) ;
1744 pc.
defineMutex(
"VisualizeError",
"VisualizeErrorData") ;
1758 bool linMethod = pc.
getInt(
"linearMethod") ;
1759 if (!drawOpt.
Contains(
"P") && errFR) {
1780 std::unique_ptr<RooArgSet> sliceSet{sliceSetTmp ?
static_cast<RooArgSet*
>(sliceSetTmp->
Clone()) :
nullptr};
1786 const char* sliceCatState = pc.
getString(
"sliceCatState",
nullptr,
true) ;
1788 if (sliceCatState) {
1792 sliceSet = std::make_unique<RooArgSet>();
1797 auto iter = sliceCatList.
begin();
1798 for (
unsigned int i=0; i < catTokens.size(); ++i) {
1799 if (
auto scat =
static_cast<RooCategory*
>(*iter)) {
1801 scat->setLabel(catTokens[i]) ;
1803 sliceSet->add(*scat,
false) ;
1816 if (vlines==2) vlines=0 ;
1822 if (vlines==2) vlines=0 ;
1842 coutE(InputArguments) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") cannot find existing curve " << o.
addToCurveName <<
" to add to in RooPlot" << std::endl ;
1848 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") Preprocessing: have slice " << *sliceSet << std::endl ;
1853 for (
const auto sliceArg : *sliceSet) {
1856 projectedVars.
remove(*arg) ;
1858 coutI(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") slice variable "
1859 << sliceArg->GetName() <<
" was not projected anyway" << std::endl ;
1862 }
else if (projSet) {
1863 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") Preprocessing: have projSet " << *projSet << std::endl ;
1866 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") Preprocessing: have neither sliceSet nor projSet " << std::endl ;
1871 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") Preprocessing: projectedVars = " << projectedVars << std::endl ;
1901 if ((fillColor != -999 || fillStyle != -999) && !drawOpt.
Contains(
"F")) {
1902 coutW(Plotting) <<
"Fill color or style was set for plotting \"" <<
GetName()
1903 <<
"\", but these only have an effect when 'DrawOption(\"F\")' for fill is used at the same time." << std::endl;
1943 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") have ProjData with observables = " << *o.
projData->
get() << std::endl ;
1946 projDataVars.
add(*tmp) ;
1947 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") have ProjDataSet = " << *o.
projDataSet <<
" will only use this subset of projData" << std::endl ;
1949 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") using full ProjData" << std::endl ;
1954 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") ProjDataVars = " << projDataVars << std::endl ;
1960 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") have input projSet = " << *o.
projSet << std::endl ;
1962 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") calculated projectedVars = " << *o.
projSet << std::endl ;
1969 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") frame->getNormVars() that are also observables = " << sliceSetTmp << std::endl ;
1971 sliceSetTmp.
remove(projectedVars,
true,
true) ;
1976 sliceSetTmp.
remove(*tmp,
true,
true) ;
1979 if (!sliceSetTmp.
empty()) {
1980 coutI(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") plot on "
1981 << frame->
getPlotVar()->
GetName() <<
" represents a slice in " << sliceSetTmp << std::endl ;
1983 sliceSet.
add(sliceSetTmp) ;
1989 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") projectedVars = " << projectedVars <<
" sliceSet = " << sliceSet << std::endl ;
1992 RooArgSet* projDataNeededVars = nullptr ;
1996 projectedVars.
remove(projDataVars,
true,
true) ;
2001 double oldPlotVarVal = plotVar->
getVal();
2004 if (!projectedVars.
empty()) {
2005 coutI(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") plot on " << plotVar->GetName()
2006 <<
" integrates over variables " << projectedVars
2009 if (projDataNeededVars && !projDataNeededVars->
empty()) {
2010 coutI(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") plot on " << plotVar->
GetName()
2011 <<
" averages using data variables " << *projDataNeededVars << std::endl ;
2015 RooArgSet* projectionCompList = nullptr ;
2019 deps.
remove(projectedVars,
true,
true) ;
2020 if (projDataNeededVars) {
2021 deps.
remove(*projDataNeededVars,
true,
true) ;
2023 deps.
remove(*plotVar,
true,
true) ;
2024 deps.
add(*plotVar) ;
2030 coutE(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") error in checkObservables, abort" << std::endl ;
2031 if (projDataNeededVars)
delete projDataNeededVars ;
2036 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") plot projection object is " << projection->
GetName() << std::endl ;
2043 fullNormSet.
add(projectedVars) ;
2044 if (projDataNeededVars && !projDataNeededVars->
empty()) {
2045 fullNormSet.
add(*projDataNeededVars) ;
2048 std::unique_ptr<RooArgSet> projectionComponents(projection->
getComponents());
2049 for(
auto * pdf : dynamic_range_cast<RooAbsPdf*>(*projectionComponents)) {
2051 pdf->selectNormalization(&fullNormSet) ;
2056 if (o.
projData && projDataNeededVars && !projDataNeededVars->
empty()) {
2060 std::unique_ptr<RooAbsData> projDataSelOwned;
2067 if (!sliceDataSet->empty()) {
2069 for(
RooAbsArg * sliceVar : *sliceDataSet) {
2086 if (!cutString.
IsNull()) {
2087 coutI(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") reducing given projection dataset to entries with " << cutString << std::endl ;
2089 projDataSelOwned = std::unique_ptr<RooAbsData>{
const_cast<RooAbsData*
>(o.
projData)->reduce(*projDataNeededVars, cutString.
IsNull() ? nullptr : cutString)};
2090 projDataSel = projDataSelOwned.
get();
2092 <<
") only the following components of the projection data will be used: " << *projDataNeededVars << std::endl ;
2101 if (!
dynamic_cast<RooCategory*
>(arg2)) allCat =
false ;
2105 coutI(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") unbinned projection dataset consist only of discrete variables,"
2106 <<
" performing projection with binned copy for optimization." << std::endl ;
2113 projDataSelOwned = std::make_unique<RooDataHist>(std::string(projDataSel->
GetName()) +
"_binned",
"Binned projection data",*projDataSel->
get(),*projDataSel);
2114 projDataSel = projDataSelOwned.
get();
2118 ScaledDataWeightedAverage scaleBind{*projection, *projDataSel, o.
scaleFactor, *plotVar};
2127 std::string curveName(projection->
GetName()) ;
2130 if (!sliceSet.
empty()) {
2144 curve->
SetName(curveName.c_str()) ;
2195 std::string curveName(projection->
GetName()) ;
2196 if (!sliceSet.
empty()) {
2222 curve->
SetName(curveName.c_str()) ;
2243 if (projDataNeededVars)
delete projDataNeededVars ;
2244 delete projectionCompList ;
2245 plotVar->setVal(oldPlotVarVal);
2265 projectedVars.
remove(*arg) ;
2267 coutI(Plotting) <<
"RooAbsReal::plotSliceOn(" <<
GetName() <<
") slice variable "
2268 << sliceArg->GetName() <<
" was not projected anyway" << std::endl ;
2310 projDataVars.
add(*tmp) ;
2318 coutE(Plotting) <<
"RooAbsReal::plotAsymOn(" <<
GetName()
2319 <<
") function doesn't depend on asymmetry category " << asymCat.
GetName() << std::endl ;
2325 coutE(Plotting) <<
"RooAbsReal::plotAsymOn(" <<
GetName()
2326 <<
") asymmetry category must have 2 or 3 states with index values -1,0,1" << std::endl ;
2340 sliceSetTmp.
remove(projectedVars,
true,
true) ;
2345 sliceSetTmp.
remove(*tmp,
true,
true) ;
2348 if (!sliceSetTmp.
empty()) {
2349 coutI(Plotting) <<
"RooAbsReal::plotAsymOn(" <<
GetName() <<
") plot on "
2350 << frame->
getPlotVar()->
GetName() <<
" represents a slice in " << sliceSetTmp << std::endl ;
2352 sliceSet.
add(sliceSetTmp) ;
2360 RooArgSet* projDataNeededVars = nullptr ;
2363 projectedVars.
remove(projDataVars,
true,
true) ;
2376 if (!projectedVars.
empty()) {
2377 coutI(Plotting) <<
"RooAbsReal::plotAsymOn(" <<
GetName() <<
") plot on " << plotVar->
GetName()
2378 <<
" projects variables " << projectedVars << std::endl ;
2380 if (projDataNeededVars && !projDataNeededVars->
empty()) {
2381 coutI(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") plot on " << plotVar->
GetName()
2382 <<
" averages using data variables "<< *projDataNeededVars << std::endl ;
2390 asymNeg->setIndex(-1) ;
2396 custNeg.replaceArg(asymCat,*asymNeg) ;
2397 std::unique_ptr<RooAbsReal> funcPos{
static_cast<RooAbsReal*
>(custPos.build())};
2398 std::unique_ptr<RooAbsReal> funcNeg{
static_cast<RooAbsReal*
>(custNeg.build())};
2401 RooArgSet *posProjCompList, *negProjCompList ;
2407 depPos.
add(projDataVars) ;
2408 depNeg.
add(projDataVars) ;
2412 if (!posProj || !negProj) {
2413 coutE(Plotting) <<
"RooAbsReal::plotAsymOn(" <<
GetName() <<
") Unable to create projections, abort" << std::endl ;
2419 asymName.
Append(
"_Asym[") ;
2423 asymTitle.
Append(
" Asymmetry of ") ;
2431 std::unique_ptr<RooAbsData> projDataSelOwned;
2438 if (!sliceDataSet.
empty()) {
2440 for(
RooAbsArg * sliceVar : sliceDataSet) {
2457 if (!cutString.
IsNull()) {
2458 coutI(Plotting) <<
"RooAbsReal::plotAsymOn(" <<
GetName()
2459 <<
") reducing given projection dataset to entries with " << cutString << std::endl ;
2461 projDataSelOwned = std::unique_ptr<RooAbsData>{
const_cast<RooAbsData*
>(o.
projData)->reduce(*projDataNeededVars,cutString.
IsNull() ? nullptr : cutString)};
2462 projDataSel = projDataSelOwned.
get();
2463 coutI(Plotting) <<
"RooAbsReal::plotAsymOn(" <<
GetName()
2464 <<
") only the following components of the projection data will be used: " << *projDataNeededVars << std::endl ;
2469 ScaledDataWeightedAverage scaleBind{funcAsym, *projDataSel, o.
scaleFactor, *plotVar};
2478 TString curveName(funcAsym.GetName()) ;
2481 if (!sliceSet.
empty()) {
2491 RooCurve *curve =
new RooCurve(funcAsym.GetName(),funcAsym.GetTitle(),scaleBind,
2499 ccoutW(Eval) << std::endl ;
2517 TString curveName(funcAsym.GetName()) ;
2518 if (!sliceSet.
empty()) {
2533 delete posProjCompList ;
2534 delete negProjCompList ;
2566 for(
auto * rrvFitRes : static_range_cast<RooRealVar*>(fr.
floatParsFinal())) {
2568 auto rrvInAbsReal =
static_cast<RooRealVar const*
>(allParamsInAbsReal.
find(*rrvFitRes));
2575 if (rrvFitRes->getError() <= std::abs(rrvFitRes->getVal()) * std::numeric_limits<double>::epsilon())
continue;
2578 if(!rrvInAbsReal)
continue;
2582 if(std::abs(rrvInAbsReal->getVal() - rrvFitRes->getVal()) > 0.01 * rrvFitRes->getError()) {
2583 std::stringstream errMsg;
2584 errMsg <<
"RooAbsReal::getPropagatedError(): the parameters of the RooAbsReal don't have"
2585 <<
" the same values as in the fit result! The logic of getPropagatedError is broken in this case.";
2587 throw std::runtime_error(errMsg.str());
2590 paramList.
add(*rrvInAbsReal);
2593 std::vector<double> plusVar;
2594 std::vector<double> minusVar;
2595 plusVar.reserve(paramList.
size());
2596 minusVar.reserve(paramList.
size());
2603 for (
Int_t ivar=0 ; ivar<paramList.
getSize() ; ivar++) {
2605 auto& rrv =
static_cast<RooRealVar&
>(paramList[ivar]);
2607 double cenVal = rrv.
getVal() ;
2608 double errVal = sqrt(V(ivar,ivar)) ;
2611 rrv.setVal(cenVal+errVal) ;
2612 plusVar.push_back(
getVal(nset)) ;
2615 rrv.setVal(cenVal-errVal) ;
2616 minusVar.push_back(
getVal(nset)) ;
2618 rrv.setVal(cenVal) ;
2631 std::vector<double> errVec(paramList.
size()) ;
2632 for (
int i=0 ; i<paramList.
getSize() ; i++) {
2633 errVec[i] = std::sqrt(V(i,i)) ;
2634 for (
int j=i ; j<paramList.
getSize() ; j++) {
2635 C(i,j) = V(i,j) / std::sqrt(V(i,i)*V(j,j));
2642 for (
unsigned int j=0 ; j<plusVar.size() ; j++) {
2643 F[j] = (plusVar[j]-minusVar[j])/2 ;
2647 double sum =
F*(C*
F) ;
2694 for (
auto * cmd : static_range_cast<RooCmdArg*>(plotArgListTmp)) {
2695 if (std::string(
"Normalization")==cmd->GetName()) {
2698 plotArgList.
Add(cmd) ;
2701 plotArgList.
Add(cmd) ;
2708 auto plotFunc = [&](
RooAbsReal const& absReal) {
2711 absReal.plotOn(frame, tmp);
2718 coutE(Plotting) <<
ClassName() <<
"::" <<
GetName() <<
":plotOnWithErrorBand: no curve for central value available" << std::endl;
2721 frame->
remove(
nullptr,
false) ;
2745 coutI(Plotting) <<
"RooAbsReal::plotOn(" <<
GetName() <<
") INFO: visualizing " << Z <<
"-sigma uncertainties in parameters "
2746 << errorParams <<
" from fit result " << fr.
GetName() <<
" using " <<
n <<
" samplings." << std::endl ;
2751 std::unique_ptr<RooDataSet> generatedData{paramPdf->
generate(errorParams,
n)};
2752 std::vector<RooCurve*> cvec ;
2753 for (
int i=0 ; i<generatedData->numEntries() ; i++) {
2754 cloneParams.
assign(*generatedData->get(i)) ;
2755 plotFunc(*cloneFunc);
2756 cvec.push_back(frame->
getCurve()) ;
2757 frame->
remove(
nullptr,
false) ;
2769 for (std::vector<RooCurve*>::iterator i=cvec.begin() ; i!=cvec.end() ; ++i) {
2787 for (
auto const* frv : static_range_cast<RooRealVar*>(fr.
floatParsFinal())) {
2788 if (frv->getError() > frv->getVal() * std::numeric_limits<double>::epsilon()) {
2789 fpf_stripped.
add(*frv);
2807 std::vector<int> fpf_idx ;
2811 paramList.
add(*par) ;
2812 fpf_idx.push_back(i) ;
2816 std::vector<RooCurve*> plusVar, minusVar ;
2825 for (
Int_t ivar=0 ; ivar<paramList.
getSize() ; ivar++) {
2829 double cenVal = rrv.
getVal() ;
2830 double errVal = sqrt(V(ivar,ivar)) ;
2833 ((
RooRealVar*)paramList.
at(ivar))->setVal(cenVal+Z*errVal) ;
2836 plotFunc(*cloneFunc);
2837 plusVar.push_back(frame->
getCurve()) ;
2838 frame->
remove(
nullptr,
false) ;
2842 ((
RooRealVar*)paramList.
at(ivar))->setVal(cenVal-Z*errVal) ;
2843 plotFunc(*cloneFunc);
2844 minusVar.push_back(frame->
getCurve()) ;
2845 frame->
remove(
nullptr,
false) ;
2851 std::vector<double> errVec(paramList.
size()) ;
2852 for (
int i=0 ; i<paramList.
getSize() ; i++) {
2853 errVec[i] = sqrt(V(i,i)) ;
2854 for (
int j=i ; j<paramList.
getSize() ; j++) {
2855 C(i,j) = V(i,j)/sqrt(V(i,i)*V(j,j)) ;
2865 for (std::vector<RooCurve*>::iterator i=plusVar.begin() ; i!=plusVar.end() ; ++i) {
2868 for (std::vector<RooCurve*>::iterator i=minusVar.begin() ; i!=minusVar.end() ; ++i) {
2875 if (!band)
return frame ;
2880 pc.
defineString(
"curveNameSuffix",
"CurveNameSuffix",0,
"") ;
2881 pc.
defineInt(
"lineColor",
"LineColor",0,-999) ;
2882 pc.
defineInt(
"lineStyle",
"LineStyle",0,-999) ;
2883 pc.
defineInt(
"lineWidth",
"LineWidth",0,-999) ;
2884 pc.
defineInt(
"markerColor",
"MarkerColor",0,-999) ;
2885 pc.
defineInt(
"markerStyle",
"MarkerStyle",0,-999) ;
2887 pc.
defineInt(
"fillColor",
"FillColor",0,-999) ;
2888 pc.
defineInt(
"fillStyle",
"FillStyle",0,-999) ;
2890 pc.
defineInt(
"curveInvisible",
"Invisible",0,0) ;
2891 pc.
defineInt(
"moveToBack",
"MoveToBack",0,0) ;
2922 if (pc.
getString(
"curveName",
nullptr,
true)) {
2924 }
else if (pc.
getString(
"curveNameSuffix",
nullptr,
true)) {
2948 if(
nullptr == frame) {
2957 <<
":plotOn: frame does not specify a plot variable" << std::endl;
2970 coutE(Plotting) <<
ClassName() <<
"::" <<
GetName() <<
":plotOn: WARNING: variable is not an explicit dependent: "
2971 << var->
GetName() << std::endl;
2989 RooArgSet& projectedVars,
bool silent)
const
2991 cxcoutD(Plotting) <<
"RooAbsReal::makeProjectionSet(" <<
GetName() <<
") plotVar = " << plotVar->
GetName()
2992 <<
" allVars = " << (allVars?(*allVars):
RooArgSet()) << std::endl ;
2995 if (!allVars) return ;
2998 projectedVars.
add(*allVars) ;
3003 projectedVars.
remove(*found);
3006 std::unique_ptr<RooArgSet> plotServers{plotVar->
getObservables(&projectedVars)};
3010 cxcoutD(Plotting) <<
"RooAbsReal::makeProjectionSet(" <<
GetName() <<
") removing " << tmp->
GetName()
3011 <<
" from projection set because it a server of " << plotVar->
GetName() << std::endl ;
3012 projectedVars.
remove(*tmp) ;
3018 <<
") WARNING: cannot project out frame variable ("
3019 << found->
GetName() <<
"), ignoring" << std::endl ;
3026 projectedVars.
remove(*arg,
true) ;
3029 <<
") function doesn't depend on projection variable "
3030 << arg->
GetName() <<
", ignoring" << std::endl ;
3067 auto binding = std::make_unique<RooRealBinding>(*
this,vars,nset,clipInvalid);
3068 if(!binding->isValid()) {
3069 coutE(InputArguments) <<
ClassName() <<
"::" <<
GetName() <<
":bindVars: cannot bind to " << vars << std::endl ;
3084 auto other =
static_cast<const RooAbsReal*
>(source);
3085 assert(
dynamic_cast<const RooAbsReal*
>(source));
3087 _value = other->_treeReadBuffer ? other->_treeReadBuffer->operator
double() : other->_value;
3127 coutE(Eval) <<
"RooAbsReal::attachToTree(" <<
GetName() <<
") ERROR: TTree branch " <<
GetName()
3128 <<
" is an array and cannot be attached to a RooAbsReal" << std::endl ;
3138 std::map<std::string, std::pair<std::string, std::function<std::unique_ptr<TreeReadBuffer>()>>> typeMap {
3139 {
"Float_t", {
"FLOAT_TREE_BRANCH", [&](){
return createTreeReadBuffer<Float_t >(cleanName, t); }}},
3140 {
"Int_t", {
"INTEGER_TREE_BRANCH", [&](){
return createTreeReadBuffer<Int_t >(cleanName, t); }}},
3141 {
"UChar_t", {
"BYTE_TREE_BRANCH", [&](){
return createTreeReadBuffer<UChar_t >(cleanName, t); }}},
3142 {
"Bool_t", {
"BOOL_TREE_BRANCH", [&](){
return createTreeReadBuffer<Bool_t >(cleanName, t); }}},
3143 {
"Char_t", {
"SIGNEDBYTE_TREE_BRANCH", [&](){
return createTreeReadBuffer<Char_t >(cleanName, t); }}},
3144 {
"UInt_t", {
"UNSIGNED_INTEGER_TREE_BRANCH", [&](){
return createTreeReadBuffer<UInt_t >(cleanName, t); }}},
3145 {
"Long64_t", {
"LONG_TREE_BRANCH", [&](){
return createTreeReadBuffer<Long64_t >(cleanName, t); }}},
3146 {
"ULong64_t", {
"UNSIGNED_LONG_TREE_BRANCH", [&](){
return createTreeReadBuffer<ULong64_t>(cleanName, t); }}},
3147 {
"Short_t", {
"SHORT_TREE_BRANCH", [&](){
return createTreeReadBuffer<Short_t >(cleanName, t); }}},
3148 {
"UShort_t", {
"UNSIGNED_SHORT_TREE_BRANCH", [&](){
return createTreeReadBuffer<UShort_t >(cleanName, t); }}},
3151 auto typeDetails = typeMap.find(typeName.
Data());
3152 if (typeDetails != typeMap.end()) {
3153 coutI(DataHandling) <<
"RooAbsReal::attachToTree(" <<
GetName() <<
") TTree " << typeDetails->first <<
" branch " <<
GetName()
3154 <<
" will be converted to double precision." << std::endl ;
3164 coutE(InputArguments) <<
"RooAbsReal::attachToTree(" <<
GetName() <<
") data type " << typeName <<
" is not supported." << std::endl ;
3186 coutE(Eval) <<
"RooAbsReal::fillTreeBranch(" <<
GetName() <<
") ERROR: not attached to tree: " <<
cleanBranchName() << std::endl ;
3215 fund->removeRange();
3217 fund->setAttribute(
"fundamentalCopy");
3218 return RooFit::Detail::owningPtr<RooAbsArg>(std::move(fund));
3324 const TList &nameList)
const
3327 bool isMatched(
true);
3328 for(
auto *
name : static_range_cast<TObjString*>(nameList)) {
3331 matched.
add(*found);
3345 if(isMatched) matchedArgs.
add(matched);
3394 if (config)
return config ;
3407 if (config)
return config ;
3501 static bool inLogEvalError = false ;
3503 if (inLogEvalError) {
3506 inLogEvalError = true ;
3511 if (serverValueString) {
3516 oocoutE(
nullptr,Eval) <<
"RooAbsReal::logEvalError(" <<
"<STATIC>" <<
") evaluation error, " << std::endl
3517 <<
" origin : " << origName << std::endl
3518 <<
" message : " << ee.
_msg << std::endl
3519 <<
" server values: " << ee.
_srvval << std::endl ;
3526 inLogEvalError = false ;
3556 static bool inLogEvalError = false ;
3558 if (inLogEvalError) {
3561 inLogEvalError = true ;
3566 if (serverValueString) {
3569 std::string srvval ;
3570 std::ostringstream oss ;
3581 p->print(oss,
true) ;
3586 std::ostringstream oss2 ;
3590 coutE(Eval) <<
"RooAbsReal::logEvalError(" <<
GetName() <<
") evaluation error, " << std::endl
3591 <<
" origin : " << oss2.str() << std::endl
3592 <<
" message : " << ee.
_msg << std::endl
3593 <<
" server values: " << ee.
_srvval << std::endl ;
3602 <<
") delayed evaluation error, " << std::endl
3603 <<
" origin : " << oss2.str() << std::endl
3604 <<
" message : " << oee.
_msg << std::endl
3605 <<
" server values: " << oee.
_srvval << std::endl ;
3612 inLogEvalError = false ;
3668 if (maxPerNode<0) return ;
3671 if (maxPerNode==0) {
3674 os << iter->second.first ;
3676 os <<
" has " << iter->second.second.size() <<
" errors" << std::endl ;
3681 os << iter->second.first << std::endl ;
3685 for(
auto iter2 = iter->second.second.begin();iter2!=iter->second.second.end() ; ++iter2, i++) {
3686 os <<
" " << iter2->_msg <<
" @ " << iter2->_srvval << std::endl ;
3688 os <<
" ... (remaining " << iter->second.second.size() - maxPerNode <<
" messages suppressed)" << std::endl ;
3709 ntot += elem.second.second.size() ;
3729 for(
auto * pdf : dynamic_range_cast<RooAbsPdf*>(*compSet)) {
3731 if (!addNormSet.
empty()) {
3732 pdf->selectNormalization(&addNormSet,force) ;
3734 pdf->selectNormalization(
nullptr,force) ;
3754 for(
auto * pdf : dynamic_range_cast<RooAbsPdf*>(*compSet)) {
3756 pdf->selectNormalizationRange(rangeName,force) ;
3774 orderedObs.
add(obs) ;
3832 pc.
defineSet(
"supNormSet",
"SupNormSet",0,
nullptr) ;
3833 pc.
defineInt(
"numScanBins",
"ScanParameters",0,1000) ;
3834 pc.
defineInt(
"intOrder",
"ScanParameters",1,2) ;
3835 pc.
defineInt(
"doScanNum",
"ScanNum",0,1) ;
3836 pc.
defineInt(
"doScanAll",
"ScanAll",0,0) ;
3837 pc.
defineInt(
"doScanNon",
"ScanNone",0,0) ;
3841 pc.
process(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) ;
3869 coutI(NumIntegration) <<
"RooAbsPdf::createRunningIntegral(" <<
GetName() <<
") integration over observable(s) " << iset <<
" involves numeric integration," << std::endl
3870 <<
" constructing cdf though numeric integration of sampled pdf in " << numScanBins <<
" bins and applying order "
3871 << intOrder <<
" interpolation on integrated histogram." << std::endl
3872 <<
" To override this choice of technique use argument ScanNone(), to change scan parameters use ScanParameters(nbins,order) argument" << std::endl ;
3890 ivar->
setBins(numScanBins,
"numcdf") ;
3891 auto ret = std::make_unique<RooNumRunningInt>(
name.c_str(),
name.c_str(),*
this,*ivar,
"numrunint") ;
3892 ret->setInterpolationOrder(intOrder) ;
3911 coutW(InputArguments) <<
"RooAbsPdf::createRunningIntegral(" <<
GetName() <<
") WARNING ignoring non-RooRealVar input argument " << arg->
GetName() << std::endl ;
3925 for(
auto * rrv : static_range_cast<RooRealVar*>(ilist)) {
3929 cloneList.
add(*cloneArg) ;
3934 cloneLo->
setVal(rrv->getMin()) ;
3935 loList.
add(*cloneLo) ;
3947 finalNset.
add(cloneList,
true) ;
3948 std::unique_ptr<RooAbsReal> cdf{tmp->
createIntegral(cloneList,finalNset,
"CDF")};
3951 cdf->addOwnedComponents(*tmp) ;
3952 cdf->addOwnedComponents(cloneList) ;
3953 cdf->addOwnedComponents(loList) ;
3967 if (realObs.
size() != obs.
size()) {
3968 coutE(InputArguments) <<
"RooAbsReal::functor(" <<
GetName() <<
") ERROR: one or more specified observables are not variables of this p.d.f" << std::endl ;
3973 if (realPars.
size() != pars.
size()) {
3974 coutE(InputArguments) <<
"RooAbsReal::functor(" <<
GetName() <<
") ERROR: one or more specified parameters are not variables of this p.d.f" << std::endl ;
3992 if (realObs.
size() != obs.
size()) {
3993 coutE(InputArguments) <<
"RooAbsReal::functor(" <<
GetName() <<
") ERROR: one or more specified observables are not variables of this p.d.f" << std::endl ;
3998 if (realPars.
size() != pars.
size()) {
3999 coutE(InputArguments) <<
"RooAbsReal::functor(" <<
GetName() <<
") ERROR: one or more specified parameters are not variables of this p.d.f" << std::endl ;
4004 for (
int i=0 ; i<obs.
getSize() ; i++) {
4006 coutE(ObjectHandling) <<
"RooAbsReal::asTF(" <<
GetName() <<
") ERROR: proposed observable " << obs.
at(0)->
GetName() <<
" is not of type RooRealVar" << std::endl ;
4010 for (
int i=0 ; i<pars.
getSize() ; i++) {
4012 coutE(ObjectHandling) <<
"RooAbsReal::asTF(" <<
GetName() <<
") ERROR: proposed parameter " << pars.
at(0)->
GetName() <<
" is not of type RooRealVar" << std::endl ;
4043 coutE(InputArguments) <<
"RooAbsReal::asTF(" <<
GetName() <<
") ERROR: " << obs.
size()
4044 <<
" observables specified, but a ROOT TFx can only have 1,2 or 3 observables" << std::endl ;
4049 for (
int i=0 ; i<pars.
getSize() ; i++) {
4079 return new RooDerivative(
name.c_str(),title.c_str(),*
this,obs,normSet,order,eps) ;
4094 std::string title=
Form(
"%sMoment of order %d of %s w.r.t %s ",(central?
"Central ":
""),order,
GetName(),obs.
GetName()) ;
4096 if (order==2)
return new RooSecondMoment(
name.c_str(),title.c_str(),*
this,obs,central,takeRoot) ;
4097 return new RooMoment(
name.c_str(),title.c_str(),*
this,obs,order,central,takeRoot) ;
4113 std::string title=
Form(
"%sMoment of order %d of %s w.r.t %s ",(central?
"Central ":
""),order,
GetName(),obs.
GetName()) ;
4115 if (order==1)
return new RooFirstMoment(
name.c_str(),title.c_str(),*
this,obs,normObs,intNormObs) ;
4116 if (order==2)
return new RooSecondMoment(
name.c_str(),title.c_str(),*
this,obs,normObs,central,takeRoot,intNormObs) ;
4117 return new RooMoment(
name.c_str(),title.c_str(),*
this,obs,normObs,order,central,takeRoot,intNormObs) ;
4211 auto createChi2DataHistCmdArgs =
"Range,RangeWithName,NumCPU,Optimize,IntegrateBins,ProjectedObservables,"
4212 "AddCoefRange,SplitRange,DataError,Extended";
4248 std::string baseName =
"chi2_" + std::string(
GetName()) +
"_" +
data.GetName();
4253 auto chi2 = std::make_unique<RooChi2Var>(baseName.c_str(), baseName.c_str(), *
this,
data, arg1, arg2, arg3, arg4,
4254 arg5, arg6, arg7, arg8);
4273 for(
auto * arg : static_range_cast<RooCmdArg*>(cmdList)) {
4280 return createChi2(
data,*cmds[0],*cmds[1],*cmds[2],*cmds[3],*cmds[4],*cmds[5],*cmds[6],*cmds[7]) ;
4344 auto createChi2DataSetCmdArgs =
"YVar,Integrate,RangeWithName,NumCPU,Verbose";
4355 std::unique_ptr<RooAbsReal> xychi2{
createChi2(xydata, chi2CmdList)};
4397 pc.
defineInt(
"integrate",
"Integrate", 0, 0);
4399 pc.
defineString(
"rangeName",
"RangeWithName", 0,
"",
true);
4401 pc.
defineInt(
"interleave",
"NumCPU", 1, 0);
4402 pc.
defineInt(
"verbose",
"Verbose", 0, 0);
4411 bool integrate = pc.
getInt(
"integrate");
4413 const char *rangeName = pc.
getString(
"rangeName", 0,
true);
4417 if (numcpu_strategy == 3 && !this->
InheritsFrom(
"RooSimultaneous")) {
4418 coutW(Minimization) <<
"Cannot use a NumCpu Strategy = 3 when the pdf is not a RooSimultaneous, "
4419 "falling back to default strategy = 0"
4421 numcpu_strategy = 0;
4424 bool verbose = pc.
getInt(
"verbose");
4427 cfg.
rangeName = rangeName ? rangeName :
"";
4433 std::string
name =
"chi2_" + std::string(
GetName()) +
"_" +
data.GetName();
4436 std::make_unique<RooXYChi2Var>(
name.c_str(),
name.c_str(), *
this,
data, yvar, integrate, cfg));
4469 for (
auto const* arg : paramVars) {
4471 coutW(InputArguments) <<
"RooAbsReal::setParameterizeIntegral(" <<
GetName()
4472 <<
") function does not depend on listed parameter " << arg->
GetName() <<
", ignoring" << std::endl ;
4475 if (!plist.empty()) plist +=
":" ;
4492 std::span<const double> batch;
4498 std::vector<ServerData> ourServers;
4501 for (
auto server :
servers()) {
4502 auto serverValues = dataMap.
at(server);
4503 if(serverValues.empty())
continue;
4506 auto oldOperMode = server->operMode();
4511 ourServers.push_back({server,
4515 server->_valueDirty,
4516 server->_shapeDirty});
4522 struct RestoreStateRAII {
4523 RestoreStateRAII(std::vector<ServerData>& servers) :
4524 _servers{servers} { }
4526 ~RestoreStateRAII() {
4527 for (
auto& serverData : _servers) {
4528 serverData.server->setCachedValue(serverData.oldValue,
true);
4529 serverData.server->setOperMode(serverData.oldOperMode);
4530 serverData.server->_valueDirty = serverData.oldValueDirty;
4531 serverData.server->_shapeDirty = serverData.oldShapeDirty;
4535 std::vector<ServerData>& _servers;
4536 } restoreState{ourServers};
4542 coutI(FastEvaluations) <<
"The class " <<
ClassName() <<
" does not implement the faster batch evaluation interface."
4543 <<
" Consider requesting or implementing it to benefit from a speed up." << std::endl;
4549 for (std::size_t i=0; i < nEvents; ++i) {
4550 for (
auto& serv : ourServers) {
4551 serv.server->setCachedValue(serv.batch[std::min(i, serv.batch.size()-1)],
false);
4569 std::stringstream errorMsg;
4570 errorMsg <<
"An analytical integral function for class \"" <<
ClassName() <<
"\" has not yet been implemented.";
4571 coutE(Minimization) << errorMsg.str() << std::endl;
4572 throw std::runtime_error(errorMsg.str().c_str());
4577 const bool tmpFast =
_fast;
4578 const double tmp =
_value;
4580 double fullEval = 0.;
4582 fullEval =
getValV(normalisationSet);
4591 if (std::isfinite(ret) && ( ret != 0. ? (ret - fullEval)/ret : ret - fullEval) > 1.E-9) {
4596 formatter <<
"--> (Scalar computation wrong here:)\n"
4597 <<
GetName() <<
" " <<
this <<
" _fast=" << tmpFast
4598 <<
"\n\tcached _value=" << std::setprecision(16) << tmp
4599 <<
"\n\treturning =" << ret
4600 <<
"\n\trecomputed =" << fullEval
4601 <<
"\n\tnew _value =" <<
_value <<
"] ";
4602 formatter <<
"\nServers:";
4616 bool nameChange,
bool isRecursiveStep)
4628 if(
auto realArg =
dynamic_cast<RooAbsReal*
>(arg)) {
4629 realArg->enableOffsetting(flag) ;
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
static void indent(ostringstream &buf, int indent_level)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t SetLineColor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
R__EXTERN TSystem * gSystem
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
bool recursiveRedirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
bool isValueDirtyAndClear() const
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...
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.
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
RooFit::OwningPtr< RooArgSet > getComponents() const
Create a RooArgSet with all components (branch nodes) of the expression tree headed by this object.
const RefCountList_t & servers() const
List of all servers of this object.
bool dependsOnValue(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr) const
Check whether this object depends on values from an element in the serverList.
void removeStringAttribute(const Text_t *key)
Delete a string attribute with a given key.
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
RooFit::OwningPtr< RooArgSet > getVariables(bool stripDisconnected=true) const
Return RooArgSet with all variables (tree leaf nodes of expression tree)
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Implement multi-line detailed printing.
virtual RooAbsArg * cloneTree(const char *newname=nullptr) const
Clone tree expression of objects.
TString cleanBranchName() const
Construct a mangled name from the actual name that is free of any math symbols that might be interpre...
Int_t numProxies() const
Return the number of registered proxies.
static bool _inhibitDirty
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
void setProxyNormSet(const RooArgSet *nset)
Forward a change in the cached normalization argset to all the registered proxies.
void branchNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=nullptr, bool recurseNonDerived=false) const
Fill supplied list with all branch nodes of the arg tree starting with ourself as top node.
RooAbsProxy * getProxy(Int_t index) const
Return the nth proxy from the proxy list.
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
RefCountList_t _serverList
void leafNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=nullptr, bool recurseNonDerived=false) const
Fill supplied list with all leaf nodes of the arg tree, starting with ourself as top node.
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
virtual bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursiveStep)
Function that is called at the end of redirectServers().
virtual bool checkObservables(const RooArgSet *nset) const
Overloadable function in which derived classes can implement consistency checks of the variables.
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...
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
virtual bool isParameterized() const
Interface function.
virtual RooAbsReal * highBoundFunc() const
Return pointer to RooAbsReal parameterized upper bound, if any.
virtual RooAbsReal * lowBoundFunc() const
Return pointer to RooAbsReal parameterized lower bound, if any.
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
virtual bool setIndex(value_type index, bool printError=true)=0
Change category state by specifying the index code of the desired state.
A space to attach TBranches.
virtual value_type getCurrentIndex() const
Return index number of current state.
bool isSignType(bool mustHaveZero=false) const
Determine if category has 2 or 3 states with index values -1,0,1.
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
RooFit::UniqueId< RooAbsCollection > const & uniqueId() const
Returns a unique ID that is different for every instantiated RooAbsCollection.
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.
Int_t getSize() const
Return the number of elements in the collection.
const char * GetName() const override
Returns name of object.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
bool overlaps(Iterator_t otherCollBegin, Iterator_t otherCollEnd) const
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...
Storage_t::size_type size() const