47#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
49#define protected public
70#define GETWS(a) a->_myws
71#define GETWSSETS(w) w->_namedSets
72#define GETWSSNAPSHOTS(w) w->_snapshots
73#define GETACTBROWSER(b) b->fActBrowser
74#define GETROOTDIR(b) b->fRootDir
75#define GETLISTTREE(b) b->fListTree
76#define GETDMP(o, m) o->m
99 return a->workspace();
107 return w->getSnapshots();
111 return b->GetActBrowser();
115 return b->GetRootDir();
119 return b->GetListTree();
121#define GETDMP(o, m) \
122 *reinterpret_cast<void **>(reinterpret_cast<unsigned char *>(o) + o->Class()->GetDataMemberOffset(#m))
173#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
177#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
206#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
214xRooNode::InteractiveObject *xRooNode::gIntObj =
nullptr;
215std::map<std::string, std::tuple<std::function<
double(
double,
double,
double)>,
bool>> xRooNode::auxFunctions;
216void xRooNode::SetAuxFunction(
const char *title,
const std::function<
double(
double,
double,
double)> &func,
219 auxFunctions[title] = std::make_tuple(func, symmetrize);
238xRooNode::xRooNode(
const char *classname,
const char *
name,
const char *title)
244#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
247 xRooNode(*
w, std::make_shared<xRooNode>()).sterilize();
253 if (
auto a = get<TNamed>();
a)
258xRooNode::xRooNode(
const char *
name,
const std::shared_ptr<TObject> &comp,
const std::shared_ptr<xRooNode> &parent)
259 :
TNamed(
name,
""), fComp(comp), fParent(parent)
269#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
270 fComp = std::make_shared<RooWorkspace>(
"workspace",
name);
275 Error(
"xRooNode",
"Error reading json workspace %s",
name);
280 Error(
"xRooNode",
"json format workspaces available only in ROOT 6.26 onwards");
286 auto _file = std::make_shared<TFile>(
291 auto keys = _file->GetListOfKeys();
293 for (
auto &&k : *keys) {
299#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
300 dynamic_cast<RooWorkspace *>(ws)->_embeddedDataList.Delete();
302 xRooNode(*ws, std::make_shared<xRooNode>()).sterilize();
308 fParent = std::make_shared<xRooNode>(
316 }
else if (pathName.EndsWith(
".root") || pathName.EndsWith(
".json")) {
321 if (
auto _ws = get<RooWorkspace>(); _ws && (!parent || parent->get<
TFile>())) {
328 for (
auto f : *
gROOT->GetListOfFiles()) {
329 if ((
dynamic_cast<TFile *
>(
f)->GetVersion() / 100) > (
gROOT->GetVersionInt() / 100)) {
330 Warning(
"xRooNode",
"There is file open with version %d > current version %d ... results may be wrong",
331 dynamic_cast<TFile *
>(
f)->GetVersion(),
gROOT->GetVersionInt());
337 for (
auto &
d : _ws->allData()) {
338 for (
auto &
a : *
d->get()) {
339 if (
auto v = _ws->var(
a->GetName());
v)
340 v->setAttribute(
"obs");
341 else if (
auto c = _ws->cat(
a->GetName());
c)
342 c->setAttribute(
"obs");
345 checkCount +=
d->TestBit(1 << 20);
348 if (checkCount == 0 && !_ws->allData().empty())
349 _ws->allData().back()->SetBit(1 << 20,
true);
352 for (
auto s : *_set) {
354 _ws->var(s->GetName())->setStringAttribute(
"nominal",
TString::Format(
"%f",
v->getVal()));
362 if (k ==
"globalObservables" ||
TString(k).
EndsWith(
"_GlobalObservables")) {
365 s->setAttribute(
"obs");
366 s->setAttribute(
"global");
369 const_cast<RooArgSet &
>(
v).setAttribAll(
"obs");
372 s->setAttribute(
"poi");
384 const_cast<RooArgSet &
>(
v).setAttribAll(
"np");
387 if (!_allGlobs.
empty() &&
GETWSSETS(_ws).count(
"globalObservables") == 0) {
388 _ws->defineSet(
"globalObservables", _allGlobs);
393 if (!_ws->allPdfs().empty()) {
394 std::set<RooRealVar *> noErrorPars;
395 std::string parNames;
396 for (
auto &
p :
np()) {
400 if (!
v->hasError()) {
401 noErrorPars.insert(
v);
402 if (!parNames.empty())
407 if (!noErrorPars.empty()) {
410 "Inferring initial errors of %d parameters (give all nuisance parameters an error to avoid this msg)",
411 int(noErrorPars.size()));
414 for (
auto &
a : *this) {
415 if (
a->fFolder ==
"!models") {
417 auto fr =
a->floats().reduced(parNames).fitResult(
"prefit");
419 for (
auto &
v : noErrorPars) {
420 if (
auto arg =
dynamic_cast<RooRealVar *
>(_fr->floatParsFinal().find(
v->GetName()));
421 arg && arg->hasError()) {
422 v->setError(arg->getError());
434 if (strlen(GetTitle()) == 0) {
450 (comp.InheritsFrom(
"RooAbsArg") && dynamic_cast<const
RooAbsArg *>(&comp)->getStringAttribute(
"alias"))
451 ? dynamic_cast<const
RooAbsArg *>(&comp)->getStringAttribute(
"alias")
460 if (
auto a = std::dynamic_pointer_cast<RooAbsArg>(comp);
a &&
a->getStringAttribute(
"alias"))
461 return a->getStringAttribute(
"alias");
463 return comp->GetName();
481 if (
auto o = get<RooAbsReal>(); o) {
482 if (o->isSelectedComp() && !val) {
485 o->setAttribute(
"hidden");
486 }
else if (!o->isSelectedComp() && !val) {
491 o->setAttribute(
"hidden",
false);
494 item->CheckItem(!o->getAttribute(
"hidden"));
495 if (o->isSelectedComp())
498 item->SetColor(
kGray);
502 if (
auto o =
get(); o) {
504 o->SetBit(1 << 20, val);
505 if (
auto fr = get<RooFitResult>(); fr) {
506 if (
auto _ws =
ws(); _ws) {
509 if (!_ws->genobj(fr->GetName())) {
511 if (
auto wfr =
dynamic_cast<RooFitResult *
>(_ws->genobj(fr->GetName()))) {
516 _allVars = fr->floatParsFinal();
517 _allVars = fr->constPars();
518 for (
auto &i : fr->floatParsInit()) {
524 for (
auto oo : _ws->allGenericObjects()) {
525 if (
auto ffr =
dynamic_cast<RooFitResult *
>(oo); ffr && ffr != fr) {
526 ffr->ResetBit(1 << 20);
530 _ws->allVars() = fr->floatParsInit();
534 if (
auto first = item->GetParent()->GetFirstChild()) {
536 if (
first->HasCheckBox()) {
538 first->CheckItem(_obj->get() && _obj->get()->TestBit(1 << 20));
549 static bool blockBrowse =
false;
553 auto b2 =
dynamic_cast<TBrowser *
>(
gROOT->GetListOfBrowsers()->Last());
554 if (!b2 || !b2->GetBrowserImp()) {
561 b2 =
new TBrowser(
"nodeBrowser",
this,
"RooFit Browser");
563 }
else if (strcmp(b2->GetName(),
"nodeBrowser") == 0) {
565 b2->BrowseObject(
this);
588 if (
auto first = item->GetFirstChild()) {
590 if (
first->HasCheckBox()) {
592 first->CheckItem(_obj->get() &&
593 (_obj->get()->TestBit(1 << 20) ||
607 if (
auto _fr = get<RooFitResult>(); _fr &&
fBrowsables.empty()) {
609 fBrowsables.push_back(std::make_shared<xRooNode>(
".Draw(\"pull\")",
nullptr, *
this));
610 fBrowsables.push_back(std::make_shared<xRooNode>(
".Draw(\"corrcolztext\")",
nullptr, *
this));
611 if (std::unique_ptr<RooAbsCollection>(_fr->floatParsFinal().selectByAttrib(
"poi",
true))->size() == 1) {
612 fBrowsables.push_back(std::make_shared<xRooNode>(
".Draw(\"impact\")",
nullptr, *
this));
618 if (
auto s = get<TStyle>()) {
619 s->SetFillAttributes();
626 Draw(
b->GetDrawOption());
628 }
catch (
const std::exception &
e) {
631 (
gROOT->GetListOfBrowsers()->At(0))
634 "Exception",
e.what(),
639 bool hasFolders =
false;
641 for (
auto &
c : *
this) {
642 if (!
c->fFolder.empty()) {
651 auto _folders =
find(
".folders");
653 _folders = emplace_back(std::make_shared<xRooNode>(
".folders",
nullptr, *
this));
656 for (
auto &
v : *
this) {
657 if (
v->fFolder !=
"" && !_folders->find(
v->fFolder,
false)) {
658 _folders->emplace_back(std::make_shared<xRooNode>(
v->fFolder.c_str(),
nullptr, *
this));
662 for (
auto &
v : *_folders) {
665 _name = _name(1, _name.
Length());
666 b->Add(
v.get(), _name);
670 for (
auto &
v : *
this) {
671 if (hasFolders && !
v->fFolder.empty())
673 if (strcmp(
v->GetName(),
".folders") == 0)
677 if (_fr && ((_fr->status() == 0 && _fr->numStatusHistory() == 0) || (_fr->floatParsFinal().empty()))) {
681 if (
v->get<
RooAbsPdf>() && get<RooSimultaneous>())
685 _name = _name(strlen(
v->get()->ClassName()) + 2, _name.
Length());
693 :
v->get()->GetName());
694 }
else if (
v->get() && !
v->get<
TFile>() && !
TString(
v->GetName()).BeginsWith(
'/'))
696 if (
auto _type =
v->GetNodeType(); strlen(_type)) {
704 for (
size_t i = 0; i < fv->dependents().
size(); i++) {
710 for (
size_t i = 0; i < gv->dependents().
size(); i++) {
717 TString nameSave(
v->TNamed::GetName());
718 TString titleSave(
v->TNamed::GetTitle());
719 if (
auto o =
v->get(); o)
720 v->TNamed::SetNameTitle(o->GetName(), o->ClassName());
721 b->Add(
v.get(), _name, _checked);
722 if (
auto o =
v->get(); o)
723 v->TNamed::SetNameTitle(nameSave, titleSave);
724 if (_checked != -1) {
725 dynamic_cast<TQObject *
>(
b->GetBrowserImp())
726 ->Connect(
"Checked(TObject *, bool)",
ClassName(),
v.get(),
"Checked(TObject *, bool)");
729 if (_fr->status() || _fr->covQual() != 3) {
730 v->GetTreeItem(
b)->SetColor((_fr->numStatusHistory() || _fr->floatParsFinal().empty()) ?
kRed :
kBlue);
731 }
else if (_fr->numStatusHistory() == 0) {
732 v->GetTreeItem(
b)->SetColor(
kGray);
735 if ((
v->fFolder ==
"!np" ||
v->fFolder ==
"!poi")) {
737 v->GetTreeItem(
b)->SetColor(
kGray);
739 v->GetTreeItem(
b)->ClearColor();
743 if (
auto fits = _htr->GetFitInfo()) {
744 for (
int i = 0; i < fits->numEntries(); i++) {
746 if (fits->get(i)->getCatIndex(
"type") != 5 && fits->get(i)->getRealValue(
"status") != 0) {
747 v->GetTreeItem(
b)->SetColor(
kRed);
752 v->GetTreeItem(
b)->SetColor(
kBlue);
779 if (_name ==
".memory")
781 TString nameSave(
v->TNamed::GetName());
782 TString titleSave(
v->TNamed::GetTitle());
783 if (
auto o =
v->get(); o)
784 v->TNamed::SetNameTitle(o->GetName(), o->ClassName());
785 b->Add(
v.get(), _name, -1);
786 if (
auto o =
v->get(); o)
787 v->TNamed::SetNameTitle(nameSave, titleSave);
790 b->SetSelected(
this);
803 auto v = std::make_shared<xRooNode>(
vars());
814 if (strcmp(
b->GetName(),
".vars") == 0)
837 if (
auto v = var();
v)
838 return v->getBinWidth(bin - 1, GetName());
843 if (
auto v = rvar();
v)
844 return (bin ==
v->getBinning(GetName()).numBins() + 1) ?
v->getBinning(GetName()).binHigh(bin - 2)
845 :
v->getBinning(GetName()).binLow(bin - 1);
850 if (
auto v = rvar();
v)
851 return (bin == 0) ?
v->getBinning(GetName()).binLow(bin) :
v->getBinning(GetName()).binHigh(bin - 1);
857 return (binning() && strlen(binning()->GetTitle())) ? binning()->GetTitle() : GetParent()->GetTitle();
864 dynamic_cast<TNamed *
>(GetParent())->SetTitle(title);
867 void Set(
Int_t nbins,
const double *xbins)
override
870 v->setBinning(
RooBinning(nbins, xbins), GetName());
875 std::vector<double> bins(nbins + 1);
876 for (
int i = 0; i <= nbins; i++)
877 bins.at(i) = xbins[i];
878 return Set(nbins, &bins[0]);
890 Int_t FindFixBin(
double x)
const override {
return (binning()) ? (binning()->binNumber(
x) + 1) :
x; }
901 if (
auto _owned =
find(
".memory"); _owned) {
902 for (
auto &o : *_owned) {
903 if (
name == o->GetName()) {
904 if (
type.empty() || o->get()->InheritsFrom(
type.c_str()))
913 while (!_provider && _parent) {
914 _provider = _parent->fProvider;
915 _parent = _parent->fParent;
918 return _provider->getObject(
name,
type);
921 std::shared_ptr<TObject> out;
922 if (
auto arg =
ws()->arg(
name.c_str()); arg) {
923 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
924 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
929 if (
auto arg =
ws()->
data(
name.c_str()); arg) {
930 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
931 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
936 if (
auto arg =
ws()->genobj(
name.c_str()); arg) {
937 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
938 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
943 if (
auto arg =
ws()->embeddedData(
name.c_str()); arg) {
944 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
945 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
951 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
952 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
967 cat && cat->numTypes() !=
fXAxis->GetNbins()) {
974 if (
auto a = get<RooAbsArg>();
a &&
a->isFundamental())
979 auto o = get<RooAbsReal>();
983 if (
auto xName = o->getStringAttribute(
"xvar"); xName) {
993 (o->dependsOn(*
dynamic_cast<RooAbsArg *
>(_parentX->GetParent())) ||
vars().size() == 0)) {
995 }
else if (
auto _obs =
obs(); !_obs.empty()) {
996 for (
auto &
v : _obs) {
1005 }
else if (
auto _pars =
pars(); !_pars.empty()) {
1006 for (
auto &
v : _pars) {
1022 if (o !=
dynamic_cast<TObject *
>(
x)) {
1027 TString binningName = o->getStringAttribute(
"binning");
1028 auto _bnames =
x->getBinningNames();
1029 bool hasBinning =
false;
1030 for (
auto &
b : _bnames) {
1031 if (
b == binningName) {
1039 Warning(
"GetXaxis",
"Binning %s not defined on %s - clearing", binningName.
Data(),
1041 o->setStringAttribute(
"binning",
nullptr);
1045 if (binningName ==
"" && o !=
dynamic_cast<TObject *
>(
x)) {
1047 auto __bnames =
x->getBinningNames();
1048 for (
auto &
b : __bnames) {
1051 if (
b == o->GetName()) {
1052 binningName = o->GetName();
1056 if (binningName ==
"") {
1062 (std::list<double> *)(
nullptr),
1063 o->binBoundaries(*
dynamic_cast<RooAbsRealLValue *
>(
x), -std::numeric_limits<double>::infinity(),
1064 std::numeric_limits<double>::infinity()));
1066 std::vector<double> _bins;
1067 for (
auto &
b : *
bins) {
1068 if (_bins.empty() || std::abs(_bins.back() -
b) > 1
e-5 * _bins.back())
1071 fXAxis = std::make_shared<Axis2>(_bins.size() - 1, &_bins[0]);
1073 if (
auto _v =
dynamic_cast<RooRealVar *
>(
x); _v) {
1074 _v->setBinning(
RooBinning(_bins.size() - 1, &_bins[0], o->GetName()), o->
GetName());
1075 _v->getBinning(o->GetName())
1080 binningName = o->GetName();
1082 }
else if (_parentX) {
1084 binningName = _parentX->GetName();
1091 if (
r->getBinning(binningName).isUniform()) {
1092 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName),
r->getMin(binningName),
r->getMax(binningName));
1094 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName),
r->getBinning(binningName).array());
1097 std::vector<double>
bins = {};
1098 for (
int i = 0; i <=
x->numBins(binningName); i++)
1100 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName), &
bins[0]);
1102 for (
int i = 0; i <
x->numBins(binningName); i++) {
1108 fXAxis->SetName(binningName);
1115 if (
auto o =
get(); o) {
1116 if (o->InheritsFrom(
"RooWorkspace"))
1118 if (o->InheritsFrom(
"RooAbsData"))
1120 if (o->InheritsFrom(
"RooSimultaneous"))
1123 if (o->InheritsFrom(
"RooProdPdf"))
1125 if (o->InheritsFrom(
"RooRealSumPdf") || o->InheritsFrom(
"RooAddPdf"))
1128 if (o->InheritsFrom(
"RooFitResult")) {
1129 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitRooFitResult",
true)) {
1130 gClient->GetMimeTypeList()->AddType(
"xRooFitRooFitResult",
"xRooFitRooFitResult",
"package.xpm",
1131 "package.xpm",
"->Browse()");
1133 return "xRooFitRooFitResult";
1135 if (o->InheritsFrom(
"RooRealVar") || o->InheritsFrom(
"RooCategory")) {
1136 if (get<RooAbsArg>()->getAttribute(
"obs")) {
1137 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitObs",
true)) {
1138 gClient->GetMimeTypeList()->AddType(
"xRooFitObs",
"xRooFitObs",
"x_pic.xpm",
"x_pic.xpm",
"->Browse()");
1140 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitGlobs",
true)) {
1141 gClient->GetMimeTypeList()->AddType(
"xRooFitGlobs",
"xRooFitGlobs",
"z_pic.xpm",
"z_pic.xpm",
1144 return (get<RooAbsArg>()->getAttribute(
"global") ?
"xRooFitGlobs" :
"xRooFitObs");
1148 if (o->InheritsFrom(
"TStyle")) {
1149 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitTStyle",
true)) {
1150 gClient->GetMimeTypeList()->AddType(
"xRooFitTStyle",
"xRooFitTStyle",
"bld_colorselect.xpm",
1151 "bld_colorselect.xpm",
"->Browse()");
1153 return "xRooFitTStyle";
1155 if (o->InheritsFrom(
"RooConstVar")) {
1161 return "TMethodBrowsable-leaf";
1163 if (o->InheritsFrom(
"RooStats::HypoTestInverterResult")) {
1164 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitScanStyle",
true)) {
1165 gClient->GetMimeTypeList()->AddType(
"xRooFitScanStyle",
"xRooFitScanStyle",
"f2_s.xpm",
"f2_s.xpm",
1168 return "xRooFitScanStyle";
1170 if (o->InheritsFrom(
"RooStats::HypoTestResult")) {
1171 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitTestStyle",
true)) {
1172 gClient->GetMimeTypeList()->AddType(
"xRooFitTestStyle",
"xRooFitTestStyle",
"diamond.xpm",
"diamond.xpm",
1175 return "xRooFitTestStyle";
1177 if (o->InheritsFrom(
"RooStats::HistFactory::FlexibleInterpVar"))
1178 return "TBranchElement-folder";
1179 if (o->InheritsFrom(
"RooAbsPdf")) {
1180 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitPDFStyle",
true)) {
1181 gClient->GetMimeTypeList()->AddType(
"xRooFitPDFStyle",
"xRooFitPDFStyle",
"pdf.xpm",
"pdf.xpm",
1184 return "xRooFitPDFStyle";
1188 _ax && (
a->isBinnedDistribution(*
dynamic_cast<RooAbsArg *
>(_ax->GetParent())) ||
1190 std::unique_ptr<std::list<double>>(
a->binBoundaries(
1191 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
1192 std::numeric_limits<double>::infinity()))))) {
1197 return o->ClassName();
1208 if (o->InheritsFrom(
"RooStats::HistFactory::FlexibleInterpVar"))
1210 if (o->InheritsFrom(
"PiecewiseInterpolation"))
1212 if (o->InheritsFrom(
"RooHistFunc"))
1213 return (
dynamic_cast<RooAbsArg *
>(o)->getAttribute(
"density")) ?
"ConstDensityHisto" :
"ConstHisto";
1214 if (o->InheritsFrom(
"RooBinWidthFunction"))
1216 if (o->InheritsFrom(
"ParamHistFunc"))
1218 if (o->InheritsFrom(
"RooRealVar"))
1220 if (o->InheritsFrom(
"RooConstVar"))
1228 xRooNode out(
".coords",
nullptr, *
this);
1230 auto _p = std::shared_ptr<xRooNode>(
const_cast<xRooNode *
>(
this), [](
xRooNode *) {});
1233 if (
auto pos = pName.
Index(
'='); pos != -1) {
1234 if (pos > 0 && pName(pos - 1) ==
'<') {
1237 pName = pName(pos + 1, pName.
Length());
1239 pName = pName(0, pName.
Index(
'<'));
1242 _obs->setVal((high + low) / 2.);
1243 static_cast<RooRealVar *
>(_obs.get())->setRange(
"coordRange", low, high);
1245 "coordRange",
"coordRange");
1247 out.emplace_back(std::make_shared<xRooNode>(_obs->GetName(), _obs, _p));
1252 }
else if (
auto _obs = _p->getObject<
RooAbsArg>(pName(0, pos)); _obs) {
1255 _cat->setLabel(pName(pos + 1, pName.
Length()));
1256 }
else if (
auto _var =
dynamic_cast<RooAbsRealLValue *
>(_obs.get()); _var) {
1260 out.emplace_back(std::make_shared<xRooNode>(_obs->GetName(), _obs, _p));
1262 throw std::runtime_error(
"Unknown observable, could not find");
1274 }
catch (
const std::exception &
e) {
1283 }
catch (
const std::exception &
e) {
1292 if (strcmp(
GetName(),
".poi") == 0) {
1298 throw std::runtime_error(
TString::Format(
"%s is not a poi", toRemove.GetName()));
1300 toRemove.get<
RooAbsArg>()->setAttribute(
"poi",
false);
1303 }
else if (strcmp(
GetName(),
".factors") == 0 || strcmp(
GetName(),
".constraints") == 0 ||
1304 strcmp(
GetName(),
".components") == 0) {
1310 pdf =
p->pdfList().find(
child.GetName());
1313 auto i =
p->pdfList().index(*pdf);
1315#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
1316 const_cast<RooArgList &
>(
p->pdfList()).remove(*pdf);
1317#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
1318 p->_pdfNSetList.erase(
p->_pdfNSetList.begin() + i);
1320 auto nset =
p->_pdfNSetList.At(i);
1321 p->_pdfNSetList.Remove(nset);
1324 if (
p->_extendedIndex == i)
1325 p->_extendedIndex = -1;
1326 else if (
p->_extendedIndex > i)
1327 p->_extendedIndex--;
1339 arg = p2->components().find(
child.GetName());
1343#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
1344 p2->_compRSet.remove(*arg);
1346 const_cast<RooArgList &
>(p2->realComponents()).remove(*arg);
1348 p2->removeServer(*arg,
true);
1353 bool removed =
false;
1356 c->constraints().Remove(toRemove);
1358 }
catch (std::runtime_error &) {
1368 arg = p4->funcList().find(
child.GetName());
1372 auto idx = p4->funcList().index(arg);
1376 const_cast<RooArgList &
>(p4->funcList()).remove(*arg);
1377 p4->removeServer(*arg,
true);
1379 std::vector<RooAbsArg *> _coefs;
1380 for (
size_t ii = 0; ii < const_cast<RooArgList &>(p4->coefList()).size(); ii++) {
1381 if (ii !=
size_t(idx))
1382 _coefs.push_back(
const_cast<RooArgList &
>(p4->coefList()).
at(ii));
1384 const_cast<RooArgList &
>(p4->coefList()).removeAll();
1385 for (
auto &
a : _coefs)
1396 if (
auto w = get<RooWorkspace>();
w) {
1398 auto arg =
w->components().find(
child.GetName());
1405 if (arg->hasClients()) {
1406 throw std::runtime_error(
1407 TString::Format(
"Cannot remove %s from workspace %s, because it has dependencies - first remove from those",
1410 const_cast<RooArgSet &
>(
w->components()).remove(*arg);
1411 Info(
"Remove",
"Deleted %s from workspace %s", out.GetName(),
GetName());
1413 }
else if (get<RooProduct>() || get<RooProdPdf>()) {
1415 }
else if (get<RooRealSumPdf>()) {
1419 throw std::runtime_error(
"Removal not implemented for this type of object");
1428 ~AutoUpdater() {
n.browse(); }
1431 AutoUpdater xxx(*
this);
1434 bool considerType(sOpt ==
"+");
1450 if (strcmp(
GetName(),
".factors") == 0) {
1453 }
else if (strcmp(
GetName(),
".components") == 0) {
1456 }
else if (strcmp(
GetName(),
".variations") == 0) {
1459 }
else if (strcmp(
GetName(),
".constraints") == 0) {
1465 }
else if ((strcmp(
GetName(),
".globs") == 0)) {
1468 out->setAttribute(
"obs");
1469 out->setAttribute(
"global");
1472 throw std::runtime_error(
"Failed to add global observable");
1473 }
else if ((strcmp(
GetName(),
".poi") == 0)) {
1476 out->setAttribute(
"poi");
1479 throw std::runtime_error(
"Failed to add parameter of interest");
1486 }
else if (strcmp(
GetName(),
".datasets()") == 0) {
1491 throw std::runtime_error(
1492 "Datasets can only be created for pdfs or workspaces (except if generated dataset, then must be pdf)");
1495 if (sOpt ==
"asimov" || sOpt ==
"toy") {
1497 auto _fr = std::dynamic_pointer_cast<const RooFitResult>(
fParent->fitResult().fComp);
1498 if (strlen(_fr->GetName()) == 0)
1499 std::const_pointer_cast<RooFitResult>(_fr)->SetName(
TUUID().AsString());
1501 if (strlen(
child.GetName()))
1502 asi.first->SetName(
child.GetName());
1504 _ws->import(*asi.first);
1506 if (_fr->numStatusHistory() == 0) {
1510 }
else if (!_ws->obj(_fr->GetName())) {
1514#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
1515 _ws->saveSnapshot(asi.first->GetName(), *asi.second,
1519 _tmp.
add(*asi.second);
1520 _ws->saveSnapshot(asi.first->GetName(), _tmp,
true);
1526 auto parentObs =
fParent->obs();
1527 auto _obs = parentObs.argList();
1529 std::unique_ptr<RooAbsCollection> _globs(_obs.selectByAttrib(
"global",
true));
1531 _obs.remove(*_globs);
1537 _obs.add(*
dynamic_cast<RooAbsArg *
>(ax->GetParent()));
1540 if (
auto _d = _ws->data(
child.GetName()); _d) {
1543 l.remove(*_d->get(),
true,
true);
1547 throw std::runtime_error(
"Cannot extend dataset with new columns");
1558 if (
auto __d = _ws->data(
child.GetName()))
1559 __d->SetBit(1 << 20, _ws->allData().size() == 1);
1567 auto out = std::shared_ptr<TObject>(_ws->data(
child.GetName()), [](
TObject *) {});
1576 throw std::runtime_error(
"Cannot create dataset");
1581 throw std::runtime_error(
"Cannot add to null object with no parentage");
1583 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(
child), [](
TObject *) {}));
1588 std::rethrow_exception(std::current_exception());
1593 throw std::runtime_error(
"No object");
1597 if (
auto p = get<RooAbsData>();
p) {
1599 bb->Add(
child, opt);
1603 throw std::runtime_error(
"Can only add datasets to a dataset");
1608 auto _globs =
globs();
1609 for (
auto &glob :
child.globs()) {
1610 if (
auto g = _globs.find(glob->GetName()); !
g) {
1612 }
else if (
g->GetContent() != glob->GetContent()) {
1613 Warning(
"Add",
"Global observable %s=%g in dataset mismatches child value %g ... ignoring child",
1614 g->GetName(),
g->GetContent(), glob->GetContent());
1618 if (
auto _dglobs =
p->getGlobalObservables()) {
1621 for (
auto g : _globs)
1624 p->setGlobalObservables(globsToAdd);
1628 for (
auto col : *_data->get()) {
1629 if (!
p->get()->contains(*col)) {
1630 ds->addColumn(*col);
1638 throw std::runtime_error(
"Can only add histogram or dataset to data");
1642 throw std::runtime_error(
"Could not find pdf");
1643 auto _ax = _pdf->GetXaxis();
1645 throw std::runtime_error(
"Cannot determine binning to add data");
1654 l.remove(*
p->get(),
true,
true);
1658 throw std::runtime_error(
"Cannot extend dataset with new columns");
1665 for (
auto &o :
obs) {
1667 if (
auto dv =
dynamic_cast<RooRealVar *
>(
p->get()->find(
v->GetName())); dv) {
1668 if (
v->getMin() < dv->getMin())
1669 dv->setMin(
v->getMin());
1670 if (
v->getMax() > dv->getMax())
1671 dv->setMax(
v->getMax());
1674 if (
auto dc =
dynamic_cast<RooCategory *
>(
p->get()->find(
c->GetName())); dc) {
1675 if (!dc->hasLabel(
c->getCurrentLabel())) {
1676 dc->defineType(
c->getCurrentLabel(),
c->getCurrentIndex());
1682 for (
int i = 1; i <= _h->GetNbinsX(); i++) {
1684 if (!_h->GetXaxis()->GetBinLabel(i)) {
1685 throw std::runtime_error(
1686 TString::Format(
"Categorical observable %s requires bin labels", _ax->GetParent()->GetName()));
1687 }
else if (!cat->hasLabel(_h->GetXaxis()->GetBinLabel(i))) {
1688 throw std::runtime_error(
TString::Format(
"Categorical observable %s does not have label %s",
1689 _ax->GetParent()->GetName(), _h->GetXaxis()->GetBinLabel(i)));
1691 cat->setLabel(_h->GetXaxis()->GetBinLabel(i));
1694 dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent())->setVal(_h->GetBinCenter(i));
1696 p->add(
obs, _h->GetBinContent(i));
1702 if (
auto p = get<RooAddPdf>();
p) {
1706 auto _pdf = std::dynamic_pointer_cast<RooAbsPdf>(out);
1708 throw std::runtime_error(
"Something went wrong with pdf acquisition");
1715 if (
auto _boundaries = std::unique_ptr<std::list<double>>(_p->binBoundaries(
1716 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
1717 std::numeric_limits<double>::infinity()));
1718 !_boundaries && _ax->GetNbins() > 0) {
1719#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
1720 Warning(
"Add",
"Adding unbinned pdf %s to binned %s - will wrap with RooBinSamplingPdf(...)",
1722 _p = acquireNew<RooBinSamplingPdf>(
TString::Format(
"%s_binned", _p->GetName()), _p->GetTitle(),
1724 _p->setStringAttribute(
"alias", std::dynamic_pointer_cast<RooAbsArg>(out)->getStringAttribute(
"alias"));
1725 if (!_p->getStringAttribute(
"alias"))
1726 _p->setStringAttribute(
"alias", out->GetName());
1728 throw std::runtime_error(
1729 "unsupported addition of unbinned pdf to binned model - please upgrade to at least ROOT 6.24");
1735 if (!(_pdf->canBeExtended() &&
p->coefList().empty())) {
1739 if (_pdf->canBeExtended()) {
1744 .add(*acquireNew<RooExtendedBinding>(
TString::Format(
"%s_extBind", _pdf->GetName()),
1748 const_cast<RooArgList &
>(
p->coefList()).add(*acquire2<RooAbsArg, RooRealVar>(
"1",
"1", 1));
1751 const_cast<RooArgList &
>(
p->pdfList()).add(*_pdf);
1755 (!
child.get() && getObject<RooAbsReal>(
child.GetName()))) &&
1758 bool tooMany(
false);
1771 }
else if (!tooMany) {
1776 _sumpdf.get<
RooAbsArg>()->setStringAttribute(
"alias",
"samples");
1777 return _sumpdf.Add(
child);
1782 if (
auto p = get<RooRealSumPdf>();
p) {
1783 std::shared_ptr<TObject> out;
1784 auto cc =
child.fComp;
1785 bool isConverted = (cc !=
child.convertForAcquisition(*
this, sOpt));
1788 if (!
child.fComp && getObject<RooAbsReal>(
child.GetName())) {
1789 Info(
"Add",
"Adding existing function %s to %s",
child.GetName(),
p->
GetName());
1790 out = getObject<RooAbsReal>(
child.GetName());
1793 if (!out && !
child.fComp) {
1794 std::shared_ptr<RooAbsArg> _func;
1805 std::make_unique<TH1D>(
child.GetName(),
child.GetTitle(), _ax->GetNbins(), _ax->binning()->array());
1807 h->GetXaxis()->SetName(
TString::Format(
"%s;%s", _ax->GetParent()->GetName(), _ax->GetName()));
1810 }
else if (_obs.size() == 1) {
1814 TString binningName =
p->getStringAttribute(
"binning");
1815 for (
auto &
b : _bnames) {
1823 auto h = std::make_unique<TH1D>(
child.GetName(),
child.GetTitle(), _x->numBins(binningName),
1824 _x->getBinningPtr(binningName)->array());
1826 h->GetXaxis()->SetName(
1830 Info(
"Add",
"Created densityhisto factor %s (xaxis=%s) for %s", _func->GetName(), _obs.at(0)->GetName(),
1833 throw std::runtime_error(
"Unsupported creation of new component in SumPdf for this many obs");
1839 _func->setStringAttribute(
"alias",
child.GetName());
1843 if (
auto _f = std::dynamic_pointer_cast<RooHistFunc>(
1847 _f->setAttribute(
"density");
1848 if (_f->getAttribute(
"autodensity")) {
1850 for (
int i = 0; i < _f->dataHist().numEntries(); i++) {
1851 auto bin_pars = _f->dataHist().get(i);
1852 _f->dataHist().set(*bin_pars, _f->dataHist().weight() / _f->dataHist().binVolume(*bin_pars));
1854 _f->setAttribute(
"autodensity",
false);
1855 _f->setValueDirty();
1864 Info(
"Add",
"Created %s factor RooHistFunc::%s for %s",
1865 _f->getAttribute(
"density") ?
"densityhisto" :
"histo", _f->GetName(),
p->
GetName());
1868 if (
auto _p = std::dynamic_pointer_cast<RooAbsPdf>(out); _p) {
1872 TString newName(_p->GetName());
1874 newName +=
"_components";
1875 Warning(
"Add",
"converting samples to components");
1880 if (
auto _boundaries = std::unique_ptr<std::list<double>>(_p->binBoundaries(
1881 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
1882 std::numeric_limits<double>::infinity()));
1883 !_boundaries && _ax->GetNbins() > 0) {
1884#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
1885 Warning(
"Add",
"Adding unbinned pdf %s to binned %s - will wrap with RooBinSamplingPdf(...)",
1887 _p = acquireNew<RooBinSamplingPdf>(
TString::Format(
"%s_binned", _p->GetName()), _p->GetTitle(),
1889 _p->setStringAttribute(
"alias", std::dynamic_pointer_cast<RooAbsArg>(out)->getStringAttribute(
"alias"));
1890 if (!_p->getStringAttribute(
"alias"))
1891 _p->setStringAttribute(
"alias", out->GetName());
1893 throw std::runtime_error(
1894 "unsupported addition of unbinned pdf to binned model - please upgrade to at least ROOT 6.24");
1901 if (!_p->canBeExtended()) {
1902 _p = acquireNew<RooExtendPdf>(
TString::Format(
"%s_extended", _p->GetName()), _p->GetTitle(), *_p,
1903 *acquire2<RooAbsReal, RooRealVar>(
"1",
"1", 1));
1906 return *(
Replace(*acquireNew<RooAddPdf>(newName, _p->GetTitle(),
RooArgList(*
p, *_p)))
1910 if (
auto _f = std::dynamic_pointer_cast<RooAbsReal>(out); _f) {
1919 if (
auto _boundaries = std::unique_ptr<std::list<double>>(_f->binBoundaries(
1920 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
1921 std::numeric_limits<double>::infinity()));
1922 !_boundaries && _ax->GetNbins() > 0) {
1923#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
1926 "Adding unbinned function %s to binned %s - will wrap with RooRealSumPdf(RooBinSamplingPdf(...))",
1928 auto sumPdf = acquireNew<RooRealSumPdf>(
TString::Format(
"%s_pdfWrapper", _f->GetName()), _f->GetTitle(),
1929 *_f, *acquire2<RooAbsArg, RooRealVar>(
"1",
"1", 1),
true);
1930 sumPdf->setStringAttribute(
"alias", _f->getStringAttribute(
"alias"));
1931 if (!sumPdf->getStringAttribute(
"alias"))
1932 sumPdf->setStringAttribute(
"alias", out->GetName());
1933 _f = acquireNew<RooBinSamplingPdf>(
TString::Format(
"%s_binned", _f->GetName()), _f->GetTitle(),
1935 _f->setStringAttribute(
"alias", std::dynamic_pointer_cast<RooAbsArg>(out)->getStringAttribute(
"alias"));
1936 if (!_f->getStringAttribute(
"alias"))
1937 _f->setStringAttribute(
"alias", out->GetName());
1939 throw std::runtime_error(
1940 "unsupported addition of unbinned function to binned model - please upgrade to at least ROOT 6.24");
1945 const_cast<RooArgList &
>(
p->coefList()).add(*acquire2<RooAbsArg, RooRealVar>(
"1",
"1", 1));
1948 if (!
p->getStringAttribute(
"binning"))
1949 p->setStringAttribute(
"binning", _f->getStringAttribute(
"binning"));
1952 if (
auto gf =
p->getStringAttribute(
"global_factors"); gf) {
1955 auto fac = getObject<RooAbsReal>(pattern.
Data());
1957 throw std::runtime_error(
TString::Format(
"Could not find global factor %s", pattern.
Data()));
1966 p->setStringAttribute(
"xvar",
nullptr);
1970 }
else if (
auto p2 = get<RooProdPdf>(); p2) {
1977 bool tooMany(
false);
1990 }
else if (!tooMany) {
1991 auto out = this->
operator[](
"components")->Add(child);
1995 (!
child.get() && getObject<RooAbsReal>(
child.GetName()))) &&
1999 bool tooMany(
false);
2008 }
else if (
auto _p2 =
pp->get<
RooAddPdf>(); _p2) {
2010 for (
auto &_pdfa :
pp->components()) {
2024 }
else if (_backup) {
2027 }
else if (!tooMany) {
2028 auto out = this->
operator[](
"samples")->Add(child);
2031 p2->setStringAttribute(
"xvar",
nullptr);
2035 }
else if (
auto s = get<RooSimultaneous>(); s) {
2043 }
else if (
auto w = get<RooWorkspace>();
w) {
2044 child.convertForAcquisition(*
this);
2048 if (!
w->import(*_d)) {
2051 throw std::runtime_error(
TString::Format(
"Could not import dataset %s into workspace %s",
child.GetName(),
w->GetName()).
Data());
2060 if (!
child.empty() ||
child.fFolder ==
"!models") {
2063 std::string catName =
"channelCat";
2064 if (!
child.empty()) {
2065 if (
TString ss =
child.at(0)->GetName(); ss.Contains(
"=")) {
2066 catName = ss(0, ss.Index(
'='));
2069 auto _cat = acquire<RooCategory>(catName.c_str(), catName.c_str());
2070 _cat->setAttribute(
"obs");
2071 auto out = acquireNew<RooSimultaneous>(
child.GetName(),
child.GetTitle(), *_cat);
2072 Info(
"Add",
"Created model RooSimultaneous::%s in workspace %s", out->GetName(),
w->GetName());
2077 if (sOpt ==
"model") {
2079 if (get<RooWorkspace>()) {
2083 }
else if (sOpt ==
"channel") {
2085 if (get<RooSimultaneous>()) {
2087 }
else if (get<RooWorkspace>()) {
2088 std::shared_ptr<TObject> out;
2089 child.convertForAcquisition(*
this);
2092 else if (!
child.fComp) {
2093 out = acquireNew<RooProdPdf>(
child.GetName(),
2095 Info(
"Add",
"Created channel RooProdPdf::%s in workspace %s", out->GetName(),
get()->
GetName());
2099 }
else if (sOpt ==
"sample" || sOpt ==
"func") {
2100 if (get<RooProdPdf>()) {
2103 return _mainChild.Add(
child, sOpt ==
"func" ?
"func" :
"");
2105 return (*
this)[
"samples"]->Add(
child, sOpt ==
"func" ?
"func" :
"");
2108 }
else if (sOpt ==
"dataset") {
2109 if (get<RooWorkspace>()) {
2111 return (*this).datasets().Add(
child);
2118 if (get<RooSimultaneous>()) {
2122 }
else if (get<RooProduct>() || get<RooProdPdf>()) {
2168 if (
auto a = get<RooAbsArg>()) {
2169 a->setAttribute(
"hidden", set);
2178 auto a = get<RooAbsArg>();
2180 return a->getAttribute(
"hidden");
2187 if (
get() == rhs.
get()) {
2237 if (
auto s = get<RooSimultaneous>(); s) {
2238 auto chans =
bins();
2239 if (!chans.empty()) {
2245 for (
auto &
c : chans) {
2247 cName = cName(cName.
Index(
'=') + 1, cName.
Length());
2250 c->shallowCopy(
name +
"_" +
c->get()->GetName(), std::shared_ptr<xRooNode>(&out, [](
xRooNode *) {}));
2251 pdf->addPdf(*
dynamic_cast<RooAbsPdf *
>(c_copy.get()), cName);
2256 }
else if (
auto p =
dynamic_cast<RooProdPdf *
>(o);
p) {
2258 std::shared_ptr<RooProdPdf> pdf =
2259 std::dynamic_pointer_cast<RooProdPdf>(out.acquire(std::shared_ptr<TObject>(
p->
Clone()),
false,
2264 std::dynamic_pointer_cast<RooAbsArg>(out.acquire(std::shared_ptr<TObject>(
main->Clone()),
false,
true));
2265 std::cout << newMain <<
" " << newMain->GetName() << std::endl;
2280 static std::unique_ptr<cout_redirect> capture;
2281 std::string captureStr;
2282 bool doCapture =
false;
2283 if (!capture &&
gROOT->FromPopUp()) {
2284 capture = std::make_unique<cout_redirect>(captureStr);
2307 if (
get() &&
get() !=
this) {
2309 if (_more || (get<RooAbsArg>() && get<RooAbsArg>()->isFundamental()) || get<RooConstVar>() ||
2310 get<RooAbsData>() || get<RooProduct>() || get<RooFitResult>()) {
2312 auto _snap = std::unique_ptr<RooAbsCollection>(_deps.snapshot());
2315 if (
auto _fr = get<RooFitResult>(); _fr &&
dynamic_cast<RooStringVar *
>(_fr->constPars().
find(
".log"))) {
2316 std::cout <<
"Minimization Logs:" << std::endl;
2317 std::cout << dynamic_cast<RooStringVar *>(_fr->constPars().find(
".log"))->getVal() << std::endl;
2319 _deps.assignValueOnly(*_snap);
2329 if (
auto fv = get<RooFormulaVar>()) {
2331 for (
size_t i = 0; i < fv->dependents().
size(); i++) {
2335 }
else if (
auto gv = get<RooGenericPdf>()) {
2337 for (
size_t i = 0; i < gv->dependents().
size(); i++) {
2345 }
else if (!
get()) {
2346 std::cout << std::endl;
2350 std::vector<std::string> folderNames;
2351 for (
auto &k : *
this) {
2352 if (std::find(folderNames.begin(), folderNames.end(), k->fFolder) == folderNames.end()) {
2353 folderNames.push_back(k->fFolder);
2356 for (
auto &
f : folderNames) {
2360 for (
int j = 0; j <
indent; j++)
2362 std::cout <<
f << std::endl;
2365 for (
auto &k : *
this) {
2366 if (k->fFolder !=
f) {
2370 for (
int j = 0; j < iindent; j++)
2372 std::cout << i++ <<
") " << k->GetName() <<
" : ";
2376 auto _deps = k->coords(
false).argList();
2377 auto _snap = std::unique_ptr<RooAbsCollection>(_deps.snapshot());
2379 k->get()->Print(sOpt);
2380 _deps.assignValueOnly(*_snap);
2383 if (
auto _type = k->GetNodeType(); strlen(_type)) {
2391 for (
size_t j = 0; j < fv->dependents().
size(); j++) {
2397 for (
size_t j = 0; j < gv->dependents().
size(); j++) {
2402 std::cout << k->get()->ClassName() <<
"::" << k->get()->GetName() << _suffix.
Data() << std::endl;
2405 k->Print(sOpt +
TString::Format(
"depth=%dindent=%d", depth - 1, iindent + 1));
2408 std::cout <<
" NULL " << std::endl;
2414 size_t lastBreak = 0;
2415 std::string captureStrWithBreaks;
2416 for (
size_t i = 0; i < captureStr.size(); i++) {
2417 captureStrWithBreaks += captureStr[i];
2418 if (captureStr[i] ==
'\n') {
2421 if (i - lastBreak > 150) {
2422 captureStrWithBreaks +=
'\n';
2427 (
gROOT->GetListOfBrowsers()->At(0))
2431 captureStrWithBreaks.c_str());
2439 if (
auto v = get<RooRealVar>();
v) {
2442 double mean = std::numeric_limits<double>::quiet_NaN();
2443 double sigma = mean;
2452 mean = std::numeric_limits<double>::quiet_NaN();
2455 constrType =
"normal";
2456 }
else if (constrType ==
"normal") {
2459 }
else if (constrType ==
"gaussian") {
2463 throw std::runtime_error(
"No error on parameter for gaussian constraint");
2466 constrType =
"normal";
2467 }
else if (constrType ==
"poisson") {
2469 throw std::runtime_error(
"No error on parameter for poisson constraint");
2471 sigma = pow(
v->getVal() /
v->getError(), 2);
2474 if (constrType ==
"poisson") {
2476 double tau_val =
sigma;
2477 auto globs = acquire<RooRealVar>(
Form(
"globs_%s",
v->GetName()),
Form(
"globs_%s",
v->GetName()),
2478 v->getVal() * tau_val, (
v->getVal() - 5 *
v->getError()) * tau_val,
2479 (
v->getVal() + 5 *
v->getError()) * tau_val);
2480 globs->setConstant();
2481 globs->setAttribute(
"obs");
2482 globs->setAttribute(
"global");
2484 auto tau = acquireNew<RooConstVar>(
TString::Format(
"tau_%s",
v->GetName()),
"", tau_val);
2485 auto constr = acquireNew<RooPoisson>(
2494 v->setError(mean / sqrt(tau_val));
2495 Info(
"Constrain",
"Added poisson constraint pdf RooPoisson::%s (tau=%g) for %s", out->GetName(), tau_val,
2498 }
else if (constrType ==
"normal") {
2500 auto globs = acquire<RooRealVar>(
Form(
"globs_%s",
v->GetName()),
Form(
"globs_%s",
v->GetName()), mean,
2502 globs->setAttribute(
"obs");
2503 globs->setAttribute(
"global");
2504 globs->setConstant();
2507 auto constr = acquireNew<RooGaussian>(
2513 Info(
"Constrain",
"Added gaussian constraint pdf RooGaussian::%s (mean=%g,sigma=%g) for %s", out->GetName(),
2520 auto _me = get<RooAbsArg>();
2522 throw std::runtime_error(
"Cannot constrain non arg");
2525 if (!
p->dependsOn(*_me)) {
2526 throw std::runtime_error(
"Constraint does not depend on constrainee");
2535 throw std::runtime_error(
"Nowhere to put constraint");
2541 for (
auto &
c : *
x) {
2547 return x->Multiply(
child);
2549 return x->Add(
child,
"+");
2562 ~AutoUpdater() {
n.browse(); }
2565 AutoUpdater xxx(*
this);
2572 auto o = std::dynamic_pointer_cast<RooAbsReal>(
acquire(
child.fComp));
2595 ?
fParent->mainChild()->GetName()
2600 binFactors =
fParent->factors().find(
"binFactors");
2602 throw std::runtime_error(
2609 for (
auto &
b : binFactors->bins()) {
2610 auto p = acquireNew<RooProduct>(
TString::Format(
"%s_bin%d", binFactors->get()->GetName(), i),
2612 p->setStringAttribute(
"alias",
TString::Format(
"%s=%g", binFactors->GetXaxis()->GetParent()->GetName(),
2613 binFactors->GetXaxis()->GetBinCenter(i)));
2620 auto _bin = binFactors->bins().at(
fBinNumber - 1);
2621 if (
auto phf = binFactors->get<
ParamHistFunc>(); phf && _bin) {
2622#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2627 if (strcmp(_bin->GetName(),
"1") == 0) {
2629 for (
int i = 0; i < pSet.
getSize(); i++) {
2631 all.
add(*pSet.
at(i));
2638 _bin->fBinNumber = -1;
2639 return _bin->Multiply(
child, opt);
2667 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(
child), [](
TObject *) {}));
2672 std::rethrow_exception(std::current_exception());
2680 if (
auto o = getObject<RooAbsReal>(
child.GetName())) {
2684 Info(
"Multiply",
"Scaled %s by existing factor %s::%s",
2687 }
else if (sOpt ==
"norm") {
2694 Info(
"Multiply",
"Scaled %s by new norm factor %s",
2698 throw std::runtime_error(
TString::Format(
"Failed to create new normFactor %s",
child.GetName()));
2702 Info(
"Multiply",
"Scaled %s by new norm factor %s",
2705 }
else if (sOpt ==
"shape" || sOpt ==
"histo" || sOpt ==
"blankshape") {
2710 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
2711 h->SetBinContent(i, 1);
2716 h->SetTitle(
child.GetTitle());
2721 Info(
"Multiply",
"Scaled %s by new %s factor %s",
2725 }
else if (sOpt ==
"overall") {
2726 auto out =
Multiply(acquireNew<RooStats::HistFactory::FlexibleInterpVar>(
2727 child.GetName(),
child.GetTitle(),
RooArgList(), 1, std::vector<double>(), std::vector<double>()));
2729 Info(
"Multiply",
"Scaled %s by new overall factor %s",
2732 }
else if (sOpt ==
"func" &&
ws()) {
2737 Info(
"Multiply",
"Scaled %s by new func factor %s",
2743 if (
auto h =
child.get<
TH1>();
h && strlen(
h->GetOption()) == 0 && strlen(opt) > 0) {
2747 if (
auto w = get<RooWorkspace>();
w) {
2749 std::shared_ptr<TObject> out;
2750 child.convertForAcquisition(*
this);
2756 if (strcmp(
GetName(),
".coef") == 0) {
2759 for (
size_t i = 0; i <
p->pdfList().size(); i++) {
2761 auto coefs =
p->coefList().at(i);
2770 for (
size_t j = 0; j <
p->coefList().size(); j++) {
2772 oldCoefs.
add(*newCoefs);
2774 oldCoefs.add(*
p->coefList().at(j));
2776 const_cast<RooArgList &
>(
p->coefList()).removeAll();
2777 const_cast<RooArgList &
>(
p->coefList()).add(oldCoefs);
2784 throw std::runtime_error(
"this coefs case is not supported");
2787 if (
auto p = get<RooProduct>();
p) {
2788 std::shared_ptr<TObject> out;
2789 auto cc =
child.fComp;
2790 bool isConverted = (
child.convertForAcquisition(*
this) != cc);
2795 if (
auto _f = std::dynamic_pointer_cast<RooHistFunc>(
2797 _f && _f->getAttribute(
"autodensity")) {
2799 bool hasDensity =
false;
2807 if (_f->getAttribute(
"density")) {
2810 for (
int i = 0; i < _f->dataHist().numEntries(); i++) {
2811 auto bin_pars = _f->dataHist().get(i);
2812 _f->dataHist().set(*bin_pars, _f->dataHist().weight() / _f->dataHist().binVolume(*bin_pars));
2814 _f->setValueDirty();
2821 _f->setAttribute(
"autodensity",
false);
2825 Info(
"Multiply",
"Created %s factor %s in %s",
2829 Info(
"Multiply",
"Created shape factor %s in %s",
child->GetName(),
p->
GetName());
2832 if (
auto _f = std::dynamic_pointer_cast<RooAbsReal>(out); _f) {
2833#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2834 p->_compRSet.add(*_f);
2836 const_cast<RooArgList &
>(
p->realComponents()).add(*_f);
2842 for (
auto &_par : _out.
pars()) {
2845 for (
auto &_constr : _par->constraints()) {
2846 if (strcmp(s, _constr->get()->GetName()) == 0) {
2853 Info(
"Multiply",
"Pulling in %s boundConstraint: %s", _par->GetName(), s);
2854 auto _pdf = getObject<RooAbsPdf>(s);
2856 throw std::runtime_error(
"Couldn't find boundConstraint");
2858 _par->Constrain(_pdf);
2865 }
else if (
auto p2 = get<RooProdPdf>(); p2) {
2867 std::shared_ptr<TObject> out;
2868 child.convertForAcquisition(*
this);
2877 std::shared_ptr<RooAbsPdf> _pdf;
2878 if (!
child.get() && strcmp(
child.GetName(),
"components") == 0) {
2879 auto _sumpdf = acquireNew<RooAddPdf>(
Form(
"%s_%s", p2->GetName(),
child.GetName()),
2880 (strlen(
child.GetTitle()) && strcmp(
child.GetTitle(),
child.GetName()))
2886 auto _sumpdf = acquireNew<RooRealSumPdf>(
2887 Form(
"%s_%s", p2->GetName(),
child.GetName()),
2891 _sumpdf->setFloor(
true);
2894 _pdf->setStringAttribute(
"alias",
child.GetName());
2896 _pdf->setStringAttribute(
"xvar", p2->getStringAttribute(
"xvar"));
2897 _pdf->setStringAttribute(
"binning", p2->getStringAttribute(
"binning"));
2899 Info(
"Multiply",
"Created %s::%s in channel %s", _pdf->ClassName(), _pdf->GetName(), p2->GetName());
2904 if (
auto _pdf = std::dynamic_pointer_cast<RooAbsPdf>(out); _pdf) {
2905#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2906 const_cast<RooArgList &
>(p2->pdfList()).add(*_pdf);
2907#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
2908 p2->_pdfNSetList.emplace_back(std::make_unique<RooArgSet>(
"nset"));
2912 if (!p2->canBeExtended() && _pdf->canBeExtended()) {
2913 p2->_extendedIndex = p2->_pdfList.size() - 1;
2922 }
else if (
auto p3 = get<RooRealSumPdf>(); p3) {
2924 std::shared_ptr<TObject> out;
2925 child.convertForAcquisition(*
this);
2931 TString s = p3->getStringAttribute(
"global_factors");
2934 s += out->GetName();
2935 p3->setStringAttribute(
"global_factors", s);
2938 "Flagged %s as a global factor in channel %s (is applied to all current and future samples in the channel)",
2939 out->GetName(), p3->GetName());
2950 std::set<RooAbsArg *> cl;
2951 for (
auto &arg : p5->clients()) {
2957 if (cl.size() > 1) {
2962 Warning(
"Multiply",
"Scaling %s that has multiple clients", p5->GetName());
2968 for (
auto &
a : p5->attributes())
2969 new_p->setAttribute(
a.c_str());
2970 for (
auto &
a : p5->stringAttributes())
2971 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
2972 if (!new_p->getStringAttribute(
"alias"))
2973 new_p->setStringAttribute(
"alias", p5->GetName());
2975 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
2976 for (
auto arg : cl) {
2977 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
2985 if (!
child.get() && strlen(opt) == 0)
2988 throw std::runtime_error(
2990 (!
child.get() && strlen(opt) == 0) ?
" (forgot to specify factor type?)" :
""));
2996 auto p5 = get<RooAbsArg>();
2998 throw std::runtime_error(
"Only replacement of RooAbsArg is supported");
3007 new_p = std::dynamic_pointer_cast<RooAbsArg>(out).get();
3009 std::set<RooAbsArg *> cl;
3010 for (
auto &arg : p5->clients()) {
3018 if (cl.size() > 1) {
3023 std::stringstream clientList;
3025 clientList <<
c->GetName() <<
",";
3026 Warning(
"Replace",
"Replacing %s in all clients: %s", p5->GetName(), clientList.str().c_str());
3030 new_p->setAttribute(
Form(
"ORIGNAME:%s", p5->GetName()));
3031 for (
auto arg : cl) {
3036 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
3047 ~AutoUpdater() {
n.browse(); }
3050 AutoUpdater xxx(*
this);
3055 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(
child), [](
TObject *) {}));
3060 std::rethrow_exception(std::current_exception());
3072 std::string label =
child.GetName();
3073 if (
auto pos = label.find(
"="); pos != std::string::npos)
3074 label = label.substr(pos + 1);
3075 if (!s->indexCat().hasLabel(label)) {
3078 std::shared_ptr<TObject> out;
3079 child.convertForAcquisition(*
this);
3082 else if (!
child.fComp) {
3083 out = acquireNew<RooProdPdf>(
TString::Format(
"%s_%s", s->GetName(), label.c_str()),
3085 Info(
"Vary",
"Created channel RooProdPdf::%s in model %s", out->GetName(), s->GetName());
3088 if (
auto _pdf = std::dynamic_pointer_cast<RooAbsPdf>(out); _pdf) {
3089 s->addPdf(*_pdf, label.c_str());
3098 }
else if (
auto p = get<RooStats::HistFactory::FlexibleInterpVar>();
p) {
3101 child.convertForAcquisition(*
this);
3103 if (!_c &&
child.get()) {
3104 throw std::runtime_error(
"Only pure consts can be set as variations of a flexible interpvar");
3106#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3107 double value = (_c ? _c->getVal() :
p->_nominal);
3108 double nomVal =
p->_nominal;
3110 double value = (_c ? _c->getVal() :
p->nominal());
3111 double nomVal =
p->nominal();
3115 if (cName ==
"nominal") {
3120 throw std::runtime_error(
"unsupported variation form");
3122 std::string parName = cName(0, cName.
Index(
'='));
3124 if (parVal != 1 && parVal != -1) {
3125 throw std::runtime_error(
"unsupported variation magnitude");
3127 bool high = parVal > 0;
3129 if (parName.empty()) {
3138 if (!
p->findServer(*
v)) {
3139#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3140 p->_paramList.add(*
v);
3141 p->_low.push_back(0);
3142 p->_high.push_back(0);
3143 p->_interpCode.push_back(4);
3146 const_cast<std::vector<double> &
>(
p->low()).push_back(0);
3147 const_cast<std::vector<double> &
>(
p->high()).push_back(0);
3148 const_cast<std::vector<int> &
>(
p->interpolationCodes()).push_back(4);
3150 v->setAttribute(
Form(
"SYMMETRIC%s_%s", high ?
"+" :
"-",
GetName()));
3155 if (
v->getAttribute(
Form(
"SYMMETRIC+_%s",
GetName()))) {
3156 p->setLow(*
v, 2 * nomVal -
value);
3158 v->setAttribute(
Form(
"SYMMETRIC-_%s",
GetName()),
false);
3161 if (
v->getAttribute(
Form(
"SYMMETRIC-_%s",
GetName()))) {
3162 p->setHigh(*
v, 2 * nomVal -
value);
3164 v->setAttribute(
Form(
"SYMMETRIC+_%s",
GetName()),
false);
3172 }
else if (
auto p2 = get<PiecewiseInterpolation>(); p2) {
3175 throw std::runtime_error(
"unsupported variation form");
3179 if (parVal != 1 && parVal != -1) {
3180 throw std::runtime_error(
"unsupported variation magnitude");
3182#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3185 throw std::runtime_error(
3186 TString::Format(
"Interpolating %s instead of RooHistFunc", p2->_nominal.absArg()->ClassName()));
3191 throw std::runtime_error(
3192 TString::Format(
"Interpolating %s instead of RooHistFunc", p2->nominalHist()->ClassName()));
3198 for (
auto par : p2->paramList()) {
3199 if (parName == par->GetName()) {
3200 f =
dynamic_cast<RooHistFunc *
>((parVal > 0 ? p2->highList() : p2->lowList()).
at(i));
3201 otherf =
dynamic_cast<RooHistFunc *
>((parVal > 0 ? p2->lowList() : p2->highList()).
at(i));
3209 auto v = acquire<RooRealVar>(parName, parName, -5, 5);
3213 std::shared_ptr<RooHistFunc> up(
3215 std::shared_ptr<RooHistFunc> down(
3218#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3219 std::unique_ptr<RooDataHist>
h1(
3220 static_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", up->GetName()))));
3221 std::unique_ptr<RooDataHist> h2(
3222 static_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", down->GetName()))));
3223 up->_dataHist =
dynamic_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", up->GetName())));
3224 down->_dataHist =
dynamic_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", down->GetName())));
3227 down->cloneAndOwnDataHist(
TString::Format(
"hist_%s", down->GetName()));
3229 auto ups = std::dynamic_pointer_cast<RooHistFunc>(
acquire(up,
false,
true));
3230 auto downs = std::dynamic_pointer_cast<RooHistFunc>(
acquire(down,
false,
true));
3231#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3232 p2->_highSet.add(*ups.get());
3233 p2->_lowSet.add(*downs.get());
3234 p2->_interpCode.push_back(4);
3235 p2->_paramSet.add(*
v);
3237 const_cast<RooArgList &
>(p2->highList()).add(*ups.get());
3238 const_cast<RooArgList &
>(p2->lowList()).add(*downs.get());
3239 const_cast<std::vector<int> &
>(p2->interpolationCodes()).push_back(4);
3240 const_cast<RooArgList &
>(p2->paramList()).add(*
v);
3242 p2->setValueDirty();
3243 f = ((parVal > 0) ? ups : downs).
get();
3244 otherf = ((parVal > 0) ? downs : ups).
get();
3246 f->setStringAttribute(
"symmetrizes", otherf->
GetName());
3247 f->setStringAttribute(
"symmetrize_nominal", nomf->
GetName());
3266 }
else if (
auto p3 = get<RooConstVar>(); p3) {
3269 if (p3->getAttribute(
"RooRealConstant_Factory_Object")) {
3270 throw std::runtime_error(
"Cannot vary pure constants");
3276 std::set<RooAbsArg *> cl;
3277 for (
auto &arg : p3->clients()) {
3282 if (cl.size() > 1) {
3287 Warning(
"Vary",
"Varying %s that has multiple clients", p3->GetName());
3290 p3->setStringAttribute(
"origName", p3->GetName());
3292 p3->SetName(
Form(
"%s_nominal", p3->GetName()));
3294 auto new_p = acquireNew<RooStats::HistFactory::FlexibleInterpVar>(
n, p3->GetTitle(),
RooArgList(), p3->getVal(),
3295 std::vector<double>(), std::vector<double>());
3298 for (
auto &
a : p3->attributes())
3299 new_p->setAttribute(
a.c_str());
3300 for (
auto &
a : p3->stringAttributes())
3301 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
3304 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
3305 for (
auto arg : cl) {
3306 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
3312 }
else if (
auto p4 = get<RooAbsReal>(); p4) {
3316 std::set<RooAbsArg *> cl;
3317 for (
auto &arg : p4->clients()) {
3322 if (cl.size() > 1) {
3327 Warning(
"Vary",
"Varying %s that has multiple clients", p4->GetName());
3330 p4->setStringAttribute(
"origName", p4->GetName());
3332 p4->SetName(
Form(
"%s_nominal", p4->GetName()));
3337 for (
auto &
a : p4->attributes())
3338 new_p->setAttribute(
a.c_str());
3339 for (
auto &
a : p4->stringAttributes())
3340 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
3343 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
3344 for (
auto arg : cl) {
3345 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
3386 if (
auto a = get<RooAbsArg>();
a && strcmp(
a->GetName(),
GetName()) && !
a->getStringAttribute(
"alias")) {
3387 a->setStringAttribute(
"alias",
GetName());
3390 throw std::runtime_error(
"Cannot determine type");
3395 if (
auto h =
dynamic_cast<const TH1 *
>(&o);
h) {
3406 bool _isData = get<RooAbsData>();
3412 throw std::runtime_error(
"no xaxis");
3413 auto _v =
dynamic_cast<RooRealVar *
>(ax->GetParent());
3416 _b.
b =
dynamic_cast<RooAbsBinning *
>(_v->getBinningPtr(0)->Clone());
3417 if (
h->GetXaxis()->IsVariableBinSize()) {
3418 _v->setBinning(
RooBinning(
h->GetNbinsX(),
h->GetXaxis()->GetXbins()->GetArray()));
3420 _v->setBinning(
RooUniformBinning(
h->GetXaxis()->GetXmin(),
h->GetXaxis()->GetXmax(),
h->GetNbinsX()));
3426 for (
int bin = 1; bin <=
h->GetNbinsX(); bin++) {
3434 if (!_isData &&
h->GetSumw2N() && !
SetBinError(bin,
h->GetBinError(bin)))
3435 throw std::runtime_error(
"Failed setting stat error");
3439 }
else if (
auto _c =
dynamic_cast<const RooConstVar *
>(&o); _c) {
3441 if (
auto a = get<RooAbsArg>();
3442 (
a &&
a->isFundamental()) || get<RooConstVar>() || get<RooStats::HistFactory::FlexibleInterpVar>()) {
3445 }
else if (get<RooAbsData>()) {
3451 throw std::runtime_error(
"Assignment failed");
3478 auto _pars =
pars();
3482 auto idx = pattern.
Index(
'=');
3485 (idx == -1) ? std::numeric_limits<double>::quiet_NaN() :
TString(pattern(idx + 1, pattern.
Length())).
Atof();
3486 for (
auto p : _pars.argList()) {
3488 p->setAttribute(
"Constant",
true);
3489 if (!std::isnan(val)) {
3498 for (
auto &
d : _dsets) {
3499 if (
d->get()->TestBit(1 << 20)) {
3500 dsetName =
d->get()->GetName();
3504 auto _nll =
nll(dsetName.
Data());
3505 _nll.fitConfigOptions()->SetValue(
"LogSize", 65536);
3506 _nll.fitConfig()->MinimizerOptions().SetPrintLevel(0);
3507 auto fr = _nll.minimize();
3510 throw std::runtime_error(
"Fit Failed");
3513 for (
unsigned int i = 0; i < fr->numStatusHistory(); i++) {
3514 statusCodes +=
TString::Format(
"\n%s = %d", fr->statusLabelHistory(i), fr->statusCodeHistory(i));
3517 (
gROOT->GetListOfBrowsers()->At(0))
3520 if (fr->status() != 0) {
3522 TString::Format(
"%s\nData = %s\nFit Status Code = %d\nCov Quality = %d\n-------------%s",
3523 fr->GetName(), dsetName.
Data(), fr->status(), fr->covQual(), statusCodes.
Data()),
3525 }
else if (fr->covQual() != 3 && _nll.fitConfig()->ParabErrors()) {
3526 new TGMsgBox(
gClient->GetRoot(),
w,
"Fit Finished with Bad Covariance Quality",
3527 TString::Format(
"%s\nData = %s\nFit Status Code = %d\nCov Quality = %d\n-------------%s",
3528 fr->GetName(), dsetName.
Data(), fr->status(), fr->covQual(), statusCodes.
Data()),
3532 TString::Format(
"%s\nData = %s\nFit Status Code = %d\nCov Quality = %d\n-------------%s",
3533 fr->GetName(), dsetName.
Data(), fr->status(), fr->covQual(), statusCodes.
Data()));
3535 }
catch (
const std::exception &
e) {
3538 (
gROOT->GetListOfBrowsers()->At(0))
3548 datasets().
Add(datasetName, expected ?
"asimov" :
"toy");
3549 }
catch (
const std::exception &
e) {
3552 (
gROOT->GetListOfBrowsers()->At(0))
3555 "Exception",
e.what(),
3561 double highX ,
const char *constParValues)
3570 for (
auto &
d : _dsets) {
3571 if (
d->get()->TestBit(1 << 20)) {
3572 dsetName =
d->get()->GetName();
3576 auto _pars =
pars();
3577 std::unique_ptr<RooAbsCollection> snap(_pars.argList().snapshot());
3580 auto idx = pattern.
Index(
'=');
3583 (idx == -1) ? std::numeric_limits<double>::quiet_NaN() :
TString(pattern(idx + 1, pattern.
Length())).
Atof();
3584 for (
auto par : _pars.argList()) {
3586 par->setAttribute(
"Constant",
true);
3587 if (!std::isnan(val)) {
3600 hs.SetTitle(sWhat +
" scan" + ((dsetName !=
"") ?
TString::Format(
" [data=%s]", dsetName.
Data()) :
""));
3601 int scanStatus = hs.scan(sWhat +
" visualize", nBinsX, lowX, highX);
3602 if (scanStatus != 0) {
3605 (
gROOT->GetListOfBrowsers()->At(0))
3608 "Scan Finished with Bad Status Code",
3609 TString::Format(
"%s\nData = %s\nScan Status Code = %d", hs.GetName(), dsetName.
Data(), scanStatus),
3614 if (
auto res = hs.result())
3618 _pars.argList() = *snap;
3620 }
catch (
const std::exception &
e) {
3623 (
gROOT->GetListOfBrowsers()->At(0))
3634 }
catch (
const std::exception &
e) {
3644 throw std::runtime_error(
"Failed to SetContent");
3645 }
catch (
const std::exception &
e) {
3659 std::shared_ptr<TH1D>
h;
3660 auto _b =
dynamic_cast<Axis2 *
>(ax)->binning();
3663 if (_b->isUniform()) {
3670 h->GetXaxis()->SetName(
TString::Format(
"%s;%s", ax->GetParent()->GetName(), ax->GetName()));
3678 if (get<RooProduct>()) {
3682 if (get<RooAbsData>()) {
3683 if (
auto _data = get<RooDataSet>(); _data) {
3684 auto _ax = (bin) ?
GetXaxis() :
nullptr;
3686 throw std::runtime_error(
"Cannot determine binning to fill data");
3688 if (_ax && _ax->GetNbins() < bin)
3689 throw std::out_of_range(
TString::Format(
"%s range %s only has %d bins", _ax->GetParent()->GetName(),
3690 _ax->GetName(), _ax->GetNbins()));
3695 for (
auto _c :
coords()) {
3699 cut +=
TString::Format(
"%s==%d", _cat->GetName(), _cat->getCurrentIndex());
3706 TString::Format(
"%s>=%f&&%s<%f", _rv->GetName(), _rv->getMin(_rv->getStringAttribute(
"coordRange")),
3707 _rv->GetName(), _rv->getMax(_rv->getStringAttribute(
"coordRange")));
3710 throw std::runtime_error(
"SetBinContent of data: Unsupported coordinate type");
3719 cut2 =
TString::Format(
"%s >= %f && %s < %f", _ax->GetParent()->GetName(), _ax->GetBinLowEdge(bin),
3720 _ax->GetParent()->GetName(), _ax->GetBinUpEdge(bin));
3752 l.remove(*_data->get(),
true,
true);
3757 _data->addColumn(*
x);
3767 for (
auto &o :
obs) {
3769 if (
auto dv =
dynamic_cast<RooRealVar *
>(_data->get()->find(
v->GetName())); dv) {
3770 if (
v->getMin() < dv->getMin())
3771 dv->setMin(
v->getMin());
3772 if (
v->getMax() > dv->getMax())
3773 dv->setMax(
v->getMax());
3776 if (
auto dc =
dynamic_cast<RooCategory *
>(_data->get()->find(
c->GetName())); dc) {
3777 if (!dc->hasLabel(
c->getCurrentLabel())) {
3778 dc->defineType(
c->getCurrentLabel(),
c->getCurrentIndex());
3787 if (
auto _nentries = std::unique_ptr<RooAbsData>(_data->reduce(cutFormula))->numEntries();
3788 _nentries != _ax->GetNbins()) {
3791 if (_nentries > 0) {
3792 Info(
"SetBinContent",
"Binning %s in channel: %s",
GetName(), cut.
Data());
3793 auto _reduced = std::unique_ptr<RooAbsData>(_data->reduce(icutFormula));
3795 for (
int j = 0; j < _reduced->numEntries(); j++) {
3796 auto _obs = _reduced->get(j);
3797 _data->add(*_obs, _reduced->weight());
3800 for (
int i = 1; i <= _ax->GetNbins(); i++) {
3804 dynamic_cast<RooAbsLValue *
>(_ax->GetParent())->setBin(i - 1, _ax->GetName());
3805 _data->add(
obs, _contents.
at(i - 1));
3810 if (std::unique_ptr<RooAbsData>(_data->reduce(cutFormula2))->numEntries() > 0) {
3811 auto _reduced = std::unique_ptr<RooAbsData>(_data->reduce(icutFormula2));
3813 for (
int j = 0; j < _reduced->numEntries(); j++) {
3814 auto _obs = _reduced->get(j);
3815 _data->add(*_obs, _reduced->weight());
3819 dynamic_cast<RooAbsLValue *
>(_ax->GetParent())->setBin(bin - 1, _ax->GetName());
3822 return bb->SetBinContent(bin,
value, par, parVal);
3825 }
else if (get<RooDataHist>()) {
3826 throw std::runtime_error(
"RooDataHist not supported yet");
3830 if (
auto _varies =
variations(); !_varies.empty() || (par && strlen(par))) {
3831 if (!par || strlen(par) == 0) {
3832 return _varies[
"nominal"]->SetBinContent(bin,
value, par, parVal);
3833 }
else if (
auto it = _varies.find(
Form(
"%s=%g", par, parVal)); it) {
3834 return it->SetBinContent(bin,
value);
3846 if (!par || strlen(par) == 0) {
3859 if (strcmp(
c->GetName(),
Form(
"%g",
c->getVal())) == 0) {
3862#if ROOT_VERSION_CODE < ROOT_VERSION(6, 24, 00)
3875 auto bin_pars =
f->dataHist().get(bin - 1);
3876 if (
f->getAttribute(
"density")) {
3877 value /=
f->dataHist().binVolume(*bin_pars);
3879 f->dataHist().set(*bin_pars,
value);
3882 if (
auto otherfName =
f->getStringAttribute(
"symmetrized_by"); otherfName) {
3884 f->setStringAttribute(
"symmetrized_by",
nullptr);
3885 if (
auto x = getObject<RooAbsArg>(otherfName);
x) {
3886 x->setStringAttribute(
"symmetrizes",
nullptr);
3887 x->setStringAttribute(
"symmetrize_nominal",
nullptr);
3889 }
else if (
auto otherfName2 =
f->getStringAttribute(
"symmetrizes"); otherfName2) {
3890 auto nomf = getObject<RooHistFunc>(
f->getStringAttribute(
"symmetrize_nominal"));
3891 auto otherf = getObject<RooHistFunc>(otherfName2);
3892 if (nomf && otherf) {
3893 otherf->dataHist().set(*bin_pars, 2 * nomf->dataHist().weight(bin - 1) -
value);
3894 otherf->setValueDirty();
3901 f2->setNominal(
value);
3913 return datasets()[dataName]->SetContents(obj);
3920 if (get<RooProduct>()) {
3924 if (
auto _varies =
variations(); !_varies.empty()) {
3925 return _varies[
"nominal"]->SetBinError(bin,
value);
3940 while (_prodParent && !_prodParent->get<
RooProduct>() && !_prodParent->get<
RooAbsPdf>()) {
3942 _prodParent.reset();
3945 _prodParent = _prodParent->fParent;
3948 (_prodParent && !_prodParent->get<
RooAbsPdf>()) ? _prodParent->factors().find(
"statFactor") :
nullptr;
3949 auto f_stat = (_f_stat) ? _f_stat->get<
ParamHistFunc>() :
nullptr;
3950 if (_f_stat && _f_stat->get() && !f_stat) {
3951 throw std::runtime_error(
"stat factor must be a paramhistfunc");
3960 for (
auto &
p :
xRooNode(
"tmp", *
f, std::shared_ptr<xRooNode>(
nullptr)).
vars()) {
3965 auto h = std::unique_ptr<TH1>(
f->dataHist().createHistogram(parNames
3972 h->SetName(
"statFactor");
3974 h->SetOption(
"blankshape");
3977 auto toMultiply =
this;
3981 f_stat =
dynamic_cast<ParamHistFunc *
>(toMultiply->Multiply(*h).get());
3983 throw std::runtime_error(
"Failed creating stat shapeFactor");
3989 TString prefix =
f->getStringAttribute(
"statPrefix");
3990 if (
value && prefix ==
"") {
3994 while (_p && !(_p->get()->InheritsFrom(
"RooRealSumPdf") || _p->get()->InheritsFrom(
"RooAddPdf") ||
3995 _p->get()->InheritsFrom(
"RooWorkspace") || _p->get()->InheritsFrom(
"RooAddition"))) {
4000 auto newVar = (
value == 0) ? getObject<RooRealVar>(
"1")
4001 : acquire<RooRealVar>(
Form(
"%s_bin%d", prefix.
Data(), bin),
4002 Form(
"%s_bin%d", prefix.
Data(), bin), 1);
4003#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
4008 auto var =
dynamic_cast<RooRealVar *
>(&pSet[bin - 1]);
4010 if (newVar.get() != var) {
4014 for (
int i = 0; i < pSet.
getSize(); i++) {
4016 all.
add(*pSet.
at(i));
4027 if (strcmp(rrv->GetName(),
"1") != 0) {
4028 TString origName = (
f->getStringAttribute(
"origName")) ?
f->getStringAttribute(
"origName") :
GetName();
4030 auto bin_pars =
f->dataHist().get(bin - 1);
4031 auto _binContent =
f->dataHist().weight();
4032 if (
f->getAttribute(
"density")) {
4033 _binContent *=
f->dataHist().binVolume(*bin_pars);
4038 for (
auto &[s, sv] : rrv->stringAttributes()) {
4039 if (s.find(
"sumw_") == 0) {
4041 }
else if (s.find(
"sumw2_") == 0) {
4045 if (sumw2 && sumw2 != std::numeric_limits<double>::infinity()) {
4046 double tau = pow(sumw, 2) / sumw2;
4047 rrv->setError((tau < 1
e-15) ? 1e15 : ( 1. / sqrt(tau)));
4048 rrv->setConstant(
false);
4050 auto _constr =
v.constraints();
4052 if (_constr.empty()) {
4053 rrv->setStringAttribute(
"boundConstraint", _constr.Add(
"poisson").get()->GetName());
4055 auto _glob = _constr.at(0)->obs().at(0)->get<
RooRealVar>();
4058 double _min = tau * (1. - 5. * sqrt(1. / tau));
4059 double _max = tau * (1. + 5. * sqrt(1. / tau));
4060 _glob->setRange(_min, _max);
4062 _constr.at(0)->pp().at(0)->SetBinContent(0, tau);
4063 rrv->setStringAttribute(
"boundConstraint", _constr.at(0)->get()->GetName());
4065 rrv->setRange(std::max((1. - 5. * sqrt(1. / tau)), 1
e-15), 1. + 5. * sqrt(1. / tau));
4068 if (
auto _constr =
v.constraints(); !_constr.empty()) {
4069 v.constraints().Remove(*_constr.at(0));
4074 rrv->setConstant(sumw2 == 0);
4086 auto res =
find(
name, browseResult);
4088 throw std::out_of_range(
name +
" does not exist");
4097 if (
auto _w = get<RooWorkspace>(); _w)
4099 if (
auto a = get<RooAbsArg>();
a &&
GETWS(
a)) {
4110 xRooNode out(
".constraints",
nullptr, *
this);
4113 getConstraint = [&](
const xRooNode &
n,
RooAbsArg &par, std::set<RooAbsPdf *> ignore) {
4115 if (ignore.count(_pdf))
4117 ignore.insert(_pdf);
4123 for (
auto &
c :
n.bins()) {
4124 if (
auto oo = getConstraint(*
c.get(), par, ignore); oo) {
4134 for (
auto p : _ws->allPdfs()) {
4135 if (ignore.count(
static_cast<RooAbsPdf *
>(
p)))
4137 if (
p->dependsOn(par)) {
4138 out.emplace_back(std::make_shared<xRooNode>(par.GetName(), *
p, *
this));
4144 return getConstraint(*
n.fParent.get(), par, ignore);
4146 for (
auto p : o->pdfList()) {
4147 if (ignore.count(
static_cast<RooAbsPdf *
>(
p)))
4149 if (
p->dependsOn(par)) {
4150 out.emplace_back(std::make_shared<xRooNode>(par.GetName(), *
p, *
this));
4156 for (
auto &
p :
vars()) {
4160 if (
v->getAttribute(
"Constant") &&
v != get<RooAbsReal>())
4162 if (
v->getAttribute(
"obs"))
4164 getConstraint(*
this, *
v, {get<RooAbsPdf>()});
4172 auto it = out.std::vector<std::shared_ptr<xRooNode>>
::begin();
4173 while (it != out.std::vector<std::shared_ptr<xRooNode>>
::end()) {
4174 bool removeIt =
false;
4175 for (
auto &
c : out) {
4176 if (
c.get() == it->get())
4180 std::set<std::string> parNames;
4181 std::string _cName =
c->GetName();
4183 parNames.insert(_cName.substr(0, _cName.find(
';')));
4184 _cName = _cName.substr(_cName.find(
';') + 1);
4185 }
while (_cName.find(
';') != std::string::npos);
4186 parNames.insert(_cName);
4187 _cName = it->get()->GetName();
4189 parNames.insert(_cName.substr(0, _cName.find(
';')));
4190 _cName = _cName.substr(_cName.find(
';') + 1);
4191 }
while (_cName.find(
';') != std::string::npos);
4192 parNames.insert(_cName);
4194 for (
auto &
x : parNames) {
4195 if (!_cName.empty())
4199 c->TNamed::SetName(_cName.c_str());
4211 if (get<RooAbsArg>() && get<RooAbsArg>()->isFundamental()) {
4212 for (
auto &o : out) {
4213 o->TNamed::SetName(o->get()->GetName());
4227 sName =
TString(
"factory:") + sName;
4231 if (
auto h = get<TH1>();
h) {
4233 std::map<std::string, std::string> stringAttrs;
4235 auto pos = sOpt2.
Index(
"=");
4236 auto start = sOpt2.
Index(
";") + 1;
4242 stringAttrs[sOpt2(start, pos - start)] = sOpt2(pos + 1,
end - pos - 1);
4248 origName = origName(1, origName.
Length());
4251 newObjName(1, newObjName.
Length());
4257 TString varName =
h->GetXaxis()->GetName();
4258 std::string binningName = newObjName.
Data();
4259 if (
auto pos = varName.Index(
';'); pos != -1) {
4260 binningName = varName(pos + 1, varName.Length());
4261 varName = varName(0, pos);
4264 if (varName ==
"xaxis" &&
4266 if (
auto ax = acquirer.
GetXaxis(); ax) {
4267 varName = ax->GetParent()->GetName();
4269 binningName = ax->GetName();
4270 }
else if (acquirer.
obs().size() == 1)
4271 varName = acquirer.
obs().
at(0)->get()->GetName();
4273 auto x = acquirer.
acquire<
RooRealVar>(varName,
h->GetXaxis()->GetTitle(),
h->GetXaxis()->GetXmin(),
4274 h->GetXaxis()->GetXmax());
4275 if (
x->getMin() >
h->GetXaxis()->GetXmin())
4276 x->setMin(
h->GetXaxis()->GetXmin());
4277 if (
x->getMax() <
h->GetXaxis()->GetXmax())
4278 x->setMax(
h->GetXaxis()->GetXmax());
4279 if (!
x->hasBinning(binningName.c_str())) {
4280 if (
h->GetXaxis()->IsVariableBinSize()) {
4281 x->setBinning(
RooBinning(
h->GetNbinsX(),
h->GetXaxis()->GetXbins()->GetArray()), binningName.c_str());
4284 RooUniformBinning(
h->GetXaxis()->GetXmin(),
h->GetXaxis()->GetXmax(),
h->GetXaxis()->GetNbins()),
4285 binningName.c_str());
4287 x->getBinning(binningName.c_str()).
SetTitle(
h->GetXaxis()->GetTitle());
4288 if (
x->getBinningNames().size() == 2) {
4290 x->setBinning(
x->getBinning(binningName.c_str()));
4294 if (
x->getBinning(binningName.c_str()).numBins() !=
h->GetNbinsX()) {
4295 throw std::runtime_error(
4296 TString::Format(
"binning mismatch for binning %s of %s", binningName.c_str(),
x->GetName()));
4300 std::shared_ptr<RooAbsArg> _f;
4306 for (
auto &[k,
v] : stringAttrs) {
4309 x->setAttribute(
"obs",
true);
4310 }
else if (sOpt2.
Contains(
"shape")) {
4312 for (
int i = 0; i <
x->getBinning(binningName.c_str()).numBins(); i++) {
4313 std::shared_ptr<RooAbsArg> arg;
4314 if (sOpt2.
Contains(
"blankshape")) {
4320 if (
h->GetMinimumStored() != -1111 ||
h->GetMaximumStored() != -1111) {
4322 h->GetBinContent(i + 1),
h->GetMinimumStored(),
4323 h->GetMaximumStored());
4326 h->GetBinContent(i + 1));
4333 auto tmp =
dynamic_cast<RooAbsBinning *
>(
x->getBinningPtr(0)->Clone());
4334 x->setBinning(
x->getBinning(binningName.c_str()));
4336#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
4337 dynamic_cast<ParamHistFunc *
>(_f.get())->_paramSet.setName(
"paramSet");
4340 .setName(
"paramSet");
4342 x->setBinning(*tmp);
4344 for (
auto &[k,
v] : stringAttrs) {
4345 _f->setStringAttribute(k.c_str(),
v.c_str());
4349 binningName.c_str() );
4351 throw std::runtime_error(
"Couldn't make data hist");
4356 f->setAttribute(
"autodensity");
4359 for (
auto &[k,
v] : stringAttrs) {
4360 _f->setStringAttribute(k.c_str(),
v.c_str());
4364 _f->setStringAttribute(
"xvar",
x->GetName());
4365 _f->setStringAttribute(
"binning", binningName.c_str());
4366 if (strcmp(_f->GetName(), origName.
Data()) && !_f->getStringAttribute(
"alias"))
4367 _f->setStringAttribute(
"alias", origName);
4370 xRooNode tmp(
h->GetName(), _f, acquirer);
4372 _f = std::dynamic_pointer_cast<RooAbsArg>(tmp.
fComp);
4375 _f->setStringAttribute(
"xvar",
x->GetName());
4376 _f->setStringAttribute(
"binning", binningName.c_str());
4379 if (strcmp(_f->GetName(), origName.
Data()) && !_f->getStringAttribute(
"alias"))
4380 _f->setStringAttribute(
"alias", origName);
4397 auto arg = get<RooAbsArg>();
4398 if (!initObject && !arg) {
4402 std::unique_ptr<TObject> argInitObject;
4408 if (arg->getStringAttribute(
"style"))
4409 t = arg->getStringAttribute(
"style");
4410 else if (autoCreate) {
4412 argInitObject = std::make_unique<TH1D>(
GetName(),
GetTitle(), 1, 0, 1);
4413 initObject = argInitObject.get();
4419 std::shared_ptr<TStyle>
style;
4421 if (!
gROOT->GetStyle(t)) {
4422 if ((
style = getObject<TStyle>(t.
Data()))) {
4432 if (
auto x =
dynamic_cast<TAttLine *
>(initObject))
4434 if (
auto x =
dynamic_cast<TAttFill *
>(initObject))
4436 if (
auto x =
dynamic_cast<TAttMarker *
>(initObject))
4444 if (arg && !arg->getStringAttribute(
"style")) {
4445 arg->setStringAttribute(
"style",
style->GetName());
4451std::shared_ptr<TObject>
xRooNode::acquire(
const std::shared_ptr<TObject> &arg,
bool checkFactory,
bool mustBeNew)
4456 return fParent->acquire(arg, checkFactory, mustBeNew);
4460 if (_ws && (
get() == _ws || _ws->arg(
GetName()) || (arg && strcmp(arg->GetName(),
GetName()) == 0))) {
4463 if (
auto a =
dynamic_cast<RooAbsArg *
>(arg.get());
a) {
4464 auto out_arg = _ws->arg(
a->GetName());
4465 TString aName = arg->GetName();
4467 while (out_arg && mustBeNew) {
4469 out_arg = _ws->arg(
a->GetName());
4471 if (aName !=
a->GetName())
4472 Warning(
"acquire",
"Renaming to %s",
a->GetName());
4476 if (
auto res = _ws->factory(arg->GetName()); res) {
4483 Info(
"acquire",
"A copy of %s has been added to workspace %s",
a->GetName(), _ws->GetName());
4489 std::set<std::string> setNames;
4492 setNames.insert(aa.first);
4495 for (
auto &aa : setNames)
4497 out_arg = _ws->arg(
a->GetName());
4498 if (
GETWS(out_arg) != _ws) {
4499 out_arg->setWorkspace(*_ws);
4503 return std::shared_ptr<TObject>(out_arg, [](
TObject *) {});
4504 }
else if (
auto a2 =
dynamic_cast<RooAbsData *
>(arg.get()); a2) {
4510 return std::shared_ptr<TObject>(_ws->embeddedData(arg->GetName()), [](
TObject *) {});
4511 }
else if (arg->InheritsFrom(
"RooFitResult") || arg->InheritsFrom(
"TTree") || arg->IsA() ==
TStyle::Class()) {
4514 TString aName = arg->GetName();
4515 TObject *out_arg = _ws->genobj(arg->GetName());
4517 while (aNamed && out_arg && mustBeNew) {
4519 out_arg = _ws->genobj(aNamed->
GetName());
4522 if (aName != arg->GetName()) {
4523 Warning(
"acquire",
"Renaming to %s", arg->GetName());
4525 if (_ws->import(*arg.get(),
false )) {
4529 out_arg = _ws->genobj(arg->GetName());
4547 return std::shared_ptr<TObject>(out_arg, [](
TObject *) {});
4554 auto out =
fProvider->getObject(arg->GetName(), arg->ClassName());
4558 auto _owned =
find(
".memory");
4560 _owned = emplace_back(std::make_shared<xRooNode>(
".memory",
nullptr, *
this));
4565 for (
auto &
r : *_owned) {
4566 if (strcmp(
r->GetName(), arg->GetName()) == 0 && strcmp(
r->get()->ClassName(), arg->ClassName()) == 0) {
4572 std::cout <<
GetName() <<
" taking over " << arg->ClassName() <<
"::" << arg->GetName() << std::endl;
4574 return _owned->emplace_back(std::make_shared<xRooNode>(arg->GetName(), arg, *
this))->fComp;
4602 auto _deps =
vars();
4614 auto a = get<RooAbsArg>();
4616 throw std::runtime_error(
"Cannot SetXaxis of non-arg");
4618 auto _x = acquire<RooRealVar>(
name, title, low, high);
4619 _x->setBinning(binning,
a->
GetName());
4620 _x->getBinning(
a->GetName()).SetTitle(title);
4621 if (_x->getBinningNames().size() == 2) {
4623 _x->setBinning(_x->getBinning(
a->GetName()));
4628 if (_x->getMax() < high)
4630 if (_x->getMin() > low)
4634 if (!_deps.find(
name) && get<RooAbsPdf>()) {
4636 _x->setAttribute(
"obs");
4639 a->setStringAttribute(
"xvar", _x->GetName());
4640 a->setStringAttribute(
"binning",
a->GetName());
4659 return find(
name,
false) !=
nullptr;
4664 std::string partname = (
name.find(
'/') != std::string::npos) ?
name.substr(0,
name.find(
'/')) :
name;
4666 : get<RooSimultaneous>();
4667 std::string extra = (_s) ? _s->indexCat().GetName() :
"";
4668 for (
auto &
child : *
this) {
4670 (_obj &&
name == _obj->GetName()) || (_obj && partname == _obj->GetName()) ||
4671 (!extra.empty() && ((extra +
"=" +
name) ==
child->GetName() ||
4672 (extra +
"=" + partname) ==
child->GetName()))) {
4676 return child->at(
name.substr(partname.length() + 1));
4682 for (
auto &child2 :
x.browse()) {
4683 if (
auto _obj = child2->get();
name == child2->GetName() || partname == child2->GetName() ||
4684 (_obj &&
name == _obj->GetName()) || (_obj && partname == _obj->GetName())) {
4687 if (partname !=
name &&
name != child2->GetName()) {
4688 return child2->at(
name.substr(partname.length() + 1));
4697 auto child2 =
at(s.Atoi());
4698 if (partname !=
name) {
4699 return child2->at(
name.substr(partname.length() + 1));
4708 std::string partname = (
name.find(
'/') != std::string::npos) ?
name.substr(0,
name.find(
'/')) :
name;
4711 : get<RooSimultaneous>();
4712 std::string extra = (_s) ? _s->indexCat().GetName() :
"";
4713 std::shared_ptr<xRooNode> folderNode;
4714 for (
auto &
child : *
this) {
4717 ((extra +
"=" +
name) ==
child->GetName() || (extra +
"=" + partname) ==
child->GetName()))) {
4720 return child->operator[](
name.substr(partname.length() + 1));
4726 for (
auto &child2 :
x.browse()) {
4727 if (
name == child2->GetName() || partname == child2->GetName()) {
4729 if (partname !=
name &&
name != child2->GetName()) {
4730 return child2->operator[](
name.substr(partname.length() + 1));
4736 if (
child->fFolder == (std::string(
"!") + partname)) {
4738 folderNode = std::make_shared<xRooNode>(
child->fFolder.c_str(),
nullptr, *
this);
4739 folderNode->push_back(
child);
4743 if (partname !=
name) {
4744 return folderNode->operator[](
name.substr(partname.length() + 1));
4750 auto child2 =
at(s.Atoi());
4751 if (partname !=
name) {
4752 return child2->operator[](
name.substr(partname.length() + 1));
4756 auto out = std::make_shared<xRooNode>(partname.c_str(),
nullptr, *
this);
4757 if (partname !=
name) {
4758 return out->operator[](
name.substr(partname.length() + 1));
4766 for (
auto o : *
gROOT->GetListOfBrowsers()) {
4768 if (!
b || !
b->GetBrowserImp())
4775 if (!
b->GetBrowserImp())
4791 for (
auto o : *
gROOT->GetListOfBrowsers()) {
4793 if (!
b || !
b->GetBrowserImp())
4800 if (
b->GetBrowserImp()) {
4806 if (
auto item =
GETLISTTREE(_b)->FindItemByObj(_root,
const_cast<xRooNode *
>(
this)); item) {
4817 if (
auto a = get<RooAbsArg>();
a)
4818 a->setStringAttribute(
"alias",
name);
4819 for (
auto o : *
gROOT->GetListOfBrowsers()) {
4820 if (
auto b =
dynamic_cast<TBrowser *
>(o);
b) {
4822 item->SetText(
name);
4830 if (
auto o = (get<TNamed>()); o) {
4845 auto findByObj = [&](
const std::shared_ptr<xRooNode> &
n) {
4846 std::vector<std::shared_ptr<xRooNode>> &nn = *
this;
4847 for (
auto &
c : nn) {
4848 if (
c->get() ==
n->get() && strcmp(
n->GetName(),
c->GetName()) == 0)
4851 return std::shared_ptr<xRooNode>(
nullptr);
4854 auto appendChildren = [&](
const xRooNode &
n) {
4856 const std::vector<std::shared_ptr<xRooNode>> &nn(
n);
4857 for (
auto &
c : nn) {
4858 if (
auto existing = findByObj(
c); existing) {
4860 existing->fFolder =
c->fFolder;
4870 const std::vector<std::shared_ptr<xRooNode>> &nn2(*
this);
4871 for (
auto &
c : nn2) {
4872 if (strlen(
c->GetName()) > 0 && (
c->GetName()[0] ==
'.')) {
4876 if (strcmp(
c->GetName(),
"!.pars") == 0) {
4887 size_t addedChildren = 0;
4891 if (get<RooWorkspace>()) {
4892 addedChildren += appendChildren(
datasets());
4906 addedChildren += appendChildren(
components());
4907 if (!get<RooWorkspace>())
4908 addedChildren += appendChildren(
factors());
4910 auto _coefs =
coefs();
4911 if (_coefs.get() && strcmp(_coefs->GetName(),
"1") != 0 && strcmp(_coefs->GetName(),
"ONE") != 0) {
4912 if (_coefs.size() == 1 && _coefs.get<
RooAddition>()) {
4913 if (strcmp(_coefs.at(0)->GetName(),
"1") != 0 &&
4914 strcmp(_coefs.at(0)->GetName(),
"ONE") != 0) {
4915 auto coef = std::make_shared<xRooNode>(
".coef", *_coefs.at(0)->get(), *
this);
4916 if (
auto existing = findByObj(coef); existing) {
4918 existing->fFolder = _coefs.at(0)->fFolder;
4924 if (
auto existing =
find(_coefs.GetName()); existing) {
4926 existing->fFolder = _coefs.fFolder;
4928 emplace_back(std::make_shared<xRooNode>(_coefs));
4932 addedChildren += appendChildren(
variations());
4933 if (get<ParamHistFunc>() || get<RooSimultaneous>())
4934 addedChildren += appendChildren(
bins());
4935 if (get<RooAbsData>())
4936 addedChildren += appendChildren(
obs());
4939 if (
auto arg = get<RooAbsArg>(); arg && addedChildren == 0) {
4940 for (
int i = 0; i < arg->numProxies(); i++) {
4941 auto _proxy = arg->getProxy(i);
4943 auto c = std::make_shared<xRooNode>(
TString::Format(
".%s", _proxy->name()), *(
a->absArg()), *
this);
4944 if (
auto existing = findByObj(
c); existing) {
4946 existing->fFolder =
c->fFolder;
4951 for (
auto a2 : *s) {
4952 auto c = std::make_shared<xRooNode>(*a2, *
this);
4953 if (arg->numProxies() != 1)
4954 c->fFolder = std::string(
"!.") +
4956 if (
auto existing = findByObj(
c); existing) {
4958 existing->fFolder =
c->fFolder;
4974 }
else if (
auto ir = get<RooStats::HypoTestInverterResult>()) {
4978 if (strcmp(
c->GetName(),
".memory") == 0 &&
c->get<
xRooHypoSpace>()) {
4986 fBrowsables.emplace_back(std::make_shared<xRooNode>(
".memory", std::make_shared<xRooHypoSpace>(ir), *
this));
4993 for (
auto a : _axes) {
4994 if (
a != _axes.first())
4997 TString::Format(
"%s=%g",
a->GetName(), hp.coords->getRealValue(
a->GetName(), ir->GetXValue(i)));
4999 auto hpn = emplace_back(std::make_shared<xRooNode>(coordString, hp.hypoTestResult, hs));
5001 hpn->fBrowsables.emplace_back(std::make_shared<xRooNode>(
5007 std::vector<std::shared_ptr<xRooNode>> &nn = *
this;
5008 for (
auto &
c : nn) {
5018 }
else if (get<RooStats::HypoTestResult>()) {
5031 std::make_shared<xRooNLLVar::xRooHypoPoint>(std::dynamic_pointer_cast<RooStats::HypoTestResult>(
fComp));
5032 fBrowsables.emplace_back(std::make_shared<xRooNode>(
".memory", shp, *
this));
5038 if (
auto fit = hp->
ufit()) {
5039 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"ufit");
5042 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"cfit_null");
5045 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"cfit_alt");
5047 if (
auto fit = hp->
gfit()) {
5048 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"gfit");
5050 if (
auto asi = hp->
asimov()) {
5051 auto asiP = fits.emplace_back(std::make_shared<xRooNode>(
5052 asi->hypoTestResult ? asi->hypoTestResult : std::make_shared<RooStats::HypoTestResult>(asi->result()),
5054 asiP->TNamed::SetName(
"asimov");
5055 asiP->fBrowsables.emplace_back(std::make_shared<xRooNode>(
".memory", asi, asiP));
5057 appendChildren(fits);
5061 auto it = std::vector<std::shared_ptr<xRooNode>>
::begin();
5062 while (it != std::vector<std::shared_ptr<xRooNode>>
::end()) {
5063 if (it->get()->fTimes == 0) {
5064 for (
auto o : *
gROOT->GetListOfBrowsers()) {
5066 if (
b &&
b->GetBrowserImp()) {
5075 if (
auto item =
GETLISTTREE(_b)->FindItemByObj(_root,
this); item) {
5113 xRooNode out(
".obs", std::make_shared<RooArgList>(), *
this);
5115 for (
auto o :
vars()) {
5118 out.emplace_back(o);
5129 xRooNode out(
".globs", std::make_shared<RooArgList>(), *
this);
5131 for (
auto o :
obs()) {
5134 out.emplace_back(o);
5145 xRooNode out(
".robs", std::make_shared<RooArgList>(), *
this);
5147 for (
auto o :
obs()) {
5150 out.emplace_back(o);
5161 xRooNode out(
".pars", std::make_shared<RooArgList>(), *
this);
5163 for (
auto o :
vars()) {
5166 out.emplace_back(o);
5177 xRooNode out(
".consts", std::make_shared<RooArgList>(), *
this);
5179 for (
auto o :
pars()) {
5182 out.emplace_back(o);
5194 xRooNode out(
".floats", std::make_shared<RooArgList>(), *
this);
5196 for (
auto o :
pars()) {
5199 out.emplace_back(o);
5211 xRooNode out(
".poi", std::make_shared<RooArgList>(), *
this);
5213 for (
auto o :
pars()) {
5216 out.emplace_back(o);
5228 xRooNode out(
".np", std::make_shared<RooArgList>(), *
this);
5230 for (
auto o :
pars()) {
5232 (!o->get<
RooAbsArg>()->getAttribute(
"Constant") && !o->get<
RooAbsArg>()->getAttribute(
"poi") &&
5235 out.emplace_back(o);
5246 xRooNode out(
".pp", std::make_shared<RooArgList>(), *
this);
5248 for (
auto o :
pars()) {
5252 out.emplace_back(o);
5263 xRooNode out(
".vars", std::make_shared<RooArgList>(), *
this);
5265 if (
auto coll = get<RooAbsCollection>(); coll) {
5266 for (
auto &
x : *
this) {
5267 for (
auto &
y :
x->vars()) {
5273 if (
auto p = get<RooAbsArg>();
p) {
5279 p->leafNodeServerList(&allLeafs);
5280 for (
auto &
c : allLeafs) {
5282 if (!
c->getAttribute(
"global")) {
5284 out.emplace_back(std::make_shared<xRooNode>(*
c, *
this));
5286 if (
c->getAttribute(
"global")) {
5287 _globs.emplace_back(std::make_shared<xRooNode>(*
c, *
this));
5288 _globs.back()->fFolder =
"!globs";
5289 }
else if (
c->getAttribute(
"obs"))
5290 out.back()->fFolder =
"!robs";
5291 else if (
c->getAttribute(
"poi"))
5292 out.back()->fFolder =
"!poi";
5293 else if (
c->getAttribute(
"np") ||
5295 out.back()->fFolder =
"!np";
5297 out.back()->fFolder =
"!floats";
5299 out.back()->fFolder =
"!pp";
5302 for (
auto g : _globs) {
5304 out.emplace_back(
g);
5306 }
else if (
auto p2 = get<RooAbsData>(); p2) {
5307 for (
auto a : *p2->get()) {
5308 a->setAttribute(
"obs");
5309 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5312 if (
auto _dglobs = p2->getGlobalObservables()) {
5313 for (
auto &
a : *_dglobs) {
5314 a->setAttribute(
"obs");
5315 a->setAttribute(
"global");
5316 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5321 a->setAttribute(
"obs");
5322 a->setAttribute(
"global");
5323 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5326 }
else if (
auto _ws =
ws(); _ws) {
5328 for (
auto a : *_globs2) {
5329 a->setAttribute(
"obs");
5330 a->setAttribute(
"global");
5331 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5335 for (
auto &_g : _gl->second) {
5336 auto _clone = std::shared_ptr<RooAbsArg>(
dynamic_cast<RooAbsArg *
>(_g->Clone(_g->GetName())));
5337 if (
auto v = std::dynamic_pointer_cast<RooAbsRealLValue>(_clone);
v && _g->getStringAttribute(
"nominal"))
5338 v->setVal(
TString(_g->getStringAttribute(
"nominal")).
Atof());
5339 out.emplace_back(std::make_shared<xRooNode>(_clone, *
this));
5347 for (
auto &_g : *_globs3) {
5348 auto _clone = std::shared_ptr<RooAbsArg>(
dynamic_cast<RooAbsArg *
>(_g->Clone(_g->GetName())));
5349 if (
auto v = std::dynamic_pointer_cast<RooAbsRealLValue>(_clone);
v && _g->getStringAttribute(
"nominal"))
5350 v->setVal(
TString(_g->getStringAttribute(
"nominal")).
Atof());
5351 out.emplace_back(std::make_shared<xRooNode>(_clone, *
this));
5356 }
else if (
auto w = get<RooWorkspace>();
w) {
5357 for (
auto a :
w->allVars()) {
5358 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5362 for (
auto a :
w->allCats()) {
5363 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5372 xRooNode out(
".components",
nullptr, *
this);
5374 if (
auto p = get<RooAddPdf>();
p) {
5376 std::set<RooAbsArg *> donePdfs;
5377 for (
auto &o :
p->pdfList()) {
5378 if (donePdfs.count(o))
5380 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5383 }
else if (
auto p2 = get<RooRealSumPdf>(); p2) {
5397 std::set<RooAbsArg *> doneFuncs;
5398 for (
auto &o : p2->funcList()) {
5399 if (doneFuncs.count(o))
5401 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5402 doneFuncs.insert(o);
5404 }
else if (
auto p3 = get<RooAddition>(); p3) {
5405 for (
auto &o : p3->list()) {
5406 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5408 }
else if (
auto p4 = get<RooAbsCollection>(); p4) {
5409 for (
auto &
a : *p4) {
5410 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5412 }
else if (
auto p5 = get<RooWorkspace>(); p5) {
5413 for (
auto &o : p5->components()) {
5416 bool hasClients =
false;
5417 for (
auto &
c : o->clients())
5418 if (!
c->InheritsFrom(
"RooRealIntegral") && p5 ==
GETWS(o)) {
5424 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5425 if (o->InheritsFrom(
"RooAbsPdf"))
5426 out.back()->fFolder =
"!models";
5428 out.back()->fFolder =
"!scratch";
5430 for (
auto &o : p5->allGenericObjects()) {
5434 s = s(0, s.
Index(
';'));
5435 if (
auto _pdf = out.find(s.
Data()); _pdf) {
5437 out.emplace_back(std::make_shared<xRooNode>(fr->GetName(), *fr, _pdf));
5444 out.emplace_back(std::make_shared<xRooNode>(fr->GetName(), *fr, *
this));
5446 out.back()->fFolder =
"!fits";
5448 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5449 if (strcmp(out.back()->get()->ClassName(),
"TStyle") == 0) {
5450 out.back()->fFolder =
"!styles";
5451 }
else if (strcmp(out.back()->get()->ClassName(),
"RooStats::HypoTestInverterResult") == 0) {
5452 out.back()->fFolder =
"!scans";
5454 out.back()->fFolder =
"!objects";
5461 if (k.find(
"CACHE_") == 0)
5463 out.emplace_back(std::make_shared<xRooNode>(k.c_str(),
v, *
this));
5464 out.back()->fFolder =
"!sets";
5470 while ((snap = iter->Next())) {
5471 out.emplace_back(std::make_shared<xRooNode>(*snap, *
this));
5472 out.back()->fFolder =
"!snapshots";
5478 out.emplace_back(
c);
5485 out.emplace_back(
c);
5499 xRooNode out(
".bins",
nullptr, *
this);
5501 if (
auto p = get<RooSimultaneous>();
p) {
5502 std::map<int, std::shared_ptr<xRooNode>> cats;
5503 for (
auto &
c :
p->indexCat()) {
5504 auto pp =
p->getPdf(
c.first.c_str());
5510 for (
auto &[
_,
n] : cats)
5511 out.emplace_back(
n);
5512 }
else if (
auto phf = get<ParamHistFunc>(); phf) {
5514#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
5515 auto &pSet = phf->_paramSet;
5517 auto &pSet = phf->paramList();
5519 for (
auto par : pSet) {
5520 out.emplace_back(std::make_shared<xRooNode>(*par, *
this));
5521 out.back()->fBinNumber = i;
5524 }
else if (
auto ax =
GetXaxis(); ax) {
5525 for (
int i = 1; i <= ax->GetNbins(); i++) {
5527 std::vector<RooAbsArg *> _factors;
5531 for (
auto &ss :
f->bins()[i - 1]->factors())
5532 _factors.push_back(ss->get<
RooAbsArg>());
5534 _factors.push_back(
f->bins()[i - 1]->get<
RooAbsArg>());
5537 out.emplace_back(std::make_shared<xRooNode>(
5538 TString::Format(
"%g<=%s<%g", ax->GetBinLowEdge(i), ax->GetParent()->GetName(), ax->GetBinLowEdge(i + 1)),
5539 _factors.empty() ? nullptr
5543 for (
auto f : _factors) {
5544#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
5550 out.back()->fBinNumber = i;
5560 bool isResidual =
false;
5568 if (!parent->fComp) {
5569 while (!parent->fComp && parent->fParent) {
5570 parent = parent->fParent;
5573 parent = parent->fParent;
5579 for (
auto &o :
p->funcList()) {
5581 if (i >=
p->coefList().size()) {
5583 coefs.add(
p->coefList());
5585 coefs.add(*
p->coefList().at(i));
5590 }
else if (
auto p2 = parent->get<
RooAddPdf>(); p2) {
5592 if (p2->coefList().empty()) {
5597 for (
auto &o : p2->pdfList()) {
5599 if (i >= p2->coefList().size()) {
5601 coefs.add(p2->coefList());
5603 coefs.add(*p2->coefList().at(i));
5614 auto coefSum =
coefs.empty()
5617 : std::make_shared<RooAddition>((isResidual) ?
".sumOfCoefs" :
".coefs",
5618 "Coefficients of",
coefs));
5619 xRooNode out(
".coef", coefSum ? std::dynamic_pointer_cast<RooAbsArg>(std::make_shared<RooFormulaVar>(
5620 ".coef",
"1-sum(otherCoefs)",
"1. - @0", *coefSum))
5622 if (coefSum &&
coefs.size() != 1) {
5623 out.emplace_back(std::make_shared<xRooNode>(
".memory",
nullptr, *
this))
5625 std::make_shared<xRooNode>(
".sumOfCoefs", coefSum, out));
5627 if (!
coefs.empty()) {
5631 }
else if (
coefs.size() == 1) {
5633 if (!
coefs.empty()) {
5642 xRooNode out(
".coefs", coefSum, *
this);
5652 xRooNode out(
".factors",
nullptr, *
this);
5654 if (
auto p = get<RooProdPdf>();
p) {
5656 if (
auto a = _main.get<
RooRealSumPdf>();
a && !
a->getStringAttribute(
"alias"))
5657 a->setStringAttribute(
"alias",
"samples");
5659 a2->setStringAttribute(
"alias",
"components");
5660 int _npdfs =
p->pdfList().size();
5661 for (
auto &o :
p->pdfList()) {
5662 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5663 if (_npdfs > 5 && o != _main.get())
5664 out.back()->fFolder =
"!constraints";
5666 }
else if (
auto p2 = get<RooProduct>(); p2) {
5667 for (
auto &o : p2->components()) {
5668 if (o->InheritsFrom(
"RooProduct")) {
5672 out.emplace_back(std::make_shared<xRooNode>(
n->GetName(),
n->fComp, *
this));
5675 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5678 }
else if (
auto w = get<RooWorkspace>();
w) {
5684 for (
auto a :
w->allFunctions()) {
5685 if (_obs.contains(*
a))
5688 for (
auto c :
a->clients()) {
5690 if (
c->InheritsFrom(
"RooProduct"))
5694 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5738 xRooNode out(
".variations",
nullptr, *
this);
5750 if (
auto p2 = get<PiecewiseInterpolation>(); p2) {
5751#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
5752 out.emplace_back(std::make_shared<xRooNode>(
"nominal", p2->_nominal.arg(), *
this));
5754 out.emplace_back(std::make_shared<xRooNode>(
"nominal", *(p2->nominalHist()), *
this));
5756 for (
size_t i = 0; i < p2->paramList().
size(); i++) {
5758 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p2->paramList().at(i)->GetName()),
5759 *p2->highList().at(i), *
this));
5760 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p2->paramList().at(i)->GetName()),
5761 *p2->lowList().at(i), *
this));
5763 }
else if (
auto p3 = get<RooStats::HistFactory::FlexibleInterpVar>(); p3) {
5764#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
5765 out.emplace_back(std::make_shared<xRooNode>(
"nominal",
RooFit::RooConst(p3->_nominal), *
this));
5766 for (
size_t i = 0; i < p3->_paramList.size(); i++) {
5767 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p3->_paramList.at(i)->GetName()),
5769 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p3->_paramList.at(i)->GetName()),
5773 out.emplace_back(std::make_shared<xRooNode>(
"nominal",
RooFit::RooConst(p3->nominal()), *
this));
5774 for (
size_t i = 0; i < p3->variables().
size(); i++) {
5775 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p3->variables().at(i)->GetName()),
5777 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p3->variables().at(i)->GetName()),
5782 }
else if (
auto p4 = get<ParamHistFunc>(); p4) {
5801 for (
auto &k : *
this) {
5810 xRooNode out(
".datasets()",
nullptr, *
this);
5811 out.fBrowseOperation = [](
xRooNode *
f) {
return f->fParent->datasets(); };
5813 if (
auto _ws = get<RooWorkspace>(); _ws) {
5814 for (
auto &
d : _ws->allData()) {
5815 out.emplace_back(std::make_shared<xRooNode>(*
d, *
this));
5816 out.back()->fFolder =
"!datasets";
5818 }
else if (
auto __ws =
ws(); __ws) {
5819 if (get<RooAbsPdf>() ||
5830 for (
auto _c :
coords()) {
5834 cut +=
TString::Format(
"%s==%d", _cat->GetName(), _cat->getCurrentIndex());
5843 TString::Format(
"%s>=%f&&%s<%f", _rv->GetName(), _rv->getMin(_rv->getStringAttribute(
"coordRange")),
5844 _rv->GetName(), _rv->getMax(_rv->getStringAttribute(
"coordRange")));
5849 throw std::runtime_error(
"datasets(): Unsupported coordinate type");
5852 if (
auto s = get<RooSimultaneous>()) {
5854 bool hasMissing =
false;
5856 for (
auto cat : s->indexCat()) {
5857 if (!s->getPdf(cat.first.c_str())) {
5862 extraCut +=
TString::Format(
"%s==%d", s->indexCat().GetName(), cat.second);
5868 cut +=
"(" + extraCut +
")";
5869 cutobs.
add(s->indexCat());
5874 auto a =
dynamic_cast<RooAbsArg *
>(ax->GetParent());
5879 if (std::unique_ptr<RooAbsCollection>(
d->obs().argList().selectCommon(_obs))->size() == _obs.
size()) {
5886 out.emplace_back(std::make_shared<xRooNode>(
5890 if (
d->get()->TestBit(1 << 20))
5891 out.back()->get()->SetBit(1 << 20);
5893 out.back()->fBrowsables.emplace_back(std::make_shared<xRooNode>(
".sourceds",
d->fComp, *
this));
5895 out.emplace_back(std::make_shared<xRooNode>(
d->fComp, *
this));
5916 if (
b && strcmp(
b->GetName(),
name) == 0)
5924 if (
auto fr = get<RooFitResult>(); fr) {
5928 if (
auto theData = get<RooDataSet>(); theData) {
5930 TH1 *theHist =
nullptr;
5935 theHist =
dynamic_cast<TH1 *
>(o);
5948 auto vo =
dynamic_cast<TObject *
>(
v);
5949 if (
v &&
obs().
find(vo->GetName())) {
5953 TString::Format(
"my temp hist;%s", strlen(vo->GetTitle()) ? vo->GetTitle() : vo->GetName()),
5954 cat->numTypes(), 0, cat->numTypes());
5955 for (
int i = 0; i < cat->numTypes(); i++) {
5960 auto _binning =
v->getBinningPtr(
nullptr);
5961 if(_binning->isUniform()) {
5964 TString::Format(
"my temp hist;%s", strlen(vo->GetTitle()) ? vo->GetTitle() : vo->GetName()),
5965 v->numBins(), _binning->lowBound(), _binning->highBound());
5969 TString::Format(
"my temp hist;%s", strlen(vo->GetTitle()) ? vo->GetTitle() : vo->GetName()),
5970 v->numBins(), _binning->array());
5974 throw std::runtime_error(
"Cannot draw dataset without parent PDF");
5977 theHist = _parentPdf->BuildHistogram(
v,
true);
5987 auto nHist = std::unique_ptr<TH1>((
TH1 *)theHist->
Clone(
"nEntries"));
5992 dataGraph->SetName(
GetName());
5993 dataGraph->SetTitle(strlen(theData->GetTitle()) ? theData->GetTitle() : theData->GetName());
5999 dataGraph->SetMarkerStyle(20);
6011 dataGraph->SetTitle(
TString::Format(
"%s = %f", dataGraph->GetTitle(), dataGraph->GetPointX(0)));
6024 auto _pos = pName.
Index(
'=');
6026 int nevent = theData->numEntries();
6027 for (
int i = 0; i < nevent; i++) {
6030 for (
auto _c : _coords) {
6032 if (cat->getIndex() != theData->get()->getCatIndex(cat->GetName())) {
6038 if (!rv->inRange(theData->get()->getRealValue(rv->GetName()), rv->getStringAttribute(
"coordRange"))) {
6046 cat && cat->
getLabel() != pName(_pos + 1, pName.Length())) {
6062 theHist->
Fill((
x) ? xvar->
getVal() : 0.5, theData->weight());
6063 nHist->Fill((
x) ? xvar->
getVal() : 0.5, 1);
6071 for (
int i = 0; i < theHist->
GetNbinsX(); i++) {
6072 if (includeZeros || nHist->GetBinContent(i + 1)) {
6075 dataGraph->SetPoint(dataGraph->GetN(),
6080 xErr = (xErr <= 0) ? 0. : sqrt(xErr);
6083 dataGraph->SetPointError(dataGraph->GetN() - 1, xErr, xErr,
6094 dataGraph->GetHistogram()->GetXaxis()->Set(theHist->
GetNbinsX(), 0, theHist->
GetNbinsX());
6095 for (
int i = 1; i <= theHist->
GetNbinsX(); i++)
6096 dataGraph->GetHistogram()->GetXaxis()->SetBinLabel(i, theHist->
GetXaxis()->
GetBinLabel(i));
6121 auto _style =
style(dataGraph);
6123 *
dynamic_cast<TAttLine *
>(dataGraph) = *_style;
6124 *
dynamic_cast<TAttFill *
>(dataGraph) = *_style;
6125 *
dynamic_cast<TAttMarker *
>(dataGraph) = *_style;
6130 throw std::runtime_error(
"Cannot build graph");
6136 if (
auto _w =
ws(); _w) {
6138 for (
auto o : _w->allGenericObjects()) {
6140 _fr->ResetBit(1 << 20);
6143 res->SetBit(1 << 20);
6145 auto allVars = _w->allVars();
6150 throw std::runtime_error(
"Not supported yet");
6164 throw std::runtime_error(
"Not a RooFitResult");
6170 if (get<RooFitResult>())
6172 if (get<RooAbsData>()) {
6173 if (
auto _fr =
find(
".fitResult"); _fr)
6175#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
6177 if (get<RooDataSet>() && get<RooDataSet>()->weightVar() &&
6178 get<RooDataSet>()->weightVar()->getStringAttribute(
"fitResult")) {
6179 return xRooNode(getObject<const RooFitResult>(get<RooDataSet>()->weightVar()->getStringAttribute(
"fitResult")),
6187 if (sOpt ==
"prefit") {
6194 auto _coefs =
coefs();
6200 std::unique_ptr<RooArgList> _pars(
dynamic_cast<RooArgList *
>(
pars().
argList().selectByAttrib(
"Constant",
false)));
6201 auto fr = std::make_shared<RooFitResult>(
"prefitResult",
"Prefit");
6202 fr->setFinalParList(*_pars);
6203 for (
auto &
p : fr->floatParsFinal()) {
6207 if (
auto s = _v->getStringAttribute(
"nominal"); s)
6210 std::shared_ptr<xRooNode> pConstr;
6211 for (
auto &
c : _constr) {
6214 bool isServer =
true;
6217 for (
auto s :
c->get<
RooAbsArg>()->servers()) {
6218 if (strcmp(s->GetName(),
p->
GetName()) == 0) {
6233 double prefitVal = 0, prefitError = 0;
6234 for (
auto &_d : pConstr->vars()) {
6235 if (strcmp(
p->
GetName(), _d->get()->GetName()) == 0)
6239 prefitVal = prefitError;
6240 prefitError = _c->getVal();
6241 }
else if (prefitError == 0)
6242 prefitError = _d->get<
RooAbsReal>()->getVal();
6247 if (pConstr->get<
RooGaussian>() && pConstr->browse().find(
".sigma")) {
6248 prefitError = pConstr->find(
".sigma")->get<
RooAbsReal>()->getVal();
6254 prefitVal /= prefitError;
6256 prefitError = 1. / sqrt(prefitError);
6258 if (!_v->getStringAttribute(
"nominal"))
6259 _v->setVal(prefitVal);
6260 _v->setError(prefitError);
6269 auto _globs =
globs();
6270 _args.add(_globs.argList());
6271 fr->setConstParList(_args);
6272 std::unique_ptr<RooArgList> _snap(
dynamic_cast<RooArgList *
>(_pars->snapshot()));
6273 for (
auto &
p : *_snap) {
6274 if (
auto atr =
p->getStringAttribute(
"initVal"); atr &&
dynamic_cast<RooRealVar *
>(
p))
6277 fr->setInitParList(*_snap);
6282 if (
auto _w =
ws(); _w) {
6283 auto checkFr = [&](
TObject *o) {
6287 for (
auto p :
pars()) {
6291 if (_fr->floatParsFinal().find(
p->
GetName()) ||
6292 std::abs(_fr->constPars().getRealValue(
p->
GetName(), std::numeric_limits<double>::quiet_NaN()) -
6298 if (_fr->constPars().find(
p->
GetName()) ||
6300 _fr->floatParsFinal().getRealValue(
p->
GetName(), std::numeric_limits<double>::quiet_NaN()) -
6309 std::unique_ptr<RooArgList> _pars(
6311 auto fr = std::make_shared<RooFitResult>(
TString::Format(
"%s-dirty", _fr->GetName()));
6313 fr->setFinalParList(*_pars);
6316 auto cov = _fr->reducedCovarianceMatrix(*_pars);
6318 for (
size_t i = 0; i < _pars->size(); i++) {
6319 if (
auto v =
dynamic_cast<RooRealVar *
>(_pars->at(i))) {
6320 cov(i, i) = pow(
v->getError(), 2);
6325 fr->setCovarianceMatrix(cov);
6331 auto _globs =
globs();
6332 _args.add(_globs.argList());
6333 fr->setConstParList(_args);
6334 std::unique_ptr<RooArgList> _snap(
dynamic_cast<RooArgList *
>(_pars->snapshot()));
6335 for (
auto &
p : *_snap) {
6336 if (
auto atr =
p->getStringAttribute(
"initVal"); atr &&
dynamic_cast<RooRealVar *
>(
p))
6339 fr->setInitParList(*_snap);
6342 return xRooNode(*_fr, std::make_shared<xRooNode>(*_w, std::make_shared<xRooNode>()));
6346 for (
auto o : _w->allGenericObjects()) {
6347 auto out = checkFr(o);
6352 auto out = checkFr(o);
6359 if (
auto fr = getObject<RooFitResult>(
".fitResult"); fr) {
6365 auto _coefs =
coefs();
6371 std::unique_ptr<RooArgList> _pars(
dynamic_cast<RooArgList *
>(
pars().
argList().selectByAttrib(
"Constant",
false)));
6372 auto fr = std::make_shared<RooFitResult>(
TUUID().AsString());
6374 fr->setFinalParList(*_pars);
6380 for (
int i = 0; i < prevCov->
GetNcols(); i++) {
6381 for (
int j = 0; j < prevCov->
GetNrows(); j++) {
6382 cov(i, j) = (*prevCov)(i, j);
6387 for (
auto &
p : fr->floatParsFinal()) {
6388 if (!prevCov || i >= prevCov->
GetNcols()) {
6390 cov(i, i) = pow(
v->getError(), 2);
6397 int covQualBackup = fr->covQual();
6398 fr->setCovarianceMatrix(cov);
6399 fr->setCovQual(covQualBackup);
6404 auto _globs =
globs();
6405 _args.add(_globs.argList());
6406 fr->setConstParList(_args);
6407 std::unique_ptr<RooArgList> _snap(
dynamic_cast<RooArgList *
>(_pars->snapshot()));
6408 for (
auto &
p : *_snap) {
6409 if (
auto atr =
p->getStringAttribute(
"initVal"); atr &&
dynamic_cast<RooRealVar *
>(
p))
6412 fr->setInitParList(*_snap);
6433 if (!std::isnan(low) && !std::isnan(high) && get<RooRealVar>()) {
6434 if (range && strlen(range))
6435 get<RooRealVar>()->setRange(range, low, high);
6437 get<RooRealVar>()->setRange(low, high);
6440 if (
auto o = get<RooAbsArg>(); o)
6441 o->setStringAttribute(
"range", range);
6448 std::string &out =
fRange;
6449 if (
auto o = get<RooAbsArg>(); o && o->getStringAttribute(
"range"))
6450 out = o->getStringAttribute(
"range");
6452 while (out.empty() && _parent) {
6453 if (
auto o = _parent->get<
RooAbsArg>(); o && o->getStringAttribute(
"range"))
6454 out = o->getStringAttribute(
"range");
6455 _parent = _parent->fParent;
6470 for (
auto opt : *defaultOpts) {
6473 for (
auto &i : nllOpts) {
6475 Info(
"nll",
"Overriding NLL Option: %s", o->GetName());
6481 return nll(_data,
l);
6486 if (!get<RooAbsPdf>()) {
6488 if (get<RooWorkspace>()) {
6489 std::shared_ptr<xRooNode> mainModel;
6495 throw std::runtime_error(
TString::Format(
"Workspace has multiple models, you must specify which to "
6496 "generate with (found at least %s and %s)",
6497 mainModel->GetName(),
c->GetName()));
6502 return mainModel->generate(fr, expected, seed);
6515 if (!get<RooAbsPdf>()) {
6517 if (get<RooWorkspace>()) {
6518 std::shared_ptr<xRooNode> mainModel;
6524 throw std::runtime_error(
TString::Format(
"Workspace has multiple models, you must specify which to "
6525 "build nll with (found at least %s and %s)",
6526 mainModel->GetName(),
c->GetName()));
6531 return mainModel->nll(_data, opts);
6537 if (get<RooSimultaneous>()) {
6538 std::string selected;
6539 bool hasDeselected =
false;
6540 for (
auto c :
bins()) {
6542 hasDeselected =
true;
6545 cName = cName(cName.Index(
'=') + 1, cName.Length());
6546 if (!selected.empty())
6548 selected += cName.Data();
6558 if (strlen(_data.
GetName()) == 0) {
6561 _d = std::make_shared<xRooNode>(asi.first, *
this);
6564 std::make_shared<xRooNode>(
".globs", std::const_pointer_cast<RooAbsCollection>(asi.second), *_d));
6569 return nll(*_d, opts);
6572 auto _globs = _data.
globs();
6585 for (
int i = 0; i < opts.
GetSize(); i++) {
6588 if (strcmp(opts.
At(i)->
GetName(),
"GlobalObservables") == 0) {
6591 _opts->Add(opts.
At(i)->
Clone(
nullptr));
6599 std::dynamic_pointer_cast<RooAbsData>(_data.
fComp), *_opts);
6697 auto rangeName = (_range.empty()) ?
GetRange() : _range;
6698 if (!rangeName.empty()) {
6699 std::vector<TString> patterns;
6702 patterns.emplace_back(pattern);
6704 if (
auto s = get<RooSimultaneous>(); s) {
6709 for (
auto &
c :
bins()) {
6711 cName = cName(cName.
Index(
'=') + 1, cName.
Length());
6712 _cat.setLabel(cName);
6713 bool matchAny =
false;
6714 for (
auto &
p : patterns) {
6719 if (_cat.hasRange(
p) && _cat.inRange(
p)) {
6724 if ((matchAny && !invert) || (!matchAny && invert)) {
6729 }
else if (
get() && !get<RooAbsCollection>() && !
components().empty()) {
6733 std::vector<TObject *>
funcs;
6734 for (
auto &
c : out.components()) {
6735 bool matchAny =
false;
6736 for (
auto &
p : patterns) {
6742 if (!((matchAny && !invert) || (!matchAny && invert)))
6743 funcs.push_back(
c->get());
6747 if (!
funcs.empty()) {
6749 _pdf->setFloor(
false);
6755 }
else if (
auto fr = get<RooFitResult>()) {
6761 for (
auto c : _pars) {
6762 bool matchAny =
false;
6763 for (
auto &
p : patterns) {
6769 if (!((matchAny && !invert) || (!matchAny && invert))) {
6773 _pars.remove(_remPars,
true);
6775 auto _tmp = fr->reducedCovarianceMatrix(_pars);
6776 int covQualBackup = fr->covQual();
6777 fr->setCovarianceMatrix(_tmp);
6778 fr->setCovQual(covQualBackup);
6779 const_cast<RooArgList &
>(fr->floatParsFinal())
6780 .remove(_remPars,
true);
6783 }
else if (!
get() || get<RooAbsCollection>()) {
6787 bool notAllArgs =
false;
6788 bool isVars = (strcmp(
GetName(),
".vars") == 0);
6789 for (
auto c : *
this) {
6790 nobs += (
c->fFolder ==
"!robs" ||
c->fFolder ==
"!globs");
6791 bool matchAny =
false;
6792 for (
auto &
p : patterns) {
6794 (isVars &&
p ==
"x" && (
c->fFolder ==
"!robs" ||
c->fFolder ==
"!globs") && nobs == 1)) {
6799 if ((matchAny && !invert) || (!matchAny && invert)) {
6815 return get<RooArgList>() ?
xRooNode(std::make_shared<RooArgList>(),
fParent) : *
this;
6898 return static_cast<RooAbsPdf *
>(intpdf.absArg())->expectedEvents(nset);
6907 return getProjection(&intobs, _normSet, (_normRange.Length() > 0 ? _normRange.Data() : 0), code)->getVal();
6916 fFunc(
"func",
"func", this,
f),
6917 fCoef(
"coef",
"coef", this),
6918 fExpPdf(
"expPdf",
"expPdf", this)
6923 fCoef.setArg(*coef);
6925 if (expPdf && expPdf->canBeExtended() && !(coef &&
dynamic_cast<RooAddPdf *
>(expPdf))) {
6926 fExpPdf.setArg(*expPdf);
6927 }
else if (
auto _p =
dynamic_cast<RooAbsPdf *
>(&
f);
6931 fExpectedEventsMode = expEvMode;
6936 fFunc(
"func", this, other.fFunc),
6937 fCoef(
"coef", this, other.fCoef),
6938 fExpPdf(
"expPdf", this, other.fExpPdf),
6939 fExpectedEventsMode(other.fExpectedEventsMode)
6946 return fFunc->binBoundaries(obs, xlo, xhi);
6951 return (fExpectedEventsMode ? 1. : fFunc) *
6952 ((fExpPdf.absArg()) ?
static_cast<RooAbsPdf *
>(fExpPdf.absArg())->expectedEvents(_normSet) : 1.) *
6953 (fCoef.absArg() ? fCoef : 1.);
6964#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 28, 00)
6965 double oo = getPropagatedError(fr, nset_in);
6966 if (std::isnan(oo)) {
6971 getParameters(&nset_in, allParamsInAbsReal);
6974 for (
auto *rrvFitRes : static_range_cast<RooRealVar *>(fr.
floatParsFinal())) {
6976 auto rrvInAbsReal =
static_cast<RooRealVar const *
>(allParamsInAbsReal.
find(*rrvFitRes));
6980 if (rrvFitRes->namePtr() == namePtr())
6984 if (!rrvFitRes->hasError() ||
6985 rrvFitRes->getError() <= std::abs(rrvFitRes->getVal()) * std::numeric_limits<double>::epsilon())
6994 if (std::abs(rrvInAbsReal->getVal() - rrvFitRes->getVal()) > 0.01 * rrvFitRes->getError()) {
6995 std::stringstream errMsg;
6997 <<
"RooAbsReal::getPropagatedError(): the parameters of the RooAbsReal don't have"
6998 <<
" the same values as in the fit result! The logic of getPropagatedError is broken in this case.";
7000 throw std::runtime_error(errMsg.str());
7003 paramList.
add(*rrvInAbsReal);
7005 if (paramList.
empty())
7008 std::vector<double> plusVar;
7009 std::vector<double> minusVar;
7010 plusVar.reserve(paramList.
size());
7011 minusVar.reserve(paramList.
size());
7017 for (
Int_t ivar = 0; ivar < paramList.
getSize(); ivar++) {
7019 auto &rrv =
static_cast<RooRealVar &
>(paramList[ivar]);
7021 double cenVal = rrv.
getVal();
7022 double errVal = sqrt(V(ivar, ivar));
7034 rrv.setVal(cenVal + errVal);
7035 plusVar.push_back(getVal(nset_in));
7038 rrv.setVal(cenVal - errVal);
7039 minusVar.push_back(getVal(nset_in));
7040#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
7064 std::vector<double> errVec(paramList.
size());
7065 for (
int i = 0; i < paramList.
getSize(); i++) {
7066 errVec[i] = std::sqrt(V(i, i));
7067 for (
int j = i; j < paramList.
getSize(); j++) {
7068 C(i, j) = V(i, j) / std::sqrt(V(i, i) * V(j, j));
7075 for (
unsigned int j = 0; j < plusVar.size(); j++) {
7076 F[j] = (plusVar[j] - minusVar[j]) / 2;
7080 double sum =
F * (C *
F);
7089 for (
auto *frv : static_range_cast<RooRealVar *>(fi.floatParsFinal())) {
7090 if (frv->getError() > 1
e-20) {
7091 fpf_stripped.
add(*frv);
7106 std::vector<int> fpf_idx;
7110 paramList.
add(*par);
7111 fpf_idx.push_back(i);
7115 std::vector<double> plusVar, minusVar;
7121 for (
Int_t ivar = 0; ivar < paramList.
getSize(); ivar++) {
7125 double cenVal = rrv.
getVal();
7126 double errVal = sqrt(V(ivar, ivar));
7129 ((
RooRealVar *)paramList.
at(ivar))->setVal(cenVal + errVal);
7132 plusVar.push_back(cloneFunc->
getVal(nset));
7135 ((
RooRealVar *)paramList.
at(ivar))->setVal(cenVal - errVal);
7138 minusVar.push_back(cloneFunc->
getVal(nset));
7146 std::vector<double> errVec(paramList.
getSize());
7147 for (
int i = 0; i < paramList.
getSize(); i++) {
7148 errVec[i] = sqrt(V(i, i));
7149 for (
int j = i; j < paramList.
getSize(); j++) {
7150 C(i, j) = V(i, j) / sqrt(V(i, i) * V(j, j));
7157 for (
unsigned int j = 0; j < plusVar.size(); j++) {
7158 F[j] = (plusVar[j] - minusVar[j]) / 2;
7162 double sum =
F * (C *
F);
7176 bool fExpectedEventsMode =
false;
7184 std::cout <<
"Got signal " << signum << std::endl;
7185 if (signum == SIGINT) {
7186 std::cout <<
"Keyboard interrupt while building histogram" << std::endl;
7196 auto _doSterilize = [](
RooAbsArg *obj) {
7199 for (
int i = 0; i < obj->numCaches(); i++) {
7205 p->setNormRange(
p->normRange());
7207#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
7212 p->setProxyNormSet(
nullptr);
7213 p->_lastNSet =
nullptr;
7216 obj->setValueDirty();
7218 if (
auto w = get<RooWorkspace>();
w) {
7220 for (
auto &
c :
w->components()) {
7239 nClients =
a->clients().size();
7240 for (
auto obj :
a->clients()) {
7242 if (
a->clients().size() != nClients) {
7247 }
while (
a->clients().size() != nClients);
7249 func(get<RooAbsArg>());
7264 out.fComp = std::shared_ptr<TH1>(
BuildHistogram(
nullptr, !content, errors, -1, -1, fr));
7265 }
else if (
vars.size() == 1) {
7267 out.fComp = std::shared_ptr<TH1>(
BuildHistogram(
v, !content, errors, 1, 0, fr));
7269 throw std::runtime_error(
"multi-dim histo not yet supported");
7272 if (
auto h = out.get<
TH1>()) {
7273 if (
h->GetXaxis()->IsAlphanumeric()) {
7275 h->GetXaxis()->SetName(
"xaxis");
7279 auto hCopy =
static_cast<TH1 *
>(
h->Clone(
"nominal"));
7286 std::map<std::string, int> colorByTitle;
7287 std::set<std::string> allTitles;
7288 bool titleMatchName =
true;
7289 std::map<std::string, TH1 *> histGroups;
7290 std::vector<TH1 *> hhs;
7298 for (
auto &
c : *comps) {
7299 if (
c->fFolder ==
"!.coeffs")
7304 if (!cms_coefs.
empty()) {
7306 std::shared_ptr<TH1> prevHist((
TH1 *)
h->Clone());
7307 for (
auto c : cms_coefs) {
7311 Form(
"ORIGNAME:%s",
c->GetName()));
7312 f->redirectServers(
RooArgSet(zero),
false,
true);
7318 if (strlen(hh->GetTitle()) == 0)
7319 hh->SetTitle(
c->GetName());
7320 titleMatchName &= (
TString(
c->GetName()) == hh->GetTitle() ||
7322 std::shared_ptr<TH1> nextHist((
TH1 *)hh->Clone());
7323 hh->Add(prevHist.get(), -1.);
7326 prevHist = nextHist;
7330 auto hh = samp->BuildHistogram(
v,
false,
false, !
v ? -1 : 1, !
v ? -1 : 0, fr);
7334 if (strlen(hh->GetTitle()) == 0)
7335 hh->SetTitle(samp->GetName());
7336 titleMatchName &= (
TString(samp->GetName()) == hh->GetTitle() ||
7340 for (
auto &hh : hhs) {
7341 if (
h->GetXaxis()->IsAlphanumeric()) {
7343 hh->GetXaxis()->SetName(
"xaxis");
7344 for (
int i = 1; i <= hh->GetNbinsX(); i++)
7345 hh->GetXaxis()->SetBinLabel(i,
h->GetXaxis()->GetBinLabel(i));
7348 if (histGroups.find(hh->GetTitle()) == histGroups.end()) {
7349 histGroups[hh->GetTitle()] = hh;
7352 histGroups[hh->GetTitle()]->Add(hh);
7356 auto hhMin = (hh->GetMinimum() == 0) ? hh->GetMinimum(1
e-9) : hh->GetMinimum();
7357 if (!stack->
GetHists() &&
h->GetMinimum() > hhMin) {
7359 if (hhMin >= 0 && newMin < 0)
7360 newMin = hhMin * 0.99;
7361 h->SetMinimum(newMin);
7363 if (
auto it = colorByTitle.find(hh->GetTitle()); it != colorByTitle.end()) {
7364 hh->SetFillColor(it->second);
7368 hh->SetFillColor((count++) % 100);
7371 for (
auto hh2 : hhs) {
7372 if (hh != hh2 && hh2->GetFillColor() == hh->GetFillColor()) {
7378 colorByTitle[hh->GetTitle()] = hh->GetFillColor();
7390 stack->
Add(hh, thisOpt);
7391 allTitles.insert(hh->GetTitle());
7399 size_t e = std::min(allTitles.begin()->size(), allTitles.rbegin()->size());
7401 bool goodPrefix =
false;
7402 std::string commonSuffix;
7403 if (titleMatchName && ll->
GetEntries() > 1) {
7404 while (ii <
e - 1 && allTitles.begin()->at(ii) == allTitles.rbegin()->at(ii)) {
7406 if (allTitles.begin()->at(ii) ==
'_' || allTitles.begin()->at(ii) ==
' ')
7412 while (!stop && commonSuffix.size() <
size_t(
e - 1)) {
7413 commonSuffix = allTitles.begin()->substr(allTitles.begin()->length() - commonSuffix.length() - 1);
7414 for (
auto &t : allTitles) {
7416 commonSuffix = commonSuffix.substr(1);
7422 if (commonSuffix.find(
'_') == std::string::npos)
7425 commonSuffix = commonSuffix.substr(commonSuffix.find(
'_'));
7433 std::map<std::string, std::string> reducedTitles;
7434 while (reducedTitles.size() != allTitles.size()) {
7436 std::map<std::string, int> titlesMap;
7437 for (
auto &s : allTitles) {
7438 if (reducedTitles.count(s))
7440 titlesMap[s.substr(0, jj)]++;
7442 for (
auto &s : allTitles) {
7443 if (titlesMap[s.substr(0, jj)] == 1 && (jj >= s.length() || s.at(jj) ==
' ' || s.at(jj) ==
'_')) {
7444 reducedTitles[s] = s.substr(0, jj);
7450 for (
int i = ll->
GetEntries() - 1; i >= 0; i--) {
7452 _title = _title.substr(ii < _title.size() ? ii : 0);
7453 if (!commonSuffix.empty() &&
TString(_title).
EndsWith(commonSuffix.c_str()))
7454 _title = _title.substr(0, _title.length() - commonSuffix.length());
7461 *
dynamic_cast<TAttLine *
>(ll->
At(i)) = *_style;
7462 *
dynamic_cast<TAttFill *
>(ll->
At(i)) = *_style;
7467 h->GetListOfFunctions()->Add(stack,
"noclearsame");
7468 if (
h->GetSumw2() &&
h->GetSumw2()->GetSum()) {
7469 hCopy->SetFillStyle(3005);
7470 hCopy->SetFillColor(
h->GetLineColor());
7472 h->GetListOfFunctions()->Add(hCopy->Clone(
".copy"),
"e2same");
7477 h->GetListOfFunctions()->Add(hCopy,
"histsame");
7478 if (
h->GetSumw2() &&
h->GetSumw2()->GetSum()) {
7480 h->SetFillColor(
h->GetLineColor());
7481 h->SetMarkerStyle(0);
7496 auto rar = get<RooAbsReal>();
7506 if (binStart != -1 || binEnd != -1) {
7517 h =
new TH1D(rar->GetName(), rar->GetTitle(), 1, 0, 1);
7518 h->GetXaxis()->SetBinLabel(1, rar->GetName());
7519 h->GetXaxis()->SetName(rar->GetName());
7524 bool setTitle =
false;
7528 h =
new TH1D(rar->GetName(), rar->GetTitle(), 1, 0, 1);
7530 h->GetXaxis()->SetBinLabel(1, rar->GetName());
7531 h->SetBinContent(1, rar->getVal());
7533 h->SetBinError(1,
x->getError());
7534 h->SetMaximum(
x->hasMax() ?
x->getMax()
7535 : (
h->GetBinContent(1) + std::max(std::abs(
h->GetBinContent(1) * 0.1), 50.)));
7536 h->SetMinimum(
x->hasMin() ?
x->getMin()
7537 : (
h->GetBinContent(1) - std::max(std::abs(
h->GetBinContent(1) * 0.1), 50.)));
7542 TString binningName = (_ax && _ax->GetParent() ==
x) ? _ax->GetName() : rar->getStringAttribute(
"binning");
7543 if (binningName ==
"")
7544 binningName = rar->GetName();
7545 if (
x->hasBinning(binningName)) {
7546 if (
x->getBinning(binningName).isUniform()) {
7547 h =
new TH1D(rar->GetName(), rar->GetTitle(),
x->numBins(binningName) <= 0 ? 100 :
x->numBins(binningName),
7548 x->getMin(binningName),
x->getMax(binningName));
7550 h =
new TH1D(rar->GetName(), rar->GetTitle(),
x->numBins(binningName),
x->getBinning(binningName).array());
7552 h->GetXaxis()->SetTitle(
x->getBinning(binningName).GetTitle());
7554 }
else if (
auto _boundaries =
7555 _or_func( (std::list<double> *)(
nullptr),
7556 rar->binBoundaries(*
x, -std::numeric_limits<double>::infinity(),
7557 std::numeric_limits<double>::infinity()));
7559 std::vector<double> _bins;
7560 for (
auto &
b : *_boundaries) {
7561 if (_bins.empty() || std::abs(_bins.back() -
b) > 1
e-5 * _bins.back())
7564 h =
new TH1D(rar->GetName(), rar->GetTitle(), _bins.size() - 1, &_bins[0]);
7566 }
else if (!
x->hasMax() || !
x->hasMin()) {
7568 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(),
x->getVal() * 0.2,
x->getVal() * 5);
7570 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(),
x->getBinning().array());
7574 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(rar->GetName()), 0,
v->numBins(rar->GetName()));
7576 for (
int i = 0; i < cat->numTypes(); i++) {
7578 h->GetXaxis()->SetBinLabel(i + 1, cat->getLabel());
7582 if (
auto o =
dynamic_cast<TObject *
>(
v); o && !setTitle) {
7583 h->GetXaxis()->SetTitle(o->GetTitle());
7589 if (
auto s =
style(
nullptr,
false); s) {
7594 if (strlen(
h->GetXaxis()->GetTitle()) == 0)
7603 if (empty && !errors) {
7609 auto _coefs =
coefs();
7624 if (!
GETDMP(fr, _finalPars)) {
7652 for (
int i = 0; i < prevCov->
GetNcols(); i++) {
7653 for (
int j = 0; j < prevCov->
GetNrows(); j++) {
7654 cov(i, j) = (*prevCov)(i, j);
7660 if (!prevCov || i >= prevCov->
GetNcols()) {
7661 cov(i, i) = pow(
dynamic_cast<RooRealVar *
>(p2)->getError(), 2);
7665 int covQualBackup = fr->
covQual();
7676 int covQualBackup = fr->
covQual();
7684 bool hasErrors =
false;
7702 binEnd =
h->GetNbinsX();
7704 bool needBinWidth =
false;
7707 if (
x && (
p || _coefs.get() || rar->getAttribute(
"density"))) {
7709 needBinWidth =
true;
7713 spdf && spdf->
canBeExtended() && !spdf->getFloor() && !_coefs.get()) {
7725 for (
auto o : _obs) {
7727 rr->removeRange(
"coordRange");
7738 bool hasRange =
false;
7739 for (
auto o : normSet) {
7750 for (
auto pdf :
bins()) {
7757 dynamic_cast<RooAbsPdf *
>(_pdf)->setNormRange(
"coordRange");
7759 newrar->addPdf(*_pdf, pdf->coords()[
"channelCat"]->get<
RooCategory>()->getLabel());
7763 rar =
p->createProjection(
7767 dynamic_cast<RooAbsPdf *
>(rar)->setNormRange(
"coordRange");
7771 p->setNormRange(
"coordRange");
7776 rar = std::unique_ptr<RooAbsReal>{rar->createIntegral(
7782 std::unique_ptr<RooAbsReal>{rar->createIntegral(*_obs.get<
RooArgList>() )}
7788 bool scaleExpected = (
p &&
p->canBeExtended() && !_coefs.get());
7792 std::unique_ptr<RooArgSet> snap(normSet.
snapshot());
7794 std::vector<double> lapTimes;
7795 bool warned =
false;
7796 if (binStart == -1 && binEnd == -1) {
7799 for (
int i = std::max(1, binStart); i <= std::min(
h->GetNbinsX(), binEnd); i++) {
7802 x->setVal(
h->GetBinCenter(i));
7805 if (
x && !
x->inRange(
"coordRange"))
7810 r = rar->getVal(
p ? &normSet :
nullptr);
7811#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
7816 if (
r && _coefs.get()) {
7820 r *=
h->GetBinWidth(i);
7822 if (scaleExpected) {
7825 r *= (
p->expectedEvents(normSet));
7828 h->SetBinContent(i,
r);
7836 .getSimplePropagatedError(*fr, normSet);
7837#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
7839 p->_normSet =
nullptr;
7844 .getPropagatedError(
7850 res *=
h->GetBinWidth(i);
7852 h->SetBinError(i, res);
7855 lapTimes.push_back(timeIt.
RealTime());
7856 double time_estimate =
7857 (lapTimes.size() > 1)
7858 ? (
h->GetNbinsX() * (std::accumulate(lapTimes.begin() + 1, lapTimes.end(), 0.) / (lapTimes.size() - 1)))
7860 if (!warned && (lapTimes.at(0) > 10 || (lapTimes.size() > 2 && time_estimate > 60.))) {
7862 t2.
Add(time_estimate);
7863 Warning(
"BuildHistogram",
"Building this histogram will take until %s", t2.
AsString());
7873 Warning(
"BuildHistogram",
"Skipping errors for remaining bins");
7886 std::vector<RooAbsArg *> extra;
7889 for (
auto _pdf : s->servers())
7891 extra.push_back(_pdf);
7893 extra.push_back(rar);
7896 for (
auto a : extra)
7902 if (!
p && !rar->getAttribute(
"density") && !needBinWidth) {
7903 h->GetYaxis()->SetTitle(rar->getStringAttribute(
"units"));
7904 }
else if ((
p &&
p->canBeExtended()) || (!
p && needBinWidth)) {
7905 h->GetYaxis()->SetTitle(
"Events");
7907 h->GetYaxis()->SetTitle(
"Probability Mass");
7909 h->GetYaxis()->SetMaxDigits(3);
7922 return std::numeric_limits<double>::quiet_NaN();
7923 return node->GetBinContent(bin);
7929 if (binStart != binEnd || !
fParent) {
7934 std::vector<double> out;
7935 if (get<RooAbsData>()) {
7943 if (binStart == binEnd && binStart == -1) {
7946 for (
int i = 0; i <
g->GetN(); i++)
7947 integral +=
g->GetPointY(i);
7948 out.push_back(integral);
7952 for (
int i = binStart - 1; i <
g->GetN() && (binEnd == 0 || i < binEnd); i++) {
7953 out.push_back(
g->GetPointY(i));
7959 bool doIntegral =
false;
7960 if (binStart == binEnd && binStart == -1) {
7970 binEnd =
h->GetNbinsX();
7974 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
7975 tot +=
h->GetBinContent(i);
7979 for (
int i = binStart; i <= binEnd; i++) {
7980 out.push_back(
h->GetBinContent(i));
7989 if (
auto a = get<RooAbsArg>();
a) {
7991 for (
auto &
l :
a->servers()) {
8011 if (
auto o =
get(); o)
8019#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
8023 for (
int i = 0; i <
p->fCGnx; i++) {
8024 for (
int j = 0; j <
p->fCGny; j++) {
8025 p->fCollideGrid[i + j *
p->fCGnx] =
true;
8028 p->FillCollideGrid(o);
8032 Int_t nxmax =
p->fCGnx - iw - 1 -
p->fCGnx *
p->GetRightMargin();
8033 Int_t nymax =
p->fCGny - ih - 1 -
p->fCGny *
p->GetTopMargin();
8035 for (
Int_t j = nymax; j >= 0; j--) {
8036 for (
Int_t i = nxmax; i >= 0; i--) {
8037 if (
p->Collide(i, j, iw, ih)) {
8048 return p->PlaceBox(o,
w,
h, xl, yb,
"trw");
8056 gPad->PaintModified();
8062 auto l =
new TPaveText(
gPad->GetLeftMargin() + 0.02, 1. -
gPad->GetTopMargin() - 0.08, 0.6,
8063 1. -
gPad->GetTopMargin() - 0.08);
8064 l->SetBorderSize(0);
8065 if (
l->GetTextSize() == 0)
8073 l->ConvertNDCtoPad();
8079 if (
auto p =
dynamic_cast<TLegend *
>(
gPad->GetPrimitive(
"legend"));
p) {
8081 double w =
p->GetX2NDC() -
p->GetX1NDC(),
h =
p->GetY2NDC() -
p->GetY1NDC();
8083 gPad->PaintModified();
8087 x = std::max(
x, (
gPad->GetLeftMargin() + 0.02));
8088 y = std::max(
y, (
gPad->GetBottomMargin() + 0.02));
8089 x = std::min(
x, (1. -
gPad->GetRightMargin() - 0.02) -
w);
8090 y = std::min(
y, (1. -
gPad->GetTopMargin() - 0.02) -
h);
8091 h = std::min(
h, (1. -
gPad->GetTopMargin() - 0.02) -
y);
8092 w = std::min(
w, (1. -
gPad->GetRightMargin() - 0.02) -
x);
8104 while ((
p !=
p->GetMother()) && (
p =
p->GetMother())) {
8105 if (
auto q =
dynamic_cast<TVirtualPad *
>(
p->GetPrimitive(
"legend"));
q) {
8113 if (
p && strcmp(
p->
GetName(),
"legend") == 0) {
8118 gPad->GetBottomMargin());
8122 l =
new TLegend(0.6, 1. -
gPad->GetTopMargin() - 0.08, 0.75, 1. -
gPad->GetTopMargin() - 0.08);
8123 l->SetBorderSize(0);
8124 if (
l->GetTextSize() == 0)
8130 l->SetName(
"legend");
8132 l->ConvertNDCtoPad();
8143 for (
auto a : *
l->GetListOfPrimitives()) {
8144 if (!strcmp(
dynamic_cast<TLegendEntry *
>(
a)->GetLabel(), title))
8147 if (
l->GetListOfPrimitives()->GetEntries() > 20)
8150 l->AddEntry(o, title, opt);
8151 if (
auto nObj =
l->GetListOfPrimitives()->GetEntries(); nObj > 0) {
8153 int nn =
l->GetNColumns();
8155 if (nObj > 1 && (nObj % nn) == 1) {
8156 l->SetNColumns(
l->GetNColumns() + 1);
8157 l->SetX1NDC(
l->GetX2NDC() - 0.15 *
l->GetNColumns());
8159 l->SetY1NDC(
l->GetY2NDC() - 0.05 *
gPad->GetHNDC() * std::ceil((
double(nObj) /
l->GetNColumns())));
8174 fPad->GetCanvas()->Paint();
8175 fPad->GetCanvas()->Update();
8176#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
8177 fPad->GetCanvas()->ResetUpdated();
8192 if (
gROOT->FromPopUp()) {
8193 gROOT->SetFromPopUp(
false);
8196 }
catch (
const std::exception &
e) {
8199 (
gROOT->GetListOfBrowsers()->At(0))
8202 "Exception",
e.what(),
8205 gROOT->SetFromPopUp(
true);
8214 if (
auto ir = get<RooStats::HypoTestInverterResult>()) {
8218 }
else if (get<RooStats::HypoTestResult>()) {
8231 auto _dsets =
fParent->datasets();
8234 for (
auto &
d : _dsets) {
8235 if (
d->get()->TestBit(1 << 20)) {
8236 dsetName =
d->get()->GetName();
8240 auto hs =
fParent->nll(dsetName.
Data()).hypoSpace(get<RooRealVar>()->GetName());
8241 hs.limits(
"cls visualize");
8253 [](
double a,
double b,
double) {
8256 if (
b == 0 &&
a == 0)
8263 [](
double n,
double b,
double sigma) {
8267 t0 = 2. * (((
n == 0) ? 0 :
n * log(
n /
b)) - (
n -
b));
8270 double b_hathat = 0.5 * (
b - sigma2 + sqrt(pow(
b - sigma2, 2) + 4 *
n * sigma2));
8273 t0 = 2. * (((
n == 0) ? 0 :
n * log(
n / b_hathat)) + b_hathat -
n + pow(
b - b_hathat, 2) / (2. * sigma2));
8277 return (
n >=
b) ? sqrt(t0) : -sqrt(t0);
8285 std::vector<double> xPoints;
8288 int _idx = sOpt2.
Index(
"x=");
8289 int _eidx = sOpt2.
Index(
';', _idx);
8290 TString varPart = sOpt(_idx + 2, (_eidx < 0 ? sOpt2.
Length() : _eidx) - (_idx + 2));
8293 if (
auto _idx2 = varPart.
Index(
"("); _idx2 > 0) {
8294 varName = varPart(0, _idx2);
8296 double min(0), max(0);
8312 for (
double x = min;
x <= max;
x += (max - min) / (nBins - 1)) {
8313 xPoints.push_back(
x);
8315 }
else if (nBins == 1)
8316 xPoints.push_back((min + max) / 2.);
8318 v = getObject<RooAbsRealLValue>(varName.Data()).get();
8320 Error(
"Draw",
"Could not find variable %s", varName.Data());
8323 if (xPoints.empty() && !
obs().
find(varName.Data())) {
8325 for (
int i = 0; i <
v->numBins(
GetName()); i++) {
8343 }
else if (get<RooAbsPdf>()) {
8345 forceNames = sOpt(sOpt2.
Index(
"force") + 5, sOpt2.
Length());
8346 sOpt = sOpt(0, sOpt2.
Index(
"force"));
8347 sOpt2 = sOpt2(0, sOpt2.
Index(
"force"));
8349 Error(
"Draw",
"Can only compute forces with PDFs");
8353 bool hasOverlay = sOpt2.
Contains(
"overlay");
8357 overlayName = sOpt(sOpt2.
Index(
"overlay") + 7, sOpt2.
Length());
8358 sOpt = sOpt(0, sOpt2.
Index(
"overlay"));
8359 sOpt2 = sOpt2(0, sOpt2.
Index(
"overlay"));
8364 sOpt +=
"auxSignif";
8366 std::string auxPlotTitle =
"";
8377 bool nostack = sOpt.
Contains(
"nostack");
8379 bool hasSame = sOpt.
Contains(
"same");
8381 bool hasGoff = sOpt.
Contains(
"goff");
8383 bool hasFR = sOpt.
Contains(
"pull") && !get<RooFitResult>();
8385 bool hasText = sOpt.
Contains(
"text");
8386 bool hasErrorOpt = sOpt.
Contains(
"e");
8390 if (auxPlotTitle ==
"Signif")
8397 TH1 *hAxis =
nullptr;
8399 auto clearPad = []() {
8401 if (
gPad->GetNumber() == 0) {
8413 if (!hasSame || !pad) {
8424 if (hAxis =
dynamic_cast<TH1 *
>(o); hAxis)
8440 auto adjustYRange = [&](
double min,
double max,
TH1 *hh =
nullptr,
bool symmetrize =
false) {
8448 double ymin = hh->GetMinimum();
8449 double ymax = hh->GetMaximum();
8450 if (hh->GetMaximumStored() == -1111)
8452 if (hh->GetMinimumStored() == -1111) {
8462 if (hh->GetSumw2()) {
8463 double smallestErrDown3 = -std::numeric_limits<double>::infinity();
8464 double smallestErrUp3 = std::numeric_limits<double>::infinity();
8465 for (
int i = 1; i <= hh->GetNbinsX(); i++) {
8466 smallestErrDown3 = std::max(smallestErrDown3, hh->GetBinContent(i) - 3 * hh->GetBinError(i));
8467 smallestErrUp3 = std::min(smallestErrUp3, hh->GetBinContent(i) + 3 * hh->GetBinError(i));
8469 max = std::max(max, smallestErrUp3);
8470 min = std::min(min, smallestErrDown3);
8472 bool change =
false;
8484 double down = hh->GetBinContent(1) -
ymin;
8485 double up =
ymax - hh->GetBinContent(1);
8487 ymax = hh->GetBinContent(1) + down;
8489 ymin = hh->GetBinContent(1) - up;
8491 if (hh == hAxis && pad && !pad->
GetLogy() &&
ymin > 0 && (log10(
ymax) - log10(max)) >= 3) {
8495 if (hh == hAxis && pad &&
ymin == 0 && pad->
GetLogy()) {
8500 hh->SetMinimum(
ymin);
8501 hh->SetMaximum(
ymax);
8502 hh->GetYaxis()->Set(1,
ymin,
ymax);
8509 double ymax = -std::numeric_limits<double>::infinity();
8510 double ymin = std::numeric_limits<double>::infinity();
8511 for (
int i = 0; i <
gr->
GetN(); i++) {
8518 if (!xPoints.empty()) {
8523 out->SetFillColor(out->GetLineColor());
8524 out->SetMarkerStyle(0);
8525 out->SetFillStyle(hasErrorOpt ? 3005 : 0);
8527 for (
auto &
x : xPoints) {
8531 out->SetPointEYlow(out->GetN() - 1,
GetError());
8532 out->SetPointEYhigh(out->GetN() - 1, out->GetErrorYlow(out->GetN() - 1));
8538 out->Draw(
TString(hasSame ?
"L" :
"AL") + (hasErrorOpt ?
"3" :
""));
8559 gPad->GetFrame()->SetFillStyle(1001);
8560 gPad->SetTopMargin(0);
8561 gPad->SetBottomMargin(0);
8562 gPad->SetName(
"pull");
8566 Error(
"Draw",
"Couldn't find pull graph");
8569 pullGraph->SetName(
"nominal");
8573 auto scaleHist =
static_cast<TH1 *
>(pullGraph->FindObject(
"scales"));
8575 throw std::runtime_error(
"Could not find scales in fit result");
8577 for (
auto i = 0; i < pullGraph->GetN(); i++) {
8579 g->
SetName(scaleHist->GetXaxis()->GetBinLabel(i + 1));
8582 Warning(
"Draw",
"Found a non-var in the floatParsFinal list: %s - this shouldn't happen",
g->GetName());
8586 "%s=%g +/- %s [%g,%g]", strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName(), _p->getVal(),
8587 _p->hasAsymError() ?
TString::Format(
"(%g,%g)", _p->getAsymErrorHi(), _p->getAsymErrorLo()).
Data()
8589 scaleHist->GetBinContent(i + 1), scaleHist->GetBinError(i + 1)));
8590 g->SetPoint(0, pullGraph->GetPointX(i), pullGraph->GetPointY(i));
8591 g->SetPointEYhigh(0, pullGraph->GetErrorYhigh(i));
8592 g->SetPointEYlow(0, pullGraph->GetErrorYlow(i));
8593 g->SetEditable(
true);
8594 g->SetHighlight(
true);
8595 g->SetMarkerStyle(20);
8596 g->SetMarkerSize(0.5);
8604 _thisClone->AppendPad();
8617 if (
auto _simPdf = get<RooSimultaneous>(); _simPdf) {
8619 auto _channels =
bins();
8620 for (
auto &_v : _channels) {
8621 if (!_v->IsHidden())
8648 dynamic_cast<TPad *
>(pad)->DivideSquare(_size, 1
e-9, 1
e-9);
8654 std::vector<TString> chanPatterns;
8655 if (_range && strlen(_range)) {
8658 chanPatterns.emplace_back(pattern);
8661 for (
auto &_v : _channels) {
8668 chanVar.setLabel(cName);
8669 bool inRange = chanPatterns.empty();
8670 for (
auto &
p : chanPatterns)
8671 if (chanVar.inRange(
p)) {
8678 gPad->SetLeftMargin(std::min(
gPad->GetLeftMargin() * (1. /
gPad->GetWNDC()), 0.3));
8688 if (!
get() || get<RooArgList>()) {
8693 for (
auto &_v : *
this) {
8696 if (strcmp(
GetName(),
".vars") == 0) {
8700 if (strcmp(_v->get()->GetName(),
"1") == 0 || strcmp(_v->get()->GetName(),
"ONE") == 0 ||
8703 if (_v->get()->InheritsFrom(
"RooConstVar"))
8714 dynamic_cast<TPad *
>(pad)->DivideSquare(_size, 1
e-9, 1
e-9);
8717 for (
auto &_v : *
this) {
8720 if (strcmp(
GetName(),
".vars") == 0) {
8724 if (strcmp(_v->get()->GetName(),
"1") == 0 || strcmp(_v->get()->GetName(),
"ONE") == 0 ||
8727 if (_v->get()->InheritsFrom(
"RooConstVar"))
8736 gPad->SetLeftMargin(std::min(
gPad->GetLeftMargin() * (1. /
gPad->GetWNDC()), 0.3));
8754 if (
auto fr = get<RooFitResult>(); fr) {
8758 auto hist = fr->correlationHist(fr->GetName());
8759 hist->SetTitle(fr->GetTitle());
8762 hist->SetStats(
false);
8763 hist->SetDirectory(
nullptr);
8766 hist->GetXaxis()->SetTickSize(0);
8767 hist->GetYaxis()->SetTickSize(0);
8768 hist->SetMinimum(-100);
8771 gPad->SetGrid(1, 1);
8782 std::string poiName;
8785 poiName = sOpt3(sOpt3.
Index(
"breakdown:") + 10, sOpt3.
Length());
8787 std::unique_ptr<RooAbsCollection> _poi(fr->floatParsFinal().selectByAttrib(
"poi",
true));
8788 if (_poi->empty()) {
8789 throw std::runtime_error(
"No floating poi in the fit");
8790 }
else if (_poi->size() != 1) {
8791 throw std::runtime_error(
"Multiple poi in the fit");
8793 poiName = _poi->first()->GetName();
8797 throw std::runtime_error(
TString::Format(
"Cannot find parameter %s", poiName.c_str()));
8799 std::set<std::string> groups;
8800 for (
auto p : fr->floatParsFinal()) {
8803 else if (
p->getStringAttribute(
"group"))
8804 groups.insert(
p->getStringAttribute(
"group"));
8816 roundedVal.second *= .1;
8824 for (
auto group : groups) {
8826 double variance = pow(
dynamic_cast<RooRealVar *
>(
poi)->getError(), 2);
8827 for (
auto p : fr->floatParsFinal()) {
8830 else if ((
p->getStringAttribute(
"group") &&
group ==
p->getStringAttribute(
"group")) ||
8836 int idx =
pars.index(poiName.c_str());
8837 double reducedVar = fr->conditionalCovarianceMatrix(
pars)(idx, idx);
8838 if (reducedVar > variance) {
8839 Warning(
"Draw",
"breakdown group %s variance bigger than preceding?",
group.c_str());
8845 std::pair(sqrt(variance - reducedVar), roundedVal.second));
8857 double variance = fr->conditionalCovarianceMatrix(*
poi)(0, 0);
8873 out->SetTitle(
"Fit Result Pulls");
8874 std::vector<TString> graphLabels;
8877 ugraph->
SetTitle(
"Fit Result Pulls");
8878 std::vector<TString> ugraphLabels;
8879 std::map<std::string, double> scale;
8880 std::map<std::string, double>
offset;
8881 for (
auto &
p : fr->floatParsFinal()) {
8886 if (std::isnan(_v->getErrorHi()) || std::isnan(_v->getErrorLo())) {
8887 Warning(
"Draw",
"%s error is invalid", _v->GetName());
8892 double prefitError = 0;
8893 double prefitVal = 0;
8894 double customScale = 0;
8897 prefitError = ip->getError();
8898 prefitVal = ip->getVal();
8901 std::shared_ptr<xRooNode> pConstr;
8904 if (_vv->hasRange(
"pullScale")) {
8905 customScale = (_vv->getMax(
"pullScale") - _vv->getMin(
"pullScale")) / 2.;
8908 for (
auto &
c : _constr) {
8911 bool isServer =
true;
8914 for (
auto s :
c->get<
RooAbsArg>()->servers()) {
8915 if (strcmp(s->GetName(),
p->
GetName()) == 0) {
8936 if (pConstr->get<
RooPoisson>() && pConstr->find(
".x")) {
8937 std::string xName = pConstr->find(
".x")->get()->GetName();
8938 prefitVal = pConstr->find(
".x")->get<
RooAbsReal>()->getVal();
8939 for (
auto &_d : pConstr->vars()) {
8940 if (strcmp(
p->
GetName(), _d->get()->GetName()) == 0)
8942 if (xName == _d->get()->GetName())
8948 prefitVal /= prefitError;
8950 prefitError = 1. / sqrt(prefitError);
8951 }
else if (
auto _g = pConstr->get<
RooGaussian>(); _g) {
8953 (pConstr->find(
".sigma")) ? pConstr->find(
".sigma")->get<
RooAbsReal>()->getVal() : prefitError;
8955 (pConstr->find(
".x")) ? pConstr->find(
".x")->get<
RooAbsReal>()->getVal() : 0;
8956 if (pConstr->find(
".x") &&
8959 prefitVal = pConstr->find(
".mean")->get<
RooAbsReal>()->getVal();
8964 prefitError = customScale;
8965 if (prefitError == 0) {
8966 Warning(
"Draw",
"failed to determine prefit error of %s, using post-fit error",
p->
GetName());
8967 prefitError = _v->getError();
8969 out->SetPoint(out->GetN(), out->GetN(), (_v->getVal() - prefitVal) / prefitError);
8970 out->SetPointError(out->GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
8971 (_v->getErrorHi()) / prefitError);
8972 graphLabels.push_back(
p->
GetName());
8978 prefitError = customScale;
8979 if (prefitError == 0) {
8981 prefitError = (std::max({_v->getMax() - _v->getVal(), _v->getVal() - _v->getMin(), 4.}) / 4);
8982 ugraph->
SetPoint(ugraph->
GetN(), ugraph->
GetN(), (_v->getVal() - prefitVal) / prefitError);
8983 ugraph->
SetPointError(ugraph->
GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
8984 (_v->getErrorHi()) / prefitError);
8985 ugraphLabels.push_back(
p->
GetName());
8987 out->SetPoint(out->GetN(), out->GetN(), (_v->getVal() - prefitVal) / prefitError);
8988 out->SetPointError(out->GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
8989 (_v->getErrorHi()) / prefitError);
8990 graphLabels.push_back(
p->
GetName());
8998 prefitError = customScale;
8999 if (prefitError == 0) {
9000 prefitError = (std::max({_v->getMax() - _v->getVal(), _v->getVal() - _v->getMin(), 4.}) / 4);
9002 ugraph->
SetPoint(ugraph->
GetN(), ugraph->
GetN(), (_v->getVal() - prefitVal) / prefitError);
9003 ugraph->
SetPointError(ugraph->
GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
9004 (_v->getErrorHi()) / prefitError);
9005 ugraphLabels.push_back(
p->
GetName());
9013 for (
int i = 0; i < ugraph->
GetN(); i++)
9015 int nUnconstrained = ugraph->
GetN();
9018 tmpList.
Add(ugraph);
9019 graph->Merge(&tmpList);
9022 for (
auto &
l : ugraphLabels) {
9023 graphLabels.push_back(
l);
9027 graph->SetMarkerStyle(20);
9028 graph->SetMarkerSize(0.5);
9030 graph->SetMaximum(4);
9031 graph->SetMinimum(-4);
9036 std::vector<std::pair<double, std::string>> covariances;
9037 std::string poiName;
9038 double maxImpact = 0;
9042 poiName = sOpt3(sOpt3.
Index(
"impact:") + 7, sOpt3.
Length());
9044 std::unique_ptr<RooAbsCollection> _poi(fr->floatParsFinal().selectByAttrib(
"poi",
true));
9045 if (_poi->empty()) {
9046 throw std::runtime_error(
"No floating poi in the fit");
9047 }
else if (_poi->size() != 1) {
9048 throw std::runtime_error(
"Multiple poi in the fit");
9050 poiName = _poi->first()->GetName();
9052 RooAbsArg *
poi = fr->floatParsFinal().find(poiName.c_str());
9054 throw std::runtime_error(
TString::Format(
"Cannot find parameter %s", poiName.c_str()));
9056 size_t poiIdx = fr->floatParsFinal().index(*
poi);
9065 for (
auto &label : graphLabels) {
9066 covariances.emplace_back(fr->covarianceMatrix()(poiIdx, fr->floatParsFinal().index(label)) /
9067 dynamic_cast<RooRealVar *
>(fr->floatParsFinal().find(label))->getError(),
9070 std::sort(covariances.begin(), covariances.end(),
9071 [&](std::pair<double, std::string> i, std::pair<double, std::string> j) {
9072 return doHorizontal ? (std::abs(i.first) < std::abs(j.first))
9073 : (std::abs(i.first) > std::abs(j.first));
9077 std::vector<TString> sortedLabels;
9078 maxImpact = (doHorizontal) ? covariances.back().first
9079 : covariances.front().first;
9080 for (
auto &
c : covariances) {
9085 c.first *= 4. / (maxImpact * 1.2);
9086 sortedLabels.push_back(
c.second);
9088 for (; i < graphLabels.size(); i++) {
9089 if (graphLabels[i] ==
c.second) {
9099 tmpList2.
Add(&sortedGraph);
9100 graph->Merge(&tmpList2);
9102 graphLabels = sortedLabels;
9103 graph->SetTitle(
"Fit Result Impact");
9109 hist =
new TH2D(
GetName(), fr->GetTitle(), 100, -4, 4, std::max(
graph->GetN(), 1), -0.5,
9110 std::max(
graph->GetN(), 1) - 0.5);
9112 for (
auto &
l : graphLabels) {
9115 if (!graphLabels.empty())
9119 hist =
new TH2D(
GetName(), fr->GetTitle(), std::max(
graph->GetN(), 1), -0.5, std::max(
graph->GetN(), 1) - 0.5,
9122 for (
auto &
l : graphLabels) {
9125 if (!graphLabels.empty())
9133 auto histCopy =
dynamic_cast<TH1 *
>(hist->
Clone(
".axis"));
9136 auto _axis = (doHorizontal ? histCopy->GetYaxis() : histCopy->GetXaxis());
9146 graph->GetHistogram()->GetXaxis()->Set(std::max(
graph->GetN(), 1), -0.5, std::max(
graph->GetN(), 1) - 0.5);
9147 for (
int ii = 1; ii <= _axis->GetNbins(); ii++) {
9148 graph->GetHistogram()->GetXaxis()->SetBinLabel(ii, _axis->GetBinLabel(ii));
9163 gPad->Divide(1, 1, 1
e-9, 1
e-9);
9167 gPad->SetLeftMargin(0.4);
9169 gPad->SetBottomMargin(0.4);
9172 auto pNamesHist =
dynamic_cast<TH1F *
>(
graph->GetHistogram()->Clone(
"scales"));
9173 pNamesHist->
Sumw2();
9174 pNamesHist->SetDirectory(0);
9176 for (
int ii = 1; ii <=
graph->GetN(); ii++) {
9177 auto _p = fr->floatParsFinal().find(_axis->GetBinLabel(ii));
9178 pNamesHist->SetBinContent(ii,
offset[_p->GetName()]);
9179 pNamesHist->SetBinError(ii, scale[_p->GetName()]);
9180 _axis->SetBinLabel(ii, strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName());
9186 for (
int ii = 2; ii >= 1; ii--) {
9190 pullBox->SetPoint(0, (doHorizontal) ? -ii : -0.5, (doHorizontal) ? -0.5 : 0);
9191 pullBox->SetPoint(1, (doHorizontal) ? ii : (_axis->GetNbins() - 0.5 - nUnconstrained),
9192 (doHorizontal) ? -0.5 : 0);
9193 pullBox->SetPointError(0, 0, (doHorizontal) ? (_axis->GetNbins() - nUnconstrained) : ii);
9194 pullBox->SetPointError(1, 0, (doHorizontal) ? (_axis->GetNbins() - nUnconstrained) : ii);
9198 auto pullLine =
new TGraph;
9199 pullLine->
SetName(
"0sigmaLine");
9201 pullLine->SetPoint(0, -0.5, 0);
9202 pullLine->SetPoint(1, _axis->GetNbins() - 0.5, 0);
9203 pullLine->SetLineStyle(2);
9204 pullLine->SetEditable(
false);
9208 if (nUnconstrained > 0) {
9210 pullLine->
SetName(
"dividerLine");
9212 pullLine->SetPoint(0,
graph->GetN() - 0.5 - nUnconstrained, -100);
9213 pullLine->SetPoint(1,
graph->GetN() - 0.5 - nUnconstrained, 100);
9214 pullLine->SetLineStyle(2);
9215 pullLine->SetEditable(
false);
9221 new TPaveText(
gPad->GetLeftMargin(), 1. -
gPad->GetTopMargin(), 1. -
gPad->GetRightMargin(), 0.98,
"NDCNB");
9228 std::string covQualTxt;
9229 switch (fr->covQual()) {
9230 case -1: covQualTxt =
"Unknown";
break;
9231 case 0: covQualTxt =
"Not calculated";
break;
9232 case 1: covQualTxt =
"Approximate";
break;
9233 case 2: covQualTxt =
"Forced Positive-Definite";
break;
9234 case 3: covQualTxt =
"Accurate";
break;
9239 std::string statusCodes;
9240 for (
unsigned int i = 0; i < fr->numStatusHistory(); i++) {
9241 statusCodes +=
TString::Format(
" %s = %d", fr->statusLabelHistory(i), fr->statusCodeHistory(i));
9248 gPad->SetTicks(0, 0);
9252 if (
int(
gPad->GetCanvas()->GetWh()) < pNamesHist->GetNbinsX() * 15) {
9253 gPad->GetCanvas()->SetCanvasSize(
gPad->GetCanvas()->GetWw(), pNamesHist->GetNbinsX() * 15);
9257 double factor = 475. /
gPad->GetCanvas()->GetWh();
9262 new TGaxis(_axis->GetXmin(), -4, _axis->GetXmin(), 4, -1.2 * maxImpact, 1.2 * maxImpact, 510,
"-S");
9266 : ((
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(10 / factor)) /
9275 : ((
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(10 / factor)) / (
gPad->GetY2() -
gPad->GetY1())));
9280 : ((
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(10 / factor)) / (
gPad->GetY2() -
gPad->GetY1())));
9283 _axis->SetLabelSize(
9284 (_axis->GetLabelFont() % 10 > 2)
9286 : ((
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(10 / factor)) / (
gPad->GetY2() -
gPad->GetY1())));
9287 histCopy->GetXaxis()->SetTickLength(histCopy->GetXaxis()->GetTickLength() * factor);
9289 histCopy->GetYaxis()->SetTickLength(histCopy->GetYaxis()->GetTickLength() * factor);
9291 histCopy->GetXaxis()->SetTitleOffset(histCopy->GetXaxis()->GetTitleOffset() * factor);
9292 histCopy->GetXaxis()->SetLabelOffset(histCopy->GetXaxis()->GetLabelOffset() * factor);
9295 histCopy->GetXaxis()->SetTitleOffset(histCopy->GetXaxis()->GetTitleOffset() * factor);
9296 histCopy->GetXaxis()->SetLabelOffset(histCopy->GetXaxis()->GetLabelOffset() * factor);
9300 for (
int tt = 0;
tt < 2;
tt++) {
9301 auto impact =
static_cast<TH1 *
>(
9304 impact->GetYaxis()->SetTitle(
TString::Format(
"#Delta%s/#sigma", poiName.c_str()));
9305 impact->SetBarWidth(0.9);
9306 impact->SetBarOffset(0.05);
9307 impact->SetLineColor(
kBlack);
9308 impact->SetFillColor(
kAzure - 4);
9309 impact->SetFillStyle(
tt == 0 ? 3013 : 1001);
9311 static_cast<TH1 *
>(impact->Clone(
TString::Format(
"%s_impact-",
tt == 0 ?
"prefit" :
"postfit")));
9313 impact2->SetFillColor(
kCyan);
9314 for (
int ii = 1; ii <= pNamesHist->GetNbinsX(); ii++) {
9315 for (
auto &
c : covariances) {
9316 if (
c.second != pNamesHist->GetXaxis()->GetBinLabel(ii))
9318 auto vv =
dynamic_cast<RooRealVar *
>(fr->floatParsFinal().find(
c.second.c_str()));
9319 auto vv_init =
dynamic_cast<RooRealVar *
>(fr->floatParsInit().find(
c.second.c_str()));
9320 impact->SetBinContent(ii, ((
tt == 0 && !vv_init->hasError()) || !
vv->hasError())
9322 :
c.first *
vv->getError() /
vv->getErrorHi() *
9323 (
tt == 0 ? (vv_init->getErrorHi() /
vv->getErrorHi()) : 1.));
9324 impact2->SetBinContent(ii, ((
tt == 0 && !vv_init->hasError()) || !
vv->hasError())
9326 :
c.first *
vv->getError() /
vv->getErrorLo() *
9327 (
tt == 0 ? (vv_init->getErrorLo() /
vv->getErrorLo()) : 1.));
9334 for (
int ii = -1; ii <= 1; ii++) {
9335 auto pullLine =
new TGraph;
9338 pullLine->SetPoint(0, -0.5, ii);
9339 pullLine->SetPoint(1, hist->
GetNbinsY() - 0.5, ii);
9340 pullLine->SetLineStyle(2);
9341 pullLine->SetEditable(
false);
9346 new TLegend(0.02, doHorizontal ? (1. - 0.22 * factor) : 0.02, 0.27, (doHorizontal ? 1. : 0.24));
9353 : ((
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(10 / factor)) /
9359 leg1->
AddEntry(hist->
FindObject(
"prefit_impact+"),
"#theta = #hat{#theta}+#Delta#theta",
"f");
9360 leg1->
AddEntry(hist->
FindObject(
"prefit_impact-"),
"#theta = #hat{#theta}-#Delta#theta",
"f");
9363 leg1->
AddEntry(hist->
FindObject(
"postfit_impact+"),
"#theta = #hat{#theta}+#Delta#theta",
"f");
9364 leg1->
AddEntry(hist->
FindObject(
"postfit_impact-"),
"#theta = #hat{#theta}-#Delta#theta",
"f");
9370 new TPaveText(
gPad->GetLeftMargin(), 1. -
gPad->AbsPixeltoY(14), 1. -
gPad->GetRightMargin(), 1.,
"NDC");
9377 : ((
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(10 / factor)) / (
gPad->GetY2() -
gPad->GetY1())));
9380 title->
AddText(histCopy->GetTitle());
9385 graph->SetEditable(
false);
9386 pNamesHist->SetLineWidth(0);
9387 pNamesHist->SetMarkerSize(0);
9388 graph->GetListOfFunctions()->Add(pNamesHist,
"same");
9392 for (
int p = 0;
p <
graph->GetN();
p++) {
9395 graph->GetErrorXhigh(
p));
9398 if (
f->InheritsFrom(
"TH1")) {
9407 else if (
auto g =
dynamic_cast<TGraph *
>(
f)) {
9408 for (
int p = 0;
p <
g->GetN();
p++) {
9409 g->SetPoint(
p,
g->GetPointY(
p),
g->GetPointX(
p));
9412 }
else if (
auto l =
dynamic_cast<TLine *
>(
f)) {
9415 l->
SetY1(_axis->GetXmax());
9416 l->
SetY2(_axis->GetXmax());
9422 graph->SetName(
"pulls");
9427 histCopy->Draw((sOpt.
Contains(
"impact") && !doHorizontal)
9442 auto hh =
dynamic_cast<TH1 *
>(histCopy->Clone(
".axiscopy"));
9446 (sOpt.
Contains(
"impact") && !doHorizontal)
9459 for (
auto c : s->bins()) {
9460 auto _pad =
dynamic_cast<TPad *
>(
gPad->GetPrimitive(
c->GetName()));
9463 auto ds =
c->datasets().find(
GetName());
9465 std::cout <<
" no ds " <<
GetName() << std::endl;
9477 if (!s && hasSame) {
9480 bool doneDraw =
false;
9481 for (
auto o : *
gPad->GetListOfPrimitives()) {
9496 auto dataGraph =
BuildGraph(
v,
false, (!s && hasSame) ?
gPad :
nullptr);
9501 dataGraph->SetMarkerSize(dataGraph->GetMarkerSize() *
gPad->GetWNDC());
9506 for (
int i = 0; i < dataGraph->GetN(); i++)
9507 tot += dataGraph->GetPointY(i);
9508 dataGraph->Scale(1. / tot);
9513 dataGraph->Draw(
"Az0p");
9514 addLegendEntry(dataGraph, strlen(dataGraph->GetTitle()) ? dataGraph->GetTitle() :
GetName(),
"pEX0");
9520 bool noPoint =
false;
9523 for (
auto o : *
gPad->GetListOfPrimitives()) {
9524 if (
auto h =
dynamic_cast<TH1 *
>(o);
9525 h && strcmp(
h->GetXaxis()->GetName(),
dynamic_cast<TObject *
>(
v)->
GetName()) == 0) {
9526 dataGraph->SetPointY(0,
h->Interpolate(dataGraph->GetPointX(0)));
9533 if (
auto _pad =
dynamic_cast<TPad *
>(
gPad->FindObject(
"auxPad")); _pad) {
9534 if (
auto h =
dynamic_cast<TH1 *
>(_pad->GetPrimitive(
"auxHist"));
h) {
9537 histName = histName(0, histName.
Index(
'|'));
9538 if (
auto mainHist =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(histName));
9542 auto ratioGraph =
dynamic_cast<TGraphAsymmErrors *
>(dataGraph->Clone(dataGraph->GetName()));
9544 for (
int i = 0; i < ratioGraph->GetN(); i++) {
9545 double val = ratioGraph->GetPointY(i);
9546 int binNum = mainHist->FindFixBin(ratioGraph->GetPointX(i));
9547 double nom = mainHist->GetBinContent(binNum);
9548 double nomerr = mainHist->GetBinError(binNum);
9550 std::get<0>(
auxFunctions[
h->GetYaxis()->GetTitle()])(ratioGraph->GetPointY(i), nom, nomerr);
9551 double yup = std::get<0>(
auxFunctions[
h->GetYaxis()->GetTitle()])(val + ratioGraph->GetErrorYhigh(i),
9554 double ydown = yval - std::get<0>(
auxFunctions[
h->GetYaxis()->GetTitle()])(
9555 val - ratioGraph->GetErrorYlow(i), nom, nomerr);
9556 if (!std::isnan(yval)) {
9557 ratioGraph->SetPointY(i, yval);
9558 if (!std::isnan(yup))
9559 ratioGraph->SetPointEYhigh(i, yup);
9560 if (!std::isnan(ydown))
9561 ratioGraph->SetPointEYlow(i, ydown);
9566 while (i < ratioGraph->GetN()) {
9567 if (ratioGraph->GetPointY(i) == 0 && ratioGraph->GetErrorYhigh(i) == 0 &&
9568 ratioGraph->GetErrorYlow(i) == 0)
9569 ratioGraph->RemovePoint(i);
9573 auto _tmpPad =
gPad;
9575 ratioGraph->Draw(
"z0psame");
9576 auto minMax = graphMinMax(ratioGraph);
9577 adjustYRange(minMax.first, minMax.second,
h, std::get<1>(
auxFunctions[
h->GetYaxis()->GetTitle()]));
9583 dataGraph->Draw(
"z0p same");
9584 addLegendEntry((noPoint) ?
nullptr : dataGraph, strlen(dataGraph->GetTitle()) ? dataGraph->GetTitle() :
GetName(),
9585 noPoint ?
"" :
"pEX0");
9588 adjustYRange(minMax.first, minMax.second);
9604 gr->
Draw(hasSame ?
"P" :
"AP");
9608 if (forceNames !=
"") {
9611 bool _drawn =
false;
9617 std::vector<double> valuesToDo = {initPar->
getVal()};
9618 if (initPar->hasError() || initPar->hasAsymError()) {
9619 valuesToDo.push_back(initPar->getVal() + initPar->getErrorLo());
9620 valuesToDo.push_back(initPar->getVal() + initPar->getErrorHi());
9623 for (
auto valueToDo : valuesToDo) {
9625 for (
auto &
d : _dsets) {
9626 if (!
d->get()->TestBit(1 << 20))
9630 auto _obs =
d->obs();
9631 auto x = _obs.find((
v) ?
dynamic_cast<TObject *
>(
v)->
GetName() : emptyHist->GetXaxis()->GetName());
9635 for (
int i = 0; i < nevent; i++) {
9638 for (
const auto &_c : _coords) {
9640 if (cat->getIndex() != theData->get()->getCatIndex(cat->GetName())) {
9650 auto val = _nll.pars()->getRealValue(initPar->GetName());
9652 _nll.pars()->setRealValue(initPar->GetName(), valueToDo);
9653 auto nllVal = _nll.getEntryVal(i);
9654 _nll.pars()->setRealValue(initPar->GetName(), initPar->getVal());
9655 auto nllVal2 = _nll.getEntryVal(i);
9656 _nll.pars()->setRealValue(initPar->GetName(), val);
9662 auto val = _nll.pars()->getRealValue(initPar->GetName());
9664 _nll.pars()->setRealValue(initPar->GetName(), valueToDo);
9665 auto _extTerm = _nll.extendedTerm();
9666 _nll.pars()->setRealValue(initPar->GetName(), initPar->getVal());
9667 auto _extTerm2 = _nll.extendedTerm();
9668 _nll.pars()->setRealValue(initPar->GetName(), val);
9669 for (
int i = 1; i <= emptyHist->GetNbinsX(); i++) {
9670 emptyHist->SetBinContent(i,
9671 emptyHist->GetBinContent(i) + (_extTerm2 - _extTerm) / emptyHist->GetNbinsX());
9672 emptyHist->SetBinError(i, 0);
9674 emptyHist->GetYaxis()->SetTitle(
"log (L(#theta)/L(#theta_{0}))");
9675 emptyHist->SetTitle(
TString::Format(
"#theta = %g", (ii > 1) ? valueToDo : val));
9677 emptyHist->SetLineColor(
kBlack);
9679 emptyHist->SetLineColor(
kRed);
9681 emptyHist->SetLineColor(
kBlue);
9682 emptyHist->Draw(_drawn ?
"same" :
"");
9689 auto rar = get<RooAbsReal>();
9709 v = getObject<RooAbsLValue>(
h->GetXaxis()->GetName()).get();
9711 if (
h->GetXaxis()->IsAlphanumeric()) {
9716 if (rar->InheritsFrom(
"RooAbsPdf") && !(rar->InheritsFrom(
"RooRealSumPdf") || rar->InheritsFrom(
"RooAddPdf"))) {
9719 rar->leafNodeServerList(&s);
9733 ss +=
TString::Format(
"%s=%g", strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName(), _v->getVal());
9734 if (_v->hasError()) {
9745 gPad->SetGrid(0, 0);
9747 gPad->SetGrid(1, 1);
9751 h->GetNbinsX() == 1 || rar->getAttribute(
"BinnedLikelihood") ||
9753 std::unique_ptr<std::list<double>>(rar->binBoundaries(*
dynamic_cast<RooAbsRealLValue *
>(
vv),
9754 -std::numeric_limits<double>::infinity(),
9755 std::numeric_limits<double>::infinity()))))
9761 if (dOpt ==
"LF2" && !
components().empty()) {
9764 bool allHist =
true;
9778 gROOT->SetEditHistograms(
true);
9780 gROOT->SetEditHistograms(
false);
9793 bool hasError(
false);
9794 for (
int i = 0; i <
h->GetSumw2N(); i++) {
9795 if (
h->GetSumw2()->At(i)) {
9806 if (!hasSame &&
h->GetYaxis()->GetTitleFont() % 10 == 2) {
9807 h->GetYaxis()->SetTitleOffset(1.);
9810 TH1 *errHist =
nullptr;
9813 h->SetFillColor(
h->GetLineColor());
9814 h->SetMarkerStyle(0);
9815 errHist =
dynamic_cast<TH1 *
>(
h->Clone(
Form(
"%s_err",
h->GetName())));
9819 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
9820 h->SetBinError(i, 0);
9832 auto _hist = (errHist) ? errHist :
h;
9833 auto hCopy = (errHist) ?
nullptr :
dynamic_cast<TH1 *
>(
h->Clone());
9836 _hist->GetListOfFunctions()->Add(node);
9837 _hist->GetListOfFunctions()->Add(
new TExec(
9840 "gROOT->SetEditHistograms(true);auto h = dynamic_cast<TH1*>(gPad->GetPrimitive(\"%s\")); if(h) { double "
9841 "range= h->GetMaximum()-h->GetMinimum(); if(auto n "
9842 "= dynamic_cast<xRooNode*>(h->GetListOfFunctions()->FindObject(\"%s\")); n && "
9843 "n->TestBit(TObject::kNotDeleted) && n->get<RooRealVar>()->getVal() != h->GetBinContent(1)) {"
9844 "h->SetBinContent(1, "
9845 "TString::Format(\"%%.2g\",int(h->GetBinContent(1)/(range*0.01))*range*0.01).Atof());n->SetContent( "
9846 "h->GetBinContent(1) ); for(auto pp : *h->GetListOfFunctions()) if(auto hh = "
9847 "dynamic_cast<TH1*>(pp))hh->SetBinContent(1,h->GetBinContent(1));} if(h->GetBinContent(1)==0.) "
9848 "h->SetBinContent(1,range*0.005); gPad->Modified();gPad->Update(); }",
9849 _hist->GetName(), node->GetName())));
9855 _hist->GetListOfFunctions()->Add(hCopy,
"TEXT HIST same");
9856 _hist->SetBinError(1, 0);
9858 _hist->SetStats(
false);
9860 _hist->Draw(((errHist) ?
"e2" :
""));
9865 bool overlayExisted =
false;
9868 if (
auto existing =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(
h->GetName())); existing) {
9873 overlayExisted =
true;
9875 TString oldStyle = (rar && rar->getStringAttribute(
"style")) ? rar->getStringAttribute(
"style") :
"";
9876 h->SetTitle(overlayName);
9902 rar->setStringAttribute(
"style", oldStyle ==
"" ?
nullptr : oldStyle.
Data());
9926 h->Draw(dOpt + sOpt);
9935 std::map<std::string, int> colorByTitle;
9936 std::set<std::string> allTitles;
9937 bool titleMatchName =
true;
9938 std::map<std::string, TH1 *> histGroups;
9939 std::vector<TH1 *> hhs;
9945 if (!rarNode->components().empty()) {
9946 auto comps = rarNode->components()[0];
9947 for (
auto &
c : *comps) {
9948 if (
c->fFolder ==
"!.coeffs")
9952 if (!cms_coefs.
empty()) {
9954 std::shared_ptr<TH1> prevHist((
TH1 *)
h->Clone());
9955 for (
auto c : cms_coefs) {
9957 std::unique_ptr<RooAbsReal>
f(
9958 dynamic_cast<RooAbsReal *
>(rarNode->components()[0]->get()->
Clone(
"tmpCopy")));
9960 Form(
"ORIGNAME:%s",
c->GetName()));
9961 f->redirectServers(
RooArgSet(zero),
false,
true);
9967 if (strlen(hh->GetTitle()) == 0)
9968 hh->SetTitle(
c->GetName());
9969 titleMatchName &= (
TString(
c->GetName()) == hh->GetTitle() ||
9971 std::shared_ptr<TH1> nextHist((
TH1 *)hh->Clone());
9972 hh->Add(prevHist.get(), -1.);
9975 prevHist = nextHist;
9978 for (
auto &samp : rarNode->components()) {
9979 auto hh = samp->BuildHistogram(
v);
9983 if (strlen(hh->GetTitle()) == 0)
9984 hh->SetTitle(samp->GetName());
9985 titleMatchName &= (
TString(samp->GetName()) == hh->GetTitle() ||
9989 for (
auto &hh : hhs) {
9991 if (histGroups.find(hh->GetTitle()) == histGroups.end()) {
9992 histGroups[hh->GetTitle()] = hh;
9995 histGroups[hh->GetTitle()]->Add(hh);
9999 auto hhMin = (hh->GetMinimum() == 0) ? hh->GetMinimum(1
e-9) : hh->GetMinimum();
10000 if (!stack->
GetHists() &&
h->GetMinimum() > hhMin) {
10002 if (hhMin >= 0 && newMin < 0)
10003 newMin = hhMin * 0.99;
10004 adjustYRange(newMin,
h->GetMaximum());
10017 stack->
Add(hh, thisOpt);
10018 allTitles.insert(hh->GetTitle());
10021 stack->
Draw(
"noclear same");
10025 h->Draw(
"axissame");
10032 size_t e = std::min(allTitles.begin()->size(), allTitles.rbegin()->size());
10034 bool goodPrefix =
false;
10035 std::string commonSuffix;
10036 if (titleMatchName && ll->
GetEntries() > 1) {
10037 while (ii <
e - 1 && allTitles.begin()->at(ii) == allTitles.rbegin()->at(ii)) {
10039 if (allTitles.begin()->at(ii) ==
'_' || allTitles.begin()->at(ii) ==
' ')
10045 while (!stop && commonSuffix.size() <
size_t(
e - 1)) {
10046 commonSuffix = allTitles.begin()->substr(allTitles.begin()->length() - commonSuffix.length() - 1);
10047 for (
auto &t : allTitles) {
10049 commonSuffix = commonSuffix.substr(1);
10055 if (commonSuffix.find(
'_') == std::string::npos)
10058 commonSuffix = commonSuffix.substr(commonSuffix.find(
'_'));
10066 std::map<std::string, std::string> reducedTitles;
10067 while (reducedTitles.size() != allTitles.size()) {
10069 std::map<std::string, int> titlesMap;
10070 for (
auto &s : allTitles) {
10071 if (reducedTitles.count(s))
10073 titlesMap[s.substr(0, jj)]++;
10075 for (
auto &s : allTitles) {
10076 if (titlesMap[s.substr(0, jj)] == 1 && (jj >= s.length() || s.at(jj) ==
' ' || s.at(jj) ==
'_')) {
10077 reducedTitles[s] = s.substr(0, jj);
10083 for (
int i = ll->
GetEntries() - 1; i >= 0; i--) {
10085 _title = _title.substr(ii < _title.size() ? ii : 0);
10086 if (!commonSuffix.empty() &&
TString(_title).
EndsWith(commonSuffix.c_str()))
10087 _title = _title.substr(0, _title.length() - commonSuffix.length());
10094 for (
auto ho : *ll) {
10095 TH1 *hh =
dynamic_cast<TH1 *
>(ho);
10098 bool createdStyle = (
xRooNode(*hh, *
this).
style(
nullptr,
false) ==
nullptr);
10100 if (createdStyle) {
10107 for (
auto ho2 : *ll) {
10108 TH1 *hh2 =
dynamic_cast<TH1 *
>(ho2);
10122 *
dynamic_cast<TAttLine *
>(hh) = *_style;
10123 *
dynamic_cast<TAttFill *
>(hh) = *_style;
10129 }
else if (!overlayExisted) {
10140 errHist->
Draw(dOpt + (dOpt.
Contains(
"LF2") ?
"e3same" :
"e2same"));
10141 double ymax = -std::numeric_limits<double>::infinity();
10142 double ymin = std::numeric_limits<double>::infinity();
10143 for (
int i = 1; i <= errHist->
GetNbinsX(); i++) {
10149 adjustYRange(
h->GetMinimum() * 0.9,
h->GetMaximum() * 1.1);
10152 if ((!auxPlotTitle.empty()) && !hasSame) {
10154 double padFrac = 0.3;
10155 auto _tmpPad =
gPad;
10156 gPad->SetBottomMargin(padFrac);
10157 auto ratioPad =
new TPad(
"auxPad",
"aux plot", 0, 0, 1, padFrac);
10158 ratioPad->SetFillColor(_tmpPad->GetFillColor());
10159 ratioPad->SetNumber(1);
10160 ratioPad->SetBottomMargin(ratioPad->GetBottomMargin() / padFrac);
10161 ratioPad->SetTopMargin(0.04);
10162 ratioPad->SetLeftMargin(
gPad->GetLeftMargin());
10163 ratioPad->SetRightMargin(
gPad->GetRightMargin());
10165 TH1 *ratioHist =
dynamic_cast<TH1 *
>((errHist) ? errHist->
Clone(
"auxHist") :
h->
Clone(
"auxHist"));
10174 auxPlotTitle.c_str()));
10177 ratioPad->SetGridy();
10179 for (
int i = 1; i <= ratioHist->
GetNbinsX(); i++) {
10187 double rHeight = 1. / padFrac;
10195#if ROOT_VERSION_CODE < ROOT_VERSION(6, 26, 00)
10204 auto _h =
dynamic_cast<TH1 *
>(ratioHist->
Clone(
"auxHist_clone"));
10206 _h->SetFillColor(0);
10212 TString::Format(
"auto h1 = (TH1*)%p; auto h2 = (TH1*)%p; if(h2->GetXaxis()->GetFirst() != "
10213 "h1->GetXaxis()->GetFirst() || h1->GetXaxis()->GetLast()!=h2->GetXaxis()->GetLast()) "
10214 "{h2->GetXaxis()->SetRange(h1->GetXaxis()->GetFirst(),h1->GetXaxis()->GetLast());if(gPad) "
10215 "{gPad->GetCanvas()->Paint();gPad->GetCanvas()->Update();}}",
10216 (
void *)ratioHist, (
void *)(
h))));
10217 ratioHist->
Draw((errHist ?
"e2" :
""));
10221 }
else if (
auto ratioPad =
dynamic_cast<TPad *
>(
gPad->GetPrimitive(
"auxPad")); hasSame && ratioPad) {
10225 if (
auto hr =
dynamic_cast<TH1 *
>(ratioPad->GetPrimitive(
"auxHist"));
10227 TString histName = hr->GetTitle();
10229 histName = histName(0, histName.
Index(
'|'));
10231 if (
auto hnom =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(histName)); hnom) {
10232 h =
dynamic_cast<TH1 *
>(
h->Clone(
h->GetName()));
10235 for (
int i = 1; i <= hnom->GetNbinsX(); i++) {
10236 double val =
h->GetBinContent(i);
10237 double err =
h->GetBinError(i);
10238 h->SetBinContent(i, std::get<0>(
auxFunctions[hr->GetYaxis()->GetTitle()])(
10239 h->GetBinContent(i), hnom->GetBinContent(i), hnom->GetBinError(i)));
10240 h->SetBinError(i, std::get<0>(
auxFunctions[hr->GetYaxis()->GetTitle()])(
10241 val + err, hnom->GetBinContent(i), hnom->GetBinError(i)) -
10242 h->GetBinContent(i));
10244 auto _tmpPad =
gPad;
10247 if (
auto existing =
dynamic_cast<TH1 *
>(ratioPad->GetPrimitive(
h->GetName())); existing) {
10252 overlayExisted =
true;
10259 double ymax = -std::numeric_limits<double>::infinity();
10260 double ymin = std::numeric_limits<double>::infinity();
10261 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
10262 ymax = std::max(
ymax,
h->GetBinContent(i) +
h->GetBinError(i));
10263 ymin = std::min(
ymin,
h->GetBinContent(i) -
h->GetBinError(i));
10292 if (
auto _pdf = get<RooAbsPdf>();
10293 !hasSame && _pdf &&
coefs().empty()) {
10296 for (
auto &
d : _dsets) {
10297 if (
d->get()->TestBit(1 << 20)) {
10316 if (
auto w = get<RooWorkspace>();
w) {
10319#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
10328 Error(
"SaveAs",
"json format workspaces only in ROOT 6.26 onwards");
10333#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
10337 for (
auto &
c :
w->components()) {
10338 c->_eocache =
nullptr;
10342 if (!
w->writeToFile(
filename, sOpt !=
"update")) {
10346 if (
auto fitDb =
dynamic_cast<TFile *
>(
gROOT->GetListOfFiles()->FindObject(
"fitDatabase"))) {
10351 auto dir =
dest->GetDirectory(source->
GetName());
10356 auto key =
dynamic_cast<TKey *
>(k);
10366 if (dir->FindKey(key->GetName()))
10369 if (strcmp(classname,
"ROOT::Fit::FitConfig") == 0) {
10371 dir->WriteObject(fc, key->GetName());
10374 TObject *obj = key->ReadObj();
10376 dir->WriteTObject(obj, key->
GetName());
10383 CopyDir(fitDb, std::make_unique<TFile>(
filename,
"UPDATE").
get());
10390#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
10392 for (
auto &
c :
w->components()) {
10393 c->setExpensiveObjectCache(
w->expensiveObjectCache());
10403 return std::numeric_limits<double>::quiet_NaN();
10410 double err = std::numeric_limits<double>::quiet_NaN();
10412 std::unique_ptr<RooAbsCollection> _snap;
10417 _pars = _fr->floatParsFinal();
10418 _pars = _fr->constPars();
10422 auto _coefs =
coefs();
10430 p->setNormRange(rangeName);
10431#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 27, 00)
10434 out *=
p->expectedEvents(*_obs.get<
RooArgList>());
10435#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
10437 p->_normSet =
nullptr;
10441 p->setNormRange(
nullptr);
10442 }
else if (
auto p2 =
dynamic_cast<RooAbsReal *
>(
get()); p2) {
10444 auto f = std::shared_ptr<RooAbsReal>(
10445 p2->createIntegral(*std::unique_ptr<RooArgSet>(p2->getObservables(*_obs.get<
RooArgList>())),
10449 out *=
f->getVal();
10452 }
else if (get<RooAbsData>()) {
10455 auto ax = (rangeName) ?
GetXaxis() :
nullptr;
10456 auto rv = (ax) ?
dynamic_cast<RooRealVar *
>(ax->GetParent()) :
nullptr;
10457 auto cv = (ax && !rv) ?
dynamic_cast<RooCategory *
>(ax->GetParent()) :
nullptr;
10459 for (
auto &
v : vals) {
10462 if (rv && !rv->inRange(ax->GetBinCenter(i), rangeName))
10464 if (cv && !cv->isStateInRange(rangeName, ax->GetBinLabel(i)))
10471 out = std::numeric_limits<double>::quiet_NaN();
10474 _pars.RooAbsCollection::operator=(*_snap);
10476 return std::make_pair(out, err);
10488 if (binStart != binEnd || !
fParent) {
10494 std::vector<double> out;
10500 std::shared_ptr<RooFitResult> fr = std::dynamic_pointer_cast<RooFitResult>(_fr.
fComp);
10503 auto _coefs =
coefs();
10513 fr = std::dynamic_pointer_cast<RooFitResult>(frn.fComp);
10516 if (!
GETDMP(fr.get(), _finalPars)) {
10540 if (!prevCov ||
size_t(prevCov->
GetNcols()) < fr->floatParsFinal().size()) {
10543 for (
int i = 0; i < prevCov->
GetNcols(); i++) {
10544 for (
int j = 0; j < prevCov->
GetNrows(); j++) {
10545 cov(i, j) = (*prevCov)(i, j);
10550 for (
auto &
p : fr->floatParsFinal()) {
10551 if (!prevCov || i >= prevCov->
GetNcols()) {
10552 cov(i, i) = pow(
dynamic_cast<RooRealVar *
>(
p)->getError(), 2);
10556 int covQualBackup = fr->covQual();
10557 fr->setCovarianceMatrix(cov);
10558 fr->setCovQual(covQualBackup);
10561 bool doBinWidth =
false;
10562 auto ax = (binStart == -1 && binEnd == -1) ?
nullptr :
GetXaxis();
10569 normSet.
add(*
dynamic_cast<RooAbsArg *
>(ax->GetParent()));
10572 if (
auto p =
dynamic_cast<RooAbsPdf *
>(o); ax && (
p || _coefs.get() || o->getAttribute(
"density"))) {
10578 binEnd = ax->GetNbins();
10582 for (
int bin = binStart; bin <= binEnd; bin++) {
10584 dynamic_cast<RooAbsLValue *
>(ax->GetParent())->setBin(bin - 1, ax->GetName());
10591#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
10593 p->_normSet =
nullptr;
10603 .getPropagatedError(*fr, normSet);
10606 res *= ax->GetBinWidth(bin);
10608 out.push_back(res);
10615 std::string cling::printValue(
const xRooNode *
v ) {
10616 if(!
v)
return "nullptr\n";
10619 size_t left =
v->size();
10622 if(!out.empty()) out +=
",";
else out +=
"{";
10623 out +=
n->GetName();
10624 if(out.length()>100 && left > 0) {
10634 return "<empty node>";
10636 return Form(
"Name: %s",
v->GetName());
#define ROOT_VERSION(a, b, c)
#define ROOT_VERSION_CODE
RooAbsTestStatistic * create(const char *name, const char *title, RooAbsReal &real, RooAbsData &adata, const RooArgSet &projDeps, RooAbsTestStatistic::Configuration const &cfg) override
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
static void indent(ostringstream &buf, int indent_level)
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
winID h TVirtualViewer3D TVirtualGLPainter p
winID h TVirtualViewer3D vv
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void funcs
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
double GetBinLowEdge(Int_t bin) const override
Return low edge of bin.
double GetBinUpEdge(Int_t bin) const override
Return up edge of bin.
Int_t FindFixBin(double x) const override
Find bin number corresponding to abscissa x.
void Set(Int_t nbins, const double *xbins) override
Initialize axis with variable bins.
RooAbsRealLValue * rvar() const
void SetTitle(const char *title) override
Set the title of the TNamed.
void Set(Int_t nbins, double xmin, double xmax) override
Initialize axis with fix bins.
Int_t FindFixBin(const char *label) const override
Find bin number with label.
RooAbsLValue * var() const
const RooAbsBinning * binning() const
void Set(Int_t nbins, const float *xbins) override
Initialize axis with variable bins.
const char * GetTitle() const override
Returns title of object.
double GetBinWidth(Int_t bin) const override
Return bin width.
PadRefresher(TVirtualPad *p)
A class which maps the current values of a RooRealVar (or a set of RooRealVars) to one of a number of...
bool isBinnedDistribution(const RooArgSet &obs) const override
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
bool selfNormalized() const override
Shows if a PDF is self-normalized, which means that no attempt is made to add a normalization term.
double getSimplePropagatedError(const RooFitResult &fr, const RooArgSet &nset_in) const
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
std::list< double > * binBoundaries(RooAbsRealLValue &obs, double xlo, double xhi) const override
Retrieve bin boundaries if this distribution is binned in obs.
PdfWrapper(const PdfWrapper &other, const char *name=0)
PdfWrapper(RooAbsReal &f, RooAbsReal *coef, bool expEvMode=false, RooAbsPdf *expPdf=nullptr)
virtual TObject * clone(const char *newname) const override
The PiecewiseInterpolation is a class that can morph distributions into each other,...
static std::shared_ptr< RooLinkedList > createNLLOptions()
static std::pair< std::shared_ptr< RooAbsData >, std::shared_ptr< const RooAbsCollection > > generateFrom(RooAbsPdf &pdf, const RooFitResult &fr, bool expected=false, int seed=0)
static xRooNLLVar createNLL(const std::shared_ptr< RooAbsPdf > pdf, const std::shared_ptr< RooAbsData > data, const RooLinkedList &nllOpts)
static std::pair< double, double > matchPrecision(const std::pair< double, double > &in)
void Draw(Option_t *opt="") override
Default Draw method for all objects.
std::shared_ptr< xRooHypoPoint > asimov(bool readOnly=false)
std::shared_ptr< const RooFitResult > ufit(bool readOnly=false)
std::shared_ptr< const RooFitResult > cfit_null(bool readOnly=false)
std::shared_ptr< const RooFitResult > cfit_alt(bool readOnly=false)
std::shared_ptr< const RooFitResult > gfit()
void Draw(Option_t *opt="") override
Default Draw method for all objects.
This xRooNLLVar object has several special methods, e.g.
xRooHypoSpace hypoSpace(const char *parName, int nPoints, double low, double high, double alt_value=std::numeric_limits< double >::quiet_NaN(), const xRooFit::Asymptotics::PLLType &pllType=xRooFit::Asymptotics::Unknown)
The xRooNode class is designed to wrap over a TObject and provide functionality to aid with interacti...
void _Add_(const char *name, const char *opt)
xRooNode filter(const xRooNode &range) const
void _scan_(const char *what="plr", double nToys=0, const char *xvar="", int nPointsX=0, double lowX=0, double highX=0, const char *constParValues="")
std::vector< std::shared_ptr< xRooNode > > fBrowsables
xRooNLLVar nll(const xRooNode &_data, std::initializer_list< RooCmdArg > nllOpts) const
xRooNode poi() const
List of parameters of interest: parameters marked as "of interest" These parameters have the "poi" at...
void SetName(const char *name) override
Set the name of the TNamed.
TGListTreeItem * GetTreeItem(TBrowser *b) const
void SetTitle(const char *title) override
Set the title of the TNamed.
xRooNode Multiply(const xRooNode &child, Option_t *opt="")
xRooNode Replace(const xRooNode &node)
xRooNode datasets() const
xRooNode Remove(const xRooNode &child)
xRooNode globs() const
List of global observables of this node.
xRooNode Combine(const xRooNode &rhs)
bool SetBinData(int bin, double value, const char *dataName="obsData")
xRooNode Add(const xRooNode &child, Option_t *opt="")
xRooNode(const char *type, const char *name, const char *title="")
const char * GetIconName() const override
Returns mime type name of object.
void Draw(Option_t *opt="") override
Default Draw method for all objects.
double GetBinError(int bin, const xRooNode &fr="") const
std::vector< double > GetBinErrors(int binStart=1, int binEnd=0, const xRooNode &fr="") const
bool _IsShowVars_() const
TGraph * BuildGraph(RooAbsLValue *v=nullptr, bool includeZeros=false, TVirtualPad *fromPad=nullptr) const
const std::shared_ptr< xRooNode > & at(size_t idx, bool browseResult=true) const
const char * GetNodeType() const
bool SetBinContent(int bin, double value, const char *par=nullptr, double parVal=1)
std::shared_ptr< xRooNode > operator[](size_t idx)
void Checked(TObject *obj, bool val)
void Print(Option_t *opt="") const override
Print TNamed name and title.
double GetContent() const
std::shared_ptr< T > acquireNew(Args &&...args)
std::shared_ptr< T > acquire2(Args &&...args)
xRooNode components() const
void SaveAs(const char *filename="", Option_t *option="") const override
Save this object in the file specified by filename.
xRooNode bins() const
bins of a channel or sample, or channels of a multi-channel pdf
std::shared_ptr< xRooNode > find(const std::string &name, bool browseResult=true) const
TGListTree * GetListTree(TBrowser *b) const
bool fInterrupted
appears that if was fXaxis then dialog box for SetXaxis will take as current value
xRooNode generate(const xRooNode &fr="", bool expected=false, int seed=0)
void Inspect() const override
Dump contents of this object in a graphics canvas.
std::shared_ptr< xRooNode > getBrowsable(const char *name) const
bool SetXaxis(const RooAbsBinning &binning)
RooArgList argList() const
void SetHidden(bool set=true)
std::function< xRooNode(xRooNode *)> fBrowseOperation
std::vector< double > GetBinContents(int binStart=1, int binEnd=0) const
xRooNode pp() const
List of prespecified parameters: non-floatable parameters.
xRooNode constraints() const
std::shared_ptr< xRooNode > fProvider
std::shared_ptr< TStyle > style(TObject *initObject=nullptr, bool autoCreate=true) const
xRooNode mainChild() const
xRooNode fitResult(const char *opt="") const
std::shared_ptr< TAxis > fXAxis
only here so can have char* GetRange return so can return nullptr for no range set (required for RooC...
xRooNode coords(bool setVals=true) const
xRooNode Vary(const xRooNode &child)
xRooNode Constrain(const xRooNode &child)
static std::map< std::string, std::tuple< std::function< double(double, double, double)>, bool > > auxFunctions
xRooNode pars() const
List of parameters (non-observables) of this node.
void _SetContent_(double value)
void SetFitResult(const RooFitResult *fr=nullptr)
void _ShowVars_(bool set=true)
bool IsFolder() const override
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
bool SetBinError(int bin, double value)
void _Vary_(const char *what)
xRooNode histo(const xRooNode &vars="x", const xRooNode &fr="", bool content=true, bool errors=true) const
bool SetContents(const TObject &obj)
std::shared_ptr< TObject > fComp
RooWorkspace * ws() const
The RooWorkspace this node belong to, if any.
xRooNode shallowCopy(const std::string &name, std::shared_ptr< xRooNode > parent=nullptr)
void _generate_(const char *name="", bool expected=false)
void _fit_(const char *constParValues="")
std::shared_ptr< TObject > getObject(const std::string &name, const std::string &type="") const
xRooNode np() const
List of nuisance parameters: non-constant parameters that are not marked of interest,...
xRooNode floats() const
List of parameters that are currently non-constant These parameters do not have the "Constant" attrib...
bool contains(const std::string &name) const
xRooNode reduced(const std::string &range="", bool invert=false) const
xRooNode variations() const
std::string GetPath() const
auto begin() const -> xRooNodeIterator
std::shared_ptr< xRooNode > parentPdf() const
like a parent but only for use by getObject
bool SetContent(double value)
std::shared_ptr< xRooNode > fParent
std::pair< double, double > IntegralAndError(const xRooNode &fr="", const char *rangeName=nullptr) const
xRooNode robs() const
List of regular observables of this node.
TClass * IsA() const override
xRooNode & operator=(const TObject &o)
auto end() const -> xRooNodeIterator
TH1 * BuildHistogram(RooAbsLValue *v=nullptr, bool empty=false, bool errors=false, int binStart=1, int binEnd=0, const xRooNode &fr="") const
xRooNode consts() const
List of parameters that are currently constant.
void _SetBinContent_(int bin, double value, const char *par="", double parVal=1)
std::shared_ptr< TObject > acquire(const std::shared_ptr< TObject > &arg, bool checkFactory=false, bool mustBeNew=false)
void Browse(TBrowser *b=nullptr) override
Browse object. May be overridden for another default action.
double GetBinData(int bin, const char *dataName="obsData")
xRooNode obs() const
List of observables (global and regular) of this node.
void SetRange(const char *range, double low=std::numeric_limits< double >::quiet_NaN(), double high=std::numeric_limits< double >::quiet_NaN())
bool SetData(const TObject &obj, const char *dataName="obsData")
static void SetAuxFunction(const char *title, const std::function< double(double, double, double)> &func, bool symmetrize=false)
std::shared_ptr< TObject > convertForAcquisition(xRooNode &acquirer, const char *opt="") const
double GetError(const xRooNode &fr="") const
xRooNode vars() const
List of variables (observables and parameters) of this node.
const char * GetRange() const
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
Common abstract base class for objects that represent a value and a "shape" in RooFit.
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
void SetName(const char *name) override
Set the name of the TNamed.
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
virtual double highBound() const =0
virtual double lowBound() const =0
Abstract base class for objects that represent a discrete value that can be set from the outside,...
A space to attach TBranches.
const char * getLabel() const
Retrieve current label. Use getCurrentLabel() for more clarity.
Abstract container object that can hold multiple RooAbsArg objects.
RooAbsCollection * selectByAttrib(const char *name, bool value) const
Create a subset of the current collection, consisting only of those elements with the specified attri...
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
Int_t getSize() const
Return the number of elements in the collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
void clear()
Clear contents. If the collection is owning, it will also delete the contents.
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
bool selectCommon(const RooAbsCollection &refColl, RooAbsCollection &outColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract base class for binned and unbinned datasets.
RooFit::OwningPtr< RooAbsData > reduce(const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={})
Create a reduced copy of this dataset.
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Abstract base class for objects that are lvalues, i.e.
virtual std::list< std::string > getBinningNames() const =0
Abstract interface for all probability density functions.
bool canBeExtended() const
If true, PDF can provide extended likelihood term.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
void setBin(Int_t ibin, const char *rangeName=nullptr) override
Set value to center of bin 'ibin' of binning 'rangeName' (or of default binning if no range is specif...
bool hasRange(const char *name) const override
Check if variable has a binning with given name.
Context to temporarily change the error logging mode as long as the context is alive.
Abstract base class for objects that represent a real value and implements functionality common to al...
bool isSelectedComp() const
If true, the current pdf is a selected component (for use in plotting)
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
virtual void forceNumInt(bool flag=true)
Efficient implementation of a sum of PDFs of the form.
RooAddition calculates the sum of a set of RooAbsReal terms, or when constructed with two sets,...
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Abstract interface for RooAbsArg proxy classes.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Class RooBinning is an implements RooAbsBinning in terms of an array of boundary values,...
Object to represent discrete states.
bool defineType(const std::string &label)
Define a state with given name.
Named container for two doubles, two integers two object points and three string pointers that can be...
static const RooCmdArg & none()
Return reference to null argument.
RooConstVar represent a constant real-valued object.
The RooDataHist is a container class to hold N-dimensional binned data.
RooDataSet is a container class to hold unbinned data.
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
void setCovQual(Int_t val)
const TMatrixDSym & covarianceMatrix() const
Return covariance matrix.
TMatrixDSym reducedCovarianceMatrix(const RooArgList ¶ms) const
Return a reduced covariance matrix (Note that Vred is a simple sub-matrix of V, row/columns are order...
void setCovarianceMatrix(TMatrixDSym &V)
Store externally provided correlation matrix in this RooFitResult ;.
const RooArgList & constPars() const
Return list of constant parameters.
Int_t covQual() const
Return MINUIT quality code of covariance matrix.
const RooArgList & floatParsFinal() const
Return list of floating parameters after fit.
void setFinalParList(const RooArgList &list)
Fill the list of final values of the floating parameters.
RooGenericPdf is a concrete implementation of a probability density function, which takes a RooArgLis...
RooHistFunc implements a real-valued function sampled from a multidimensional histogram.
bool isBinnedDistribution(const RooArgSet &) const override
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
TObject * At(int index) const
Return object stored in sequential position given by index.
TIterator * MakeIterator(bool forward=true) const
Create a TIterator for this list.
static RooMsgService & instance()
Return reference to singleton instance.
StreamConfig & getStream(Int_t id)
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
Class RooObjCacheManager is an implementation of class RooCacheManager<RooAbsCacheElement> and specia...
Efficient implementation of a product of PDFs of the form.
A RooProduct represents the product of a given set of RooAbsReal objects.
Class RooProjectedPdf is a RooAbsPdf implementation that represent a projection of a given input p....
RooProjectedPdf()
Default constructor.
Implements a PDF constructed from a sum of functions:
RooRealVar represents a variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
void setError(double value)
bool hasError(bool allowZero=true) const
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
HypoTestResult is a base class for results from hypothesis tests.
RooStringVar is a RooAbsArg implementing string values.
Persistable container for RooFit projects.
const std::map< std::string, RooArgSet > & sets() const
bool import(const RooAbsArg &arg, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}, const RooCmdArg &arg9={})
Import a RooAbsArg object, e.g.
bool removeSet(const char *name)
Remove a named set from the workspace.
RooFactoryWSTool & factory()
Return instance to factory tool.
const Double_t * GetArray() const
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
virtual Style_t GetTitleFont() const
virtual Float_t GetLabelOffset() const
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels.
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title.
virtual Float_t GetTitleSize() const
virtual Float_t GetLabelSize() const
virtual Float_t GetTickLength() const
virtual Float_t GetTitleOffset() const
virtual void SetTickLength(Float_t length=0.03)
Set tick mark length.
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Fill Area Attributes class.
virtual Color_t GetFillColor() const
Return the fill area color.
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
virtual Font_t GetTextFont() const
Return the text font.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Class to manage histogram axis.
virtual void LabelsOption(Option_t *option="h")
Set option(s) to draw axis with labels option can be:
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Bool_t IsVariableBinSize() const
const char * GetTitle() const override
Returns title of object.
TAxis()
Default constructor.
const TArrayD * GetXbins() const
const char * GetBinLabel(Int_t bin) const
Return label for bin.
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x.
Using a TBrowser one can browse all ROOT objects.
TBrowserImp * GetBrowserImp() const
static TCanvas * MakeDefCanvas()
Static function to build a default canvas.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
void SetName(const char *name)
virtual Int_t GetEntries() const
virtual void RemoveAll(TCollection *col)
Remove all objects in collection col from this collection.
static Int_t GetColorPalette(Int_t i)
Static function returning the color number i in current palette.
static Int_t GetNumberOfColors()
Static function returning number of colors in the color palette.
Describe directory structure in memory.
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
virtual TList * GetListOfKeys() const
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=nullptr)
Set the value of a resource or create a new resource.
TExec is a utility class that can be used to execute a C++ command when some event happens in a pad.
A ROOT file is composed of a header, followed by consecutive data records (TKey instances) with a wel...
System file browser, used as TRootBrowser plug-in.
void AddFSDirectory(const char *entry, const char *path=nullptr, Option_t *opt="")
Add file system directory in the list tree.
A list tree is a widget that can contain a number of items arranged in a tree structure.
ROOT GUI Window base class.
virtual void SetName(const char *name)
void SetTitleOffset(Float_t titleoffset=1)
void SetLabelFont(Int_t labelfont)
void SetTitleSize(Float_t titlesize)
virtual void SetTitle(const char *title="")
Change the title of the axis.
Int_t GetLabelFont() const
Float_t GetTitleOffset() const
Float_t GetTickSize() const
void SetTickSize(Float_t ticksize)
void SetLabelSize(Float_t labelsize)
TGraph with asymmetric error bars.
virtual void SetPointError(Double_t exl, Double_t exh, Double_t eyl, Double_t eyh)
Set ex and ey values for point pointed by the mouse.
A TGraphErrors is a TGraph with error bars.
Double_t GetErrorYlow(Int_t bin) const override
It returns the error along Y at point i.
Double_t GetErrorYhigh(Int_t bin) const override
It returns the error along Y at point i.
A TGraph is an object made of two arrays X and Y with npoints each.
virtual void AddPoint(Double_t x, Double_t y)
Append a new point to the graph.
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
void SetName(const char *name="") override
Set graph name.
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
virtual Double_t GetPointY(Int_t i) const
Get y value for point i.
void SetTitle(const char *title="") override
Change (i.e.
virtual void SetPointX(Int_t i, Double_t x)
Set x value for point i.
virtual void SetEditable(Bool_t editable=kTRUE)
if editable=kFALSE, the graph cannot be modified with the mouse by default a TGraph is editable
1-D histogram with a double per channel (see TH1 documentation)}
1-D histogram with a float per channel (see TH1 documentation)}
TH1 is the base class of all histogram classes in ROOT.
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
void SetTitle(const char *title) override
Change/set the title.
virtual Int_t GetNbinsY() const
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
@ kNoTitle
Don't draw the histogram title.
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
TObject * FindObject(const char *name) const override
Search object named name in the list of functions.
virtual Int_t GetNbinsX() const
virtual void SetMaximum(Double_t maximum=-1111)
virtual void SetBinError(Int_t bin, Double_t error)
Set the bin Error Note that this resets the bin eror option to be of Normal Type and for the non-empt...
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
void Draw(Option_t *option="") override
Draw this histogram with options.
virtual void SetMinimum(Double_t minimum=-1111)
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
TList * GetListOfFunctions() const
void SetName(const char *name) override
Change the name of this histogram.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
virtual Bool_t Divide(TF1 *f1, Double_t c1=1)
Performs the operation: this = this/(c1*f1) if errors are defined (see TH1::Sumw2),...
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
2-D histogram with a double per channel (see TH1 documentation)}
The Histogram stack class.
virtual void Add(TH1 *h, Option_t *option="")
add a new histogram to the list Only 1-d and 2-d histograms currently supported.
void Draw(Option_t *chopt="") override
Draw this multihist with its current attributes.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
virtual const char * GetClassName() const
Storage class for one entry of a TLegend.
This class displays a legend box (TPaveText) containing several legend entries.
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
void SetNColumns(Int_t nColumns)
Set the number of columns for the legend.
void SetMargin(Float_t margin)
Use the TLine constructor to create a simple line.
virtual void SetY2(Double_t y2)
virtual void SetX2(Double_t x2)
virtual void SetX1(Double_t x1)
virtual void SetY1(Double_t y1)
void Add(TObject *obj) override
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
A TMultiGraph is a collection of TGraph (or derived) objects.
virtual void Add(TGraph *graph, Option_t *chopt="")
Add a new graph to the list of graphs.
void Draw(Option_t *chopt="") override
Draw this multigraph with its current attributes.
The TNamed class is the base class for all named ROOT classes.
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
void Clear(Option_t *option="") override
Set name and title to empty strings ("").
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Mother of all ROOT objects.
virtual void Inspect() const
Dump contents of this object in a graphics canvas.
virtual const char * GetName() const
Returns name of object.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
virtual void Delete(Option_t *option="")
Delete this object.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual const char * GetTitle() const
Returns title of object.
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
@ kCanDelete
if object in a list can be deleted
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
The most important graphics class in the ROOT system.
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
A Pave (see TPave) with text, lines or/and boxes inside.
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
virtual void SetMargin(Float_t margin=0.05)
virtual void SetY1NDC(Double_t y1)
virtual void ConvertNDCtoPad()
Convert pave coordinates from NDC to Pad coordinates.
virtual void SetName(const char *name="")
virtual void SetBorderSize(Int_t bordersize=4)
virtual void SetY2NDC(Double_t y2)
void SetEntryVal(Int_t, Double_t)
Set the value of a slice.
void SetEntryFillColor(Int_t, Int_t)
Set the color for the slice "i".
void SetRadius(Double_t)
Set the pie chart's radius' value.
void SetEntryLabel(Int_t, const char *text="Slice")
Set slice number "i" label.
void Draw(Option_t *option="l") override
Draw the pie chart.
This is the ROOT implementation of the Qt object communication mechanism (see also http://www....
Regular expression class.
This class creates a ROOT object browser, constituted by three main tabs.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Stop()
Stop the stopwatch.
Provides iteration through tokens of a given string.
Bool_t NextToken()
Get the next token, it is stored in this TString.
Bool_t IsDec() const
Returns true if all characters in string are decimal digits (0-9).
void ToLower()
Change string to lower-case.
Int_t Atoi() const
Return integer value of string.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Double_t Atof() const
Return floating-point value contained in string.
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Int_t CountChar(Int_t c) const
Return number of times character c occurs in the string.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
TStyle objects may be created to define special styles.
void SetPaintTextFormat(const char *format="g")
Int_t GetOptTitle() const
Float_t GetLabelSize(Option_t *axis="X") const
Return label size.
Float_t GetPadRightMargin() const
Style_t GetTitleFont(Option_t *axis="X") const
Return title font.
Bool_t GetHistMinimumZero() const
Float_t GetPadLeftMargin() const
Float_t GetTitleYSize() const
Double_t GetHistTopMargin() const
Float_t GetPadBottomMargin() const
const char * GetPaintTextFormat() const
Float_t GetPadTopMargin() const
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
The TTimeStamp encapsulates seconds and ns since EPOCH.
void Add(const TTimeStamp &offset)
Add "offset" as a delta time.
const char * AsString(const Option_t *option="") const
Return the date & time as a string.
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
static TVirtualPadEditor * GetPadEditor(Bool_t load=kTRUE)
Returns the pad editor dialog. Static method.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
virtual void Modified(Bool_t flag=1)=0
virtual TList * GetListOfPrimitives() const =0
virtual void SetPad(const char *name, const char *title, Double_t xlow, Double_t ylow, Double_t xup, Double_t yup, Color_t color=35, Short_t bordersize=5, Short_t bordermode=-1)=0
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
void Draw(Option_t *option="") override=0
Default Draw method for all objects.
const char * GetName() const override=0
Returns name of object.
virtual TVirtualPad * GetPad(Int_t subpadnumber) const =0
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)=0
virtual Int_t GetLogy() const =0
virtual void SetLogy(Int_t value=1)=0
virtual TObject * GetPrimitive(const char *name) const =0
virtual void SetBorderSize(Short_t bordersize)=0
virtual void SetName(const char *name)=0
TClass * IsA() const override
double evaluate() const override
Evaluate projected p.d.f.
virtual TObject * clone(const char *newname) const override
double expectedEvents(const RooArgSet *nset) const override
Return expected number of events to be used in calculation of extended likelihood.
ExtendMode extendMode() const override
Returns ability of PDF to provide extended likelihood terms.
RooCmdArg RecycleConflictNodes(bool flag=true)
RooConstVar & RooConst(double val)
RooCmdArg Embedded(bool flag=true)
RooCmdArg GlobalObservables(Args_t &&... argsOrArgSet)
RooCmdArg Range(const char *rangeName, bool adjustNorm=true)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
Double_t Prob(Double_t chi2, Int_t ndf)
Computation of the probability for a certain Chi-squared (chi2) and number of degrees of freedom (ndf...
Double_t ChisquareQuantile(Double_t p, Double_t ndf)
Evaluate the quantiles of the chi-squared probability distribution function.
#define END_XROOFIT_NAMESPACE
void removeTopic(RooFit::MsgTopic oldTopic)
bool isNaNWithPayload() const
Test if this struct has a float packed into its mantissa.
static float unpackNaN(double val)
If val is NaN and a this NaN has been tagged as containing a payload, unpack the float from the manti...
static uint64_t sum(uint64_t i)
#define dest(otri, vertexptr)
void(* gOldHandlerr)(int)
void addLegendEntry(TObject *o, const char *title, const char *opt)
void buildHistogramInterrupt(int signum)
auto GETACTBROWSER(TRootBrowser *b)
auto & GETWSSNAPSHOTS(RooWorkspace *w)
bool TopRightPlaceBox(TPad *p, TObject *o, double w, double h, double &xl, double &yb)
TPaveText * getPave(const char *name="labels", bool create=true, bool doPaint=false)
auto GETROOTDIR(TGFileBrowser *b)
const xRooNode * runningNode
auto GETLISTTREE(TGFileBrowser *b)
const T & _or_func(const T &a, const T &b)
TLegend * getLegend(bool create=true, bool doPaint=false)