35 #include <sys/types.h>
110 using namespace std ;
114 Bool_t RooAbsReal::_globalSelectComp = false;
115 Bool_t RooAbsReal::_hideOffset = kTRUE ;
117 void RooAbsReal::setHideOffset(Bool_t flag) { _hideOffset = flag ; }
118 Bool_t RooAbsReal::hideOffset() {
return _hideOffset ; }
120 RooAbsReal::ErrorLoggingMode RooAbsReal::_evalErrorMode = RooAbsReal::PrintErrors ;
121 Int_t RooAbsReal::_evalErrorCount = 0 ;
122 map<const RooAbsArg*,pair<string,list<RooAbsReal::EvalError> > > RooAbsReal::_evalErrorList ;
129 RooAbsReal::RooAbsReal() : _specIntegratorConfig(0), _treeVar(kFALSE), _selectComp(kTRUE), _lastNSet(0)
138 RooAbsReal::RooAbsReal(
const char *name,
const char *title,
const char *unit) :
139 RooAbsArg(name,title), _plotMin(0), _plotMax(0), _plotBins(100),
140 _value(0), _unit(unit), _forceNumInt(kFALSE), _specIntegratorConfig(0), _treeVar(kFALSE), _selectComp(kTRUE), _lastNSet(0)
152 RooAbsReal::RooAbsReal(
const char *name,
const char *title, Double_t inMinVal,
153 Double_t inMaxVal,
const char *unit) :
154 RooAbsArg(name,title), _plotMin(inMinVal), _plotMax(inMaxVal), _plotBins(100),
155 _value(0), _unit(unit), _forceNumInt(kFALSE), _specIntegratorConfig(0), _treeVar(kFALSE), _selectComp(kTRUE), _lastNSet(0)
166 RooAbsReal::RooAbsReal(
const RooAbsReal& other,
const char* name) :
167 RooAbsArg(other,name), _plotMin(other._plotMin), _plotMax(other._plotMax),
168 _plotBins(other._plotBins), _value(other._value), _unit(other._unit), _label(other._label),
169 _forceNumInt(other._forceNumInt), _treeVar(other._treeVar), _selectComp(other._selectComp), _lastNSet(0)
171 if (other._specIntegratorConfig) {
172 _specIntegratorConfig =
new RooNumIntConfig(*other._specIntegratorConfig) ;
174 _specIntegratorConfig = 0 ;
181 RooAbsReal& RooAbsReal::operator=(
const RooAbsReal& other) {
182 RooAbsArg::operator=(other);
184 _plotMin = other._plotMin;
185 _plotMax = other._plotMax;
186 _plotBins = other._plotBins;
187 _value = other._value;
189 _label = other._label;
190 _forceNumInt = other._forceNumInt;
191 _treeVar = other._treeVar;
192 _selectComp = other._selectComp;
193 _lastNSet = other._lastNSet;
195 if (other._specIntegratorConfig) {
196 _specIntegratorConfig =
new RooNumIntConfig(*other._specIntegratorConfig);
198 _specIntegratorConfig =
nullptr;
209 RooAbsReal::~RooAbsReal()
211 if (_specIntegratorConfig)
delete _specIntegratorConfig ;
219 Bool_t RooAbsReal::operator==(Double_t value)
const
221 return (getVal()==value) ;
230 Bool_t RooAbsReal::operator==(
const RooAbsArg& other)
232 const RooAbsReal* otherReal =
dynamic_cast<const RooAbsReal*
>(&other) ;
233 return otherReal ? operator==(otherReal->getVal()) : kFALSE ;
239 Bool_t RooAbsReal::isIdentical(
const RooAbsArg& other, Bool_t assumeSameType)
241 if (!assumeSameType) {
242 const RooAbsReal* otherReal =
dynamic_cast<const RooAbsReal*
>(&other) ;
243 return otherReal ? operator==(otherReal->getVal()) : kFALSE ;
245 return getVal()==((RooAbsReal&)other).getVal() ;
254 TString RooAbsReal::getTitle(Bool_t appendUnit)
const
256 TString title(GetTitle());
257 if(appendUnit && 0 != strlen(getUnit())) {
259 title.Append(getUnit());
272 Double_t RooAbsReal::getValV(
const RooArgSet* nset)
const
274 if (nset && nset!=_lastNSet) {
275 ((RooAbsReal*)
this)->setProxyNormSet(nset) ;
276 _lastNSet = (RooArgSet*) nset ;
279 if (isValueDirtyAndClear()) {
280 _value = traceEval(nset) ;
285 Double_t ret(_value) ;
286 if (hideOffset()) ret += offset() ;
296 RooSpan<const double> RooAbsReal::getValBatch(std::size_t begin, std::size_t maxSize,
297 const RooArgSet* normSet)
const {
301 if (_allBatchesDirty || _operMode == ADirty) {
302 _batchData.markDirty();
303 _allBatchesDirty =
false;
306 if (normSet && normSet != _lastNSet) {
307 const_cast<RooAbsReal*
>(
this)->setProxyNormSet(normSet);
308 _lastNSet = (RooArgSet*) normSet;
312 if (_batchData.status(begin, maxSize) < BatchHelpers::BatchData::kReady) {
313 auto ret = evaluateBatch(begin, maxSize);
314 maxSize = ret.size();
315 _batchData.setStatus(begin, maxSize, BatchHelpers::BatchData::kReady);
318 return _batchData.getBatch(begin, maxSize);
324 Int_t RooAbsReal::numEvalErrorItems()
326 return _evalErrorList.size() ;
332 RooAbsReal::EvalErrorIter RooAbsReal::evalErrorIter()
334 return _evalErrorList.begin() ;
341 Double_t RooAbsReal::traceEval(
const RooArgSet* )
const
343 Double_t value = evaluate() ;
345 if (TMath::IsNaN(value)) {
346 logEvalError(
"function value is NAN") ;
352 if (!isValidReal(value)) {
353 coutW(Tracing) <<
"RooAbsReal::traceEval(" << GetName()
354 <<
"): validation failed: " << value << endl ;
373 Int_t RooAbsReal::getAnalyticalIntegralWN(RooArgSet& allDeps, RooArgSet& analDeps,
374 const RooArgSet* ,
const char* rangeName)
const
376 return _forceNumInt ? 0 : getAnalyticalIntegral(allDeps,analDeps,rangeName) ;
390 Int_t RooAbsReal::getAnalyticalIntegral(RooArgSet& , RooArgSet& ,
const char* )
const
402 Double_t RooAbsReal::analyticalIntegralWN(Int_t code,
const RooArgSet* normSet,
const char* rangeName)
const
405 if (code==0)
return getVal(normSet) ;
406 return analyticalIntegral(code,rangeName) ;
416 Double_t RooAbsReal::analyticalIntegral(Int_t code,
const char* )
const
419 coutF(Eval) <<
"RooAbsReal::analyticalIntegral(" << GetName() <<
") code " << code <<
" not implemented" << endl ;
428 const char *RooAbsReal::getPlotLabel()
const
430 return _label.IsNull() ? fName.Data() : _label.Data();
438 void RooAbsReal::setPlotLabel(
const char *label)
448 Bool_t RooAbsReal::readFromStream(istream& , Bool_t , Bool_t )
458 void RooAbsReal::writeToStream(ostream& , Bool_t )
const
467 void RooAbsReal::printValue(ostream& os)
const
477 void RooAbsReal::printMultiline(ostream& os, Int_t contents, Bool_t verbose, TString indent)
const
479 RooAbsArg::printMultiline(os,contents,verbose,indent) ;
480 os << indent <<
"--- RooAbsReal ---" << endl;
482 if(!unit.IsNull()) unit.Prepend(
' ');
484 os << endl << indent <<
" Plot label is \"" << getPlotLabel() <<
"\"" <<
"\n";
486 _batchData.print(os, indent.Data());
493 Bool_t RooAbsReal::isValid()
const
495 return isValidReal(_value) ;
504 Bool_t RooAbsReal::isValidReal(Double_t , Bool_t )
const
517 RooAbsReal* RooAbsReal::createProfile(
const RooArgSet& paramsOfInterest)
520 TString name(Form(
"%s_Profile[",GetName())) ;
521 TIterator* iter = paramsOfInterest.createIterator() ;
523 Bool_t first(kTRUE) ;
524 while((arg=(RooAbsArg*)iter->Next())) {
530 name.Append(arg->GetName()) ;
536 return new RooProfileLL(name.Data(),Form(
"Profile of %s",GetTitle()),*
this,paramsOfInterest) ;
562 RooAbsReal* RooAbsReal::createIntegral(
const RooArgSet& iset,
const RooCmdArg& arg1,
const RooCmdArg& arg2,
563 const RooCmdArg& arg3,
const RooCmdArg& arg4,
const RooCmdArg& arg5,
564 const RooCmdArg& arg6,
const RooCmdArg& arg7,
const RooCmdArg& arg8)
const
569 RooCmdConfig pc(Form(
"RooAbsReal::createIntegral(%s)",GetName())) ;
570 pc.defineString(
"rangeName",
"RangeWithName",0,
"",kTRUE) ;
571 pc.defineObject(
"normSet",
"NormSet",0,0) ;
572 pc.defineObject(
"numIntConfig",
"NumIntConfig",0,0) ;
575 pc.process(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) ;
581 const char* rangeName = pc.getString(
"rangeName",0,kTRUE) ;
582 const RooArgSet* nset =
static_cast<const RooArgSet*
>(pc.getObject(
"normSet",0)) ;
583 const RooNumIntConfig* cfg =
static_cast<const RooNumIntConfig*
>(pc.getObject(
"numIntConfig",0)) ;
585 return createIntegral(iset,nset,cfg,rangeName) ;
603 RooAbsReal* RooAbsReal::createIntegral(
const RooArgSet& iset,
const RooArgSet* nset,
604 const RooNumIntConfig* cfg,
const char* rangeName)
const
606 if (!rangeName || strchr(rangeName,
',')==0) {
608 return createIntObj(iset,nset,cfg,rangeName) ;
612 RooArgSet components ;
614 auto tokens = RooHelpers::tokenise(rangeName,
",");
616 for (
const std::string& token : tokens) {
617 RooAbsReal* compIntegral = createIntObj(iset,nset,cfg, token.c_str());
618 components.add(*compIntegral);
621 TString title(GetTitle()) ;
622 title.Prepend(
"Integral of ") ;
623 TString fullName(GetName()) ;
624 fullName.Append(integralNameSuffix(iset,nset,rangeName)) ;
626 return new RooAddition(fullName.Data(),title.Data(),components,kTRUE) ;
633 RooAbsReal* RooAbsReal::createIntObj(
const RooArgSet& iset2,
const RooArgSet* nset2,
634 const RooNumIntConfig* cfg,
const char* rangeName)
const
637 RooArgSet iset(iset2) ;
638 const RooArgSet* nset = nset2 ;
642 Bool_t error = kFALSE ;
643 const RooAbsReal* integrand = this ;
644 RooAbsReal* integral = 0 ;
647 if (iset.getSize()==0) {
649 TString title(GetTitle()) ;
650 title.Prepend(
"Integral of ") ;
652 TString name(GetName()) ;
653 name.Append(integralNameSuffix(iset,nset,rangeName)) ;
655 return new RooRealIntegral(name,title,*
this,iset,nset,cfg,rangeName) ;
659 while(iset.getSize()>0) {
664 findInnerMostIntegration(iset,innerSet,rangeName) ;
668 if (innerSet.getSize()==0) {
674 TString title(integrand->GetTitle()) ;
675 title.Prepend(
"Integral of ") ;
677 TString name(integrand->GetName()) ;
678 name.Append(integrand->integralNameSuffix(innerSet,nset,rangeName)) ;
681 integral =
new RooRealIntegral(name,title,*integrand,innerSet,nset,cfg,rangeName) ;
684 if (integrand !=
this) {
685 integral->addOwnedComponents(*integrand) ;
689 iset.remove(innerSet) ;
692 if (integrand ==
this && iset.getSize()>0) {
693 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" << endl ;
697 integrand = integral ;
705 coutE(Integration) << GetName() <<
" : ERROR while defining recursive integral over observables with parameterized integration ranges, please check that integration rangs specify uniquely defined integral " << endl;
713 const char* cacheParamsStr = getStringAttribute(
"CACHEPARAMINT") ;
714 if (cacheParamsStr && strlen(cacheParamsStr)) {
716 RooArgSet* intParams = integral->getVariables() ;
718 RooNameSet cacheParamNames ;
719 cacheParamNames.setNameList(cacheParamsStr) ;
720 RooArgSet* cacheParams = cacheParamNames.select(*intParams) ;
722 if (cacheParams->getSize()>0) {
723 cxcoutD(Caching) <<
"RooAbsReal::createIntObj(" << GetName() <<
") INFO: constructing " << cacheParams->getSize()
724 <<
"-dim value cache for integral over " << iset2 <<
" as a function of " << *cacheParams <<
" in range " << (rangeName?rangeName:
"<none>") << endl ;
725 string name = Form(
"%s_CACHE_[%s]",integral->GetName(),cacheParams->contentsString().c_str()) ;
726 RooCachedReal* cachedIntegral =
new RooCachedReal(name.c_str(),name.c_str(),*integral,*cacheParams) ;
727 cachedIntegral->setInterpolationOrder(2) ;
728 cachedIntegral->addOwnedComponents(*integral) ;
729 cachedIntegral->setCacheSource(kTRUE) ;
730 if (integral->operMode()==ADirty) {
731 cachedIntegral->setOperMode(ADirty) ;
734 integral = cachedIntegral ;
754 void RooAbsReal::findInnerMostIntegration(
const RooArgSet& allObs, RooArgSet& innerObs,
const char* rangeName)
const
760 RooArgSet obsWithFixedRange(allObs) ;
761 RooArgSet obsWithParamRange ;
762 RooArgSet obsServingAsRangeParams ;
765 for (
const auto aarg : allObs) {
767 RooAbsRealLValue* arglv =
dynamic_cast<RooAbsRealLValue*
>(aarg) ;
771 RooAbsBinning& binning = arglv->getBinning(rangeName,kFALSE,kTRUE) ;
772 if (binning.isParameterized()) {
773 RooArgSet* loBoundObs = binning.lowBoundFunc()->getObservables(allObs) ;
774 RooArgSet* hiBoundObs = binning.highBoundFunc()->getObservables(allObs) ;
777 if (loBoundObs->overlaps(allObs) || hiBoundObs->overlaps(allObs)) {
778 obsWithParamRange.add(*aarg) ;
779 obsWithFixedRange.remove(*aarg) ;
780 obsServingAsRangeParams.add(*loBoundObs,kFALSE) ;
781 obsServingAsRangeParams.add(*hiBoundObs,kFALSE) ;
790 RooArgSet obsWithFixedRangeNP(obsWithFixedRange) ;
791 obsWithFixedRangeNP.remove(obsServingAsRangeParams) ;
794 RooArgSet obsWithParamRangeNP(obsWithParamRange) ;
795 obsWithParamRangeNP.remove(obsServingAsRangeParams) ;
798 innerObs.removeAll() ;
799 innerObs.add(obsWithFixedRangeNP) ;
800 innerObs.add(obsWithParamRangeNP) ;
809 TString RooAbsReal::integralNameSuffix(
const RooArgSet& iset,
const RooArgSet* nset,
const char* rangeName, Bool_t omitEmpty)
const
812 if (iset.getSize()>0) {
814 RooArgSet isetTmp(iset) ;
817 name.Append(
"_Int[") ;
818 TIterator* iter = isetTmp.createIterator() ;
820 Bool_t first(kTRUE) ;
821 while((arg=(RooAbsArg*)iter->Next())) {
827 name.Append(arg->GetName()) ;
832 name.Append(rangeName) ;
835 }
else if (!omitEmpty) {
836 name.Append(
"_Int[]") ;
839 if (nset && nset->getSize()>0 ) {
841 RooArgSet nsetTmp(*nset) ;
844 name.Append(
"_Norm[") ;
846 TIterator* iter = nsetTmp.createIterator() ;
848 while((arg=(RooAbsArg*)iter->Next())) {
854 name.Append(arg->GetName()) ;
857 const RooAbsPdf* thisPdf =
dynamic_cast<const RooAbsPdf*
>(
this) ;
858 if (thisPdf && thisPdf->normRange()) {
860 name.Append(thisPdf->normRange()) ;
875 const RooAbsReal* RooAbsReal::createPlotProjection(
const RooArgSet& depVars,
const RooArgSet& projVars,
876 RooArgSet*& cloneSet)
const
878 return createPlotProjection(depVars,&projVars,cloneSet) ;
888 const RooAbsReal* RooAbsReal::createPlotProjection(
const RooArgSet& depVars,
const RooArgSet& projVars)
const
890 RooArgSet* cloneSet =
new RooArgSet() ;
891 return createPlotProjection(depVars,&projVars,cloneSet) ;
918 const RooAbsReal *RooAbsReal::createPlotProjection(
const RooArgSet &dependentVars,
const RooArgSet *projectedVars,
919 RooArgSet *&cloneSet,
const char* rangeName,
const RooArgSet* condObs)
const
924 leafNodeServerList(&leafNodes,
this);
925 treeNodeServerList(&treeNodes,
this) ;
931 for (
const auto arg : dependentVars) {
932 if(!arg->isFundamental() && !
dynamic_cast<const RooAbsLValue*
>(arg)) {
933 coutE(Plotting) << ClassName() <<
"::" << GetName() <<
":createPlotProjection: variable \"" << arg->GetName()
934 <<
"\" of wrong type: " << arg->ClassName() << endl;
938 RooAbsArg *found= treeNodes.find(arg->GetName());
940 coutE(Plotting) << ClassName() <<
"::" << GetName() <<
":createPlotProjection: \"" << arg->GetName()
941 <<
"\" is not a dependent and will be ignored." << endl;
945 if (leafNodes.find(found->GetName())) {
946 leafNodes.replace(*found,*arg);
948 leafNodes.add(*arg) ;
951 RooArgSet* lvDep = arg->getObservables(&leafNodes) ;
952 for (
const auto lvs : *lvDep) {
953 RooAbsArg* tmp = leafNodes.find(lvs->GetName()) ;
955 leafNodes.remove(*tmp) ;
956 leafNodes.add(*lvs) ;
963 if(0 != projectedVars && projectedVars->find(arg->GetName())) {
964 coutE(Plotting) << ClassName() <<
"::" << GetName() <<
":createPlotProjection: \"" << arg->GetName()
965 <<
"\" cannot be both a dependent and a projected variable." << endl;
971 if(0 != projectedVars) leafNodes.remove(*projectedVars,kTRUE);
974 cloneSet= (RooArgSet*)RooArgSet(*this).snapshot(kTRUE);
976 coutE(Plotting) <<
"RooAbsPdf::createPlotProjection(" << GetName() <<
") Couldn't deep-clone PDF, abort," << endl ;
979 RooAbsReal *theClone= (RooAbsReal*)cloneSet->find(GetName());
987 RooArgSet* plotLeafNodes = (RooArgSet*) leafNodes.selectCommon(dependentVars) ;
988 theClone->recursiveRedirectServers(*plotLeafNodes,kFALSE,kFALSE,kFALSE);
989 delete plotLeafNodes ;
992 RooArgSet normSet(dependentVars);
993 if(0 != projectedVars) normSet.add(*projectedVars);
995 normSet.remove(*condObs,kTRUE,kTRUE) ;
1002 if(0 == projectedVars) projectedVars= ∅
1004 TString name = GetName() ;
1005 name += integralNameSuffix(*projectedVars,&normSet,rangeName,kTRUE) ;
1007 TString title(GetTitle());
1008 title.Prepend(
"Projection of ");
1011 RooAbsReal* projected= theClone->createIntegral(*projectedVars,normSet,rangeName) ;
1013 if(0 == projected || !projected->isValid()) {
1014 coutE(Plotting) << ClassName() <<
"::" << GetName() <<
":createPlotProjection: cannot integrate out ";
1015 projectedVars->printStream(cout,kName|kArgs,kSingleLine);
1017 if(0 != projected)
delete projected;
1021 if(projected->InheritsFrom(RooRealIntegral::Class())){
1022 static_cast<RooRealIntegral*
>(projected)->setAllowComponentSelection(
true);
1025 projected->SetName(name.Data()) ;
1026 projected->SetTitle(title.Data()) ;
1029 cloneSet->addOwned(*projected);
1053 TH1 *RooAbsReal::fillHistogram(TH1 *hist,
const RooArgList &plotVars,
1054 Double_t scaleFactor,
const RooArgSet *projectedVars, Bool_t scaleForDensity,
1055 const RooArgSet* condObs, Bool_t setError)
const
1059 coutE(InputArguments) << ClassName() <<
"::" << GetName() <<
":fillHistogram: no valid histogram to fill" << endl;
1064 Int_t hdim= hist->GetDimension();
1065 if(hdim != plotVars.getSize()) {
1066 coutE(InputArguments) << ClassName() <<
"::" << GetName() <<
":fillHistogram: plotVars has the wrong dimension" << endl;
1073 RooArgSet plotClones;
1074 for(Int_t index= 0; index < plotVars.getSize(); index++) {
1075 const RooAbsArg *var= plotVars.at(index);
1076 const RooRealVar *realVar=
dynamic_cast<const RooRealVar*
>(var);
1078 coutE(InputArguments) << ClassName() <<
"::" << GetName() <<
":fillHistogram: cannot plot variable \"" << var->GetName()
1079 <<
"\" of type " << var->ClassName() << endl;
1082 if(!this->dependsOn(*realVar)) {
1083 coutE(InputArguments) << ClassName() <<
"::" << GetName()
1084 <<
":fillHistogram: WARNING: variable is not an explicit dependent: " << realVar->GetName() << endl;
1086 plotClones.addClone(*realVar,kTRUE);
1090 TIterator* pciter= plotClones.createIterator() ;
1092 while((pc=(RooAbsArg*)pciter->Next())) {
1093 pc->recursiveRedirectServers(plotClones,kFALSE,kFALSE,kTRUE) ;
1099 RooArgSet allDeps(plotClones) ;
1100 if (projectedVars) {
1101 allDeps.add(*projectedVars) ;
1103 if (checkObservables(&allDeps)) {
1104 coutE(InputArguments) <<
"RooAbsReal::fillHistogram(" << GetName() <<
") error in checkObservables, abort" << endl ;
1109 RooArgSet *cloneSet = 0;
1110 const RooAbsReal *projected= createPlotProjection(plotClones,projectedVars,cloneSet,0,condObs);
1112 cxcoutD(Plotting) <<
"RooAbsReal::fillHistogram(" << GetName() <<
") plot projection object is " << projected->GetName() << endl ;
1115 Int_t xbins(0),ybins(1),zbins(1);
1116 RooRealVar *xvar = 0;
1117 RooRealVar *yvar = 0;
1118 RooRealVar *zvar = 0;
1124 zbins= hist->GetNbinsZ();
1125 zvar=
dynamic_cast<RooRealVar*
>(plotClones.find(plotVars.at(2)->GetName()));
1126 zaxis= hist->GetZaxis();
1127 assert(0 != zvar && 0 != zaxis);
1128 if (scaleForDensity) {
1129 scaleFactor*= (zaxis->GetXmax() - zaxis->GetXmin())/zbins;
1133 ybins= hist->GetNbinsY();
1134 yvar=
dynamic_cast<RooRealVar*
>(plotClones.find(plotVars.at(1)->GetName()));
1135 yaxis= hist->GetYaxis();
1136 assert(0 != yvar && 0 != yaxis);
1137 if (scaleForDensity) {
1138 scaleFactor*= (yaxis->GetXmax() - yaxis->GetXmin())/ybins;
1142 xbins= hist->GetNbinsX();
1143 xvar=
dynamic_cast<RooRealVar*
>(plotClones.find(plotVars.at(0)->GetName()));
1144 xaxis= hist->GetXaxis();
1145 assert(0 != xvar && 0 != xaxis);
1146 if (scaleForDensity) {
1147 scaleFactor*= (xaxis->GetXmax() - xaxis->GetXmin())/xbins;
1151 coutE(InputArguments) << ClassName() <<
"::" << GetName() <<
":fillHistogram: cannot fill histogram with "
1152 << hdim <<
" dimensions" << endl;
1158 RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;
1159 Int_t xbin(0),ybin(0),zbin(0);
1160 Int_t bins= xbins*ybins*zbins;
1161 for(Int_t bin= 0; bin < bins; bin++) {
1164 if(bin % (xbins*ybins) == 0) {
1166 zvar->setVal(zaxis->GetBinCenter(zbin));
1170 if(bin % xbins == 0) {
1171 ybin= (ybin%ybins) + 1;
1172 yvar->setVal(yaxis->GetBinCenter(ybin));
1176 xbin= (xbin%xbins) + 1;
1177 xvar->setVal(xaxis->GetBinCenter(xbin));
1180 coutE(InputArguments) <<
"RooAbsReal::fillHistogram: Internal Error!" << endl;
1184 Double_t result= scaleFactor*projected->getVal();
1185 if (RooAbsReal::numEvalErrors()>0) {
1186 coutW(Plotting) <<
"WARNING: Function evaluation error(s) at coordinates [x]=" << xvar->getVal() ;
1187 if (hdim==2) ccoutW(Plotting) <<
" [y]=" << yvar->getVal() ;
1188 if (hdim==3) ccoutW(Plotting) <<
" [z]=" << zvar->getVal() ;
1189 ccoutW(Plotting) << endl ;
1193 RooAbsReal::clearEvalErrorLog() ;
1195 hist->SetBinContent(hist->GetBin(xbin,ybin,zbin),result);
1197 hist->SetBinError(hist->GetBin(xbin,ybin,zbin),sqrt(result)) ;
1202 RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;
1230 RooDataHist* RooAbsReal::fillDataHist(RooDataHist *hist,
const RooArgSet* normSet, Double_t scaleFactor,
1231 Bool_t correctForBinSize, Bool_t showProgress)
const
1235 coutE(InputArguments) << ClassName() <<
"::" << GetName() <<
":fillDataHist: no valid RooDataHist to fill" << endl;
1240 RooArgSet allDeps(*hist->get()) ;
1241 if (checkObservables(&allDeps)) {
1242 coutE(InputArguments) <<
"RooAbsReal::fillDataHist(" << GetName() <<
") error in checkObservables, abort" << endl ;
1248 RooArgSet* cloneSet = (RooArgSet*) RooArgSet(*this).snapshot(kTRUE) ;
1249 RooAbsReal* theClone = (RooAbsReal*) cloneSet->find(GetName()) ;
1250 theClone->recursiveRedirectServers(*hist->get()) ;
1254 Int_t onePct = hist->numEntries()/100 ;
1258 for (Int_t i=0 ; i<hist->numEntries() ; i++) {
1259 if (showProgress && (i%onePct==0)) {
1260 ccoutP(Eval) <<
"." << flush ;
1262 const RooArgSet* obs = hist->get(i) ;
1263 Double_t binVal = theClone->getVal(normSet?normSet:obs)*scaleFactor ;
1264 if (correctForBinSize) {
1265 binVal*= hist->binVolume() ;
1292 TH1* RooAbsReal::createHistogram(
const char* varNameList, Int_t xbins, Int_t ybins, Int_t zbins)
const
1296 strlcpy(buf,varNameList,1024) ;
1297 char* varName = strtok(buf,
",:") ;
1299 RooArgSet* vars = getVariables() ;
1301 RooRealVar* xvar = (RooRealVar*) vars->find(varName) ;
1302 varName = strtok(0,
",") ;
1303 RooRealVar* yvar = varName ? (RooRealVar*) vars->find(varName) : 0 ;
1304 varName = strtok(0,
",") ;
1305 RooRealVar* zvar = varName ? (RooRealVar*) vars->find(varName) : 0 ;
1311 RooLinkedList argList ;
1313 argList.Add(RooFit::Binning(xbins).Clone()) ;
1318 argList.Add(RooFit::YVar(*yvar,RooFit::Binning(ybins)).Clone()) ;
1320 argList.Add(RooFit::YVar(*yvar).Clone()) ;
1327 argList.Add(RooFit::ZVar(*zvar,RooFit::Binning(zbins)).Clone()) ;
1329 argList.Add(RooFit::ZVar(*zvar).Clone()) ;
1335 TH1* result = createHistogram(GetName(),*xvar,argList) ;
1373 TH1 *RooAbsReal::createHistogram(
const char *name,
const RooAbsRealLValue& xvar,
1374 const RooCmdArg& arg1,
const RooCmdArg& arg2,
const RooCmdArg& arg3,
const RooCmdArg& arg4,
1375 const RooCmdArg& arg5,
const RooCmdArg& arg6,
const RooCmdArg& arg7,
const RooCmdArg& arg8)
const
1379 l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
1380 l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
1381 l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
1382 l.Add((TObject*)&arg7) ; l.Add((TObject*)&arg8) ;
1384 return createHistogram(name,xvar,l) ;
1391 TH1* RooAbsReal::createHistogram(
const char *name,
const RooAbsRealLValue& xvar, RooLinkedList& argList)
const
1395 RooCmdConfig pc(Form(
"RooAbsReal::createHistogram(%s)",GetName())) ;
1396 pc.defineInt(
"scaling",
"Scaling",0,1) ;
1397 pc.defineInt(
"intBinning",
"IntrinsicBinning",0,2) ;
1398 pc.defineInt(
"extended",
"Extended",0,2) ;
1400 pc.defineObject(
"compSet",
"SelectCompSet",0) ;
1401 pc.defineString(
"compSpec",
"SelectCompSpec",0) ;
1402 pc.defineSet(
"projObs",
"ProjectedObservables",0,0) ;
1403 pc.defineObject(
"yvar",
"YVar",0,0) ;
1404 pc.defineObject(
"zvar",
"ZVar",0,0) ;
1405 pc.defineMutex(
"SelectCompSet",
"SelectCompSpec") ;
1406 pc.defineMutex(
"IntrinsicBinning",
"Binning") ;
1407 pc.defineMutex(
"IntrinsicBinning",
"BinningName") ;
1408 pc.defineMutex(
"IntrinsicBinning",
"BinningSpec") ;
1409 pc.allowUndefined() ;
1412 pc.process(argList) ;
1413 if (!pc.ok(kTRUE)) {
1417 RooArgList vars(xvar) ;
1418 RooAbsArg* yvar =
static_cast<RooAbsArg*
>(pc.getObject(
"yvar")) ;
1422 RooAbsArg* zvar =
static_cast<RooAbsArg*
>(pc.getObject(
"zvar")) ;
1427 RooArgSet* projObs = pc.getSet(
"projObs") ;
1428 RooArgSet* intObs = 0 ;
1430 Bool_t doScaling = pc.getInt(
"scaling") ;
1431 Int_t doIntBinning = pc.getInt(
"intBinning") ;
1432 Int_t doExtended = pc.getInt(
"extended") ;
1435 const RooAbsPdf* pdfSelf =
dynamic_cast<const RooAbsPdf*
>(
this) ;
1436 if (!pdfSelf && doExtended>0) {
1437 coutW(InputArguments) <<
"RooAbsReal::createHistogram(" << GetName() <<
") WARNING extended mode requested for a non-pdf object, ignored" << endl ;
1440 if (pdfSelf && doExtended==1 && pdfSelf->extendMode()==RooAbsPdf::CanNotBeExtended) {
1441 coutW(InputArguments) <<
"RooAbsReal::createHistogram(" << GetName() <<
") WARNING extended mode requested for a non-extendable pdf, ignored" << endl ;
1444 if (pdfSelf && doExtended==2) {
1445 doExtended = pdfSelf->extendMode()==RooAbsPdf::CanNotBeExtended ? 0 : 1 ;
1448 const char* compSpec = pc.getString(
"compSpec") ;
1449 const RooArgSet* compSet = (
const RooArgSet*) pc.getObject(
"compSet") ;
1450 Bool_t haveCompSel = ( (compSpec && strlen(compSpec)>0) || compSet) ;
1452 RooBinning* intBinning(0) ;
1453 if (doIntBinning>0) {
1455 list<Double_t>* bl = binBoundaries((RooRealVar&)xvar,xvar.getMin(),xvar.getMax()) ;
1458 if (doIntBinning==1) {
1459 coutW(InputArguments) <<
"RooAbsReal::createHistogram(" << GetName()
1460 <<
") WARNING, intrinsic model binning requested for histogram, but model does not define bin boundaries, reverting to default binning"<< endl ;
1463 if (doIntBinning==2) {
1464 coutI(InputArguments) <<
"RooAbsReal::createHistogram(" << GetName()
1465 <<
") INFO: Model has intrinsic binning definition, selecting that binning for the histogram"<< endl ;
1467 Double_t* ba =
new Double_t[bl->size()] ;
int i=0 ;
1468 for (list<double>::iterator it=bl->begin() ; it!=bl->end() ; ++it) { ba[i++] = *it ; }
1469 intBinning =
new RooBinning(bl->size()-1,ba) ;
1474 RooLinkedList argListCreate(argList) ;
1475 pc.stripCmdList(argListCreate,
"Scaling,ProjectedObservables,IntrinsicBinning,SelectCompSet,SelectCompSpec,Extended") ;
1479 RooCmdArg tmp = RooFit::Binning(*intBinning) ;
1480 argListCreate.Add(&tmp) ;
1481 histo = xvar.createHistogram(name,argListCreate) ;
1484 histo = xvar.createHistogram(name,argListCreate) ;
1491 RooArgSet branchNodeSet ;
1492 branchNodeServerList(&branchNodeSet) ;
1495 TIterator* iter = branchNodeSet.createIterator() ;
1497 while((arg=(RooAbsArg*)iter->Next())) {
1498 if (!dynamic_cast<RooAbsReal*>(arg)) {
1499 branchNodeSet.remove(*arg) ;
1504 RooArgSet* dirSelNodes ;
1506 dirSelNodes = (RooArgSet*) branchNodeSet.selectCommon(*compSet) ;
1508 dirSelNodes = (RooArgSet*) branchNodeSet.selectByName(compSpec) ;
1510 if (dirSelNodes->getSize()>0) {
1511 coutI(Plotting) <<
"RooAbsPdf::createHistogram(" << GetName() <<
") directly selected PDF components: " << *dirSelNodes << endl ;
1514 plotOnCompSelect(dirSelNodes) ;
1517 coutE(Plotting) <<
"RooAbsPdf::createHistogram(" << GetName() <<
") ERROR: component selection set " << *compSet <<
" does not match any components of p.d.f." << endl ;
1519 coutE(Plotting) <<
"RooAbsPdf::createHistogram(" << GetName() <<
") ERROR: component selection expression '" << compSpec <<
"' does not select any components of p.d.f." << endl ;
1523 delete dirSelNodes ;
1526 Double_t scaleFactor(1.0) ;
1528 scaleFactor = pdfSelf->expectedEvents(vars) ;
1532 fillHistogram(histo,vars,scaleFactor,intObs,doScaling,projObs,kFALSE) ;
1536 plotOnCompSelect(0) ;
1551 void RooAbsReal::plotOnCompSelect(RooArgSet* selNodes)
const
1554 RooArgSet branchNodeSet;
1555 branchNodeServerList(&branchNodeSet);
1559 for (
unsigned int i = 0; i < branchNodeSet.size(); ++i) {
1560 const auto arg = branchNodeSet[i];
1561 if (!dynamic_cast<RooAbsReal*>(arg)) {
1562 branchNodeSet.remove(*arg) ;
1569 for (
const auto arg : branchNodeSet) {
1570 static_cast<RooAbsReal*
>(arg)->selectComp(
true);
1578 for (
const auto arg : branchNodeSet) {
1579 for (
const auto selNode : *selNodes) {
1580 if (selNode->dependsOn(*arg)) {
1581 tmp.add(*arg,kTRUE);
1587 for (
const auto arg : branchNodeSet) {
1588 if (arg->dependsOn(*selNodes)) {
1589 tmp.add(*arg,kTRUE);
1593 tmp.remove(*selNodes,
true);
1596 coutI(Plotting) <<
"RooAbsPdf::plotOn(" << GetName() <<
") indirectly selected PDF components: " << tmp << endl ;
1599 for (
const auto arg : branchNodeSet) {
1600 Bool_t select = selNodes->find(arg->GetName()) !=
nullptr;
1601 static_cast<RooAbsReal*
>(arg)->selectComp(select);
1715 RooPlot* RooAbsReal::plotOn(RooPlot* frame,
const RooCmdArg& arg1,
const RooCmdArg& arg2,
1716 const RooCmdArg& arg3,
const RooCmdArg& arg4,
1717 const RooCmdArg& arg5,
const RooCmdArg& arg6,
1718 const RooCmdArg& arg7,
const RooCmdArg& arg8,
1719 const RooCmdArg& arg9,
const RooCmdArg& arg10)
const
1722 l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
1723 l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
1724 l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
1725 l.Add((TObject*)&arg7) ; l.Add((TObject*)&arg8) ;
1726 l.Add((TObject*)&arg9) ; l.Add((TObject*)&arg10) ;
1727 return plotOn(frame,l) ;
1735 RooPlot* RooAbsReal::plotOn(RooPlot* frame, RooLinkedList& argList)
const
1740 RooCmdArg* rcmd = (RooCmdArg*) argList.FindObject(
"RangeWithName") ;
1741 if (rcmd && TString(rcmd->getString(0)).Contains(
",")) {
1744 RooCmdArg rnorm = RooFit::NormRange(rcmd->getString(0)) ;
1745 argList.Add(&rnorm) ;
1747 std::vector<string> rlist;
1750 for (
const std::string& rangeNameToken : RooHelpers::tokenise(rcmd->getString(0),
",")) {
1751 rlist.emplace_back(rangeNameToken);
1754 for (
const auto& rangeString : rlist) {
1756 rcmd->setString(0, rangeString.c_str());
1757 RooAbsReal::plotOn(frame,argList);
1764 RooCmdConfig pc(Form(
"RooAbsReal::plotOn(%s)",GetName())) ;
1765 pc.defineString(
"drawOption",
"DrawOption",0,
"L") ;
1766 pc.defineString(
"projectionRangeName",
"ProjectionRange",0,
"",kTRUE) ;
1767 pc.defineString(
"curveNameSuffix",
"CurveNameSuffix",0,
"") ;
1768 pc.defineString(
"sliceCatState",
"SliceCat",0,
"",kTRUE) ;
1769 pc.defineDouble(
"scaleFactor",
"Normalization",0,1.0) ;
1770 pc.defineInt(
"scaleType",
"Normalization",0,Relative) ;
1771 pc.defineObject(
"sliceSet",
"SliceVars",0) ;
1772 pc.defineObject(
"sliceCatList",
"SliceCat",0,0,kTRUE) ;
1773 pc.defineObject(
"projSet",
"Project",0) ;
1774 pc.defineObject(
"asymCat",
"Asymmetry",0) ;
1775 pc.defineDouble(
"precision",
"Precision",0,1e-3) ;
1776 pc.defineDouble(
"evalErrorVal",
"EvalErrorValue",0,0) ;
1777 pc.defineInt(
"doEvalError",
"EvalErrorValue",0,0) ;
1778 pc.defineInt(
"shiftToZero",
"ShiftToZero",0,0) ;
1779 pc.defineObject(
"projDataSet",
"ProjData",0) ;
1780 pc.defineObject(
"projData",
"ProjData",1) ;
1781 pc.defineObject(
"errorFR",
"VisualizeError",0) ;
1782 pc.defineDouble(
"errorZ",
"VisualizeError",0,1.) ;
1783 pc.defineSet(
"errorPars",
"VisualizeError",0) ;
1784 pc.defineInt(
"linearMethod",
"VisualizeError",0,0) ;
1785 pc.defineInt(
"binProjData",
"ProjData",0,0) ;
1786 pc.defineDouble(
"rangeLo",
"Range",0,-999.) ;
1787 pc.defineDouble(
"rangeHi",
"Range",1,-999.) ;
1788 pc.defineInt(
"numee",
"PrintEvalErrors",0,10) ;
1789 pc.defineInt(
"rangeAdjustNorm",
"Range",0,0) ;
1790 pc.defineInt(
"rangeWNAdjustNorm",
"RangeWithName",0,0) ;
1791 pc.defineInt(
"VLines",
"VLines",0,2) ;
1792 pc.defineString(
"rangeName",
"RangeWithName",0,
"") ;
1793 pc.defineString(
"normRangeName",
"NormRange",0,
"") ;
1794 pc.defineInt(
"markerColor",
"MarkerColor",0,-999) ;
1795 pc.defineInt(
"markerStyle",
"MarkerStyle",0,-999) ;
1796 pc.defineDouble(
"markerSize",
"MarkerSize",0,-999) ;
1797 pc.defineInt(
"lineColor",
"LineColor",0,-999) ;
1798 pc.defineInt(
"lineStyle",
"LineStyle",0,-999) ;
1799 pc.defineInt(
"lineWidth",
"LineWidth",0,-999) ;
1800 pc.defineInt(
"fillColor",
"FillColor",0,-999) ;
1801 pc.defineInt(
"fillStyle",
"FillStyle",0,-999) ;
1802 pc.defineString(
"curveName",
"Name",0,
"") ;
1803 pc.defineInt(
"curveInvisible",
"Invisible",0,0) ;
1804 pc.defineInt(
"showProg",
"ShowProgress",0,0) ;
1805 pc.defineInt(
"numCPU",
"NumCPU",0,1) ;
1806 pc.defineInt(
"interleave",
"NumCPU",1,0) ;
1807 pc.defineString(
"addToCurveName",
"AddTo",0,
"") ;
1808 pc.defineDouble(
"addToWgtSelf",
"AddTo",0,1.) ;
1809 pc.defineDouble(
"addToWgtOther",
"AddTo",1,1.) ;
1810 pc.defineInt(
"moveToBack",
"MoveToBack",0,0) ;
1811 pc.defineMutex(
"SliceVars",
"Project") ;
1812 pc.defineMutex(
"AddTo",
"Asymmetry") ;
1813 pc.defineMutex(
"Range",
"RangeWithName") ;
1814 pc.defineMutex(
"VisualizeError",
"VisualizeErrorData") ;
1817 pc.process(argList) ;
1818 if (!pc.ok(kTRUE)) {
1823 TString drawOpt(pc.getString(
"drawOption"));
1825 RooFitResult* errFR = (RooFitResult*) pc.getObject(
"errorFR") ;
1826 Double_t errZ = pc.getDouble(
"errorZ") ;
1827 RooArgSet* errPars = pc.getSet(
"errorPars") ;
1828 Bool_t linMethod = pc.getInt(
"linearMethod") ;
1829 if (!drawOpt.Contains(
"P") && errFR) {
1830 return plotOnWithErrorBand(frame,*errFR,errZ,errPars,argList,linMethod) ;
1836 o.numee = pc.getInt(
"numee") ;
1837 o.drawOptions = drawOpt.Data();
1838 o.curveNameSuffix = pc.getString(
"curveNameSuffix") ;
1839 o.scaleFactor = pc.getDouble(
"scaleFactor") ;
1840 o.stype = (ScaleType) pc.getInt(
"scaleType") ;
1841 o.projData = (
const RooAbsData*) pc.getObject(
"projData") ;
1842 o.binProjData = pc.getInt(
"binProjData") ;
1843 o.projDataSet = (
const RooArgSet*) pc.getObject(
"projDataSet") ;
1844 o.numCPU = pc.getInt(
"numCPU") ;
1845 o.interleave = (RooFit::MPSplit) pc.getInt(
"interleave") ;
1846 o.eeval = pc.getDouble(
"evalErrorVal") ;
1847 o.doeeval = pc.getInt(
"doEvalError") ;
1849 const RooArgSet* sliceSetTmp = (
const RooArgSet*) pc.getObject(
"sliceSet") ;
1850 RooArgSet* sliceSet = sliceSetTmp ? ((RooArgSet*) sliceSetTmp->Clone()) : 0 ;
1851 const RooArgSet* projSet = (
const RooArgSet*) pc.getObject(
"projSet") ;
1852 const RooAbsCategoryLValue* asymCat = (
const RooAbsCategoryLValue*) pc.getObject(
"asymCat") ;
1856 const char* sliceCatState = pc.getString(
"sliceCatState",0,kTRUE) ;
1857 const RooLinkedList& sliceCatList = pc.getObjectList(
"sliceCatList") ;
1858 if (sliceCatState) {
1862 sliceSet =
new RooArgSet ;
1867 strlcpy(buf,sliceCatState,1024) ;
1868 const char* slabel = strtok(buf,
",") ;
1871 TIterator* iter = sliceCatList.MakeIterator() ;
1873 while((scat=(RooCategory*)iter->Next())) {
1876 scat->setLabel(slabel) ;
1878 sliceSet->add(*scat,kFALSE) ;
1880 slabel = strtok(0,
",") ;
1885 o.precision = pc.getDouble(
"precision") ;
1886 o.shiftToZero = (pc.getInt(
"shiftToZero")!=0) ;
1887 Int_t vlines = pc.getInt(
"VLines");
1888 if (pc.hasProcessed(
"Range")) {
1889 o.rangeLo = pc.getDouble(
"rangeLo") ;
1890 o.rangeHi = pc.getDouble(
"rangeHi") ;
1891 o.postRangeFracScale = pc.getInt(
"rangeAdjustNorm") ;
1892 if (vlines==2) vlines=0 ;
1893 }
else if (pc.hasProcessed(
"RangeWithName")) {
1894 o.normRangeName = pc.getString(
"rangeName",0,kTRUE) ;
1895 o.rangeLo = frame->getPlotVar()->getMin(pc.getString(
"rangeName",0,kTRUE)) ;
1896 o.rangeHi = frame->getPlotVar()->getMax(pc.getString(
"rangeName",0,kTRUE)) ;
1897 o.postRangeFracScale = pc.getInt(
"rangeWNAdjustNorm") ;
1898 if (vlines==2) vlines=0 ;
1903 if (pc.hasProcessed(
"NormRange")) {
1904 o.normRangeName = pc.getString(
"normRangeName") ;
1905 o.postRangeFracScale = kTRUE ;
1908 o.wmode = (vlines==2)?RooCurve::Extended:(vlines==1?RooCurve::Straight:RooCurve::NoWings) ;
1909 o.projectionRangeName = pc.getString(
"projectionRangeName",0,kTRUE) ;
1910 o.curveName = pc.getString(
"curveName",0,kTRUE) ;
1911 o.curveInvisible = pc.getInt(
"curveInvisible") ;
1912 o.progress = pc.getInt(
"showProg") ;
1913 o.addToCurveName = pc.getString(
"addToCurveName",0,kTRUE) ;
1914 o.addToWgtSelf = pc.getDouble(
"addToWgtSelf") ;
1915 o.addToWgtOther = pc.getDouble(
"addToWgtOther") ;
1917 if (o.addToCurveName && !frame->findObject(o.addToCurveName,RooCurve::Class())) {
1918 coutE(InputArguments) <<
"RooAbsReal::plotOn(" << GetName() <<
") cannot find existing curve " << o.addToCurveName <<
" to add to in RooPlot" << endl ;
1922 RooArgSet projectedVars ;
1924 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") Preprocessing: have slice " << *sliceSet << endl ;
1926 makeProjectionSet(frame->getPlotVar(),frame->getNormVars(),projectedVars,kTRUE) ;
1929 TIterator* iter = sliceSet->createIterator() ;
1930 RooAbsArg* sliceArg ;
1931 while((sliceArg=(RooAbsArg*)iter->Next())) {
1932 RooAbsArg* arg = projectedVars.find(sliceArg->GetName()) ;
1934 projectedVars.remove(*arg) ;
1936 coutI(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") slice variable "
1937 << sliceArg->GetName() <<
" was not projected anyway" << endl ;
1941 }
else if (projSet) {
1942 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") Preprocessing: have projSet " << *projSet << endl ;
1943 makeProjectionSet(frame->getPlotVar(),projSet,projectedVars,kFALSE) ;
1945 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") Preprocessing: have neither sliceSet nor projSet " << endl ;
1946 makeProjectionSet(frame->getPlotVar(),frame->getNormVars(),projectedVars,kTRUE) ;
1948 o.projSet = &projectedVars ;
1950 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") Preprocessing: projectedVars = " << projectedVars << endl ;
1956 ret = RooAbsReal::plotOn(frame,o) ;
1959 ret = RooAbsReal::plotAsymOn(frame,*asymCat,o) ;
1965 Int_t lineColor = pc.getInt(
"lineColor") ;
1966 Int_t lineStyle = pc.getInt(
"lineStyle") ;
1967 Int_t lineWidth = pc.getInt(
"lineWidth") ;
1968 Int_t markerColor = pc.getInt(
"markerColor") ;
1969 Int_t markerStyle = pc.getInt(
"markerStyle") ;
1970 Size_t markerSize = pc.getDouble(
"markerSize") ;
1971 Int_t fillColor = pc.getInt(
"fillColor") ;
1972 Int_t fillStyle = pc.getInt(
"fillStyle") ;
1973 if (lineColor!=-999) ret->getAttLine()->SetLineColor(lineColor) ;
1974 if (lineStyle!=-999) ret->getAttLine()->SetLineStyle(lineStyle) ;
1975 if (lineWidth!=-999) ret->getAttLine()->SetLineWidth(lineWidth) ;
1976 if (fillColor!=-999) ret->getAttFill()->SetFillColor(fillColor) ;
1977 if (fillStyle!=-999) ret->getAttFill()->SetFillStyle(fillStyle) ;
1978 if (markerColor!=-999) ret->getAttMarker()->SetMarkerColor(markerColor) ;
1979 if (markerStyle!=-999) ret->getAttMarker()->SetMarkerStyle(markerStyle) ;
1980 if (markerSize!=-999) ret->getAttMarker()->SetMarkerSize(markerSize) ;
1983 if (pc.getInt(
"moveToBack") && frame->numItems()>1) {
1984 frame->drawBefore(frame->getObject(0)->GetName(), frame->getCurve()->GetName());
2009 RooPlot* RooAbsReal::plotOn(RooPlot *frame, PlotOpt o)
const
2014 if (plotSanityChecks(frame))
return frame ;
2017 RooArgSet projDataVars ;
2019 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") have ProjData with observables = " << *o.projData->get() << endl ;
2020 if (o.projDataSet) {
2021 RooArgSet* tmp = (RooArgSet*) o.projData->get()->selectCommon(*o.projDataSet) ;
2022 projDataVars.add(*tmp) ;
2023 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") have ProjDataSet = " << *o.projDataSet <<
" will only use this subset of projData" << endl ;
2026 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") using full ProjData" << endl ;
2027 projDataVars.add(*o.projData->get()) ;
2031 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") ProjDataVars = " << projDataVars << endl ;
2034 RooArgSet projectedVars ;
2035 RooArgSet sliceSet ;
2037 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") have input projSet = " << *o.projSet << endl ;
2038 makeProjectionSet(frame->getPlotVar(),o.projSet,projectedVars,kFALSE) ;
2039 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") calculated projectedVars = " << *o.projSet << endl ;
2042 if (frame->getNormVars()) {
2043 RooArgSet *sliceSetTmp = getObservables(*frame->getNormVars()) ;
2045 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") frame->getNormVars() that are also observables = " << *sliceSetTmp << endl ;
2047 sliceSetTmp->remove(projectedVars,kTRUE,kTRUE) ;
2048 sliceSetTmp->remove(*frame->getPlotVar(),kTRUE,kTRUE) ;
2051 RooArgSet* tmp = (RooArgSet*) projDataVars.selectCommon(*o.projSet) ;
2052 sliceSetTmp->remove(*tmp,kTRUE,kTRUE) ;
2056 if (sliceSetTmp->getSize()) {
2057 coutI(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") plot on "
2058 << frame->getPlotVar()->GetName() <<
" represents a slice in " << *sliceSetTmp << endl ;
2060 sliceSet.add(*sliceSetTmp) ;
2061 delete sliceSetTmp ;
2064 makeProjectionSet(frame->getPlotVar(),frame->getNormVars(),projectedVars,kTRUE) ;
2067 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") projectedVars = " << projectedVars <<
" sliceSet = " << sliceSet << endl ;
2070 RooArgSet* projDataNeededVars = 0 ;
2073 projDataNeededVars = (RooArgSet*) projectedVars.selectCommon(projDataVars) ;
2074 projectedVars.remove(projDataVars,kTRUE,kTRUE) ;
2078 RooAbsReal* realVar = (RooRealVar*) frame->getPlotVar() ;
2079 RooArgSet* plotCloneSet = (RooArgSet*) RooArgSet(*realVar).snapshot(kTRUE) ;
2080 if (!plotCloneSet) {
2081 coutE(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") Couldn't deep-clone self, abort," << endl ;
2084 RooRealVar* plotVar = (RooRealVar*) plotCloneSet->find(realVar->GetName());
2087 if (projectedVars.getSize()) {
2088 coutI(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") plot on " << plotVar->GetName()
2089 <<
" integrates over variables " << projectedVars
2090 << (o.projectionRangeName?Form(
" in range %s",o.projectionRangeName):
"") << endl;
2092 if (projDataNeededVars && projDataNeededVars->getSize()>0) {
2093 coutI(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") plot on " << plotVar->GetName()
2094 <<
" averages using data variables " << *projDataNeededVars << endl ;
2098 RooArgSet* projectionCompList = 0 ;
2100 RooArgSet* deps = getObservables(frame->getNormVars()) ;
2101 deps->remove(projectedVars,kTRUE,kTRUE) ;
2102 if (projDataNeededVars) {
2103 deps->remove(*projDataNeededVars,kTRUE,kTRUE) ;
2105 deps->remove(*plotVar,kTRUE,kTRUE) ;
2106 deps->add(*plotVar) ;
2111 if (checkObservables(deps)) {
2112 coutE(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") error in checkObservables, abort" << endl ;
2114 delete plotCloneSet ;
2115 if (projDataNeededVars)
delete projDataNeededVars ;
2119 RooArgSet normSet(*deps) ;
2122 RooAbsReal *projection = (RooAbsReal*) createPlotProjection(normSet, &projectedVars, projectionCompList, o.projectionRangeName) ;
2123 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") plot projection object is " << projection->GetName() << endl ;
2124 if (dologD(Plotting)) {
2125 projection->printStream(ccoutD(Plotting),0,kVerbose) ;
2129 RooArgSet fullNormSet(*deps) ;
2130 fullNormSet.add(projectedVars) ;
2131 if (projDataNeededVars && projDataNeededVars->getSize()>0) {
2132 fullNormSet.add(*projDataNeededVars) ;
2134 RooArgSet* compSet = projection->getComponents() ;
2135 TIterator* iter = compSet->createIterator() ;
2137 while((arg=(RooAbsArg*)iter->Next())) {
2138 RooAbsPdf* pdf =
dynamic_cast<RooAbsPdf*
>(arg) ;
2140 pdf->selectNormalization(&fullNormSet) ;
2148 if (o.projData && projDataNeededVars && projDataNeededVars->getSize()>0) {
2151 RooAbsData* projDataSel = (RooAbsData*)o.projData;
2153 if (projDataNeededVars->getSize()<o.projData->get()->getSize()) {
2156 RooArgSet* sliceDataSet = (RooArgSet*) sliceSet.selectCommon(*o.projData->get()) ;
2158 if (sliceDataSet->getSize()>0) {
2159 TIterator* iter2 = sliceDataSet->createIterator() ;
2160 RooAbsArg* sliceVar ;
2161 Bool_t first(kTRUE) ;
2162 while((sliceVar=(RooAbsArg*)iter2->Next())) {
2164 cutString.Append(
"&&") ;
2169 RooAbsRealLValue* real ;
2170 RooAbsCategoryLValue* cat ;
2171 if ((real = dynamic_cast<RooAbsRealLValue*>(sliceVar))) {
2172 cutString.Append(Form(
"%s==%f",real->GetName(),real->getVal())) ;
2173 }
else if ((cat = dynamic_cast<RooAbsCategoryLValue*>(sliceVar))) {
2174 cutString.Append(Form(
"%s==%d",cat->GetName(),cat->getIndex())) ;
2179 delete sliceDataSet ;
2181 if (!cutString.IsNull()) {
2182 projDataSel = ((RooAbsData*)o.projData)->reduce(*projDataNeededVars,cutString) ;
2183 coutI(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") reducing given projection dataset to entries with " << cutString << endl ;
2185 projDataSel = ((RooAbsData*)o.projData)->reduce(*projDataNeededVars) ;
2187 coutI(Plotting) <<
"RooAbsReal::plotOn(" << GetName()
2188 <<
") only the following components of the projection data will be used: " << *projDataNeededVars << endl ;
2192 if (!o.binProjData && dynamic_cast<RooDataSet*>(projDataSel)!=0) {
2195 TIterator* iter2 = projDataSel->get()->createIterator() ;
2196 Bool_t allCat(kTRUE) ;
2198 while((arg2=(RooAbsArg*)iter2->Next())) {
2199 if (!dynamic_cast<RooCategory*>(arg2)) allCat = kFALSE ;
2203 o.binProjData = kTRUE ;
2204 coutI(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") unbinned projection dataset consist only of discrete variables,"
2205 <<
" performing projection with binned copy for optimization." << endl ;
2211 if (o.binProjData) {
2212 RooAbsData* tmp =
new RooDataHist(Form(
"%s_binned",projDataSel->GetName()),
"Binned projection data",*projDataSel->get(),*projDataSel) ;
2213 if (projDataSel!=o.projData)
delete projDataSel ;
2220 projection->getVal(projDataSel->get()) ;
2221 projection->attachDataSet(*projDataSel) ;
2224 RooDataWeightedAverage dwa(Form(
"%sDataWgtAvg",GetName()),
"Data Weighted average",*projection,*projDataSel,RooArgSet(),o.numCPU,o.interleave,kTRUE) ;
2228 dwa.constOptimizeTestStatistic(Activate,kFALSE) ;
2230 RooRealBinding projBind(dwa,*plotVar) ;
2231 RooScaledFunc scaleBind(projBind,o.scaleFactor);
2234 if (o.rangeLo==0 && o.rangeHi==0) {
2235 o.rangeLo = frame->GetXaxis()->GetXmin() ;
2236 o.rangeHi = frame->GetXaxis()->GetXmax() ;
2240 TString curveName(projection->GetName()) ;
2241 curveName.Append(Form(
"_DataAvg[%s]",projDataSel->get()->contentsString().c_str())) ;
2243 if (sliceSet.getSize()>0) {
2244 curveName.Append(Form(
"_Slice[%s]",sliceSet.contentsString().c_str())) ;
2247 if (o.curveNameSuffix) {
2248 curveName.Append(o.curveNameSuffix) ;
2252 RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;
2253 RooCurve *curve =
new RooCurve(projection->GetName(),projection->GetTitle(),scaleBind,
2254 o.rangeLo,o.rangeHi,frame->GetNbinsX(),o.precision,o.precision,o.shiftToZero,o.wmode,o.numee,o.doeeval,o.eeval) ;
2255 RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;
2257 curve->SetName(curveName.Data()) ;
2260 if (o.addToCurveName) {
2261 RooCurve* otherCurve =
static_cast<RooCurve*
>(frame->findObject(o.addToCurveName,RooCurve::Class())) ;
2264 RooCurve* sumCurve =
new RooCurve(projection->GetName(),projection->GetTitle(),*curve,*otherCurve,o.addToWgtSelf,o.addToWgtOther) ;
2265 sumCurve->SetName(Form(
"%s_PLUS_%s",curve->GetName(),otherCurve->GetName())) ;
2272 curve->SetName(o.curveName) ;
2276 frame->addPlotable(curve, o.drawOptions, o.curveInvisible);
2278 if (projDataSel!=o.projData)
delete projDataSel ;
2283 if (o.rangeLo==0 && o.rangeHi==0) {
2284 o.rangeLo = frame->GetXaxis()->GetXmin() ;
2285 o.rangeHi = frame->GetXaxis()->GetXmax() ;
2290 if (o.postRangeFracScale) {
2291 if (!o.normRangeName) {
2292 o.normRangeName =
"plotRange" ;
2293 plotVar->setRange(
"plotRange",o.rangeLo,o.rangeHi) ;
2297 GlobalSelectComponentRAII selectCompRAII(
true);
2298 RooAbsReal* intFrac = projection->createIntegral(*plotVar,*plotVar,o.normRangeName) ;
2299 _globalSelectComp =
true;
2300 if(o.stype != RooAbsReal::Raw || this->InheritsFrom(RooAbsPdf::Class())){
2303 o.scaleFactor /= intFrac->getVal() ;
2313 TString curveName(projection->GetName()) ;
2314 if (sliceSet.getSize()>0) {
2315 curveName.Append(Form(
"_Slice[%s]",sliceSet.contentsString().c_str())) ;
2317 if (o.curveNameSuffix) {
2319 curveName.Append(o.curveNameSuffix) ;
2322 TString opt(o.drawOptions);
2323 if(opt.Contains(
"P")){
2324 RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;
2325 RooHist *graph=
new RooHist(*projection,*plotVar,1.,o.scaleFactor,frame->getNormVars(),o.errorFR);
2326 RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;
2330 graph->SetName(o.curveName) ;
2334 frame->addPlotable(graph, o.drawOptions, o.curveInvisible);
2336 RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;
2337 RooCurve *curve =
new RooCurve(*projection,*plotVar,o.rangeLo,o.rangeHi,frame->GetNbinsX(),
2338 o.scaleFactor,0,o.precision,o.precision,o.shiftToZero,o.wmode,o.numee,o.doeeval,o.eeval,o.progress);
2339 RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;
2340 curve->SetName(curveName.Data()) ;
2343 if (o.addToCurveName) {
2344 RooCurve* otherCurve =
static_cast<RooCurve*
>(frame->findObject(o.addToCurveName,RooCurve::Class())) ;
2345 RooCurve* sumCurve =
new RooCurve(projection->GetName(),projection->GetTitle(),*curve,*otherCurve,o.addToWgtSelf,o.addToWgtOther) ;
2346 sumCurve->SetName(Form(
"%s_PLUS_%s",curve->GetName(),otherCurve->GetName())) ;
2353 curve->SetName(o.curveName) ;
2357 frame->addPlotable(curve, o.drawOptions, o.curveInvisible);
2361 if (projDataNeededVars)
delete projDataNeededVars ;
2363 delete projectionCompList ;
2364 delete plotCloneSet ;
2374 RooPlot* RooAbsReal::plotSliceOn(RooPlot *frame,
const RooArgSet& sliceSet, Option_t* drawOptions,
2375 Double_t scaleFactor, ScaleType stype,
const RooAbsData* projData)
const
2377 RooArgSet projectedVars ;
2378 makeProjectionSet(frame->getPlotVar(),frame->getNormVars(),projectedVars,kTRUE) ;
2381 TIterator* iter = sliceSet.createIterator() ;
2382 RooAbsArg* sliceArg ;
2383 while((sliceArg=(RooAbsArg*)iter->Next())) {
2384 RooAbsArg* arg = projectedVars.find(sliceArg->GetName()) ;
2386 projectedVars.remove(*arg) ;
2388 coutI(Plotting) <<
"RooAbsReal::plotSliceOn(" << GetName() <<
") slice variable "
2389 << sliceArg->GetName() <<
" was not projected anyway" << endl ;
2395 o.drawOptions = drawOptions ;
2396 o.scaleFactor = scaleFactor ;
2398 o.projData = projData ;
2399 o.projSet = &projectedVars ;
2400 return plotOn(frame,o) ;
2408 RooPlot* RooAbsReal::plotAsymOn(RooPlot *frame,
const RooAbsCategoryLValue& asymCat, PlotOpt o)
const
2425 if (plotSanityChecks(frame))
return frame ;
2428 RooArgSet projDataVars ;
2430 if (o.projDataSet) {
2431 RooArgSet* tmp = (RooArgSet*) o.projData->get()->selectCommon(*o.projDataSet) ;
2432 projDataVars.add(*tmp) ;
2435 projDataVars.add(*o.projData->get()) ;
2440 if (!dependsOn(asymCat)) {
2441 coutE(Plotting) <<
"RooAbsReal::plotAsymOn(" << GetName()
2442 <<
") function doesn't depend on asymmetry category " << asymCat.GetName() << endl ;
2447 if (!asymCat.isSignType()) {
2448 coutE(Plotting) <<
"RooAbsReal::plotAsymOn(" << GetName()
2449 <<
") asymmetry category must have 2 or 3 states with index values -1,0,1" << endl ;
2454 RooArgSet projectedVars ;
2455 RooArgSet sliceSet ;
2457 makeProjectionSet(frame->getPlotVar(),o.projSet,projectedVars,kFALSE) ;
2460 if (frame->getNormVars()) {
2461 RooArgSet *sliceSetTmp = getObservables(*frame->getNormVars()) ;
2462 sliceSetTmp->remove(projectedVars,kTRUE,kTRUE) ;
2463 sliceSetTmp->remove(*frame->getPlotVar(),kTRUE,kTRUE) ;
2466 RooArgSet* tmp = (RooArgSet*) projDataVars.selectCommon(*o.projSet) ;
2467 sliceSetTmp->remove(*tmp,kTRUE,kTRUE) ;
2471 if (sliceSetTmp->getSize()) {
2472 coutI(Plotting) <<
"RooAbsReal::plotAsymOn(" << GetName() <<
") plot on "
2473 << frame->getPlotVar()->GetName() <<
" represents a slice in " << *sliceSetTmp << endl ;
2475 sliceSet.add(*sliceSetTmp) ;
2476 delete sliceSetTmp ;
2479 makeProjectionSet(frame->getPlotVar(),frame->getNormVars(),projectedVars,kTRUE) ;
2484 RooArgSet* projDataNeededVars = 0 ;
2486 projDataNeededVars = (RooArgSet*) projectedVars.selectCommon(projDataVars) ;
2487 projectedVars.remove(projDataVars,kTRUE,kTRUE) ;
2491 if (projectedVars.find(asymCat.GetName())) {
2492 projectedVars.remove(*projectedVars.find(asymCat.GetName())) ;
2496 RooAbsReal* realVar = (RooRealVar*) frame->getPlotVar() ;
2497 RooRealVar* plotVar = (RooRealVar*) realVar->Clone() ;
2500 if (projectedVars.getSize()) {
2501 coutI(Plotting) <<
"RooAbsReal::plotAsymOn(" << GetName() <<
") plot on " << plotVar->GetName()
2502 <<
" projects variables " << projectedVars << endl ;
2504 if (projDataNeededVars && projDataNeededVars->getSize()>0) {
2505 coutI(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") plot on " << plotVar->GetName()
2506 <<
" averages using data variables "<< *projDataNeededVars << endl ;
2511 RooAbsCategoryLValue* asymPos = (RooAbsCategoryLValue*) asymCat.Clone(
"asym_pos") ;
2512 RooAbsCategoryLValue* asymNeg = (RooAbsCategoryLValue*) asymCat.Clone(
"asym_neg") ;
2513 asymPos->setIndex(1) ;
2514 asymNeg->setIndex(-1) ;
2515 RooCustomizer* custPos =
new RooCustomizer(*
this,
"pos") ;
2516 RooCustomizer* custNeg =
new RooCustomizer(*
this,
"neg") ;
2519 custPos->replaceArg(asymCat,*asymPos) ;
2520 custNeg->replaceArg(asymCat,*asymNeg) ;
2521 RooAbsReal* funcPos = (RooAbsReal*) custPos->build() ;
2522 RooAbsReal* funcNeg = (RooAbsReal*) custNeg->build() ;
2525 RooArgSet *posProjCompList, *negProjCompList ;
2529 RooArgSet depPos(*plotVar,*asymPos) ;
2530 RooArgSet depNeg(*plotVar,*asymNeg) ;
2531 depPos.add(projDataVars) ;
2532 depNeg.add(projDataVars) ;
2534 const RooAbsReal *posProj = funcPos->createPlotProjection(depPos, &projectedVars, posProjCompList, o.projectionRangeName) ;
2535 const RooAbsReal *negProj = funcNeg->createPlotProjection(depNeg, &projectedVars, negProjCompList, o.projectionRangeName) ;
2536 if (!posProj || !negProj) {
2537 coutE(Plotting) <<
"RooAbsReal::plotAsymOn(" << GetName() <<
") Unable to create projections, abort" << endl ;
2542 TString asymName(GetName()) ;
2543 asymName.Append(
"_Asym[") ;
2544 asymName.Append(asymCat.GetName()) ;
2545 asymName.Append(
"]") ;
2546 TString asymTitle(asymCat.GetName()) ;
2547 asymTitle.Append(
" Asymmetry of ") ;
2548 asymTitle.Append(GetTitle()) ;
2549 RooFormulaVar* funcAsym =
new RooFormulaVar(asymName,asymTitle,
"(@0-@1)/(@0+@1)",RooArgSet(*posProj,*negProj)) ;
2554 RooAbsData* projDataSel = (RooAbsData*)o.projData;
2555 if (projDataNeededVars && projDataNeededVars->getSize()<o.projData->get()->getSize()) {
2558 RooArgSet* sliceDataSet = (RooArgSet*) sliceSet.selectCommon(*o.projData->get()) ;
2560 if (sliceDataSet->getSize()>0) {
2561 TIterator* iter = sliceDataSet->createIterator() ;
2562 RooAbsArg* sliceVar ;
2563 Bool_t first(kTRUE) ;
2564 while((sliceVar=(RooAbsArg*)iter->Next())) {
2566 cutString.Append(
"&&") ;
2571 RooAbsRealLValue* real ;
2572 RooAbsCategoryLValue* cat ;
2573 if ((real = dynamic_cast<RooAbsRealLValue*>(sliceVar))) {
2574 cutString.Append(Form(
"%s==%f",real->GetName(),real->getVal())) ;
2575 }
else if ((cat = dynamic_cast<RooAbsCategoryLValue*>(sliceVar))) {
2576 cutString.Append(Form(
"%s==%d",cat->GetName(),cat->getIndex())) ;
2581 delete sliceDataSet ;
2583 if (!cutString.IsNull()) {
2584 projDataSel = ((RooAbsData*)o.projData)->reduce(*projDataNeededVars,cutString) ;
2585 coutI(Plotting) <<
"RooAbsReal::plotAsymOn(" << GetName()
2586 <<
") reducing given projection dataset to entries with " << cutString << endl ;
2588 projDataSel = ((RooAbsData*)o.projData)->reduce(*projDataNeededVars) ;
2590 coutI(Plotting) <<
"RooAbsReal::plotAsymOn(" << GetName()
2591 <<
") only the following components of the projection data will be used: " << *projDataNeededVars << endl ;
2595 RooDataWeightedAverage dwa(Form(
"%sDataWgtAvg",GetName()),
"Data Weighted average",*funcAsym,*projDataSel,RooArgSet(),o.numCPU,o.interleave,kTRUE) ;
2597 dwa.constOptimizeTestStatistic(Activate) ;
2599 RooRealBinding projBind(dwa,*plotVar) ;
2601 ((RooAbsReal*)posProj)->attachDataSet(*projDataSel) ;
2602 ((RooAbsReal*)negProj)->attachDataSet(*projDataSel) ;
2604 RooScaledFunc scaleBind(projBind,o.scaleFactor);
2607 if (o.rangeLo==0 && o.rangeHi==0) {
2608 o.rangeLo = frame->GetXaxis()->GetXmin() ;
2609 o.rangeHi = frame->GetXaxis()->GetXmax() ;
2613 TString curveName(funcAsym->GetName()) ;
2614 curveName.Append(Form(
"_DataAvg[%s]",projDataSel->get()->contentsString().c_str())) ;
2616 if (sliceSet.getSize()>0) {
2617 curveName.Append(Form(
"_Slice[%s]",sliceSet.contentsString().c_str())) ;
2620 if (o.curveNameSuffix) {
2621 curveName.Append(o.curveNameSuffix) ;
2625 RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;
2626 RooCurve *curve =
new RooCurve(funcAsym->GetName(),funcAsym->GetTitle(),scaleBind,
2627 o.rangeLo,o.rangeHi,frame->GetNbinsX(),o.precision,o.precision,kFALSE,o.wmode,o.numee,o.doeeval,o.eeval) ;
2628 RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;
2630 dynamic_cast<TAttLine*
>(curve)->SetLineColor(2) ;
2632 frame->addPlotable(curve, o.drawOptions);
2634 ccoutW(Eval) << endl ;
2636 if (projDataSel!=o.projData)
delete projDataSel ;
2641 if (o.rangeLo==0 && o.rangeHi==0) {
2642 o.rangeLo = frame->GetXaxis()->GetXmin() ;
2643 o.rangeHi = frame->GetXaxis()->GetXmax() ;
2646 RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;
2647 RooCurve* curve=
new RooCurve(*funcAsym,*plotVar,o.rangeLo,o.rangeHi,frame->GetNbinsX(),
2648 o.scaleFactor,0,o.precision,o.precision,kFALSE,o.wmode,o.numee,o.doeeval,o.eeval);
2649 RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;
2651 dynamic_cast<TAttLine*
>(curve)->SetLineColor(2) ;
2655 TString curveName(funcAsym->GetName()) ;
2656 if (sliceSet.getSize()>0) {
2657 curveName.Append(Form(
"_Slice[%s]",sliceSet.contentsString().c_str())) ;
2659 if (o.curveNameSuffix) {
2661 curveName.Append(o.curveNameSuffix) ;
2663 curve->SetName(curveName.Data()) ;
2666 frame->addPlotable(curve, o.drawOptions);
2675 delete posProjCompList ;
2676 delete negProjCompList ;
2699 Double_t RooAbsReal::getPropagatedError(
const RooFitResult &fr,
const RooArgSet &nset_in)
const
2703 RooArgList fpf_stripped;
2704 RooFIter fi = fr.floatParsFinal().fwdIterator();
2706 while ((frv = (RooRealVar *)fi.next())) {
2707 if (frv->getError() > 1e-20) {
2708 fpf_stripped.add(*frv);
2713 RooAbsReal *cloneFunc = (RooAbsReal *)cloneTree();
2714 RooArgSet *errorParams = cloneFunc->getObservables(fpf_stripped);
2717 nset_in.getSize() == 0 ? cloneFunc->getParameters(*errorParams) : cloneFunc->getObservables(nset_in);
2720 RooArgList paramList;
2721 const RooArgList &fpf = fpf_stripped;
2722 vector<int> fpf_idx;
2723 for (Int_t i = 0; i < fpf.getSize(); i++) {
2724 RooAbsArg *par = errorParams->find(fpf[i].GetName());
2726 paramList.add(*par);
2727 fpf_idx.push_back(i);
2731 vector<Double_t> plusVar, minusVar ;
2734 TMatrixDSym V(paramList.getSize()==fr.floatParsFinal().getSize()?
2735 fr.covarianceMatrix():
2736 fr.reducedCovarianceMatrix(paramList)) ;
2738 for (Int_t ivar=0 ; ivar<paramList.getSize() ; ivar++) {
2740 RooRealVar& rrv = (RooRealVar&)fpf[fpf_idx[ivar]] ;
2742 Double_t cenVal = rrv.getVal() ;
2743 Double_t errVal = sqrt(V(ivar,ivar)) ;
2746 ((RooRealVar*)paramList.at(ivar))->setVal(cenVal+errVal) ;
2747 plusVar.push_back(cloneFunc->getVal(nset)) ;
2750 ((RooRealVar*)paramList.at(ivar))->setVal(cenVal-errVal) ;
2751 minusVar.push_back(cloneFunc->getVal(nset)) ;
2753 ((RooRealVar*)paramList.at(ivar))->setVal(cenVal) ;
2756 TMatrixDSym C(paramList.getSize()) ;
2757 vector<double> errVec(paramList.getSize()) ;
2758 for (
int i=0 ; i<paramList.getSize() ; i++) {
2759 errVec[i] = sqrt(V(i,i)) ;
2760 for (
int j=i ; j<paramList.getSize() ; j++) {
2761 C(i,j) = V(i,j)/sqrt(V(i,i)*V(j,j)) ;
2767 TVectorD F(plusVar.size()) ;
2768 for (
unsigned int j=0 ; j<plusVar.size() ; j++) {
2769 F[j] = (plusVar[j]-minusVar[j])/2 ;
2773 Double_t sum = F*(C*F) ;
2776 delete errorParams ;
2824 RooPlot* RooAbsReal::plotOnWithErrorBand(RooPlot* frame,
const RooFitResult& fr, Double_t Z,
const RooArgSet* params,
const RooLinkedList& argList, Bool_t linMethod)
const
2826 RooLinkedList plotArgListTmp(argList) ;
2827 RooCmdConfig pc(Form(
"RooAbsPdf::plotOn(%s)",GetName())) ;
2828 pc.stripCmdList(plotArgListTmp,
"VisualizeError,MoveToBack") ;
2831 RooLinkedList plotArgList ;
2832 RooFIter iter = plotArgListTmp.fwdIterator() ;
2834 while ((cmd=(RooCmdArg*)iter.next())) {
2835 if (std::string(
"Normalization")==cmd->GetName()) {
2836 if (((RooCmdArg*)cmd)->getInt(1)!=0) {
2838 plotArgList.Add(cmd) ;
2841 plotArgList.Add(cmd) ;
2846 RooLinkedList tmp(plotArgList) ;
2848 RooCurve* cenCurve = frame->getCurve() ;
2850 coutE(Plotting) << ClassName() <<
"::" << GetName() <<
":plotOnWithErrorBand: no curve for central value available" << endl;
2853 frame->remove(0,kFALSE) ;
2863 RooAbsReal* cloneFunc = (RooAbsReal*) cloneTree() ;
2864 RooArgSet* cloneParams = cloneFunc->getObservables(fr.floatParsFinal()) ;
2865 RooArgSet* errorParams = params?((RooArgSet*)cloneParams->selectCommon(*params)):cloneParams ;
2868 RooAbsPdf* paramPdf = fr.createHessePdf(*errorParams) ;
2869 Int_t n = Int_t(100./TMath::Erfc(Z/sqrt(2.))) ;
2872 coutI(Plotting) <<
"RooAbsReal::plotOn(" << GetName() <<
") INFO: visualizing " << Z <<
"-sigma uncertainties in parameters "
2873 << *errorParams <<
" from fit result " << fr.GetName() <<
" using " << n <<
" samplings." << endl ;
2876 Double_t ymin = frame->GetMinimum() ;
2877 Double_t ymax = frame->GetMaximum() ;
2878 RooDataSet* d = paramPdf->generate(*errorParams,n) ;
2879 vector<RooCurve*> cvec ;
2880 for (
int i=0 ; i<d->numEntries() ; i++) {
2881 *cloneParams = (*d->get(i)) ;
2882 RooLinkedList tmp2(plotArgList) ;
2883 cloneFunc->plotOn(frame,tmp2) ;
2884 cvec.push_back(frame->getCurve()) ;
2885 frame->remove(0,kFALSE) ;
2887 frame->SetMinimum(ymin) ;
2888 frame->SetMaximum(ymax) ;
2892 band = cenCurve->makeErrorBand(cvec,Z) ;
2897 for (vector<RooCurve*>::iterator i=cvec.begin() ; i!=cvec.end() ; ++i) {
2914 RooArgList fpf_stripped;
2915 RooFIter fi = fr.floatParsFinal().fwdIterator();
2917 while ((frv = (RooRealVar *)fi.next())) {
2918 if (frv->getError() > 1e-20) {
2919 fpf_stripped.add(*frv);
2924 RooAbsReal* cloneFunc = (RooAbsReal*) cloneTree() ;
2925 RooArgSet *cloneParams = cloneFunc->getObservables(fpf_stripped);
2926 RooArgSet* errorParams = params?((RooArgSet*)cloneParams->selectCommon(*params)):cloneParams ;
2930 RooArgList paramList ;
2931 const RooArgList& fpf = fr.floatParsFinal() ;
2932 vector<int> fpf_idx ;
2933 for (Int_t i=0 ; i<fpf.getSize() ; i++) {
2934 RooAbsArg* par = errorParams->find(fpf[i].GetName()) ;
2936 paramList.add(*par) ;
2937 fpf_idx.push_back(i) ;
2941 vector<RooCurve*> plusVar, minusVar ;
2945 TMatrixDSym V(paramList.getSize()==fr.floatParsFinal().getSize()?
2946 fr.covarianceMatrix():
2947 fr.reducedCovarianceMatrix(paramList)) ;
2950 for (Int_t ivar=0 ; ivar<paramList.getSize() ; ivar++) {
2952 RooRealVar& rrv = (RooRealVar&)fpf[fpf_idx[ivar]] ;
2954 Double_t cenVal = rrv.getVal() ;
2955 Double_t errVal = sqrt(V(ivar,ivar)) ;
2958 ((RooRealVar*)paramList.at(ivar))->setVal(cenVal+Z*errVal) ;
2961 RooLinkedList tmp2(plotArgList) ;
2962 cloneFunc->plotOn(frame,tmp2) ;
2963 plusVar.push_back(frame->getCurve()) ;
2964 frame->remove(0,kFALSE) ;
2968 ((RooRealVar*)paramList.at(ivar))->setVal(cenVal-Z*errVal) ;
2969 RooLinkedList tmp3(plotArgList) ;
2970 cloneFunc->plotOn(frame,tmp3) ;
2971 minusVar.push_back(frame->getCurve()) ;
2972 frame->remove(0,kFALSE) ;
2974 ((RooRealVar*)paramList.at(ivar))->setVal(cenVal) ;
2977 TMatrixDSym C(paramList.getSize()) ;
2978 vector<double> errVec(paramList.getSize()) ;
2979 for (
int i=0 ; i<paramList.getSize() ; i++) {
2980 errVec[i] = sqrt(V(i,i)) ;
2981 for (
int j=i ; j<paramList.getSize() ; j++) {
2982 C(i,j) = V(i,j)/sqrt(V(i,i)*V(j,j)) ;
2987 band = cenCurve->makeErrorBand(plusVar,minusVar,C,Z) ;
2992 for (vector<RooCurve*>::iterator i=plusVar.begin() ; i!=plusVar.end() ; ++i) {
2995 for (vector<RooCurve*>::iterator i=minusVar.begin() ; i!=minusVar.end() ; ++i) {
3002 if (!band)
return frame ;
3005 pc.defineString(
"drawOption",
"DrawOption",0,
"F") ;
3006 pc.defineString(
"curveNameSuffix",
"CurveNameSuffix",0,
"") ;
3007 pc.defineInt(
"lineColor",
"LineColor",0,-999) ;
3008 pc.defineInt(
"lineStyle",
"LineStyle",0,-999) ;
3009 pc.defineInt(
"lineWidth",
"LineWidth",0,-999) ;
3010 pc.defineInt(
"markerColor",
"MarkerColor",0,-999) ;
3011 pc.defineInt(
"markerStyle",
"MarkerStyle",0,-999) ;
3012 pc.defineDouble(
"markerSize",
"MarkerSize",0,-999) ;
3013 pc.defineInt(
"fillColor",
"FillColor",0,-999) ;
3014 pc.defineInt(
"fillStyle",
"FillStyle",0,-999) ;
3015 pc.defineString(
"curveName",
"Name",0,
"") ;
3016 pc.defineInt(
"curveInvisible",
"Invisible",0,0) ;
3017 pc.defineInt(
"moveToBack",
"MoveToBack",0,0) ;
3018 pc.allowUndefined() ;
3021 pc.process(argList) ;
3022 if (!pc.ok(kTRUE)) {
3027 frame->addPlotable(band,pc.getString(
"drawOption"),pc.getInt(
"curveInvisible")) ;
3030 Int_t lineColor = pc.getInt(
"lineColor") ;
3031 Int_t lineStyle = pc.getInt(
"lineStyle") ;
3032 Int_t lineWidth = pc.getInt(
"lineWidth") ;
3033 Int_t markerColor = pc.getInt(
"markerColor") ;
3034 Int_t markerStyle = pc.getInt(
"markerStyle") ;
3035 Size_t markerSize = pc.getDouble(
"markerSize") ;
3036 Int_t fillColor = pc.getInt(
"fillColor") ;
3037 Int_t fillStyle = pc.getInt(
"fillStyle") ;
3038 if (lineColor!=-999) frame->getAttLine()->SetLineColor(lineColor) ;
3039 if (lineStyle!=-999) frame->getAttLine()->SetLineStyle(lineStyle) ;
3040 if (lineWidth!=-999) frame->getAttLine()->SetLineWidth(lineWidth) ;
3041 if (fillColor!=-999) frame->getAttFill()->SetFillColor(fillColor) ;
3042 if (fillStyle!=-999) frame->getAttFill()->SetFillStyle(fillStyle) ;
3043 if (markerColor!=-999) frame->getAttMarker()->SetMarkerColor(markerColor) ;
3044 if (markerStyle!=-999) frame->getAttMarker()->SetMarkerStyle(markerStyle) ;
3045 if (markerSize!=-999) frame->getAttMarker()->SetMarkerSize(markerSize) ;
3048 if (pc.getString(
"curveName",0,kTRUE)) {
3049 band->SetName(pc.getString(
"curveName",0,kTRUE)) ;
3050 }
else if (pc.getString(
"curveNameSuffix",0,kTRUE)) {
3051 TString name(band->GetName()) ;
3052 name.Append(pc.getString(
"curveNameSuffix",0,kTRUE)) ;
3053 band->SetName(name.Data()) ;
3057 if (pc.getInt(
"moveToBack") && frame->numItems()>1) {
3058 frame->drawBefore(frame->getObject(0)->GetName(), frame->getCurve()->GetName());
3071 Bool_t RooAbsReal::plotSanityChecks(RooPlot* frame)
const
3075 coutE(Plotting) << ClassName() <<
"::" << GetName() <<
":plotOn: frame is null" << endl;
3080 RooAbsReal* var = frame->getPlotVar() ;
3082 coutE(Plotting) << ClassName() <<
"::" << GetName()
3083 <<
":plotOn: frame does not specify a plot variable" << endl;
3088 if(!dynamic_cast<RooAbsRealLValue*>(var)) {
3089 coutE(Plotting) << ClassName() <<
"::" << GetName() <<
":plotOn: cannot plot variable \""
3090 << var->GetName() <<
"\" of type " << var->ClassName() << endl;
3095 if(!this->dependsOn(*var)) {
3096 coutE(Plotting) << ClassName() <<
"::" << GetName() <<
":plotOn: WARNING: variable is not an explicit dependent: "
3097 << var->GetName() << endl;
3114 void RooAbsReal::makeProjectionSet(
const RooAbsArg* plotVar,
const RooArgSet* allVars,
3115 RooArgSet& projectedVars, Bool_t silent)
const
3117 cxcoutD(Plotting) <<
"RooAbsReal::makeProjectionSet(" << GetName() <<
") plotVar = " << plotVar->GetName()
3118 <<
" allVars = " << (allVars?(*allVars):RooArgSet()) << endl ;
3120 projectedVars.removeAll() ;
3121 if (!allVars) return ;
3124 projectedVars.add(*allVars) ;
3127 RooAbsArg *found= projectedVars.find(plotVar->GetName());
3129 projectedVars.remove(*found);
3132 RooArgSet* plotServers = plotVar->getObservables(&projectedVars) ;
3133 TIterator* psIter = plotServers->createIterator() ;
3135 while((ps=(RooAbsArg*)psIter->Next())) {
3136 RooAbsArg* tmp = projectedVars.find(ps->GetName()) ;
3138 cxcoutD(Plotting) <<
"RooAbsReal::makeProjectionSet(" << GetName() <<
") removing " << tmp->GetName()
3139 <<
" from projection set because it a server of " << plotVar->GetName() << endl ;
3140 projectedVars.remove(*tmp) ;
3144 delete plotServers ;
3147 coutW(Plotting) <<
"RooAbsReal::plotOn(" << GetName()
3148 <<
") WARNING: cannot project out frame variable ("
3149 << found->GetName() <<
"), ignoring" << endl ;
3154 TIterator* iter = allVars->createIterator() ;
3156 while((arg=(RooAbsArg*)iter->Next())) {
3157 if (!dependsOnValue(*arg)) {
3158 projectedVars.remove(*arg,kTRUE) ;
3160 cxcoutD(Plotting) <<
"RooAbsReal::plotOn(" << GetName()
3161 <<
") function doesn't depend on projection variable "
3162 << arg->GetName() <<
", ignoring" << endl ;
3174 Bool_t RooAbsReal::isSelectedComp()
const
3176 return _selectComp || _globalSelectComp ;
3184 void RooAbsReal::globalSelectComp(Bool_t flag)
3186 _globalSelectComp = flag ;
3198 RooAbsFunc *RooAbsReal::bindVars(
const RooArgSet &vars,
const RooArgSet* nset, Bool_t clipInvalid)
const
3200 RooAbsFunc *binding=
new RooRealBinding(*
this,vars,nset,clipInvalid);
3201 if(binding && !binding->isValid()) {
3202 coutE(InputArguments) << ClassName() <<
"::" << GetName() <<
":bindVars: cannot bind to " << vars << endl ;
3216 void RooAbsReal::copyCache(
const RooAbsArg* source, Bool_t , Bool_t setValDirty)
3218 auto other =
static_cast<const RooAbsReal*
>(source);
3219 assert(dynamic_cast<const RooAbsReal*>(source));
3221 if (!other->_treeVar) {
3222 _value = other->_value ;
3224 if (source->getAttribute(
"FLOAT_TREE_BRANCH")) {
3225 _value = other->_floatValue ;
3226 }
else if (source->getAttribute(
"INTEGER_TREE_BRANCH")) {
3227 _value = other->_intValue ;
3228 }
else if (source->getAttribute(
"BYTE_TREE_BRANCH")) {
3229 _value = other->_byteValue ;
3230 }
else if (source->getAttribute(
"BOOL_TREE_BRANCH")) {
3231 _value = other->_boolValue ;
3232 }
else if (source->getAttribute(
"SIGNEDBYTE_TREE_BRANCH")) {
3233 _value = other->_sbyteValue ;
3234 }
else if (source->getAttribute(
"UNSIGNED_INTEGER_TREE_BRANCH")) {
3235 _value = other->_uintValue ;
3247 void RooAbsReal::attachToVStore(RooVectorDataStore& vstore)
3249 RooVectorDataStore::RealVector* rv = vstore.addReal(
this) ;
3250 rv->setBuffer(
this,&_value) ;
3252 _batchData.attachForeignStorage(rv->data());
3270 void RooAbsReal::attachToTree(TTree& t, Int_t bufSize)
3273 TString cleanName(cleanBranchName()) ;
3274 TBranch* branch = t.GetBranch(cleanName) ;
3278 TLeaf* leaf = (TLeaf*)branch->GetListOfLeaves()->At(0) ;
3282 TLeaf* counterLeaf = leaf->GetLeafCounter(dummy) ;
3284 coutE(Eval) <<
"RooAbsReal::attachToTree(" << GetName() <<
") ERROR: TTree branch " << GetName()
3285 <<
" is an array and cannot be attached to a RooAbsReal" << endl ;
3289 TString typeName(leaf->GetTypeName()) ;
3291 if (!typeName.CompareTo(
"Float_t")) {
3292 coutI(Eval) <<
"RooAbsReal::attachToTree(" << GetName() <<
") TTree Float_t branch " << GetName()
3293 <<
" will be converted to double precision" << endl ;
3294 setAttribute(
"FLOAT_TREE_BRANCH",kTRUE) ;
3296 t.SetBranchAddress(cleanName,&_floatValue) ;
3297 }
else if (!typeName.CompareTo(
"Int_t")) {
3298 coutI(Eval) <<
"RooAbsReal::attachToTree(" << GetName() <<
") TTree Int_t branch " << GetName()
3299 <<
" will be converted to double precision" << endl ;
3300 setAttribute(
"INTEGER_TREE_BRANCH",kTRUE) ;
3302 t.SetBranchAddress(cleanName,&_intValue) ;
3303 }
else if (!typeName.CompareTo(
"UChar_t")) {
3304 coutI(Eval) <<
"RooAbsReal::attachToTree(" << GetName() <<
") TTree UChar_t branch " << GetName()
3305 <<
" will be converted to double precision" << endl ;
3306 setAttribute(
"BYTE_TREE_BRANCH",kTRUE) ;
3308 t.SetBranchAddress(cleanName,&_byteValue) ;
3309 }
else if (!typeName.CompareTo(
"Bool_t")) {
3310 coutI(Eval) <<
"RooAbsReal::attachToTree(" << GetName() <<
") TTree Bool_t branch " << GetName()
3311 <<
" will be converted to double precision" << endl ;
3312 setAttribute(
"BOOL_TREE_BRANCH",kTRUE) ;
3314 t.SetBranchAddress(cleanName,&_boolValue) ;
3315 }
else if (!typeName.CompareTo(
"Char_t")) {
3316 coutI(Eval) <<
"RooAbsReal::attachToTree(" << GetName() <<
") TTree Char_t branch " << GetName()
3317 <<
" will be converted to double precision" << endl ;
3318 setAttribute(
"SIGNEDBYTE_TREE_BRANCH",kTRUE) ;
3320 t.SetBranchAddress(cleanName,&_sbyteValue) ;
3321 }
else if (!typeName.CompareTo(
"UInt_t")) {
3322 coutI(Eval) <<
"RooAbsReal::attachToTree(" << GetName() <<
") TTree UInt_t branch " << GetName()
3323 <<
" will be converted to double precision" << endl ;
3324 setAttribute(
"UNSIGNED_INTEGER_TREE_BRANCH",kTRUE) ;
3326 t.SetBranchAddress(cleanName,&_uintValue) ;
3327 }
else if (!typeName.CompareTo(
"Double_t")) {
3328 t.SetBranchAddress(cleanName,&_value) ;
3330 coutE(InputArguments) <<
"RooAbsReal::attachToTree(" << GetName() <<
") data type " << typeName <<
" is not supported" << endl ;
3337 TString format(cleanName);
3338 format.Append(
"/D");
3339 branch = t.Branch(cleanName, &_value, (
const Text_t*)format, bufSize);
3350 void RooAbsReal::fillTreeBranch(TTree& t)
3353 TBranch* branch = t.GetBranch(cleanBranchName()) ;
3355 coutE(Eval) <<
"RooAbsReal::fillTreeBranch(" << GetName() <<
") ERROR: not attached to tree: " << cleanBranchName() << endl ;
3367 void RooAbsReal::setTreeBranchStatus(TTree& t, Bool_t active)
3369 TBranch* branch = t.GetBranch(cleanBranchName()) ;
3371 t.SetBranchStatus(cleanBranchName(),active?1:0) ;
3381 RooAbsArg *RooAbsReal::createFundamental(
const char* newname)
const
3383 RooRealVar *fund=
new RooRealVar(newname?newname:GetName(),GetTitle(),_value,getUnit());
3384 fund->removeRange();
3385 fund->setPlotLabel(getPlotLabel());
3386 fund->setAttribute(
"fundamentalCopy");
3397 Bool_t RooAbsReal::matchArgs(
const RooArgSet& allDeps, RooArgSet& analDeps,
3398 const RooArgProxy& a)
const
3401 nameList.Add(
new TObjString(a.absArg()->GetName())) ;
3402 Bool_t result = matchArgsByName(allDeps,analDeps,nameList) ;
3414 Bool_t RooAbsReal::matchArgs(
const RooArgSet& allDeps, RooArgSet& analDeps,
3415 const RooArgProxy& a,
const RooArgProxy& b)
const
3418 nameList.Add(
new TObjString(a.absArg()->GetName())) ;
3419 nameList.Add(
new TObjString(b.absArg()->GetName())) ;
3420 Bool_t result = matchArgsByName(allDeps,analDeps,nameList) ;
3432 Bool_t RooAbsReal::matchArgs(
const RooArgSet& allDeps, RooArgSet& analDeps,
3433 const RooArgProxy& a,
const RooArgProxy& b,
3434 const RooArgProxy& c)
const
3437 nameList.Add(
new TObjString(a.absArg()->GetName())) ;
3438 nameList.Add(
new TObjString(b.absArg()->GetName())) ;
3439 nameList.Add(
new TObjString(c.absArg()->GetName())) ;
3440 Bool_t result = matchArgsByName(allDeps,analDeps,nameList) ;
3452 Bool_t RooAbsReal::matchArgs(
const RooArgSet& allDeps, RooArgSet& analDeps,
3453 const RooArgProxy& a,
const RooArgProxy& b,
3454 const RooArgProxy& c,
const RooArgProxy& d)
const
3457 nameList.Add(
new TObjString(a.absArg()->GetName())) ;
3458 nameList.Add(
new TObjString(b.absArg()->GetName())) ;
3459 nameList.Add(
new TObjString(c.absArg()->GetName())) ;
3460 nameList.Add(
new TObjString(d.absArg()->GetName())) ;
3461 Bool_t result = matchArgsByName(allDeps,analDeps,nameList) ;
3472 Bool_t RooAbsReal::matchArgs(
const RooArgSet& allDeps, RooArgSet& analDeps,
3473 const RooArgSet& refset)
const
3476 TIterator* iter = refset.createIterator() ;
3478 while ((arg=(RooAbsArg*)iter->Next())) {
3479 nameList.Add(
new TObjString(arg->GetName())) ;
3483 Bool_t result = matchArgsByName(allDeps,analDeps,nameList) ;
3495 Bool_t RooAbsReal::matchArgsByName(
const RooArgSet &allArgs, RooArgSet &matchedArgs,
3496 const TList &nameList)
const
3498 RooArgSet matched(
"matched");
3499 TIterator *iterator= nameList.MakeIterator();
3500 TObjString *name = 0;
3501 Bool_t isMatched(kTRUE);
3502 while((isMatched && (name= (TObjString*)iterator->Next()))) {
3503 RooAbsArg *found= allArgs.find(name->String().Data());
3505 matched.add(*found);
3514 if (isMatched && (matched.getSize()!=nameList.GetSize())) {
3515 isMatched = kFALSE ;
3519 if(isMatched) matchedArgs.add(matched);
3528 RooNumIntConfig* RooAbsReal::defaultIntegratorConfig()
3530 return &RooNumIntConfig::defaultConfig() ;
3538 RooNumIntConfig* RooAbsReal::specialIntegratorConfig()
const
3540 return _specIntegratorConfig ;
3550 RooNumIntConfig* RooAbsReal::specialIntegratorConfig(Bool_t createOnTheFly)
3552 if (!_specIntegratorConfig && createOnTheFly) {
3553 _specIntegratorConfig =
new RooNumIntConfig(*defaultIntegratorConfig()) ;
3555 return _specIntegratorConfig ;
3565 const RooNumIntConfig* RooAbsReal::getIntegratorConfig()
const
3567 const RooNumIntConfig* config = specialIntegratorConfig() ;
3568 if (config)
return config ;
3569 return defaultIntegratorConfig() ;
3578 RooNumIntConfig* RooAbsReal::getIntegratorConfig()
3580 RooNumIntConfig* config = specialIntegratorConfig() ;
3581 if (config)
return config ;
3582 return defaultIntegratorConfig() ;
3591 void RooAbsReal::setIntegratorConfig(
const RooNumIntConfig& config)
3593 if (_specIntegratorConfig) {
3594 delete _specIntegratorConfig ;
3596 _specIntegratorConfig =
new RooNumIntConfig(config) ;
3605 void RooAbsReal::setIntegratorConfig()
3607 if (_specIntegratorConfig) {
3608 delete _specIntegratorConfig ;
3610 _specIntegratorConfig = 0 ;
3622 void RooAbsReal::selectNormalization(
const RooArgSet*, Bool_t)
3635 void RooAbsReal::selectNormalizationRange(
const char*, Bool_t)
3648 Int_t RooAbsReal::getMaxVal(
const RooArgSet& )
const
3659 Double_t RooAbsReal::maxVal(Int_t )
const
3670 void RooAbsReal::logEvalError(
const RooAbsReal* originator,
const char* origName,
const char* message,
const char* serverValueString)
3672 if (_evalErrorMode==Ignore) {
3676 if (_evalErrorMode==CountErrors) {
3681 static Bool_t inLogEvalError = kFALSE ;
3683 if (inLogEvalError) {
3686 inLogEvalError = kTRUE ;
3689 ee.setMessage(message) ;
3691 if (serverValueString) {
3692 ee.setServerValues(serverValueString) ;
3695 if (_evalErrorMode==PrintErrors) {
3696 oocoutE((TObject*)0,Eval) <<
"RooAbsReal::logEvalError(" <<
"<STATIC>" <<
") evaluation error, " << endl
3697 <<
" origin : " << origName << endl
3698 <<
" message : " << ee._msg << endl
3699 <<
" server values: " << ee._srvval << endl ;
3700 }
else if (_evalErrorMode==CollectErrors) {
3701 _evalErrorList[originator].first = origName ;
3702 _evalErrorList[originator].second.push_back(ee) ;
3706 inLogEvalError = kFALSE ;
3725 void RooAbsReal::logEvalError(
const char* message,
const char* serverValueString)
const
3727 if (_evalErrorMode==Ignore) {
3731 if (_evalErrorMode==CountErrors) {
3736 static Bool_t inLogEvalError = kFALSE ;
3738 if (inLogEvalError) {
3741 inLogEvalError = kTRUE ;
3744 ee.setMessage(message) ;
3746 if (serverValueString) {
3747 ee.setServerValues(serverValueString) ;
3751 Bool_t first(kTRUE) ;
3752 for (Int_t i=0 ; i<numProxies() ; i++) {
3753 RooAbsProxy* p = getProxy(i) ;
3761 p->print(oss,kTRUE) ;
3763 ee.setServerValues(oss.str().c_str()) ;
3766 ostringstream oss2 ;
3767 printStream(oss2,kName|kClassName|kArgs,kInline) ;
3769 if (_evalErrorMode==PrintErrors) {
3770 coutE(Eval) <<
"RooAbsReal::logEvalError(" << GetName() <<
") evaluation error, " << endl
3771 <<
" origin : " << oss2.str() << endl
3772 <<
" message : " << ee._msg << endl
3773 <<
" server values: " << ee._srvval << endl ;
3774 }
else if (_evalErrorMode==CollectErrors) {
3775 if (_evalErrorList[
this].second.size() >= 2048) {
3778 const EvalError& oee = _evalErrorList[
this].second.front();
3781 ccoutD(Eval) <<
"RooAbsReal::logEvalError(" << GetName()
3782 <<
") delayed evaluation error, " << endl
3783 <<
" origin : " << oss2.str() << endl
3784 <<
" message : " << oee._msg << endl
3785 <<
" server values: " << oee._srvval << endl ;
3786 _evalErrorList[
this].second.pop_front();
3788 _evalErrorList[
this].first = oss2.str().c_str() ;
3789 _evalErrorList[
this].second.push_back(ee) ;
3792 inLogEvalError = kFALSE ;
3802 void RooAbsReal::clearEvalErrorLog()
3804 if (_evalErrorMode==PrintErrors) {
3806 }
else if (_evalErrorMode==CollectErrors) {
3807 _evalErrorList.clear() ;
3809 _evalErrorCount = 0 ;
3822 void RooAbsReal::printEvalErrors(ostream& os, Int_t maxPerNode)
3824 if (_evalErrorMode == CountErrors) {
3825 os << _evalErrorCount <<
" errors counted" << endl ;
3828 if (maxPerNode<0) return ;
3830 map<const RooAbsArg*,pair<string,list<EvalError> > >::iterator iter = _evalErrorList.begin() ;
3832 for(;iter!=_evalErrorList.end() ; ++iter) {
3833 if (maxPerNode==0) {
3836 os << iter->second.first ;
3838 os <<
" has " << iter->second.second.size() <<
" errors" << endl ;
3843 os << iter->second.first << endl ;
3847 std::list<EvalError>::iterator iter2 = iter->second.second.begin() ;
3848 for(;iter2!=iter->second.second.end() ; ++iter2, i++) {
3849 os <<
" " << iter2->_msg <<
" @ " << iter2->_srvval << endl ;
3851 os <<
" ... (remaining " << iter->second.second.size() - maxPerNode <<
" messages suppressed)" << endl ;
3864 Int_t RooAbsReal::numEvalErrors()
3866 if (_evalErrorMode==CountErrors) {
3867 return _evalErrorCount ;
3871 map<const RooAbsArg*,pair<string,list<EvalError> > >::iterator iter = _evalErrorList.begin() ;
3872 for(;iter!=_evalErrorList.end() ; ++iter) {
3873 ntot += iter->second.second.size() ;
3890 void RooAbsReal::fixAddCoefNormalization(
const RooArgSet& addNormSet, Bool_t force)
3892 RooArgSet* compSet = getComponents() ;
3893 TIterator* iter = compSet->createIterator() ;
3895 while((arg=(RooAbsArg*)iter->Next())) {
3896 RooAbsPdf* pdf =
dynamic_cast<RooAbsPdf*
>(arg) ;
3898 if (addNormSet.getSize()>0) {
3899 pdf->selectNormalization(&addNormSet,force) ;
3901 pdf->selectNormalization(0,force) ;
3920 void RooAbsReal::fixAddCoefRange(
const char* rangeName, Bool_t force)
3922 RooArgSet* compSet = getComponents() ;
3923 TIterator* iter = compSet->createIterator() ;
3925 while((arg=(RooAbsArg*)iter->Next())) {
3926 RooAbsPdf* pdf =
dynamic_cast<RooAbsPdf*
>(arg) ;
3928 pdf->selectNormalizationRange(rangeName,force) ;
3944 void RooAbsReal::preferredObservableScanOrder(
const RooArgSet& obs, RooArgSet& orderedObs)
const
3947 orderedObs.removeAll() ;
3948 orderedObs.add(obs) ;
3956 RooAbsReal* RooAbsReal::createRunningIntegral(
const RooArgSet& iset,
const RooArgSet& nset)
3958 return createRunningIntegral(iset,RooFit::SupNormSet(nset)) ;
4000 RooAbsReal* RooAbsReal::createRunningIntegral(
const RooArgSet& iset,
const RooCmdArg& arg1,
const RooCmdArg& arg2,
4001 const RooCmdArg& arg3,
const RooCmdArg& arg4,
const RooCmdArg& arg5,
4002 const RooCmdArg& arg6,
const RooCmdArg& arg7,
const RooCmdArg& arg8)
4005 RooCmdConfig pc(Form(
"RooAbsReal::createRunningIntegral(%s)",GetName())) ;
4006 pc.defineObject(
"supNormSet",
"SupNormSet",0,0) ;
4007 pc.defineInt(
"numScanBins",
"ScanParameters",0,1000) ;
4008 pc.defineInt(
"intOrder",
"ScanParameters",1,2) ;
4009 pc.defineInt(
"doScanNum",
"ScanNum",0,1) ;
4010 pc.defineInt(
"doScanAll",
"ScanAll",0,0) ;
4011 pc.defineInt(
"doScanNon",
"ScanNone",0,0) ;
4012 pc.defineMutex(
"ScanNum",
"ScanAll",
"ScanNone") ;
4015 pc.process(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) ;
4016 if (!pc.ok(kTRUE)) {
4021 const RooArgSet* snset =
static_cast<const RooArgSet*
>(pc.getObject(
"supNormSet",0)) ;
4026 Int_t numScanBins = pc.getInt(
"numScanBins") ;
4027 Int_t intOrder = pc.getInt(
"intOrder") ;
4028 Int_t doScanNum = pc.getInt(
"doScanNum") ;
4029 Int_t doScanAll = pc.getInt(
"doScanAll") ;
4030 Int_t doScanNon = pc.getInt(
"doScanNon") ;
4034 return createIntRI(iset,nset) ;
4037 return createScanRI(iset,nset,numScanBins,intOrder) ;
4040 RooRealIntegral* tmp = (RooRealIntegral*) createIntegral(iset) ;
4041 Int_t isNum= (tmp->numIntRealVars().getSize()==1) ;
4045 coutI(NumIntegration) <<
"RooAbsPdf::createRunningIntegral(" << GetName() <<
") integration over observable(s) " << iset <<
" involves numeric integration," << endl
4046 <<
" constructing cdf though numeric integration of sampled pdf in " << numScanBins <<
" bins and applying order "
4047 << intOrder <<
" interpolation on integrated histogram." << endl
4048 <<
" To override this choice of technique use argument ScanNone(), to change scan parameters use ScanParameters(nbins,order) argument" << endl ;
4051 return isNum ? createScanRI(iset,nset,numScanBins,intOrder) : createIntRI(iset,nset) ;
4062 RooAbsReal* RooAbsReal::createScanRI(
const RooArgSet& iset,
const RooArgSet& nset, Int_t numScanBins, Int_t intOrder)
4064 string name = string(GetName()) +
"_NUMRUNINT_" + integralNameSuffix(iset,&nset).Data() ;
4065 RooRealVar* ivar = (RooRealVar*) iset.first() ;
4066 ivar->setBins(numScanBins,
"numcdf") ;
4067 RooNumRunningInt* ret =
new RooNumRunningInt(name.c_str(),name.c_str(),*
this,*ivar,
"numrunint") ;
4068 ret->setInterpolationOrder(intOrder) ;
4079 RooAbsReal* RooAbsReal::createIntRI(
const RooArgSet& iset,
const RooArgSet& nset)
4083 TIterator* iter2 = iset.createIterator() ;
4085 while((arg=(RooAbsArg*)iter2->Next())) {
4086 if (dynamic_cast<RooRealVar*>(arg)) {
4089 coutW(InputArguments) <<
"RooAbsPdf::createRunningIntegral(" << GetName() <<
") WARNING ignoring non-RooRealVar input argument " << arg->GetName() << endl ;
4094 RooArgList cloneList ;
4096 RooArgSet clonedBranchNodes ;
4099 RooCustomizer cust(*
this,
"cdf") ;
4100 cust.setCloneBranchSet(clonedBranchNodes) ;
4101 cust.setOwning(kFALSE) ;
4104 TIterator* iter = ilist.createIterator() ;
4106 while((rrv=(RooRealVar*)iter->Next())) {
4109 RooRealVar* cloneArg = (RooRealVar*) rrv->clone(Form(
"%s_prime",rrv->GetName())) ;
4110 cloneList.add(*cloneArg) ;
4111 cust.replaceArg(*rrv,*cloneArg) ;
4114 RooRealVar* cloneLo = (RooRealVar*) rrv->clone(Form(
"%s_lowbound",rrv->GetName())) ;
4115 cloneLo->setVal(rrv->getMin()) ;
4116 loList.add(*cloneLo) ;
4119 RooParamBinning pb(*cloneLo,*rrv,100) ;
4120 cloneArg->setBinning(pb,
"CDF") ;
4125 RooAbsReal* tmp = (RooAbsReal*) cust.build() ;
4128 RooArgSet finalNset(nset) ;
4129 finalNset.add(cloneList,kTRUE) ;
4130 RooAbsReal* cdf = tmp->createIntegral(cloneList,finalNset,
"CDF") ;
4133 cdf->addOwnedComponents(*tmp) ;
4134 cdf->addOwnedComponents(cloneList) ;
4135 cdf->addOwnedComponents(loList) ;
4145 RooFunctor* RooAbsReal::functor(
const RooArgList& obs,
const RooArgList& pars,
const RooArgSet& nset)
const
4147 RooArgSet* realObs = getObservables(obs) ;
4148 if (realObs->getSize() != obs.getSize()) {
4149 coutE(InputArguments) <<
"RooAbsReal::functor(" << GetName() <<
") ERROR: one or more specified observables are not variables of this p.d.f" << endl ;
4153 RooArgSet* realPars = getObservables(pars) ;
4154 if (realPars->getSize() != pars.getSize()) {
4155 coutE(InputArguments) <<
"RooAbsReal::functor(" << GetName() <<
") ERROR: one or more specified parameters are not variables of this p.d.f" << endl ;
4162 return new RooFunctor(*
this,obs,pars,nset) ;
4171 TF1* RooAbsReal::asTF(
const RooArgList& obs,
const RooArgList& pars,
const RooArgSet& nset)
const
4174 RooArgSet* realObs = getObservables(obs) ;
4175 if (realObs->getSize() != obs.getSize()) {
4176 coutE(InputArguments) <<
"RooAbsReal::functor(" << GetName() <<
") ERROR: one or more specified observables are not variables of this p.d.f" << endl ;
4180 RooArgSet* realPars = getObservables(pars) ;
4181 if (realPars->getSize() != pars.getSize()) {
4182 coutE(InputArguments) <<
"RooAbsReal::functor(" << GetName() <<
") ERROR: one or more specified parameters are not variables of this p.d.f" << endl ;
4190 for (
int i=0 ; i<obs.getSize() ; i++) {
4191 if (dynamic_cast<RooRealVar*>(obs.at(i))==0) {
4192 coutE(ObjectHandling) <<
"RooAbsReal::asTF(" << GetName() <<
") ERROR: proposed observable " << obs.at(0)->GetName() <<
" is not of type RooRealVar" << endl ;
4196 for (
int i=0 ; i<pars.getSize() ; i++) {
4197 if (dynamic_cast<RooRealVar*>(pars.at(i))==0) {
4198 coutE(ObjectHandling) <<
"RooAbsReal::asTF(" << GetName() <<
") ERROR: proposed parameter " << pars.at(0)->GetName() <<
" is not of type RooRealVar" << endl ;
4206 switch(obs.getSize()) {
4208 RooRealVar* x = (RooRealVar*)obs.at(0) ;
4209 f = functor(obs,pars,nset) ;
4210 tf =
new TF1(GetName(),f,x->getMin(),x->getMax(),pars.getSize()) ;
4214 RooRealVar* x = (RooRealVar*)obs.at(0) ;
4215 RooRealVar* y = (RooRealVar*)obs.at(1) ;
4216 f = functor(obs,pars,nset) ;
4217 tf =
new TF2(GetName(),f,x->getMin(),x->getMax(),y->getMin(),y->getMax(),pars.getSize()) ;
4221 RooRealVar* x = (RooRealVar*)obs.at(0) ;
4222 RooRealVar* y = (RooRealVar*)obs.at(1) ;
4223 RooRealVar* z = (RooRealVar*)obs.at(2) ;
4224 f = functor(obs,pars,nset) ;
4225 tf =
new TF3(GetName(),f,x->getMin(),x->getMax(),y->getMin(),y->getMax(),z->getMin(),z->getMax(),pars.getSize()) ;
4229 coutE(InputArguments) <<
"RooAbsReal::asTF(" << GetName() <<
") ERROR: " << obs.getSize()
4230 <<
" observables specified, but a ROOT TFx can only have 1,2 or 3 observables" << endl ;
4235 for (
int i=0 ; i<pars.getSize() ; i++) {
4236 RooRealVar* p = (RooRealVar*) pars.at(i) ;
4237 tf->SetParameter(i,p->getVal()) ;
4238 tf->SetParName(i,p->GetName()) ;
4249 RooDerivative* RooAbsReal::derivative(RooRealVar& obs, Int_t order, Double_t eps)
4251 string name=Form(
"%s_DERIV_%s",GetName(),obs.GetName()) ;
4252 string title=Form(
"Derivative of %s w.r.t %s ",GetName(),obs.GetName()) ;
4253 return new RooDerivative(name.c_str(),title.c_str(),*
this,obs,order,eps) ;
4261 RooDerivative* RooAbsReal::derivative(RooRealVar& obs,
const RooArgSet& normSet, Int_t order, Double_t eps)
4263 string name=Form(
"%s_DERIV_%s",GetName(),obs.GetName()) ;
4264 string title=Form(
"Derivative of %s w.r.t %s ",GetName(),obs.GetName()) ;
4265 return new RooDerivative(name.c_str(),title.c_str(),*
this,obs,normSet,order,eps) ;
4277 RooAbsMoment* RooAbsReal::moment(RooRealVar& obs, Int_t order, Bool_t central, Bool_t takeRoot)
4279 string name=Form(
"%s_MOMENT_%d%s_%s",GetName(),order,(central?
"C":
""),obs.GetName()) ;
4280 string title=Form(
"%sMoment of order %d of %s w.r.t %s ",(central?
"Central ":
""),order,GetName(),obs.GetName()) ;
4281 if (order==1)
return new RooFirstMoment(name.c_str(),title.c_str(),*
this,obs) ;
4282 if (order==2)
return new RooSecondMoment(name.c_str(),title.c_str(),*
this,obs,central,takeRoot) ;
4283 return new RooMoment(name.c_str(),title.c_str(),*
this,obs,order,central,takeRoot) ;
4296 RooAbsMoment* RooAbsReal::moment(RooRealVar& obs,
const RooArgSet& normObs, Int_t order, Bool_t central, Bool_t takeRoot, Bool_t intNormObs)
4298 string name=Form(
"%s_MOMENT_%d%s_%s",GetName(),order,(central?
"C":
""),obs.GetName()) ;
4299 string title=Form(
"%sMoment of order %d of %s w.r.t %s ",(central?
"Central ":
""),order,GetName(),obs.GetName()) ;
4301 if (order==1)
return new RooFirstMoment(name.c_str(),title.c_str(),*
this,obs,normObs,intNormObs) ;
4302 if (order==2)
return new RooSecondMoment(name.c_str(),title.c_str(),*
this,obs,normObs,central,takeRoot,intNormObs) ;
4303 return new RooMoment(name.c_str(),title.c_str(),*
this,obs,normObs,order,central,takeRoot,intNormObs) ;
4313 Double_t RooAbsReal::findRoot(RooRealVar& x, Double_t xmin, Double_t xmax, Double_t yval)
4315 Double_t result(0) ;
4316 RooBrentRootFinder(RooRealBinding(*
this,x)).findRoot(result,xmin,xmax,yval) ;
4325 RooGenFunction* RooAbsReal::iGenFunction(RooRealVar& x,
const RooArgSet& nset)
4327 return new RooGenFunction(*
this,x,RooArgList(),nset.getSize()>0?nset:RooArgSet(x)) ;
4334 RooMultiGenFunction* RooAbsReal::iGenFunction(
const RooArgSet& observables,
const RooArgSet& nset)
4336 return new RooMultiGenFunction(*
this,observables,RooArgList(),nset.getSize()>0?nset:observables) ;
4378 RooFitResult* RooAbsReal::chi2FitTo(RooDataHist& data,
const RooCmdArg& arg1,
const RooCmdArg& arg2,
4379 const RooCmdArg& arg3,
const RooCmdArg& arg4,
const RooCmdArg& arg5,
4380 const RooCmdArg& arg6,
const RooCmdArg& arg7,
const RooCmdArg& arg8)
4383 l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
4384 l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
4385 l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
4386 l.Add((TObject*)&arg7) ; l.Add((TObject*)&arg8) ;
4387 return chi2FitTo(data,l) ;
4396 RooFitResult* RooAbsReal::chi2FitTo(RooDataHist& data,
const RooLinkedList& cmdList)
4399 RooCmdConfig pc(Form(
"RooAbsPdf::chi2FitTo(%s)",GetName())) ;
4402 RooLinkedList fitCmdList(cmdList) ;
4403 RooLinkedList chi2CmdList = pc.filterCmdList(fitCmdList,
"Range,RangeWithName,NumCPU,Optimize") ;
4405 RooAbsReal* chi2 = createChi2(data,chi2CmdList) ;
4406 RooFitResult* ret = chi2FitDriver(*chi2,fitCmdList) ;
4430 RooAbsReal* RooAbsReal::createChi2(RooDataHist& data,
const RooCmdArg& arg1,
const RooCmdArg& arg2,
4431 const RooCmdArg& arg3,
const RooCmdArg& arg4,
const RooCmdArg& arg5,
4432 const RooCmdArg& arg6,
const RooCmdArg& arg7,
const RooCmdArg& arg8)
4434 string name = Form(
"chi2_%s_%s",GetName(),data.GetName()) ;
4436 return new RooChi2Var(name.c_str(),name.c_str(),*
this,data,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) ;
4446 RooAbsReal* RooAbsReal::createChi2(RooDataHist& data,
const RooLinkedList& cmdList)
4449 const RooCmdArg* cmds[8] ;
4450 TIterator* iter = cmdList.MakeIterator() ;
4453 while((arg=(RooCmdArg*)iter->Next())) {
4457 cmds[i] = &RooCmdArg::none() ;
4461 return createChi2(data,*cmds[0],*cmds[1],*cmds[2],*cmds[3],*cmds[4],*cmds[5],*cmds[6],*cmds[7]) ;
4502 RooFitResult* RooAbsReal::chi2FitTo(RooDataSet& xydata,
const RooCmdArg& arg1,
const RooCmdArg& arg2,
4503 const RooCmdArg& arg3,
const RooCmdArg& arg4,
const RooCmdArg& arg5,
4504 const RooCmdArg& arg6,
const RooCmdArg& arg7,
const RooCmdArg& arg8)
4507 l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
4508 l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
4509 l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
4510 l.Add((TObject*)&arg7) ; l.Add((TObject*)&arg8) ;
4511 return chi2FitTo(xydata,l) ;
4520 RooFitResult* RooAbsReal::chi2FitTo(RooDataSet& xydata,
const RooLinkedList& cmdList)
4523 RooCmdConfig pc(Form(
"RooAbsPdf::chi2FitTo(%s)",GetName())) ;
4526 RooLinkedList fitCmdList(cmdList) ;
4527 RooLinkedList chi2CmdList = pc.filterCmdList(fitCmdList,
"YVar,Integrate") ;
4529 RooAbsReal* xychi2 = createChi2(xydata,chi2CmdList) ;
4530 RooFitResult* ret = chi2FitDriver(*xychi2,fitCmdList) ;
4554 RooAbsReal* RooAbsReal::createChi2(RooDataSet& data,
const RooCmdArg& arg1,
const RooCmdArg& arg2,
4555 const RooCmdArg& arg3,
const RooCmdArg& arg4,
const RooCmdArg& arg5,
4556 const RooCmdArg& arg6,
const RooCmdArg& arg7,
const RooCmdArg& arg8)
4559 l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
4560 l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
4561 l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
4562 l.Add((TObject*)&arg7) ; l.Add((TObject*)&arg8) ;
4563 return createChi2(data,l) ;
4571 RooAbsReal* RooAbsReal::createChi2(RooDataSet& data,
const RooLinkedList& cmdList)
4574 RooCmdConfig pc(Form(
"RooAbsPdf::fitTo(%s)",GetName())) ;
4576 pc.defineInt(
"integrate",
"Integrate",0,0) ;
4577 pc.defineObject(
"yvar",
"YVar",0,0) ;
4580 pc.process(cmdList) ;
4581 if (!pc.ok(kTRUE)) {
4586 Bool_t integrate = pc.getInt(
"integrate") ;
4587 RooRealVar* yvar = (RooRealVar*) pc.getObject(
"yvar") ;
4589 string name = Form(
"chi2_%s_%s",GetName(),data.GetName()) ;
4592 return new RooXYChi2Var(name.c_str(),name.c_str(),*
this,data,*yvar,integrate) ;
4594 return new RooXYChi2Var(name.c_str(),name.c_str(),*
this,data,integrate) ;
4606 RooFitResult* RooAbsReal::chi2FitDriver(RooAbsReal& fcn, RooLinkedList& cmdList)
4609 RooCmdConfig pc(Form(
"RooAbsPdf::chi2FitDriver(%s)",GetName())) ;
4611 pc.defineString(
"fitOpt",
"FitOptions",0,
"") ;
4613 pc.defineInt(
"optConst",
"Optimize",0,1) ;
4614 pc.defineInt(
"verbose",
"Verbose",0,0) ;
4615 pc.defineInt(
"doSave",
"Save",0,0) ;
4616 pc.defineInt(
"doTimer",
"Timer",0,0) ;
4617 pc.defineInt(
"plevel",
"PrintLevel",0,1) ;
4618 pc.defineInt(
"strat",
"Strategy",0,1) ;
4619 pc.defineInt(
"initHesse",
"InitialHesse",0,0) ;
4620 pc.defineInt(
"hesse",
"Hesse",0,1) ;
4621 pc.defineInt(
"minos",
"Minos",0,0) ;
4622 pc.defineInt(
"ext",
"Extended",0,2) ;
4623 pc.defineInt(
"numee",
"PrintEvalErrors",0,10) ;
4624 pc.defineInt(
"doWarn",
"Warnings",0,1) ;
4625 pc.defineString(
"mintype",
"Minimizer",0,
"Minuit") ;
4626 pc.defineString(
"minalg",
"Minimizer",1,
"minuit") ;
4627 pc.defineObject(
"minosSet",
"Minos",0,0) ;
4629 pc.defineMutex(
"FitOptions",
"Verbose") ;
4630 pc.defineMutex(
"FitOptions",
"Save") ;
4631 pc.defineMutex(
"FitOptions",
"Timer") ;
4632 pc.defineMutex(
"FitOptions",
"Strategy") ;
4633 pc.defineMutex(
"FitOptions",
"InitialHesse") ;
4634 pc.defineMutex(
"FitOptions",
"Hesse") ;
4635 pc.defineMutex(
"FitOptions",
"Minos") ;
4638 pc.process(cmdList) ;
4639 if (!pc.ok(kTRUE)) {
4644 const char* fitOpt = pc.getString(
"fitOpt",0,kTRUE) ;
4645 #ifdef __ROOFIT_NOROOMINIMIZER
4646 const char* minType =0 ;
4648 const char* minType = pc.getString(
"mintype",
"Minuit") ;
4649 const char* minAlg = pc.getString(
"minalg",
"minuit") ;
4651 Int_t optConst = pc.getInt(
"optConst") ;
4652 Int_t verbose = pc.getInt(
"verbose") ;
4653 Int_t doSave = pc.getInt(
"doSave") ;
4654 Int_t doTimer = pc.getInt(
"doTimer") ;
4655 Int_t plevel = pc.getInt(
"plevel") ;
4656 Int_t strat = pc.getInt(
"strat") ;
4657 Int_t initHesse= pc.getInt(
"initHesse") ;
4658 Int_t hesse = pc.getInt(
"hesse") ;
4659 Int_t minos = pc.getInt(
"minos") ;
4660 Int_t numee = pc.getInt(
"numee") ;
4661 Int_t doWarn = pc.getInt(
"doWarn") ;
4662 const RooArgSet* minosSet =
static_cast<RooArgSet*
>(pc.getObject(
"minosSet")) ;
4664 RooFitResult *ret = 0 ;
4666 #ifdef __ROOFIT_NOROOMINIMIZER
4669 if (
"OldMinuit" ==
string(minType)) {
4678 m.setPrintEvalErrors(numee) ;
4680 m.setPrintLevel(plevel) ;
4685 m.optimizeConst(optConst);
4691 ret = m.fit(fitOpt) ;
4706 m.setStrategy(strat) ;
4725 m.minos(*minosSet) ;
4733 string name = Form(
"fitresult_%s",fcn.GetName()) ;
4734 string title = Form(
"Result of fit of %s ",GetName()) ;
4735 ret = m.save(name.c_str(),title.c_str()) ;
4740 #ifndef __ROOFIT_NOROOMINIMIZER
4742 RooMinimizer m(fcn) ;
4743 m.setMinimizerType(minType);
4749 m.setPrintEvalErrors(numee) ;
4751 m.setPrintLevel(plevel) ;
4756 m.optimizeConst(optConst);
4762 ret = m.fit(fitOpt) ;
4777 m.setStrategy(strat) ;
4786 m.minimize(minType, minAlg) ;
4796 m.minos(*minosSet) ;
4804 string name = Form(
"fitresult_%s",fcn.GetName()) ;
4805 string title = Form(
"Result of fit of %s ",GetName()) ;
4806 ret = m.save(name.c_str(),title.c_str()) ;
4821 RooAbsReal::ErrorLoggingMode RooAbsReal::evalErrorLoggingMode()
4823 return _evalErrorMode ;
4835 void RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::ErrorLoggingMode m)
4843 void RooAbsReal::setParameterizeIntegral(
const RooArgSet& paramVars)
4845 RooFIter iter = paramVars.fwdIterator() ;
4848 while((arg=iter.next())) {
4849 if (!dependsOnValue(*arg)) {
4850 coutW(InputArguments) <<
"RooAbsReal::setParameterizeIntegral(" << GetName()
4851 <<
") function does not depend on listed parameter " << arg->GetName() <<
", ignoring" << endl ;
4854 if (plist.size()>0) plist +=
":" ;
4855 plist += arg->GetName() ;
4857 setStringAttribute(
"CACHEPARAMINT",plist.c_str()) ;
4869 RooSpan<double> RooAbsReal::evaluateBatch(std::size_t begin, std::size_t maxSize)
const {
4870 assert(_batchData.status(begin, maxSize) != BatchHelpers::BatchData::kReadyAndConstant);
4873 leafNodeServerList(&allLeafs);
4875 if (RooMsgService::instance().isActive(
this, RooFit::Optimization, RooFit::INFO)) {
4876 coutI(Optimization) <<
"The class " << IsA()->GetName() <<
" does not have the faster batch evaluation interface."
4877 <<
" Consider requesting this feature on ROOT's JIRA tracker." << std::endl;
4882 std::vector<std::tuple<RooRealVar*, RooSpan<const double>,
double>> batchLeafs;
4883 for (
auto leaf : allLeafs) {
4884 auto leafRRV =
dynamic_cast<RooRealVar*
>(leaf);
4888 auto leafBatch = leafRRV->getValBatch(begin, maxSize);
4889 if (leafBatch.empty())
4892 maxSize = std::min(maxSize, leafBatch.size());
4893 batchLeafs.emplace_back(leafRRV, leafBatch, leafRRV->_value);
4896 if (batchLeafs.empty() || maxSize == 0)
4900 auto output = _batchData.makeWritableBatchUnInit(begin, maxSize);
4902 for (std::size_t i = 0; i < output.size(); ++i) {
4903 for (
auto& tup : batchLeafs) {
4904 RooRealVar* leaf = std::get<0>(tup);
4905 auto batch = std::get<1>(tup);
4907 leaf->setVal(batch[i]);
4910 output[i] = evaluate();
4914 for (
auto& tup : batchLeafs) {
4915 std::get<0>(tup)->setVal(std::get<2>(tup));
4927 using RooHelpers::CachingError;
4928 using RooHelpers::FormatPdfTree;
4931 Double_t RooAbsReal::_DEBUG_getVal(
const RooArgSet* normalisationSet)
const {
4933 const bool tmpFast = _fast;
4934 const double tmp = _value;
4936 double fullEval = 0.;
4938 fullEval = getValV(normalisationSet);
4940 catch (CachingError& error) {
4941 throw CachingError(std::move(error),
4942 FormatPdfTree() << *
this);
4945 const double ret = (_fast && !_inhibitDirty) ? _value : fullEval;
4947 if (std::isfinite(ret) && ( ret != 0. ? (ret - fullEval)/ret : ret - fullEval) > 1.E-9) {
4948 gSystem->StackTrace();
4949 FormatPdfTree formatter;
4950 formatter <<
"--> (Scalar computation wrong here:)\n"
4951 << GetName() <<
" " <<
this <<
" _fast=" << tmpFast
4952 <<
"\n\tcached _value=" << std::setprecision(16) << tmp
4953 <<
"\n\treturning =" << ret
4954 <<
"\n\trecomputed =" << fullEval
4955 <<
"\n\tnew _value =" << _value <<
"] ";
4956 formatter <<
"\nServers:";
4957 for (
const auto server : _serverList) {
4959 server->printStream(formatter.stream(), kName | kClassName | kArgs | kExtras | kAddress | kValue, kInline);
4962 throw CachingError(formatter);
4969 void RooAbsReal::checkBatchComputation(std::size_t evtNo,
const RooArgSet* normSet,
double relAccuracy)
const {
4970 for (
const auto server : _serverList) {
4972 auto realServer =
dynamic_cast<RooAbsReal*
>(server);
4974 realServer->checkBatchComputation(evtNo, normSet, relAccuracy);
4975 }
catch (CachingError& error) {
4976 throw CachingError(std::move(error),
4977 FormatPdfTree() << *
this);
4981 if (!_allBatchesDirty && _batchData.status(evtNo, 1) >= BatchHelpers::BatchData::kReady) {
4982 RooSpan<const double> batch = _batchData.getBatch(evtNo, 1);
4983 RooSpan<const double> enclosingBatch = _batchData.getBatch(evtNo-1, 3);
4984 const double batchVal = batch[0];
4985 const double relDiff = _value != 0. ? (_value - batchVal)/_value : _value - batchVal;
4987 if (fabs(relDiff) > relAccuracy && fabs(_value) > 1.E-300) {
4988 FormatPdfTree formatter;
4989 formatter <<
"--> (Batch computation wrong here:)\n";
4990 printStream(formatter.stream(), kName | kClassName | kArgs | kExtras | kAddress, kInline);
4991 formatter << std::setprecision(17)
4992 <<
"\n _batch[" << std::setw(7) << evtNo-1 <<
"]= " << (enclosingBatch.empty() ? 0 : enclosingBatch[0])
4993 <<
"\n _batch[" << std::setw(7) << evtNo <<
"]= " << batchVal <<
" !!!"
4994 <<
"\n expected ('_value'): " << _value
4995 <<
"\n delta " <<
" = " << _value - batchVal
4996 <<
"\n rel delta " <<
" = " << relDiff
4997 <<
"\n _batch[" << std::setw(7) << evtNo+1 <<
"]= " << (enclosingBatch.empty() ? 0 : enclosingBatch[2]);
4999 formatter <<
"\n" << std::left << std::setw(24) <<
"evaluate(unnorm.)" <<
'=' << evaluate();
5001 formatter <<
"\nServers: ";
5002 for (
const auto server : _serverList) {
5003 formatter <<
"\n - ";
5004 server->printStream(formatter.stream(), kName | kClassName | kArgs | kExtras | kAddress | kValue, kInline);
5005 formatter << std::setprecision(17);
5007 auto serverAsReal =
dynamic_cast<RooAbsReal*
>(server);
5009 const BatchHelpers::BatchData& serverBatchData = serverAsReal->batchData();
5010 RooSpan<const double> theBatch = serverBatchData.getBatch(evtNo-1, 3);
5011 if (!theBatch.empty()) {
5012 formatter <<
"\n _batch[" << evtNo-1 <<
"]=" << theBatch[0]
5013 <<
"\n _batch[" << evtNo <<
"]=" << theBatch[1]
5014 <<
"\n _batch[" << evtNo+1 <<
"]=" << theBatch[2];
5017 formatter << std::setprecision(17)
5018 <<
"\n getVal()=" << serverAsReal->getVal(normSet);
5023 throw CachingError(formatter);