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
101 return a->workspace();
109 return w->getSnapshots();
113 return b->GetActBrowser();
117 return b->GetRootDir();
121 return b->GetListTree();
123#define GETDMP(o, m) \
124 *reinterpret_cast<void **>(reinterpret_cast<unsigned char *>(o) + o->Class()->GetDataMemberOffset(#m))
175#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
179#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
208#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 gROOT->GetListOfColors()->Clear();
338 for (
auto col : *
colors) {
339 gROOT->GetListOfColors()->Add(col);
345 for (
auto &
d : _ws->allData()) {
346 for (
auto &
a : *
d->get()) {
347 if (
auto v = _ws->var(
a->GetName());
v) {
348 v->setAttribute(
"obs");
349 }
else if (
auto c = _ws->cat(
a->GetName());
c) {
350 c->setAttribute(
"obs");
354 checkCount +=
d->TestBit(1 << 20);
357 if (checkCount == 0 && !_ws->allData().empty())
358 _ws->allData().back()->SetBit(1 << 20,
true);
361 for (
auto s : *_set) {
363 _ws->var(s->GetName())->setStringAttribute(
"nominal",
TString::Format(
"%f",
v->getVal()));
371 if (k ==
"globalObservables" ||
TString(k).
EndsWith(
"_GlobalObservables")) {
374 s->setAttribute(
"obs");
375 s->setAttribute(
"global");
378 const_cast<RooArgSet &
>(
v).setAttribAll(
"obs");
381 s->setAttribute(
"poi");
393 const_cast<RooArgSet &
>(
v).setAttribAll(
"np");
396 if (!_allGlobs.
empty() &&
GETWSSETS(_ws).count(
"globalObservables") == 0) {
397 _ws->defineSet(
"globalObservables", _allGlobs);
402 if (!_ws->allPdfs().empty()) {
403 std::set<RooRealVar *> noErrorPars;
404 std::string parNames;
405 for (
auto &
p :
np()) {
409 if (!
v->hasError()) {
410 noErrorPars.insert(
v);
411 if (!parNames.empty())
416 if (!noErrorPars.empty()) {
418 "Inferring initial errors of %d parameters (%s%s) (give all nuisance parameters an error to avoid "
420 int(noErrorPars.size()), (*noErrorPars.begin())->GetName(), (noErrorPars.size() > 1) ?
",..." :
"");
423 for (
auto &
a : *this) {
424 if (noErrorPars.empty()) {
427 if (
a->fFolder ==
"!pdfs") {
429 auto fr =
a->floats().reduced(parNames).fitResult(
"prefit");
431 std::set<RooRealVar *> foundPars;
432 for (
auto &
v : noErrorPars) {
433 if (
auto arg =
dynamic_cast<RooRealVar *
>(_fr->floatParsFinal().find(
v->GetName()));
434 arg && arg->hasError()) {
435 v->setError(arg->getError());
439 for (
auto &
v : foundPars) {
440 noErrorPars.erase(
v);
451 if (strlen(GetTitle()) == 0) {
468 (comp.InheritsFrom(
"RooAbsArg") && dynamic_cast<const
RooAbsArg *>(&comp)->getStringAttribute(
"alias"))
469 ? dynamic_cast<const
RooAbsArg *>(&comp)->getStringAttribute(
"alias")
478 if (
auto a = std::dynamic_pointer_cast<RooAbsArg>(comp);
a &&
a->getStringAttribute(
"alias"))
479 return a->getStringAttribute(
"alias");
481 return comp->GetName();
499 if (
auto o = get<RooAbsReal>(); o) {
500 if (o->isSelectedComp() && !val) {
503 o->setAttribute(
"hidden");
504 }
else if (!o->isSelectedComp() && !val) {
509 o->setAttribute(
"hidden",
false);
512 item->CheckItem(!o->getAttribute(
"hidden"));
513 if (o->isSelectedComp()) {
516 item->SetColor(
kGray);
521 if (
auto o =
get(); o) {
523 o->SetBit(1 << 20, val);
524 if (
auto fr = get<RooFitResult>(); fr) {
525 if (
auto _ws =
ws(); _ws) {
528 if (!_ws->genobj(fr->GetName())) {
530 if (
auto wfr =
dynamic_cast<RooFitResult *
>(_ws->genobj(fr->GetName()))) {
535 _allVars = fr->floatParsFinal();
536 _allVars = fr->constPars();
537 for (
auto &i : fr->floatParsInit()) {
543 for (
auto oo : _ws->allGenericObjects()) {
544 if (
auto ffr =
dynamic_cast<RooFitResult *
>(oo); ffr && ffr != fr) {
545 ffr->ResetBit(1 << 20);
549 _ws->allVars() = fr->floatParsInit();
553 if (
auto first = item->GetParent()->GetFirstChild()) {
555 if (first->HasCheckBox()) {
556 auto _obj =
static_cast<xRooNode *
>(first->GetUserData());
557 first->CheckItem(_obj->get() && _obj->get()->TestBit(1 << 20));
559 }
while ((first = first->GetNextSibling()));
568 static bool blockBrowse =
false;
572 auto b2 =
dynamic_cast<TBrowser *
>(
gROOT->GetListOfBrowsers()->Last());
573 if (!b2 || !b2->GetBrowserImp()) {
580 b2 =
new TBrowser(
"nodeBrowser",
this,
"RooFit Browser");
582 }
else if (strcmp(b2->GetName(),
"nodeBrowser") == 0) {
584 b2->BrowseObject(
this);
596 _b->GotoDir(
nullptr);
607 if (
auto first = item->GetFirstChild()) {
609 if (first->HasCheckBox()) {
610 auto _obj =
static_cast<xRooNode *
>(first->GetUserData());
611 first->CheckItem(_obj->get() &&
612 (_obj->get()->TestBit(1 << 20) ||
615 }
while ((first = first->GetNextSibling()));
626 if (
auto _fr = get<RooFitResult>(); _fr &&
fBrowsables.empty()) {
628 fBrowsables.push_back(std::make_shared<xRooNode>(
".Draw(\"pull\")",
nullptr, *
this));
629 fBrowsables.push_back(std::make_shared<xRooNode>(
".Draw(\"corrcolztext\")",
nullptr, *
this));
630 if (std::unique_ptr<RooAbsCollection>(_fr->floatParsFinal().selectByAttrib(
"poi",
true))->size() == 1) {
631 fBrowsables.push_back(std::make_shared<xRooNode>(
".Draw(\"impact\")",
nullptr, *
this));
637 if (
auto s = get<TStyle>()) {
638 s->SetFillAttributes();
645 Draw(
b->GetDrawOption());
647 }
catch (
const std::exception &
e) {
650 (
gROOT->GetListOfBrowsers()->At(0))
653 "Exception",
e.what(),
658 bool hasFolders =
false;
660 for (
auto &
c : *
this) {
661 if (!
c->fFolder.empty()) {
670 auto _folders =
find(
".folders");
672 _folders = emplace_back(std::make_shared<xRooNode>(
".folders",
nullptr, *
this));
675 for (
auto &
v : *
this) {
676 if (!
v->fFolder.empty() && !_folders->find(
v->fFolder,
false)) {
677 _folders->emplace_back(std::make_shared<xRooNode>(
v->fFolder.c_str(),
nullptr, *
this));
681 for (
auto &
v : *_folders) {
684 _name = _name(1, _name.
Length());
685 b->Add(
v.get(), _name);
689 for (
auto &
v : *
this) {
690 if (hasFolders && !
v->fFolder.empty())
692 if (strcmp(
v->GetName(),
".folders") == 0)
696 if (_fr && ((_fr->status() == 0 && _fr->numStatusHistory() == 0) || (_fr->floatParsFinal().empty()))) {
700 if (
v->get<
RooAbsPdf>() && get<RooSimultaneous>())
704 _name = _name(strlen(
v->get()->ClassName()) + 2, _name.
Length());
712 :
v->get()->GetName());
714 }
else if (
v->get() && !
v->get<
TFile>() && !
TString(
v->GetName()).BeginsWith(
'/'))
716 if (
auto _type =
v->GetNodeType(); strlen(_type)) {
724 for (
size_t i = 0; i < fv->dependents().
size(); i++) {
730 for (
size_t i = 0; i < gv->dependents().
size(); i++) {
737 TString nameSave(
v->TNamed::GetName());
738 TString titleSave(
v->TNamed::GetTitle());
739 if (
auto o =
v->get(); o)
740 v->TNamed::SetNameTitle(o->GetName(), o->ClassName());
741 b->Add(
v.get(), _name, _checked);
742 if (
auto o =
v->get(); o)
743 v->TNamed::SetNameTitle(nameSave, titleSave);
744 if (_checked != -1) {
745 dynamic_cast<TQObject *
>(
b->GetBrowserImp())
746 ->Connect(
"Checked(TObject *, bool)",
ClassName(),
v.get(),
"Checked(TObject *, bool)");
749 if (_fr->status() || _fr->covQual() != 3) {
750 v->GetTreeItem(
b)->SetColor((_fr->numStatusHistory() || _fr->floatParsFinal().empty()) ?
kRed :
kBlue);
751 }
else if (_fr->numStatusHistory() == 0) {
752 v->GetTreeItem(
b)->SetColor(
kGray);
755 if ((
v->fFolder ==
"!np" ||
v->fFolder ==
"!poi")) {
757 v->GetTreeItem(
b)->SetColor(
kGray);
759 v->GetTreeItem(
b)->ClearColor();
763 if (
auto fits = _htr->GetFitInfo()) {
764 for (
int i = 0; i < fits->numEntries(); i++) {
766 if (fits->get(i)->getCatIndex(
"type") != 5 && fits->get(i)->getRealValue(
"status") != 0) {
767 v->GetTreeItem(
b)->SetColor(
kRed);
772 v->GetTreeItem(
b)->SetColor(
kBlue);
799 if (_name ==
".memory")
801 TString nameSave(
v->TNamed::GetName());
802 TString titleSave(
v->TNamed::GetTitle());
803 if (
auto o =
v->get(); o)
804 v->TNamed::SetNameTitle(o->GetName(), o->ClassName());
805 b->Add(
v.get(), _name, -1);
806 if (
auto o =
v->get(); o)
807 v->TNamed::SetNameTitle(nameSave, titleSave);
810 b->SetSelected(
this);
823 auto v = std::make_shared<xRooNode>(
vars());
834 if (strcmp(
b->GetName(),
".vars") == 0)
857 if (
auto v = var();
v)
858 return v->getBinWidth(bin - 1, GetName());
863 if (
auto v = rvar();
v) {
864 return (bin ==
v->getBinning(GetName()).numBins() + 1) ?
v->getBinning(GetName()).binHigh(bin - 2)
865 :
v->getBinning(GetName()).binLow(bin - 1);
871 if (
auto v = rvar();
v)
872 return (bin == 0) ?
v->getBinning(GetName()).binLow(bin) :
v->getBinning(GetName()).binHigh(bin - 1);
878 return (binning() && strlen(binning()->GetTitle())) ? binning()->GetTitle() : GetParent()->GetTitle();
885 dynamic_cast<TNamed *
>(GetParent())->SetTitle(title);
889 void Set(
Int_t nbins,
const double *xbins)
override
892 v->setBinning(
RooBinning(nbins, xbins), GetName());
897 std::vector<double> bins(nbins + 1);
898 for (
int i = 0; i <= nbins; i++)
899 bins.at(i) = xbins[i];
900 return Set(nbins, &bins[0]);
912 Int_t FindFixBin(
double x)
const override {
return (binning()) ? (binning()->binNumber(
x) + 1) :
x; }
923 if (
auto _owned =
find(
".memory"); _owned) {
924 for (
auto &o : *_owned) {
925 if (
name == o->GetName()) {
926 if (
type.empty() || o->get()->InheritsFrom(
type.c_str()))
935 while (!_provider && _parent) {
936 _provider = _parent->fProvider;
937 _parent = _parent->fParent;
940 return _provider->getObject(
name,
type);
943 std::shared_ptr<TObject> out;
944 if (
auto arg =
ws()->arg(
name.c_str()); arg) {
945 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
946 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
951 if (
auto arg =
ws()->
data(
name.c_str()); arg) {
952 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
953 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
958 if (
auto arg =
ws()->genobj(
name.c_str()); arg) {
959 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
960 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
965 if (
auto arg =
ws()->embeddedData(
name.c_str()); arg) {
966 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
967 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
973 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
974 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
981 if (
auto arg = get<RooAbsArg>()) {
984 arg->treeNodeServerList(&nodes);
985 if (
auto server = nodes.
find(
name.c_str())) {
986 return std::shared_ptr<TObject>(server, [](
TObject *) {});
997 cat && cat->numTypes() !=
fXAxis->GetNbins()) {
1004 if (
auto a = get<RooAbsArg>();
a &&
a->isFundamental())
1009 auto o = get<RooAbsReal>();
1013 if (
auto xName = o->getStringAttribute(
"xvar"); xName) {
1023 (o->dependsOn(*
dynamic_cast<RooAbsArg *
>(_parentX->GetParent())) ||
vars().empty())) {
1025 }
else if (
auto _obs =
obs(); !_obs.empty()) {
1026 for (
auto &
v : _obs) {
1035 }
else if (
auto _pars =
pars(); !_pars.empty()) {
1036 for (
auto &
v : _pars) {
1052 if (o !=
dynamic_cast<TObject *
>(
x)) {
1057 TString binningName = o->getStringAttribute(
"binning");
1058 auto _bnames =
x->getBinningNames();
1059 bool hasBinning =
false;
1060 for (
auto &
b : _bnames) {
1061 if (
b == binningName) {
1069 Warning(
"GetXaxis",
"Binning %s not defined on %s - clearing", binningName.
Data(),
1071 o->setStringAttribute(
"binning",
nullptr);
1075 if (binningName ==
"" && o !=
dynamic_cast<TObject *
>(
x)) {
1077 auto __bnames =
x->getBinningNames();
1078 for (
auto &
b : __bnames) {
1081 if (
b == o->GetName()) {
1082 binningName = o->GetName();
1086 if (binningName ==
"") {
1092 (std::list<double> *)(
nullptr),
1093 o->binBoundaries(*
dynamic_cast<RooAbsRealLValue *
>(
x), -std::numeric_limits<double>::infinity(),
1094 std::numeric_limits<double>::infinity()));
1096 std::vector<double> _bins;
1097 for (
auto &
b : *
bins) {
1098 if (_bins.empty() || std::abs(_bins.back() -
b) > 1
e-5 * _bins.back())
1101 fXAxis = std::make_shared<Axis2>(_bins.size() - 1, &_bins[0]);
1103 if (
auto _v =
dynamic_cast<RooRealVar *
>(
x); _v) {
1104 _v->setBinning(
RooBinning(_bins.size() - 1, &_bins[0], o->GetName()), o->
GetName());
1105 _v->getBinning(o->GetName())
1110 binningName = o->GetName();
1112 }
else if (_parentX) {
1114 binningName = _parentX->GetName();
1121 if (
r->getBinning(binningName).isUniform()) {
1122 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName),
r->getMin(binningName),
r->getMax(binningName));
1124 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName),
r->getBinning(binningName).array());
1126 }
else if (
auto cat =
dynamic_cast<RooCategory *
>(
x)) {
1127 std::vector<double>
bins = {};
1128 for (
int i = 0; i <=
x->numBins(binningName); i++)
1130 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName), &
bins[0]);
1133 std::map<int, std::string> cats;
1134 for (
auto &
c : *cat) {
1135 if (cat->isStateInRange(binningName,
c.first.c_str())) {
1136 cats[
c.second] =
c.first;
1139 for (
auto &[
_, label] : cats) {
1140 fXAxis->SetBinLabel(i++, label.c_str());
1145 fXAxis->SetName(binningName);
1152 if (
auto o =
get(); o) {
1153 if (o->InheritsFrom(
"RooWorkspace"))
1155 if (o->InheritsFrom(
"RooAbsData"))
1157 if (o->InheritsFrom(
"RooSimultaneous"))
1160 if (o->InheritsFrom(
"RooProdPdf"))
1162 if (o->InheritsFrom(
"RooRealSumPdf") || o->InheritsFrom(
"RooAddPdf"))
1165 if (o->InheritsFrom(
"RooFitResult")) {
1166 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitRooFitResult",
true)) {
1167 gClient->GetMimeTypeList()->AddType(
"xRooFitRooFitResult",
"xRooFitRooFitResult",
"package.xpm",
1168 "package.xpm",
"->Browse()");
1170 return "xRooFitRooFitResult";
1172 if (o->InheritsFrom(
"RooRealVar") || o->InheritsFrom(
"RooCategory")) {
1173 if (get<RooAbsArg>()->getAttribute(
"obs")) {
1174 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitObs",
true)) {
1175 gClient->GetMimeTypeList()->AddType(
"xRooFitObs",
"xRooFitObs",
"x_pic.xpm",
"x_pic.xpm",
"->Browse()");
1177 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitGlobs",
true)) {
1178 gClient->GetMimeTypeList()->AddType(
"xRooFitGlobs",
"xRooFitGlobs",
"z_pic.xpm",
"z_pic.xpm",
1181 return (get<RooAbsArg>()->getAttribute(
"global") ?
"xRooFitGlobs" :
"xRooFitObs");
1185 if (o->InheritsFrom(
"TStyle")) {
1186 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitTStyle",
true)) {
1187 gClient->GetMimeTypeList()->AddType(
"xRooFitTStyle",
"xRooFitTStyle",
"bld_colorselect.xpm",
1188 "bld_colorselect.xpm",
"->Browse()");
1190 return "xRooFitTStyle";
1192 if (o->InheritsFrom(
"RooConstVar")) {
1198 return "TMethodBrowsable-leaf";
1200 if (o->InheritsFrom(
"RooStats::HypoTestInverterResult")) {
1201 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitScanStyle",
true)) {
1202 gClient->GetMimeTypeList()->AddType(
"xRooFitScanStyle",
"xRooFitScanStyle",
"f2_s.xpm",
"f2_s.xpm",
1205 return "xRooFitScanStyle";
1207 if (o->InheritsFrom(
"RooStats::HypoTestResult")) {
1208 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitTestStyle",
true)) {
1209 gClient->GetMimeTypeList()->AddType(
"xRooFitTestStyle",
"xRooFitTestStyle",
"diamond.xpm",
"diamond.xpm",
1212 return "xRooFitTestStyle";
1214 if (o->InheritsFrom(
"RooStats::HistFactory::FlexibleInterpVar"))
1215 return "TBranchElement-folder";
1216 if (o->InheritsFrom(
"RooAbsPdf")) {
1217 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitPDFStyle",
true)) {
1218 gClient->GetMimeTypeList()->AddType(
"xRooFitPDFStyle",
"xRooFitPDFStyle",
"pdf.xpm",
"pdf.xpm",
1221 return "xRooFitPDFStyle";
1223 if (o->InheritsFrom(
"RooStats::ModelConfig")) {
1224 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitMCStyle",
true)) {
1225 gClient->GetMimeTypeList()->AddType(
"xRooFitMCStyle",
"xRooFitMCStyle",
"app_t.xpm",
"app_t.xpm",
1228 return "xRooFitMCStyle";
1232 _ax && (
a->isBinnedDistribution(*
dynamic_cast<RooAbsArg *
>(_ax->GetParent())) ||
1234 std::unique_ptr<std::list<double>>(
a->binBoundaries(
1235 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
1236 std::numeric_limits<double>::infinity()))))) {
1241 return o->ClassName();
1252 if (o->InheritsFrom(
"RooStats::HistFactory::FlexibleInterpVar"))
1254 if (o->InheritsFrom(
"PiecewiseInterpolation"))
1256 if (o->InheritsFrom(
"RooHistFunc"))
1257 return (
dynamic_cast<RooAbsArg *
>(o)->getAttribute(
"density")) ?
"ConstDensityHisto" :
"ConstHisto";
1258 if (o->InheritsFrom(
"RooBinWidthFunction"))
1260 if (o->InheritsFrom(
"ParamHistFunc"))
1262 if (o->InheritsFrom(
"RooRealVar"))
1264 if (o->InheritsFrom(
"RooConstVar"))
1272 xRooNode out(
".coords",
nullptr, *
this);
1274 auto _p = std::shared_ptr<xRooNode>(
const_cast<xRooNode *
>(
this), [](
xRooNode *) {});
1304 if (
auto pos = pName.
Index(
'='); pos != -1) {
1305 if (pos > 0 && pName(pos - 1) ==
'<') {
1308 pName = pName(pos + 1, pName.
Length());
1310 pName = pName(0, pName.
Index(
'<'));
1313 _obs->setVal((high + low) / 2.);
1314 static_cast<RooRealVar *
>(_obs.get())->setRange(
"coordRange", low, high);
1316 "coordRange",
"coordRange");
1318 out.emplace_back(std::make_shared<xRooNode>(_obs->GetName(), _obs, _p));
1323 }
else if (
auto _obs = _p->getObject<
RooAbsArg>(pName(0, pos)); _obs) {
1326 _cat->setLabel(pName(pos + 1, pName.
Length()));
1327 }
else if (
auto _var =
dynamic_cast<RooAbsRealLValue *
>(_obs.get()); _var) {
1331 out.emplace_back(std::make_shared<xRooNode>(_obs->GetName(), _obs, _p));
1333 throw std::runtime_error(
"Unknown observable, could not find");
1345 }
catch (
const std::exception &
e) {
1354 }
catch (
const std::exception &
e) {
1363 if (strcmp(
GetName(),
".poi") == 0) {
1369 throw std::runtime_error(
TString::Format(
"%s is not a poi", toRemove.GetName()));
1371 toRemove.get<
RooAbsArg>()->setAttribute(
"poi",
false);
1374 }
else if (strcmp(
GetName(),
".factors") == 0 || strcmp(
GetName(),
".constraints") == 0 ||
1375 strcmp(
GetName(),
".components") == 0) {
1381 pdf =
p->pdfList().find(
child.GetName());
1384 auto i =
p->pdfList().index(*pdf);
1386#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
1387 const_cast<RooArgList &
>(
p->pdfList()).remove(*pdf);
1388#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
1389 p->_pdfNSetList.erase(
p->_pdfNSetList.begin() + i);
1391 auto nset =
p->_pdfNSetList.At(i);
1392 p->_pdfNSetList.Remove(nset);
1395 if (
p->_extendedIndex == i)
1396 p->_extendedIndex = -1;
1397 else if (
p->_extendedIndex > i)
1398 p->_extendedIndex--;
1410 arg = p2->components().find(
child.GetName());
1414#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
1415 p2->_compRSet.remove(*arg);
1417 const_cast<RooArgList &
>(p2->realComponents()).remove(*arg);
1419 p2->removeServer(*arg,
true);
1424 bool removed =
false;
1427 c->constraints().Remove(toRemove);
1429 }
catch (std::runtime_error &) {
1439 arg = p4->funcList().find(
child.GetName());
1443 auto idx = p4->funcList().index(arg);
1447 const_cast<RooArgList &
>(p4->funcList()).remove(*arg);
1448 p4->removeServer(*arg,
true);
1450 std::vector<RooAbsArg *> _coefs;
1451 for (
size_t ii = 0; ii < const_cast<RooArgList &>(p4->coefList()).size(); ii++) {
1452 if (ii !=
size_t(idx))
1453 _coefs.push_back(
const_cast<RooArgList &
>(p4->coefList()).
at(ii));
1455 const_cast<RooArgList &
>(p4->coefList()).removeAll();
1456 for (
auto &
a : _coefs)
1467 arg = p5->pdfList().find(
child.GetName());
1471 auto idx = p5->pdfList().index(arg);
1475 const_cast<RooArgList &
>(p5->pdfList()).remove(*arg);
1476 p5->removeServer(*arg,
true);
1478 std::vector<RooAbsArg *> _coefs;
1479 for (
size_t ii = 0; ii < const_cast<RooArgList &>(p5->coefList()).size(); ii++) {
1480 if (ii !=
size_t(idx))
1481 _coefs.push_back(
const_cast<RooArgList &
>(p5->coefList()).
at(ii));
1483 const_cast<RooArgList &
>(p5->coefList()).removeAll();
1484 for (
auto &
a : _coefs)
1495 arg = p6->list().find(
child.GetName());
1499 const_cast<RooArgList &
>(p6->list()).remove(*arg);
1500 p6->removeServer(*arg,
true);
1506 if (
auto w = get<RooWorkspace>();
w) {
1508 auto arg =
w->components().find(
child.GetName());
1515 if (arg->hasClients()) {
1516 throw std::runtime_error(
1517 TString::Format(
"Cannot remove %s from workspace %s, because it has dependencies - first remove from those",
1520 const_cast<RooArgSet &
>(
w->components()).remove(*arg);
1521 Info(
"Remove",
"Deleted %s from workspace %s", out.GetName(),
GetName());
1523 }
else if (get<RooProduct>() || get<RooProdPdf>()) {
1525 }
else if (get<RooRealSumPdf>() || get<RooAddPdf>() || get<RooAddition>()) {
1529 throw std::runtime_error(
"Removal not implemented for object type " +
1539 ~AutoUpdater() {
n.browse(); }
1542 AutoUpdater xxx(*
this);
1545 bool considerType(sOpt ==
"+");
1561 if (strcmp(
GetName(),
".factors") == 0) {
1564 }
else if (strcmp(
GetName(),
".components") == 0) {
1567 }
else if (strcmp(
GetName(),
".variations") == 0) {
1570 }
else if (strcmp(
GetName(),
".constraints") == 0) {
1576 }
else if ((strcmp(
GetName(),
".globs") == 0)) {
1579 out->setAttribute(
"obs");
1580 out->setAttribute(
"global");
1583 throw std::runtime_error(
"Failed to add global observable");
1584 }
else if ((strcmp(
GetName(),
".poi") == 0)) {
1587 out->setAttribute(
"poi");
1595 throw std::runtime_error(
"Failed to add parameter of interest");
1602 }
else if (strcmp(
GetName(),
".datasets()") == 0) {
1607 throw std::runtime_error(
1608 "Datasets can only be created for pdfs or workspaces (except if generated dataset, then must be pdf)");
1611 if (sOpt ==
"asimov" || sOpt ==
"toy") {
1613 auto _fr =
fParent->fitResult();
1614 if (strlen(_fr->GetName()) == 0) {
1617 auto ds =
fParent->generate(_fr, sOpt ==
"asimov");
1618 if (strlen(
child.GetName())) {
1629 }
else if (!_ws->obj(_fr->GetName())) {
1635 auto parentObs =
fParent->obs();
1636 auto _obs = parentObs.argList();
1638 std::unique_ptr<RooAbsCollection> _globs(_obs.selectByAttrib(
"global",
true));
1640 _obs.remove(*_globs);
1646 _obs.add(*
dynamic_cast<RooAbsArg *
>(ax->GetParent()));
1649 if (
auto _d = _ws->data(
child.GetName()); _d) {
1652 l.remove(*_d->get(),
true,
true);
1656 throw std::runtime_error(
"Cannot extend dataset with new columns");
1667 if (
auto __d = _ws->data(
child.GetName()))
1668 __d->SetBit(1 << 20, _ws->allData().size() == 1);
1676 auto out = std::shared_ptr<TObject>(_ws->data(
child.GetName()), [](
TObject *) {});
1685 throw std::runtime_error(
"Cannot create dataset");
1690 throw std::runtime_error(
"Cannot add to null object with no parentage");
1692 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(
child), [](
TObject *) {}));
1697 std::rethrow_exception(std::current_exception());
1702 throw std::runtime_error(
"No object");
1706 if (
auto p = get<RooAbsData>();
p) {
1708 bb->Add(
child, opt);
1712 throw std::runtime_error(
"Can only add datasets to a dataset");
1717 auto _globs =
globs();
1718 for (
auto &glob :
child.globs()) {
1719 if (
auto g = _globs.find(glob->GetName()); !
g) {
1721 }
else if (
g->GetContent() != glob->GetContent()) {
1722 Warning(
"Add",
"Global observable %s=%g in dataset %s mismatches %s value %g ... ignoring latter",
1723 g->GetName(),
g->GetContent(),
GetName(),
child.GetName(), glob->GetContent());
1727 if (
auto _dglobs =
p->getGlobalObservables()) {
1730 for (
auto g : _globs)
1733 p->setGlobalObservables(globsToAdd);
1737 for (
auto col : *_data->get()) {
1738 if (!
p->get()->contains(*col)) {
1739 ds->addColumn(*col);
1743 ds->SetTitle(
TString(ds->GetTitle()) +
" + " + _data->GetTitle());
1749 throw std::runtime_error(
"Can only add histogram or dataset to data");
1753 throw std::runtime_error(
"Could not find pdf");
1754 auto _ax = _pdf->GetXaxis();
1756 throw std::runtime_error(
"Cannot determine binning to add data");
1765 l.remove(*
p->get(),
true,
true);
1769 throw std::runtime_error(
"Cannot extend dataset with new columns");
1776 for (
auto &o :
obs) {
1778 if (
auto dv =
dynamic_cast<RooRealVar *
>(
p->get()->find(
v->GetName())); dv) {
1779 if (
v->getMin() < dv->getMin())
1780 dv->setMin(
v->getMin());
1781 if (
v->getMax() > dv->getMax())
1782 dv->setMax(
v->getMax());
1785 if (
auto dc =
dynamic_cast<RooCategory *
>(
p->get()->find(
c->GetName())); dc) {
1786 if (!dc->hasLabel(
c->getCurrentLabel())) {
1787 dc->defineType(
c->getCurrentLabel(),
c->getCurrentIndex());
1793 for (
int i = 1; i <= _h->GetNbinsX(); i++) {
1795 if (!_h->GetXaxis()->GetBinLabel(i)) {
1796 throw std::runtime_error(
1797 TString::Format(
"Categorical observable %s requires bin labels", _ax->GetParent()->GetName()));
1798 }
else if (!cat->hasLabel(_h->GetXaxis()->GetBinLabel(i))) {
1799 throw std::runtime_error(
TString::Format(
"Categorical observable %s does not have label %s",
1800 _ax->GetParent()->GetName(), _h->GetXaxis()->GetBinLabel(i)));
1802 cat->setLabel(_h->GetXaxis()->GetBinLabel(i));
1805 dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent())->setVal(_h->GetBinCenter(i));
1807 p->add(
obs, _h->GetBinContent(i));
1813 if (
auto p = get<RooAddPdf>();
p) {
1817 auto _pdf = std::dynamic_pointer_cast<RooAbsPdf>(out);
1819 throw std::runtime_error(
"Something went wrong with pdf acquisition");
1826 if (
auto _boundaries = std::unique_ptr<std::list<double>>(_p->binBoundaries(
1827 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
1828 std::numeric_limits<double>::infinity()));
1829 !_boundaries && _ax->GetNbins() > 0) {
1830#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
1831 Warning(
"Add",
"Adding unbinned pdf %s to binned %s - will wrap with RooBinSamplingPdf(...)",
1833 _p = acquireNew<RooBinSamplingPdf>(
TString::Format(
"%s_binned", _p->GetName()), _p->GetTitle(),
1835 _p->setStringAttribute(
"alias", std::dynamic_pointer_cast<RooAbsArg>(out)->getStringAttribute(
"alias"));
1836 if (!_p->getStringAttribute(
"alias"))
1837 _p->setStringAttribute(
"alias", out->GetName());
1839 throw std::runtime_error(
1840 "unsupported addition of unbinned pdf to binned model - please upgrade to at least ROOT 6.24");
1846 if (!(_pdf->canBeExtended() &&
p->coefList().empty())) {
1850 if (_pdf->canBeExtended()) {
1855 .add(*acquireNew<RooExtendedBinding>(
TString::Format(
"%s_extBind", _pdf->GetName()),
1861 for (
auto i =
p->coefList().size(); i <
p->pdfList().size(); i++) {
1863 .add(*acquireNew<RooExtendedBinding>(
1866 *
static_cast<RooAbsPdf *
>(
p->pdfList().at(i))));
1869 const_cast<RooArgList &
>(
p->coefList()).add(*acquire2<RooAbsArg, RooRealVar>(
"1",
"1", 1));
1872 *
reinterpret_cast<bool *
>(
reinterpret_cast<unsigned char *
>(
p) +
1874 *
reinterpret_cast<bool *
>(
reinterpret_cast<unsigned char *
>(
p) +
1877 const_cast<RooArgList &
>(
p->pdfList()).add(*_pdf);
1881 (!
child.get() && getObject<RooAbsReal>(
child.GetName()))) &&
1884 bool tooMany(
false);
1897 }
else if (!tooMany) {
1902 _sumpdf.get<
RooAbsArg>()->setStringAttribute(
"alias",
"samples");
1903 return _sumpdf.Add(
child);
1908 if (
auto p = get<RooRealSumPdf>();
p) {
1909 std::shared_ptr<TObject> out;
1910 auto cc =
child.fComp;
1911 bool isConverted = (cc !=
child.convertForAcquisition(*
this, sOpt));
1914 if (std::dynamic_pointer_cast<TH1>(cc) && !
TString(cc->GetOption()).
Contains(
"nostyle")) {
1918 if (!
child.fComp && getObject<RooAbsReal>(
child.GetName())) {
1919 Info(
"Add",
"Adding existing function %s to %s",
child.GetName(),
p->
GetName());
1920 out = getObject<RooAbsReal>(
child.GetName());
1923 if (!out && !
child.fComp) {
1924 std::shared_ptr<RooAbsArg> _func;
1935 std::make_unique<TH1D>(
child.GetName(),
child.GetTitle(), _ax->GetNbins(), _ax->binning()->array());
1937 h->GetXaxis()->SetName(
TString::Format(
"%s;%s", _ax->GetParent()->GetName(), _ax->GetName()));
1940 }
else if (_obs.size() == 1) {
1944 TString binningName =
p->getStringAttribute(
"binning");
1945 for (
auto &
b : _bnames) {
1953 auto h = std::make_unique<TH1D>(
child.GetName(),
child.GetTitle(), _x->numBins(binningName),
1954 _x->getBinningPtr(binningName)->array());
1956 h->GetXaxis()->SetName(
1960 Info(
"Add",
"Created densityhisto factor %s (xaxis=%s) for %s", _func->GetName(), _obs.at(0)->GetName(),
1963 throw std::runtime_error(
"Unsupported creation of new component in SumPdf for this many obs");
1969 _func->setStringAttribute(
"alias",
child.GetName());
1973 if (
auto _f = std::dynamic_pointer_cast<RooHistFunc>(
1977 _f->setAttribute(
"density");
1978 if (_f->getAttribute(
"autodensity")) {
1980 for (
int i = 0; i < _f->dataHist().numEntries(); i++) {
1981 auto bin_pars = _f->dataHist().get(i);
1982 _f->dataHist().set(*bin_pars, _f->dataHist().weight() / _f->dataHist().binVolume(*bin_pars));
1984 _f->setAttribute(
"autodensity",
false);
1985 _f->setValueDirty();
1994 Info(
"Add",
"Created %s factor RooHistFunc::%s for %s",
1995 _f->getAttribute(
"density") ?
"densityhisto" :
"histo", _f->GetName(),
p->
GetName());
1999 if (
auto _p = std::dynamic_pointer_cast<RooAbsPdf>(out); _p) {
2003 TString newName(_p->GetName());
2005 newName +=
"_components";
2006 Warning(
"Add",
"converting samples to components");
2011 if (
auto _boundaries = std::unique_ptr<std::list<double>>(_p->binBoundaries(
2012 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
2013 std::numeric_limits<double>::infinity()));
2014 !_boundaries && _ax->GetNbins() > 0) {
2015#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
2016 Warning(
"Add",
"Adding unbinned pdf %s to binned %s - will wrap with RooBinSamplingPdf(...)",
2018 _p = acquireNew<RooBinSamplingPdf>(
TString::Format(
"%s_binned", _p->GetName()), _p->GetTitle(),
2020 _p->setStringAttribute(
"alias", std::dynamic_pointer_cast<RooAbsArg>(out)->getStringAttribute(
"alias"));
2021 if (!_p->getStringAttribute(
"alias"))
2022 _p->setStringAttribute(
"alias", out->GetName());
2024 throw std::runtime_error(
2025 "unsupported addition of unbinned pdf to binned model - please upgrade to at least ROOT 6.24");
2032 if (!_p->canBeExtended()) {
2033 _p = acquireNew<RooExtendPdf>(
TString::Format(
"%s_extended", _p->GetName()), _p->GetTitle(), *_p,
2034 *acquire2<RooAbsReal, RooRealVar>(
"1",
"1", 1));
2037 return *(
Replace(*acquireNew<RooAddPdf>(newName, _p->GetTitle(),
RooArgList(*
p, *_p)))
2041 if (
auto _f = std::dynamic_pointer_cast<RooAbsReal>(out); _f) {
2050 if (
auto _boundaries = std::unique_ptr<std::list<double>>(_f->binBoundaries(
2051 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
2052 std::numeric_limits<double>::infinity()));
2053 !_boundaries && _ax->GetNbins() > 0) {
2054#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
2057 "Adding unbinned function %s to binned %s - will wrap with RooRealSumPdf(RooBinSamplingPdf(...))",
2059 auto sumPdf = acquireNew<RooRealSumPdf>(
TString::Format(
"%s_pdfWrapper", _f->GetName()), _f->GetTitle(),
2060 *_f, *acquire2<RooAbsArg, RooRealVar>(
"1",
"1", 1),
true);
2061 sumPdf->setStringAttribute(
"alias", _f->getStringAttribute(
"alias"));
2062 if (!sumPdf->getStringAttribute(
"alias"))
2063 sumPdf->setStringAttribute(
"alias", out->GetName());
2064 _f = acquireNew<RooBinSamplingPdf>(
TString::Format(
"%s_binned", _f->GetName()), _f->GetTitle(),
2066 _f->setStringAttribute(
"alias", std::dynamic_pointer_cast<RooAbsArg>(out)->getStringAttribute(
"alias"));
2067 if (!_f->getStringAttribute(
"alias"))
2068 _f->setStringAttribute(
"alias", out->GetName());
2070 throw std::runtime_error(
2071 "unsupported addition of unbinned function to binned model - please upgrade to at least ROOT 6.24");
2076 const_cast<RooArgList &
>(
p->coefList()).add(*acquire2<RooAbsArg, RooRealVar>(
"1",
"1", 1));
2079 if (!
p->getStringAttribute(
"binning"))
2080 p->setStringAttribute(
"binning", _f->getStringAttribute(
"binning"));
2083 if (
auto gf =
p->getStringAttribute(
"global_factors"); gf) {
2086 auto fac = getObject<RooAbsReal>(pattern.
Data());
2088 throw std::runtime_error(
TString::Format(
"Could not find global factor %s", pattern.
Data()));
2097 p->setStringAttribute(
"xvar",
nullptr);
2101 }
else if (
auto p2 = get<RooProdPdf>(); p2) {
2108 bool tooMany(
false);
2121 }
else if (!tooMany) {
2122 auto out = this->
operator[](
"components")->Add(child);
2126 (!
child.get() && getObject<RooAbsReal>(
child.GetName()))) &&
2130 bool tooMany(
false);
2139 }
else if (
auto _p2 =
pp->get<
RooAddPdf>(); _p2) {
2141 for (
auto &_pdfa :
pp->components()) {
2155 }
else if (_backup) {
2158 }
else if (!tooMany) {
2159 auto out = this->
operator[](
"samples")->Add(child);
2162 p2->setStringAttribute(
"xvar",
nullptr);
2166 }
else if (
auto s = get<RooSimultaneous>(); s) {
2174 }
else if (
auto w = get<RooWorkspace>();
w) {
2175 child.convertForAcquisition(
2176 *
this,
child.get() ?
"" :
"func" );
2180 if (!
w->import(*_d)) {
2183 std::unique_ptr<RooAbsCollection>(
w->allVars().selectCommon(*_d->get()))->setAttribAll(
"obs");
2185 if (_d->getGlobalObservables()) {
2186 std::unique_ptr<RooAbsCollection>
globs(
w->allVars().selectCommon(*_d->get()));
2187 globs->setAttribAll(
"obs");
2188 globs->setAttribAll(
"global");
2192 throw std::runtime_error(
2203 if (!
child.empty() ||
child.fFolder ==
"!pdfs") {
2206 std::string catName =
"channelCat";
2207 if (!
child.empty()) {
2208 if (
TString ss =
child.at(0)->GetName(); ss.Contains(
"=")) {
2209 catName = ss(0, ss.Index(
'='));
2212 auto _cat = acquire<RooCategory>(catName.c_str(), catName.c_str());
2213 _cat->setAttribute(
"obs");
2214 auto out = acquireNew<RooSimultaneous>(
child.GetName(),
child.GetTitle(), *_cat);
2215 Info(
"Add",
"Created pdf RooSimultaneous::%s in workspace %s", out->GetName(),
w->GetName());
2220 if (sOpt ==
"pdf") {
2222 if (get<RooWorkspace>()) {
2226 }
else if (sOpt ==
"channel") {
2228 if (get<RooSimultaneous>()) {
2230 }
else if (get<RooWorkspace>()) {
2231 std::shared_ptr<TObject> out;
2232 child.convertForAcquisition(*
this);
2235 }
else if (!
child.fComp) {
2236 out = acquireNew<RooProdPdf>(
child.GetName(),
2238 Info(
"Add",
"Created channel RooProdPdf::%s in workspace %s", out->GetName(),
get()->
GetName());
2242 }
else if (sOpt ==
"sample" || sOpt ==
"func") {
2243 if (get<RooProdPdf>()) {
2246 return _mainChild.Add(
child, sOpt ==
"func" ?
"func" :
"");
2248 return (*
this)[
"samples"]->Add(
child, sOpt ==
"func" ?
"func" :
"");
2251 }
else if (sOpt ==
"dataset") {
2252 if (get<RooWorkspace>()) {
2254 return (*this).datasets().Add(
child);
2261 if (get<RooSimultaneous>()) {
2265 }
else if (get<RooProduct>() || get<RooProdPdf>()) {
2311 if (
auto a = get<RooAbsArg>()) {
2312 a->setAttribute(
"hidden", set);
2321 auto a = get<RooAbsArg>();
2323 return a->getAttribute(
"hidden");
2330 if (
get() == rhs.
get()) {
2380 if (
auto s = get<RooSimultaneous>(); s) {
2381 auto chans =
bins();
2382 if (!chans.empty()) {
2388 for (
auto &
c : chans) {
2390 cName = cName(cName.
Index(
'=') + 1, cName.
Length());
2393 c->shallowCopy(
name +
"_" +
c->get()->GetName(), std::shared_ptr<xRooNode>(&out, [](
xRooNode *) {}));
2394 pdf->addPdf(*
dynamic_cast<RooAbsPdf *
>(c_copy.get()), cName);
2399 }
else if (
auto p =
dynamic_cast<RooProdPdf *
>(o);
p) {
2401 std::shared_ptr<RooProdPdf> pdf =
2402 std::dynamic_pointer_cast<RooProdPdf>(out.acquire(std::shared_ptr<TObject>(
p->
Clone()),
false,
2407 std::dynamic_pointer_cast<RooAbsArg>(out.acquire(std::shared_ptr<TObject>(
main->Clone()),
false,
true));
2408 std::cout << newMain <<
" " << newMain->GetName() << std::endl;
2423 static std::unique_ptr<cout_redirect> capture;
2424 std::string captureStr;
2425 bool doCapture =
false;
2426 if (!capture &&
gROOT->FromPopUp()) {
2427 capture = std::make_unique<cout_redirect>(captureStr);
2450 if (
get() &&
get() !=
this) {
2452 if (_more || (get<RooAbsArg>() && get<RooAbsArg>()->isFundamental()) || get<RooConstVar>() ||
2453 get<RooAbsData>() || get<RooProduct>() || get<RooFitResult>()) {
2455 auto _snap = std::unique_ptr<RooAbsCollection>(_deps.snapshot());
2458 if (
auto _fr = get<RooFitResult>(); _fr &&
dynamic_cast<RooStringVar *
>(_fr->constPars().
find(
".log"))) {
2459 std::cout <<
"Minimization Logs:" << std::endl;
2460 std::cout << dynamic_cast<RooStringVar *>(_fr->constPars().find(
".log"))->getVal() << std::endl;
2462 _deps.assignValueOnly(*_snap);
2472 if (
auto fv = get<RooFormulaVar>()) {
2474 for (
size_t i = 0; i < fv->dependents().
size(); i++) {
2478 }
else if (
auto gv = get<RooGenericPdf>()) {
2480 for (
size_t i = 0; i < gv->dependents().
size(); i++) {
2488 }
else if (!
get()) {
2489 std::cout << std::endl;
2493 std::vector<std::string> folderNames;
2494 for (
auto &k : *
this) {
2495 if (std::find(folderNames.begin(), folderNames.end(), k->fFolder) == folderNames.end()) {
2496 folderNames.push_back(k->fFolder);
2499 for (
auto &
f : folderNames) {
2503 for (
int j = 0; j <
indent; j++)
2505 std::cout <<
f << std::endl;
2508 for (
auto &k : *
this) {
2509 if (k->fFolder !=
f) {
2513 for (
int j = 0; j < iindent; j++)
2515 std::cout << i++ <<
") " << k->GetName() <<
" : ";
2519 auto _deps = k->coords(
false).argList();
2520 auto _snap = std::unique_ptr<RooAbsCollection>(_deps.snapshot());
2522 k->get()->Print(sOpt);
2523 _deps.assignValueOnly(*_snap);
2526 if (
auto _type = k->GetNodeType(); strlen(_type)) {
2534 for (
size_t j = 0; j < fv->dependents().
size(); j++) {
2540 for (
size_t j = 0; j < gv->dependents().
size(); j++) {
2545 std::cout << k->get()->ClassName() <<
"::" << k->get()->GetName() << _suffix.
Data() << std::endl;
2548 k->Print(sOpt +
TString::Format(
"depth=%dindent=%d", depth - 1, iindent + 1));
2551 std::cout <<
" NULL " << std::endl;
2557 size_t lastBreak = 0;
2558 std::string captureStrWithBreaks;
2559 for (
size_t i = 0; i < captureStr.size(); i++) {
2560 captureStrWithBreaks += captureStr[i];
2561 if (captureStr[i] ==
'\n') {
2564 if (i - lastBreak > 150) {
2565 captureStrWithBreaks +=
'\n';
2570 (
gROOT->GetListOfBrowsers()->At(0))
2574 captureStrWithBreaks.c_str());
2582 if (
auto v = get<RooRealVar>();
v) {
2585 double mean = std::numeric_limits<double>::quiet_NaN();
2586 double sigma = mean;
2595 mean = std::numeric_limits<double>::quiet_NaN();
2598 constrType =
"normal";
2599 }
else if (constrType ==
"normal") {
2602 }
else if (constrType ==
"gaussian") {
2606 throw std::runtime_error(
"No error on parameter for gaussian constraint");
2609 constrType =
"normal";
2610 }
else if (constrType ==
"poisson") {
2612 throw std::runtime_error(
"No error on parameter for poisson constraint");
2614 sigma = pow(
v->getVal() /
v->getError(), 2);
2617 if (constrType ==
"poisson") {
2619 double tau_val =
sigma;
2620 auto globs = acquire<RooRealVar>(
Form(
"globs_%s",
v->GetName()),
Form(
"globs_%s",
v->GetName()),
2621 v->getVal() * tau_val, (
v->getVal() - 5 *
v->getError()) * tau_val,
2622 (
v->getVal() + 5 *
v->getError()) * tau_val);
2623 globs->setConstant();
2624 globs->setAttribute(
"obs");
2625 globs->setAttribute(
"global");
2627 auto tau = acquireNew<RooConstVar>(
TString::Format(
"tau_%s",
v->GetName()),
"", tau_val);
2628 auto constr = acquireNew<RooPoisson>(
2637 v->setError(mean / sqrt(tau_val));
2638 Info(
"Constrain",
"Added poisson constraint pdf RooPoisson::%s (tau=%g) for %s", out->GetName(), tau_val,
2641 }
else if (constrType ==
"normal") {
2643 auto globs = acquire<RooRealVar>(
Form(
"globs_%s",
v->GetName()),
Form(
"globs_%s",
v->GetName()), mean,
2645 globs->setAttribute(
"obs");
2646 globs->setAttribute(
"global");
2647 globs->setConstant();
2650 auto constr = acquireNew<RooGaussian>(
2656 Info(
"Constrain",
"Added gaussian constraint pdf RooGaussian::%s (mean=%g,sigma=%g) for %s", out->GetName(),
2663 auto _me = get<RooAbsArg>();
2665 throw std::runtime_error(
"Cannot constrain non arg");
2668 if (!
p->dependsOn(*_me)) {
2669 throw std::runtime_error(
"Constraint does not depend on constrainee");
2678 throw std::runtime_error(
"Nowhere to put constraint");
2681 auto childGlobs =
child.globs();
2682 if (!childGlobs.empty()) {
2683 for (
auto d :
x->datasets()) {
2687 d->get<
RooAbsData>()->setGlobalObservables(newGlobs);
2693 if (k ==
"globalObservables" ||
TString(k).
EndsWith(
"_GlobalObservables")) {
2702 for (
auto &
c : *
x) {
2708 return x->Multiply(
child);
2710 return x->Add(
child,
"+");
2723 ~AutoUpdater() {
n.browse(); }
2726 AutoUpdater xxx(*
this);
2733 auto o = std::dynamic_pointer_cast<RooAbsReal>(
acquire(
child.fComp));
2756 ?
fParent->mainChild()->GetName()
2761 binFactors =
fParent->factors().find(
"binFactors");
2763 throw std::runtime_error(
2770 for (
auto &
b : binFactors->bins()) {
2771 auto p = acquireNew<RooProduct>(
TString::Format(
"%s_bin%d", binFactors->get()->GetName(), i),
2773 p->setStringAttribute(
"alias",
TString::Format(
"%s=%g", binFactors->GetXaxis()->GetParent()->GetName(),
2774 binFactors->GetXaxis()->GetBinCenter(i)));
2781 auto _bin = binFactors->bins().at(
fBinNumber - 1);
2782 if (
auto phf = binFactors->get<
ParamHistFunc>(); phf && _bin) {
2783#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2788 if (strcmp(_bin->GetName(),
"1") == 0) {
2790 for (std::size_t i = 0; i < pSet.
size(); i++) {
2792 all.
add(*pSet.
at(i));
2800 _bin->fBinNumber = -1;
2801 return _bin->Multiply(
child, opt);
2829 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(
child), [](
TObject *) {}));
2834 std::rethrow_exception(std::current_exception());
2842 if (
auto o = getObject<RooAbsReal>(
child.GetName())) {
2846 Info(
"Multiply",
"Scaled %s by existing factor %s::%s",
2850 }
else if (sOpt ==
"norm") {
2857 Info(
"Multiply",
"Scaled %s by new norm factor %s",
2862 throw std::runtime_error(
TString::Format(
"Failed to create new normFactor %s",
child.GetName()));
2866 Info(
"Multiply",
"Scaled %s by new norm factor %s",
2870 }
else if (sOpt ==
"shape" || sOpt ==
"histo" || sOpt ==
"blankshape") {
2875 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
2876 h->SetBinContent(i, 1);
2881 h->SetTitle(
child.GetTitle());
2886 Info(
"Multiply",
"Scaled %s by new %s factor %s",
2891 }
else if (sOpt ==
"overall") {
2892 auto out =
Multiply(acquireNew<RooStats::HistFactory::FlexibleInterpVar>(
2893 child.GetName(),
child.GetTitle(),
RooArgList(), 1, std::vector<double>(), std::vector<double>()));
2895 Info(
"Multiply",
"Scaled %s by new overall factor %s",
2899 }
else if (sOpt ==
"func" &&
ws()) {
2904 Info(
"Multiply",
"Scaled %s by new func factor %s",
2911 if (
auto h =
child.get<
TH1>();
h && strlen(
h->GetOption()) == 0 && strlen(opt) > 0) {
2915 if (
auto w = get<RooWorkspace>();
w) {
2917 std::shared_ptr<TObject> out;
2918 child.convertForAcquisition(*
this);
2924 if (strcmp(
GetName(),
".coef") == 0) {
2929 if (
p->coefList().empty() && !
p->pdfList().empty()) {
2930 for (
auto _pdf :
p->pdfList()) {
2932 .add(*acquireNew<RooExtendedBinding>(
TString::Format(
"%s_extBind", _pdf->GetName()),
2936 Info(
"Multiply",
"Created RooExtendedBinding coefficients for all pdfs of %s so that can multiply coef",
2938 *
reinterpret_cast<bool *
>(
reinterpret_cast<unsigned char *
>(
p) +
2940 *
reinterpret_cast<bool *
>(
reinterpret_cast<unsigned char *
>(
p) +
2943 for (
size_t i = 0; i <
p->pdfList().size(); i++) {
2945 auto coefs =
p->coefList().at(i);
2954 for (
size_t j = 0; j <
p->coefList().size(); j++) {
2956 oldCoefs.
add(*newCoefs);
2958 oldCoefs.add(*
p->coefList().at(j));
2961 const_cast<RooArgList &
>(
p->coefList()).removeAll();
2962 const_cast<RooArgList &
>(
p->coefList()).add(oldCoefs);
2969 throw std::runtime_error(
"this coefs case is not supported");
2972 if (
auto p = get<RooProduct>();
p) {
2973 std::shared_ptr<TObject> out;
2974 auto cc =
child.fComp;
2975 bool isConverted = (
child.convertForAcquisition(*
this) != cc);
2980 if (
auto _f = std::dynamic_pointer_cast<RooHistFunc>(
2982 _f && _f->getAttribute(
"autodensity")) {
2984 bool hasDensity =
false;
2992 if (_f->getAttribute(
"density")) {
2995 for (
int i = 0; i < _f->dataHist().numEntries(); i++) {
2996 auto bin_pars = _f->dataHist().get(i);
2997 _f->dataHist().set(*bin_pars, _f->dataHist().weight() / _f->dataHist().binVolume(*bin_pars));
2999 _f->setValueDirty();
3006 _f->setAttribute(
"autodensity",
false);
3010 Info(
"Multiply",
"Created %s factor %s in %s",
3014 Info(
"Multiply",
"Created shape factor %s in %s",
child->GetName(),
p->
GetName());
3017 if (
auto _f = std::dynamic_pointer_cast<RooAbsReal>(out); _f) {
3018#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3019 p->_compRSet.add(*_f);
3021 const_cast<RooArgList &
>(
p->realComponents()).add(*_f);
3027 for (
auto &_par : _out.
pars()) {
3030 for (
auto &_constr : _par->constraints()) {
3031 if (strcmp(s, _constr->get()->GetName()) == 0) {
3038 Info(
"Multiply",
"Pulling in %s boundConstraint: %s", _par->GetName(), s);
3039 auto _pdf = getObject<RooAbsPdf>(s);
3041 throw std::runtime_error(
"Couldn't find boundConstraint");
3043 _par->Constrain(_pdf);
3050 }
else if (
auto p2 = get<RooProdPdf>(); p2) {
3052 std::shared_ptr<TObject> out;
3053 child.convertForAcquisition(*
this);
3062 std::shared_ptr<RooAbsPdf> _pdf;
3063 if (!
child.get() && strcmp(
child.GetName(),
"components") == 0) {
3064 auto _sumpdf = acquireNew<RooAddPdf>(
3065 Form(
"%s_%s", p2->GetName(),
child.GetName()),
3071 auto _sumpdf = acquireNew<RooRealSumPdf>(
3072 Form(
"%s_%s", p2->GetName(),
child.GetName()),
3076 _sumpdf->setFloor(
true);
3079 _pdf->setStringAttribute(
"alias",
child.GetName());
3081 _pdf->setStringAttribute(
"xvar", p2->getStringAttribute(
"xvar"));
3082 _pdf->setStringAttribute(
"binning", p2->getStringAttribute(
"binning"));
3084 Info(
"Multiply",
"Created %s::%s in channel %s", _pdf->ClassName(), _pdf->GetName(), p2->GetName());
3089 if (
auto _pdf = std::dynamic_pointer_cast<RooAbsPdf>(out); _pdf) {
3090#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3091 const_cast<RooArgList &
>(p2->pdfList()).add(*_pdf);
3092#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
3093 p2->_pdfNSetList.emplace_back(std::make_unique<RooArgSet>(
"nset"));
3097 if (!p2->canBeExtended() && _pdf->canBeExtended()) {
3098 p2->_extendedIndex = p2->_pdfList.size() - 1;
3107 }
else if (
auto p3 = get<RooRealSumPdf>(); p3) {
3109 std::shared_ptr<TObject> out;
3110 child.convertForAcquisition(*
this);
3116 TString s = p3->getStringAttribute(
"global_factors");
3119 s += out->GetName();
3120 p3->setStringAttribute(
"global_factors", s);
3123 "Flagged %s as a global factor in channel %s (is applied to all current and future samples in the channel)",
3124 out->GetName(), p3->GetName());
3135 std::set<RooAbsArg *> cl;
3136 for (
auto &arg : p5->clients()) {
3142 if (cl.size() > 1) {
3147 Warning(
"Multiply",
"Scaling %s that has multiple clients", p5->GetName());
3153 for (
auto &
a : p5->attributes())
3154 new_p->setAttribute(
a.c_str());
3155 for (
auto &
a : p5->stringAttributes())
3156 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
3157 if (!new_p->getStringAttribute(
"alias"))
3158 new_p->setStringAttribute(
"alias", p5->GetName());
3160 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
3161 for (
auto arg : cl) {
3162 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
3170 if (!
child.get() && strlen(opt) == 0)
3173 throw std::runtime_error(
3175 (!
child.get() && strlen(opt) == 0) ?
" (forgot to specify factor type?)" :
""));
3181 auto p5 = get<RooAbsArg>();
3183 throw std::runtime_error(
"Only replacement of RooAbsArg is supported");
3192 new_p = std::dynamic_pointer_cast<RooAbsArg>(out).get();
3194 std::set<RooAbsArg *> cl;
3195 for (
auto &arg : p5->clients()) {
3203 if (cl.size() > 1) {
3208 std::stringstream clientList;
3210 clientList <<
c->GetName() <<
",";
3211 Warning(
"Replace",
"Replacing %s in all clients: %s", p5->GetName(), clientList.str().c_str());
3215 new_p->setAttribute(
Form(
"ORIGNAME:%s", p5->GetName()));
3216 for (
auto arg : cl) {
3221 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
3232 ~AutoUpdater() {
n.browse(); }
3235 AutoUpdater xxx(*
this);
3240 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(
child), [](
TObject *) {}));
3245 std::rethrow_exception(std::current_exception());
3257 std::string label =
child.GetName();
3258 if (
auto pos = label.find(
'='); pos != std::string::npos)
3259 label = label.substr(pos + 1);
3260 if (!s->indexCat().hasLabel(label)) {
3263 std::shared_ptr<TObject> out;
3264 child.convertForAcquisition(*
this);
3267 }
else if (!
child.fComp) {
3268 out = acquireNew<RooProdPdf>(
TString::Format(
"%s_%s", s->GetName(), label.c_str()),
3270 Info(
"Vary",
"Created channel RooProdPdf::%s in model %s", out->GetName(), s->GetName());
3273 if (
auto _pdf = std::dynamic_pointer_cast<RooAbsPdf>(out); _pdf) {
3274 s->addPdf(*_pdf, label.c_str());
3283 }
else if (
auto p = get<RooStats::HistFactory::FlexibleInterpVar>();
p) {
3286 child.convertForAcquisition(*
this);
3288 if (!_c &&
child.get()) {
3289 throw std::runtime_error(
"Only pure consts can be set as variations of a flexible interpvar");
3291#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3292 double value = (_c ? _c->getVal() :
p->_nominal);
3293 double nomVal =
p->_nominal;
3295 double value = (_c ? _c->getVal() :
p->nominal());
3296 double nomVal =
p->nominal();
3300 if (cName ==
"nominal") {
3305 throw std::runtime_error(
"unsupported variation form");
3307 std::string parName = cName(0, cName.
Index(
'='));
3309 if (parVal != 1 && parVal != -1) {
3310 throw std::runtime_error(
"unsupported variation magnitude");
3312 bool high = parVal > 0;
3314 if (parName.empty()) {
3323 if (!
p->findServer(*
v)) {
3324#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3325 p->_paramList.add(*
v);
3326 p->_low.push_back(0);
3327 p->_high.push_back(0);
3328 p->_interpCode.push_back(4);
3331 const_cast<std::vector<double> &
>(
p->low()).push_back(0);
3332 const_cast<std::vector<double> &
>(
p->high()).push_back(0);
3333 const_cast<std::vector<int> &
>(
p->interpolationCodes()).push_back(4);
3335 v->setAttribute(
Form(
"SYMMETRIC%s_%s", high ?
"+" :
"-",
GetName()));
3340 if (
v->getAttribute(
Form(
"SYMMETRIC+_%s",
GetName()))) {
3341 p->setLow(*
v, 2 * nomVal -
value);
3343 v->setAttribute(
Form(
"SYMMETRIC-_%s",
GetName()),
false);
3346 if (
v->getAttribute(
Form(
"SYMMETRIC-_%s",
GetName()))) {
3347 p->setHigh(*
v, 2 * nomVal -
value);
3349 v->setAttribute(
Form(
"SYMMETRIC+_%s",
GetName()),
false);
3357 }
else if (
auto p2 = get<PiecewiseInterpolation>(); p2) {
3360 throw std::runtime_error(
"unsupported variation form");
3364 if (parVal != 1 && parVal != -1) {
3365 throw std::runtime_error(
"unsupported variation magnitude");
3367#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3370 throw std::runtime_error(
3371 TString::Format(
"Interpolating %s instead of RooHistFunc", p2->_nominal.absArg()->ClassName()));
3376 throw std::runtime_error(
3377 TString::Format(
"Interpolating %s instead of RooHistFunc", p2->nominalHist()->ClassName()));
3383 for (
auto par : p2->paramList()) {
3384 if (parName == par->GetName()) {
3385 f =
dynamic_cast<RooHistFunc *
>((parVal > 0 ? p2->highList() : p2->lowList()).
at(i));
3386 otherf =
dynamic_cast<RooHistFunc *
>((parVal > 0 ? p2->lowList() : p2->highList()).
at(i));
3394 auto v = acquire<RooRealVar>(parName, parName, -5, 5);
3398 std::shared_ptr<RooHistFunc> up(
3400 std::shared_ptr<RooHistFunc> down(
3403#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3404 std::unique_ptr<RooDataHist>
h1(
3405 static_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", up->GetName()))));
3406 std::unique_ptr<RooDataHist> h2(
3407 static_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", down->GetName()))));
3408 up->_dataHist =
dynamic_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", up->GetName())));
3409 down->_dataHist =
dynamic_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", down->GetName())));
3412 down->cloneAndOwnDataHist(
TString::Format(
"hist_%s", down->GetName()));
3414 auto ups = std::dynamic_pointer_cast<RooHistFunc>(
acquire(up,
false,
true));
3415 auto downs = std::dynamic_pointer_cast<RooHistFunc>(
acquire(down,
false,
true));
3416#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3417 p2->_highSet.add(*ups.get());
3418 p2->_lowSet.add(*downs.get());
3419 p2->_interpCode.push_back(4);
3420 p2->_paramSet.add(*
v);
3422 const_cast<RooArgList &
>(p2->highList()).add(*ups);
3423 const_cast<RooArgList &
>(p2->lowList()).add(*downs);
3424 const_cast<std::vector<int> &
>(p2->interpolationCodes()).push_back(4);
3425 const_cast<RooArgList &
>(p2->paramList()).add(*
v);
3427 p2->setValueDirty();
3428 f = ((parVal > 0) ? ups : downs).
get();
3429 otherf = ((parVal > 0) ? downs : ups).
get();
3431 f->setStringAttribute(
"symmetrizes", otherf->
GetName());
3432 f->setStringAttribute(
"symmetrize_nominal", nomf->
GetName());
3451 }
else if (
auto p3 = get<RooConstVar>(); p3) {
3454 if (p3->getAttribute(
"RooRealConstant_Factory_Object")) {
3455 throw std::runtime_error(
"Cannot vary pure constants");
3461 std::set<RooAbsArg *> cl;
3462 for (
auto &arg : p3->clients()) {
3467 if (cl.size() > 1) {
3472 Warning(
"Vary",
"Varying %s that has multiple clients", p3->GetName());
3475 p3->setStringAttribute(
"origName", p3->GetName());
3477 p3->SetName(
Form(
"%s_nominal", p3->GetName()));
3479 auto new_p = acquireNew<RooStats::HistFactory::FlexibleInterpVar>(
n, p3->GetTitle(),
RooArgList(), p3->getVal(),
3480 std::vector<double>(), std::vector<double>());
3483 for (
auto &
a : p3->attributes())
3484 new_p->setAttribute(
a.c_str());
3485 for (
auto &
a : p3->stringAttributes())
3486 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
3489 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
3490 for (
auto arg : cl) {
3491 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
3497 }
else if (
auto p4 = get<RooAbsReal>(); p4) {
3501 std::set<RooAbsArg *> cl;
3502 for (
auto &arg : p4->clients()) {
3507 if (cl.size() > 1) {
3512 Warning(
"Vary",
"Varying %s that has multiple clients", p4->GetName());
3515 p4->setStringAttribute(
"origName", p4->GetName());
3517 p4->SetName(
Form(
"%s_nominal", p4->GetName()));
3522 for (
auto &
a : p4->attributes())
3523 new_p->setAttribute(
a.c_str());
3524 for (
auto &
a : p4->stringAttributes())
3525 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
3528 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
3529 for (
auto arg : cl) {
3530 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
3571 if (
auto a = get<RooAbsArg>();
a && strcmp(
a->GetName(),
GetName()) && !
a->getStringAttribute(
"alias")) {
3572 a->setStringAttribute(
"alias",
GetName());
3575 throw std::runtime_error(
"Cannot determine type");
3580 if (
auto h =
dynamic_cast<const TH1 *
>(&o);
h) {
3591 bool _isData = get<RooAbsData>();
3597 throw std::runtime_error(
"no xaxis");
3598 auto _v =
dynamic_cast<RooRealVar *
>(ax->GetParent());
3601 _b.
b =
dynamic_cast<RooAbsBinning *
>(_v->getBinningPtr(
nullptr)->Clone());
3602 if (
h->GetXaxis()->IsVariableBinSize()) {
3603 _v->setBinning(
RooBinning(
h->GetNbinsX(),
h->GetXaxis()->GetXbins()->GetArray()));
3605 _v->setBinning(
RooUniformBinning(
h->GetXaxis()->GetXmin(),
h->GetXaxis()->GetXmax(),
h->GetNbinsX()));
3611 for (
int bin = 1; bin <=
h->GetNbinsX(); bin++) {
3619 if (!_isData &&
h->GetSumw2N() && !
SetBinError(bin,
h->GetBinError(bin)))
3620 throw std::runtime_error(
"Failed setting stat error");
3624 }
else if (
auto _c =
dynamic_cast<const RooConstVar *
>(&o); _c) {
3626 if (
auto a = get<RooAbsArg>();
3627 (
a &&
a->isFundamental()) || get<RooConstVar>() || get<RooStats::HistFactory::FlexibleInterpVar>()) {
3630 }
else if (get<RooAbsData>()) {
3636 throw std::runtime_error(
"Assignment failed");
3663 auto _pars =
pars();
3666 std::map<RooAbsRealLValue *, double> valsToSet;
3668 auto idx = pattern.
Index(
'=');
3671 (idx == -1) ? std::numeric_limits<double>::quiet_NaN() :
TString(pattern(idx + 1, pattern.
Length())).
Atof();
3672 for (
auto p : _pars.argList()) {
3674 p->setAttribute(
"Constant",
true);
3675 if (!std::isnan(val)) {
3686 for (
auto &
d : _dsets) {
3687 if (
d->get()->TestBit(1 << 20)) {
3688 dsetName =
d->get()->GetName();
3692 auto _nll =
nll(dsetName.
Data());
3694 for (
auto [
p,
v] : valsToSet) {
3697 _nll.fitConfigOptions()->SetValue(
"LogSize", 65536);
3698 _nll.fitConfig()->MinimizerOptions().SetPrintLevel(0);
3699 auto fr = _nll.minimize();
3702 throw std::runtime_error(
"Fit Failed");
3705 for (
unsigned int i = 0; i < fr->numStatusHistory(); i++) {
3706 statusCodes +=
TString::Format(
"\n%s = %d", fr->statusLabelHistory(i), fr->statusCodeHistory(i));
3709 (
gROOT->GetListOfBrowsers()->At(0))
3712 if (fr->status() != 0) {
3714 TString::Format(
"%s\nData = %s\nFit Status Code = %d\nCov Quality = %d\n-------------%s",
3715 fr->GetName(), dsetName.
Data(), fr->status(), fr->covQual(), statusCodes.
Data()),
3717 }
else if (fr->covQual() != 3 && _nll.fitConfig()->ParabErrors()) {
3718 new TGMsgBox(
gClient->GetRoot(),
w,
"Fit Finished with Bad Covariance Quality",
3719 TString::Format(
"%s\nData = %s\nFit Status Code = %d\nCov Quality = %d\n-------------%s",
3720 fr->GetName(), dsetName.
Data(), fr->status(), fr->covQual(), statusCodes.
Data()),
3724 TString::Format(
"%s\nData = %s\nFit Status Code = %d\nCov Quality = %d\n-------------%s",
3725 fr->GetName(), dsetName.
Data(), fr->status(), fr->covQual(), statusCodes.
Data()));
3727 }
catch (
const std::exception &
e) {
3730 (
gROOT->GetListOfBrowsers()->At(0))
3740 datasets().
Add(datasetName, expected ?
"asimov" :
"toy");
3741 }
catch (
const std::exception &
e) {
3744 (
gROOT->GetListOfBrowsers()->At(0))
3747 "Exception",
e.what(),
3753 double highX ,
const char *constParValues)
3762 for (
auto &
d : _dsets) {
3763 if (
d->get()->TestBit(1 << 20)) {
3764 dsetName =
d->get()->GetName();
3768 auto _pars =
pars();
3769 std::unique_ptr<RooAbsCollection> snap(_pars.argList().snapshot());
3772 auto idx = pattern.
Index(
'=');
3775 (idx == -1) ? std::numeric_limits<double>::quiet_NaN() :
TString(pattern(idx + 1, pattern.
Length())).
Atof();
3776 for (
auto par : _pars.argList()) {
3778 par->setAttribute(
"Constant",
true);
3779 if (!std::isnan(val)) {
3792 hs.SetTitle(sWhat +
" scan" + ((dsetName !=
"") ?
TString::Format(
" [data=%s]", dsetName.
Data()) :
""));
3793 int scanStatus = hs.scan(sWhat +
" visualize", nBinsX, lowX, highX);
3794 if (scanStatus != 0) {
3797 (
gROOT->GetListOfBrowsers()->At(0))
3800 "Scan Finished with Bad Status Code",
3801 TString::Format(
"%s\nData = %s\nScan Status Code = %d", hs.GetName(), dsetName.
Data(), scanStatus),
3806 if (
auto res = hs.result())
3810 _pars.argList() = *snap;
3812 }
catch (
const std::exception &
e) {
3815 (
gROOT->GetListOfBrowsers()->At(0))
3826 }
catch (
const std::exception &
e) {
3835#if ROOT_VERSION_CODE > ROOT_VERSION(6, 29, 00)
3840 for (
auto a : *
this) {
3847 for (
auto c : args) {
3853 f.SetParName(i,
c->GetName());
3855 f.SetParLimits(i,
v->getMin(),
v->getMax());
3856 if (
v->isConstant())
3857 f.FixParameter(i,
v->getVal());
3859 f.SetParameter(i,
v->getVal());
3860 f.SetParError(i,
v->getError());
3871 (
gROOT->GetListOfBrowsers()->At(0))
3877 for (i = 0; i <
f.GetNpar(); i++) {
3878 auto c = args.
find(
f.GetParName(i));
3883 f.GetParLimits(i, low, high);
3885 v->setConstant(low);
3887 v->setRange(low, high);
3897 throw std::runtime_error(
"Failed to SetContent");
3898 }
catch (
const std::exception &
e) {
3912 std::shared_ptr<TH1D>
h;
3913 auto _b =
dynamic_cast<Axis2 *
>(ax)->binning();
3916 if (_b->isUniform()) {
3921 h->SetOption(
"nostyle");
3922 h->SetDirectory(
nullptr);
3924 h->GetXaxis()->SetName(
TString::Format(
"%s;%s", ax->GetParent()->GetName(), ax->GetName()));
3932 if (get<RooProduct>()) {
3936 if (get<RooAbsData>()) {
3937 if (
auto _data = get<RooDataSet>(); _data) {
3938 auto _ax = (bin) ?
GetXaxis() :
nullptr;
3940 throw std::runtime_error(
"Cannot determine binning to fill data");
3942 if (_ax && _ax->GetNbins() < bin) {
3943 throw std::out_of_range(
TString::Format(
"%s range %s only has %d bins", _ax->GetParent()->GetName(),
3944 _ax->GetName(), _ax->GetNbins()));
3950 for (
auto _c :
coords()) {
3954 cut +=
TString::Format(
"%s==%d", _cat->GetName(), _cat->getCurrentIndex());
3961 TString::Format(
"%s>=%f&&%s<%f", _rv->GetName(), _rv->getMin(_rv->getStringAttribute(
"coordRange")),
3962 _rv->GetName(), _rv->getMax(_rv->getStringAttribute(
"coordRange")));
3965 throw std::runtime_error(
"SetBinContent of data: Unsupported coordinate type");
3974 cut2 =
TString::Format(
"%s >= %f && %s < %f", _ax->GetParent()->GetName(), _ax->GetBinLowEdge(bin),
3975 _ax->GetParent()->GetName(), _ax->GetBinUpEdge(bin));
4007 l.remove(*_data->get(),
true,
true);
4012 _data->addColumn(*
x);
4022 for (
auto &o :
obs) {
4024 if (
auto dv =
dynamic_cast<RooRealVar *
>(_data->get()->find(
v->GetName())); dv) {
4025 if (
v->getMin() < dv->getMin())
4026 dv->setMin(
v->getMin());
4027 if (
v->getMax() > dv->getMax())
4028 dv->setMax(
v->getMax());
4031 if (
auto dc =
dynamic_cast<RooCategory *
>(_data->get()->find(
c->GetName())); dc) {
4032 if (!dc->hasLabel(
c->getCurrentLabel())) {
4033 dc->defineType(
c->getCurrentLabel(),
c->getCurrentIndex());
4042 if (
auto _nentries = std::unique_ptr<RooAbsData>(_data->reduce(cutFormula))->numEntries();
4043 _nentries != _ax->GetNbins()) {
4046 if (_nentries > 0) {
4047 Info(
"SetBinContent",
"Binning %s in channel: %s",
GetName(), cut.
Data());
4048 auto _reduced = std::unique_ptr<RooAbsData>(_data->reduce(icutFormula));
4050 for (
int j = 0; j < _reduced->numEntries(); j++) {
4051 auto _obs = _reduced->get(j);
4052 _data->add(*_obs, _reduced->weight());
4055 for (
int i = 1; i <= _ax->GetNbins(); i++) {
4059 dynamic_cast<RooAbsLValue *
>(_ax->GetParent())->setBin(i - 1, _ax->GetName());
4060 _data->add(
obs, _contents.
at(i - 1));
4065 if (std::unique_ptr<RooAbsData>(_data->reduce(cutFormula2))->numEntries() > 0) {
4066 auto _reduced = std::unique_ptr<RooAbsData>(_data->reduce(icutFormula2));
4068 for (
int j = 0; j < _reduced->numEntries(); j++) {
4069 auto _obs = _reduced->get(j);
4070 _data->add(*_obs, _reduced->weight());
4074 dynamic_cast<RooAbsLValue *
>(_ax->GetParent())->setBin(bin - 1, _ax->GetName());
4077 return bb->SetBinContent(bin,
value, par, parVal);
4080 }
else if (get<RooDataHist>()) {
4081 throw std::runtime_error(
"RooDataHist not supported yet");
4085 if (
auto _varies =
variations(); !_varies.empty() || (par && strlen(par))) {
4086 if (!par || strlen(par) == 0) {
4087 return _varies[
"nominal"]->SetBinContent(bin,
value, par, parVal);
4088 }
else if (
auto it = _varies.find(
Form(
"%s=%g", par, parVal)); it) {
4089 return it->SetBinContent(bin,
value);
4101 if (!par || strlen(par) == 0) {
4114 if (strcmp(
c->GetName(),
Form(
"%g",
c->getVal())) == 0) {
4117#if ROOT_VERSION_CODE < ROOT_VERSION(6, 24, 00)
4130 auto bin_pars =
f->dataHist().get(bin - 1);
4131 if (
f->getAttribute(
"density")) {
4132 value /=
f->dataHist().binVolume(*bin_pars);
4134 f->dataHist().set(*bin_pars,
value);
4137 if (
auto otherfName =
f->getStringAttribute(
"symmetrized_by"); otherfName) {
4139 f->setStringAttribute(
"symmetrized_by",
nullptr);
4140 if (
auto x = getObject<RooAbsArg>(otherfName);
x) {
4141 x->setStringAttribute(
"symmetrizes",
nullptr);
4142 x->setStringAttribute(
"symmetrize_nominal",
nullptr);
4144 }
else if (
auto otherfName2 =
f->getStringAttribute(
"symmetrizes"); otherfName2) {
4145 auto nomf = getObject<RooHistFunc>(
f->getStringAttribute(
"symmetrize_nominal"));
4146 auto otherf = getObject<RooHistFunc>(otherfName2);
4147 if (nomf && otherf) {
4148 otherf->dataHist().set(*bin_pars, 2 * nomf->dataHist().weight(bin - 1) -
value);
4149 otherf->setValueDirty();
4156 f2->setNominal(
value);
4165 push_back(std::make_shared<xRooNode>(
data));
4172 return node->SetBinContent(bin,
value);
4179 push_back(std::make_shared<xRooNode>(
data));
4186 return node->SetContents(obj);
4193 if (get<RooProduct>()) {
4197 if (
auto _varies =
variations(); !_varies.empty()) {
4198 return _varies[
"nominal"]->SetBinError(bin,
value);
4213 while (_prodParent && !_prodParent->get<
RooProduct>() && !_prodParent->get<
RooAbsPdf>()) {
4215 _prodParent.reset();
4218 _prodParent = _prodParent->fParent;
4221 (_prodParent && !_prodParent->get<
RooAbsPdf>()) ? _prodParent->factors().find(
"statFactor") :
nullptr;
4222 auto f_stat = (_f_stat) ? _f_stat->get<
ParamHistFunc>() :
nullptr;
4223 if (_f_stat && _f_stat->get() && !f_stat) {
4224 throw std::runtime_error(
"stat factor must be a paramhistfunc");
4233 for (
auto &
p :
xRooNode(
"tmp", *
f, std::shared_ptr<xRooNode>(
nullptr)).
vars()) {
4238 auto h = std::unique_ptr<TH1>(
f->dataHist().createHistogram(parNames
4245 h->SetName(
"statFactor");
4247 h->SetOption(
"blankshape");
4250 auto toMultiply =
this;
4254 f_stat =
dynamic_cast<ParamHistFunc *
>(toMultiply->Multiply(*h).get());
4256 throw std::runtime_error(
"Failed creating stat shapeFactor");
4262 TString prefix =
f->getStringAttribute(
"statPrefix");
4263 if (
value && prefix ==
"") {
4267 while (_p && !(_p->get()->InheritsFrom(
"RooRealSumPdf") || _p->get()->InheritsFrom(
"RooAddPdf") ||
4268 _p->get()->InheritsFrom(
"RooWorkspace") || _p->get()->InheritsFrom(
"RooAddition"))) {
4273 auto newVar = (
value == 0) ? getObject<RooRealVar>(
"1")
4274 : acquire<RooRealVar>(
Form(
"%s_bin%d", prefix.
Data(), bin),
4275 Form(
"%s_bin%d", prefix.
Data(), bin), 1);
4276#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
4281 auto var =
dynamic_cast<RooRealVar *
>(&pSet[bin - 1]);
4283 if (newVar.get() != var) {
4287 for (std::size_t i = 0; i < pSet.
size(); i++) {
4288 if (
int(i) != bin - 1) {
4289 all.
add(*pSet.
at(i));
4300 if (strcmp(rrv->GetName(),
"1") != 0) {
4301 TString origName = (
f->getStringAttribute(
"origName")) ?
f->getStringAttribute(
"origName") :
GetName();
4303 auto bin_pars =
f->dataHist().get(bin - 1);
4304 auto _binContent =
f->dataHist().weight();
4305 if (
f->getAttribute(
"density")) {
4306 _binContent *=
f->dataHist().binVolume(*bin_pars);
4311 for (
auto &[s, sv] : rrv->stringAttributes()) {
4312 if (s.find(
"sumw_") == 0) {
4314 }
else if (s.find(
"sumw2_") == 0) {
4318 if (sumw2 && sumw2 != std::numeric_limits<double>::infinity()) {
4319 double tau = pow(sumw, 2) / sumw2;
4320 rrv->setError((tau < 1
e-15) ? 1e15 : ( 1. / sqrt(tau)));
4321 rrv->setConstant(
false);
4323 auto _constr =
v.constraints();
4325 if (_constr.empty()) {
4326 rrv->setStringAttribute(
"boundConstraint", _constr.Add(
"poisson").get()->GetName());
4328 auto _glob = _constr.at(0)->obs().at(0)->get<
RooRealVar>();
4331 double _min = tau * (1. - 5. * sqrt(1. / tau));
4332 double _max = tau * (1. + 5. * sqrt(1. / tau));
4333 _glob->setRange(_min, _max);
4335 _constr.at(0)->pp().at(0)->SetBinContent(0, tau);
4336 rrv->setStringAttribute(
"boundConstraint", _constr.at(0)->get()->GetName());
4338 rrv->setRange(std::max((1. - 5. * sqrt(1. / tau)), 1
e-15), 1. + 5. * sqrt(1. / tau));
4341 if (
auto _constr =
v.constraints(); !_constr.empty()) {
4342 v.constraints().Remove(*_constr.at(0));
4347 rrv->setConstant(sumw2 == 0);
4359 auto res =
find(
name, browseResult);
4361 throw std::out_of_range(
name +
" does not exist");
4370 if (
auto _w = get<RooWorkspace>(); _w)
4372 if (
auto a = get<RooAbsArg>();
a &&
GETWS(
a)) {
4383 xRooNode out(
".constraints",
nullptr, *
this);
4386 getConstraint = [&](
const xRooNode &
n,
RooAbsArg &par, std::set<RooAbsPdf *> ignore) {
4388 if (ignore.count(_pdf))
4390 ignore.insert(_pdf);
4396 for (
auto &
c :
n.bins()) {
4397 if (
auto oo = getConstraint(*
c, par, ignore); oo) {
4407 for (
auto p : _ws->allPdfs()) {
4408 if (ignore.count(
static_cast<RooAbsPdf *
>(
p)))
4410 if (
p->dependsOn(par)) {
4411 out.emplace_back(std::make_shared<xRooNode>(par.GetName(), *
p, *
this));
4417 return getConstraint(*
n.fParent, par, ignore);
4419 for (
auto p : o->pdfList()) {
4420 if (ignore.count(
static_cast<RooAbsPdf *
>(
p)))
4422 if (
p->dependsOn(par)) {
4423 out.emplace_back(std::make_shared<xRooNode>(par.GetName(), *
p, *
this));
4429 for (
auto &
p :
vars()) {
4433 if (
v->getAttribute(
"Constant") &&
v != get<RooAbsReal>())
4435 if (
v->getAttribute(
"obs"))
4437 getConstraint(*
this, *
v, {get<RooAbsPdf>()});
4445 auto it = out.std::vector<std::shared_ptr<xRooNode>>
::begin();
4446 while (it != out.std::vector<std::shared_ptr<xRooNode>>
::end()) {
4447 bool removeIt =
false;
4448 for (
auto &
c : out) {
4449 if (
c.get() == it->get())
4453 std::set<std::string> parNames;
4454 std::string _cName =
c->GetName();
4456 parNames.insert(_cName.substr(0, _cName.find(
';')));
4457 _cName = _cName.substr(_cName.find(
';') + 1);
4458 }
while (_cName.find(
';') != std::string::npos);
4459 parNames.insert(_cName);
4460 _cName = it->get()->GetName();
4462 parNames.insert(_cName.substr(0, _cName.find(
';')));
4463 _cName = _cName.substr(_cName.find(
';') + 1);
4464 }
while (_cName.find(
';') != std::string::npos);
4465 parNames.insert(_cName);
4467 for (
auto &
x : parNames) {
4468 if (!_cName.empty())
4472 c->TNamed::SetName(_cName.c_str());
4485 if (get<RooAbsArg>() && get<RooAbsArg>()->isFundamental()) {
4486 for (
auto &o : out) {
4487 o->TNamed::SetName(o->get()->GetName());
4501 sName =
TString(
"factory:") + sName;
4505 if (
auto h = get<TH1>();
h) {
4507 std::map<std::string, std::string> stringAttrs;
4509 auto pos = sOpt2.
Index(
"=");
4510 auto start = sOpt2.
Index(
";") + 1;
4516 stringAttrs[sOpt2(start, pos - start)] = sOpt2(pos + 1,
end - pos - 1);
4522 origName = origName(1, origName.
Length());
4525 newObjName(1, newObjName.
Length());
4532 TString varName =
h->GetXaxis()->GetName();
4533 std::string binningName = newObjName.
Data();
4534 if (
auto pos = varName.
Index(
';'); pos != -1) {
4535 binningName = varName(pos + 1, varName.
Length());
4536 varName = varName(0, pos);
4539 if (varName ==
"xaxis" &&
4541 if (
auto ax = acquirer.
GetXaxis(); ax) {
4542 varName = ax->GetParent()->GetName();
4544 binningName = ax->GetName();
4545 }
else if (acquirer.
obs().size() == 1)
4546 varName = acquirer.
obs().
at(0)->get()->GetName();
4548 auto x = acquirer.
acquire<
RooRealVar>(varName,
h->GetXaxis()->GetTitle(),
h->GetXaxis()->GetXmin(),
4549 h->GetXaxis()->GetXmax());
4550 if (
x->getMin() >
h->GetXaxis()->GetXmin())
4551 x->setMin(
h->GetXaxis()->GetXmin());
4552 if (
x->getMax() <
h->GetXaxis()->GetXmax())
4553 x->setMax(
h->GetXaxis()->GetXmax());
4554 if (!
x->hasBinning(binningName.c_str())) {
4555 if (
h->GetXaxis()->IsVariableBinSize()) {
4556 x->setBinning(
RooBinning(
h->GetNbinsX(),
h->GetXaxis()->GetXbins()->GetArray()), binningName.c_str());
4559 RooUniformBinning(
h->GetXaxis()->GetXmin(),
h->GetXaxis()->GetXmax(),
h->GetXaxis()->GetNbins()),
4560 binningName.c_str());
4562 x->getBinning(binningName.c_str()).
SetTitle(
h->GetXaxis()->GetTitle());
4563 if (
x->getBinningNames().size() == 2) {
4565 x->setBinning(
x->getBinning(binningName.c_str()));
4569 if (
x->getBinning(binningName.c_str()).numBins() !=
h->GetNbinsX()) {
4570 throw std::runtime_error(
4571 TString::Format(
"binning mismatch for binning %s of %s", binningName.c_str(),
x->GetName()));
4575 std::shared_ptr<RooAbsArg> _f;
4581 for (
auto &[k,
v] : stringAttrs) {
4584 x->setAttribute(
"obs",
true);
4585 }
else if (sOpt2.
Contains(
"shape")) {
4587 for (
int i = 0; i <
x->getBinning(binningName.c_str()).numBins(); i++) {
4588 std::shared_ptr<RooAbsArg> arg;
4589 if (sOpt2.
Contains(
"blankshape")) {
4595 if (
h->GetMinimumStored() != -1111 ||
h->GetMaximumStored() != -1111) {
4597 h->GetBinContent(i + 1),
h->GetMinimumStored(),
4598 h->GetMaximumStored());
4601 h->GetBinContent(i + 1));
4608 auto tmp =
dynamic_cast<RooAbsBinning *
>(
x->getBinningPtr(
nullptr)->Clone());
4609 x->setBinning(
x->getBinning(binningName.c_str()));
4611#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
4612 dynamic_cast<ParamHistFunc *
>(_f.get())->_paramSet.setName(
"paramSet");
4615 .setName(
"paramSet");
4617 x->setBinning(*tmp);
4619 for (
auto &[k,
v] : stringAttrs) {
4620 _f->setStringAttribute(k.c_str(),
v.c_str());
4624 binningName.c_str() );
4626 throw std::runtime_error(
"Couldn't make data hist");
4631 f->setAttribute(
"autodensity");
4634 for (
auto &[k,
v] : stringAttrs) {
4635 _f->setStringAttribute(k.c_str(),
v.c_str());
4639 _f->setStringAttribute(
"xvar",
x->GetName());
4640 _f->setStringAttribute(
"binning", binningName.c_str());
4641 if (strcmp(_f->GetName(), origName.
Data()) && !_f->getStringAttribute(
"alias"))
4642 _f->setStringAttribute(
"alias", origName);
4645 xRooNode tmp(
h->GetName(), _f, acquirer);
4647 _f = std::dynamic_pointer_cast<RooAbsArg>(tmp.fComp);
4650 _f->setStringAttribute(
"xvar",
x->GetName());
4651 _f->setStringAttribute(
"binning", binningName.c_str());
4654 if (strcmp(_f->GetName(), origName.
Data()) && !_f->getStringAttribute(
"alias"))
4655 _f->setStringAttribute(
"alias", origName);
4674 return std::dynamic_pointer_cast<TStyle>(
styles(initObject, autoCreate).
fComp);
4681 auto arg = get<RooAbsArg>();
4682 if (!initObject && !arg && !
gROOT->GetStyle(t)) {
4686 std::unique_ptr<TObject> argInitObject;
4691 if (arg->getStringAttribute(
"style")) {
4692 t = arg->getStringAttribute(
"style");
4693 }
else if (autoCreate) {
4695 argInitObject = std::make_unique<TH1D>(
GetName(),
GetTitle(), 1, 0, 1);
4696 initObject = argInitObject.get();
4702 std::shared_ptr<TStyle>
style;
4704 if (!
gROOT->GetStyle(t)) {
4705 if ((
style = getObject<TStyle>(t.
Data()))) {
4715 if (
auto x =
dynamic_cast<TAttLine *
>(initObject))
4717 if (
auto x =
dynamic_cast<TAttFill *
>(initObject))
4719 if (
auto x =
dynamic_cast<TAttMarker *
>(initObject))
4727 if (arg && !arg->getStringAttribute(
"style")) {
4728 arg->setStringAttribute(
"style",
style->GetName());
4734std::shared_ptr<TObject>
xRooNode::acquire(
const std::shared_ptr<TObject> &arg,
bool checkFactory,
bool mustBeNew)
4739 return fParent->acquire(arg, checkFactory, mustBeNew);
4743 if (_ws && (
get() == _ws || _ws->arg(
GetName()) || (arg && strcmp(arg->GetName(),
GetName()) == 0))) {
4746 if (
auto a =
dynamic_cast<RooAbsArg *
>(arg.get());
a) {
4747 auto out_arg = _ws->arg(
a->GetName());
4748 TString aName = arg->GetName();
4750 while (out_arg && mustBeNew) {
4752 out_arg = _ws->arg(
a->GetName());
4754 if (aName !=
a->GetName())
4755 Warning(
"acquire",
"Renaming to %s",
a->GetName());
4759 if (
auto res = _ws->factory(arg->GetName()); res) {
4766 Info(
"acquire",
"A copy of %s has been added to workspace %s",
a->GetName(), _ws->GetName());
4772 std::set<std::string> setNames;
4775 setNames.insert(aa.first);
4778 for (
auto &aa : setNames)
4780 out_arg = _ws->arg(
a->GetName());
4781 if (
GETWS(out_arg) != _ws) {
4782 out_arg->setWorkspace(*_ws);
4786 return std::shared_ptr<TObject>(out_arg, [](
TObject *) {});
4787 }
else if (
auto a2 =
dynamic_cast<RooAbsData *
>(arg.get()); a2) {
4793 return std::shared_ptr<TObject>(_ws->embeddedData(arg->GetName()), [](
TObject *) {});
4794 }
else if (arg->InheritsFrom(
"RooFitResult") || arg->InheritsFrom(
"TTree") || arg->IsA() ==
TStyle::Class() ||
4795 arg->
InheritsFrom(
"RooStats::HypoTestInverterResult") ||
4796 arg->InheritsFrom(
"RooStats::HypoTestResult")) {
4799 TString aName = arg->GetName();
4800 TObject *out_arg = _ws->genobj(arg->GetName());
4802 while (aNamed && out_arg && mustBeNew) {
4804 out_arg = _ws->genobj(aNamed->
GetName());
4807 if (aName != arg->GetName()) {
4808 Warning(
"acquire",
"Renaming to %s", arg->GetName());
4810 if (_ws->import(*arg,
false )) {
4814 out_arg = _ws->genobj(arg->GetName());
4832 return std::shared_ptr<TObject>(out_arg, [](
TObject *) {});
4839 auto out =
fProvider->getObject(arg->GetName(), arg->ClassName());
4843 auto _owned =
find(
".memory");
4845 _owned = emplace_back(std::make_shared<xRooNode>(
".memory",
nullptr, *
this));
4850 for (
auto &
r : *_owned) {
4851 if (strcmp(
r->GetName(), arg->GetName()) == 0 && strcmp(
r->get()->ClassName(), arg->ClassName()) == 0) {
4857 std::cout <<
GetName() <<
" taking over " << arg->ClassName() <<
"::" << arg->GetName() << std::endl;
4859 return _owned->emplace_back(std::make_shared<xRooNode>(arg->GetName(), arg, *
this))->fComp;
4887 auto _deps =
vars();
4899 auto a = get<RooAbsArg>();
4901 throw std::runtime_error(
"Cannot SetXaxis of non-arg");
4903 auto _x = acquire<RooRealVar>(
name, title, low, high);
4904 _x->setBinning(binning,
a->
GetName());
4905 _x->getBinning(
a->GetName()).SetTitle(title);
4906 if (_x->getBinningNames().size() == 2) {
4908 _x->setBinning(_x->getBinning(
a->GetName()));
4913 if (_x->getMax() < high)
4915 if (_x->getMin() > low)
4919 if (!_deps.find(
name) && get<RooAbsPdf>()) {
4921 _x->setAttribute(
"obs");
4924 a->setStringAttribute(
"xvar", _x->GetName());
4925 a->setStringAttribute(
"binning",
a->GetName());
4944 return find(
name,
false) !=
nullptr;
4949 std::string partname = (
name.find(
'/') != std::string::npos) ?
name.substr(0,
name.find(
'/')) :
name;
4951 : get<RooSimultaneous>();
4952 std::string extra = (_s) ? _s->indexCat().GetName() :
"";
4953 for (
auto &
child : *
this) {
4955 (_obj &&
name == _obj->GetName()) || (_obj && partname == _obj->GetName()) ||
4956 (!extra.empty() && ((extra +
"=" +
name) ==
child->GetName() ||
4957 (extra +
"=" + partname) ==
child->GetName()))) {
4961 return child->at(
name.substr(partname.length() + 1));
4965 if (partname.find(
'.') != 0) {
4969 for (
auto &child2 :
x.browse()) {
4970 if (
auto _obj = child2->get();
name == child2->GetName() || partname == child2->GetName() ||
4971 (_obj &&
name == _obj->GetName()) ||
4972 (_obj && partname == _obj->GetName())) {
4975 if (partname !=
name &&
name != child2->GetName()) {
4976 return child2->at(
name.substr(partname.length() + 1));
4986 auto child2 =
at(s.Atoi());
4987 if (partname !=
name) {
4988 return child2->at(
name.substr(partname.length() + 1));
4993 if (get<RooWorkspace>() &&
name !=
".memory") {
4995 auto out = std::make_shared<xRooNode>(obj, *
this);
5006 std::string partname = (
name.find(
'/') != std::string::npos) ?
name.substr(0,
name.find(
'/')) :
name;
5009 : get<RooSimultaneous>();
5010 std::string extra = (_s) ? _s->indexCat().GetName() :
"";
5011 std::shared_ptr<xRooNode> folderNode;
5012 for (
auto &
child : *
this) {
5015 ((extra +
"=" +
name) ==
child->GetName() || (extra +
"=" + partname) ==
child->GetName()))) {
5018 return child->operator[](
name.substr(partname.length() + 1));
5024 for (
auto &child2 :
x.browse()) {
5025 if (
name == child2->GetName() || partname == child2->GetName()) {
5027 if (partname !=
name &&
name != child2->GetName()) {
5028 return child2->operator[](
name.substr(partname.length() + 1));
5034 if (
child->fFolder == (std::string(
"!") + partname)) {
5036 folderNode = std::make_shared<xRooNode>(
child->fFolder.c_str(),
nullptr, *
this);
5037 folderNode->push_back(
child);
5041 if (partname !=
name) {
5042 return folderNode->operator[](
name.substr(partname.length() + 1));
5048 auto child2 =
at(s.Atoi());
5049 if (partname !=
name) {
5050 return child2->operator[](
name.substr(partname.length() + 1));
5054 auto out = std::make_shared<xRooNode>(partname.c_str(),
nullptr, *
this);
5056 if (get<RooWorkspace>() && partname ==
"pdfs") {
5057 out->SetName(
"!pdfs");
5059 if (partname !=
name) {
5060 return out->operator[](
name.substr(partname.length() + 1));
5068 for (
auto o : *
gROOT->GetListOfBrowsers()) {
5070 if (!
b || !
b->GetBrowserImp())
5077 if (!
b->GetBrowserImp())
5093 for (
auto o : *
gROOT->GetListOfBrowsers()) {
5095 if (!
b || !
b->GetBrowserImp())
5102 if (
b->GetBrowserImp()) {
5108 if (
auto item =
GETLISTTREE(_b)->FindItemByObj(_root,
const_cast<xRooNode *
>(
this)); item) {
5119 if (
auto a = get<RooAbsArg>();
a)
5120 a->setStringAttribute(
"alias",
name);
5121 for (
auto o : *
gROOT->GetListOfBrowsers()) {
5122 if (
auto b =
dynamic_cast<TBrowser *
>(o);
b) {
5124 item->SetText(
name);
5132 if (
auto o = (get<TNamed>()); o) {
5147 auto findByObj = [&](
const std::shared_ptr<xRooNode> &
n) {
5148 std::vector<std::shared_ptr<xRooNode>> &nn = *
this;
5149 for (
auto &
c : nn) {
5150 if (
c->get() ==
n->get() && strcmp(
n->GetName(),
c->GetName()) == 0)
5153 return std::shared_ptr<xRooNode>(
nullptr);
5156 auto appendChildren = [&](
const xRooNode &
n) {
5158 const std::vector<std::shared_ptr<xRooNode>> &nn(
n);
5159 for (
auto &
c : nn) {
5160 if (
auto existing = findByObj(
c); existing) {
5162 existing->fFolder =
c->fFolder;
5172 const std::vector<std::shared_ptr<xRooNode>> &nn2(*
this);
5173 for (
auto &
c : nn2) {
5174 if (strlen(
c->GetName()) > 0 && (
c->GetName()[0] ==
'.')) {
5178 if (strcmp(
c->GetName(),
"!.pars") == 0) {
5189 size_t addedChildren = 0;
5193 if (get<RooWorkspace>()) {
5194 addedChildren += appendChildren(
datasets());
5208 addedChildren += appendChildren(
components());
5209 if (!get<RooWorkspace>())
5210 addedChildren += appendChildren(
factors());
5212 auto _coefs =
coefs();
5213 if (_coefs.get() && strcmp(_coefs->GetName(),
"1") != 0 && strcmp(_coefs->GetName(),
"ONE") != 0) {
5214 if (_coefs.size() == 1 && _coefs.get<
RooAddition>()) {
5215 if (strcmp(_coefs.at(0)->GetName(),
"1") != 0 &&
5216 strcmp(_coefs.at(0)->GetName(),
"ONE") != 0) {
5217 auto coef = std::make_shared<xRooNode>(
".coef", *_coefs.at(0)->get(), *
this);
5218 if (
auto existing = findByObj(coef); existing) {
5220 existing->fFolder = _coefs.at(0)->fFolder;
5226 if (
auto existing =
find(_coefs.GetName()); existing) {
5228 existing->fFolder = _coefs.fFolder;
5230 emplace_back(std::make_shared<xRooNode>(_coefs));
5234 addedChildren += appendChildren(
variations());
5235 if (get<ParamHistFunc>() || get<RooSimultaneous>())
5236 addedChildren += appendChildren(
bins());
5237 if (get<RooAbsData>())
5238 addedChildren += appendChildren(
obs());
5241 if (
auto arg = get<RooAbsArg>(); arg && addedChildren == 0) {
5242 for (
int i = 0; i < arg->numProxies(); i++) {
5243 auto _proxy = arg->getProxy(i);
5245 auto c = std::make_shared<xRooNode>(
TString::Format(
".%s", _proxy->name()), *(
a->absArg()), *
this);
5246 if (
auto existing = findByObj(
c); existing) {
5248 existing->fFolder =
c->fFolder;
5253 for (
auto &
child : *
this) {
5254 if (strcmp(
child->GetName(),
c->GetName()) == 0) {
5261 for (
auto a2 : *s) {
5262 auto c = std::make_shared<xRooNode>(*a2, *
this);
5263 if (arg->numProxies() != 1) {
5264 c->fFolder = std::string(
"!.") +
5267 if (
auto existing = findByObj(
c); existing) {
5269 existing->fFolder =
c->fFolder;
5285 }
else if (
auto ir = get<RooStats::HypoTestInverterResult>()) {
5289 if (strcmp(
c->GetName(),
".memory") == 0 &&
c->get<
xRooHypoSpace>()) {
5297 fBrowsables.emplace_back(std::make_shared<xRooNode>(
".memory", std::make_shared<xRooHypoSpace>(ir), *
this));
5304 for (
auto a : _axes) {
5305 if (
a != _axes.first())
5308 TString::Format(
"%s=%g",
a->GetName(), hp.coords->getRealValue(
a->GetName(), ir->GetXValue(i)));
5310 auto hpn = emplace_back(std::make_shared<xRooNode>(coordString, hp.hypoTestResult, hs));
5312 hpn->fBrowsables.emplace_back(std::make_shared<xRooNode>(
5318 std::vector<std::shared_ptr<xRooNode>> &nn = *
this;
5319 for (
auto &
c : nn) {
5329 }
else if (get<RooStats::HypoTestResult>()) {
5342 std::make_shared<xRooNLLVar::xRooHypoPoint>(std::dynamic_pointer_cast<RooStats::HypoTestResult>(
fComp));
5343 fBrowsables.emplace_back(std::make_shared<xRooNode>(
".memory", shp, *
this));
5349 if (
auto fit = hp->
ufit()) {
5350 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"ufit");
5353 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"cfit_null");
5356 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"cfit_alt");
5358 if (
auto fit = hp->
gfit()) {
5359 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"gfit");
5361 if (
auto asi = hp->
asimov()) {
5362 auto asiP = fits.emplace_back(std::make_shared<xRooNode>(
5363 asi->hypoTestResult ? asi->hypoTestResult : std::make_shared<RooStats::HypoTestResult>(asi->result()),
5365 asiP->TNamed::SetName(
"asimov");
5366 asiP->fBrowsables.emplace_back(std::make_shared<xRooNode>(
".memory", asi, asiP));
5368 appendChildren(fits);
5372 auto it = std::vector<std::shared_ptr<xRooNode>>
::begin();
5373 while (it != std::vector<std::shared_ptr<xRooNode>>
::end()) {
5374 if (it->get()->fTimes == 0) {
5375 for (
auto o : *
gROOT->GetListOfBrowsers()) {
5377 if (
b &&
b->GetBrowserImp()) {
5386 if (
auto item =
GETLISTTREE(_b)->FindItemByObj(_root,
this); item) {
5424 xRooNode out(
".obs", std::make_shared<RooArgList>(), *
this);
5426 for (
auto o :
vars()) {
5429 out.emplace_back(o);
5440 xRooNode out(
".globs", std::make_shared<RooArgList>(), *
this);
5442 for (
auto o :
obs()) {
5445 out.emplace_back(o);
5456 xRooNode out(
".robs", std::make_shared<RooArgList>(), *
this);
5458 for (
auto o :
obs()) {
5461 out.emplace_back(o);
5476 xRooNode out(
".pars", std::make_shared<RooArgList>(), *
this);
5478 for (
auto o :
vars()) {
5481 out.emplace_back(o);
5492 xRooNode out(
".consts", std::make_shared<RooArgList>(), *
this);
5494 for (
auto o :
pars()) {
5497 out.emplace_back(o);
5509 xRooNode out(
".floats", std::make_shared<RooArgList>(), *
this);
5511 for (
auto o :
pars()) {
5514 out.emplace_back(o);
5526 xRooNode out(
".poi", std::make_shared<RooArgList>(), *
this);
5528 for (
auto o :
pars()) {
5531 out.emplace_back(o);
5543 xRooNode out(
".np", std::make_shared<RooArgList>(), *
this);
5545 for (
auto o :
pars()) {
5547 (!o->get<
RooAbsArg>()->getAttribute(
"Constant") && !o->get<
RooAbsArg>()->getAttribute(
"poi") &&
5550 out.emplace_back(o);
5561 xRooNode out(
".pp", std::make_shared<RooArgList>(), *
this);
5563 for (
auto o :
pars()) {
5567 out.emplace_back(o);
5578 xRooNode out(
".vars", std::make_shared<RooArgList>(), *
this);
5580 if (
auto coll = get<RooAbsCollection>(); coll) {
5581 for (
auto &
x : *
this) {
5582 for (
auto &
y :
x->vars()) {
5588 if (
auto p = get<RooAbsArg>();
p) {
5594 p->leafNodeServerList(&allLeaves);
5595 for (
auto &
c : allLeaves) {
5597 if (!
c->getAttribute(
"global")) {
5599 out.emplace_back(std::make_shared<xRooNode>(*
c, *
this));
5601 if (
c->getAttribute(
"global")) {
5602 _globs.emplace_back(std::make_shared<xRooNode>(*
c, *
this));
5603 _globs.back()->fFolder =
"!globs";
5604 }
else if (
c->getAttribute(
"obs")) {
5605 out.back()->fFolder =
"!robs";
5606 }
else if (
c->getAttribute(
"poi")) {
5607 out.back()->fFolder =
"!poi";
5608 }
else if (
c->getAttribute(
"np") ||
5610 out.back()->fFolder =
"!np";
5612 out.back()->fFolder =
"!floats";
5614 out.back()->fFolder =
"!pp";
5618 for (
auto g : _globs) {
5620 out.emplace_back(
g);
5622 }
else if (
auto p2 = get<RooAbsData>(); p2) {
5623 for (
auto a : *p2->get()) {
5624 a->setAttribute(
"obs");
5625 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5628 if (
auto _dglobs = p2->getGlobalObservables()) {
5629 for (
auto &
a : *_dglobs) {
5630 a->setAttribute(
"obs");
5631 a->setAttribute(
"global");
5632 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5637 a->setAttribute(
"obs");
5638 a->setAttribute(
"global");
5639 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5642 }
else if (
auto _ws =
ws(); _ws) {
5644 for (
auto a : *_globs2) {
5645 a->setAttribute(
"obs");
5646 a->setAttribute(
"global");
5647 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5651 for (
auto &_g : _gl->second) {
5652 auto _clone = std::shared_ptr<RooAbsArg>(
dynamic_cast<RooAbsArg *
>(_g->Clone(_g->GetName())));
5653 if (
auto v = std::dynamic_pointer_cast<RooAbsRealLValue>(_clone);
v && _g->getStringAttribute(
"nominal"))
5654 v->setVal(
TString(_g->getStringAttribute(
"nominal")).
Atof());
5655 out.emplace_back(std::make_shared<xRooNode>(_clone, *
this));
5663 for (
auto &_g : *_globs3) {
5664 auto _clone = std::shared_ptr<RooAbsArg>(
dynamic_cast<RooAbsArg *
>(_g->Clone(_g->GetName())));
5665 if (
auto v = std::dynamic_pointer_cast<RooAbsRealLValue>(_clone);
v && _g->getStringAttribute(
"nominal"))
5666 v->setVal(
TString(_g->getStringAttribute(
"nominal")).
Atof());
5667 out.emplace_back(std::make_shared<xRooNode>(_clone, *
this));
5672 }
else if (
auto w = get<RooWorkspace>();
w) {
5673 for (
auto a :
w->allVars()) {
5674 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5678 for (
auto a :
w->allCats()) {
5679 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5688 xRooNode out(
".components",
nullptr, *
this);
5690 if (
auto p = get<RooAddPdf>();
p) {
5692 std::set<RooAbsArg *> donePdfs;
5693 for (
auto &o :
p->pdfList()) {
5694 if (donePdfs.count(o))
5696 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5699 }
else if (
auto p2 = get<RooRealSumPdf>(); p2) {
5713 std::set<RooAbsArg *> doneFuncs;
5714 for (
auto &o : p2->funcList()) {
5715 if (doneFuncs.count(o))
5717 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5718 doneFuncs.insert(o);
5720 }
else if (
auto p3 = get<RooAddition>(); p3) {
5721 for (
auto &o : p3->list()) {
5722 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5724 }
else if (
auto p4 = get<RooAbsCollection>(); p4) {
5725 for (
auto &
a : *p4) {
5726 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5728 }
else if (
auto p5 = get<RooWorkspace>(); p5) {
5729 for (
auto &o : p5->components()) {
5732 bool hasClients =
false;
5733 for (
auto &
c : o->clients()) {
5734 if (!
c->InheritsFrom(
"RooRealIntegral") && p5 ==
GETWS(
c)) {
5741 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5742 if (o->InheritsFrom(
"RooAbsPdf")) {
5743 out.back()->fFolder =
"!pdfs";
5745 out.back()->fFolder =
"!scratch";
5748 for (
auto &o : p5->allGenericObjects()) {
5752 s = s(0, s.
Index(
';'));
5753 if (
auto _pdf = out.find(s.
Data()); _pdf) {
5755 out.emplace_back(std::make_shared<xRooNode>(fr->GetName(), *fr, _pdf));
5762 out.emplace_back(std::make_shared<xRooNode>(fr->GetName(), *fr, *
this));
5764 out.back()->fFolder =
"!fits";
5766 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5767 if (strcmp(out.back()->get()->ClassName(),
"TStyle") == 0) {
5768 out.back()->fFolder =
"!styles";
5769 }
else if (strcmp(out.back()->get()->ClassName(),
"RooStats::HypoTestInverterResult") == 0) {
5770 out.back()->fFolder =
"!scans";
5771 }
else if (strcmp(out.back()->get()->ClassName(),
"RooStats::ModelConfig") == 0) {
5772 out.back()->fFolder =
"!models";
5774 out.back()->fFolder =
"!objects";
5781 if (k.find(
"CACHE_") == 0)
5783 out.emplace_back(std::make_shared<xRooNode>(k.c_str(),
v, *
this));
5784 out.back()->fFolder =
"!sets";
5790 while ((snap = iter->Next())) {
5791 out.emplace_back(std::make_shared<xRooNode>(*snap, *
this));
5792 out.back()->fFolder =
"!snapshots";
5794 }
else if (
auto mc = get<RooStats::ModelConfig>()) {
5797 out.emplace_back(std::make_shared<xRooNode>(
".pdf", *mc->GetPdf(), *
this));
5799 if (mc->GetExternalConstraints()) {
5800 out.emplace_back(std::make_shared<xRooNode>(
".extCons", *mc->GetExternalConstraints(), *
this));
5806 out.emplace_back(
c);
5813 out.emplace_back(
c);
5827 xRooNode out(
".bins",
nullptr, *
this);
5829 if (
auto p = get<RooSimultaneous>();
p) {
5830 std::map<int, std::shared_ptr<xRooNode>> cats;
5831 for (
auto &
c :
p->indexCat()) {
5832 auto pp =
p->getPdf(
c.first.c_str());
5838 for (
auto &[
_,
n] : cats)
5839 out.emplace_back(
n);
5840 }
else if (
auto phf = get<ParamHistFunc>(); phf) {
5842#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
5843 auto &pSet = phf->_paramSet;
5845 auto &pSet = phf->paramList();
5847 for (
auto par : pSet) {
5848 out.emplace_back(std::make_shared<xRooNode>(*par, *
this));
5849 out.back()->fBinNumber = i;
5852 }
else if (
auto ax =
GetXaxis(); ax) {
5853 for (
int i = 1; i <= ax->GetNbins(); i++) {
5855 std::vector<RooAbsArg *> _factors;
5859 for (
auto &ss :
f->bins()[i - 1]->factors())
5860 _factors.push_back(ss->get<
RooAbsArg>());
5862 _factors.push_back(
f->bins()[i - 1]->get<
RooAbsArg>());
5866 out.emplace_back(std::make_shared<xRooNode>(
5867 TString::Format(
"%g<=%s<%g", ax->GetBinLowEdge(i), ax->GetParent()->GetName(), ax->GetBinLowEdge(i + 1)),
5868 _factors.empty() ? nullptr
5872 for (
auto f : _factors) {
5873#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
5879 out.back()->fBinNumber = i;
5893 auto parentCoefs =
fParent->coefs(
true);
5904 std::make_shared<RooProduct>(
".recursiveCoefs",
5909 auto mem = out.emplace_back(std::make_shared<xRooNode>(
".memory",
nullptr, *
this));
5910 mem->emplace_back(std::make_shared<xRooNode>(ourCoefs));
5911 mem->emplace_back(std::make_shared<xRooNode>(parentCoefs));
5915 bool isResidual =
false;
5923 if (!parent->fComp) {
5924 while (!parent->fComp && parent->fParent) {
5925 parent = parent->fParent;
5928 parent = parent->fParent;
5934 for (
auto &o :
p->funcList()) {
5936 if (i >=
p->coefList().size()) {
5938 coefs.add(
p->coefList());
5940 coefs.add(*
p->coefList().at(i));
5945 }
else if (
auto p2 = parent->get<
RooAddPdf>(); p2) {
5947 if (p2->coefList().empty()) {
5952 for (
auto &o : p2->pdfList()) {
5954 if (i >= p2->coefList().size()) {
5956 coefs.add(p2->coefList());
5958 coefs.add(*p2->coefList().at(i));
5969 auto coefSum =
coefs.empty()
5972 : std::make_shared<RooAddition>((isResidual) ?
".sumOfCoefs" :
".coefs",
5973 "Coefficients of",
coefs));
5974 xRooNode out(
".coef", coefSum ? std::dynamic_pointer_cast<RooAbsArg>(std::make_shared<RooFormulaVar>(
5975 ".coef",
"1-sum(otherCoefs)",
"1. - @0", *coefSum))
5977 if (coefSum &&
coefs.size() != 1) {
5978 out.emplace_back(std::make_shared<xRooNode>(
".memory",
nullptr, *
this))
5980 std::make_shared<xRooNode>(
".sumOfCoefs", coefSum, out));
5982 if (!
coefs.empty()) {
5986 }
else if (
coefs.size() == 1) {
5988 if (!
coefs.empty()) {
5997 xRooNode out(
".coefs", coefSum, *
this);
6007 xRooNode out(
".factors",
nullptr, *
this);
6009 if (
auto p = get<RooProdPdf>();
p) {
6011 if (
auto a = _main.get<
RooRealSumPdf>();
a && !
a->getStringAttribute(
"alias")) {
6012 a->setStringAttribute(
"alias",
"samples");
6014 a2->setStringAttribute(
"alias",
"components");
6016 int _npdfs =
p->pdfList().size();
6017 for (
auto &o :
p->pdfList()) {
6018 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
6019 if (_npdfs > 5 && o != _main.get())
6020 out.back()->fFolder =
"!constraints";
6022 }
else if (
auto p2 = get<RooProduct>(); p2) {
6023 for (
auto &o : p2->components()) {
6024 if (o->InheritsFrom(
"RooProduct")) {
6028 out.emplace_back(std::make_shared<xRooNode>(
n->GetName(),
n->fComp, *
this));
6031 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
6034 }
else if (
auto w = get<RooWorkspace>();
w) {
6040 for (
auto a :
w->allFunctions()) {
6041 if (_obs.contains(*
a))
6044 for (
auto c :
a->clients()) {
6046 if (
c->InheritsFrom(
"RooProduct")) {
6052 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
6096 xRooNode out(
".variations",
nullptr, *
this);
6108 if (
auto p2 = get<PiecewiseInterpolation>(); p2) {
6109#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
6110 out.emplace_back(std::make_shared<xRooNode>(
"nominal", p2->_nominal.arg(), *
this));
6112 out.emplace_back(std::make_shared<xRooNode>(
"nominal", *(p2->nominalHist()), *
this));
6114 for (
size_t i = 0; i < p2->paramList().
size(); i++) {
6116 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p2->paramList().at(i)->GetName()),
6117 *p2->highList().at(i), *
this));
6118 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p2->paramList().at(i)->GetName()),
6119 *p2->lowList().at(i), *
this));
6121 }
else if (
auto p3 = get<RooStats::HistFactory::FlexibleInterpVar>(); p3) {
6122#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
6123 out.emplace_back(std::make_shared<xRooNode>(
"nominal",
RooFit::RooConst(p3->_nominal), *
this));
6124 for (
size_t i = 0; i < p3->_paramList.size(); i++) {
6125 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p3->_paramList.at(i)->GetName()),
6127 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p3->_paramList.at(i)->GetName()),
6131 out.emplace_back(std::make_shared<xRooNode>(
"nominal",
RooFit::RooConst(p3->nominal()), *
this));
6132 for (
size_t i = 0; i < p3->variables().
size(); i++) {
6133 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p3->variables().at(i)->GetName()),
6135 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p3->variables().at(i)->GetName()),
6140 }
else if (
auto p4 = get<ParamHistFunc>(); p4) {
6159 for (
auto &k : *
this) {
6168 xRooNode out(
".datasets()",
nullptr, *
this);
6173 if (
auto _ws = get<RooWorkspace>(); _ws) {
6174 for (
auto &
d : _ws->allData()) {
6175 out.emplace_back(std::make_shared<xRooNode>(*
d, *
this));
6176 out.back()->fFolder =
"!datasets";
6178 }
else if (get<RooAbsPdf>() ||
6189 for (
auto _c :
coords()) {
6193 cut +=
TString::Format(
"%s==%d", _cat->GetName(), _cat->getCurrentIndex());
6201 cut +=
TString::Format(
"%s>=%f&&%s<%f", _rv->GetName(), _rv->getMin(_rv->getStringAttribute(
"coordRange")),
6202 _rv->GetName(), _rv->getMax(_rv->getStringAttribute(
"coordRange")));
6207 throw std::runtime_error(
"datasets(): Unsupported coordinate type");
6210 if (
auto s = get<RooSimultaneous>()) {
6212 bool hasMissing =
false;
6214 for (
auto cat : s->indexCat()) {
6215 if (!s->getPdf(cat.first.c_str())) {
6220 extraCut +=
TString::Format(
"%s==%d", s->indexCat().GetName(), cat.second);
6226 cut +=
"(" + extraCut +
")";
6227 cutobs.
add(s->indexCat());
6232 auto a =
dynamic_cast<RooAbsArg *
>(ax->GetParent());
6236 for (
auto &
child : *
this) {
6238 _datasets.push_back(
child);
6240 if (
auto __ws =
ws(); __ws) {
6243 _datasets.push_back(
d);
6247 for (
auto &
d : _datasets) {
6248 if (std::unique_ptr<RooAbsCollection>(
d->obs().argList().selectCommon(_obs))->size() == _obs.
size()) {
6255 out.emplace_back(std::make_shared<xRooNode>(
6260 out.back()->get<
RooAbsData>()->setGlobalObservables(*std::unique_ptr<RooAbsCollection>(
6262 if (
d->get()->TestBit(1 << 20))
6263 out.back()->get()->SetBit(1 << 20);
6265 out.back()->fBrowsables.emplace_back(std::make_shared<xRooNode>(
".sourceds",
d->fComp, *
this));
6267 out.emplace_back(std::make_shared<xRooNode>(
d->fComp, *
this));
6280 }
else if (
auto mc = get<RooStats::ModelConfig>()) {
6290 if (
b && strcmp(
b->GetName(),
name) == 0)
6299 if (
auto fr = get<RooFitResult>(); fr) {
6303 if (
auto theData = get<RooDataSet>(); theData) {
6305 TH1 *theHist =
nullptr;
6310 theHist =
dynamic_cast<TH1 *
>(o);
6312 theHist =
static_cast<TH1 *
>(theHist->
Clone());
6323 auto vo =
dynamic_cast<TObject *
>(
v);
6324 if (
v &&
obs().
find(vo->GetName())) {
6328 TString::Format(
"my temp hist;%s", strlen(vo->GetTitle()) ? vo->GetTitle() : vo->GetName()),
6329 cat->numTypes(), 0, cat->numTypes());
6331 std::map<int, std::string> cats;
6332 for (
auto &
c : *cat) {
6333 cats[
c.second] =
c.first;
6335 for (
auto &[
_, label] : cats) {
6339 auto _binning =
v->getBinningPtr(
nullptr);
6340 if (_binning->isUniform()) {
6343 TString::Format(
"my temp hist;%s", strlen(vo->GetTitle()) ? vo->GetTitle() : vo->GetName()),
6344 v->numBins(), _binning->lowBound(), _binning->highBound());
6348 TString::Format(
"my temp hist;%s", strlen(vo->GetTitle()) ? vo->GetTitle() : vo->GetName()),
6349 v->numBins(), _binning->array());
6353 throw std::runtime_error(
"Cannot draw dataset without parent PDF");
6356 theHist = _parentPdf->BuildHistogram(
v,
true);
6362 TH1 *xPos =
static_cast<TH1 *
>(theHist->
Clone(
"xPos"));
6364 TH1 *xPos2 =
static_cast<TH1 *
>(theHist->
Clone(
"xPos2"));
6366 auto nHist = std::unique_ptr<TH1>(
static_cast<TH1 *
>(theHist->
Clone(
"nEntries")));
6371 dataGraph->SetName(
GetName());
6372 dataGraph->SetTitle(strlen(theData->GetTitle()) ? theData->GetTitle() : theData->GetName());
6378 dataGraph->SetMarkerStyle(20);
6392 dataGraph->SetTitle(
TString::Format(
"%s = %f", dataGraph->GetTitle(), dataGraph->GetPointX(0)));
6405 auto _pos = pName.
Index(
'=');
6407 int nevent = theData->numEntries();
6408 for (
int i = 0; i < nevent; i++) {
6411 for (
auto _c : _coords) {
6413 if (cat->getIndex() != theData->get()->getCatIndex(cat->GetName())) {
6419 if (!rv->inRange(theData->get()->getRealValue(rv->GetName()), rv->getStringAttribute(
"coordRange"))) {
6427 cat && cat->
getLabel() != pName(_pos + 1, pName.Length())) {
6443 theHist->
Fill((
x) ? xvar->
getVal() : 0.5, theData->weight());
6444 nHist->Fill((
x) ? xvar->
getVal() : 0.5, 1);
6452 for (
int i = 0; i < theHist->
GetNbinsX(); i++) {
6453 if (includeZeros || nHist->GetBinContent(i + 1)) {
6456 dataGraph->SetPoint(dataGraph->GetN(),
6461 xErr = (xErr <= 0) ? 0. : sqrt(xErr);
6464 dataGraph->SetPointError(dataGraph->GetN() - 1, xErr, xErr,
6476 dataGraph->GetHistogram()->GetXaxis()->Set(theHist->
GetNbinsX(), 0, theHist->
GetNbinsX());
6477 for (
int i = 1; i <= theHist->
GetNbinsX(); i++)
6478 dataGraph->GetHistogram()->GetXaxis()->SetBinLabel(i, theHist->
GetXaxis()->
GetBinLabel(i));
6503 auto _styleNode =
styles(dataGraph);
6504 if (
auto _style = _styleNode.get<
TStyle>()) {
6505 *
dynamic_cast<TAttLine *
>(dataGraph) = *_style;
6506 *
dynamic_cast<TAttFill *
>(dataGraph) = *_style;
6507 *
dynamic_cast<TAttMarker *
>(dataGraph) = *_style;
6512 throw std::runtime_error(
"Cannot build graph");
6518 if (
auto _w =
ws(); _w) {
6520 for (
auto o : _w->allGenericObjects()) {
6522 _fr->ResetBit(1 << 20);
6525 res->SetBit(1 << 20);
6527 auto allVars = _w->allVars();
6532 throw std::runtime_error(
"Not supported yet");
6546 throw std::runtime_error(
"Not a RooFitResult");
6552 if (get<RooFitResult>())
6554 if (get<RooAbsData>()) {
6555 if (
auto _fr =
find(
".fitResult"); _fr)
6557#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
6559 if (get<RooDataSet>() && get<RooDataSet>()->weightVar() &&
6560 get<RooDataSet>()->weightVar()->getStringAttribute(
"fitResult")) {
6561 return xRooNode(getObject<const RooFitResult>(get<RooDataSet>()->weightVar()->getStringAttribute(
"fitResult")),
6569 if (sOpt ==
"prefit") {
6576 auto _coefs =
coefs();
6582 std::unique_ptr<RooArgList> _pars(
dynamic_cast<RooArgList *
>(
pars().
argList().selectByAttrib(
"Constant",
false)));
6583 auto fr = std::make_shared<RooFitResult>(
"prefitResult",
"Prefit");
6584 fr->setFinalParList(*_pars);
6585 for (
auto &
p : fr->floatParsFinal()) {
6589 if (
auto s = _v->getStringAttribute(
"nominal"); s)
6592 std::shared_ptr<xRooNode> pConstr;
6593 for (
auto &
c : _constr) {
6596 bool isServer =
true;
6599 for (
auto s :
c->get<
RooAbsArg>()->servers()) {
6600 if (strcmp(s->GetName(),
p->
GetName()) == 0) {
6615 double prefitVal = 0;
6616 double prefitError = 0;
6617 for (
auto &_d : pConstr->vars()) {
6618 if (strcmp(
p->
GetName(), _d->get()->GetName()) == 0)
6622 prefitVal = prefitError;
6623 prefitError = _c->getVal();
6624 }
else if (prefitError == 0) {
6625 prefitError = _d->get<
RooAbsReal>()->getVal();
6631 if (pConstr->get<
RooGaussian>() && pConstr->browse().find(
".sigma")) {
6632 prefitError = pConstr->find(
".sigma")->get<
RooAbsReal>()->getVal();
6638 prefitVal /= prefitError;
6640 prefitError = 1. / sqrt(prefitError);
6642 if (!_v->getStringAttribute(
"nominal"))
6643 _v->setVal(prefitVal);
6644 _v->setError(prefitError);
6653 auto _globs =
globs();
6654 _args.add(_globs.argList());
6655 fr->setConstParList(_args);
6656 std::unique_ptr<RooArgList> _snap(
dynamic_cast<RooArgList *
>(_pars->snapshot()));
6657 for (
auto &
p : *_snap) {
6658 if (
auto atr =
p->getStringAttribute(
"initVal"); atr &&
dynamic_cast<RooRealVar *
>(
p))
6661 fr->setInitParList(*_snap);
6666 if (
auto _w =
ws(); _w) {
6667 auto checkFr = [&](
TObject *o) {
6671 for (
auto p :
pars()) {
6675 _fr->floatParsFinal().getCatIndex(cat->GetName(), std::numeric_limits<int>().max())) {
6680 if (_fr->floatParsFinal().find(
p->
GetName()) ||
6681 std::abs(_fr->constPars().getRealValue(
p->
GetName(), std::numeric_limits<double>::quiet_NaN()) -
6687 if (_fr->constPars().find(
p->
GetName()) ||
6689 _fr->floatParsFinal().getRealValue(
p->
GetName(), std::numeric_limits<double>::quiet_NaN()) -
6698 std::unique_ptr<RooArgList> _pars(
6700 auto fr = std::make_shared<RooFitResult>(
TString::Format(
"%s-dirty", _fr->GetName()));
6702 fr->setFinalParList(*_pars);
6705 auto cov = _fr->reducedCovarianceMatrix(*_pars);
6707 for (
size_t i = 0; i < _pars->size(); i++) {
6708 if (
auto v =
dynamic_cast<RooRealVar *
>(_pars->at(i))) {
6709 cov(i, i) = pow(
v->getError(), 2);
6714 fr->setCovarianceMatrix(cov);
6720 auto _globs =
globs();
6721 _args.add(_globs.argList());
6722 fr->setConstParList(_args);
6723 std::unique_ptr<RooArgList> _snap(
dynamic_cast<RooArgList *
>(_pars->snapshot()));
6724 for (
auto &
p : *_snap) {
6725 if (
auto atr =
p->getStringAttribute(
"initVal"); atr &&
dynamic_cast<RooRealVar *
>(
p))
6728 fr->setInitParList(*_snap);
6731 return xRooNode(*_fr, std::make_shared<xRooNode>(*_w, std::make_shared<xRooNode>()));
6735 for (
auto o : _w->allGenericObjects()) {
6736 auto out = checkFr(o);
6741 auto out = checkFr(o);
6748 if (
auto fr = getObject<RooFitResult>(
".fitResult"); fr) {
6754 auto _coefs =
coefs();
6760 std::unique_ptr<RooArgList> _pars(
dynamic_cast<RooArgList *
>(
pars().
argList().selectByAttrib(
"Constant",
false)));
6761 auto fr = std::make_shared<RooFitResult>(
TUUID().AsString());
6763 fr->setFinalParList(*_pars);
6769 for (
int i = 0; i < prevCov->
GetNcols(); i++) {
6770 for (
int j = 0; j < prevCov->
GetNrows(); j++) {
6771 cov(i, j) = (*prevCov)(i, j);
6776 for (
auto &
p : fr->floatParsFinal()) {
6777 if (!prevCov || i >= prevCov->
GetNcols()) {
6779 cov(i, i) = pow(
v->getError(), 2);
6786 int covQualBackup = fr->covQual();
6787 fr->setCovarianceMatrix(cov);
6788 fr->setCovQual(covQualBackup);
6793 auto _globs =
globs();
6794 _args.add(_globs.argList());
6795 fr->setConstParList(_args);
6796 std::unique_ptr<RooArgList> _snap(
dynamic_cast<RooArgList *
>(_pars->snapshot()));
6797 for (
auto &
p : *_snap) {
6798 if (
auto atr =
p->getStringAttribute(
"initVal"); atr &&
dynamic_cast<RooRealVar *
>(
p))
6801 fr->setInitParList(*_snap);
6822 if (!std::isnan(low) && !std::isnan(high) && get<RooRealVar>()) {
6823 if (range && strlen(range)) {
6824 get<RooRealVar>()->setRange(range, low, high);
6826 get<RooRealVar>()->setRange(low, high);
6830 if (
auto o = get<RooAbsArg>(); o)
6831 o->setStringAttribute(
"range", range);
6838 std::string &out =
fRange;
6839 if (
auto o = get<RooAbsArg>(); o && o->getStringAttribute(
"range"))
6840 out = o->getStringAttribute(
"range");
6842 while (out.empty() && _parent) {
6843 if (
auto o = _parent->get<
RooAbsArg>(); o && o->getStringAttribute(
"range"))
6844 out = o->getStringAttribute(
"range");
6845 _parent = _parent->fParent;
6865 for (
auto opt : *defaultOpts) {
6868 for (
auto &i : nllOpts) {
6870 Info(
"nll",
"Overriding NLL Option: %s", o->GetName());
6876 return nll(_data,
l);
6881 if (
auto mc = get<RooStats::ModelConfig>()) {
6885 if (!get<RooAbsPdf>()) {
6887 if (get<RooWorkspace>()) {
6888 std::shared_ptr<xRooNode> mainModel;
6894 throw std::runtime_error(
TString::Format(
"Workspace has multiple models, you must specify which to "
6895 "generate with (found at least %s and %s)",
6896 mainModel->GetName(),
c->GetName()));
6901 return mainModel->generate(fr, expected, seed);
6909 if (get<RooSimultaneous>()) {
6910 std::string selected;
6912 bool hasDeselected =
false;
6913 for (
auto c :
bins()) {
6915 cName = cName(cName.
Index(
'=') + 1, cName.
Length());
6917 hasDeselected =
true;
6919 if (!fromds.empty())
6921 fromds += cName.
Data();
6924 if (!selected.empty())
6926 selected += cName.
Data();
6929 if (hasDeselected) {
6930 std::string dsetName =
"";
6931 if (!fromds.empty()) {
6934 for (
auto &
d : _dsets) {
6935 if (
d->get()->TestBit(1 << 20)) {
6936 dsetName =
d->get()->GetName();
6940 if (dsetName.empty()) {
6941 throw std::runtime_error(
6942 "Need at least one dataset selected (SetChecked) to use for deselected regions");
6946 if (!fromds.empty()) {
6962 if (
auto mc = get<RooStats::ModelConfig>()) {
6963 if (mc->GetExternalConstraints()) {
6965 for (
auto o : opts) {
6966 optsWithConstraints.
Add(o->Clone(
nullptr));
6969 return xRooNode(*mc->GetPdf(),
fParent).nll(_data, optsWithConstraints);
6971 return xRooNode(*mc->GetPdf(),
fParent).nll(_data, opts);
6975 if (!get<RooAbsPdf>()) {
6977 if (get<RooWorkspace>()) {
6978 std::shared_ptr<xRooNode> mainPdf, mainModel, otherPdf;
6990 throw std::runtime_error(
TString::Format(
"Workspace has multiple models, you must specify which to "
6991 "build nll with (found at least %s and %s)",
6992 mainModel->GetName(),
c->GetName()));
6997 return mainModel->nll(_data, opts);
7000 throw std::runtime_error(
TString::Format(
"Workspace has multiple pdfs, you must specify which to "
7001 "build nll with (found at least %s and %s)",
7002 mainPdf->GetName(), otherPdf->GetName()));
7004 return mainPdf->nll(_data, opts);
7011 if (get<RooSimultaneous>()) {
7012 std::string selected;
7013 bool hasDeselected =
false;
7014 for (
auto c :
bins()) {
7016 hasDeselected =
true;
7019 cName = cName(cName.Index(
'=') + 1, cName.Length());
7020 if (!selected.empty())
7022 selected += cName.Data();
7032 if (strlen(_data.
GetName()) == 0) {
7035 _d = std::make_shared<xRooNode>(asi.first, *
this);
7038 std::make_shared<xRooNode>(
".globs", std::const_pointer_cast<RooAbsCollection>(asi.second), *_d));
7043 return nll(*_d, opts);
7048 me.push_back(std::make_shared<xRooNode>(_data));
7049 return nll(*me.datasets().at(_data.
GetName()), opts);
7052 auto _globs = _data.
globs();
7065 for (
int i = 0; i < opts.
GetSize(); i++) {
7068 if (strcmp(opts.
At(i)->
GetName(),
"GlobalObservables") == 0) {
7071 _opts->Add(opts.
At(i)->
Clone(
nullptr));
7079 std::dynamic_pointer_cast<RooAbsData>(_data.
fComp), *_opts);
7177 auto rangeName = (_range.empty()) ?
GetRange() : _range;
7178 if (!rangeName.empty()) {
7179 std::vector<TString> patterns;
7182 patterns.emplace_back(pattern);
7184 if (
auto s = get<RooSimultaneous>(); s) {
7189 for (
auto &
c :
bins()) {
7191 cName = cName(cName.
Index(
'=') + 1, cName.
Length());
7192 _cat.setLabel(cName);
7193 bool matchAny =
false;
7194 for (
auto &
p : patterns) {
7199 if (_cat.hasRange(
p) && _cat.inRange(
p)) {
7204 if ((matchAny && !invert) || (!matchAny && invert)) {
7209 }
else if (
get() && !get<RooAbsCollection>() && !
components().empty()) {
7213 std::vector<TObject *>
funcs;
7214 for (
auto &
c : out.components()) {
7215 bool matchAny =
false;
7216 for (
auto &
p : patterns) {
7222 if (!((matchAny && !invert) || (!matchAny && invert)))
7223 funcs.push_back(
c->get());
7227 if (!
funcs.empty()) {
7229 _pdf->setFloor(
false);
7235 }
else if (
auto fr = get<RooFitResult>()) {
7241 for (
auto c : _pars) {
7242 bool matchAny =
false;
7243 for (
auto &
p : patterns) {
7249 if (!((matchAny && !invert) || (!matchAny && invert))) {
7253 _pars.remove(_remPars,
true);
7255 auto _tmp = fr->reducedCovarianceMatrix(_pars);
7256 int covQualBackup = fr->covQual();
7257 fr->setCovarianceMatrix(_tmp);
7258 fr->setCovQual(covQualBackup);
7259 const_cast<RooArgList &
>(fr->floatParsFinal())
7260 .remove(_remPars,
true);
7263 }
else if (!
get() || get<RooAbsCollection>()) {
7268 bool notAllArgs =
false;
7269 bool isVars = (strcmp(
GetName(),
".vars") == 0);
7270 for (
auto c : *
this) {
7271 nobs += (
c->fFolder ==
"!robs" ||
c->fFolder ==
"!globs");
7272 bool matchAny =
false;
7273 for (
auto &
p : patterns) {
7275 (isVars &&
p ==
"x" && (
c->fFolder ==
"!robs" ||
c->fFolder ==
"!globs") && nobs == 1)) {
7280 if ((matchAny && !invert) || (!matchAny && invert)) {
7296 return get<RooArgList>() ?
xRooNode(std::make_shared<RooArgList>(),
fParent) : *
this;
7379 return static_cast<RooAbsPdf *
>(intpdf.absArg())->expectedEvents(nset);
7388 return getProjection(&intobs, _normSet, (_normRange.Length() > 0 ? _normRange.Data() :
nullptr), code)->getVal();
7393 RooArgList **pars =
nullptr,
bool asymHi =
false,
bool asymLo =
false)
7399 if (
auto rrv =
dynamic_cast<const RooRealVar *
>(&
f); rrv) {
7404 return rrv->getErrorHi();
7405 }
else if (asymLo) {
7406 return rrv->getErrorLo();
7408 return rrv->getError();
7412 RooArgList *_pars = (pars) ? *pars : nullptr;
7417 f.getParameters(&nset, allParamsInAbsReal);
7422 auto rrvInAbsReal =
static_cast<RooRealVar const *
>(allParamsInAbsReal.
find(*rrvFitRes));
7425 if (rrvFitRes->getError() <= std::abs(rrvFitRes->getVal()) * std::numeric_limits<double>::epsilon())
7434 if (std::abs(rrvInAbsReal->getVal() - rrvFitRes->getVal()) > 0.01 * rrvFitRes->getError()) {
7435 std::stringstream errMsg;
7436 errMsg <<
"RooAbsReal::getPropagatedError(): the parameters of the RooAbsReal don't have"
7437 <<
" the same values as in the fit result! The logic of getPropagatedError is broken in this case.";
7439 throw std::runtime_error(errMsg.str());
7442 _pars->
add(*rrvInAbsReal);
7451 : fr.reducedCovarianceMatrix(*_pars));
7455 double nomVal =
f.getVal(nset);
7457 for (std::size_t ivar = 0; ivar < _pars->
size(); ivar++) {
7459 auto &rrv =
static_cast<RooRealVar &
>((*_pars)[ivar]);
7462 double cenVal = rrv.
getVal();
7463 double plusVar, minusVar, errVal;
7465 if (asymHi || asymLo) {
7466 errVal = frrrv->getErrorHi();
7467 rrv.setVal(cenVal + errVal);
7468 plusVar =
f.getVal(nset);
7469 errVal = frrrv->getErrorLo();
7470 rrv.setVal(cenVal + errVal);
7471 minusVar =
f.getVal(nset);
7474 plusVar = std::max(plusVar, minusVar);
7475 minusVar = 2 * nomVal - plusVar;
7478 minusVar = std::min(plusVar, minusVar);
7479 plusVar = 2 * nomVal - minusVar;
7482 errVal =
sqrt(V(ivar, ivar));
7484 rrv.setVal(cenVal + errVal);
7485 plusVar =
f.getVal(nset);
7487 rrv.setVal(cenVal - errVal);
7488 minusVar =
f.getVal(nset);
7490 F[ivar] = (plusVar - minusVar) * 0.5;
7504 std::vector<double> errVec(_pars->
size());
7505 for (std::size_t i = 0; i < _pars->
size(); i++) {
7506 errVec[i] = std::sqrt(V(i, i));
7507 for (std::size_t j = i; j < _pars->
size(); j++) {
7508 C(i, j) = V(i, j) / std::sqrt(V(i, i) * V(j, j));
7514 double sum =
F * (
C *
F);
7530 fFunc(
"func",
"func", this,
f),
7531 fCoef(
"coef",
"coef", this),
7532 fExpPdf(
"expPdf",
"expPdf", this)
7537 fCoef.setArg(*coef);
7539 if (expPdf && expPdf->canBeExtended() && !(coef &&
dynamic_cast<RooAddPdf *
>(expPdf))) {
7540 fExpPdf.setArg(*expPdf);
7541 }
else if (
auto _p =
dynamic_cast<RooAbsPdf *
>(&
f);
7545 fExpectedEventsMode = expEvMode;
7550 fFunc(
"func", this, other.fFunc),
7551 fCoef(
"coef", this, other.fCoef),
7552 fExpPdf(
"expPdf", this, other.fExpPdf),
7553 fExpectedEventsMode(other.fExpectedEventsMode)
7560 return fFunc->binBoundaries(obs, xlo, xhi);
7565 return (fExpectedEventsMode ? 1. : fFunc) *
7566 ((fExpPdf.absArg()) ?
static_cast<RooAbsPdf *
>(fExpPdf.absArg())->expectedEvents(_normSet) : 1.) *
7567 (fCoef.absArg() ? fCoef : 1.);
7578#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 28, 00)
7579 double oo = getPropagatedError(fr, nset_in);
7580 if (std::isnan(oo)) {
7585 getParameters(&nset_in, allParamsInAbsReal);
7588 for (
auto *rrvFitRes : static_range_cast<RooRealVar *>(fr.
floatParsFinal())) {
7590 auto rrvInAbsReal =
static_cast<RooRealVar const *
>(allParamsInAbsReal.
find(*rrvFitRes));
7594 if (rrvFitRes->namePtr() == namePtr())
7598 if (!rrvFitRes->hasError() ||
7599 rrvFitRes->getError() <= std::abs(rrvFitRes->getVal()) * std::numeric_limits<double>::epsilon())
7608 if (std::abs(rrvInAbsReal->getVal() - rrvFitRes->getVal()) > 0.01 * rrvFitRes->getError()) {
7609 std::stringstream errMsg;
7611 <<
"RooAbsReal::getPropagatedError(): the parameters of the RooAbsReal don't have"
7612 <<
" the same values as in the fit result! The logic of getPropagatedError is broken in this case.";
7614 throw std::runtime_error(errMsg.str());
7617 paramList.
add(*rrvInAbsReal);
7619 if (paramList.
empty())
7622 std::vector<double> plusVar;
7623 std::vector<double> minusVar;
7624 plusVar.reserve(paramList.
size());
7625 minusVar.reserve(paramList.
size());
7631 for (std::size_t ivar = 0; ivar < paramList.
size(); ivar++) {
7633 auto &rrv =
static_cast<RooRealVar &
>(paramList[ivar]);
7635 double cenVal = rrv.getVal();
7636 double errVal = sqrt(V(ivar, ivar));
7648 rrv.setVal(cenVal + errVal);
7649 plusVar.push_back(getVal(nset_in));
7652 rrv.setVal(cenVal - errVal);
7653 minusVar.push_back(getVal(nset_in));
7654#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
7678 std::vector<double> errVec(paramList.
size());
7679 for (std::size_t i = 0; i < paramList.
size(); i++) {
7680 errVec[i] = std::sqrt(V(i, i));
7681 for (std::size_t j = i; j < paramList.
size(); j++) {
7682 C(i, j) = V(i, j) / std::sqrt(V(i, i) * V(j, j));
7689 for (
unsigned int j = 0; j < plusVar.size(); j++) {
7690 F[j] = (plusVar[j] - minusVar[j]) / 2;
7694 double sum =
F * (C *
F);
7703 for (
auto *frv : static_range_cast<RooRealVar *>(fr.
floatParsFinal())) {
7704 if (frv->getError() > 1
e-20) {
7705 fpf_stripped.
add(*frv);
7720 std::vector<int> fpf_idx;
7721 for (
Int_t i = 0; i < fpf.
size(); i++) {
7724 paramList.
add(*par);
7725 fpf_idx.push_back(i);
7729 std::vector<double> plusVar, minusVar;
7735 for (
Int_t ivar = 0; ivar < paramList.
size(); ivar++) {
7739 double cenVal = rrv.
getVal();
7740 double errVal = sqrt(V(ivar, ivar));
7743 ((
RooRealVar *)paramList.
at(ivar))->setVal(cenVal + errVal);
7746 plusVar.push_back(cloneFunc->
getVal(nset));
7749 ((
RooRealVar *)paramList.
at(ivar))->setVal(cenVal - errVal);
7752 minusVar.push_back(cloneFunc->
getVal(nset));
7760 std::vector<double> errVec(paramList.
size());
7761 for (
int i = 0; i < paramList.
size(); i++) {
7762 errVec[i] = sqrt(V(i, i));
7763 for (
int j = i; j < paramList.
size(); j++) {
7764 C(i, j) = V(i, j) / sqrt(V(i, i) * V(j, j));
7771 for (
unsigned int j = 0; j < plusVar.size(); j++) {
7772 F[j] = (plusVar[j] - minusVar[j]) / 2;
7776 double sum =
F * (C *
F);
7790 bool fExpectedEventsMode =
false;
7798 std::cout <<
"Got signal " << signum << std::endl;
7799 if (signum == SIGINT) {
7800 std::cout <<
"Keyboard interrupt while building histogram" << std::endl;
7810 auto _doSterilize = [](
RooAbsArg *obj) {
7813 for (
int i = 0; i < obj->numCaches(); i++) {
7819 p->setNormRange(
p->normRange());
7821#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
7826 p->setProxyNormSet(
nullptr);
7827 p->_lastNSet =
nullptr;
7830 obj->setValueDirty();
7832 if (
auto w = get<RooWorkspace>();
w) {
7834 for (
auto &
c :
w->components()) {
7853 nClients =
a->clients().size();
7854 for (
auto obj :
a->clients()) {
7856 if (
a->clients().size() != nClients) {
7861 }
while (
a->clients().size() != nClients);
7863 func(get<RooAbsArg>());
7868 bool errorsLo,
int nErrorToys)
const
7880 out.fComp = std::shared_ptr<TH1>(
7881 BuildHistogram(
nullptr, !content, errors, -1, -1, fr, errorsHi, errorsLo, nErrorToys,
nullptr, !stack,
false));
7882 }
else if (
vars.size() == 1) {
7884 out.fComp = std::shared_ptr<TH1>(
7885 BuildHistogram(
v, !content, errors, 1, 0, fr, errorsHi, errorsLo, nErrorToys,
nullptr, !stack,
true));
7887 throw std::runtime_error(
"multi-dim histo not yet supported");
7899 bool errorsHi,
bool errorsLo,
int nErrorToys,
TH1 *templateHist,
bool nostack,
7900 bool setInterp)
const
7902 auto rar = get<RooAbsReal>();
7912 if (binStart != -1 || binEnd != -1) {
7923 h =
new TH1D(rar->GetName(), rar->GetTitle(), 1, 0, 1);
7924 h->GetXaxis()->SetBinLabel(1, rar->GetName());
7925 h->GetXaxis()->SetTimeFormat(rar->GetName());
7930 bool setTitle =
false;
7933 h =
static_cast<TH1 *
>(templateHist->
Clone(rar->GetName()));
7934 if (
h->GetListOfFunctions())
7937 h->SetTitle(rar->GetTitle());
7942 h =
new TH1D(rar->GetName(), rar->GetTitle(), 1, 0, 1);
7944 h->GetXaxis()->SetBinLabel(1, rar->GetName());
7945 h->SetBinContent(1, rar->getVal());
7946 if (
x->getError()) {
7947 h->SetBinError(1,
x->getError());
7948 h->SetFillStyle(3005);
7949 h->SetFillColor(
h->GetLineColor());
7951 h->SetMaximum(
x->hasMax() ?
x->getMax()
7952 : (
h->GetBinContent(1) + std::max(std::abs(
h->GetBinContent(1) * 0.1), 50.)));
7953 h->SetMinimum(
x->hasMin() ?
x->getMin()
7954 : (
h->GetBinContent(1) - std::max(std::abs(
h->GetBinContent(1) * 0.1), 50.)));
7957 h->SetMarkerSize(0);
7958 h->SetMarkerStyle(0);
7963 TString binningName = (_ax && _ax->GetParent() ==
x) ? _ax->GetName() : rar->getStringAttribute(
"binning");
7964 if (binningName ==
"")
7965 binningName = rar->GetName();
7966 if (
x->hasBinning(binningName)) {
7967 if (
x->getBinning(binningName).isUniform()) {
7968 h =
new TH1D(rar->GetName(), rar->GetTitle(),
x->numBins(binningName) <= 0 ? 100 :
x->numBins(binningName),
7969 x->getMin(binningName),
x->getMax(binningName));
7971 h =
new TH1D(rar->GetName(), rar->GetTitle(),
x->numBins(binningName),
x->getBinning(binningName).array());
7973 h->GetXaxis()->SetTitle(
x->getBinning(binningName).GetTitle());
7975 }
else if (
auto _boundaries =
7976 _or_func( (std::list<double> *)(
nullptr),
7977 rar->binBoundaries(*
x, -std::numeric_limits<double>::infinity(),
7978 std::numeric_limits<double>::infinity()));
7980 std::vector<double> _bins;
7981 for (
auto &
b : *_boundaries) {
7982 if (_bins.empty() || std::abs(_bins.back() -
b) > 1
e-5 * _bins.back())
7985 h =
new TH1D(rar->GetName(), rar->GetTitle(), _bins.size() - 1, &_bins[0]);
7987 }
else if (!
x->hasMax() || !
x->hasMin()) {
7989 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(),
x->getVal() * 0.2,
x->getVal() * 5);
7991 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(),
x->getBinning().array());
7995 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(rar->GetName()), 0,
v->numBins(rar->GetName()));
7998 std::map<int, std::string> cats;
7999 for (
auto &
c : *cat) {
8000 cats[
c.second] =
c.first;
8002 for (
auto &[
_, label] : cats) {
8003 h->GetXaxis()->SetBinLabel(i++, label.c_str());
8008 if (
auto o =
dynamic_cast<TObject *
>(
v); o && !setTitle) {
8009 h->GetXaxis()->SetTitle(o->GetTitle());
8013 if (
h->GetXaxis()->IsAlphanumeric()) {
8022 if (
auto s =
styles(
nullptr,
false); s) {
8023 auto _style = s.get<
TStyle>();
8024 static_cast<TAttLine &
>(*h) = *_style;
8025 static_cast<TAttFill &
>(*h) = *_style;
8028 if (strlen(
h->GetXaxis()->GetTitle()) == 0)
8037 if (empty && !errors) {
8043 auto _coefs =
coefs();
8058 if (!
GETDMP(fr, _finalPars)) {
8086 for (
int i = 0; i < prevCov->
GetNcols(); i++) {
8087 for (
int j = 0; j < prevCov->
GetNrows(); j++) {
8088 cov(i, j) = (*prevCov)(i, j);
8094 if (!prevCov || i >= prevCov->
GetNcols()) {
8095 cov(i, i) = pow(
dynamic_cast<RooRealVar *
>(p2)->getError(), 2);
8099 int covQualBackup = fr->
covQual();
8110 int covQualBackup = fr->
covQual();
8118 bool hasErrors =
false;
8136 binEnd =
h->GetNbinsX();
8138 bool needBinWidth =
false;
8141 if (
x && (
p || _coefs.get() || rar->getAttribute(
"density"))) {
8143 needBinWidth =
true;
8147 spdf && spdf->
canBeExtended() && !spdf->getFloor() && !_coefs.get()) {
8159 for (
auto o : _obs) {
8161 rr->removeRange(
"coordRange");
8162 rr->setStringAttribute(
"coordRange",
nullptr);
8167 rr->removeRange(
"coordRange");
8168 rr->setStringAttribute(
"coordRange",
nullptr);
8178 bool hasRange =
false;
8179 for (
auto o : normSet) {
8181 rr && (rr->getStringAttribute(
"coordRange")) && strlen(rr->getStringAttribute(
"coordRange"))) {
8191 for (
auto pdf :
bins()) {
8198 dynamic_cast<RooAbsPdf *
>(_pdf)->setNormRange(
"coordRange");
8200 newrar->addPdf(*_pdf, pdf->coords()[s->indexCat().GetName()]->get<
RooCategory>()->getLabel());
8204 rar =
p->createProjection(
8208 dynamic_cast<RooAbsPdf *
>(rar)->setNormRange(
"coordRange");
8212 p->setNormRange(
"coordRange");
8217 rar = std::unique_ptr<RooAbsReal>{rar->createIntegral(
8223 std::unique_ptr<RooAbsReal>{rar->createIntegral(*_obs.get<
RooArgList>() )}
8229 bool scaleExpected = (
p &&
p->canBeExtended() && !_coefs.get());
8235 if (!nostack &&
p &&
p->canBeExtended() && _coefs.get()) {
8241 std::unique_ptr<RooArgSet> snap(normSet.
snapshot());
8243 std::vector<double> lapTimes;
8244 bool warned =
false;
8245 if (binStart == -1 && binEnd == -1) {
8250 std::unique_ptr<RooAbsCollection> errorParsSnap;
8260 TString clNameNoNamespace = rar->ClassName();
8261 clNameNoNamespace = clNameNoNamespace(clNameNoNamespace.
Last(
':') + 1, clNameNoNamespace.
Length());
8262 setInterp = (clNameNoNamespace.
Contains(
"Hist") || vvv->
isCategory() || rar->isBinnedDistribution(*vvv) ||
8263 h->GetNbinsX() == 1 || rar->getAttribute(
"BinnedLikelihood") ||
8265 std::unique_ptr<std::list<double>>(rar->binBoundaries(*
dynamic_cast<RooAbsRealLValue *
>(vvv),
8266 -std::numeric_limits<double>::infinity(),
8267 std::numeric_limits<double>::infinity()))))
8276 bool allHist =
true;
8278 TString _clName = s->get()->ClassName();
8279 _clName = _clName(_clName.
Last(
':') + 1, _clName.
Length());
8280 if (!(s->get() && _clName.
Contains(
"Hist"))) {
8298 auto l =
static_cast<TH1 *
>(
h->Clone(
"nominal"));
8301 h->GetListOfFunctions()->Add(
l, (setInterp) ?
"lsame" :
"histsame");
8302 h->SetOption(setInterp ?
"e3" :
"e2");
8305 h->SetMarkerSize(0);
8306 h->SetFillStyle(3005);
8307 h->SetFillColor(
h->GetLineColor());
8310 if (nErrorToys > 0) {
8319 errorPars->
add(*par);
8322 errorParsSnap.reset(errorPars->
snapshot());
8323 auto l =
static_cast<TH1 *
>(
h->Clone(
"toys"));
8326 h->GetListOfFunctions()->Add(
8329 if (errorsLo || errorsHi)
8333 for (
int toy = 0; toy < (nErrorToys + 1); toy++) {
8345 for (
int i = std::max(1, binStart); i <= std::min(
h->GetNbinsX(), binEnd); i++) {
8348 x->setVal(
h->GetBinCenter(i));
8350 cat->setLabel(
h->GetXaxis()->GetBinLabel(i));
8354 if (
x && !
x->inRange(
"coordRange"))
8358 if (!empty || toy > 0) {
8359 r = rar->getVal(
p ? &normSet :
nullptr);
8360#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
8365 if (
r && _coefs.get()) {
8369 r *=
h->GetBinWidth(i);
8371 if (scaleExpected) {
8374 r *= (
p->expectedEvents(normSet));
8377 h->SetBinContent(i,
r);
8382 bool doAsym = (errorsHi && errorsLo);
8393 &errorPars, errorsHi, errorsLo);
8394#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
8396 p->_normSet =
nullptr;
8408 *fr, {}, &errorPars, errorsHi,
8414 res *=
h->GetBinWidth(i);
8416 h->SetBinError(i, res);
8424 &errorPars, errorsHi, errorsLo);
8429 *fr, {}, &errorPars, errorsHi, errorsLo);
8432 res *=
h->GetBinWidth(i);
8437 h->SetBinContent(i,
h->GetBinContent(i) + (res -
h->GetBinError(i)) * 0.5);
8438 h->SetBinError(i, (res +
h->GetBinError(i)) * 0.5);
8442 lapTimes.push_back(timeIt.
RealTime());
8443 double time_estimate =
8444 (lapTimes.size() > 1)
8445 ? (
h->GetNbinsX() * (std::accumulate(lapTimes.begin() + 1, lapTimes.end(), 0.) / (lapTimes.size() - 1)))
8447 if (!warned && (lapTimes.at(0) > 10 || (lapTimes.size() > 2 && time_estimate > 60.))) {
8449 t2.
Add(time_estimate);
8450 Warning(
"BuildHistogram",
"Building this histogram will take until %s", t2.
AsString());
8460 Warning(
"BuildHistogram",
"Skipping errors for remaining bins");
8478 *errorPars = *errorParsSnap;
8485 if (errorsLo && errorsHi) {
8486 auto nomHist =
static_cast<TH1 *
>(
h->FindObject(
"nominal"));
8489 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
8490 std::vector<double> vals;
8491 vals.reserve(nErrorToys);
8492 for (
int j = 1; j < (nErrorToys + 1); j++) {
8496 double upVal, downVal;
8497 if (errorsLo || errorsHi) {
8498 std::sort(vals.begin(), vals.end());
8502 downVal = 2. *
h->GetBinContent(i) - upVal;
8504 upVal = 2. *
h->GetBinContent(i) - downVal;
8507 upVal =
h->GetBinContent(i) + err;
8508 downVal =
h->GetBinContent(i) - err;
8510 h->SetBinContent(i, (upVal + downVal) * 0.5);
8511 h->SetBinError(i, (upVal - downVal) * 0.5);
8516 std::vector<RooAbsArg *> extra;
8519 for (
auto _pdf : s->servers()) {
8521 extra.push_back(_pdf);
8524 extra.push_back(rar);
8527 for (
auto a : extra)
8533 if (!
p && !rar->getAttribute(
"density") && !needBinWidth) {
8534 h->GetYaxis()->SetTitle(rar->getStringAttribute(
"units"));
8535 }
else if ((
p &&
p->canBeExtended()) || (!
p && needBinWidth)) {
8536 h->GetYaxis()->SetTitle(
"Events");
8538 h->GetYaxis()->SetTitle(
"Probability Mass");
8540 h->GetYaxis()->SetMaxDigits(3);
8549 auto hCopy =
static_cast<TH1 *
>(
h->Clone(
"copy"));
8553 hCopy->SetStats(
false);
8554 h->GetListOfFunctions()->Add(hCopy,
TString(
h->GetOption()) +
"same");
8555 h->GetListOfFunctions()->Add(hCopy,
"axissame");
8556 TString dOpt = (setInterp) ?
"LF2" :
"";
8569 std::map<std::string, int> colorByTitle;
8570 std::set<std::string> allTitles;
8571 bool titleMatchName =
true;
8572 std::map<std::string, TH1 *> histGroups;
8573 std::vector<TH1 *> hhs;
8574 std::set<TH1 *> histsWithBadTitles;
8580 if (!rarNode->components().empty()) {
8581 auto comps = rarNode->components()[0];
8582 for (
auto &
c : *comps) {
8583 if (
c->fFolder ==
"!.coeffs")
8587 if (!cms_coefs.
empty()) {
8589 std::shared_ptr<TH1> prevHist(
static_cast<TH1 *
>(
h->Clone()));
8592 for (
auto c : cms_coefs) {
8594 std::unique_ptr<RooAbsReal>
f(
8595 dynamic_cast<RooAbsReal *
>(rarNode->components()[0]->get()->
Clone(
"tmpCopy")));
8597 f->redirectServers(
RooArgSet(zero),
false,
true);
8604 if (strlen(hh->GetTitle()) == 0) {
8605 hh->SetTitle(
c->GetName());
8606 histsWithBadTitles.insert(hh);
8607 }
else if (strcmp(hh->GetName(), hh->GetTitle()) == 0) {
8608 histsWithBadTitles.insert(hh);
8610 titleMatchName &= (
TString(
c->GetName()) == hh->GetTitle() ||
8612 std::shared_ptr<TH1> nextHist(
static_cast<TH1 *
>(hh->Clone()));
8613 hh->Add(prevHist.get(), -1.);
8616 prevHist = nextHist;
8618 }
else if (get<RooSimultaneous>()) {
8622 for (
auto &chan :
bins()) {
8623 TString chanName(chan->GetName());
8624 chanName = chanName(chanName.
Index(
"=") + 1, chanName.
Length());
8625 auto samps = chan->mainChild();
8628 for (
auto &samp : samps.components()) {
8629 auto hh =
static_cast<TH1 *
>(
h->Clone(samp->GetName()));
8631 hh->SetTitle(samp->GetTitle());
8632 if (strlen(hh->GetTitle()) == 0) {
8633 hh->SetTitle(samp->GetName());
8634 histsWithBadTitles.insert(hh);
8635 }
else if (strcmp(hh->GetName(), hh->GetTitle()) == 0) {
8636 histsWithBadTitles.insert(hh);
8638 hh->SetTitle(
TString(hh->GetTitle())
8639 .ReplaceAll(
TString(chan->get()->GetName()) +
"_",
8641 titleMatchName &= (
TString(samp->GetName()) == hh->GetTitle() ||
8643 hh->SetBinContent(hh->GetXaxis()->FindFixBin(chanName), samp->GetContent());
8648 for (
auto &samp : rarNode->components()) {
8649 auto hh = samp->BuildHistogram(
8650 v, empty,
false , binStart, binEnd, _fr,
false,
false, 0,
h,
true,
8652 hh->SetName(samp->GetName());
8656 if (strlen(hh->GetTitle()) == 0) {
8657 hh->SetTitle(samp->GetName());
8658 histsWithBadTitles.insert(hh);
8659 }
else if (strcmp(hh->GetName(), hh->GetTitle()) == 0) {
8660 histsWithBadTitles.insert(hh);
8662 titleMatchName &= (
TString(samp->GetName()) == hh->GetTitle() ||
8668 for (
auto &hh : hhs) {
8669 allTitles.insert(hh->GetTitle());
8674 size_t e = std::min(allTitles.begin()->size(), allTitles.rbegin()->size());
8676 bool goodPrefix =
false;
8677 std::string commonSuffix;
8678 if (titleMatchName && hhs.size() > 1) {
8679 while (ii <
e - 1 && allTitles.begin()->at(ii) == allTitles.rbegin()->at(ii)) {
8681 if (allTitles.begin()->at(ii) ==
'_' || allTitles.begin()->at(ii) ==
' ')
8687 while (!stop && commonSuffix.size() <
size_t(
e - 1)) {
8688 commonSuffix = allTitles.begin()->substr(allTitles.begin()->length() - commonSuffix.length() - 1);
8689 for (
auto &
tt : allTitles) {
8691 commonSuffix = commonSuffix.substr(1);
8697 if (commonSuffix.find(
'_') == std::string::npos) {
8700 commonSuffix = commonSuffix.substr(commonSuffix.find(
'_'));
8709 std::map<std::string, std::string> reducedTitles;
8710 while (reducedTitles.size() != allTitles.size()) {
8712 std::map<std::string, int> titlesMap;
8713 for (
auto &s : allTitles) {
8714 if (reducedTitles.count(s))
8716 titlesMap[s.substr(0, jj)]++;
8718 for (
auto &s : allTitles) {
8719 if (titlesMap[s.substr(0, jj)] == 1 && (jj >= s.length() || s.at(jj) ==
' ' || s.at(jj) ==
'_')) {
8720 reducedTitles[s] = s.substr(0, jj);
8726 for (
auto ritr = hhs.rbegin(); ritr != hhs.rend(); ++ritr) {
8727 if (!histsWithBadTitles.count((*ritr))) {
8730 auto _title = (hhs.size() > 5) ? reducedTitles[(*ritr)->GetTitle()] : (*ritr)->GetTitle();
8731 _title = _title.substr(ii < _title.size() ? ii : 0);
8732 if (!commonSuffix.empty() &&
TString(_title).
EndsWith(commonSuffix.c_str()))
8733 _title = _title.substr(0, _title.length() - commonSuffix.length());
8734 (*ritr)->SetTitle(_title.c_str());
8738 for (
auto &hh : hhs) {
8740 if (histGroups.find(hh->GetTitle()) == histGroups.end()) {
8741 histGroups[hh->GetTitle()] = hh;
8744 histGroups[hh->GetTitle()]->Add(hh);
8749 auto hhMin = (hh->GetMinimum() == 0) ? hh->GetMinimum(1
e-9) : hh->GetMinimum();
8750 if (!stack->
GetHists() &&
h->GetMinimum() > hhMin) {
8752 if (hhMin >= 0 && newMin < 0)
8753 newMin = hhMin * 0.99;
8767 stack->
Add(hh, thisOpt);
8770 h->GetListOfFunctions()->AddFirst(stack,
"noclear same");
8782 for (
auto ho : *ll) {
8783 TH1 *hh =
dynamic_cast<TH1 *
>(ho);
8796 for (
auto ho2 : *ll) {
8797 TH1 *hh2 =
dynamic_cast<TH1 *
>(ho2);
8811 if (
auto _style = _styleNode.get<
TStyle>()) {
8812 *
dynamic_cast<TAttLine *
>(hh) = *_style;
8813 *
dynamic_cast<TAttFill *
>(hh) = *_style;
8833 push_back(std::make_shared<xRooNode>(
data));
8841 return std::numeric_limits<double>::quiet_NaN();
8842 return node->GetBinContent(bin);
8848 if (binStart != binEnd || !
fParent) {
8853 std::vector<double> out;
8854 if (get<RooAbsData>()) {
8862 if (binStart == binEnd && binStart == -1) {
8865 for (
int i = 0; i <
g->GetN(); i++)
8866 integral +=
g->GetPointY(i);
8867 out.push_back(integral);
8871 for (
int i = binStart - 1; i <
g->GetN() && (binEnd == 0 || i < binEnd); i++) {
8872 out.push_back(
g->GetPointY(i));
8878 bool doIntegral =
false;
8879 if (binStart == binEnd && binStart == -1) {
8889 binEnd =
h->GetNbinsX();
8893 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
8894 tot +=
h->GetBinContent(i);
8898 for (
int i = binStart; i <= binEnd; i++) {
8899 out.push_back(
h->GetBinContent(i));
8908 if (
auto a = get<RooAbsArg>();
a) {
8910 for (
auto &
l :
a->servers()) {
8930 if (
auto o =
get(); o) {
8939#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
8943 for (
int i = 0; i <
p->fCGnx; i++) {
8944 for (
int j = 0; j <
p->fCGny; j++) {
8945 p->fCollideGrid[i + j *
p->fCGnx] =
true;
8948 p->FillCollideGrid(o);
8952 Int_t nxmax =
p->fCGnx - iw - 1 -
p->fCGnx *
p->GetRightMargin();
8953 Int_t nymax =
p->fCGny - ih - 1 -
p->fCGny *
p->GetTopMargin();
8955 for (
Int_t j = nymax; j >= 0; j--) {
8956 for (
Int_t i = nxmax; i >= 0; i--) {
8957 if (
p->Collide(i, j, iw, ih)) {
8968 return p->PlaceBox(o,
w,
h, xl, yb,
"trw");
8976 gPad->PaintModified();
8982 auto l =
new TPaveText(
gPad->GetLeftMargin() + 0.02, 1. -
gPad->GetTopMargin() - 0.08, 0.6,
8983 1. -
gPad->GetTopMargin() - 0.08);
8984 l->SetBorderSize(0);
8985 if (
l->GetTextSize() == 0)
8993 l->ConvertNDCtoPad();
8999 if (
auto p =
dynamic_cast<TLegend *
>(
gPad->GetPrimitive(
"legend"));
p) {
9002 double w =
p->GetX2NDC() -
p->GetX1NDC();
9003 double h =
p->GetY2NDC() -
p->GetY1NDC();
9005 gPad->PaintModified();
9009 x = std::max(
x, (
gPad->GetLeftMargin() + 0.02));
9010 y = std::max(
y, (
gPad->GetBottomMargin() + 0.02));
9011 x = std::min(
x, (1. -
gPad->GetRightMargin() - 0.02) -
w);
9012 y = std::min(
y, (1. -
gPad->GetTopMargin() - 0.02) -
h);
9013 h = std::min(
h, (1. -
gPad->GetTopMargin() - 0.02) -
y);
9014 w = std::min(
w, (1. -
gPad->GetRightMargin() - 0.02) -
x);
9026 while ((
p !=
p->GetMother()) && (
p =
p->GetMother())) {
9027 if (
auto q =
dynamic_cast<TVirtualPad *
>(
p->GetPrimitive(
"legend"));
q) {
9035 if (
p && strcmp(
p->
GetName(),
"legend") == 0) {
9036 if (
l =
dynamic_cast<TLegend *
>(
p->GetPrimitive(
"legend"));
l || !create)
9040 gPad->GetBottomMargin());
9041 l->SetBorderSize(1);
9045 l =
new TLegend(0.6, 1. -
gPad->GetTopMargin() - 0.08, 0.75, 1. -
gPad->GetTopMargin() - 0.08);
9046 l->SetBorderSize(0);
9048 if (
l->GetTextSize() == 0) {
9056 l->SetName(
"legend");
9058 l->ConvertNDCtoPad();
9065 auto i = s.find(
"\n");
9066 if (i == std::string::npos) {
9069 return std::string(
"#splitline{") + s.substr(0, i) +
"}{" +
formatLegendString(s.substr(i + 1)) +
"}";
9078 for (
auto a : *
l->GetListOfPrimitives()) {
9082 if (
l->GetListOfPrimitives()->GetEntries() > 20)
9086 if (
auto nObj =
l->GetListOfPrimitives()->GetEntries(); nObj > 0) {
9088 int nn =
l->GetNColumns();
9090 if (nObj > 1 && (nObj % nn) == 1) {
9091 l->SetNColumns(
l->GetNColumns() + 1);
9092 if (
l->GetBorderSize() == 0) {
9093 l->SetX1NDC(
l->GetX2NDC() - 0.15 *
l->GetNColumns());
9096 if (
l->GetBorderSize() == 0) {
9097 l->SetY1NDC(
l->GetY2NDC() - 0.05 *
gPad->GetHNDC() * std::ceil((
double(nObj) /
l->GetNColumns())));
9113 fPad->GetCanvas()->Paint();
9114 fPad->GetCanvas()->Update();
9115#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
9116 fPad->GetCanvas()->ResetUpdated();
9131 if (
gROOT->FromPopUp()) {
9132 gROOT->SetFromPopUp(
false);
9135 }
catch (
const std::exception &
e) {
9138 (
gROOT->GetListOfBrowsers()->At(0))
9141 "Exception",
e.what(),
9144 gROOT->SetFromPopUp(
true);
9153 if (
auto mc = get<RooStats::ModelConfig>()) {
9155 }
else if (
auto ir = get<RooStats::HypoTestInverterResult>()) {
9159 }
else if (get<RooStats::HypoTestResult>()) {
9172 auto _dsets =
fParent->datasets();
9175 for (
auto &
d : _dsets) {
9176 if (
d->get()->TestBit(1 << 20)) {
9177 dsetName =
d->get()->GetName();
9181 auto hs =
fParent->nll(dsetName.
Data()).hypoSpace(get<RooRealVar>()->GetName());
9182 hs.limits(
"cls visualize");
9194 [](
double a,
double b,
double) {
9197 if (
b == 0 &&
a == 0)
9204 [](
double n,
double b,
double sigma) {
9208 t0 = 2. * (((
n == 0) ? 0 :
n * log(
n /
b)) - (
n -
b));
9211 double b_hathat = 0.5 * (
b - sigma2 + sqrt(pow(
b - sigma2, 2) + 4 *
n * sigma2));
9214 t0 = 2. * (((
n == 0) ? 0 :
n * log(
n / b_hathat)) + b_hathat -
n + pow(
b - b_hathat, 2) / (2. * sigma2));
9218 return (
n >=
b) ? sqrt(t0) : -sqrt(t0);
9226 std::vector<double> xPoints;
9229 int _idx = sOpt2.
Index(
"x=");
9230 int _eidx = sOpt2.
Index(
';', _idx);
9231 TString varPart = sOpt(_idx + 2, (_eidx < 0 ? sOpt2.
Length() : _eidx) - (_idx + 2));
9234 if (
auto _idx2 = varPart.
Index(
"("); _idx2 > 0) {
9235 varName = varPart(0, _idx2);
9245 }
else if (ii == 1) {
9247 }
else if (ii == 2) {
9255 for (
double x = min;
x <= max;
x += (max - min) / (nBins - 1)) {
9256 xPoints.push_back(
x);
9258 }
else if (nBins == 1)
9259 xPoints.push_back((min + max) / 2.);
9261 v = getObject<RooAbsLValue>(varName.Data()).get();
9263 throw std::runtime_error(
TString::Format(
"Could not find variable %s", varName.Data()));
9265 if (xPoints.empty() && !
obs().
find(varName.Data()) &&
9268 for (
int i = 0; i <
v->numBins(
GetName()); i++) {
9286 }
else if (get<RooAbsPdf>()) {
9288 forceNames = sOpt(sOpt2.
Index(
"force") + 5, sOpt2.
Length());
9289 sOpt = sOpt(0, sOpt2.
Index(
"force"));
9290 sOpt2 = sOpt2(0, sOpt2.
Index(
"force"));
9292 Error(
"Draw",
"Can only compute forces with PDFs");
9296 bool hasOverlay = sOpt2.
Contains(
"overlay");
9300 overlayName = sOpt(sOpt2.
Index(
"overlay") + 7, sOpt2.
Length());
9301 sOpt = sOpt(0, sOpt2.
Index(
"overlay"));
9302 sOpt2 = sOpt2(0, sOpt2.
Index(
"overlay"));
9307 sOpt +=
"auxSignif";
9309 std::string auxPlotTitle;
9320 bool nostack = sOpt.
Contains(
"nostack");
9322 bool hasSame = sOpt.
Contains(
"same");
9324 bool hasGoff = sOpt.
Contains(
"goff");
9326 bool hasFR = sOpt.
Contains(
"pull") && !get<RooFitResult>();
9328 bool hasText = sOpt.
Contains(
"text");
9329 bool hasTexte = sOpt.
Contains(
"texte");
9330 bool hasErrorOpt = sOpt.
Contains(
"e");
9334 }
else if (hasText) {
9337 if (auxPlotTitle ==
"Signif")
9344 TH1 *hAxis =
nullptr;
9346 auto clearPad = []() {
9348 if (
gPad->GetNumber() == 0) {
9360 if (!hasSame || !pad) {
9371 if (hAxis =
dynamic_cast<TH1 *
>(o); hAxis)
9391 auto adjustYRange = [&](
double min,
double max,
TH1 *hh =
nullptr,
bool symmetrize =
false) {
9399 double ymin = hh->GetMinimum();
9400 double ymax = hh->GetMaximum();
9401 if (hh->GetMaximumStored() == -1111)
9403 if (hh->GetMinimumStored() == -1111) {
9406 }
else if (
ymin < 0) {
9414 if (hh->GetSumw2()) {
9415 double smallestErrDown3 = -std::numeric_limits<double>::infinity();
9416 double smallestErrUp3 = std::numeric_limits<double>::infinity();
9417 for (
int i = 1; i <= hh->GetNbinsX(); i++) {
9418 smallestErrDown3 = std::max(smallestErrDown3, hh->GetBinContent(i) - 3 * hh->GetBinError(i));
9419 smallestErrUp3 = std::min(smallestErrUp3, hh->GetBinContent(i) + 3 * hh->GetBinError(i));
9421 max = std::max(max, smallestErrUp3);
9422 min = std::min(min, smallestErrDown3);
9424 bool change =
false;
9436 double down = hh->GetBinContent(1) -
ymin;
9437 double up =
ymax - hh->GetBinContent(1);
9439 ymax = hh->GetBinContent(1) + down;
9441 ymin = hh->GetBinContent(1) - up;
9444 if (hh == hAxis && pad && !pad->
GetLogy() &&
ymin > 0 && (log10(
ymax) - log10(max)) >= 3) {
9448 if (hh == hAxis && pad &&
ymin == 0 && pad->
GetLogy()) {
9453 hh->SetMinimum(
ymin);
9454 hh->SetMaximum(
ymax);
9455 hh->GetYaxis()->Set(1,
ymin,
ymax);
9462 double ymax = -std::numeric_limits<double>::infinity();
9463 double ymin = std::numeric_limits<double>::infinity();
9464 for (
int i = 0; i <
gr->
GetN(); i++) {
9471 if (!xPoints.empty()) {
9476 out->SetFillColor(out->GetLineColor());
9477 out->SetMarkerStyle(0);
9478 out->SetFillStyle(hasErrorOpt ? 3005 : 0);
9480 for (
auto &
x : xPoints) {
9484 out->SetPointEYlow(out->GetN() - 1,
GetError());
9485 out->SetPointEYhigh(out->GetN() - 1, out->GetErrorYlow(out->GetN() - 1));
9491 out->Draw(
TString(hasSame ?
"L" :
"AL") + (hasErrorOpt ?
"3" :
""));
9512 gPad->GetFrame()->SetFillStyle(1001);
9513 gPad->SetTopMargin(0);
9514 gPad->SetBottomMargin(0);
9515 gPad->SetName(
"pull");
9519 Error(
"Draw",
"Couldn't find pull graph");
9522 pullGraph->SetName(
"nominal");
9526 auto scaleHist =
static_cast<TH1 *
>(pullGraph->FindObject(
"scales"));
9528 throw std::runtime_error(
"Could not find scales in fit result");
9530 for (
auto i = 0; i < pullGraph->GetN(); i++) {
9532 g->
SetName(scaleHist->GetXaxis()->GetBinLabel(i + 1));
9535 Warning(
"Draw",
"Found a non-var in the floatParsFinal list: %s - this shouldn't happen",
g->GetName());
9539 "%s=%g +/- %s [%g,%g]", strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName(), _p->getVal(),
9540 _p->hasAsymError() ?
TString::Format(
"(%g,%g)", _p->getAsymErrorHi(), _p->getAsymErrorLo()).
Data()
9542 scaleHist->GetBinContent(i + 1), scaleHist->GetBinError(i + 1)));
9543 g->SetPoint(0, pullGraph->GetPointX(i), pullGraph->GetPointY(i));
9544 g->SetPointEYhigh(0, pullGraph->GetErrorYhigh(i));
9545 g->SetPointEYlow(0, pullGraph->GetErrorYlow(i));
9546 g->SetEditable(
true);
9547 g->SetHighlight(
true);
9548 g->SetMarkerStyle(20);
9549 g->SetMarkerSize(0.5);
9557 _thisClone->AppendPad();
9570 if (
auto _simPdf = get<RooSimultaneous>();
9571 _simPdf && !(
v && strcmp(_simPdf->indexCat().GetName(),
dynamic_cast<TObject *
>(
v)->
GetName()) == 0)) {
9572 auto _channels =
bins();
9574 for (
auto &_v : _channels) {
9575 if (!_v->IsHidden())
9606 dynamic_cast<TPad *
>(pad)->DivideSquare(_size, 1
e-9, 1
e-9);
9608 auto _pad = pad->
GetPad(_size);
9611 _pad->SetPad(_pad->GetXlowNDC(), _pad->GetYlowNDC(), 1.0, _pad->GetYlowNDC() + _pad->GetHNDC());
9624 std::vector<TString> chanPatterns;
9625 if (_range && strlen(_range)) {
9628 chanPatterns.emplace_back(pattern);
9631 for (
auto &_v : _channels) {
9638 chanVar.setLabel(cName);
9639 bool inRange = chanPatterns.empty();
9640 for (
auto &
p : chanPatterns) {
9641 if (chanVar.inRange(
p)) {
9649 gPad->SetLeftMargin(std::min(
gPad->GetLeftMargin() * (1. /
gPad->GetWNDC()), 0.3));
9659 if (!
get() || get<RooArgList>()) {
9664 for (
auto &_v : *
this) {
9667 if (strcmp(
GetName(),
".vars") == 0) {
9671 if (strcmp(_v->get()->GetName(),
"1") == 0 || strcmp(_v->get()->GetName(),
"ONE") == 0 ||
9674 if (_v->get()->InheritsFrom(
"RooConstVar"))
9685 dynamic_cast<TPad *
>(pad)->DivideSquare(_size, 1
e-9, 1
e-9);
9688 for (
auto &_v : *
this) {
9691 if (strcmp(
GetName(),
".vars") == 0) {
9695 if (strcmp(_v->get()->GetName(),
"1") == 0 || strcmp(_v->get()->GetName(),
"ONE") == 0 ||
9698 if (_v->get()->InheritsFrom(
"RooConstVar"))
9707 gPad->SetLeftMargin(std::min(
gPad->GetLeftMargin() * (1. /
gPad->GetWNDC()), 0.3));
9722 _mainChild.Draw(opt);
9728 if (
auto fr = get<RooFitResult>(); fr) {
9736 hist->SetStats(
false);
9737 hist->SetDirectory(
nullptr);
9740 hist->GetXaxis()->SetTickSize(0);
9741 hist->GetYaxis()->SetTickSize(0);
9742 hist->SetMinimum(-100);
9745 gPad->SetGrid(1, 1);
9756 std::string poiName;
9759 poiName = sOpt3(sOpt3.
Index(
"breakdown:") + 10, sOpt3.
Length());
9762 if (_poi->empty()) {
9763 throw std::runtime_error(
"No floating poi in the fit");
9764 }
else if (_poi->size() != 1) {
9765 throw std::runtime_error(
"Multiple poi in the fit");
9767 poiName = _poi->first()->GetName();
9771 throw std::runtime_error(
TString::Format(
"Cannot find parameter %s", poiName.c_str()));
9773 std::set<std::string> groups;
9777 }
else if (
p->getStringAttribute(
"group")) {
9778 groups.insert(
p->getStringAttribute(
"group"));
9791 roundedVal.second *= .1;
9799 for (
auto group : groups) {
9801 double variance = pow(
dynamic_cast<RooRealVar *
>(
poi)->getError(), 2);
9805 }
else if ((
p->getStringAttribute(
"group") &&
group ==
p->getStringAttribute(
"group")) ||
9811 int idx =
pars.index(poiName.c_str());
9813 if (reducedVar > variance) {
9814 Warning(
"Draw",
"breakdown group %s variance bigger than preceding?",
group.c_str());
9820 std::pair(sqrt(variance - reducedVar), roundedVal.second));
9848 out->SetTitle(
"Fit Result Pulls");
9849 std::vector<TString> graphLabels;
9852 ugraph->
SetTitle(
"Fit Result Pulls");
9853 std::vector<TString> ugraphLabels;
9854 std::map<std::string, double> scale;
9855 std::map<std::string, double>
offset;
9861 if (std::isnan(_v->getErrorHi()) || std::isnan(_v->getErrorLo())) {
9862 Warning(
"Draw",
"%s error is invalid", _v->GetName());
9867 double prefitError = 0;
9868 double prefitVal = 0;
9869 double customScale = 0;
9872 prefitError = ip->getError();
9873 prefitVal = ip->getVal();
9876 std::shared_ptr<xRooNode> pConstr;
9879 if (_vv->hasRange(
"pullScale")) {
9880 customScale = (_vv->getMax(
"pullScale") - _vv->getMin(
"pullScale")) / 2.;
9883 for (
auto &
c : _constr) {
9886 bool isServer =
true;
9889 for (
auto s :
c->get<
RooAbsArg>()->servers()) {
9890 if (strcmp(s->GetName(),
p->
GetName()) == 0) {
9911 if (pConstr->get<
RooPoisson>() && pConstr->find(
".x")) {
9912 std::string xName = pConstr->find(
".x")->get()->GetName();
9913 prefitVal = pConstr->find(
".x")->get<
RooAbsReal>()->getVal();
9914 for (
auto &_d : pConstr->vars()) {
9915 if (strcmp(
p->
GetName(), _d->get()->GetName()) == 0)
9917 if (xName == _d->get()->GetName())
9923 prefitVal /= prefitError;
9925 prefitError = 1. / sqrt(prefitError);
9926 }
else if (
auto _g = pConstr->get<
RooGaussian>(); _g) {
9928 (pConstr->find(
".sigma")) ? pConstr->find(
".sigma")->get<
RooAbsReal>()->getVal() : prefitError;
9930 (pConstr->find(
".x")) ? pConstr->find(
".x")->get<
RooAbsReal>()->getVal() : 0;
9931 if (pConstr->find(
".x") &&
9934 prefitVal = pConstr->find(
".mean")->get<
RooAbsReal>()->getVal();
9939 prefitError = customScale;
9940 if (prefitError == 0) {
9941 Warning(
"Draw",
"failed to determine prefit error of %s, using post-fit error",
p->
GetName());
9942 prefitError = _v->getError();
9944 out->SetPoint(out->GetN(), out->GetN(), (_v->getVal() - prefitVal) / prefitError);
9945 out->SetPointError(out->GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
9946 (_v->getErrorHi()) / prefitError);
9947 graphLabels.push_back(
p->
GetName());
9953 prefitError = customScale;
9954 if (prefitError == 0) {
9956 prefitError = (std::max({_v->getMax() - _v->getVal(), _v->getVal() - _v->getMin(), 4.}) / 4);
9957 ugraph->
SetPoint(ugraph->
GetN(), ugraph->
GetN(), (_v->getVal() - prefitVal) / prefitError);
9958 ugraph->
SetPointError(ugraph->
GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
9959 (_v->getErrorHi()) / prefitError);
9960 ugraphLabels.push_back(
p->
GetName());
9962 out->SetPoint(out->GetN(), out->GetN(), (_v->getVal() - prefitVal) / prefitError);
9963 out->SetPointError(out->GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
9964 (_v->getErrorHi()) / prefitError);
9965 graphLabels.push_back(
p->
GetName());
9973 prefitError = customScale;
9974 if (prefitError == 0) {
9975 prefitError = (std::max({_v->getMax() - _v->getVal(), _v->getVal() - _v->getMin(), 4.}) / 4);
9977 ugraph->
SetPoint(ugraph->
GetN(), ugraph->
GetN(), (_v->getVal() - prefitVal) / prefitError);
9978 ugraph->
SetPointError(ugraph->
GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
9979 (_v->getErrorHi()) / prefitError);
9980 ugraphLabels.push_back(
p->
GetName());
9988 for (
int i = 0; i < ugraph->
GetN(); i++)
9990 int nUnconstrained = ugraph->
GetN();
9993 tmpList.
Add(ugraph);
9994 graph->Merge(&tmpList);
9997 for (
auto &
l : ugraphLabels) {
9998 graphLabels.push_back(
l);
10002 graph->SetMarkerStyle(20);
10003 graph->SetMarkerSize(0.5);
10005 graph->SetMaximum(4);
10006 graph->SetMinimum(-4);
10008 bool doHorizontal =
10011 std::vector<std::pair<double, std::string>>
covariances;
10012 std::string poiName;
10013 double maxImpact = 0;
10017 poiName = sOpt3(sOpt3.
Index(
"impact:") + 7, sOpt3.
Length());
10020 if (_poi->empty()) {
10021 throw std::runtime_error(
"No floating poi in the fit");
10022 }
else if (_poi->size() != 1) {
10023 throw std::runtime_error(
"Multiple poi in the fit");
10025 poiName = _poi->first()->GetName();
10029 throw std::runtime_error(
TString::Format(
"Cannot find parameter %s", poiName.c_str()));
10040 for (
auto &label : graphLabels) {
10046 [&](std::pair<double, std::string> i, std::pair<double, std::string> j) {
10047 return doHorizontal ? (std::abs(i.first) < std::abs(j.first))
10048 : (std::abs(i.first) > std::abs(j.first));
10052 std::vector<TString> sortedLabels;
10053 maxImpact = (doHorizontal) ?
covariances.back().first
10060 c.first *= 4. / (maxImpact * 1.2);
10061 sortedLabels.push_back(
c.second);
10063 for (; i < graphLabels.size(); i++) {
10064 if (graphLabels[i] ==
c.second) {
10074 tmpList2.
Add(&sortedGraph);
10075 graph->Merge(&tmpList2);
10077 graphLabels = sortedLabels;
10078 graph->SetTitle(
"Fit Result Impact");
10083 if (doHorizontal) {
10085 std::max(
graph->GetN(), 1) - 0.5);
10087 for (
auto &
l : graphLabels) {
10090 if (!graphLabels.empty())
10097 for (
auto &
l : graphLabels) {
10100 if (!graphLabels.empty())
10108 auto histCopy =
dynamic_cast<TH1 *
>(hist->
Clone(
".axis"));
10111 auto _axis = (doHorizontal ? histCopy->GetYaxis() : histCopy->GetXaxis());
10121 graph->GetHistogram()->GetXaxis()->Set(std::max(
graph->GetN(), 1), -0.5, std::max(
graph->GetN(), 1) - 0.5);
10122 for (
int ii = 1; ii <= _axis->GetNbins(); ii++) {
10123 graph->GetHistogram()->GetXaxis()->SetBinLabel(ii, _axis->GetBinLabel(ii));
10137 auto oldPad =
gPad;
10138 gPad->Divide(1, 1, 1
e-9, 1
e-9);
10141 if (doHorizontal) {
10142 gPad->SetLeftMargin(0.4);
10144 gPad->SetBottomMargin(0.4);
10147 auto pNamesHist =
dynamic_cast<TH1F *
>(
graph->GetHistogram()->Clone(
"scales"));
10148 pNamesHist->
Sumw2();
10149 pNamesHist->SetDirectory(
nullptr);
10151 for (
int ii = 1; ii <=
graph->GetN(); ii++) {
10153 pNamesHist->SetBinContent(ii,
offset[_p->GetName()]);
10154 pNamesHist->SetBinError(ii, scale[_p->GetName()]);
10155 _axis->SetBinLabel(ii, strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName());
10161 for (
int ii = 2; ii >= 1; ii--) {
10165 pullBox->SetPoint(0, (doHorizontal) ? -ii : -0.5, (doHorizontal) ? -0.5 : 0);
10166 pullBox->SetPoint(1, (doHorizontal) ? ii : (_axis->GetNbins() - 0.5 - nUnconstrained),
10167 (doHorizontal) ? -0.5 : 0);
10168 pullBox->SetPointError(0, 0, (doHorizontal) ? (_axis->GetNbins() - nUnconstrained) : ii);
10169 pullBox->SetPointError(1, 0, (doHorizontal) ? (_axis->GetNbins() - nUnconstrained) : ii);
10173 auto pullLine =
new TGraph;
10174 pullLine->
SetName(
"0sigmaLine");
10176 pullLine->SetPoint(0, -0.5, 0);
10177 pullLine->SetPoint(1, _axis->GetNbins() - 0.5, 0);
10178 pullLine->SetLineStyle(2);
10179 pullLine->SetEditable(
false);
10183 if (nUnconstrained > 0) {
10185 pullLine->
SetName(
"dividerLine");
10187 pullLine->SetPoint(0,
graph->GetN() - 0.5 - nUnconstrained, -100);
10188 pullLine->SetPoint(1,
graph->GetN() - 0.5 - nUnconstrained, 100);
10189 pullLine->SetLineStyle(2);
10190 pullLine->SetEditable(
false);
10196 new TPaveText(
gPad->GetLeftMargin(), 1. -
gPad->GetTopMargin(), 1. -
gPad->GetRightMargin(), 0.98,
"NDCNB");
10203 std::string covQualTxt;
10205 case -1: covQualTxt =
"Unknown";
break;
10206 case 0: covQualTxt =
"Not calculated";
break;
10207 case 1: covQualTxt =
"Approximate";
break;
10208 case 2: covQualTxt =
"Forced Positive-Definite";
break;
10209 case 3: covQualTxt =
"Accurate";
break;
10214 std::string statusCodes;
10223 gPad->SetTicks(0, 0);
10225 if (doHorizontal) {
10227 if (
int(
gPad->GetCanvas()->GetWh()) < pNamesHist->GetNbinsX() * 15) {
10228 gPad->GetCanvas()->SetCanvasSize(
gPad->GetCanvas()->GetWw(), pNamesHist->GetNbinsX() * 15);
10232 double factor = 475. /
gPad->GetCanvas()->GetWh();
10237 new TGaxis(_axis->GetXmin(), -4, _axis->GetXmin(), 4, -1.2 * maxImpact, 1.2 * maxImpact, 510,
"-S");
10239 if (doHorizontal) {
10261 for (
int tt = 0;
tt < 2;
tt++) {
10262 auto impact =
static_cast<TH1 *
>(
10265 impact->GetYaxis()->SetTitle(
TString::Format(
"#Delta%s/#sigma", poiName.c_str()));
10266 impact->SetBarWidth(0.9);
10267 impact->SetBarOffset(0.05);
10268 impact->SetLineColor(
kBlack);
10269 impact->SetFillColor(
kAzure - 4);
10270 impact->SetFillStyle(
tt == 0 ? 3013 : 1001);
10272 static_cast<TH1 *
>(impact->Clone(
TString::Format(
"%s_impact-",
tt == 0 ?
"prefit" :
"postfit")));
10274 impact2->SetFillColor(
kCyan);
10275 for (
int ii = 1; ii <= pNamesHist->GetNbinsX(); ii++) {
10277 if (
c.second != pNamesHist->GetXaxis()->GetBinLabel(ii))
10281 impact->SetBinContent(ii, ((
tt == 0 && !vv_init->hasError()) || !
vv->hasError())
10283 :
c.first *
vv->getError() /
vv->getErrorHi() *
10284 (
tt == 0 ? (vv_init->getErrorHi() /
vv->getErrorHi()) : 1.));
10285 impact2->SetBinContent(ii, ((
tt == 0 && !vv_init->hasError()) || !
vv->hasError())
10287 :
c.first *
vv->getError() /
vv->getErrorLo() *
10288 (
tt == 0 ? (vv_init->getErrorLo() /
vv->getErrorLo()) : 1.));
10295 for (
int ii = -1; ii <= 1; ii++) {
10296 auto pullLine =
new TGraph;
10299 pullLine->SetPoint(0, -0.5, ii);
10300 pullLine->SetPoint(1, hist->
GetNbinsY() - 0.5, ii);
10301 pullLine->SetLineStyle(2);
10302 pullLine->SetEditable(
false);
10307 new TLegend(0.02, doHorizontal ? (1. - 0.22 * factor) : 0.02, 0.27, (doHorizontal ? 1. : 0.24));
10317 leg1->
AddEntry(hist->
FindObject(
"prefit_impact+"),
"#theta = #hat{#theta}+#Delta#theta",
"f");
10318 leg1->
AddEntry(hist->
FindObject(
"prefit_impact-"),
"#theta = #hat{#theta}-#Delta#theta",
"f");
10321 leg1->
AddEntry(hist->
FindObject(
"postfit_impact+"),
"#theta = #hat{#theta}+#Delta#theta",
"f");
10322 leg1->
AddEntry(hist->
FindObject(
"postfit_impact-"),
"#theta = #hat{#theta}-#Delta#theta",
"f");
10328 new TPaveText(
gPad->GetLeftMargin(), 1. -
gPad->AbsPixeltoY(14), 1. -
gPad->GetRightMargin(), 1.,
"NDC");
10335 : ((
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(10 / factor)) / (
gPad->GetY2() -
gPad->GetY1())));
10338 title->
AddText(histCopy->GetTitle());
10343 graph->SetEditable(
false);
10344 pNamesHist->SetLineWidth(0);
10345 pNamesHist->SetMarkerSize(0);
10346 pNamesHist->SetMarkerStyle(0);
10347 graph->GetListOfFunctions()->Add(pNamesHist,
"same");
10348 if (doHorizontal) {
10351 for (
int p = 0;
p <
graph->GetN();
p++) {
10354 graph->GetErrorXhigh(
p));
10357 if (
f->InheritsFrom(
"TH1")) {
10366 else if (
auto g =
dynamic_cast<TGraph *
>(
f)) {
10367 for (
int p = 0;
p <
g->GetN();
p++) {
10368 g->SetPoint(
p,
g->GetPointY(
p),
g->GetPointX(
p));
10371 }
else if (
auto l =
dynamic_cast<TLine *
>(
f)) {
10374 l->
SetY1(_axis->GetXmax());
10375 l->
SetY2(_axis->GetXmax());
10381 graph->SetName(
"pulls");
10386 histCopy->Draw((sOpt.
Contains(
"impact") && !doHorizontal)
10390 hist->
Draw(
"same");
10402 auto hh =
dynamic_cast<TH1 *
>(histCopy->Clone(
".axiscopy"));
10406 (sOpt.
Contains(
"impact") && !doHorizontal)
10420 bool doneDraw =
false;
10421 for (
auto c : s->bins()) {
10422 auto _pad =
dynamic_cast<TPad *
>(
gPad->GetPrimitive(
c->GetName()));
10427 c->push_back(std::make_shared<xRooNode>(*
this));
10428 auto ds =
c->datasets().find(
GetName());
10429 c->resize(
c->size() - 1);
10431 std::cout <<
" no ds " <<
GetName() <<
" - this should never happen!" << std::endl;
10446 if (!s && hasSame) {
10449 bool doneDraw =
false;
10450 for (
auto o : *
gPad->GetListOfPrimitives()) {
10465 auto dataGraph =
BuildGraph(
v,
false, (!s && hasSame) ?
gPad :
nullptr);
10470 dataGraph->SetMarkerSize(dataGraph->GetMarkerSize() *
gPad->GetWNDC());
10475 for (
int i = 0; i < dataGraph->GetN(); i++)
10476 tot += dataGraph->GetPointY(i);
10477 dataGraph->Scale(1. / tot);
10482 dataGraph->Draw(
"Az0p");
10483 addLegendEntry(dataGraph, strlen(dataGraph->GetTitle()) ? dataGraph->GetTitle() :
GetName(),
"pEX0");
10489 bool noPoint =
false;
10492 for (
auto o : *
gPad->GetListOfPrimitives()) {
10493 if (
auto h =
dynamic_cast<TH1 *
>(o);
10494 h && strcmp(
h->GetXaxis()->GetName(),
dynamic_cast<TObject *
>(
v)->
GetName()) == 0) {
10495 dataGraph->SetPointY(0,
h->Interpolate(dataGraph->GetPointX(0)));
10502 if (
auto _pad =
dynamic_cast<TPad *
>(
gPad->FindObject(
"auxPad")); _pad) {
10503 if (
auto h =
dynamic_cast<TH1 *
>(_pad->GetPrimitive(
"auxHist"));
h) {
10506 histName = histName(0, histName.
Index(
'|'));
10507 if (
auto mainHist =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(histName));
10511 auto ratioGraph =
dynamic_cast<TGraphAsymmErrors *
>(dataGraph->Clone(dataGraph->GetName()));
10513 for (
int i = 0; i < ratioGraph->GetN(); i++) {
10514 double val = ratioGraph->GetPointY(i);
10515 int binNum = mainHist->FindFixBin(ratioGraph->GetPointX(i));
10516 double nom = mainHist->GetBinContent(binNum);
10517 double nomerr = mainHist->GetBinError(binNum);
10519 std::get<0>(
auxFunctions[
h->GetYaxis()->GetTitle()])(ratioGraph->GetPointY(i), nom, nomerr);
10520 double yup = std::get<0>(
auxFunctions[
h->GetYaxis()->GetTitle()])(val + ratioGraph->GetErrorYhigh(i),
10523 double ydown = yval - std::get<0>(
auxFunctions[
h->GetYaxis()->GetTitle()])(
10524 val - ratioGraph->GetErrorYlow(i), nom, nomerr);
10525 if (!std::isnan(yval)) {
10526 ratioGraph->SetPointY(i, yval);
10527 if (!std::isnan(yup))
10528 ratioGraph->SetPointEYhigh(i, yup);
10529 if (!std::isnan(ydown))
10530 ratioGraph->SetPointEYlow(i, ydown);
10535 while (i < ratioGraph->GetN()) {
10536 if (ratioGraph->GetPointY(i) == 0 && ratioGraph->GetErrorYhigh(i) == 0 &&
10537 ratioGraph->GetErrorYlow(i) == 0) {
10538 ratioGraph->RemovePoint(i);
10543 auto _tmpPad =
gPad;
10545 ratioGraph->Draw(
"z0psame");
10546 auto minMax = graphMinMax(ratioGraph);
10547 adjustYRange(minMax.first, minMax.second,
h, std::get<1>(
auxFunctions[
h->GetYaxis()->GetTitle()]));
10553 dataGraph->Draw(
"z0p same");
10554 addLegendEntry((noPoint) ?
nullptr : dataGraph, strlen(dataGraph->GetTitle()) ? dataGraph->GetTitle() :
GetName(),
10555 noPoint ?
"" :
"pEX0");
10558 adjustYRange(minMax.first, minMax.second);
10574 gr->
Draw(hasSame ?
"P" :
"AP");
10578 if (forceNames !=
"") {
10581 bool _drawn =
false;
10582 auto _coords =
coords();
10587 std::vector<double> valuesToDo = {initPar->
getVal()};
10588 if (initPar->hasError() || initPar->hasAsymError()) {
10589 valuesToDo.push_back(initPar->getVal() + initPar->getErrorLo());
10590 valuesToDo.push_back(initPar->getVal() + initPar->getErrorHi());
10593 for (
auto valueToDo : valuesToDo) {
10595 for (
auto &
d : _dsets) {
10596 if (!
d->get()->TestBit(1 << 20))
10600 auto _obs =
d->obs();
10601 auto x = _obs.find((
v) ?
dynamic_cast<TObject *
>(
v)->
GetName() : emptyHist->GetXaxis()->GetName());
10602 auto _nll =
nll(
d);
10605 for (
int i = 0; i < nevent; i++) {
10607 bool _skip =
false;
10608 for (
const auto &_c : _coords) {
10610 if (cat->getIndex() != theData->get()->getCatIndex(cat->GetName())) {
10620 auto val = _nll.pars()->getRealValue(initPar->GetName());
10622 _nll.pars()->setRealValue(initPar->GetName(), valueToDo);
10623 auto nllVal = _nll.getEntryVal(i);
10624 _nll.pars()->setRealValue(initPar->GetName(), initPar->getVal());
10625 auto nllVal2 = _nll.getEntryVal(i);
10626 _nll.pars()->setRealValue(initPar->GetName(), val);
10632 auto val = _nll.pars()->getRealValue(initPar->GetName());
10634 _nll.pars()->setRealValue(initPar->GetName(), valueToDo);
10635 auto _extTerm = _nll.extendedTermVal();
10636 _nll.pars()->setRealValue(initPar->GetName(), initPar->getVal());
10637 auto _extTerm2 = _nll.extendedTermVal();
10638 _nll.pars()->setRealValue(initPar->GetName(), val);
10639 for (
int i = 1; i <= emptyHist->GetNbinsX(); i++) {
10640 emptyHist->SetBinContent(i,
10641 emptyHist->GetBinContent(i) + (_extTerm2 - _extTerm) / emptyHist->GetNbinsX());
10642 emptyHist->SetBinError(i, 0);
10644 emptyHist->GetYaxis()->SetTitle(
"log (L(#theta)/L(#theta_{0}))");
10645 emptyHist->SetTitle(
TString::Format(
"#theta = %g", (ii > 1) ? valueToDo : val));
10647 emptyHist->SetLineColor(
kBlack);
10649 emptyHist->SetLineColor(
kRed);
10650 }
else if (ii == 3) {
10651 emptyHist->SetLineColor(
kBlue);
10653 emptyHist->Draw(_drawn ?
"same" :
"");
10660 auto rar = get<RooAbsReal>();
10670 rarNode =
find(
".pdf").
get();
10675 if (!nostack && !hasOverlay &&
10685 auto h =
BuildHistogram(
v,
false, hasErrorOpt, 1, 0,
"",
false,
false, 0,
nullptr, nostack,
true );
10696 v = getObject<RooAbsLValue>(
h->GetXaxis()->IsAlphanumeric() ?
h->GetXaxis()->GetTimeFormatOnly()
10697 :
h->GetXaxis()->GetName())
10700 if (
h->GetXaxis()->IsAlphanumeric()) {
10708 if (rar->InheritsFrom(
"RooAbsPdf") && !(rar->InheritsFrom(
"RooRealSumPdf") || rar->InheritsFrom(
"RooAddPdf") ||
10709 rar->InheritsFrom(
"RooSimultaneous"))) {
10712 rar->leafNodeServerList(&s);
10719 for (
auto _p : s) {
10726 ss +=
TString::Format(
"%s=%g", strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName(), _v->getVal());
10727 if (_v->hasError()) {
10738 gPad->SetGrid(0, 0);
10740 gPad->SetGrid(1, 1);
10745 h->SetFillStyle(0);
10794 gROOT->SetEditHistograms(
true);
10796 gROOT->SetEditHistograms(
false);
10810 bool hasError(
false);
10811 for (
int i = 0; i <
h->GetSumw2N(); i++) {
10812 if (
h->GetSumw2()->At(i)) {
10823 if (!hasSame &&
h->GetYaxis()->GetTitleFont() % 10 == 2) {
10824 h->GetYaxis()->SetTitleOffset(1.);
10827 TH1 *errHist =
nullptr;
10837 auto _hist = (errHist) ? errHist :
h;
10838 auto hCopy = (errHist) ?
nullptr :
dynamic_cast<TH1 *
>(
h->Clone());
10842 hCopy->SetDirectory(
nullptr);
10844 _hist->GetListOfFunctions()->Add(node);
10845 _hist->GetListOfFunctions()->Add(
new TExec(
10848 "gROOT->SetEditHistograms(true);auto h = dynamic_cast<TH1*>(gPad->GetPrimitive(\"%s\")); if(h) { double "
10849 "range= h->GetMaximum()-h->GetMinimum(); if(auto n "
10850 "= dynamic_cast<xRooNode*>(h->GetListOfFunctions()->FindObject(\"%s\")); n && "
10851 "n->TestBit(TObject::kNotDeleted) && n->get<RooRealVar>()->getVal() != h->GetBinContent(1)) {"
10852 "h->SetBinContent(1, "
10853 "TString::Format(\"%%.2g\",int(h->GetBinContent(1)/(range*0.01))*range*0.01).Atof());n->SetContent( "
10854 "h->GetBinContent(1) ); for(auto pp : *h->GetListOfFunctions()) if(auto hh = "
10855 "dynamic_cast<TH1*>(pp))hh->SetBinContent(1,h->GetBinContent(1));} if(h->GetBinContent(1)==0.) "
10856 "h->SetBinContent(1,range*0.005); gPad->Modified();gPad->Update(); }",
10857 _hist->GetName(), node->GetName())));
10863 hCopy->SetFillStyle(0);
10864 _hist->GetListOfFunctions()->Add(hCopy,
"TEXT HIST same");
10867 _hist->SetStats(
false);
10874 bool overlayExisted =
false;
10877 if (
auto existing =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(
h->GetName())); existing) {
10882 overlayExisted =
true;
10884 TString oldStyle = (rar && rar->getStringAttribute(
"style")) ? rar->getStringAttribute(
"style") :
"";
10885 h->SetTitle(overlayName);
10914 rar->setStringAttribute(
"style", oldStyle ==
"" ?
nullptr : oldStyle.
Data());
10915 if (
auto _style = _styleNode.get<
TStyle>()) {
10920 h->Draw(dOpt ==
"LF2" ?
"e3" : dOpt);
10943 if (
auto stack =
dynamic_cast<THStack *
>(
h->FindObject(
"stack"))) {
10945 TObjLink *lnk = stack->GetHists()->FirstLink();
10950 if (lnk == stack->GetHists()->FirstLink() &&
h->GetMinimum() > hhMin) {
10952 if (hhMin >= 0 && newMin < 0)
10953 newMin = hhMin * 0.99;
10954 adjustYRange(newMin,
h->GetMaximum());
11226 }
else if (!overlayExisted) {
11237 errHist->
Draw(dOpt + (dOpt.
Contains(
"LF2") ?
"e3same" :
"e2same"));
11238 double ymax = -std::numeric_limits<double>::infinity();
11239 double ymin = std::numeric_limits<double>::infinity();
11240 for (
int i = 1; i <= errHist->
GetNbinsX(); i++) {
11246 adjustYRange(
h->GetMinimum() * 0.9,
h->GetMaximum() * 1.1);
11249 if ((!auxPlotTitle.empty()) && !hasSame) {
11251 double padFrac = 0.3;
11252 auto _tmpPad =
gPad;
11253 gPad->SetBottomMargin(padFrac);
11254 auto ratioPad =
new TPad(
"auxPad",
"aux plot", 0, 0, 1, padFrac);
11255 ratioPad->SetFillColor(_tmpPad->GetFillColor());
11256 ratioPad->SetNumber(1);
11257 ratioPad->SetBottomMargin(ratioPad->GetBottomMargin() / padFrac);
11258 ratioPad->SetTopMargin(0.04);
11259 ratioPad->SetLeftMargin(
gPad->GetLeftMargin());
11260 ratioPad->SetRightMargin(
gPad->GetRightMargin());
11262 TH1 *ratioHist =
dynamic_cast<TH1 *
>((errHist) ? errHist->
Clone(
"auxHist") :
h->
Clone(
"auxHist"));
11263 ratioHist->
Reset();
11273 auxPlotTitle.c_str()));
11276 ratioPad->SetGridy();
11278 for (
int i = 1; i <= ratioHist->
GetNbinsX(); i++) {
11286 double rHeight = 1. / padFrac;
11294#if ROOT_VERSION_CODE < ROOT_VERSION(6, 26, 00)
11303 auto _h =
dynamic_cast<TH1 *
>(ratioHist->
Clone(
"auxHist_clone"));
11305 _h->SetFillColor(0);
11311 TString::Format(
"auto h1 = (TH1*)%p; auto h2 = (TH1*)%p; if(h2->GetXaxis()->GetFirst() != "
11312 "h1->GetXaxis()->GetFirst() || h1->GetXaxis()->GetLast()!=h2->GetXaxis()->GetLast()) "
11313 "{h2->GetXaxis()->SetRange(h1->GetXaxis()->GetFirst(),h1->GetXaxis()->GetLast());if(gPad) "
11314 "{gPad->GetCanvas()->Paint();gPad->GetCanvas()->Update();}}",
11315 (
void *)ratioHist, (
void *)(
h))));
11316 ratioHist->
Draw((errHist ?
"e2" :
""));
11320 }
else if (
auto ratioPad =
dynamic_cast<TPad *
>(
gPad->GetPrimitive(
"auxPad")); hasSame && ratioPad) {
11324 if (
auto hr =
dynamic_cast<TH1 *
>(ratioPad->GetPrimitive(
"auxHist"));
11326 TString histName = hr->GetTitle();
11328 histName = histName(0, histName.
Index(
'|'));
11330 if (
auto hnom =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(histName)); hnom) {
11331 h =
dynamic_cast<TH1 *
>(
h->Clone(
h->GetName()));
11334 for (
int i = 1; i <= hnom->GetNbinsX(); i++) {
11335 double val =
h->GetBinContent(i);
11336 double err =
h->GetBinError(i);
11337 h->SetBinContent(i, std::get<0>(
auxFunctions[hr->GetYaxis()->GetTitle()])(
11338 h->GetBinContent(i), hnom->GetBinContent(i), hnom->GetBinError(i)));
11339 h->SetBinError(i, std::get<0>(
auxFunctions[hr->GetYaxis()->GetTitle()])(
11340 val + err, hnom->GetBinContent(i), hnom->GetBinError(i)) -
11341 h->GetBinContent(i));
11343 auto _tmpPad =
gPad;
11346 if (
auto existing =
dynamic_cast<TH1 *
>(ratioPad->GetPrimitive(
h->GetName())); existing) {
11351 overlayExisted =
true;
11358 double ymax = -std::numeric_limits<double>::infinity();
11359 double ymin = std::numeric_limits<double>::infinity();
11360 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
11361 ymax = std::max(
ymax,
h->GetBinContent(i) +
h->GetBinError(i));
11362 ymin = std::min(
ymin,
h->GetBinContent(i) -
h->GetBinError(i));
11391 if (
auto _pdf = get<RooAbsPdf>();
11392 !hasSame && _pdf &&
coefs(
true).empty()) {
11395 for (
auto &
d : _dsets) {
11396 if (
d->get()->TestBit(1 << 20)) {
11415 if (
auto w = get<RooWorkspace>();
w) {
11417 w->import(*
gROOT->GetListOfColors(),
true);
11420#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
11429 Error(
"SaveAs",
"json format workspaces only in ROOT 6.26 onwards");
11434#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
11438 for (
auto &
c :
w->components()) {
11439 c->_eocache =
nullptr;
11443 if (!
w->writeToFile(
filename, sOpt !=
"update")) {
11447 if (
auto fitDb =
dynamic_cast<TFile *
>(
gROOT->GetListOfFiles()->FindObject(
"fitDatabase"))) {
11452 auto dir =
dest->GetDirectory(source->
GetName());
11457 auto key =
dynamic_cast<TKey *
>(k);
11467 if (dir->FindKey(key->GetName()))
11470 if (strcmp(classname,
"ROOT::Fit::FitConfig") == 0) {
11472 dir->WriteObject(fc, key->GetName());
11475 TObject *obj = key->ReadObj();
11477 dir->WriteTObject(obj, key->
GetName());
11484 CopyDir(fitDb, std::make_unique<TFile>(
filename,
"UPDATE").
get());
11491#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
11493 for (
auto &
c :
w->components()) {
11494 c->setExpensiveObjectCache(
w->expensiveObjectCache());
11502 auto res =
GetBinErrors(bin, bin, fr, nToys, errorsHi, errorsLo);
11504 return std::numeric_limits<double>::quiet_NaN();
11510 std::vector<double> out;
11511 out.reserve(
size());
11512 for (
auto child : *
this) {
11513 out.push_back(
child->GetContent());
11527 auto rho = _fr->correlationMatrix();
11531 auto _pars =
pars();
11536 for (
int m = 0;
m < rho.GetNrows();
m++) {
11537 auto p_m =
dynamic_cast<RooRealVar *
>(_fr->floatParsFinal().at(
m));
11543 auto tmp = _p->getVal();
11544 _p->setVal(p_m->getVal() + p_m->getErrorHi());
11546 _p->setVal(p_m->getVal() + p_m->getErrorLo());
11549 for (
int n = 0;
n < rho.GetNrows();
n++) {
11550 auto p_n =
dynamic_cast<RooRealVar *
>(_fr->floatParsFinal().at(
n));
11556 auto tmp2 = _p2->
getVal();
11557 _p2->setVal(p_n->getVal() + p_n->getErrorHi());
11558 auto nu_n = (p_n == p_m) ? nu_m :
contents();
11559 _p2->setVal(p_n->getVal() + p_n->getErrorLo());
11560 auto nu_n2 = (p_n == p_m) ? nu_m2 :
contents();
11562 for (
int i = 0; i < out.GetNrows(); i++) {
11563 for (
int j = 0; j < out.GetNrows(); j++) {
11564 out(i, j) += 0.25 * (nu_m[i] - nu_m2[i]) * rho(
m,
n) * (nu_n[j] - nu_n2[j]);
11575 double err = std::numeric_limits<double>::quiet_NaN();
11577 std::unique_ptr<RooAbsCollection> _snap;
11582 _pars = _fr->floatParsFinal();
11583 _pars = _fr->constPars();
11587 auto _coefs =
coefs();
11595 p->setNormRange(rangeName);
11596#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 27, 00)
11599 out *=
p->expectedEvents(*_obs.get<
RooArgList>());
11600#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
11602 p->_normSet =
nullptr;
11606 p->setNormRange(
nullptr);
11607 }
else if (
auto p2 =
dynamic_cast<RooAbsReal *
>(
get()); p2) {
11609 auto f = std::shared_ptr<RooAbsReal>(
11610 p2->createIntegral(*std::unique_ptr<RooArgSet>(p2->getObservables(*_obs.get<
RooArgList>())),
11614 out *=
f->getVal();
11617 }
else if (get<RooAbsData>()) {
11620 auto ax = (rangeName) ?
GetXaxis() :
nullptr;
11621 auto rv = (ax) ?
dynamic_cast<RooRealVar *
>(ax->GetParent()) :
nullptr;
11622 auto cv = (ax && !rv) ?
dynamic_cast<RooCategory *
>(ax->GetParent()) :
nullptr;
11624 for (
auto &
v : vals) {
11627 if (rv && !rv->inRange(ax->GetBinCenter(i), rangeName))
11629 if (cv && !cv->isStateInRange(rangeName, ax->GetBinLabel(i)))
11636 out = std::numeric_limits<double>::quiet_NaN();
11639 _pars.RooAbsCollection::operator=(*_snap);
11641 return std::make_pair(out, err);
11654 if (binStart != binEnd || !
fParent) {
11660 std::vector<double> out;
11662 auto _hist =
BuildHistogram(
nullptr,
true,
true, binStart, binEnd, _fr, errorHi, errorLo, nToys);
11666 binEnd = _hist->GetNbinsX();
11667 }
else if (binEnd == binStart && binEnd == -1) {
11671 for (
int bin = binStart; bin <= binEnd; bin++) {
11672 out.push_back(((errorLo && !errorHi) ? (-1.) : 1.) *
11673 _hist->GetBinError(bin));
11798std::string cling::printValue(
const xRooNode *
v)
11801 return "nullptr\n";
11804 size_t left =
v->size();
11805 for (
auto n : *
v) {
11811 out +=
n->GetName();
11812 if (out.length() > 100 && left > 0) {
11818 out = std::string(
Form(
"<%s> %s",
v->get() ?
v->get()->ClassName() :
"nullptr",
v->GetName())) + out;
11823 return "<nullptr>";
11825 return Form(
"<%s> %s",
v->get() ?
v->get()->ClassName() :
"nullptr",
v->GetName());
#define ROOT_VERSION(a, b, c)
#define ROOT_VERSION_CODE
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
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 dest
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 result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t 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.
TObject * clone(const char *newname) const override
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=nullptr)
PdfWrapper(RooAbsReal &f, RooAbsReal *coef, bool expEvMode=false, RooAbsPdf *expPdf=nullptr)
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)
TH1 * BuildHistogram(RooAbsLValue *v=nullptr, bool empty=false, bool errors=false, int binStart=1, int binEnd=0, const xRooNode &fr="", bool errorsHi=false, bool errorsLo=false, int nErrorToys=0, TH1 *templateHist=nullptr, bool nostack=true, bool setInterp=false) const
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)
bool SetData(const TObject &obj, const xRooNode &data="obsData")
xRooNode datasets() const
xRooNode Remove(const xRooNode &child)
xRooNode globs() const
List of global observables of this node.
xRooNode Combine(const xRooNode &rhs)
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.
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
xRooNode styles(TObject *initObject=nullptr, bool autoCreate=true) 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)
double GetBinError(int bin, const xRooNode &fr="", int nToys=0, bool errorsHi=false, bool errorsLo=false) const
RooArgList argList() const
bool SetBinData(int bin, double value, const xRooNode &data="obsData")
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)
xRooNode coefs(bool recurse=false) const
bool IsFolder() const override
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
double GetBinData(int bin, const xRooNode &data="obsData")
bool SetBinError(int bin, double value)
void _Vary_(const char *what)
bool SetContents(const TObject &obj)
std::shared_ptr< TObject > fComp
std::vector< double > contents() const
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
double GetBinContent(int bin) const
xRooNode reduced(const std::string &range="", bool invert=false) const
xRooNode variations() const
std::string GetPath() const
std::vector< double > GetBinErrors(int binStart=1, int binEnd=0, const xRooNode &fr="", int nToys=0, bool errorsHi=false, bool errorsLo=false) 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
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)
xRooNode histo(const xRooNode &vars="x", const xRooNode &fr="", bool content=true, bool errors=true, bool stack=true, bool errorsHi=false, bool errorsLo=false, int nErrorToys=0) const
void Browse(TBrowser *b=nullptr) override
Browse object. May be overridden for another default action.
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())
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
TMatrixDSym covariances(const xRooNode &fr="") 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.
virtual bool isCategory() const
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
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...
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.
virtual value_type getCurrentIndex() const
Return index number of current state.
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.
Storage_t const & get() const
Const access to the underlying stl container.
RooAbsCollection & assignValueOnly(const RooAbsCollection &other, bool forceIfSizeOne=false)
Sets the value of any argument in our set that also appears in the other set.
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
Storage_t::size_type size() const
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={}) const
Create a reduced copy of this dataset.
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
RooArgSet const * getGlobalObservables() const
Returns snapshot of global observables stored in this data.
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.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
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.
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.
Implements a RooAbsBinning in terms of an array of boundary values, posing no constraints on the choi...
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.
TObject * Clone(const char *newName=nullptr) const override
Make a clone of an object using the Streamer facility.
Represents a constant real-valued object.
Container class to hold N-dimensional binned data.
Container class to hold unbinned data.
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
TMatrixDSym conditionalCovarianceMatrix(const RooArgList ¶ms) const
Return a reduced covariance matrix, which is calculated as.
void setCovQual(Int_t val)
const TMatrixDSym & covarianceMatrix() const
Return covariance matrix.
Int_t statusCodeHistory(UInt_t icycle) const
const RooArgList & floatParsInit() const
Return list of floating parameters before fit.
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...
const RooArgList & randomizePars() const
Generate random perturbations of the final parameters using the covariance matrix.
void setCovarianceMatrix(TMatrixDSym &V)
Store externally provided correlation matrix in this RooFitResult ;.
double edm() const
Return estimated distance to minimum.
const RooArgList & constPars() const
Return list of constant parameters.
void SetName(const char *name) override
Change name of RooFitResult object.
const char * statusLabelHistory(UInt_t icycle) const
Int_t covQual() const
Return MINUIT quality code of covariance matrix.
TH2 * correlationHist(const char *name="correlation_matrix") const
Return TH2D of correlation matrix.
const RooArgList & floatParsFinal() const
Return list of floating parameters after fit.
Int_t status() const
Return MINUIT status code.
void setFinalParList(const RooArgList &list)
Fill the list of final values of the floating parameters.
UInt_t numStatusHistory() const
double minNll() const
Return minimized -log(L) value.
Implementation of a probability density function that takes a RooArgList of servers and a C++ express...
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.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
TObject * At(int index) const
Return object stored in sequential position given by index.
virtual void Add(TObject *arg)
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
Implementation of a RooCacheManager<RooAbsCacheElement> that specializes in the storage of cache elem...
Efficient implementation of a product of PDFs of the form.
Represents the product of a given set of RooAbsReal objects.
A RooAbsPdf implementation that represent a projection of a given input p.d.f and the object returned...
RooProjectedPdf()
Default constructor.
Implements a PDF constructed from a sum of functions:
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.
const RooAbsCategoryLValue & indexCat() const
HypoTestResult is a base class for results from hypothesis tests.
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
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 void SetLabelSize(Float_t size=0.04)
Set size of axis 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 Style_t GetFillStyle() const
Return the fill area style.
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 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 IsAlphanumeric() const
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.
virtual const char * GetTimeFormatOnly() const
Return only the time format from the string fTimeFormat.
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.
Longptr_t GetDataMemberOffset(const char *membername) const
return offset for member name.
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 an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Create a dialog for fit function parameter settings.
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)
virtual void SetTitle(const char *title="")
Change the title of the axis.
virtual void ImportAxisAttributes(TAxis *axis)
Internal method to import TAxis attributes to this TGaxis.
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 Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="")
Performs the operation: this = this + c1*f1 if errors are defined (see TH1::Sumw2),...
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.
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 Double_t GetMinimum(Double_t minval=-FLT_MAX) const
Return minimum value larger than minval of bins in the range, unless the value has been overridden by...
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.
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 Clear(Option_t *option="") override
Remove all objects from the list.
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
void Add(TObject *obj) override
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).
Wrapper around a TObject so it can be stored in a TList.
TObject * GetObject() const
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 * DrawClone(Option_t *option="") const
Draw a clone of this object in the current selected pad with: gROOT->SetSelectedPad(c1).
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.
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)
Sets the border size of the TPave box and shadow.
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.
Sequenceable collection abstract base class.
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)
Ssiz_t Last(char c) const
Find last occurrence of a character c.
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
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.
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 WeightVar(const char *name="weight", bool reinterpretAsWeight=false)
RooCmdArg GlobalObservables(Args_t &&... argsOrArgSet)
RooCmdArg ExternalConstraints(const RooArgSet &constraintPdfs)
RooCmdArg Range(const char *rangeName, bool adjustNorm=true)
double gaussian_cdf(double x, double sigma=1, double x0=0)
Alternative name for same function.
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
constexpr Double_t C()
Velocity of light in .
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.
Double_t StdDev(Long64_t n, const T *a, const Double_t *w=nullptr)
#define BEGIN_XROOFIT_NAMESPACE
#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)
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)
std::string formatLegendString(const std::string &s)
auto GETROOTDIR(TGFileBrowser *b)
const xRooNode * runningNode
auto GETLISTTREE(TGFileBrowser *b)
const T & _or_func(const T &a, const T &b)
double new_getPropagatedError(const RooAbsReal &f, const RooFitResult &fr, const RooArgSet &nset={}, RooArgList **pars=nullptr, bool asymHi=false, bool asymLo=false)
TLegend * getLegend(bool create=true, bool doPaint=false)