47#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
49#define protected public
70#define GETWS(a) a->_myws
71#define GETWSSETS(w) w->_namedSets
72#define GETWSSNAPSHOTS(w) w->_snapshots
73#define GETACTBROWSER(b) b->fActBrowser
74#define GETROOTDIR(b) b->fRootDir
75#define GETLISTTREE(b) b->fListTree
76#define GETDMP(o, m) o->m
99 return a->workspace();
107 return w->getSnapshots();
111 return b->GetActBrowser();
115 return b->GetRootDir();
119 return b->GetListTree();
121#define GETDMP(o, m) \
122 *reinterpret_cast<void **>(reinterpret_cast<unsigned char *>(o) + o->Class()->GetDataMemberOffset(#m))
173#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
177#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
206#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
214xRooNode::InteractiveObject *xRooNode::gIntObj =
nullptr;
215std::map<std::string, std::tuple<std::function<
double(
double,
double,
double)>,
bool>> xRooNode::auxFunctions;
216void xRooNode::SetAuxFunction(
const char *title,
const std::function<
double(
double,
double,
double)> &func,
219 auxFunctions[title] = std::make_tuple(func, symmetrize);
238xRooNode::xRooNode(
const char *classname,
const char *
name,
const char *title)
244#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
247 xRooNode(*
w, std::make_shared<xRooNode>()).sterilize();
253 if (
auto a = get<TNamed>();
a)
258xRooNode::xRooNode(
const char *
name,
const std::shared_ptr<TObject> &comp,
const std::shared_ptr<xRooNode> &parent)
259 :
TNamed(
name,
""), fComp(comp), fParent(parent)
269#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
270 fComp = std::make_shared<RooWorkspace>(
"workspace",
name);
275 Error(
"xRooNode",
"Error reading json workspace %s",
name);
280 Error(
"xRooNode",
"json format workspaces available only in ROOT 6.26 onwards");
286 auto _file = std::make_shared<TFile>(
291 auto keys = _file->GetListOfKeys();
293 for (
auto &&k : *keys) {
299#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
300 dynamic_cast<RooWorkspace *>(ws)->_embeddedDataList.Delete();
302 xRooNode(*ws, std::make_shared<xRooNode>()).sterilize();
308 fParent = std::make_shared<xRooNode>(
316 }
else if (pathName.EndsWith(
".root") || pathName.EndsWith(
".json")) {
321 if (
auto _ws = get<RooWorkspace>(); _ws && (!parent || parent->get<
TFile>())) {
328 for (
auto f : *
gROOT->GetListOfFiles()) {
329 if ((
dynamic_cast<TFile *
>(
f)->GetVersion() / 100) > (
gROOT->GetVersionInt() / 100)) {
330 Warning(
"xRooNode",
"There is file open with version %d > current version %d ... results may be wrong",
331 dynamic_cast<TFile *
>(
f)->GetVersion(),
gROOT->GetVersionInt());
337 for (
auto &
d : _ws->allData()) {
338 for (
auto &
a : *
d->get()) {
339 if (
auto v = _ws->var(
a->GetName());
v) {
340 v->setAttribute(
"obs");
341 }
else if (
auto c = _ws->cat(
a->GetName());
c) {
342 c->setAttribute(
"obs");
346 checkCount +=
d->TestBit(1 << 20);
349 if (checkCount == 0 && !_ws->allData().empty())
350 _ws->allData().back()->SetBit(1 << 20,
true);
353 for (
auto s : *_set) {
355 _ws->var(s->GetName())->setStringAttribute(
"nominal",
TString::Format(
"%f",
v->getVal()));
363 if (k ==
"globalObservables" ||
TString(k).
EndsWith(
"_GlobalObservables")) {
366 s->setAttribute(
"obs");
367 s->setAttribute(
"global");
370 const_cast<RooArgSet &
>(
v).setAttribAll(
"obs");
373 s->setAttribute(
"poi");
385 const_cast<RooArgSet &
>(
v).setAttribAll(
"np");
388 if (!_allGlobs.
empty() &&
GETWSSETS(_ws).count(
"globalObservables") == 0) {
389 _ws->defineSet(
"globalObservables", _allGlobs);
394 if (!_ws->allPdfs().empty()) {
395 std::set<RooRealVar *> noErrorPars;
396 std::string parNames;
397 for (
auto &
p :
np()) {
401 if (!
v->hasError()) {
402 noErrorPars.insert(
v);
403 if (!parNames.empty())
408 if (!noErrorPars.empty()) {
411 "Inferring initial errors of %d parameters (give all nuisance parameters an error to avoid this msg)",
412 int(noErrorPars.size()));
415 for (
auto &
a : *this) {
416 if (
a->fFolder ==
"!models") {
418 auto fr =
a->floats().reduced(parNames).fitResult(
"prefit");
420 for (
auto &
v : noErrorPars) {
421 if (
auto arg =
dynamic_cast<RooRealVar *
>(_fr->floatParsFinal().find(
v->GetName()));
422 arg && arg->hasError()) {
423 v->setError(arg->getError());
435 if (strlen(GetTitle()) == 0) {
452 (comp.InheritsFrom(
"RooAbsArg") && dynamic_cast<const
RooAbsArg *>(&comp)->getStringAttribute(
"alias"))
453 ? dynamic_cast<const
RooAbsArg *>(&comp)->getStringAttribute(
"alias")
462 if (
auto a = std::dynamic_pointer_cast<RooAbsArg>(comp);
a &&
a->getStringAttribute(
"alias"))
463 return a->getStringAttribute(
"alias");
465 return comp->GetName();
483 if (
auto o = get<RooAbsReal>(); o) {
484 if (o->isSelectedComp() && !val) {
487 o->setAttribute(
"hidden");
488 }
else if (!o->isSelectedComp() && !val) {
493 o->setAttribute(
"hidden",
false);
496 item->CheckItem(!o->getAttribute(
"hidden"));
497 if (o->isSelectedComp()) {
500 item->SetColor(
kGray);
505 if (
auto o =
get(); o) {
507 o->SetBit(1 << 20, val);
508 if (
auto fr = get<RooFitResult>(); fr) {
509 if (
auto _ws =
ws(); _ws) {
512 if (!_ws->genobj(fr->GetName())) {
514 if (
auto wfr =
dynamic_cast<RooFitResult *
>(_ws->genobj(fr->GetName()))) {
519 _allVars = fr->floatParsFinal();
520 _allVars = fr->constPars();
521 for (
auto &i : fr->floatParsInit()) {
527 for (
auto oo : _ws->allGenericObjects()) {
528 if (
auto ffr =
dynamic_cast<RooFitResult *
>(oo); ffr && ffr != fr) {
529 ffr->ResetBit(1 << 20);
533 _ws->allVars() = fr->floatParsInit();
537 if (
auto first = item->GetParent()->GetFirstChild()) {
539 if (first->HasCheckBox()) {
540 auto _obj =
static_cast<xRooNode *
>(first->GetUserData());
541 first->CheckItem(_obj->get() && _obj->get()->TestBit(1 << 20));
543 }
while ((first = first->GetNextSibling()));
552 static bool blockBrowse =
false;
556 auto b2 =
dynamic_cast<TBrowser *
>(
gROOT->GetListOfBrowsers()->Last());
557 if (!b2 || !b2->GetBrowserImp()) {
564 b2 =
new TBrowser(
"nodeBrowser",
this,
"RooFit Browser");
566 }
else if (strcmp(b2->GetName(),
"nodeBrowser") == 0) {
568 b2->BrowseObject(
this);
580 _b->GotoDir(
nullptr);
591 if (
auto first = item->GetFirstChild()) {
593 if (first->HasCheckBox()) {
594 auto _obj =
static_cast<xRooNode *
>(first->GetUserData());
595 first->CheckItem(_obj->get() &&
596 (_obj->get()->TestBit(1 << 20) ||
599 }
while ((first = first->GetNextSibling()));
610 if (
auto _fr = get<RooFitResult>(); _fr &&
fBrowsables.empty()) {
612 fBrowsables.push_back(std::make_shared<xRooNode>(
".Draw(\"pull\")",
nullptr, *
this));
613 fBrowsables.push_back(std::make_shared<xRooNode>(
".Draw(\"corrcolztext\")",
nullptr, *
this));
614 if (std::unique_ptr<RooAbsCollection>(_fr->floatParsFinal().selectByAttrib(
"poi",
true))->size() == 1) {
615 fBrowsables.push_back(std::make_shared<xRooNode>(
".Draw(\"impact\")",
nullptr, *
this));
621 if (
auto s = get<TStyle>()) {
622 s->SetFillAttributes();
629 Draw(
b->GetDrawOption());
631 }
catch (
const std::exception &
e) {
634 (
gROOT->GetListOfBrowsers()->At(0))
637 "Exception",
e.what(),
642 bool hasFolders =
false;
644 for (
auto &
c : *
this) {
645 if (!
c->fFolder.empty()) {
654 auto _folders =
find(
".folders");
656 _folders = emplace_back(std::make_shared<xRooNode>(
".folders",
nullptr, *
this));
659 for (
auto &
v : *
this) {
660 if (!
v->fFolder.empty() && !_folders->find(
v->fFolder,
false)) {
661 _folders->emplace_back(std::make_shared<xRooNode>(
v->fFolder.c_str(),
nullptr, *
this));
665 for (
auto &
v : *_folders) {
668 _name = _name(1, _name.
Length());
669 b->Add(
v.get(), _name);
673 for (
auto &
v : *
this) {
674 if (hasFolders && !
v->fFolder.empty())
676 if (strcmp(
v->GetName(),
".folders") == 0)
680 if (_fr && ((_fr->status() == 0 && _fr->numStatusHistory() == 0) || (_fr->floatParsFinal().empty()))) {
684 if (
v->get<
RooAbsPdf>() && get<RooSimultaneous>())
688 _name = _name(strlen(
v->get()->ClassName()) + 2, _name.
Length());
696 :
v->get()->GetName());
698 }
else if (
v->get() && !
v->get<
TFile>() && !
TString(
v->GetName()).BeginsWith(
'/'))
700 if (
auto _type =
v->GetNodeType(); strlen(_type)) {
708 for (
size_t i = 0; i < fv->dependents().
size(); i++) {
714 for (
size_t i = 0; i < gv->dependents().
size(); i++) {
721 TString nameSave(
v->TNamed::GetName());
722 TString titleSave(
v->TNamed::GetTitle());
723 if (
auto o =
v->get(); o)
724 v->TNamed::SetNameTitle(o->GetName(), o->ClassName());
725 b->Add(
v.get(), _name, _checked);
726 if (
auto o =
v->get(); o)
727 v->TNamed::SetNameTitle(nameSave, titleSave);
728 if (_checked != -1) {
729 dynamic_cast<TQObject *
>(
b->GetBrowserImp())
730 ->Connect(
"Checked(TObject *, bool)",
ClassName(),
v.get(),
"Checked(TObject *, bool)");
733 if (_fr->status() || _fr->covQual() != 3) {
734 v->GetTreeItem(
b)->SetColor((_fr->numStatusHistory() || _fr->floatParsFinal().empty()) ?
kRed :
kBlue);
735 }
else if (_fr->numStatusHistory() == 0) {
736 v->GetTreeItem(
b)->SetColor(
kGray);
739 if ((
v->fFolder ==
"!np" ||
v->fFolder ==
"!poi")) {
741 v->GetTreeItem(
b)->SetColor(
kGray);
743 v->GetTreeItem(
b)->ClearColor();
747 if (
auto fits = _htr->GetFitInfo()) {
748 for (
int i = 0; i < fits->numEntries(); i++) {
750 if (fits->get(i)->getCatIndex(
"type") != 5 && fits->get(i)->getRealValue(
"status") != 0) {
751 v->GetTreeItem(
b)->SetColor(
kRed);
756 v->GetTreeItem(
b)->SetColor(
kBlue);
783 if (_name ==
".memory")
785 TString nameSave(
v->TNamed::GetName());
786 TString titleSave(
v->TNamed::GetTitle());
787 if (
auto o =
v->get(); o)
788 v->TNamed::SetNameTitle(o->GetName(), o->ClassName());
789 b->Add(
v.get(), _name, -1);
790 if (
auto o =
v->get(); o)
791 v->TNamed::SetNameTitle(nameSave, titleSave);
794 b->SetSelected(
this);
807 auto v = std::make_shared<xRooNode>(
vars());
818 if (strcmp(
b->GetName(),
".vars") == 0)
841 if (
auto v = var();
v)
842 return v->getBinWidth(bin - 1, GetName());
847 if (
auto v = rvar();
v) {
848 return (bin ==
v->getBinning(GetName()).numBins() + 1) ?
v->getBinning(GetName()).binHigh(bin - 2)
849 :
v->getBinning(GetName()).binLow(bin - 1);
855 if (
auto v = rvar();
v)
856 return (bin == 0) ?
v->getBinning(GetName()).binLow(bin) :
v->getBinning(GetName()).binHigh(bin - 1);
862 return (binning() && strlen(binning()->GetTitle())) ? binning()->GetTitle() : GetParent()->GetTitle();
869 dynamic_cast<TNamed *
>(GetParent())->SetTitle(title);
873 void Set(
Int_t nbins,
const double *xbins)
override
876 v->setBinning(
RooBinning(nbins, xbins), GetName());
881 std::vector<double> bins(nbins + 1);
882 for (
int i = 0; i <= nbins; i++)
883 bins.at(i) = xbins[i];
884 return Set(nbins, &bins[0]);
896 Int_t FindFixBin(
double x)
const override {
return (binning()) ? (binning()->binNumber(
x) + 1) :
x; }
907 if (
auto _owned =
find(
".memory"); _owned) {
908 for (
auto &o : *_owned) {
909 if (
name == o->GetName()) {
910 if (
type.empty() || o->get()->InheritsFrom(
type.c_str()))
919 while (!_provider && _parent) {
920 _provider = _parent->fProvider;
921 _parent = _parent->fParent;
924 return _provider->getObject(
name,
type);
927 std::shared_ptr<TObject> out;
928 if (
auto arg =
ws()->arg(
name.c_str()); arg) {
929 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
930 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
935 if (
auto arg =
ws()->
data(
name.c_str()); arg) {
936 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
937 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
942 if (
auto arg =
ws()->genobj(
name.c_str()); arg) {
943 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
944 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
949 if (
auto arg =
ws()->embeddedData(
name.c_str()); arg) {
950 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
951 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
957 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
958 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
973 cat && cat->numTypes() !=
fXAxis->GetNbins()) {
980 if (
auto a = get<RooAbsArg>();
a &&
a->isFundamental())
985 auto o = get<RooAbsReal>();
989 if (
auto xName = o->getStringAttribute(
"xvar"); xName) {
999 (o->dependsOn(*
dynamic_cast<RooAbsArg *
>(_parentX->GetParent())) ||
vars().empty())) {
1001 }
else if (
auto _obs =
obs(); !_obs.empty()) {
1002 for (
auto &
v : _obs) {
1011 }
else if (
auto _pars =
pars(); !_pars.empty()) {
1012 for (
auto &
v : _pars) {
1028 if (o !=
dynamic_cast<TObject *
>(
x)) {
1033 TString binningName = o->getStringAttribute(
"binning");
1034 auto _bnames =
x->getBinningNames();
1035 bool hasBinning =
false;
1036 for (
auto &
b : _bnames) {
1037 if (
b == binningName) {
1045 Warning(
"GetXaxis",
"Binning %s not defined on %s - clearing", binningName.
Data(),
1047 o->setStringAttribute(
"binning",
nullptr);
1051 if (binningName ==
"" && o !=
dynamic_cast<TObject *
>(
x)) {
1053 auto __bnames =
x->getBinningNames();
1054 for (
auto &
b : __bnames) {
1057 if (
b == o->GetName()) {
1058 binningName = o->GetName();
1062 if (binningName ==
"") {
1068 (std::list<double> *)(
nullptr),
1069 o->binBoundaries(*
dynamic_cast<RooAbsRealLValue *
>(
x), -std::numeric_limits<double>::infinity(),
1070 std::numeric_limits<double>::infinity()));
1072 std::vector<double> _bins;
1073 for (
auto &
b : *
bins) {
1074 if (_bins.empty() || std::abs(_bins.back() -
b) > 1
e-5 * _bins.back())
1077 fXAxis = std::make_shared<Axis2>(_bins.size() - 1, &_bins[0]);
1079 if (
auto _v =
dynamic_cast<RooRealVar *
>(
x); _v) {
1080 _v->setBinning(
RooBinning(_bins.size() - 1, &_bins[0], o->GetName()), o->
GetName());
1081 _v->getBinning(o->GetName())
1086 binningName = o->GetName();
1088 }
else if (_parentX) {
1090 binningName = _parentX->GetName();
1097 if (
r->getBinning(binningName).isUniform()) {
1098 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName),
r->getMin(binningName),
r->getMax(binningName));
1100 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName),
r->getBinning(binningName).array());
1103 std::vector<double>
bins = {};
1104 for (
int i = 0; i <=
x->numBins(binningName); i++)
1106 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName), &
bins[0]);
1108 for (
int i = 0; i <
x->numBins(binningName); i++) {
1114 fXAxis->SetName(binningName);
1121 if (
auto o =
get(); o) {
1122 if (o->InheritsFrom(
"RooWorkspace"))
1124 if (o->InheritsFrom(
"RooAbsData"))
1126 if (o->InheritsFrom(
"RooSimultaneous"))
1129 if (o->InheritsFrom(
"RooProdPdf"))
1131 if (o->InheritsFrom(
"RooRealSumPdf") || o->InheritsFrom(
"RooAddPdf"))
1134 if (o->InheritsFrom(
"RooFitResult")) {
1135 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitRooFitResult",
true)) {
1136 gClient->GetMimeTypeList()->AddType(
"xRooFitRooFitResult",
"xRooFitRooFitResult",
"package.xpm",
1137 "package.xpm",
"->Browse()");
1139 return "xRooFitRooFitResult";
1141 if (o->InheritsFrom(
"RooRealVar") || o->InheritsFrom(
"RooCategory")) {
1142 if (get<RooAbsArg>()->getAttribute(
"obs")) {
1143 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitObs",
true)) {
1144 gClient->GetMimeTypeList()->AddType(
"xRooFitObs",
"xRooFitObs",
"x_pic.xpm",
"x_pic.xpm",
"->Browse()");
1146 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitGlobs",
true)) {
1147 gClient->GetMimeTypeList()->AddType(
"xRooFitGlobs",
"xRooFitGlobs",
"z_pic.xpm",
"z_pic.xpm",
1150 return (get<RooAbsArg>()->getAttribute(
"global") ?
"xRooFitGlobs" :
"xRooFitObs");
1154 if (o->InheritsFrom(
"TStyle")) {
1155 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitTStyle",
true)) {
1156 gClient->GetMimeTypeList()->AddType(
"xRooFitTStyle",
"xRooFitTStyle",
"bld_colorselect.xpm",
1157 "bld_colorselect.xpm",
"->Browse()");
1159 return "xRooFitTStyle";
1161 if (o->InheritsFrom(
"RooConstVar")) {
1167 return "TMethodBrowsable-leaf";
1169 if (o->InheritsFrom(
"RooStats::HypoTestInverterResult")) {
1170 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitScanStyle",
true)) {
1171 gClient->GetMimeTypeList()->AddType(
"xRooFitScanStyle",
"xRooFitScanStyle",
"f2_s.xpm",
"f2_s.xpm",
1174 return "xRooFitScanStyle";
1176 if (o->InheritsFrom(
"RooStats::HypoTestResult")) {
1177 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitTestStyle",
true)) {
1178 gClient->GetMimeTypeList()->AddType(
"xRooFitTestStyle",
"xRooFitTestStyle",
"diamond.xpm",
"diamond.xpm",
1181 return "xRooFitTestStyle";
1183 if (o->InheritsFrom(
"RooStats::HistFactory::FlexibleInterpVar"))
1184 return "TBranchElement-folder";
1185 if (o->InheritsFrom(
"RooAbsPdf")) {
1186 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitPDFStyle",
true)) {
1187 gClient->GetMimeTypeList()->AddType(
"xRooFitPDFStyle",
"xRooFitPDFStyle",
"pdf.xpm",
"pdf.xpm",
1190 return "xRooFitPDFStyle";
1194 _ax && (
a->isBinnedDistribution(*
dynamic_cast<RooAbsArg *
>(_ax->GetParent())) ||
1196 std::unique_ptr<std::list<double>>(
a->binBoundaries(
1197 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
1198 std::numeric_limits<double>::infinity()))))) {
1203 return o->ClassName();
1214 if (o->InheritsFrom(
"RooStats::HistFactory::FlexibleInterpVar"))
1216 if (o->InheritsFrom(
"PiecewiseInterpolation"))
1218 if (o->InheritsFrom(
"RooHistFunc"))
1219 return (
dynamic_cast<RooAbsArg *
>(o)->getAttribute(
"density")) ?
"ConstDensityHisto" :
"ConstHisto";
1220 if (o->InheritsFrom(
"RooBinWidthFunction"))
1222 if (o->InheritsFrom(
"ParamHistFunc"))
1224 if (o->InheritsFrom(
"RooRealVar"))
1226 if (o->InheritsFrom(
"RooConstVar"))
1234 xRooNode out(
".coords",
nullptr, *
this);
1236 auto _p = std::shared_ptr<xRooNode>(
const_cast<xRooNode *
>(
this), [](
xRooNode *) {});
1239 if (
auto pos = pName.
Index(
'='); pos != -1) {
1240 if (pos > 0 && pName(pos - 1) ==
'<') {
1243 pName = pName(pos + 1, pName.
Length());
1245 pName = pName(0, pName.
Index(
'<'));
1248 _obs->setVal((high + low) / 2.);
1249 static_cast<RooRealVar *
>(_obs.get())->setRange(
"coordRange", low, high);
1251 "coordRange",
"coordRange");
1253 out.emplace_back(std::make_shared<xRooNode>(_obs->GetName(), _obs, _p));
1258 }
else if (
auto _obs = _p->getObject<
RooAbsArg>(pName(0, pos)); _obs) {
1261 _cat->setLabel(pName(pos + 1, pName.
Length()));
1262 }
else if (
auto _var =
dynamic_cast<RooAbsRealLValue *
>(_obs.get()); _var) {
1266 out.emplace_back(std::make_shared<xRooNode>(_obs->GetName(), _obs, _p));
1268 throw std::runtime_error(
"Unknown observable, could not find");
1280 }
catch (
const std::exception &
e) {
1289 }
catch (
const std::exception &
e) {
1298 if (strcmp(
GetName(),
".poi") == 0) {
1304 throw std::runtime_error(
TString::Format(
"%s is not a poi", toRemove.GetName()));
1306 toRemove.get<
RooAbsArg>()->setAttribute(
"poi",
false);
1309 }
else if (strcmp(
GetName(),
".factors") == 0 || strcmp(
GetName(),
".constraints") == 0 ||
1310 strcmp(
GetName(),
".components") == 0) {
1316 pdf =
p->pdfList().find(
child.GetName());
1319 auto i =
p->pdfList().index(*pdf);
1321#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
1322 const_cast<RooArgList &
>(
p->pdfList()).remove(*pdf);
1323#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
1324 p->_pdfNSetList.erase(
p->_pdfNSetList.begin() + i);
1326 auto nset =
p->_pdfNSetList.At(i);
1327 p->_pdfNSetList.Remove(nset);
1330 if (
p->_extendedIndex == i)
1331 p->_extendedIndex = -1;
1332 else if (
p->_extendedIndex > i)
1333 p->_extendedIndex--;
1345 arg = p2->components().find(
child.GetName());
1349#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
1350 p2->_compRSet.remove(*arg);
1352 const_cast<RooArgList &
>(p2->realComponents()).remove(*arg);
1354 p2->removeServer(*arg,
true);
1359 bool removed =
false;
1362 c->constraints().Remove(toRemove);
1364 }
catch (std::runtime_error &) {
1374 arg = p4->funcList().find(
child.GetName());
1378 auto idx = p4->funcList().index(arg);
1382 const_cast<RooArgList &
>(p4->funcList()).remove(*arg);
1383 p4->removeServer(*arg,
true);
1385 std::vector<RooAbsArg *> _coefs;
1386 for (
size_t ii = 0; ii < const_cast<RooArgList &>(p4->coefList()).size(); ii++) {
1387 if (ii !=
size_t(idx))
1388 _coefs.push_back(
const_cast<RooArgList &
>(p4->coefList()).
at(ii));
1390 const_cast<RooArgList &
>(p4->coefList()).removeAll();
1391 for (
auto &
a : _coefs)
1402 if (
auto w = get<RooWorkspace>();
w) {
1404 auto arg =
w->components().find(
child.GetName());
1411 if (arg->hasClients()) {
1412 throw std::runtime_error(
1413 TString::Format(
"Cannot remove %s from workspace %s, because it has dependencies - first remove from those",
1416 const_cast<RooArgSet &
>(
w->components()).remove(*arg);
1417 Info(
"Remove",
"Deleted %s from workspace %s", out.GetName(),
GetName());
1419 }
else if (get<RooProduct>() || get<RooProdPdf>()) {
1421 }
else if (get<RooRealSumPdf>()) {
1425 throw std::runtime_error(
"Removal not implemented for this type of object");
1434 ~AutoUpdater() {
n.browse(); }
1437 AutoUpdater xxx(*
this);
1440 bool considerType(sOpt ==
"+");
1456 if (strcmp(
GetName(),
".factors") == 0) {
1459 }
else if (strcmp(
GetName(),
".components") == 0) {
1462 }
else if (strcmp(
GetName(),
".variations") == 0) {
1465 }
else if (strcmp(
GetName(),
".constraints") == 0) {
1471 }
else if ((strcmp(
GetName(),
".globs") == 0)) {
1474 out->setAttribute(
"obs");
1475 out->setAttribute(
"global");
1478 throw std::runtime_error(
"Failed to add global observable");
1479 }
else if ((strcmp(
GetName(),
".poi") == 0)) {
1482 out->setAttribute(
"poi");
1485 throw std::runtime_error(
"Failed to add parameter of interest");
1492 }
else if (strcmp(
GetName(),
".datasets()") == 0) {
1497 throw std::runtime_error(
1498 "Datasets can only be created for pdfs or workspaces (except if generated dataset, then must be pdf)");
1501 if (sOpt ==
"asimov" || sOpt ==
"toy") {
1503 auto _fr = std::dynamic_pointer_cast<const RooFitResult>(
fParent->fitResult().fComp);
1504 if (strlen(_fr->GetName()) == 0)
1505 std::const_pointer_cast<RooFitResult>(_fr)->SetName(
TUUID().AsString());
1507 if (strlen(
child.GetName()))
1508 asi.first->SetName(
child.GetName());
1510 _ws->import(*asi.first);
1512 if (_fr->numStatusHistory() == 0) {
1516 }
else if (!_ws->obj(_fr->GetName())) {
1520#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
1521 _ws->saveSnapshot(asi.first->GetName(), *asi.second,
1525 _tmp.
add(*asi.second);
1526 _ws->saveSnapshot(asi.first->GetName(), _tmp,
true);
1532 auto parentObs =
fParent->obs();
1533 auto _obs = parentObs.argList();
1535 std::unique_ptr<RooAbsCollection> _globs(_obs.selectByAttrib(
"global",
true));
1537 _obs.remove(*_globs);
1543 _obs.add(*
dynamic_cast<RooAbsArg *
>(ax->GetParent()));
1546 if (
auto _d = _ws->data(
child.GetName()); _d) {
1549 l.remove(*_d->get(),
true,
true);
1553 throw std::runtime_error(
"Cannot extend dataset with new columns");
1564 if (
auto __d = _ws->data(
child.GetName()))
1565 __d->SetBit(1 << 20, _ws->allData().size() == 1);
1573 auto out = std::shared_ptr<TObject>(_ws->data(
child.GetName()), [](
TObject *) {});
1582 throw std::runtime_error(
"Cannot create dataset");
1587 throw std::runtime_error(
"Cannot add to null object with no parentage");
1589 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(
child), [](
TObject *) {}));
1594 std::rethrow_exception(std::current_exception());
1599 throw std::runtime_error(
"No object");
1603 if (
auto p = get<RooAbsData>();
p) {
1605 bb->Add(
child, opt);
1609 throw std::runtime_error(
"Can only add datasets to a dataset");
1614 auto _globs =
globs();
1615 for (
auto &glob :
child.globs()) {
1616 if (
auto g = _globs.find(glob->GetName()); !
g) {
1618 }
else if (
g->GetContent() != glob->GetContent()) {
1619 Warning(
"Add",
"Global observable %s=%g in dataset mismatches child value %g ... ignoring child",
1620 g->GetName(),
g->GetContent(), glob->GetContent());
1624 if (
auto _dglobs =
p->getGlobalObservables()) {
1627 for (
auto g : _globs)
1630 p->setGlobalObservables(globsToAdd);
1635 if (!
p->get()->contains(*col)) {
1636 ds->addColumn(*col);
1644 throw std::runtime_error(
"Can only add histogram or dataset to data");
1648 throw std::runtime_error(
"Could not find pdf");
1649 auto _ax = _pdf->GetXaxis();
1651 throw std::runtime_error(
"Cannot determine binning to add data");
1660 l.remove(*
p->get(),
true,
true);
1664 throw std::runtime_error(
"Cannot extend dataset with new columns");
1671 for (
auto &o :
obs) {
1673 if (
auto dv =
dynamic_cast<RooRealVar *
>(
p->get()->find(
v->GetName())); dv) {
1674 if (
v->getMin() < dv->getMin())
1675 dv->setMin(
v->getMin());
1676 if (
v->getMax() > dv->getMax())
1677 dv->setMax(
v->getMax());
1680 if (
auto dc =
dynamic_cast<RooCategory *
>(
p->get()->find(
c->GetName())); dc) {
1681 if (!dc->hasLabel(
c->getCurrentLabel())) {
1682 dc->defineType(
c->getCurrentLabel(),
c->getCurrentIndex());
1688 for (
int i = 1; i <= _h->GetNbinsX(); i++) {
1690 if (!_h->GetXaxis()->GetBinLabel(i)) {
1691 throw std::runtime_error(
1692 TString::Format(
"Categorical observable %s requires bin labels", _ax->GetParent()->GetName()));
1693 }
else if (!cat->hasLabel(_h->GetXaxis()->GetBinLabel(i))) {
1694 throw std::runtime_error(
TString::Format(
"Categorical observable %s does not have label %s",
1695 _ax->GetParent()->GetName(), _h->GetXaxis()->GetBinLabel(i)));
1697 cat->setLabel(_h->GetXaxis()->GetBinLabel(i));
1700 dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent())->setVal(_h->GetBinCenter(i));
1702 p->add(
obs, _h->GetBinContent(i));
1708 if (
auto p = get<RooAddPdf>();
p) {
1712 auto _pdf = std::dynamic_pointer_cast<RooAbsPdf>(out);
1714 throw std::runtime_error(
"Something went wrong with pdf acquisition");
1721 if (
auto _boundaries = std::unique_ptr<std::list<double>>(_p->binBoundaries(
1722 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
1723 std::numeric_limits<double>::infinity()));
1724 !_boundaries && _ax->GetNbins() > 0) {
1725#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
1726 Warning(
"Add",
"Adding unbinned pdf %s to binned %s - will wrap with RooBinSamplingPdf(...)",
1728 _p = acquireNew<RooBinSamplingPdf>(
TString::Format(
"%s_binned", _p->GetName()), _p->GetTitle(),
1730 _p->setStringAttribute(
"alias", std::dynamic_pointer_cast<RooAbsArg>(out)->getStringAttribute(
"alias"));
1731 if (!_p->getStringAttribute(
"alias"))
1732 _p->setStringAttribute(
"alias", out->GetName());
1734 throw std::runtime_error(
1735 "unsupported addition of unbinned pdf to binned model - please upgrade to at least ROOT 6.24");
1741 if (!(_pdf->canBeExtended() &&
p->coefList().empty())) {
1745 if (_pdf->canBeExtended()) {
1750 .add(*acquireNew<RooExtendedBinding>(
TString::Format(
"%s_extBind", _pdf->GetName()),
1754 const_cast<RooArgList &
>(
p->coefList()).add(*acquire2<RooAbsArg, RooRealVar>(
"1",
"1", 1));
1757 const_cast<RooArgList &
>(
p->pdfList()).add(*_pdf);
1761 (!
child.get() && getObject<RooAbsReal>(
child.GetName()))) &&
1764 bool tooMany(
false);
1777 }
else if (!tooMany) {
1782 _sumpdf.get<
RooAbsArg>()->setStringAttribute(
"alias",
"samples");
1783 return _sumpdf.Add(
child);
1788 if (
auto p = get<RooRealSumPdf>();
p) {
1789 std::shared_ptr<TObject> out;
1790 auto cc =
child.fComp;
1791 bool isConverted = (cc !=
child.convertForAcquisition(*
this, sOpt));
1794 if (!
child.fComp && getObject<RooAbsReal>(
child.GetName())) {
1795 Info(
"Add",
"Adding existing function %s to %s",
child.GetName(),
p->
GetName());
1796 out = getObject<RooAbsReal>(
child.GetName());
1799 if (!out && !
child.fComp) {
1800 std::shared_ptr<RooAbsArg>
_func;
1811 std::make_unique<TH1D>(
child.GetName(),
child.GetTitle(), _ax->GetNbins(), _ax->binning()->array());
1813 h->GetXaxis()->SetName(
TString::Format(
"%s;%s", _ax->GetParent()->GetName(), _ax->GetName()));
1816 }
else if (_obs.size() == 1) {
1820 TString binningName =
p->getStringAttribute(
"binning");
1821 for (
auto &
b : _bnames) {
1829 auto h = std::make_unique<TH1D>(
child.GetName(),
child.GetTitle(), _x->numBins(binningName),
1830 _x->getBinningPtr(binningName)->array());
1832 h->GetXaxis()->SetName(
1836 Info(
"Add",
"Created densityhisto factor %s (xaxis=%s) for %s",
_func->
GetName(), _obs.at(0)->GetName(),
1839 throw std::runtime_error(
"Unsupported creation of new component in SumPdf for this many obs");
1849 if (
auto _f = std::dynamic_pointer_cast<RooHistFunc>(
1854 if (_f->getAttribute(
"autodensity")) {
1856 for (
int i = 0; i < _f->dataHist().numEntries(); i++) {
1857 auto bin_pars = _f->dataHist().get(i);
1858 _f->dataHist().set(*bin_pars, _f->dataHist().weight() / _f->dataHist().binVolume(*bin_pars));
1860 _f->setAttribute(
"autodensity",
false);
1861 _f->setValueDirty();
1870 Info(
"Add",
"Created %s factor RooHistFunc::%s for %s",
1871 _f->getAttribute(
"density") ?
"densityhisto" :
"histo", _f->GetName(),
p->
GetName());
1875 if (
auto _p = std::dynamic_pointer_cast<RooAbsPdf>(out); _p) {
1879 TString newName(_p->GetName());
1881 newName +=
"_components";
1882 Warning(
"Add",
"converting samples to components");
1887 if (
auto _boundaries = std::unique_ptr<std::list<double>>(_p->binBoundaries(
1888 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
1889 std::numeric_limits<double>::infinity()));
1890 !_boundaries && _ax->GetNbins() > 0) {
1891#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
1892 Warning(
"Add",
"Adding unbinned pdf %s to binned %s - will wrap with RooBinSamplingPdf(...)",
1894 _p = acquireNew<RooBinSamplingPdf>(
TString::Format(
"%s_binned", _p->GetName()), _p->GetTitle(),
1896 _p->setStringAttribute(
"alias", std::dynamic_pointer_cast<RooAbsArg>(out)->getStringAttribute(
"alias"));
1897 if (!_p->getStringAttribute(
"alias"))
1898 _p->setStringAttribute(
"alias", out->GetName());
1900 throw std::runtime_error(
1901 "unsupported addition of unbinned pdf to binned model - please upgrade to at least ROOT 6.24");
1908 if (!_p->canBeExtended()) {
1909 _p = acquireNew<RooExtendPdf>(
TString::Format(
"%s_extended", _p->GetName()), _p->GetTitle(), *_p,
1910 *acquire2<RooAbsReal, RooRealVar>(
"1",
"1", 1));
1913 return *(
Replace(*acquireNew<RooAddPdf>(newName, _p->GetTitle(),
RooArgList(*
p, *_p)))
1917 if (
auto _f = std::dynamic_pointer_cast<RooAbsReal>(out); _f) {
1926 if (
auto _boundaries = std::unique_ptr<std::list<double>>(_f->binBoundaries(
1927 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
1928 std::numeric_limits<double>::infinity()));
1929 !_boundaries && _ax->GetNbins() > 0) {
1930#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
1933 "Adding unbinned function %s to binned %s - will wrap with RooRealSumPdf(RooBinSamplingPdf(...))",
1935 auto sumPdf = acquireNew<RooRealSumPdf>(
TString::Format(
"%s_pdfWrapper", _f->GetName()), _f->GetTitle(),
1936 *_f, *acquire2<RooAbsArg, RooRealVar>(
"1",
"1", 1),
true);
1937 sumPdf->setStringAttribute(
"alias", _f->getStringAttribute(
"alias"));
1938 if (!sumPdf->getStringAttribute(
"alias"))
1939 sumPdf->setStringAttribute(
"alias", out->GetName());
1940 _f = acquireNew<RooBinSamplingPdf>(
TString::Format(
"%s_binned", _f->GetName()), _f->GetTitle(),
1942 _f->setStringAttribute(
"alias", std::dynamic_pointer_cast<RooAbsArg>(out)->getStringAttribute(
"alias"));
1943 if (!_f->getStringAttribute(
"alias"))
1944 _f->setStringAttribute(
"alias", out->GetName());
1946 throw std::runtime_error(
1947 "unsupported addition of unbinned function to binned model - please upgrade to at least ROOT 6.24");
1952 const_cast<RooArgList &
>(
p->coefList()).add(*acquire2<RooAbsArg, RooRealVar>(
"1",
"1", 1));
1955 if (!
p->getStringAttribute(
"binning"))
1956 p->setStringAttribute(
"binning", _f->getStringAttribute(
"binning"));
1959 if (
auto gf =
p->getStringAttribute(
"global_factors"); gf) {
1962 auto fac = getObject<RooAbsReal>(pattern.
Data());
1964 throw std::runtime_error(
TString::Format(
"Could not find global factor %s", pattern.
Data()));
1973 p->setStringAttribute(
"xvar",
nullptr);
1977 }
else if (
auto p2 = get<RooProdPdf>(); p2) {
1984 bool tooMany(
false);
1997 }
else if (!tooMany) {
1998 auto out = this->
operator[](
"components")->Add(child);
2002 (!
child.get() && getObject<RooAbsReal>(
child.GetName()))) &&
2006 bool tooMany(
false);
2015 }
else if (
auto _p2 =
pp->get<
RooAddPdf>(); _p2) {
2017 for (
auto &_pdfa :
pp->components()) {
2031 }
else if (_backup) {
2034 }
else if (!tooMany) {
2035 auto out = this->
operator[](
"samples")->Add(child);
2038 p2->setStringAttribute(
"xvar",
nullptr);
2042 }
else if (
auto s = get<RooSimultaneous>(); s) {
2050 }
else if (
auto w = get<RooWorkspace>();
w) {
2051 child.convertForAcquisition(*
this);
2055 if (!
w->import(*_d)) {
2058 throw std::runtime_error(
TString::Format(
"Could not import dataset %s into workspace %s",
child.GetName(),
w->GetName()).
Data());
2067 if (!
child.empty() ||
child.fFolder ==
"!models") {
2070 std::string catName =
"channelCat";
2071 if (!
child.empty()) {
2072 if (
TString ss =
child.at(0)->GetName(); ss.Contains(
"=")) {
2073 catName = ss(0, ss.Index(
'='));
2076 auto _cat = acquire<RooCategory>(catName.c_str(), catName.c_str());
2077 _cat->setAttribute(
"obs");
2078 auto out = acquireNew<RooSimultaneous>(
child.GetName(),
child.GetTitle(), *_cat);
2079 Info(
"Add",
"Created model RooSimultaneous::%s in workspace %s", out->GetName(),
w->GetName());
2084 if (sOpt ==
"model") {
2086 if (get<RooWorkspace>()) {
2090 }
else if (sOpt ==
"channel") {
2092 if (get<RooSimultaneous>()) {
2094 }
else if (get<RooWorkspace>()) {
2095 std::shared_ptr<TObject> out;
2096 child.convertForAcquisition(*
this);
2099 }
else if (!
child.fComp) {
2100 out = acquireNew<RooProdPdf>(
child.GetName(),
2102 Info(
"Add",
"Created channel RooProdPdf::%s in workspace %s", out->GetName(),
get()->
GetName());
2106 }
else if (sOpt ==
"sample" || sOpt ==
"func") {
2107 if (get<RooProdPdf>()) {
2110 return _mainChild.Add(
child, sOpt ==
"func" ?
"func" :
"");
2112 return (*
this)[
"samples"]->Add(
child, sOpt ==
"func" ?
"func" :
"");
2115 }
else if (sOpt ==
"dataset") {
2116 if (get<RooWorkspace>()) {
2118 return (*this).datasets().Add(
child);
2125 if (get<RooSimultaneous>()) {
2129 }
else if (get<RooProduct>() || get<RooProdPdf>()) {
2175 if (
auto a = get<RooAbsArg>()) {
2176 a->setAttribute(
"hidden", set);
2185 auto a = get<RooAbsArg>();
2187 return a->getAttribute(
"hidden");
2194 if (
get() == rhs.
get()) {
2244 if (
auto s = get<RooSimultaneous>(); s) {
2245 auto chans =
bins();
2246 if (!chans.empty()) {
2252 for (
auto &
c : chans) {
2254 cName = cName(cName.
Index(
'=') + 1, cName.
Length());
2257 c->shallowCopy(
name +
"_" +
c->get()->GetName(), std::shared_ptr<xRooNode>(&out, [](
xRooNode *) {}));
2258 pdf->addPdf(*
dynamic_cast<RooAbsPdf *
>(c_copy.get()), cName);
2263 }
else if (
auto p =
dynamic_cast<RooProdPdf *
>(o);
p) {
2265 std::shared_ptr<RooProdPdf> pdf =
2266 std::dynamic_pointer_cast<RooProdPdf>(out.acquire(std::shared_ptr<TObject>(
p->
Clone()),
false,
2271 std::dynamic_pointer_cast<RooAbsArg>(out.acquire(std::shared_ptr<TObject>(
main->Clone()),
false,
true));
2272 std::cout << newMain <<
" " << newMain->GetName() << std::endl;
2287 static std::unique_ptr<cout_redirect> capture;
2288 std::string captureStr;
2289 bool doCapture =
false;
2290 if (!capture &&
gROOT->FromPopUp()) {
2291 capture = std::make_unique<cout_redirect>(captureStr);
2314 if (
get() &&
get() !=
this) {
2316 if (_more || (get<RooAbsArg>() && get<RooAbsArg>()->isFundamental()) || get<RooConstVar>() ||
2317 get<RooAbsData>() || get<RooProduct>() || get<RooFitResult>()) {
2319 auto _snap = std::unique_ptr<RooAbsCollection>(_deps.snapshot());
2322 if (
auto _fr = get<RooFitResult>(); _fr &&
dynamic_cast<RooStringVar *
>(_fr->constPars().
find(
".log"))) {
2323 std::cout <<
"Minimization Logs:" << std::endl;
2324 std::cout << dynamic_cast<RooStringVar *>(_fr->constPars().find(
".log"))->getVal() << std::endl;
2326 _deps.assignValueOnly(*_snap);
2336 if (
auto fv = get<RooFormulaVar>()) {
2338 for (
size_t i = 0; i < fv->dependents().
size(); i++) {
2342 }
else if (
auto gv = get<RooGenericPdf>()) {
2344 for (
size_t i = 0; i < gv->dependents().
size(); i++) {
2352 }
else if (!
get()) {
2353 std::cout << std::endl;
2357 std::vector<std::string> folderNames;
2358 for (
auto &k : *
this) {
2359 if (std::find(folderNames.begin(), folderNames.end(), k->fFolder) == folderNames.end()) {
2360 folderNames.push_back(k->fFolder);
2363 for (
auto &
f : folderNames) {
2367 for (
int j = 0; j <
indent; j++)
2369 std::cout <<
f << std::endl;
2372 for (
auto &k : *
this) {
2373 if (k->fFolder !=
f) {
2377 for (
int j = 0; j < iindent; j++)
2379 std::cout << i++ <<
") " << k->GetName() <<
" : ";
2383 auto _deps = k->coords(
false).argList();
2384 auto _snap = std::unique_ptr<RooAbsCollection>(_deps.snapshot());
2386 k->get()->Print(sOpt);
2387 _deps.assignValueOnly(*_snap);
2390 if (
auto _type = k->GetNodeType(); strlen(_type)) {
2398 for (
size_t j = 0; j < fv->dependents().
size(); j++) {
2404 for (
size_t j = 0; j < gv->dependents().
size(); j++) {
2409 std::cout << k->get()->ClassName() <<
"::" << k->get()->GetName() << _suffix.
Data() << std::endl;
2412 k->Print(sOpt +
TString::Format(
"depth=%dindent=%d", depth - 1, iindent + 1));
2415 std::cout <<
" NULL " << std::endl;
2421 size_t lastBreak = 0;
2422 std::string captureStrWithBreaks;
2423 for (
size_t i = 0; i < captureStr.size(); i++) {
2424 captureStrWithBreaks += captureStr[i];
2425 if (captureStr[i] ==
'\n') {
2428 if (i - lastBreak > 150) {
2429 captureStrWithBreaks +=
'\n';
2434 (
gROOT->GetListOfBrowsers()->At(0))
2438 captureStrWithBreaks.c_str());
2446 if (
auto v = get<RooRealVar>();
v) {
2449 double mean = std::numeric_limits<double>::quiet_NaN();
2450 double sigma = mean;
2459 mean = std::numeric_limits<double>::quiet_NaN();
2462 constrType =
"normal";
2463 }
else if (constrType ==
"normal") {
2466 }
else if (constrType ==
"gaussian") {
2470 throw std::runtime_error(
"No error on parameter for gaussian constraint");
2473 constrType =
"normal";
2474 }
else if (constrType ==
"poisson") {
2476 throw std::runtime_error(
"No error on parameter for poisson constraint");
2478 sigma = pow(
v->getVal() /
v->getError(), 2);
2481 if (constrType ==
"poisson") {
2483 double tau_val =
sigma;
2484 auto globs = acquire<RooRealVar>(
Form(
"globs_%s",
v->GetName()),
Form(
"globs_%s",
v->GetName()),
2485 v->getVal() * tau_val, (
v->getVal() - 5 *
v->getError()) * tau_val,
2486 (
v->getVal() + 5 *
v->getError()) * tau_val);
2487 globs->setConstant();
2488 globs->setAttribute(
"obs");
2489 globs->setAttribute(
"global");
2491 auto tau = acquireNew<RooConstVar>(
TString::Format(
"tau_%s",
v->GetName()),
"", tau_val);
2492 auto constr = acquireNew<RooPoisson>(
2501 v->setError(mean / sqrt(tau_val));
2502 Info(
"Constrain",
"Added poisson constraint pdf RooPoisson::%s (tau=%g) for %s", out->GetName(), tau_val,
2505 }
else if (constrType ==
"normal") {
2507 auto globs = acquire<RooRealVar>(
Form(
"globs_%s",
v->GetName()),
Form(
"globs_%s",
v->GetName()), mean,
2509 globs->setAttribute(
"obs");
2510 globs->setAttribute(
"global");
2511 globs->setConstant();
2514 auto constr = acquireNew<RooGaussian>(
2520 Info(
"Constrain",
"Added gaussian constraint pdf RooGaussian::%s (mean=%g,sigma=%g) for %s", out->GetName(),
2527 auto _me = get<RooAbsArg>();
2529 throw std::runtime_error(
"Cannot constrain non arg");
2532 if (!
p->dependsOn(*_me)) {
2533 throw std::runtime_error(
"Constraint does not depend on constrainee");
2542 throw std::runtime_error(
"Nowhere to put constraint");
2548 for (
auto &
c : *
x) {
2554 return x->Multiply(
child);
2556 return x->Add(
child,
"+");
2569 ~AutoUpdater() {
n.browse(); }
2572 AutoUpdater xxx(*
this);
2579 auto o = std::dynamic_pointer_cast<RooAbsReal>(
acquire(
child.fComp));
2602 ?
fParent->mainChild()->GetName()
2607 binFactors =
fParent->factors().find(
"binFactors");
2609 throw std::runtime_error(
2616 for (
auto &
b : binFactors->bins()) {
2617 auto p = acquireNew<RooProduct>(
TString::Format(
"%s_bin%d", binFactors->get()->GetName(), i),
2619 p->setStringAttribute(
"alias",
TString::Format(
"%s=%g", binFactors->GetXaxis()->GetParent()->GetName(),
2620 binFactors->GetXaxis()->GetBinCenter(i)));
2627 auto _bin = binFactors->bins().at(
fBinNumber - 1);
2628 if (
auto phf = binFactors->get<
ParamHistFunc>(); phf && _bin) {
2629#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2634 if (strcmp(_bin->GetName(),
"1") == 0) {
2636 for (std::size_t i = 0; i < pSet.
size(); i++) {
2638 all.
add(*pSet.
at(i));
2646 _bin->fBinNumber = -1;
2647 return _bin->Multiply(
child, opt);
2675 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(
child), [](
TObject *) {}));
2680 std::rethrow_exception(std::current_exception());
2688 if (
auto o = getObject<RooAbsReal>(
child.GetName())) {
2692 Info(
"Multiply",
"Scaled %s by existing factor %s::%s",
2696 }
else if (sOpt ==
"norm") {
2703 Info(
"Multiply",
"Scaled %s by new norm factor %s",
2708 throw std::runtime_error(
TString::Format(
"Failed to create new normFactor %s",
child.GetName()));
2712 Info(
"Multiply",
"Scaled %s by new norm factor %s",
2716 }
else if (sOpt ==
"shape" || sOpt ==
"histo" || sOpt ==
"blankshape") {
2721 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
2722 h->SetBinContent(i, 1);
2727 h->SetTitle(
child.GetTitle());
2732 Info(
"Multiply",
"Scaled %s by new %s factor %s",
2737 }
else if (sOpt ==
"overall") {
2738 auto out =
Multiply(acquireNew<RooStats::HistFactory::FlexibleInterpVar>(
2739 child.GetName(),
child.GetTitle(),
RooArgList(), 1, std::vector<double>(), std::vector<double>()));
2741 Info(
"Multiply",
"Scaled %s by new overall factor %s",
2745 }
else if (sOpt ==
"func" &&
ws()) {
2750 Info(
"Multiply",
"Scaled %s by new func factor %s",
2757 if (
auto h =
child.get<
TH1>();
h && strlen(
h->GetOption()) == 0 && strlen(opt) > 0) {
2761 if (
auto w = get<RooWorkspace>();
w) {
2763 std::shared_ptr<TObject> out;
2764 child.convertForAcquisition(*
this);
2770 if (strcmp(
GetName(),
".coef") == 0) {
2773 for (
size_t i = 0; i <
p->pdfList().size(); i++) {
2775 auto coefs =
p->coefList().at(i);
2784 for (
size_t j = 0; j <
p->coefList().size(); j++) {
2786 oldCoefs.
add(*newCoefs);
2788 oldCoefs.add(*
p->coefList().at(j));
2791 const_cast<RooArgList &
>(
p->coefList()).removeAll();
2792 const_cast<RooArgList &
>(
p->coefList()).add(oldCoefs);
2799 throw std::runtime_error(
"this coefs case is not supported");
2802 if (
auto p = get<RooProduct>();
p) {
2803 std::shared_ptr<TObject> out;
2804 auto cc =
child.fComp;
2805 bool isConverted = (
child.convertForAcquisition(*
this) != cc);
2810 if (
auto _f = std::dynamic_pointer_cast<RooHistFunc>(
2812 _f && _f->getAttribute(
"autodensity")) {
2814 bool hasDensity =
false;
2822 if (_f->getAttribute(
"density")) {
2825 for (
int i = 0; i < _f->dataHist().numEntries(); i++) {
2826 auto bin_pars = _f->dataHist().get(i);
2827 _f->dataHist().set(*bin_pars, _f->dataHist().weight() / _f->dataHist().binVolume(*bin_pars));
2829 _f->setValueDirty();
2836 _f->setAttribute(
"autodensity",
false);
2840 Info(
"Multiply",
"Created %s factor %s in %s",
2844 Info(
"Multiply",
"Created shape factor %s in %s",
child->GetName(),
p->
GetName());
2847 if (
auto _f = std::dynamic_pointer_cast<RooAbsReal>(out); _f) {
2848#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2849 p->_compRSet.add(*_f);
2851 const_cast<RooArgList &
>(
p->realComponents()).add(*_f);
2857 for (
auto &_par : _out.
pars()) {
2860 for (
auto &_constr : _par->constraints()) {
2861 if (strcmp(s, _constr->get()->GetName()) == 0) {
2868 Info(
"Multiply",
"Pulling in %s boundConstraint: %s", _par->GetName(), s);
2869 auto _pdf = getObject<RooAbsPdf>(s);
2871 throw std::runtime_error(
"Couldn't find boundConstraint");
2873 _par->Constrain(_pdf);
2880 }
else if (
auto p2 = get<RooProdPdf>(); p2) {
2882 std::shared_ptr<TObject> out;
2883 child.convertForAcquisition(*
this);
2892 std::shared_ptr<RooAbsPdf> _pdf;
2893 if (!
child.get() && strcmp(
child.GetName(),
"components") == 0) {
2894 auto _sumpdf = acquireNew<RooAddPdf>(
Form(
"%s_%s", p2->GetName(),
child.GetName()),
2895 (strlen(
child.GetTitle()) && strcmp(
child.GetTitle(),
child.GetName()))
2901 auto _sumpdf = acquireNew<RooRealSumPdf>(
2902 Form(
"%s_%s", p2->GetName(),
child.GetName()),
2906 _sumpdf->setFloor(
true);
2909 _pdf->setStringAttribute(
"alias",
child.GetName());
2911 _pdf->setStringAttribute(
"xvar", p2->getStringAttribute(
"xvar"));
2912 _pdf->setStringAttribute(
"binning", p2->getStringAttribute(
"binning"));
2914 Info(
"Multiply",
"Created %s::%s in channel %s", _pdf->ClassName(), _pdf->GetName(), p2->GetName());
2919 if (
auto _pdf = std::dynamic_pointer_cast<RooAbsPdf>(out); _pdf) {
2920#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2921 const_cast<RooArgList &
>(p2->pdfList()).add(*_pdf);
2922#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
2923 p2->_pdfNSetList.emplace_back(std::make_unique<RooArgSet>(
"nset"));
2927 if (!p2->canBeExtended() && _pdf->canBeExtended()) {
2928 p2->_extendedIndex = p2->_pdfList.size() - 1;
2937 }
else if (
auto p3 = get<RooRealSumPdf>(); p3) {
2939 std::shared_ptr<TObject> out;
2940 child.convertForAcquisition(*
this);
2946 TString s = p3->getStringAttribute(
"global_factors");
2949 s += out->GetName();
2950 p3->setStringAttribute(
"global_factors", s);
2953 "Flagged %s as a global factor in channel %s (is applied to all current and future samples in the channel)",
2954 out->GetName(), p3->GetName());
2965 std::set<RooAbsArg *> cl;
2966 for (
auto &arg : p5->clients()) {
2972 if (cl.size() > 1) {
2977 Warning(
"Multiply",
"Scaling %s that has multiple clients", p5->GetName());
2983 for (
auto &
a : p5->attributes())
2984 new_p->setAttribute(
a.c_str());
2985 for (
auto &
a : p5->stringAttributes())
2986 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
2987 if (!new_p->getStringAttribute(
"alias"))
2988 new_p->setStringAttribute(
"alias", p5->GetName());
2990 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
2991 for (
auto arg : cl) {
2992 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
3000 if (!
child.get() && strlen(opt) == 0)
3003 throw std::runtime_error(
3005 (!
child.get() && strlen(opt) == 0) ?
" (forgot to specify factor type?)" :
""));
3011 auto p5 = get<RooAbsArg>();
3013 throw std::runtime_error(
"Only replacement of RooAbsArg is supported");
3022 new_p = std::dynamic_pointer_cast<RooAbsArg>(out).get();
3024 std::set<RooAbsArg *> cl;
3025 for (
auto &arg : p5->clients()) {
3033 if (cl.size() > 1) {
3038 std::stringstream clientList;
3040 clientList <<
c->GetName() <<
",";
3041 Warning(
"Replace",
"Replacing %s in all clients: %s", p5->GetName(), clientList.str().c_str());
3045 new_p->setAttribute(
Form(
"ORIGNAME:%s", p5->GetName()));
3046 for (
auto arg : cl) {
3051 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
3062 ~AutoUpdater() {
n.browse(); }
3065 AutoUpdater xxx(*
this);
3070 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(
child), [](
TObject *) {}));
3075 std::rethrow_exception(std::current_exception());
3087 std::string label =
child.GetName();
3088 if (
auto pos = label.find(
'='); pos != std::string::npos)
3089 label = label.substr(pos + 1);
3090 if (!s->indexCat().hasLabel(label)) {
3093 std::shared_ptr<TObject> out;
3094 child.convertForAcquisition(*
this);
3097 }
else if (!
child.fComp) {
3098 out = acquireNew<RooProdPdf>(
TString::Format(
"%s_%s", s->GetName(), label.c_str()),
3100 Info(
"Vary",
"Created channel RooProdPdf::%s in model %s", out->GetName(), s->GetName());
3103 if (
auto _pdf = std::dynamic_pointer_cast<RooAbsPdf>(out); _pdf) {
3104 s->addPdf(*_pdf, label.c_str());
3113 }
else if (
auto p = get<RooStats::HistFactory::FlexibleInterpVar>();
p) {
3116 child.convertForAcquisition(*
this);
3118 if (!_c &&
child.get()) {
3119 throw std::runtime_error(
"Only pure consts can be set as variations of a flexible interpvar");
3121#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3122 double value = (_c ? _c->getVal() :
p->_nominal);
3123 double nomVal =
p->_nominal;
3125 double value = (_c ? _c->getVal() :
p->nominal());
3126 double nomVal =
p->nominal();
3130 if (cName ==
"nominal") {
3135 throw std::runtime_error(
"unsupported variation form");
3137 std::string parName = cName(0, cName.
Index(
'='));
3139 if (parVal != 1 && parVal != -1) {
3140 throw std::runtime_error(
"unsupported variation magnitude");
3142 bool high = parVal > 0;
3144 if (parName.empty()) {
3153 if (!
p->findServer(*
v)) {
3154#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3155 p->_paramList.add(*
v);
3156 p->_low.push_back(0);
3157 p->_high.push_back(0);
3158 p->_interpCode.push_back(4);
3161 const_cast<std::vector<double> &
>(
p->low()).push_back(0);
3162 const_cast<std::vector<double> &
>(
p->high()).push_back(0);
3163 const_cast<std::vector<int> &
>(
p->interpolationCodes()).push_back(4);
3165 v->setAttribute(
Form(
"SYMMETRIC%s_%s", high ?
"+" :
"-",
GetName()));
3170 if (
v->getAttribute(
Form(
"SYMMETRIC+_%s",
GetName()))) {
3171 p->setLow(*
v, 2 * nomVal -
value);
3173 v->setAttribute(
Form(
"SYMMETRIC-_%s",
GetName()),
false);
3176 if (
v->getAttribute(
Form(
"SYMMETRIC-_%s",
GetName()))) {
3177 p->setHigh(*
v, 2 * nomVal -
value);
3179 v->setAttribute(
Form(
"SYMMETRIC+_%s",
GetName()),
false);
3187 }
else if (
auto p2 = get<PiecewiseInterpolation>(); p2) {
3190 throw std::runtime_error(
"unsupported variation form");
3194 if (parVal != 1 && parVal != -1) {
3195 throw std::runtime_error(
"unsupported variation magnitude");
3197#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3200 throw std::runtime_error(
3201 TString::Format(
"Interpolating %s instead of RooHistFunc", p2->_nominal.absArg()->ClassName()));
3206 throw std::runtime_error(
3207 TString::Format(
"Interpolating %s instead of RooHistFunc", p2->nominalHist()->ClassName()));
3213 for (
auto par : p2->paramList()) {
3214 if (parName == par->GetName()) {
3215 f =
dynamic_cast<RooHistFunc *
>((parVal > 0 ? p2->highList() : p2->lowList()).
at(i));
3216 otherf =
dynamic_cast<RooHistFunc *
>((parVal > 0 ? p2->lowList() : p2->highList()).
at(i));
3224 auto v = acquire<RooRealVar>(parName, parName, -5, 5);
3228 std::shared_ptr<RooHistFunc> up(
3230 std::shared_ptr<RooHistFunc> down(
3233#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3234 std::unique_ptr<RooDataHist>
h1(
3235 static_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", up->GetName()))));
3236 std::unique_ptr<RooDataHist> h2(
3237 static_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", down->GetName()))));
3238 up->_dataHist =
dynamic_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", up->GetName())));
3239 down->_dataHist =
dynamic_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", down->GetName())));
3242 down->cloneAndOwnDataHist(
TString::Format(
"hist_%s", down->GetName()));
3244 auto ups = std::dynamic_pointer_cast<RooHistFunc>(
acquire(up,
false,
true));
3245 auto downs = std::dynamic_pointer_cast<RooHistFunc>(
acquire(down,
false,
true));
3246#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3247 p2->_highSet.add(*ups.get());
3248 p2->_lowSet.add(*downs.get());
3249 p2->_interpCode.push_back(4);
3250 p2->_paramSet.add(*
v);
3252 const_cast<RooArgList &
>(p2->highList()).add(*ups);
3253 const_cast<RooArgList &
>(p2->lowList()).add(*downs);
3254 const_cast<std::vector<int> &
>(p2->interpolationCodes()).push_back(4);
3255 const_cast<RooArgList &
>(p2->paramList()).add(*
v);
3257 p2->setValueDirty();
3258 f = ((parVal > 0) ? ups : downs).
get();
3259 otherf = ((parVal > 0) ? downs : ups).
get();
3261 f->setStringAttribute(
"symmetrizes", otherf->
GetName());
3262 f->setStringAttribute(
"symmetrize_nominal", nomf->
GetName());
3281 }
else if (
auto p3 = get<RooConstVar>(); p3) {
3284 if (p3->getAttribute(
"RooRealConstant_Factory_Object")) {
3285 throw std::runtime_error(
"Cannot vary pure constants");
3291 std::set<RooAbsArg *> cl;
3292 for (
auto &arg : p3->clients()) {
3297 if (cl.size() > 1) {
3302 Warning(
"Vary",
"Varying %s that has multiple clients", p3->GetName());
3305 p3->setStringAttribute(
"origName", p3->GetName());
3307 p3->SetName(
Form(
"%s_nominal", p3->GetName()));
3309 auto new_p = acquireNew<RooStats::HistFactory::FlexibleInterpVar>(
n, p3->GetTitle(),
RooArgList(), p3->getVal(),
3310 std::vector<double>(), std::vector<double>());
3313 for (
auto &
a : p3->attributes())
3314 new_p->setAttribute(
a.c_str());
3315 for (
auto &
a : p3->stringAttributes())
3316 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
3319 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
3320 for (
auto arg : cl) {
3321 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
3327 }
else if (
auto p4 = get<RooAbsReal>(); p4) {
3331 std::set<RooAbsArg *> cl;
3332 for (
auto &arg : p4->clients()) {
3337 if (cl.size() > 1) {
3342 Warning(
"Vary",
"Varying %s that has multiple clients", p4->GetName());
3345 p4->setStringAttribute(
"origName", p4->GetName());
3347 p4->SetName(
Form(
"%s_nominal", p4->GetName()));
3352 for (
auto &
a : p4->attributes())
3353 new_p->setAttribute(
a.c_str());
3354 for (
auto &
a : p4->stringAttributes())
3355 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
3358 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
3359 for (
auto arg : cl) {
3360 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
3401 if (
auto a = get<RooAbsArg>();
a && strcmp(
a->GetName(),
GetName()) && !
a->getStringAttribute(
"alias")) {
3402 a->setStringAttribute(
"alias",
GetName());
3405 throw std::runtime_error(
"Cannot determine type");
3410 if (
auto h =
dynamic_cast<const TH1 *
>(&o);
h) {
3421 bool _isData = get<RooAbsData>();
3427 throw std::runtime_error(
"no xaxis");
3428 auto _v =
dynamic_cast<RooRealVar *
>(ax->GetParent());
3431 _b.
b =
dynamic_cast<RooAbsBinning *
>(_v->getBinningPtr(
nullptr)->Clone());
3432 if (
h->GetXaxis()->IsVariableBinSize()) {
3433 _v->setBinning(
RooBinning(
h->GetNbinsX(),
h->GetXaxis()->GetXbins()->GetArray()));
3435 _v->setBinning(
RooUniformBinning(
h->GetXaxis()->GetXmin(),
h->GetXaxis()->GetXmax(),
h->GetNbinsX()));
3441 for (
int bin = 1; bin <=
h->GetNbinsX(); bin++) {
3449 if (!_isData &&
h->GetSumw2N() && !
SetBinError(bin,
h->GetBinError(bin)))
3450 throw std::runtime_error(
"Failed setting stat error");
3454 }
else if (
auto _c =
dynamic_cast<const RooConstVar *
>(&o); _c) {
3456 if (
auto a = get<RooAbsArg>();
3457 (
a &&
a->isFundamental()) || get<RooConstVar>() || get<RooStats::HistFactory::FlexibleInterpVar>()) {
3460 }
else if (get<RooAbsData>()) {
3466 throw std::runtime_error(
"Assignment failed");
3493 auto _pars =
pars();
3497 auto idx = pattern.
Index(
'=');
3500 (idx == -1) ? std::numeric_limits<double>::quiet_NaN() :
TString(pattern(idx + 1, pattern.
Length())).
Atof();
3501 for (
auto p : _pars.argList()) {
3503 p->setAttribute(
"Constant",
true);
3504 if (!std::isnan(val)) {
3513 for (
auto &
d : _dsets) {
3514 if (
d->get()->TestBit(1 << 20)) {
3515 dsetName =
d->get()->GetName();
3519 auto _nll =
nll(dsetName.
Data());
3520 _nll.fitConfigOptions()->SetValue(
"LogSize", 65536);
3521 _nll.fitConfig()->MinimizerOptions().SetPrintLevel(0);
3522 auto fr = _nll.minimize();
3525 throw std::runtime_error(
"Fit Failed");
3528 for (
unsigned int i = 0; i < fr->numStatusHistory(); i++) {
3529 statusCodes +=
TString::Format(
"\n%s = %d", fr->statusLabelHistory(i), fr->statusCodeHistory(i));
3532 (
gROOT->GetListOfBrowsers()->At(0))
3535 if (fr->status() != 0) {
3537 TString::Format(
"%s\nData = %s\nFit Status Code = %d\nCov Quality = %d\n-------------%s",
3538 fr->GetName(), dsetName.
Data(), fr->status(), fr->covQual(), statusCodes.
Data()),
3540 }
else if (fr->covQual() != 3 && _nll.fitConfig()->ParabErrors()) {
3541 new TGMsgBox(
gClient->GetRoot(),
w,
"Fit Finished with Bad Covariance Quality",
3542 TString::Format(
"%s\nData = %s\nFit Status Code = %d\nCov Quality = %d\n-------------%s",
3543 fr->GetName(), dsetName.
Data(), fr->status(), fr->covQual(), statusCodes.
Data()),
3547 TString::Format(
"%s\nData = %s\nFit Status Code = %d\nCov Quality = %d\n-------------%s",
3548 fr->GetName(), dsetName.
Data(), fr->status(), fr->covQual(), statusCodes.
Data()));
3550 }
catch (
const std::exception &
e) {
3553 (
gROOT->GetListOfBrowsers()->At(0))
3563 datasets().
Add(datasetName, expected ?
"asimov" :
"toy");
3564 }
catch (
const std::exception &
e) {
3567 (
gROOT->GetListOfBrowsers()->At(0))
3570 "Exception",
e.what(),
3576 double highX ,
const char *constParValues)
3585 for (
auto &
d : _dsets) {
3586 if (
d->get()->TestBit(1 << 20)) {
3587 dsetName =
d->get()->GetName();
3591 auto _pars =
pars();
3592 std::unique_ptr<RooAbsCollection> snap(_pars.argList().snapshot());
3595 auto idx = pattern.
Index(
'=');
3598 (idx == -1) ? std::numeric_limits<double>::quiet_NaN() :
TString(pattern(idx + 1, pattern.
Length())).
Atof();
3599 for (
auto par : _pars.argList()) {
3601 par->setAttribute(
"Constant",
true);
3602 if (!std::isnan(val)) {
3615 hs.SetTitle(sWhat +
" scan" + ((dsetName !=
"") ?
TString::Format(
" [data=%s]", dsetName.
Data()) :
""));
3616 int scanStatus = hs.scan(sWhat +
" visualize", nBinsX, lowX, highX);
3617 if (scanStatus != 0) {
3620 (
gROOT->GetListOfBrowsers()->At(0))
3623 "Scan Finished with Bad Status Code",
3624 TString::Format(
"%s\nData = %s\nScan Status Code = %d", hs.GetName(), dsetName.
Data(), scanStatus),
3629 if (
auto res = hs.result())
3633 _pars.argList() = *snap;
3635 }
catch (
const std::exception &
e) {
3638 (
gROOT->GetListOfBrowsers()->At(0))
3649 }
catch (
const std::exception &
e) {
3659 throw std::runtime_error(
"Failed to SetContent");
3660 }
catch (
const std::exception &
e) {
3674 std::shared_ptr<TH1D>
h;
3675 auto _b =
dynamic_cast<Axis2 *
>(ax)->binning();
3678 if (_b->isUniform()) {
3683 h->SetDirectory(
nullptr);
3685 h->GetXaxis()->SetName(
TString::Format(
"%s;%s", ax->GetParent()->GetName(), ax->GetName()));
3693 if (get<RooProduct>()) {
3697 if (get<RooAbsData>()) {
3699 auto _ax = (bin) ?
GetXaxis() :
nullptr;
3701 throw std::runtime_error(
"Cannot determine binning to fill data");
3703 if (_ax && _ax->GetNbins() < bin) {
3704 throw std::out_of_range(
TString::Format(
"%s range %s only has %d bins", _ax->GetParent()->GetName(),
3705 _ax->GetName(), _ax->GetNbins()));
3711 for (
auto _c :
coords()) {
3715 cut +=
TString::Format(
"%s==%d", _cat->GetName(), _cat->getCurrentIndex());
3722 TString::Format(
"%s>=%f&&%s<%f", _rv->GetName(), _rv->getMin(_rv->getStringAttribute(
"coordRange")),
3723 _rv->GetName(), _rv->getMax(_rv->getStringAttribute(
"coordRange")));
3726 throw std::runtime_error(
"SetBinContent of data: Unsupported coordinate type");
3735 cut2 =
TString::Format(
"%s >= %f && %s < %f", _ax->GetParent()->GetName(), _ax->GetBinLowEdge(bin),
3736 _ax->GetParent()->GetName(), _ax->GetBinUpEdge(bin));
3783 for (
auto &o :
obs) {
3786 if (
v->getMin() < dv->getMin())
3787 dv->setMin(
v->getMin());
3788 if (
v->getMax() > dv->getMax())
3789 dv->setMax(
v->getMax());
3793 if (!dc->hasLabel(
c->getCurrentLabel())) {
3794 dc->defineType(
c->getCurrentLabel(),
c->getCurrentIndex());
3803 if (
auto _nentries = std::unique_ptr<RooAbsData>(
_data->
reduce(cutFormula))->numEntries();
3804 _nentries != _ax->GetNbins()) {
3807 if (_nentries > 0) {
3808 Info(
"SetBinContent",
"Binning %s in channel: %s",
GetName(), cut.
Data());
3809 auto _reduced = std::unique_ptr<RooAbsData>(
_data->
reduce(icutFormula));
3811 for (
int j = 0; j < _reduced->numEntries(); j++) {
3812 auto _obs = _reduced->get(j);
3813 _data->
add(*_obs, _reduced->weight());
3816 for (
int i = 1; i <= _ax->GetNbins(); i++) {
3820 dynamic_cast<RooAbsLValue *
>(_ax->GetParent())->setBin(i - 1, _ax->GetName());
3826 if (std::unique_ptr<RooAbsData>(
_data->
reduce(cutFormula2))->numEntries() > 0) {
3827 auto _reduced = std::unique_ptr<RooAbsData>(
_data->
reduce(icutFormula2));
3829 for (
int j = 0; j < _reduced->numEntries(); j++) {
3830 auto _obs = _reduced->get(j);
3831 _data->
add(*_obs, _reduced->weight());
3835 dynamic_cast<RooAbsLValue *
>(_ax->GetParent())->setBin(bin - 1, _ax->GetName());
3838 return bb->SetBinContent(bin,
value, par, parVal);
3841 }
else if (get<RooDataHist>()) {
3842 throw std::runtime_error(
"RooDataHist not supported yet");
3846 if (
auto _varies =
variations(); !_varies.empty() || (par && strlen(par))) {
3847 if (!par || strlen(par) == 0) {
3848 return _varies[
"nominal"]->SetBinContent(bin,
value, par, parVal);
3849 }
else if (
auto it = _varies.find(
Form(
"%s=%g", par, parVal)); it) {
3850 return it->SetBinContent(bin,
value);
3862 if (!par || strlen(par) == 0) {
3875 if (strcmp(
c->GetName(),
Form(
"%g",
c->getVal())) == 0) {
3878#if ROOT_VERSION_CODE < ROOT_VERSION(6, 24, 00)
3891 auto bin_pars =
f->dataHist().get(bin - 1);
3892 if (
f->getAttribute(
"density")) {
3893 value /=
f->dataHist().binVolume(*bin_pars);
3895 f->dataHist().set(*bin_pars,
value);
3898 if (
auto otherfName =
f->getStringAttribute(
"symmetrized_by"); otherfName) {
3900 f->setStringAttribute(
"symmetrized_by",
nullptr);
3901 if (
auto x = getObject<RooAbsArg>(otherfName);
x) {
3902 x->setStringAttribute(
"symmetrizes",
nullptr);
3903 x->setStringAttribute(
"symmetrize_nominal",
nullptr);
3905 }
else if (
auto otherfName2 =
f->getStringAttribute(
"symmetrizes"); otherfName2) {
3906 auto nomf = getObject<RooHistFunc>(
f->getStringAttribute(
"symmetrize_nominal"));
3907 auto otherf = getObject<RooHistFunc>(otherfName2);
3908 if (nomf && otherf) {
3909 otherf->dataHist().set(*bin_pars, 2 * nomf->dataHist().weight(bin - 1) -
value);
3910 otherf->setValueDirty();
3917 f2->setNominal(
value);
3929 return datasets()[dataName]->SetContents(obj);
3936 if (get<RooProduct>()) {
3940 if (
auto _varies =
variations(); !_varies.empty()) {
3941 return _varies[
"nominal"]->SetBinError(bin,
value);
3956 while (_prodParent && !_prodParent->get<
RooProduct>() && !_prodParent->get<
RooAbsPdf>()) {
3958 _prodParent.reset();
3961 _prodParent = _prodParent->fParent;
3964 (_prodParent && !_prodParent->get<
RooAbsPdf>()) ? _prodParent->factors().find(
"statFactor") :
nullptr;
3965 auto f_stat = (_f_stat) ? _f_stat->get<
ParamHistFunc>() :
nullptr;
3966 if (_f_stat && _f_stat->get() && !f_stat) {
3967 throw std::runtime_error(
"stat factor must be a paramhistfunc");
3976 for (
auto &
p :
xRooNode(
"tmp", *
f, std::shared_ptr<xRooNode>(
nullptr)).
vars()) {
3981 auto h = std::unique_ptr<TH1>(
f->dataHist().createHistogram(parNames
3988 h->SetName(
"statFactor");
3990 h->SetOption(
"blankshape");
3993 auto toMultiply =
this;
3997 f_stat =
dynamic_cast<ParamHistFunc *
>(toMultiply->Multiply(*h).get());
3999 throw std::runtime_error(
"Failed creating stat shapeFactor");
4005 TString prefix =
f->getStringAttribute(
"statPrefix");
4006 if (
value && prefix ==
"") {
4010 while (_p && !(_p->get()->InheritsFrom(
"RooRealSumPdf") || _p->get()->InheritsFrom(
"RooAddPdf") ||
4011 _p->get()->InheritsFrom(
"RooWorkspace") || _p->get()->InheritsFrom(
"RooAddition"))) {
4016 auto newVar = (
value == 0) ? getObject<RooRealVar>(
"1")
4017 : acquire<RooRealVar>(
Form(
"%s_bin%d", prefix.
Data(), bin),
4018 Form(
"%s_bin%d", prefix.
Data(), bin), 1);
4019#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
4024 auto var =
dynamic_cast<RooRealVar *
>(&pSet[bin - 1]);
4026 if (newVar.get() != var) {
4030 for (std::size_t i = 0; i < pSet.
size(); i++) {
4031 if (
int(i) != bin - 1) {
4032 all.
add(*pSet.
at(i));
4043 if (strcmp(rrv->GetName(),
"1") != 0) {
4044 TString origName = (
f->getStringAttribute(
"origName")) ?
f->getStringAttribute(
"origName") :
GetName();
4046 auto bin_pars =
f->dataHist().get(bin - 1);
4047 auto _binContent =
f->dataHist().weight();
4048 if (
f->getAttribute(
"density")) {
4049 _binContent *=
f->dataHist().binVolume(*bin_pars);
4054 for (
auto &[s, sv] : rrv->stringAttributes()) {
4055 if (s.find(
"sumw_") == 0) {
4057 }
else if (s.find(
"sumw2_") == 0) {
4061 if (sumw2 && sumw2 != std::numeric_limits<double>::infinity()) {
4062 double tau = pow(sumw, 2) / sumw2;
4063 rrv->setError((tau < 1
e-15) ? 1e15 : ( 1. / sqrt(tau)));
4064 rrv->setConstant(
false);
4066 auto _constr =
v.constraints();
4068 if (_constr.empty()) {
4069 rrv->setStringAttribute(
"boundConstraint", _constr.Add(
"poisson").get()->GetName());
4071 auto _glob = _constr.at(0)->obs().at(0)->get<
RooRealVar>();
4074 double _min = tau * (1. - 5. * sqrt(1. / tau));
4075 double _max = tau * (1. + 5. * sqrt(1. / tau));
4076 _glob->setRange(_min, _max);
4078 _constr.at(0)->pp().at(0)->SetBinContent(0, tau);
4079 rrv->setStringAttribute(
"boundConstraint", _constr.at(0)->get()->GetName());
4081 rrv->setRange(std::max((1. - 5. * sqrt(1. / tau)), 1
e-15), 1. + 5. * sqrt(1. / tau));
4084 if (
auto _constr =
v.constraints(); !_constr.empty()) {
4085 v.constraints().Remove(*_constr.at(0));
4090 rrv->setConstant(sumw2 == 0);
4102 auto res =
find(
name, browseResult);
4104 throw std::out_of_range(
name +
" does not exist");
4113 if (
auto _w = get<RooWorkspace>(); _w)
4115 if (
auto a = get<RooAbsArg>();
a &&
GETWS(
a)) {
4126 xRooNode out(
".constraints",
nullptr, *
this);
4129 getConstraint = [&](
const xRooNode &
n,
RooAbsArg &par, std::set<RooAbsPdf *> ignore) {
4131 if (ignore.count(_pdf))
4133 ignore.insert(_pdf);
4139 for (
auto &
c :
n.bins()) {
4140 if (
auto oo = getConstraint(*
c, par, ignore); oo) {
4150 for (
auto p : _ws->allPdfs()) {
4151 if (ignore.count(
static_cast<RooAbsPdf *
>(
p)))
4153 if (
p->dependsOn(par)) {
4154 out.emplace_back(std::make_shared<xRooNode>(par.GetName(), *
p, *
this));
4160 return getConstraint(*
n.fParent, par, ignore);
4162 for (
auto p : o->pdfList()) {
4163 if (ignore.count(
static_cast<RooAbsPdf *
>(
p)))
4165 if (
p->dependsOn(par)) {
4166 out.emplace_back(std::make_shared<xRooNode>(par.GetName(), *
p, *
this));
4172 for (
auto &
p :
vars()) {
4176 if (
v->getAttribute(
"Constant") &&
v != get<RooAbsReal>())
4178 if (
v->getAttribute(
"obs"))
4180 getConstraint(*
this, *
v, {get<RooAbsPdf>()});
4188 auto it = out.std::vector<std::shared_ptr<xRooNode>>
::begin();
4189 while (it != out.std::vector<std::shared_ptr<xRooNode>>
::end()) {
4190 bool removeIt =
false;
4191 for (
auto &
c : out) {
4192 if (
c.get() == it->get())
4196 std::set<std::string> parNames;
4197 std::string _cName =
c->GetName();
4199 parNames.insert(_cName.substr(0, _cName.find(
';')));
4200 _cName = _cName.substr(_cName.find(
';') + 1);
4201 }
while (_cName.find(
';') != std::string::npos);
4202 parNames.insert(_cName);
4203 _cName = it->get()->GetName();
4205 parNames.insert(_cName.substr(0, _cName.find(
';')));
4206 _cName = _cName.substr(_cName.find(
';') + 1);
4207 }
while (_cName.find(
';') != std::string::npos);
4208 parNames.insert(_cName);
4210 for (
auto &
x : parNames) {
4211 if (!_cName.empty())
4215 c->TNamed::SetName(_cName.c_str());
4228 if (get<RooAbsArg>() && get<RooAbsArg>()->isFundamental()) {
4229 for (
auto &o : out) {
4230 o->TNamed::SetName(o->get()->GetName());
4244 sName =
TString(
"factory:") + sName;
4248 if (
auto h = get<TH1>();
h) {
4250 std::map<std::string, std::string> stringAttrs;
4252 auto pos = sOpt2.
Index(
"=");
4253 auto start = sOpt2.
Index(
";") + 1;
4259 stringAttrs[sOpt2(start, pos - start)] = sOpt2(pos + 1,
end - pos - 1);
4265 origName = origName(1, origName.
Length());
4268 newObjName(1, newObjName.
Length());
4275 TString varName =
h->GetXaxis()->GetName();
4276 std::string binningName = newObjName.
Data();
4277 if (
auto pos = varName.
Index(
';'); pos != -1) {
4278 binningName = varName(pos + 1, varName.
Length());
4279 varName = varName(0, pos);
4282 if (varName ==
"xaxis" &&
4284 if (
auto ax = acquirer.
GetXaxis(); ax) {
4285 varName = ax->GetParent()->GetName();
4287 binningName = ax->GetName();
4288 }
else if (acquirer.
obs().size() == 1)
4289 varName = acquirer.
obs().
at(0)->get()->GetName();
4291 auto x = acquirer.
acquire<
RooRealVar>(varName,
h->GetXaxis()->GetTitle(),
h->GetXaxis()->GetXmin(),
4292 h->GetXaxis()->GetXmax());
4293 if (
x->getMin() >
h->GetXaxis()->GetXmin())
4294 x->setMin(
h->GetXaxis()->GetXmin());
4295 if (
x->getMax() <
h->GetXaxis()->GetXmax())
4296 x->setMax(
h->GetXaxis()->GetXmax());
4297 if (!
x->hasBinning(binningName.c_str())) {
4298 if (
h->GetXaxis()->IsVariableBinSize()) {
4299 x->setBinning(
RooBinning(
h->GetNbinsX(),
h->GetXaxis()->GetXbins()->GetArray()), binningName.c_str());
4302 RooUniformBinning(
h->GetXaxis()->GetXmin(),
h->GetXaxis()->GetXmax(),
h->GetXaxis()->GetNbins()),
4303 binningName.c_str());
4305 x->getBinning(binningName.c_str()).
SetTitle(
h->GetXaxis()->GetTitle());
4306 if (
x->getBinningNames().size() == 2) {
4308 x->setBinning(
x->getBinning(binningName.c_str()));
4312 if (
x->getBinning(binningName.c_str()).numBins() !=
h->GetNbinsX()) {
4313 throw std::runtime_error(
4314 TString::Format(
"binning mismatch for binning %s of %s", binningName.c_str(),
x->GetName()));
4318 std::shared_ptr<RooAbsArg> _f;
4324 for (
auto &[k,
v] : stringAttrs) {
4327 x->setAttribute(
"obs",
true);
4328 }
else if (sOpt2.
Contains(
"shape")) {
4330 for (
int i = 0; i <
x->getBinning(binningName.c_str()).numBins(); i++) {
4331 std::shared_ptr<RooAbsArg> arg;
4332 if (sOpt2.
Contains(
"blankshape")) {
4338 if (
h->GetMinimumStored() != -1111 ||
h->GetMaximumStored() != -1111) {
4340 h->GetBinContent(i + 1),
h->GetMinimumStored(),
4341 h->GetMaximumStored());
4344 h->GetBinContent(i + 1));
4351 auto tmp =
dynamic_cast<RooAbsBinning *
>(
x->getBinningPtr(
nullptr)->Clone());
4352 x->setBinning(
x->getBinning(binningName.c_str()));
4354#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
4358 .setName(
"paramSet");
4360 x->setBinning(*tmp);
4362 for (
auto &[k,
v] : stringAttrs) {
4363 _f->setStringAttribute(k.c_str(),
v.c_str());
4367 binningName.c_str() );
4369 throw std::runtime_error(
"Couldn't make data hist");
4374 f->setAttribute(
"autodensity");
4377 for (
auto &[k,
v] : stringAttrs) {
4378 _f->setStringAttribute(k.c_str(),
v.c_str());
4382 _f->setStringAttribute(
"xvar",
x->GetName());
4383 _f->setStringAttribute(
"binning", binningName.c_str());
4384 if (strcmp(_f->GetName(), origName.
Data()) && !_f->getStringAttribute(
"alias"))
4385 _f->setStringAttribute(
"alias", origName);
4388 xRooNode tmp(
h->GetName(), _f, acquirer);
4390 _f = std::dynamic_pointer_cast<RooAbsArg>(tmp.fComp);
4393 _f->setStringAttribute(
"xvar",
x->GetName());
4394 _f->setStringAttribute(
"binning", binningName.c_str());
4397 if (strcmp(_f->GetName(), origName.
Data()) && !_f->getStringAttribute(
"alias"))
4398 _f->setStringAttribute(
"alias", origName);
4415 auto arg = get<RooAbsArg>();
4416 if (!initObject && !arg) {
4420 std::unique_ptr<TObject> argInitObject;
4426 if (arg->getStringAttribute(
"style")) {
4427 t = arg->getStringAttribute(
"style");
4428 }
else if (autoCreate) {
4430 argInitObject = std::make_unique<TH1D>(
GetName(),
GetTitle(), 1, 0, 1);
4431 initObject = argInitObject.get();
4437 std::shared_ptr<TStyle>
style;
4439 if (!
gROOT->GetStyle(t)) {
4440 if ((
style = getObject<TStyle>(t.
Data()))) {
4450 if (
auto x =
dynamic_cast<TAttLine *
>(initObject))
4452 if (
auto x =
dynamic_cast<TAttFill *
>(initObject))
4454 if (
auto x =
dynamic_cast<TAttMarker *
>(initObject))
4462 if (arg && !arg->getStringAttribute(
"style")) {
4463 arg->setStringAttribute(
"style",
style->GetName());
4469std::shared_ptr<TObject>
xRooNode::acquire(
const std::shared_ptr<TObject> &arg,
bool checkFactory,
bool mustBeNew)
4474 return fParent->acquire(arg, checkFactory, mustBeNew);
4478 if (_ws && (
get() == _ws || _ws->arg(
GetName()) || (arg && strcmp(arg->GetName(),
GetName()) == 0))) {
4481 if (
auto a =
dynamic_cast<RooAbsArg *
>(arg.get());
a) {
4482 auto out_arg = _ws->arg(
a->GetName());
4483 TString aName = arg->GetName();
4485 while (out_arg && mustBeNew) {
4487 out_arg = _ws->arg(
a->GetName());
4489 if (aName !=
a->GetName())
4490 Warning(
"acquire",
"Renaming to %s",
a->GetName());
4494 if (
auto res = _ws->factory(arg->GetName()); res) {
4501 Info(
"acquire",
"A copy of %s has been added to workspace %s",
a->GetName(), _ws->GetName());
4507 std::set<std::string> setNames;
4510 setNames.insert(aa.first);
4513 for (
auto &aa : setNames)
4515 out_arg = _ws->arg(
a->GetName());
4516 if (
GETWS(out_arg) != _ws) {
4517 out_arg->setWorkspace(*_ws);
4521 return std::shared_ptr<TObject>(out_arg, [](
TObject *) {});
4522 }
else if (
auto a2 =
dynamic_cast<RooAbsData *
>(arg.get()); a2) {
4528 return std::shared_ptr<TObject>(_ws->embeddedData(arg->GetName()), [](
TObject *) {});
4529 }
else if (arg->InheritsFrom(
"RooFitResult") || arg->InheritsFrom(
"TTree") || arg->IsA() ==
TStyle::Class()) {
4532 TString aName = arg->GetName();
4533 TObject *out_arg = _ws->genobj(arg->GetName());
4535 while (aNamed && out_arg && mustBeNew) {
4537 out_arg = _ws->genobj(aNamed->
GetName());
4540 if (aName != arg->GetName()) {
4541 Warning(
"acquire",
"Renaming to %s", arg->GetName());
4543 if (_ws->import(*arg,
false )) {
4547 out_arg = _ws->genobj(arg->GetName());
4565 return std::shared_ptr<TObject>(out_arg, [](
TObject *) {});
4572 auto out =
fProvider->getObject(arg->GetName(), arg->ClassName());
4576 auto _owned =
find(
".memory");
4578 _owned = emplace_back(std::make_shared<xRooNode>(
".memory",
nullptr, *
this));
4583 for (
auto &
r : *_owned) {
4584 if (strcmp(
r->GetName(), arg->GetName()) == 0 && strcmp(
r->get()->ClassName(), arg->ClassName()) == 0) {
4590 std::cout <<
GetName() <<
" taking over " << arg->ClassName() <<
"::" << arg->GetName() << std::endl;
4592 return _owned->emplace_back(std::make_shared<xRooNode>(arg->GetName(), arg, *
this))->fComp;
4620 auto _deps =
vars();
4632 auto a = get<RooAbsArg>();
4634 throw std::runtime_error(
"Cannot SetXaxis of non-arg");
4636 auto _x = acquire<RooRealVar>(
name, title, low, high);
4637 _x->setBinning(binning,
a->
GetName());
4638 _x->getBinning(
a->GetName()).SetTitle(title);
4639 if (_x->getBinningNames().size() == 2) {
4641 _x->setBinning(_x->getBinning(
a->GetName()));
4646 if (_x->getMax() < high)
4648 if (_x->getMin() > low)
4652 if (!_deps.find(
name) && get<RooAbsPdf>()) {
4654 _x->setAttribute(
"obs");
4657 a->setStringAttribute(
"xvar", _x->GetName());
4658 a->setStringAttribute(
"binning",
a->GetName());
4677 return find(
name,
false) !=
nullptr;
4682 std::string partname = (
name.find(
'/') != std::string::npos) ?
name.substr(0,
name.find(
'/')) :
name;
4684 : get<RooSimultaneous>();
4685 std::string extra = (_s) ? _s->indexCat().GetName() :
"";
4686 for (
auto &
child : *
this) {
4688 (_obj &&
name == _obj->GetName()) || (_obj && partname == _obj->GetName()) ||
4689 (!extra.empty() && ((extra +
"=" +
name) ==
child->GetName() ||
4690 (extra +
"=" + partname) ==
child->GetName()))) {
4694 return child->at(
name.substr(partname.length() + 1));
4700 for (
auto &child2 :
x.browse()) {
4701 if (
auto _obj = child2->get();
name == child2->GetName() || partname == child2->GetName() ||
4702 (_obj &&
name == _obj->GetName()) || (_obj && partname == _obj->GetName())) {
4705 if (partname !=
name &&
name != child2->GetName()) {
4706 return child2->at(
name.substr(partname.length() + 1));
4715 auto child2 =
at(s.Atoi());
4716 if (partname !=
name) {
4717 return child2->at(
name.substr(partname.length() + 1));
4726 std::string partname = (
name.find(
'/') != std::string::npos) ?
name.substr(0,
name.find(
'/')) :
name;
4729 : get<RooSimultaneous>();
4730 std::string extra = (_s) ? _s->indexCat().GetName() :
"";
4731 std::shared_ptr<xRooNode> folderNode;
4732 for (
auto &
child : *
this) {
4735 ((extra +
"=" +
name) ==
child->GetName() || (extra +
"=" + partname) ==
child->GetName()))) {
4738 return child->operator[](
name.substr(partname.length() + 1));
4744 for (
auto &child2 :
x.browse()) {
4745 if (
name == child2->GetName() || partname == child2->GetName()) {
4747 if (partname !=
name &&
name != child2->GetName()) {
4748 return child2->operator[](
name.substr(partname.length() + 1));
4754 if (
child->fFolder == (std::string(
"!") + partname)) {
4756 folderNode = std::make_shared<xRooNode>(
child->fFolder.c_str(),
nullptr, *
this);
4757 folderNode->push_back(
child);
4761 if (partname !=
name) {
4762 return folderNode->operator[](
name.substr(partname.length() + 1));
4768 auto child2 =
at(s.Atoi());
4769 if (partname !=
name) {
4770 return child2->operator[](
name.substr(partname.length() + 1));
4774 auto out = std::make_shared<xRooNode>(partname.c_str(),
nullptr, *
this);
4775 if (partname !=
name) {
4776 return out->operator[](
name.substr(partname.length() + 1));
4784 for (
auto o : *
gROOT->GetListOfBrowsers()) {
4786 if (!
b || !
b->GetBrowserImp())
4793 if (!
b->GetBrowserImp())
4809 for (
auto o : *
gROOT->GetListOfBrowsers()) {
4811 if (!
b || !
b->GetBrowserImp())
4818 if (
b->GetBrowserImp()) {
4824 if (
auto item =
GETLISTTREE(_b)->FindItemByObj(_root,
const_cast<xRooNode *
>(
this)); item) {
4835 if (
auto a = get<RooAbsArg>();
a)
4836 a->setStringAttribute(
"alias",
name);
4837 for (
auto o : *
gROOT->GetListOfBrowsers()) {
4838 if (
auto b =
dynamic_cast<TBrowser *
>(o);
b) {
4840 item->SetText(
name);
4848 if (
auto o = (get<TNamed>()); o) {
4863 auto findByObj = [&](
const std::shared_ptr<xRooNode> &
n) {
4864 std::vector<std::shared_ptr<xRooNode>> &nn = *
this;
4865 for (
auto &
c : nn) {
4866 if (
c->get() ==
n->get() && strcmp(
n->GetName(),
c->GetName()) == 0)
4869 return std::shared_ptr<xRooNode>(
nullptr);
4872 auto appendChildren = [&](
const xRooNode &
n) {
4874 const std::vector<std::shared_ptr<xRooNode>> &nn(
n);
4875 for (
auto &
c : nn) {
4876 if (
auto existing = findByObj(
c); existing) {
4878 existing->fFolder =
c->fFolder;
4888 const std::vector<std::shared_ptr<xRooNode>> &nn2(*
this);
4889 for (
auto &
c : nn2) {
4890 if (strlen(
c->GetName()) > 0 && (
c->GetName()[0] ==
'.')) {
4894 if (strcmp(
c->GetName(),
"!.pars") == 0) {
4905 size_t addedChildren = 0;
4909 if (get<RooWorkspace>()) {
4910 addedChildren += appendChildren(
datasets());
4924 addedChildren += appendChildren(
components());
4925 if (!get<RooWorkspace>())
4926 addedChildren += appendChildren(
factors());
4928 auto _coefs =
coefs();
4929 if (_coefs.get() && strcmp(_coefs->GetName(),
"1") != 0 && strcmp(_coefs->GetName(),
"ONE") != 0) {
4930 if (_coefs.size() == 1 && _coefs.get<
RooAddition>()) {
4931 if (strcmp(_coefs.at(0)->GetName(),
"1") != 0 &&
4932 strcmp(_coefs.at(0)->GetName(),
"ONE") != 0) {
4933 auto coef = std::make_shared<xRooNode>(
".coef", *_coefs.at(0)->get(), *
this);
4934 if (
auto existing = findByObj(coef); existing) {
4936 existing->fFolder = _coefs.at(0)->fFolder;
4942 if (
auto existing =
find(_coefs.GetName()); existing) {
4944 existing->fFolder = _coefs.fFolder;
4946 emplace_back(std::make_shared<xRooNode>(_coefs));
4950 addedChildren += appendChildren(
variations());
4951 if (get<ParamHistFunc>() || get<RooSimultaneous>())
4952 addedChildren += appendChildren(
bins());
4953 if (get<RooAbsData>())
4954 addedChildren += appendChildren(
obs());
4957 if (
auto arg = get<RooAbsArg>(); arg && addedChildren == 0) {
4958 for (
int i = 0; i < arg->numProxies(); i++) {
4959 auto _proxy = arg->getProxy(i);
4961 auto c = std::make_shared<xRooNode>(
TString::Format(
".%s", _proxy->name()), *(
a->absArg()), *
this);
4962 if (
auto existing = findByObj(
c); existing) {
4964 existing->fFolder =
c->fFolder;
4969 for (
auto a2 : *s) {
4970 auto c = std::make_shared<xRooNode>(*a2, *
this);
4971 if (arg->numProxies() != 1) {
4972 c->fFolder = std::string(
"!.") +
4975 if (
auto existing = findByObj(
c); existing) {
4977 existing->fFolder =
c->fFolder;
4993 }
else if (
auto ir = get<RooStats::HypoTestInverterResult>()) {
4997 if (strcmp(
c->GetName(),
".memory") == 0 &&
c->get<
xRooHypoSpace>()) {
5005 fBrowsables.emplace_back(std::make_shared<xRooNode>(
".memory", std::make_shared<xRooHypoSpace>(ir), *
this));
5012 for (
auto a : _axes) {
5013 if (
a != _axes.first())
5016 TString::Format(
"%s=%g",
a->GetName(), hp.coords->getRealValue(
a->GetName(), ir->GetXValue(i)));
5018 auto hpn = emplace_back(std::make_shared<xRooNode>(coordString, hp.hypoTestResult, hs));
5020 hpn->fBrowsables.emplace_back(std::make_shared<xRooNode>(
5026 std::vector<std::shared_ptr<xRooNode>> &nn = *
this;
5027 for (
auto &
c : nn) {
5037 }
else if (get<RooStats::HypoTestResult>()) {
5050 std::make_shared<xRooNLLVar::xRooHypoPoint>(std::dynamic_pointer_cast<RooStats::HypoTestResult>(
fComp));
5051 fBrowsables.emplace_back(std::make_shared<xRooNode>(
".memory", shp, *
this));
5057 if (
auto fit = hp->
ufit()) {
5058 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"ufit");
5061 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"cfit_null");
5064 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"cfit_alt");
5066 if (
auto fit = hp->
gfit()) {
5067 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"gfit");
5069 if (
auto asi = hp->
asimov()) {
5070 auto asiP = fits.emplace_back(std::make_shared<xRooNode>(
5071 asi->hypoTestResult ? asi->hypoTestResult : std::make_shared<RooStats::HypoTestResult>(asi->result()),
5073 asiP->TNamed::SetName(
"asimov");
5074 asiP->fBrowsables.emplace_back(std::make_shared<xRooNode>(
".memory", asi, asiP));
5076 appendChildren(fits);
5080 auto it = std::vector<std::shared_ptr<xRooNode>>
::begin();
5081 while (it != std::vector<std::shared_ptr<xRooNode>>
::end()) {
5082 if (it->get()->fTimes == 0) {
5083 for (
auto o : *
gROOT->GetListOfBrowsers()) {
5085 if (
b &&
b->GetBrowserImp()) {
5094 if (
auto item =
GETLISTTREE(_b)->FindItemByObj(_root,
this); item) {
5132 xRooNode out(
".obs", std::make_shared<RooArgList>(), *
this);
5134 for (
auto o :
vars()) {
5137 out.emplace_back(o);
5148 xRooNode out(
".globs", std::make_shared<RooArgList>(), *
this);
5150 for (
auto o :
obs()) {
5153 out.emplace_back(o);
5164 xRooNode out(
".robs", std::make_shared<RooArgList>(), *
this);
5166 for (
auto o :
obs()) {
5169 out.emplace_back(o);
5180 xRooNode out(
".pars", std::make_shared<RooArgList>(), *
this);
5182 for (
auto o :
vars()) {
5185 out.emplace_back(o);
5196 xRooNode out(
".consts", std::make_shared<RooArgList>(), *
this);
5198 for (
auto o :
pars()) {
5201 out.emplace_back(o);
5213 xRooNode out(
".floats", std::make_shared<RooArgList>(), *
this);
5215 for (
auto o :
pars()) {
5218 out.emplace_back(o);
5230 xRooNode out(
".poi", std::make_shared<RooArgList>(), *
this);
5232 for (
auto o :
pars()) {
5235 out.emplace_back(o);
5247 xRooNode out(
".np", std::make_shared<RooArgList>(), *
this);
5249 for (
auto o :
pars()) {
5251 (!o->get<
RooAbsArg>()->getAttribute(
"Constant") && !o->get<
RooAbsArg>()->getAttribute(
"poi") &&
5254 out.emplace_back(o);
5265 xRooNode out(
".pp", std::make_shared<RooArgList>(), *
this);
5267 for (
auto o :
pars()) {
5271 out.emplace_back(o);
5282 xRooNode out(
".vars", std::make_shared<RooArgList>(), *
this);
5284 if (
auto coll = get<RooAbsCollection>(); coll) {
5285 for (
auto &
x : *
this) {
5286 for (
auto &
y :
x->vars()) {
5292 if (
auto p = get<RooAbsArg>();
p) {
5298 p->leafNodeServerList(&allLeaves);
5299 for (
auto &
c : allLeaves) {
5301 if (!
c->getAttribute(
"global")) {
5303 out.emplace_back(std::make_shared<xRooNode>(*
c, *
this));
5305 if (
c->getAttribute(
"global")) {
5306 _globs.emplace_back(std::make_shared<xRooNode>(*
c, *
this));
5307 _globs.back()->fFolder =
"!globs";
5308 }
else if (
c->getAttribute(
"obs")) {
5309 out.back()->fFolder =
"!robs";
5310 }
else if (
c->getAttribute(
"poi")) {
5311 out.back()->fFolder =
"!poi";
5312 }
else if (
c->getAttribute(
"np") ||
5314 out.back()->fFolder =
"!np";
5316 out.back()->fFolder =
"!floats";
5318 out.back()->fFolder =
"!pp";
5322 for (
auto g : _globs) {
5324 out.emplace_back(
g);
5326 }
else if (
auto p2 = get<RooAbsData>(); p2) {
5327 for (
auto a : *p2->get()) {
5328 a->setAttribute(
"obs");
5329 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5332 if (
auto _dglobs = p2->getGlobalObservables()) {
5333 for (
auto &
a : *_dglobs) {
5334 a->setAttribute(
"obs");
5335 a->setAttribute(
"global");
5336 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5341 a->setAttribute(
"obs");
5342 a->setAttribute(
"global");
5343 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5346 }
else if (
auto _ws =
ws(); _ws) {
5348 for (
auto a : *_globs2) {
5349 a->setAttribute(
"obs");
5350 a->setAttribute(
"global");
5351 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5355 for (
auto &_g : _gl->second) {
5356 auto _clone = std::shared_ptr<RooAbsArg>(
dynamic_cast<RooAbsArg *
>(_g->Clone(_g->GetName())));
5357 if (
auto v = std::dynamic_pointer_cast<RooAbsRealLValue>(_clone);
v && _g->getStringAttribute(
"nominal"))
5358 v->setVal(
TString(_g->getStringAttribute(
"nominal")).
Atof());
5359 out.emplace_back(std::make_shared<xRooNode>(_clone, *
this));
5367 for (
auto &_g : *_globs3) {
5368 auto _clone = std::shared_ptr<RooAbsArg>(
dynamic_cast<RooAbsArg *
>(_g->Clone(_g->GetName())));
5369 if (
auto v = std::dynamic_pointer_cast<RooAbsRealLValue>(_clone);
v && _g->getStringAttribute(
"nominal"))
5370 v->setVal(
TString(_g->getStringAttribute(
"nominal")).
Atof());
5371 out.emplace_back(std::make_shared<xRooNode>(_clone, *
this));
5376 }
else if (
auto w = get<RooWorkspace>();
w) {
5377 for (
auto a :
w->allVars()) {
5378 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5382 for (
auto a :
w->allCats()) {
5383 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5392 xRooNode out(
".components",
nullptr, *
this);
5394 if (
auto p = get<RooAddPdf>();
p) {
5396 std::set<RooAbsArg *> donePdfs;
5397 for (
auto &o :
p->pdfList()) {
5398 if (donePdfs.count(o))
5400 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5403 }
else if (
auto p2 = get<RooRealSumPdf>(); p2) {
5417 std::set<RooAbsArg *> doneFuncs;
5418 for (
auto &o : p2->funcList()) {
5419 if (doneFuncs.count(o))
5421 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5422 doneFuncs.insert(o);
5424 }
else if (
auto p3 = get<RooAddition>(); p3) {
5425 for (
auto &o : p3->list()) {
5426 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5428 }
else if (
auto p4 = get<RooAbsCollection>(); p4) {
5429 for (
auto &
a : *p4) {
5430 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5432 }
else if (
auto p5 = get<RooWorkspace>(); p5) {
5433 for (
auto &o : p5->components()) {
5436 bool hasClients =
false;
5437 for (
auto &
c : o->clients()) {
5438 if (!
c->InheritsFrom(
"RooRealIntegral") && p5 ==
GETWS(o)) {
5445 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5446 if (o->InheritsFrom(
"RooAbsPdf")) {
5447 out.back()->fFolder =
"!models";
5449 out.back()->fFolder =
"!scratch";
5452 for (
auto &o : p5->allGenericObjects()) {
5456 s = s(0, s.
Index(
';'));
5457 if (
auto _pdf = out.find(s.
Data()); _pdf) {
5459 out.emplace_back(std::make_shared<xRooNode>(fr->GetName(), *fr, _pdf));
5466 out.emplace_back(std::make_shared<xRooNode>(fr->GetName(), *fr, *
this));
5468 out.back()->fFolder =
"!fits";
5470 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5471 if (strcmp(out.back()->get()->ClassName(),
"TStyle") == 0) {
5472 out.back()->fFolder =
"!styles";
5473 }
else if (strcmp(out.back()->get()->ClassName(),
"RooStats::HypoTestInverterResult") == 0) {
5474 out.back()->fFolder =
"!scans";
5476 out.back()->fFolder =
"!objects";
5483 if (k.find(
"CACHE_") == 0)
5485 out.emplace_back(std::make_shared<xRooNode>(k.c_str(),
v, *
this));
5486 out.back()->fFolder =
"!sets";
5492 while ((snap = iter->Next())) {
5493 out.emplace_back(std::make_shared<xRooNode>(*snap, *
this));
5494 out.back()->fFolder =
"!snapshots";
5500 out.emplace_back(
c);
5507 out.emplace_back(
c);
5521 xRooNode out(
".bins",
nullptr, *
this);
5523 if (
auto p = get<RooSimultaneous>();
p) {
5524 std::map<int, std::shared_ptr<xRooNode>> cats;
5525 for (
auto &
c :
p->indexCat()) {
5526 auto pp =
p->getPdf(
c.first.c_str());
5532 for (
auto &[
_,
n] : cats)
5533 out.emplace_back(
n);
5534 }
else if (
auto phf = get<ParamHistFunc>(); phf) {
5536#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
5537 auto &pSet = phf->_paramSet;
5539 auto &pSet = phf->paramList();
5541 for (
auto par : pSet) {
5542 out.emplace_back(std::make_shared<xRooNode>(*par, *
this));
5543 out.back()->fBinNumber = i;
5546 }
else if (
auto ax =
GetXaxis(); ax) {
5547 for (
int i = 1; i <= ax->GetNbins(); i++) {
5549 std::vector<RooAbsArg *> _factors;
5553 for (
auto &ss :
f->bins()[i - 1]->factors())
5554 _factors.push_back(ss->get<
RooAbsArg>());
5556 _factors.push_back(
f->bins()[i - 1]->get<
RooAbsArg>());
5560 out.emplace_back(std::make_shared<xRooNode>(
5561 TString::Format(
"%g<=%s<%g", ax->GetBinLowEdge(i), ax->GetParent()->GetName(), ax->GetBinLowEdge(i + 1)),
5562 _factors.empty() ? nullptr
5566 for (
auto f : _factors) {
5567#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
5573 out.back()->fBinNumber = i;
5583 bool isResidual =
false;
5591 if (!parent->fComp) {
5592 while (!parent->fComp && parent->fParent) {
5593 parent = parent->fParent;
5596 parent = parent->fParent;
5602 for (
auto &o :
p->funcList()) {
5604 if (i >=
p->coefList().size()) {
5606 coefs.add(
p->coefList());
5608 coefs.add(*
p->coefList().at(i));
5613 }
else if (
auto p2 = parent->get<
RooAddPdf>(); p2) {
5615 if (p2->coefList().empty()) {
5620 for (
auto &o : p2->pdfList()) {
5622 if (i >= p2->coefList().size()) {
5624 coefs.add(p2->coefList());
5626 coefs.add(*p2->coefList().at(i));
5637 auto coefSum =
coefs.empty()
5640 : std::make_shared<RooAddition>((isResidual) ?
".sumOfCoefs" :
".coefs",
5641 "Coefficients of",
coefs));
5642 xRooNode out(
".coef", coefSum ? std::dynamic_pointer_cast<RooAbsArg>(std::make_shared<RooFormulaVar>(
5643 ".coef",
"1-sum(otherCoefs)",
"1. - @0", *coefSum))
5645 if (coefSum &&
coefs.size() != 1) {
5646 out.emplace_back(std::make_shared<xRooNode>(
".memory",
nullptr, *
this))
5648 std::make_shared<xRooNode>(
".sumOfCoefs", coefSum, out));
5650 if (!
coefs.empty()) {
5654 }
else if (
coefs.size() == 1) {
5656 if (!
coefs.empty()) {
5665 xRooNode out(
".coefs", coefSum, *
this);
5675 xRooNode out(
".factors",
nullptr, *
this);
5677 if (
auto p = get<RooProdPdf>();
p) {
5679 if (
auto a = _main.get<
RooRealSumPdf>();
a && !
a->getStringAttribute(
"alias")) {
5680 a->setStringAttribute(
"alias",
"samples");
5682 a2->setStringAttribute(
"alias",
"components");
5684 int _npdfs =
p->pdfList().size();
5685 for (
auto &o :
p->pdfList()) {
5686 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5687 if (_npdfs > 5 && o != _main.get())
5688 out.back()->fFolder =
"!constraints";
5690 }
else if (
auto p2 = get<RooProduct>(); p2) {
5691 for (
auto &o : p2->components()) {
5692 if (o->InheritsFrom(
"RooProduct")) {
5696 out.emplace_back(std::make_shared<xRooNode>(
n->GetName(),
n->fComp, *
this));
5699 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
5702 }
else if (
auto w = get<RooWorkspace>();
w) {
5708 for (
auto a :
w->allFunctions()) {
5709 if (_obs.contains(*
a))
5712 for (
auto c :
a->clients()) {
5714 if (
c->InheritsFrom(
"RooProduct"))
5718 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
5762 xRooNode out(
".variations",
nullptr, *
this);
5774 if (
auto p2 = get<PiecewiseInterpolation>(); p2) {
5775#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
5776 out.emplace_back(std::make_shared<xRooNode>(
"nominal", p2->_nominal.arg(), *
this));
5778 out.emplace_back(std::make_shared<xRooNode>(
"nominal", *(p2->nominalHist()), *
this));
5780 for (
size_t i = 0; i < p2->paramList().
size(); i++) {
5782 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p2->paramList().at(i)->GetName()),
5783 *p2->highList().at(i), *
this));
5784 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p2->paramList().at(i)->GetName()),
5785 *p2->lowList().at(i), *
this));
5787 }
else if (
auto p3 = get<RooStats::HistFactory::FlexibleInterpVar>(); p3) {
5788#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
5789 out.emplace_back(std::make_shared<xRooNode>(
"nominal",
RooFit::RooConst(p3->_nominal), *
this));
5790 for (
size_t i = 0; i < p3->_paramList.size(); i++) {
5791 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p3->_paramList.at(i)->GetName()),
5793 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p3->_paramList.at(i)->GetName()),
5797 out.emplace_back(std::make_shared<xRooNode>(
"nominal",
RooFit::RooConst(p3->nominal()), *
this));
5798 for (
size_t i = 0; i < p3->variables().
size(); i++) {
5799 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p3->variables().at(i)->GetName()),
5801 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p3->variables().at(i)->GetName()),
5806 }
else if (
auto p4 = get<ParamHistFunc>(); p4) {
5825 for (
auto &k : *
this) {
5834 xRooNode out(
".datasets()",
nullptr, *
this);
5835 out.fBrowseOperation = [](
xRooNode *
f) {
return f->fParent->datasets(); };
5837 if (
auto _ws = get<RooWorkspace>(); _ws) {
5838 for (
auto &
d : _ws->allData()) {
5839 out.emplace_back(std::make_shared<xRooNode>(*
d, *
this));
5840 out.back()->fFolder =
"!datasets";
5842 }
else if (
auto __ws =
ws(); __ws) {
5843 if (get<RooAbsPdf>() ||
5854 for (
auto _c :
coords()) {
5858 cut +=
TString::Format(
"%s==%d", _cat->GetName(), _cat->getCurrentIndex());
5867 TString::Format(
"%s>=%f&&%s<%f", _rv->GetName(), _rv->getMin(_rv->getStringAttribute(
"coordRange")),
5868 _rv->GetName(), _rv->getMax(_rv->getStringAttribute(
"coordRange")));
5873 throw std::runtime_error(
"datasets(): Unsupported coordinate type");
5876 if (
auto s = get<RooSimultaneous>()) {
5878 bool hasMissing =
false;
5880 for (
auto cat : s->indexCat()) {
5881 if (!s->getPdf(cat.first.c_str())) {
5886 extraCut +=
TString::Format(
"%s==%d", s->indexCat().GetName(), cat.second);
5892 cut +=
"(" + extraCut +
")";
5893 cutobs.
add(s->indexCat());
5898 auto a =
dynamic_cast<RooAbsArg *
>(ax->GetParent());
5903 if (std::unique_ptr<RooAbsCollection>(
d->obs().argList().selectCommon(_obs))->size() == _obs.
size()) {
5910 out.emplace_back(std::make_shared<xRooNode>(
5914 if (
d->get()->TestBit(1 << 20))
5915 out.back()->get()->SetBit(1 << 20);
5917 out.back()->fBrowsables.emplace_back(std::make_shared<xRooNode>(
".sourceds",
d->fComp, *
this));
5919 out.emplace_back(std::make_shared<xRooNode>(
d->fComp, *
this));
5940 if (
b && strcmp(
b->GetName(),
name) == 0)
5949 if (
auto fr = get<RooFitResult>(); fr) {
5953 if (
auto theData = get<RooDataSet>(); theData) {
5955 TH1 *theHist =
nullptr;
5960 theHist =
dynamic_cast<TH1 *
>(o);
5962 theHist =
static_cast<TH1 *
>(theHist->
Clone());
5973 auto vo =
dynamic_cast<TObject *
>(
v);
5974 if (
v &&
obs().
find(vo->GetName())) {
5978 TString::Format(
"my temp hist;%s", strlen(vo->GetTitle()) ? vo->GetTitle() : vo->GetName()),
5979 cat->numTypes(), 0, cat->numTypes());
5980 for (
int i = 0; i < cat->numTypes(); i++) {
5985 auto _binning =
v->getBinningPtr(
nullptr);
5986 if(_binning->isUniform()) {
5989 TString::Format(
"my temp hist;%s", strlen(vo->GetTitle()) ? vo->GetTitle() : vo->GetName()),
5990 v->numBins(), _binning->lowBound(), _binning->highBound());
5994 TString::Format(
"my temp hist;%s", strlen(vo->GetTitle()) ? vo->GetTitle() : vo->GetName()),
5995 v->numBins(), _binning->array());
5999 throw std::runtime_error(
"Cannot draw dataset without parent PDF");
6002 theHist = _parentPdf->BuildHistogram(
v,
true);
6008 TH1 *xPos =
static_cast<TH1 *
>(theHist->
Clone(
"xPos"));
6010 TH1 *xPos2 =
static_cast<TH1 *
>(theHist->
Clone(
"xPos2"));
6012 auto nHist = std::unique_ptr<TH1>(
static_cast<TH1 *
>(theHist->
Clone(
"nEntries")));
6017 dataGraph->SetName(
GetName());
6018 dataGraph->SetTitle(strlen(theData->GetTitle()) ? theData->GetTitle() : theData->GetName());
6024 dataGraph->SetMarkerStyle(20);
6036 dataGraph->SetTitle(
TString::Format(
"%s = %f", dataGraph->GetTitle(), dataGraph->GetPointX(0)));
6049 auto _pos = pName.
Index(
'=');
6051 int nevent = theData->numEntries();
6052 for (
int i = 0; i < nevent; i++) {
6055 for (
auto _c : _coords) {
6057 if (cat->getIndex() != theData->get()->getCatIndex(cat->GetName())) {
6063 if (!rv->inRange(theData->get()->getRealValue(rv->GetName()), rv->getStringAttribute(
"coordRange"))) {
6071 cat && cat->
getLabel() != pName(_pos + 1, pName.Length())) {
6087 theHist->
Fill((
x) ? xvar->
getVal() : 0.5, theData->weight());
6088 nHist->Fill((
x) ? xvar->
getVal() : 0.5, 1);
6096 for (
int i = 0; i < theHist->
GetNbinsX(); i++) {
6097 if (includeZeros || nHist->GetBinContent(i + 1)) {
6100 dataGraph->SetPoint(dataGraph->GetN(),
6105 xErr = (xErr <= 0) ? 0. : sqrt(xErr);
6108 dataGraph->SetPointError(dataGraph->GetN() - 1, xErr, xErr,
6120 dataGraph->GetHistogram()->GetXaxis()->Set(theHist->
GetNbinsX(), 0, theHist->
GetNbinsX());
6121 for (
int i = 1; i <= theHist->
GetNbinsX(); i++)
6122 dataGraph->GetHistogram()->GetXaxis()->SetBinLabel(i, theHist->
GetXaxis()->
GetBinLabel(i));
6147 auto _style =
style(dataGraph);
6149 *
dynamic_cast<TAttLine *
>(dataGraph) = *_style;
6150 *
dynamic_cast<TAttFill *
>(dataGraph) = *_style;
6151 *
dynamic_cast<TAttMarker *
>(dataGraph) = *_style;
6156 throw std::runtime_error(
"Cannot build graph");
6162 if (
auto _w =
ws(); _w) {
6164 for (
auto o : _w->allGenericObjects()) {
6166 _fr->ResetBit(1 << 20);
6169 res->SetBit(1 << 20);
6171 auto allVars = _w->allVars();
6176 throw std::runtime_error(
"Not supported yet");
6190 throw std::runtime_error(
"Not a RooFitResult");
6196 if (get<RooFitResult>())
6198 if (get<RooAbsData>()) {
6199 if (
auto _fr =
find(
".fitResult"); _fr)
6201#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
6203 if (get<RooDataSet>() && get<RooDataSet>()->weightVar() &&
6204 get<RooDataSet>()->weightVar()->getStringAttribute(
"fitResult")) {
6205 return xRooNode(getObject<const RooFitResult>(get<RooDataSet>()->weightVar()->getStringAttribute(
"fitResult")),
6213 if (sOpt ==
"prefit") {
6220 auto _coefs =
coefs();
6226 std::unique_ptr<RooArgList> _pars(
dynamic_cast<RooArgList *
>(
pars().
argList().selectByAttrib(
"Constant",
false)));
6227 auto fr = std::make_shared<RooFitResult>(
"prefitResult",
"Prefit");
6228 fr->setFinalParList(*_pars);
6229 for (
auto &
p : fr->floatParsFinal()) {
6233 if (
auto s = _v->getStringAttribute(
"nominal"); s)
6236 std::shared_ptr<xRooNode> pConstr;
6237 for (
auto &
c : _constr) {
6240 bool isServer =
true;
6243 for (
auto s :
c->get<
RooAbsArg>()->servers()) {
6244 if (strcmp(s->GetName(),
p->
GetName()) == 0) {
6259 double prefitVal = 0;
6260 double prefitError = 0;
6261 for (
auto &_d : pConstr->vars()) {
6262 if (strcmp(
p->
GetName(), _d->get()->GetName()) == 0)
6266 prefitVal = prefitError;
6267 prefitError = _c->getVal();
6268 }
else if (prefitError == 0) {
6269 prefitError = _d->get<
RooAbsReal>()->getVal();
6275 if (pConstr->get<
RooGaussian>() && pConstr->browse().find(
".sigma")) {
6276 prefitError = pConstr->find(
".sigma")->get<
RooAbsReal>()->getVal();
6282 prefitVal /= prefitError;
6284 prefitError = 1. / sqrt(prefitError);
6286 if (!_v->getStringAttribute(
"nominal"))
6287 _v->setVal(prefitVal);
6288 _v->setError(prefitError);
6297 auto _globs =
globs();
6298 _args.add(_globs.argList());
6299 fr->setConstParList(_args);
6300 std::unique_ptr<RooArgList> _snap(
dynamic_cast<RooArgList *
>(_pars->snapshot()));
6301 for (
auto &
p : *_snap) {
6302 if (
auto atr =
p->getStringAttribute(
"initVal"); atr &&
dynamic_cast<RooRealVar *
>(
p))
6305 fr->setInitParList(*_snap);
6310 if (
auto _w =
ws(); _w) {
6311 auto checkFr = [&](
TObject *o) {
6315 for (
auto p :
pars()) {
6319 if (_fr->floatParsFinal().find(
p->
GetName()) ||
6320 std::abs(_fr->constPars().getRealValue(
p->
GetName(), std::numeric_limits<double>::quiet_NaN()) -
6326 if (_fr->constPars().find(
p->
GetName()) ||
6328 _fr->floatParsFinal().getRealValue(
p->
GetName(), std::numeric_limits<double>::quiet_NaN()) -
6337 std::unique_ptr<RooArgList> _pars(
6339 auto fr = std::make_shared<RooFitResult>(
TString::Format(
"%s-dirty", _fr->GetName()));
6341 fr->setFinalParList(*_pars);
6344 auto cov = _fr->reducedCovarianceMatrix(*_pars);
6346 for (
size_t i = 0; i < _pars->size(); i++) {
6347 if (
auto v =
dynamic_cast<RooRealVar *
>(_pars->at(i))) {
6348 cov(i, i) = pow(
v->getError(), 2);
6353 fr->setCovarianceMatrix(cov);
6359 auto _globs =
globs();
6360 _args.add(_globs.argList());
6361 fr->setConstParList(_args);
6362 std::unique_ptr<RooArgList> _snap(
dynamic_cast<RooArgList *
>(_pars->snapshot()));
6363 for (
auto &
p : *_snap) {
6364 if (
auto atr =
p->getStringAttribute(
"initVal"); atr &&
dynamic_cast<RooRealVar *
>(
p))
6367 fr->setInitParList(*_snap);
6370 return xRooNode(*_fr, std::make_shared<xRooNode>(*_w, std::make_shared<xRooNode>()));
6374 for (
auto o : _w->allGenericObjects()) {
6375 auto out = checkFr(o);
6380 auto out = checkFr(o);
6387 if (
auto fr = getObject<RooFitResult>(
".fitResult"); fr) {
6393 auto _coefs =
coefs();
6399 std::unique_ptr<RooArgList> _pars(
dynamic_cast<RooArgList *
>(
pars().
argList().selectByAttrib(
"Constant",
false)));
6400 auto fr = std::make_shared<RooFitResult>(
TUUID().AsString());
6402 fr->setFinalParList(*_pars);
6408 for (
int i = 0; i < prevCov->
GetNcols(); i++) {
6409 for (
int j = 0; j < prevCov->
GetNrows(); j++) {
6410 cov(i, j) = (*prevCov)(i, j);
6415 for (
auto &
p : fr->floatParsFinal()) {
6416 if (!prevCov || i >= prevCov->
GetNcols()) {
6418 cov(i, i) = pow(
v->getError(), 2);
6425 int covQualBackup = fr->covQual();
6426 fr->setCovarianceMatrix(cov);
6427 fr->setCovQual(covQualBackup);
6432 auto _globs =
globs();
6433 _args.add(_globs.argList());
6434 fr->setConstParList(_args);
6435 std::unique_ptr<RooArgList> _snap(
dynamic_cast<RooArgList *
>(_pars->snapshot()));
6436 for (
auto &
p : *_snap) {
6437 if (
auto atr =
p->getStringAttribute(
"initVal"); atr &&
dynamic_cast<RooRealVar *
>(
p))
6440 fr->setInitParList(*_snap);
6461 if (!std::isnan(low) && !std::isnan(high) && get<RooRealVar>()) {
6462 if (range && strlen(range)) {
6463 get<RooRealVar>()->setRange(range, low, high);
6465 get<RooRealVar>()->setRange(low, high);
6469 if (
auto o = get<RooAbsArg>(); o)
6470 o->setStringAttribute(
"range", range);
6477 std::string &out =
fRange;
6478 if (
auto o = get<RooAbsArg>(); o && o->getStringAttribute(
"range"))
6479 out = o->getStringAttribute(
"range");
6481 while (out.empty() && _parent) {
6482 if (
auto o = _parent->get<
RooAbsArg>(); o && o->getStringAttribute(
"range"))
6483 out = o->getStringAttribute(
"range");
6484 _parent = _parent->fParent;
6499 for (
auto opt : *defaultOpts) {
6502 for (
auto &i : nllOpts) {
6504 Info(
"nll",
"Overriding NLL Option: %s", o->GetName());
6515 if (!get<RooAbsPdf>()) {
6517 if (get<RooWorkspace>()) {
6518 std::shared_ptr<xRooNode> mainModel;
6524 throw std::runtime_error(
TString::Format(
"Workspace has multiple models, you must specify which to "
6525 "generate with (found at least %s and %s)",
6526 mainModel->GetName(),
c->GetName()));
6531 return mainModel->generate(fr, expected, seed);
6544 if (!get<RooAbsPdf>()) {
6546 if (get<RooWorkspace>()) {
6547 std::shared_ptr<xRooNode> mainModel;
6553 throw std::runtime_error(
TString::Format(
"Workspace has multiple models, you must specify which to "
6554 "build nll with (found at least %s and %s)",
6555 mainModel->GetName(),
c->GetName()));
6560 return mainModel->nll(
_data, opts);
6566 if (get<RooSimultaneous>()) {
6567 std::string selected;
6568 bool hasDeselected =
false;
6569 for (
auto c :
bins()) {
6571 hasDeselected =
true;
6574 cName = cName(cName.Index(
'=') + 1, cName.Length());
6575 if (!selected.empty())
6577 selected += cName.Data();
6590 _d = std::make_shared<xRooNode>(asi.first, *
this);
6593 std::make_shared<xRooNode>(
".globs", std::const_pointer_cast<RooAbsCollection>(asi.second), *_d));
6598 return nll(*_d, opts);
6601 auto _globs =
_data.globs();
6614 for (
int i = 0; i < opts.
GetSize(); i++) {
6617 if (strcmp(opts.
At(i)->
GetName(),
"GlobalObservables") == 0) {
6620 _opts->Add(opts.
At(i)->
Clone(
nullptr));
6628 std::dynamic_pointer_cast<RooAbsData>(
_data.fComp), *_opts);
6726 auto rangeName = (_range.empty()) ?
GetRange() : _range;
6727 if (!rangeName.empty()) {
6728 std::vector<TString> patterns;
6731 patterns.emplace_back(pattern);
6733 if (
auto s = get<RooSimultaneous>(); s) {
6738 for (
auto &
c :
bins()) {
6740 cName = cName(cName.
Index(
'=') + 1, cName.
Length());
6741 _cat.setLabel(cName);
6742 bool matchAny =
false;
6743 for (
auto &
p : patterns) {
6748 if (_cat.hasRange(
p) && _cat.inRange(
p)) {
6753 if ((matchAny && !invert) || (!matchAny && invert)) {
6758 }
else if (
get() && !get<RooAbsCollection>() && !
components().empty()) {
6762 std::vector<TObject *>
funcs;
6763 for (
auto &
c : out.components()) {
6764 bool matchAny =
false;
6765 for (
auto &
p : patterns) {
6771 if (!((matchAny && !invert) || (!matchAny && invert)))
6772 funcs.push_back(
c->get());
6776 if (!
funcs.empty()) {
6778 _pdf->setFloor(
false);
6784 }
else if (
auto fr = get<RooFitResult>()) {
6790 for (
auto c : _pars) {
6791 bool matchAny =
false;
6792 for (
auto &
p : patterns) {
6798 if (!((matchAny && !invert) || (!matchAny && invert))) {
6802 _pars.remove(_remPars,
true);
6804 auto _tmp = fr->reducedCovarianceMatrix(_pars);
6805 int covQualBackup = fr->covQual();
6806 fr->setCovarianceMatrix(_tmp);
6807 fr->setCovQual(covQualBackup);
6808 const_cast<RooArgList &
>(fr->floatParsFinal())
6809 .remove(_remPars,
true);
6812 }
else if (!
get() || get<RooAbsCollection>()) {
6816 bool notAllArgs =
false;
6817 bool isVars = (strcmp(
GetName(),
".vars") == 0);
6818 for (
auto c : *
this) {
6819 nobs += (
c->fFolder ==
"!robs" ||
c->fFolder ==
"!globs");
6820 bool matchAny =
false;
6821 for (
auto &
p : patterns) {
6823 (isVars &&
p ==
"x" && (
c->fFolder ==
"!robs" ||
c->fFolder ==
"!globs") && nobs == 1)) {
6828 if ((matchAny && !invert) || (!matchAny && invert)) {
6844 return get<RooArgList>() ?
xRooNode(std::make_shared<RooArgList>(),
fParent) : *
this;
6927 return static_cast<RooAbsPdf *
>(intpdf.absArg())->expectedEvents(nset);
6936 return getProjection(&intobs,
_normSet, (_normRange.Length() > 0 ? _normRange.Data() :
nullptr), code)->getVal();
6945 fFunc(
"func",
"func", this,
f),
6946 fCoef(
"coef",
"coef", this),
6947 fExpPdf(
"expPdf",
"expPdf", this)
6952 fCoef.setArg(*coef);
6954 if (expPdf && expPdf->canBeExtended() && !(coef &&
dynamic_cast<RooAddPdf *
>(expPdf))) {
6955 fExpPdf.setArg(*expPdf);
6956 }
else if (
auto _p =
dynamic_cast<RooAbsPdf *
>(&
f);
6960 fExpectedEventsMode = expEvMode;
6965 fFunc(
"func", this, other.fFunc),
6966 fCoef(
"coef", this, other.fCoef),
6967 fExpPdf(
"expPdf", this, other.fExpPdf),
6968 fExpectedEventsMode(other.fExpectedEventsMode)
6975 return fFunc->binBoundaries(obs, xlo, xhi);
6980 return (fExpectedEventsMode ? 1. : fFunc) *
6981 ((fExpPdf.absArg()) ?
static_cast<RooAbsPdf *
>(fExpPdf.absArg())->expectedEvents(
_normSet) : 1.) *
6982 (fCoef.absArg() ? fCoef : 1.);
6993#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 28, 00)
6994 double oo = getPropagatedError(fr, nset_in);
6995 if (std::isnan(oo)) {
7000 getParameters(&nset_in, allParamsInAbsReal);
7003 for (
auto *rrvFitRes : static_range_cast<RooRealVar *>(fr.
floatParsFinal())) {
7005 auto rrvInAbsReal =
static_cast<RooRealVar const *
>(allParamsInAbsReal.
find(*rrvFitRes));
7009 if (rrvFitRes->namePtr() == namePtr())
7013 if (!rrvFitRes->hasError() ||
7014 rrvFitRes->getError() <= std::abs(rrvFitRes->getVal()) * std::numeric_limits<double>::epsilon())
7023 if (std::abs(rrvInAbsReal->getVal() - rrvFitRes->getVal()) > 0.01 * rrvFitRes->getError()) {
7024 std::stringstream errMsg;
7026 <<
"RooAbsReal::getPropagatedError(): the parameters of the RooAbsReal don't have"
7027 <<
" the same values as in the fit result! The logic of getPropagatedError is broken in this case.";
7029 throw std::runtime_error(errMsg.str());
7032 paramList.
add(*rrvInAbsReal);
7034 if (paramList.
empty())
7037 std::vector<double> plusVar;
7038 std::vector<double> minusVar;
7039 plusVar.reserve(paramList.
size());
7040 minusVar.reserve(paramList.
size());
7046 for (std::size_t ivar = 0; ivar < paramList.
size(); ivar++) {
7048 auto &rrv =
static_cast<RooRealVar &
>(paramList[ivar]);
7050 double cenVal = rrv.
getVal();
7051 double errVal = sqrt(V(ivar, ivar));
7063 rrv.setVal(cenVal + errVal);
7064 plusVar.push_back(getVal(nset_in));
7067 rrv.setVal(cenVal - errVal);
7068 minusVar.push_back(getVal(nset_in));
7069#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
7093 std::vector<double> errVec(paramList.
size());
7094 for (std::size_t i = 0; i < paramList.
size(); i++) {
7095 errVec[i] = std::sqrt(V(i, i));
7096 for (std::size_t j = i; j < paramList.
size(); j++) {
7097 C(i, j) = V(i, j) / std::sqrt(V(i, i) * V(j, j));
7104 for (
unsigned int j = 0; j < plusVar.size(); j++) {
7105 F[j] = (plusVar[j] - minusVar[j]) / 2;
7109 double sum =
F * (C *
F);
7118 for (
auto *frv : static_range_cast<RooRealVar *>(fi.floatParsFinal())) {
7119 if (frv->getError() > 1
e-20) {
7120 fpf_stripped.
add(*frv);
7135 std::vector<int> fpf_idx;
7136 for (
Int_t i = 0; i < fpf.
size(); i++) {
7139 paramList.
add(*par);
7140 fpf_idx.push_back(i);
7144 std::vector<double> plusVar, minusVar;
7150 for (
Int_t ivar = 0; ivar < paramList.
size(); ivar++) {
7154 double cenVal = rrv.
getVal();
7155 double errVal = sqrt(V(ivar, ivar));
7158 ((
RooRealVar *)paramList.
at(ivar))->setVal(cenVal + errVal);
7161 plusVar.push_back(cloneFunc->
getVal(nset));
7164 ((
RooRealVar *)paramList.
at(ivar))->setVal(cenVal - errVal);
7167 minusVar.push_back(cloneFunc->
getVal(nset));
7175 std::vector<double> errVec(paramList.
size());
7176 for (
int i = 0; i < paramList.
size(); i++) {
7177 errVec[i] = sqrt(V(i, i));
7178 for (
int j = i; j < paramList.
size(); j++) {
7179 C(i, j) = V(i, j) / sqrt(V(i, i) * V(j, j));
7186 for (
unsigned int j = 0; j < plusVar.size(); j++) {
7187 F[j] = (plusVar[j] - minusVar[j]) / 2;
7191 double sum =
F * (C *
F);
7205 bool fExpectedEventsMode =
false;
7213 std::cout <<
"Got signal " << signum << std::endl;
7214 if (signum == SIGINT) {
7215 std::cout <<
"Keyboard interrupt while building histogram" << std::endl;
7225 auto _doSterilize = [](
RooAbsArg *obj) {
7228 for (
int i = 0; i < obj->numCaches(); i++) {
7234 p->setNormRange(
p->normRange());
7236#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
7241 p->setProxyNormSet(
nullptr);
7242 p->_lastNSet =
nullptr;
7245 obj->setValueDirty();
7247 if (
auto w = get<RooWorkspace>();
w) {
7249 for (
auto &
c :
w->components()) {
7268 nClients =
a->clients().size();
7269 for (
auto obj :
a->clients()) {
7271 if (
a->clients().size() != nClients) {
7276 }
while (
a->clients().size() != nClients);
7278 func(get<RooAbsArg>());
7293 out.fComp = std::shared_ptr<TH1>(
BuildHistogram(
nullptr, !content, errors, -1, -1, fr));
7294 }
else if (
vars.size() == 1) {
7296 out.fComp = std::shared_ptr<TH1>(
BuildHistogram(
v, !content, errors, 1, 0, fr));
7298 throw std::runtime_error(
"multi-dim histo not yet supported");
7301 if (
auto h = out.get<
TH1>()) {
7302 if (
h->GetXaxis()->IsAlphanumeric()) {
7304 h->GetXaxis()->SetName(
"xaxis");
7308 auto hCopy =
static_cast<TH1 *
>(
h->Clone(
"nominal"));
7315 std::map<std::string, int> colorByTitle;
7316 std::set<std::string> allTitles;
7317 bool titleMatchName =
true;
7318 std::map<std::string, TH1 *> histGroups;
7319 std::vector<TH1 *> hhs;
7327 for (
auto &
c : *comps) {
7328 if (
c->fFolder ==
"!.coeffs")
7333 if (!cms_coefs.
empty()) {
7335 std::shared_ptr<TH1> prevHist(
static_cast<TH1 *
>(
h->Clone()));
7336 for (
auto c : cms_coefs) {
7340 Form(
"ORIGNAME:%s",
c->GetName()));
7341 f->redirectServers(
RooArgSet(zero),
false,
true);
7347 if (strlen(hh->GetTitle()) == 0)
7348 hh->SetTitle(
c->GetName());
7349 titleMatchName &= (
TString(
c->GetName()) == hh->GetTitle() ||
7351 std::shared_ptr<TH1> nextHist(
static_cast<TH1 *
>(hh->Clone()));
7352 hh->Add(prevHist.get(), -1.);
7355 prevHist = nextHist;
7359 auto hh = samp->BuildHistogram(
v,
false,
false, !
v ? -1 : 1, !
v ? -1 : 0, fr);
7363 if (strlen(hh->GetTitle()) == 0)
7364 hh->SetTitle(samp->GetName());
7365 titleMatchName &= (
TString(samp->GetName()) == hh->GetTitle() ||
7369 for (
auto &hh : hhs) {
7370 if (
h->GetXaxis()->IsAlphanumeric()) {
7372 hh->GetXaxis()->SetName(
"xaxis");
7373 for (
int i = 1; i <= hh->GetNbinsX(); i++)
7374 hh->GetXaxis()->SetBinLabel(i,
h->GetXaxis()->GetBinLabel(i));
7377 if (histGroups.find(hh->GetTitle()) == histGroups.end()) {
7378 histGroups[hh->GetTitle()] = hh;
7381 histGroups[hh->GetTitle()]->Add(hh);
7385 auto hhMin = (hh->GetMinimum() == 0) ? hh->GetMinimum(1
e-9) : hh->GetMinimum();
7386 if (!stack->
GetHists() &&
h->GetMinimum() > hhMin) {
7388 if (hhMin >= 0 && newMin < 0)
7389 newMin = hhMin * 0.99;
7390 h->SetMinimum(newMin);
7392 if (
auto it = colorByTitle.find(hh->GetTitle()); it != colorByTitle.end()) {
7393 hh->SetFillColor(it->second);
7397 hh->SetFillColor((count++) % 100);
7400 for (
auto hh2 : hhs) {
7401 if (hh != hh2 && hh2->GetFillColor() == hh->GetFillColor()) {
7407 colorByTitle[hh->GetTitle()] = hh->GetFillColor();
7419 stack->
Add(hh, thisOpt);
7420 allTitles.insert(hh->GetTitle());
7428 size_t e = std::min(allTitles.begin()->size(), allTitles.rbegin()->size());
7430 bool goodPrefix =
false;
7431 std::string commonSuffix;
7432 if (titleMatchName && ll->
GetEntries() > 1) {
7433 while (ii <
e - 1 && allTitles.begin()->at(ii) == allTitles.rbegin()->at(ii)) {
7435 if (allTitles.begin()->at(ii) ==
'_' || allTitles.begin()->at(ii) ==
' ')
7441 while (!stop && commonSuffix.size() <
size_t(
e - 1)) {
7442 commonSuffix = allTitles.begin()->substr(allTitles.begin()->length() - commonSuffix.length() - 1);
7443 for (
auto &t : allTitles) {
7445 commonSuffix = commonSuffix.substr(1);
7451 if (commonSuffix.find(
'_') == std::string::npos) {
7454 commonSuffix = commonSuffix.substr(commonSuffix.find(
'_'));
7463 std::map<std::string, std::string> reducedTitles;
7464 while (reducedTitles.size() != allTitles.size()) {
7466 std::map<std::string, int> titlesMap;
7467 for (
auto &s : allTitles) {
7468 if (reducedTitles.count(s))
7470 titlesMap[s.substr(0, jj)]++;
7472 for (
auto &s : allTitles) {
7473 if (titlesMap[s.substr(0, jj)] == 1 && (jj >= s.length() || s.at(jj) ==
' ' || s.at(jj) ==
'_')) {
7474 reducedTitles[s] = s.substr(0, jj);
7480 for (
int i = ll->
GetEntries() - 1; i >= 0; i--) {
7482 _title = _title.substr(ii < _title.size() ? ii : 0);
7483 if (!commonSuffix.empty() &&
TString(_title).
EndsWith(commonSuffix.c_str()))
7484 _title = _title.substr(0, _title.length() - commonSuffix.length());
7491 *
dynamic_cast<TAttLine *
>(ll->
At(i)) = *_style;
7492 *
dynamic_cast<TAttFill *
>(ll->
At(i)) = *_style;
7497 h->GetListOfFunctions()->Add(stack,
"noclearsame");
7498 if (
h->GetSumw2() &&
h->GetSumw2()->GetSum()) {
7499 hCopy->SetFillStyle(3005);
7500 hCopy->SetFillColor(
h->GetLineColor());
7502 h->GetListOfFunctions()->Add(hCopy->Clone(
".copy"),
"e2same");
7507 h->GetListOfFunctions()->Add(hCopy,
"histsame");
7508 if (
h->GetSumw2() &&
h->GetSumw2()->GetSum()) {
7510 h->SetFillColor(
h->GetLineColor());
7511 h->SetMarkerStyle(0);
7526 auto rar = get<RooAbsReal>();
7536 if (binStart != -1 || binEnd != -1) {
7547 h =
new TH1D(rar->GetName(), rar->GetTitle(), 1, 0, 1);
7548 h->GetXaxis()->SetBinLabel(1, rar->GetName());
7549 h->GetXaxis()->SetName(rar->GetName());
7554 bool setTitle =
false;
7558 h =
new TH1D(rar->GetName(), rar->GetTitle(), 1, 0, 1);
7560 h->GetXaxis()->SetBinLabel(1, rar->GetName());
7561 h->SetBinContent(1, rar->getVal());
7563 h->SetBinError(1,
x->getError());
7564 h->SetMaximum(
x->hasMax() ?
x->getMax()
7565 : (
h->GetBinContent(1) + std::max(std::abs(
h->GetBinContent(1) * 0.1), 50.)));
7566 h->SetMinimum(
x->hasMin() ?
x->getMin()
7567 : (
h->GetBinContent(1) - std::max(std::abs(
h->GetBinContent(1) * 0.1), 50.)));
7572 TString binningName = (_ax && _ax->GetParent() ==
x) ? _ax->GetName() : rar->getStringAttribute(
"binning");
7573 if (binningName ==
"")
7574 binningName = rar->GetName();
7575 if (
x->hasBinning(binningName)) {
7576 if (
x->getBinning(binningName).isUniform()) {
7577 h =
new TH1D(rar->GetName(), rar->GetTitle(),
x->numBins(binningName) <= 0 ? 100 :
x->numBins(binningName),
7578 x->getMin(binningName),
x->getMax(binningName));
7580 h =
new TH1D(rar->GetName(), rar->GetTitle(),
x->numBins(binningName),
x->getBinning(binningName).array());
7582 h->GetXaxis()->SetTitle(
x->getBinning(binningName).GetTitle());
7584 }
else if (
auto _boundaries =
7585 _or_func( (std::list<double> *)(
nullptr),
7586 rar->binBoundaries(*
x, -std::numeric_limits<double>::infinity(),
7587 std::numeric_limits<double>::infinity()));
7589 std::vector<double> _bins;
7590 for (
auto &
b : *_boundaries) {
7591 if (_bins.empty() || std::abs(_bins.back() -
b) > 1
e-5 * _bins.back())
7594 h =
new TH1D(rar->GetName(), rar->GetTitle(), _bins.size() - 1, &_bins[0]);
7596 }
else if (!
x->hasMax() || !
x->hasMin()) {
7598 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(),
x->getVal() * 0.2,
x->getVal() * 5);
7600 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(),
x->getBinning().array());
7604 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(rar->GetName()), 0,
v->numBins(rar->GetName()));
7606 for (
int i = 0; i < cat->numTypes(); i++) {
7608 h->GetXaxis()->SetBinLabel(i + 1, cat->getLabel());
7612 if (
auto o =
dynamic_cast<TObject *
>(
v); o && !setTitle) {
7613 h->GetXaxis()->SetTitle(o->GetTitle());
7619 if (
auto s =
style(
nullptr,
false); s) {
7624 if (strlen(
h->GetXaxis()->GetTitle()) == 0)
7633 if (empty && !errors) {
7639 auto _coefs =
coefs();
7654 if (!
GETDMP(fr, _finalPars)) {
7682 for (
int i = 0; i < prevCov->
GetNcols(); i++) {
7683 for (
int j = 0; j < prevCov->
GetNrows(); j++) {
7684 cov(i, j) = (*prevCov)(i, j);
7690 if (!prevCov || i >= prevCov->
GetNcols()) {
7691 cov(i, i) = pow(
dynamic_cast<RooRealVar *
>(p2)->getError(), 2);
7695 int covQualBackup = fr->
covQual();
7706 int covQualBackup = fr->
covQual();
7714 bool hasErrors =
false;
7732 binEnd =
h->GetNbinsX();
7734 bool needBinWidth =
false;
7737 if (
x && (
p || _coefs.get() || rar->getAttribute(
"density"))) {
7739 needBinWidth =
true;
7743 spdf && spdf->
canBeExtended() && !spdf->getFloor() && !_coefs.get()) {
7755 for (
auto o : _obs) {
7757 rr->removeRange(
"coordRange");
7768 bool hasRange =
false;
7769 for (
auto o : normSet) {
7780 for (
auto pdf :
bins()) {
7787 dynamic_cast<RooAbsPdf *
>(_pdf)->setNormRange(
"coordRange");
7789 newrar->addPdf(*_pdf, pdf->coords()[
"channelCat"]->get<
RooCategory>()->getLabel());
7793 rar =
p->createProjection(
7797 dynamic_cast<RooAbsPdf *
>(rar)->setNormRange(
"coordRange");
7801 p->setNormRange(
"coordRange");
7806 rar = std::unique_ptr<RooAbsReal>{rar->createIntegral(
7812 std::unique_ptr<RooAbsReal>{rar->createIntegral(*_obs.get<
RooArgList>() )}
7818 bool scaleExpected = (
p &&
p->canBeExtended() && !_coefs.get());
7822 std::unique_ptr<RooArgSet> snap(normSet.
snapshot());
7824 std::vector<double> lapTimes;
7825 bool warned =
false;
7826 if (binStart == -1 && binEnd == -1) {
7829 for (
int i = std::max(1, binStart); i <= std::min(
h->GetNbinsX(), binEnd); i++) {
7832 x->setVal(
h->GetBinCenter(i));
7836 if (
x && !
x->inRange(
"coordRange"))
7841 r = rar->getVal(
p ? &normSet :
nullptr);
7842#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
7847 if (
r && _coefs.get()) {
7851 r *=
h->GetBinWidth(i);
7853 if (scaleExpected) {
7856 r *= (
p->expectedEvents(normSet));
7859 h->SetBinContent(i,
r);
7867 .getSimplePropagatedError(*fr, normSet);
7868#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
7870 p->_normSet =
nullptr;
7875 .getPropagatedError(
7881 res *=
h->GetBinWidth(i);
7883 h->SetBinError(i, res);
7886 lapTimes.push_back(timeIt.
RealTime());
7887 double time_estimate =
7888 (lapTimes.size() > 1)
7889 ? (
h->GetNbinsX() * (std::accumulate(lapTimes.begin() + 1, lapTimes.end(), 0.) / (lapTimes.size() - 1)))
7891 if (!warned && (lapTimes.at(0) > 10 || (lapTimes.size() > 2 && time_estimate > 60.))) {
7893 t2.
Add(time_estimate);
7894 Warning(
"BuildHistogram",
"Building this histogram will take until %s", t2.
AsString());
7904 Warning(
"BuildHistogram",
"Skipping errors for remaining bins");
7917 std::vector<RooAbsArg *> extra;
7920 for (
auto _pdf : s->servers()) {
7922 extra.push_back(_pdf);
7925 extra.push_back(rar);
7928 for (
auto a : extra)
7934 if (!
p && !rar->getAttribute(
"density") && !needBinWidth) {
7935 h->GetYaxis()->SetTitle(rar->getStringAttribute(
"units"));
7936 }
else if ((
p &&
p->canBeExtended()) || (!
p && needBinWidth)) {
7937 h->GetYaxis()->SetTitle(
"Events");
7939 h->GetYaxis()->SetTitle(
"Probability Mass");
7941 h->GetYaxis()->SetMaxDigits(3);
7954 return std::numeric_limits<double>::quiet_NaN();
7955 return node->GetBinContent(bin);
7961 if (binStart != binEnd || !
fParent) {
7966 std::vector<double> out;
7967 if (get<RooAbsData>()) {
7975 if (binStart == binEnd && binStart == -1) {
7978 for (
int i = 0; i <
g->GetN(); i++)
7979 integral +=
g->GetPointY(i);
7980 out.push_back(integral);
7984 for (
int i = binStart - 1; i <
g->GetN() && (binEnd == 0 || i < binEnd); i++) {
7985 out.push_back(
g->GetPointY(i));
7991 bool doIntegral =
false;
7992 if (binStart == binEnd && binStart == -1) {
8002 binEnd =
h->GetNbinsX();
8006 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
8007 tot +=
h->GetBinContent(i);
8011 for (
int i = binStart; i <= binEnd; i++) {
8012 out.push_back(
h->GetBinContent(i));
8021 if (
auto a = get<RooAbsArg>();
a) {
8023 for (
auto &
l :
a->servers()) {
8043 if (
auto o =
get(); o) {
8052#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
8056 for (
int i = 0; i <
p->fCGnx; i++) {
8057 for (
int j = 0; j <
p->fCGny; j++) {
8058 p->fCollideGrid[i + j *
p->fCGnx] =
true;
8061 p->FillCollideGrid(o);
8065 Int_t nxmax =
p->fCGnx - iw - 1 -
p->fCGnx *
p->GetRightMargin();
8066 Int_t nymax =
p->fCGny - ih - 1 -
p->fCGny *
p->GetTopMargin();
8068 for (
Int_t j = nymax; j >= 0; j--) {
8069 for (
Int_t i = nxmax; i >= 0; i--) {
8070 if (
p->Collide(i, j, iw, ih)) {
8081 return p->PlaceBox(o,
w,
h, xl, yb,
"trw");
8089 gPad->PaintModified();
8095 auto l =
new TPaveText(
gPad->GetLeftMargin() + 0.02, 1. -
gPad->GetTopMargin() - 0.08, 0.6,
8096 1. -
gPad->GetTopMargin() - 0.08);
8097 l->SetBorderSize(0);
8098 if (
l->GetTextSize() == 0)
8106 l->ConvertNDCtoPad();
8112 if (
auto p =
dynamic_cast<TLegend *
>(
gPad->GetPrimitive(
"legend"));
p) {
8115 double w =
p->GetX2NDC() -
p->GetX1NDC();
8116 double h =
p->GetY2NDC() -
p->GetY1NDC();
8118 gPad->PaintModified();
8122 x = std::max(
x, (
gPad->GetLeftMargin() + 0.02));
8123 y = std::max(
y, (
gPad->GetBottomMargin() + 0.02));
8124 x = std::min(
x, (1. -
gPad->GetRightMargin() - 0.02) -
w);
8125 y = std::min(
y, (1. -
gPad->GetTopMargin() - 0.02) -
h);
8126 h = std::min(
h, (1. -
gPad->GetTopMargin() - 0.02) -
y);
8127 w = std::min(
w, (1. -
gPad->GetRightMargin() - 0.02) -
x);
8139 while ((
p !=
p->GetMother()) && (
p =
p->GetMother())) {
8140 if (
auto q =
dynamic_cast<TVirtualPad *
>(
p->GetPrimitive(
"legend"));
q) {
8148 if (
p && strcmp(
p->
GetName(),
"legend") == 0) {
8153 gPad->GetBottomMargin());
8157 l =
new TLegend(0.6, 1. -
gPad->GetTopMargin() - 0.08, 0.75, 1. -
gPad->GetTopMargin() - 0.08);
8158 l->SetBorderSize(0);
8159 if (
l->GetTextSize() == 0)
8165 l->SetName(
"legend");
8167 l->ConvertNDCtoPad();
8178 for (
auto a : *
l->GetListOfPrimitives()) {
8179 if (!strcmp(
dynamic_cast<TLegendEntry *
>(
a)->GetLabel(), title))
8182 if (
l->GetListOfPrimitives()->GetEntries() > 20)
8185 l->AddEntry(o, title, opt);
8186 if (
auto nObj =
l->GetListOfPrimitives()->GetEntries(); nObj > 0) {
8188 int nn =
l->GetNColumns();
8190 if (nObj > 1 && (nObj % nn) == 1) {
8191 l->SetNColumns(
l->GetNColumns() + 1);
8192 l->SetX1NDC(
l->GetX2NDC() - 0.15 *
l->GetNColumns());
8194 l->SetY1NDC(
l->GetY2NDC() - 0.05 *
gPad->GetHNDC() * std::ceil((
double(nObj) /
l->GetNColumns())));
8209 fPad->GetCanvas()->Paint();
8210 fPad->GetCanvas()->Update();
8211#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
8212 fPad->GetCanvas()->ResetUpdated();
8227 if (
gROOT->FromPopUp()) {
8228 gROOT->SetFromPopUp(
false);
8231 }
catch (
const std::exception &
e) {
8234 (
gROOT->GetListOfBrowsers()->At(0))
8237 "Exception",
e.what(),
8240 gROOT->SetFromPopUp(
true);
8249 if (
auto ir = get<RooStats::HypoTestInverterResult>()) {
8253 }
else if (get<RooStats::HypoTestResult>()) {
8266 auto _dsets =
fParent->datasets();
8269 for (
auto &
d : _dsets) {
8270 if (
d->get()->TestBit(1 << 20)) {
8271 dsetName =
d->get()->GetName();
8275 auto hs =
fParent->nll(dsetName.
Data()).hypoSpace(get<RooRealVar>()->GetName());
8276 hs.limits(
"cls visualize");
8288 [](
double a,
double b,
double) {
8291 if (
b == 0 &&
a == 0)
8298 [](
double n,
double b,
double sigma) {
8302 t0 = 2. * (((
n == 0) ? 0 :
n * log(
n /
b)) - (
n -
b));
8305 double b_hathat = 0.5 * (
b - sigma2 + sqrt(pow(
b - sigma2, 2) + 4 *
n * sigma2));
8308 t0 = 2. * (((
n == 0) ? 0 :
n * log(
n / b_hathat)) + b_hathat -
n + pow(
b - b_hathat, 2) / (2. * sigma2));
8312 return (
n >=
b) ? sqrt(t0) : -sqrt(t0);
8320 std::vector<double> xPoints;
8323 int _idx = sOpt2.
Index(
"x=");
8324 int _eidx = sOpt2.
Index(
';', _idx);
8325 TString varPart = sOpt(_idx + 2, (_eidx < 0 ? sOpt2.
Length() : _eidx) - (_idx + 2));
8328 if (
auto _idx2 = varPart.
Index(
"("); _idx2 > 0) {
8329 varName = varPart(0, _idx2);
8339 }
else if (ii == 1) {
8341 }
else if (ii == 2) {
8349 for (
double x = min;
x <= max;
x += (max - min) / (nBins - 1)) {
8350 xPoints.push_back(
x);
8352 }
else if (nBins == 1)
8353 xPoints.push_back((min + max) / 2.);
8355 v = getObject<RooAbsRealLValue>(varName.Data()).get();
8357 Error(
"Draw",
"Could not find variable %s", varName.Data());
8360 if (xPoints.empty() && !
obs().
find(varName.Data())) {
8362 for (
int i = 0; i <
v->numBins(
GetName()); i++) {
8380 }
else if (get<RooAbsPdf>()) {
8382 forceNames = sOpt(sOpt2.
Index(
"force") + 5, sOpt2.
Length());
8383 sOpt = sOpt(0, sOpt2.
Index(
"force"));
8384 sOpt2 = sOpt2(0, sOpt2.
Index(
"force"));
8386 Error(
"Draw",
"Can only compute forces with PDFs");
8390 bool hasOverlay = sOpt2.
Contains(
"overlay");
8394 overlayName = sOpt(sOpt2.
Index(
"overlay") + 7, sOpt2.
Length());
8395 sOpt = sOpt(0, sOpt2.
Index(
"overlay"));
8396 sOpt2 = sOpt2(0, sOpt2.
Index(
"overlay"));
8401 sOpt +=
"auxSignif";
8403 std::string auxPlotTitle;
8414 bool nostack = sOpt.
Contains(
"nostack");
8416 bool hasSame = sOpt.
Contains(
"same");
8418 bool hasGoff = sOpt.
Contains(
"goff");
8420 bool hasFR = sOpt.
Contains(
"pull") && !get<RooFitResult>();
8422 bool hasText = sOpt.
Contains(
"text");
8423 bool hasErrorOpt = sOpt.
Contains(
"e");
8427 if (auxPlotTitle ==
"Signif")
8434 TH1 *hAxis =
nullptr;
8436 auto clearPad = []() {
8438 if (
gPad->GetNumber() == 0) {
8450 if (!hasSame || !pad) {
8461 if (hAxis =
dynamic_cast<TH1 *
>(o); hAxis)
8477 auto adjustYRange = [&](
double min,
double max,
TH1 *hh =
nullptr,
bool symmetrize =
false) {
8485 double ymin = hh->GetMinimum();
8486 double ymax = hh->GetMaximum();
8487 if (hh->GetMaximumStored() == -1111)
8489 if (hh->GetMinimumStored() == -1111) {
8492 }
else if (
ymin < 0) {
8500 if (hh->GetSumw2()) {
8501 double smallestErrDown3 = -std::numeric_limits<double>::infinity();
8502 double smallestErrUp3 = std::numeric_limits<double>::infinity();
8503 for (
int i = 1; i <= hh->GetNbinsX(); i++) {
8504 smallestErrDown3 = std::max(smallestErrDown3, hh->GetBinContent(i) - 3 * hh->GetBinError(i));
8505 smallestErrUp3 = std::min(smallestErrUp3, hh->GetBinContent(i) + 3 * hh->GetBinError(i));
8507 max = std::max(max, smallestErrUp3);
8508 min = std::min(min, smallestErrDown3);
8510 bool change =
false;
8522 double down = hh->GetBinContent(1) -
ymin;
8523 double up =
ymax - hh->GetBinContent(1);
8525 ymax = hh->GetBinContent(1) + down;
8527 ymin = hh->GetBinContent(1) - up;
8530 if (hh == hAxis && pad && !pad->
GetLogy() &&
ymin > 0 && (log10(
ymax) - log10(max)) >= 3) {
8534 if (hh == hAxis && pad &&
ymin == 0 && pad->
GetLogy()) {
8539 hh->SetMinimum(
ymin);
8540 hh->SetMaximum(
ymax);
8541 hh->GetYaxis()->Set(1,
ymin,
ymax);
8548 double ymax = -std::numeric_limits<double>::infinity();
8549 double ymin = std::numeric_limits<double>::infinity();
8550 for (
int i = 0; i <
gr->
GetN(); i++) {
8557 if (!xPoints.empty()) {
8562 out->SetFillColor(out->GetLineColor());
8563 out->SetMarkerStyle(0);
8564 out->SetFillStyle(hasErrorOpt ? 3005 : 0);
8566 for (
auto &
x : xPoints) {
8570 out->SetPointEYlow(out->GetN() - 1,
GetError());
8571 out->SetPointEYhigh(out->GetN() - 1, out->GetErrorYlow(out->GetN() - 1));
8577 out->Draw(
TString(hasSame ?
"L" :
"AL") + (hasErrorOpt ?
"3" :
""));
8598 gPad->GetFrame()->SetFillStyle(1001);
8599 gPad->SetTopMargin(0);
8600 gPad->SetBottomMargin(0);
8601 gPad->SetName(
"pull");
8605 Error(
"Draw",
"Couldn't find pull graph");
8608 pullGraph->SetName(
"nominal");
8612 auto scaleHist =
static_cast<TH1 *
>(pullGraph->FindObject(
"scales"));
8614 throw std::runtime_error(
"Could not find scales in fit result");
8616 for (
auto i = 0; i < pullGraph->GetN(); i++) {
8618 g->
SetName(scaleHist->GetXaxis()->GetBinLabel(i + 1));
8621 Warning(
"Draw",
"Found a non-var in the floatParsFinal list: %s - this shouldn't happen",
g->GetName());
8625 "%s=%g +/- %s [%g,%g]", strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName(), _p->getVal(),
8626 _p->hasAsymError() ?
TString::Format(
"(%g,%g)", _p->getAsymErrorHi(), _p->getAsymErrorLo()).
Data()
8628 scaleHist->GetBinContent(i + 1), scaleHist->GetBinError(i + 1)));
8629 g->SetPoint(0, pullGraph->GetPointX(i), pullGraph->GetPointY(i));
8630 g->SetPointEYhigh(0, pullGraph->GetErrorYhigh(i));
8631 g->SetPointEYlow(0, pullGraph->GetErrorYlow(i));
8632 g->SetEditable(
true);
8633 g->SetHighlight(
true);
8634 g->SetMarkerStyle(20);
8635 g->SetMarkerSize(0.5);
8643 _thisClone->AppendPad();
8656 if (
auto _simPdf = get<RooSimultaneous>(); _simPdf) {
8658 auto _channels =
bins();
8659 for (
auto &_v : _channels) {
8660 if (!_v->IsHidden())
8687 dynamic_cast<TPad *
>(pad)->DivideSquare(_size, 1
e-9, 1
e-9);
8693 std::vector<TString> chanPatterns;
8694 if (_range && strlen(_range)) {
8697 chanPatterns.emplace_back(pattern);
8700 for (
auto &_v : _channels) {
8707 chanVar.setLabel(cName);
8708 bool inRange = chanPatterns.empty();
8709 for (
auto &
p : chanPatterns) {
8710 if (chanVar.inRange(
p)) {
8718 gPad->SetLeftMargin(std::min(
gPad->GetLeftMargin() * (1. /
gPad->GetWNDC()), 0.3));
8728 if (!
get() || get<RooArgList>()) {
8733 for (
auto &_v : *
this) {
8736 if (strcmp(
GetName(),
".vars") == 0) {
8740 if (strcmp(_v->get()->GetName(),
"1") == 0 || strcmp(_v->get()->GetName(),
"ONE") == 0 ||
8743 if (_v->get()->InheritsFrom(
"RooConstVar"))
8754 dynamic_cast<TPad *
>(pad)->DivideSquare(_size, 1
e-9, 1
e-9);
8757 for (
auto &_v : *
this) {
8760 if (strcmp(
GetName(),
".vars") == 0) {
8764 if (strcmp(_v->get()->GetName(),
"1") == 0 || strcmp(_v->get()->GetName(),
"ONE") == 0 ||
8767 if (_v->get()->InheritsFrom(
"RooConstVar"))
8776 gPad->SetLeftMargin(std::min(
gPad->GetLeftMargin() * (1. /
gPad->GetWNDC()), 0.3));
8794 if (
auto fr = get<RooFitResult>(); fr) {
8798 auto hist = fr->correlationHist(fr->GetName());
8799 hist->SetTitle(fr->GetTitle());
8802 hist->SetStats(
false);
8803 hist->SetDirectory(
nullptr);
8806 hist->GetXaxis()->SetTickSize(0);
8807 hist->GetYaxis()->SetTickSize(0);
8808 hist->SetMinimum(-100);
8811 gPad->SetGrid(1, 1);
8822 std::string poiName;
8825 poiName = sOpt3(sOpt3.
Index(
"breakdown:") + 10, sOpt3.
Length());
8827 std::unique_ptr<RooAbsCollection> _poi(fr->floatParsFinal().selectByAttrib(
"poi",
true));
8828 if (_poi->empty()) {
8829 throw std::runtime_error(
"No floating poi in the fit");
8830 }
else if (_poi->size() != 1) {
8831 throw std::runtime_error(
"Multiple poi in the fit");
8833 poiName = _poi->first()->GetName();
8837 throw std::runtime_error(
TString::Format(
"Cannot find parameter %s", poiName.c_str()));
8839 std::set<std::string> groups;
8840 for (
auto p : fr->floatParsFinal()) {
8843 }
else if (
p->getStringAttribute(
"group")) {
8844 groups.insert(
p->getStringAttribute(
"group"));
8857 roundedVal.second *= .1;
8865 for (
auto group : groups) {
8867 double variance = pow(
dynamic_cast<RooRealVar *
>(
poi)->getError(), 2);
8868 for (
auto p : fr->floatParsFinal()) {
8871 }
else if ((
p->getStringAttribute(
"group") &&
group ==
p->getStringAttribute(
"group")) ||
8877 int idx =
pars.index(poiName.c_str());
8878 double reducedVar = fr->conditionalCovarianceMatrix(
pars)(idx, idx);
8879 if (reducedVar > variance) {
8880 Warning(
"Draw",
"breakdown group %s variance bigger than preceding?",
group.c_str());
8886 std::pair(sqrt(variance - reducedVar), roundedVal.second));
8898 double variance = fr->conditionalCovarianceMatrix(*
poi)(0, 0);
8914 out->SetTitle(
"Fit Result Pulls");
8915 std::vector<TString> graphLabels;
8918 ugraph->
SetTitle(
"Fit Result Pulls");
8919 std::vector<TString> ugraphLabels;
8920 std::map<std::string, double> scale;
8921 std::map<std::string, double>
offset;
8922 for (
auto &
p : fr->floatParsFinal()) {
8927 if (std::isnan(_v->getErrorHi()) || std::isnan(_v->getErrorLo())) {
8928 Warning(
"Draw",
"%s error is invalid", _v->GetName());
8933 double prefitError = 0;
8934 double prefitVal = 0;
8935 double customScale = 0;
8938 prefitError = ip->getError();
8939 prefitVal = ip->getVal();
8942 std::shared_ptr<xRooNode> pConstr;
8945 if (_vv->hasRange(
"pullScale")) {
8946 customScale = (_vv->getMax(
"pullScale") - _vv->getMin(
"pullScale")) / 2.;
8949 for (
auto &
c : _constr) {
8952 bool isServer =
true;
8955 for (
auto s :
c->get<
RooAbsArg>()->servers()) {
8956 if (strcmp(s->GetName(),
p->
GetName()) == 0) {
8977 if (pConstr->get<
RooPoisson>() && pConstr->find(
".x")) {
8978 std::string xName = pConstr->find(
".x")->get()->GetName();
8979 prefitVal = pConstr->find(
".x")->get<
RooAbsReal>()->getVal();
8980 for (
auto &_d : pConstr->vars()) {
8981 if (strcmp(
p->
GetName(), _d->get()->GetName()) == 0)
8983 if (xName == _d->get()->GetName())
8989 prefitVal /= prefitError;
8991 prefitError = 1. / sqrt(prefitError);
8992 }
else if (
auto _g = pConstr->get<
RooGaussian>(); _g) {
8994 (pConstr->find(
".sigma")) ? pConstr->find(
".sigma")->get<
RooAbsReal>()->getVal() : prefitError;
8996 (pConstr->find(
".x")) ? pConstr->find(
".x")->get<
RooAbsReal>()->getVal() : 0;
8997 if (pConstr->find(
".x") &&
9000 prefitVal = pConstr->find(
".mean")->get<
RooAbsReal>()->getVal();
9005 prefitError = customScale;
9006 if (prefitError == 0) {
9007 Warning(
"Draw",
"failed to determine prefit error of %s, using post-fit error",
p->
GetName());
9008 prefitError = _v->getError();
9010 out->SetPoint(out->GetN(), out->GetN(), (_v->getVal() - prefitVal) / prefitError);
9011 out->SetPointError(out->GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
9012 (_v->getErrorHi()) / prefitError);
9013 graphLabels.push_back(
p->
GetName());
9019 prefitError = customScale;
9020 if (prefitError == 0) {
9022 prefitError = (std::max({_v->getMax() - _v->getVal(), _v->getVal() - _v->getMin(), 4.}) / 4);
9023 ugraph->
SetPoint(ugraph->
GetN(), ugraph->
GetN(), (_v->getVal() - prefitVal) / prefitError);
9024 ugraph->
SetPointError(ugraph->
GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
9025 (_v->getErrorHi()) / prefitError);
9026 ugraphLabels.push_back(
p->
GetName());
9028 out->SetPoint(out->GetN(), out->GetN(), (_v->getVal() - prefitVal) / prefitError);
9029 out->SetPointError(out->GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
9030 (_v->getErrorHi()) / prefitError);
9031 graphLabels.push_back(
p->
GetName());
9039 prefitError = customScale;
9040 if (prefitError == 0) {
9041 prefitError = (std::max({_v->getMax() - _v->getVal(), _v->getVal() - _v->getMin(), 4.}) / 4);
9043 ugraph->
SetPoint(ugraph->
GetN(), ugraph->
GetN(), (_v->getVal() - prefitVal) / prefitError);
9044 ugraph->
SetPointError(ugraph->
GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
9045 (_v->getErrorHi()) / prefitError);
9046 ugraphLabels.push_back(
p->
GetName());
9054 for (
int i = 0; i < ugraph->
GetN(); i++)
9056 int nUnconstrained = ugraph->
GetN();
9059 tmpList.
Add(ugraph);
9060 graph->Merge(&tmpList);
9063 for (
auto &
l : ugraphLabels) {
9064 graphLabels.push_back(
l);
9068 graph->SetMarkerStyle(20);
9069 graph->SetMarkerSize(0.5);
9071 graph->SetMaximum(4);
9072 graph->SetMinimum(-4);
9077 std::vector<std::pair<double, std::string>> covariances;
9078 std::string poiName;
9079 double maxImpact = 0;
9083 poiName = sOpt3(sOpt3.
Index(
"impact:") + 7, sOpt3.
Length());
9085 std::unique_ptr<RooAbsCollection> _poi(fr->floatParsFinal().selectByAttrib(
"poi",
true));
9086 if (_poi->empty()) {
9087 throw std::runtime_error(
"No floating poi in the fit");
9088 }
else if (_poi->size() != 1) {
9089 throw std::runtime_error(
"Multiple poi in the fit");
9091 poiName = _poi->first()->GetName();
9093 RooAbsArg *
poi = fr->floatParsFinal().find(poiName.c_str());
9095 throw std::runtime_error(
TString::Format(
"Cannot find parameter %s", poiName.c_str()));
9097 size_t poiIdx = fr->floatParsFinal().index(*
poi);
9106 for (
auto &label : graphLabels) {
9107 covariances.emplace_back(fr->covarianceMatrix()(poiIdx, fr->floatParsFinal().index(label)) /
9108 dynamic_cast<RooRealVar *
>(fr->floatParsFinal().find(label))->getError(),
9111 std::sort(covariances.begin(), covariances.end(),
9112 [&](std::pair<double, std::string> i, std::pair<double, std::string> j) {
9113 return doHorizontal ? (std::abs(i.first) < std::abs(j.first))
9114 : (std::abs(i.first) > std::abs(j.first));
9118 std::vector<TString> sortedLabels;
9119 maxImpact = (doHorizontal) ? covariances.back().first
9120 : covariances.front().first;
9121 for (
auto &
c : covariances) {
9126 c.first *= 4. / (maxImpact * 1.2);
9127 sortedLabels.push_back(
c.second);
9129 for (; i < graphLabels.size(); i++) {
9130 if (graphLabels[i] ==
c.second) {
9140 tmpList2.
Add(&sortedGraph);
9141 graph->Merge(&tmpList2);
9143 graphLabels = sortedLabels;
9144 graph->SetTitle(
"Fit Result Impact");
9150 hist =
new TH2D(
GetName(), fr->GetTitle(), 100, -4, 4, std::max(
graph->GetN(), 1), -0.5,
9151 std::max(
graph->GetN(), 1) - 0.5);
9153 for (
auto &
l : graphLabels) {
9156 if (!graphLabels.empty())
9160 hist =
new TH2D(
GetName(), fr->GetTitle(), std::max(
graph->GetN(), 1), -0.5, std::max(
graph->GetN(), 1) - 0.5,
9163 for (
auto &
l : graphLabels) {
9166 if (!graphLabels.empty())
9174 auto histCopy =
dynamic_cast<TH1 *
>(hist->
Clone(
".axis"));
9177 auto _axis = (doHorizontal ? histCopy->GetYaxis() : histCopy->GetXaxis());
9187 graph->GetHistogram()->GetXaxis()->Set(std::max(
graph->GetN(), 1), -0.5, std::max(
graph->GetN(), 1) - 0.5);
9188 for (
int ii = 1; ii <= _axis->GetNbins(); ii++) {
9189 graph->GetHistogram()->GetXaxis()->SetBinLabel(ii, _axis->GetBinLabel(ii));
9204 gPad->Divide(1, 1, 1
e-9, 1
e-9);
9208 gPad->SetLeftMargin(0.4);
9210 gPad->SetBottomMargin(0.4);
9213 auto pNamesHist =
dynamic_cast<TH1F *
>(
graph->GetHistogram()->Clone(
"scales"));
9214 pNamesHist->
Sumw2();
9215 pNamesHist->SetDirectory(
nullptr);
9217 for (
int ii = 1; ii <=
graph->GetN(); ii++) {
9218 auto _p = fr->floatParsFinal().find(_axis->GetBinLabel(ii));
9219 pNamesHist->SetBinContent(ii,
offset[_p->GetName()]);
9220 pNamesHist->SetBinError(ii, scale[_p->GetName()]);
9221 _axis->SetBinLabel(ii, strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName());
9227 for (
int ii = 2; ii >= 1; ii--) {
9231 pullBox->SetPoint(0, (doHorizontal) ? -ii : -0.5, (doHorizontal) ? -0.5 : 0);
9232 pullBox->SetPoint(1, (doHorizontal) ? ii : (_axis->GetNbins() - 0.5 - nUnconstrained),
9233 (doHorizontal) ? -0.5 : 0);
9234 pullBox->SetPointError(0, 0, (doHorizontal) ? (_axis->GetNbins() - nUnconstrained) : ii);
9235 pullBox->SetPointError(1, 0, (doHorizontal) ? (_axis->GetNbins() - nUnconstrained) : ii);
9239 auto pullLine =
new TGraph;
9240 pullLine->
SetName(
"0sigmaLine");
9242 pullLine->SetPoint(0, -0.5, 0);
9243 pullLine->SetPoint(1, _axis->GetNbins() - 0.5, 0);
9244 pullLine->SetLineStyle(2);
9245 pullLine->SetEditable(
false);
9249 if (nUnconstrained > 0) {
9251 pullLine->
SetName(
"dividerLine");
9253 pullLine->SetPoint(0,
graph->GetN() - 0.5 - nUnconstrained, -100);
9254 pullLine->SetPoint(1,
graph->GetN() - 0.5 - nUnconstrained, 100);
9255 pullLine->SetLineStyle(2);
9256 pullLine->SetEditable(
false);
9262 new TPaveText(
gPad->GetLeftMargin(), 1. -
gPad->GetTopMargin(), 1. -
gPad->GetRightMargin(), 0.98,
"NDCNB");
9269 std::string covQualTxt;
9270 switch (fr->covQual()) {
9271 case -1: covQualTxt =
"Unknown";
break;
9272 case 0: covQualTxt =
"Not calculated";
break;
9273 case 1: covQualTxt =
"Approximate";
break;
9274 case 2: covQualTxt =
"Forced Positive-Definite";
break;
9275 case 3: covQualTxt =
"Accurate";
break;
9280 std::string statusCodes;
9281 for (
unsigned int i = 0; i < fr->numStatusHistory(); i++) {
9282 statusCodes +=
TString::Format(
" %s = %d", fr->statusLabelHistory(i), fr->statusCodeHistory(i));
9289 gPad->SetTicks(0, 0);
9293 if (
int(
gPad->GetCanvas()->GetWh()) < pNamesHist->GetNbinsX() * 15) {
9294 gPad->GetCanvas()->SetCanvasSize(
gPad->GetCanvas()->GetWw(), pNamesHist->GetNbinsX() * 15);
9298 double factor = 475. /
gPad->GetCanvas()->GetWh();
9303 new TGaxis(_axis->GetXmin(), -4, _axis->GetXmin(), 4, -1.2 * maxImpact, 1.2 * maxImpact, 510,
"-S");
9307 : ((
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(10 / factor)) /
9316 : ((
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(10 / factor)) / (
gPad->GetY2() -
gPad->GetY1())));
9321 : ((
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(10 / factor)) / (
gPad->GetY2() -
gPad->GetY1())));
9324 _axis->SetLabelSize(
9325 (_axis->GetLabelFont() % 10 > 2)
9327 : ((
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(10 / factor)) / (
gPad->GetY2() -
gPad->GetY1())));
9328 histCopy->GetXaxis()->SetTickLength(histCopy->GetXaxis()->GetTickLength() * factor);
9330 histCopy->GetYaxis()->SetTickLength(histCopy->GetYaxis()->GetTickLength() * factor);
9332 histCopy->GetXaxis()->SetTitleOffset(histCopy->GetXaxis()->GetTitleOffset() * factor);
9333 histCopy->GetXaxis()->SetLabelOffset(histCopy->GetXaxis()->GetLabelOffset() * factor);
9336 histCopy->GetXaxis()->SetTitleOffset(histCopy->GetXaxis()->GetTitleOffset() * factor);
9337 histCopy->GetXaxis()->SetLabelOffset(histCopy->GetXaxis()->GetLabelOffset() * factor);
9341 for (
int tt = 0;
tt < 2;
tt++) {
9342 auto impact =
static_cast<TH1 *
>(
9345 impact->GetYaxis()->SetTitle(
TString::Format(
"#Delta%s/#sigma", poiName.c_str()));
9346 impact->SetBarWidth(0.9);
9347 impact->SetBarOffset(0.05);
9348 impact->SetLineColor(
kBlack);
9349 impact->SetFillColor(
kAzure - 4);
9350 impact->SetFillStyle(
tt == 0 ? 3013 : 1001);
9352 static_cast<TH1 *
>(impact->Clone(
TString::Format(
"%s_impact-",
tt == 0 ?
"prefit" :
"postfit")));
9354 impact2->SetFillColor(
kCyan);
9355 for (
int ii = 1; ii <= pNamesHist->GetNbinsX(); ii++) {
9356 for (
auto &
c : covariances) {
9357 if (
c.second != pNamesHist->GetXaxis()->GetBinLabel(ii))
9359 auto vv =
dynamic_cast<RooRealVar *
>(fr->floatParsFinal().find(
c.second.c_str()));
9360 auto vv_init =
dynamic_cast<RooRealVar *
>(fr->floatParsInit().find(
c.second.c_str()));
9361 impact->SetBinContent(ii, ((
tt == 0 && !vv_init->hasError()) || !
vv->hasError())
9363 :
c.first *
vv->getError() /
vv->getErrorHi() *
9364 (
tt == 0 ? (vv_init->getErrorHi() /
vv->getErrorHi()) : 1.));
9365 impact2->SetBinContent(ii, ((
tt == 0 && !vv_init->hasError()) || !
vv->hasError())
9367 :
c.first *
vv->getError() /
vv->getErrorLo() *
9368 (
tt == 0 ? (vv_init->getErrorLo() /
vv->getErrorLo()) : 1.));
9375 for (
int ii = -1; ii <= 1; ii++) {
9376 auto pullLine =
new TGraph;
9379 pullLine->SetPoint(0, -0.5, ii);
9380 pullLine->SetPoint(1, hist->
GetNbinsY() - 0.5, ii);
9381 pullLine->SetLineStyle(2);
9382 pullLine->SetEditable(
false);
9387 new TLegend(0.02, doHorizontal ? (1. - 0.22 * factor) : 0.02, 0.27, (doHorizontal ? 1. : 0.24));
9394 : ((
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(10 / factor)) /
9400 leg1->
AddEntry(hist->
FindObject(
"prefit_impact+"),
"#theta = #hat{#theta}+#Delta#theta",
"f");
9401 leg1->
AddEntry(hist->
FindObject(
"prefit_impact-"),
"#theta = #hat{#theta}-#Delta#theta",
"f");
9404 leg1->
AddEntry(hist->
FindObject(
"postfit_impact+"),
"#theta = #hat{#theta}+#Delta#theta",
"f");
9405 leg1->
AddEntry(hist->
FindObject(
"postfit_impact-"),
"#theta = #hat{#theta}-#Delta#theta",
"f");
9411 new TPaveText(
gPad->GetLeftMargin(), 1. -
gPad->AbsPixeltoY(14), 1. -
gPad->GetRightMargin(), 1.,
"NDC");
9418 : ((
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(10 / factor)) / (
gPad->GetY2() -
gPad->GetY1())));
9421 title->
AddText(histCopy->GetTitle());
9426 graph->SetEditable(
false);
9427 pNamesHist->SetLineWidth(0);
9428 pNamesHist->SetMarkerSize(0);
9429 graph->GetListOfFunctions()->Add(pNamesHist,
"same");
9433 for (
int p = 0;
p <
graph->GetN();
p++) {
9436 graph->GetErrorXhigh(
p));
9439 if (
f->InheritsFrom(
"TH1")) {
9448 else if (
auto g =
dynamic_cast<TGraph *
>(
f)) {
9449 for (
int p = 0;
p <
g->GetN();
p++) {
9450 g->SetPoint(
p,
g->GetPointY(
p),
g->GetPointX(
p));
9453 }
else if (
auto l =
dynamic_cast<TLine *
>(
f)) {
9456 l->
SetY1(_axis->GetXmax());
9457 l->
SetY2(_axis->GetXmax());
9463 graph->SetName(
"pulls");
9468 histCopy->Draw((sOpt.
Contains(
"impact") && !doHorizontal)
9484 auto hh =
dynamic_cast<TH1 *
>(histCopy->Clone(
".axiscopy"));
9488 (sOpt.
Contains(
"impact") && !doHorizontal)
9501 for (
auto c : s->bins()) {
9502 auto _pad =
dynamic_cast<TPad *
>(
gPad->GetPrimitive(
c->GetName()));
9505 auto ds =
c->datasets().find(
GetName());
9507 std::cout <<
" no ds " <<
GetName() << std::endl;
9519 if (!s && hasSame) {
9522 bool doneDraw =
false;
9523 for (
auto o : *
gPad->GetListOfPrimitives()) {
9538 auto dataGraph =
BuildGraph(
v,
false, (!s && hasSame) ?
gPad :
nullptr);
9543 dataGraph->SetMarkerSize(dataGraph->GetMarkerSize() *
gPad->GetWNDC());
9548 for (
int i = 0; i < dataGraph->GetN(); i++)
9549 tot += dataGraph->GetPointY(i);
9550 dataGraph->Scale(1. / tot);
9555 dataGraph->Draw(
"Az0p");
9556 addLegendEntry(dataGraph, strlen(dataGraph->GetTitle()) ? dataGraph->GetTitle() :
GetName(),
"pEX0");
9562 bool noPoint =
false;
9565 for (
auto o : *
gPad->GetListOfPrimitives()) {
9566 if (
auto h =
dynamic_cast<TH1 *
>(o);
9567 h && strcmp(
h->GetXaxis()->GetName(),
dynamic_cast<TObject *
>(
v)->
GetName()) == 0) {
9568 dataGraph->SetPointY(0,
h->Interpolate(dataGraph->GetPointX(0)));
9575 if (
auto _pad =
dynamic_cast<TPad *
>(
gPad->FindObject(
"auxPad")); _pad) {
9576 if (
auto h =
dynamic_cast<TH1 *
>(_pad->GetPrimitive(
"auxHist"));
h) {
9579 histName = histName(0, histName.
Index(
'|'));
9580 if (
auto mainHist =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(histName));
9584 auto ratioGraph =
dynamic_cast<TGraphAsymmErrors *
>(dataGraph->Clone(dataGraph->GetName()));
9586 for (
int i = 0; i < ratioGraph->GetN(); i++) {
9587 double val = ratioGraph->GetPointY(i);
9588 int binNum = mainHist->FindFixBin(ratioGraph->GetPointX(i));
9589 double nom = mainHist->GetBinContent(binNum);
9590 double nomerr = mainHist->GetBinError(binNum);
9592 std::get<0>(
auxFunctions[
h->GetYaxis()->GetTitle()])(ratioGraph->GetPointY(i), nom, nomerr);
9593 double yup = std::get<0>(
auxFunctions[
h->GetYaxis()->GetTitle()])(val + ratioGraph->GetErrorYhigh(i),
9596 double ydown = yval - std::get<0>(
auxFunctions[
h->GetYaxis()->GetTitle()])(
9597 val - ratioGraph->GetErrorYlow(i), nom, nomerr);
9598 if (!std::isnan(yval)) {
9599 ratioGraph->SetPointY(i, yval);
9600 if (!std::isnan(yup))
9601 ratioGraph->SetPointEYhigh(i, yup);
9602 if (!std::isnan(ydown))
9603 ratioGraph->SetPointEYlow(i, ydown);
9608 while (i < ratioGraph->GetN()) {
9609 if (ratioGraph->GetPointY(i) == 0 && ratioGraph->GetErrorYhigh(i) == 0 &&
9610 ratioGraph->GetErrorYlow(i) == 0) {
9611 ratioGraph->RemovePoint(i);
9616 auto _tmpPad =
gPad;
9618 ratioGraph->Draw(
"z0psame");
9619 auto minMax = graphMinMax(ratioGraph);
9620 adjustYRange(minMax.first, minMax.second,
h, std::get<1>(
auxFunctions[
h->GetYaxis()->GetTitle()]));
9626 dataGraph->Draw(
"z0p same");
9627 addLegendEntry((noPoint) ?
nullptr : dataGraph, strlen(dataGraph->GetTitle()) ? dataGraph->GetTitle() :
GetName(),
9628 noPoint ?
"" :
"pEX0");
9631 adjustYRange(minMax.first, minMax.second);
9647 gr->
Draw(hasSame ?
"P" :
"AP");
9651 if (forceNames !=
"") {
9654 bool _drawn =
false;
9660 std::vector<double> valuesToDo = {initPar->
getVal()};
9661 if (initPar->hasError() || initPar->hasAsymError()) {
9662 valuesToDo.push_back(initPar->getVal() + initPar->getErrorLo());
9663 valuesToDo.push_back(initPar->getVal() + initPar->getErrorHi());
9666 for (
auto valueToDo : valuesToDo) {
9668 for (
auto &
d : _dsets) {
9669 if (!
d->get()->TestBit(1 << 20))
9673 auto _obs =
d->obs();
9674 auto x = _obs.find((
v) ?
dynamic_cast<TObject *
>(
v)->
GetName() : emptyHist->GetXaxis()->GetName());
9678 for (
int i = 0; i < nevent; i++) {
9681 for (
const auto &_c : _coords) {
9683 if (cat->getIndex() != theData->get()->getCatIndex(cat->GetName())) {
9693 auto val = _nll.pars()->getRealValue(initPar->GetName());
9695 _nll.pars()->setRealValue(initPar->GetName(), valueToDo);
9696 auto nllVal = _nll.getEntryVal(i);
9697 _nll.pars()->setRealValue(initPar->GetName(), initPar->getVal());
9698 auto nllVal2 = _nll.getEntryVal(i);
9699 _nll.pars()->setRealValue(initPar->GetName(), val);
9705 auto val = _nll.pars()->getRealValue(initPar->GetName());
9707 _nll.pars()->setRealValue(initPar->GetName(), valueToDo);
9708 auto _extTerm = _nll.extendedTerm();
9709 _nll.pars()->setRealValue(initPar->GetName(), initPar->getVal());
9710 auto _extTerm2 = _nll.extendedTerm();
9711 _nll.pars()->setRealValue(initPar->GetName(), val);
9712 for (
int i = 1; i <= emptyHist->GetNbinsX(); i++) {
9713 emptyHist->SetBinContent(i,
9714 emptyHist->GetBinContent(i) + (_extTerm2 - _extTerm) / emptyHist->GetNbinsX());
9715 emptyHist->SetBinError(i, 0);
9717 emptyHist->GetYaxis()->SetTitle(
"log (L(#theta)/L(#theta_{0}))");
9718 emptyHist->SetTitle(
TString::Format(
"#theta = %g", (ii > 1) ? valueToDo : val));
9720 emptyHist->SetLineColor(
kBlack);
9722 emptyHist->SetLineColor(
kRed);
9723 }
else if (ii == 3) {
9724 emptyHist->SetLineColor(
kBlue);
9726 emptyHist->Draw(_drawn ?
"same" :
"");
9733 auto rar = get<RooAbsReal>();
9753 v = getObject<RooAbsLValue>(
h->GetXaxis()->GetName()).get();
9755 if (
h->GetXaxis()->IsAlphanumeric()) {
9760 if (rar->InheritsFrom(
"RooAbsPdf") && !(rar->InheritsFrom(
"RooRealSumPdf") || rar->InheritsFrom(
"RooAddPdf"))) {
9763 rar->leafNodeServerList(&s);
9777 ss +=
TString::Format(
"%s=%g", strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName(), _v->getVal());
9778 if (_v->hasError()) {
9789 gPad->SetGrid(0, 0);
9791 gPad->SetGrid(1, 1);
9795 h->GetNbinsX() == 1 || rar->getAttribute(
"BinnedLikelihood") ||
9797 std::unique_ptr<std::list<double>>(rar->binBoundaries(*
dynamic_cast<RooAbsRealLValue *
>(
vv),
9798 -std::numeric_limits<double>::infinity(),
9799 std::numeric_limits<double>::infinity()))))
9805 if (dOpt ==
"LF2" && !
components().empty()) {
9808 bool allHist =
true;
9822 gROOT->SetEditHistograms(
true);
9824 gROOT->SetEditHistograms(
false);
9838 bool hasError(
false);
9839 for (
int i = 0; i <
h->GetSumw2N(); i++) {
9840 if (
h->GetSumw2()->At(i)) {
9851 if (!hasSame &&
h->GetYaxis()->GetTitleFont() % 10 == 2) {
9852 h->GetYaxis()->SetTitleOffset(1.);
9855 TH1 *errHist =
nullptr;
9858 h->SetFillColor(
h->GetLineColor());
9859 h->SetMarkerStyle(0);
9860 errHist =
dynamic_cast<TH1 *
>(
h->Clone(
Form(
"%s_err",
h->GetName())));
9864 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
9865 h->SetBinError(i, 0);
9877 auto _hist = (errHist) ? errHist :
h;
9878 auto hCopy = (errHist) ?
nullptr :
dynamic_cast<TH1 *
>(
h->Clone());
9881 _hist->GetListOfFunctions()->Add(node);
9882 _hist->GetListOfFunctions()->Add(
new TExec(
9885 "gROOT->SetEditHistograms(true);auto h = dynamic_cast<TH1*>(gPad->GetPrimitive(\"%s\")); if(h) { double "
9886 "range= h->GetMaximum()-h->GetMinimum(); if(auto n "
9887 "= dynamic_cast<xRooNode*>(h->GetListOfFunctions()->FindObject(\"%s\")); n && "
9888 "n->TestBit(TObject::kNotDeleted) && n->get<RooRealVar>()->getVal() != h->GetBinContent(1)) {"
9889 "h->SetBinContent(1, "
9890 "TString::Format(\"%%.2g\",int(h->GetBinContent(1)/(range*0.01))*range*0.01).Atof());n->SetContent( "
9891 "h->GetBinContent(1) ); for(auto pp : *h->GetListOfFunctions()) if(auto hh = "
9892 "dynamic_cast<TH1*>(pp))hh->SetBinContent(1,h->GetBinContent(1));} if(h->GetBinContent(1)==0.) "
9893 "h->SetBinContent(1,range*0.005); gPad->Modified();gPad->Update(); }",
9894 _hist->GetName(), node->GetName())));
9900 _hist->GetListOfFunctions()->Add(hCopy,
"TEXT HIST same");
9901 _hist->SetBinError(1, 0);
9903 _hist->SetStats(
false);
9905 _hist->Draw(((errHist) ?
"e2" :
""));
9910 bool overlayExisted =
false;
9913 if (
auto existing =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(
h->GetName())); existing) {
9918 overlayExisted =
true;
9920 TString oldStyle = (rar && rar->getStringAttribute(
"style")) ? rar->getStringAttribute(
"style") :
"";
9921 h->SetTitle(overlayName);
9947 rar->setStringAttribute(
"style", oldStyle ==
"" ?
nullptr : oldStyle.
Data());
9971 h->Draw(dOpt + sOpt);
9980 std::map<std::string, int> colorByTitle;
9981 std::set<std::string> allTitles;
9982 bool titleMatchName =
true;
9983 std::map<std::string, TH1 *> histGroups;
9984 std::vector<TH1 *> hhs;
9990 if (!rarNode->components().empty()) {
9991 auto comps = rarNode->components()[0];
9992 for (
auto &
c : *comps) {
9993 if (
c->fFolder ==
"!.coeffs")
9997 if (!cms_coefs.
empty()) {
9999 std::shared_ptr<TH1> prevHist(
static_cast<TH1 *
>(
h->Clone()));
10000 for (
auto c : cms_coefs) {
10002 std::unique_ptr<RooAbsReal>
f(
10003 dynamic_cast<RooAbsReal *
>(rarNode->components()[0]->get()->
Clone(
"tmpCopy")));
10005 Form(
"ORIGNAME:%s",
c->GetName()));
10006 f->redirectServers(
RooArgSet(zero),
false,
true);
10012 if (strlen(hh->GetTitle()) == 0)
10013 hh->SetTitle(
c->GetName());
10014 titleMatchName &= (
TString(
c->GetName()) == hh->GetTitle() ||
10016 std::shared_ptr<TH1> nextHist(
static_cast<TH1 *
>(hh->Clone()));
10017 hh->Add(prevHist.get(), -1.);
10020 prevHist = nextHist;
10023 for (
auto &samp : rarNode->components()) {
10024 auto hh = samp->BuildHistogram(
v);
10026 hh->Scale(sf->
getVal());
10028 if (strlen(hh->GetTitle()) == 0)
10029 hh->SetTitle(samp->GetName());
10030 titleMatchName &= (
TString(samp->GetName()) == hh->GetTitle() ||
10034 for (
auto &hh : hhs) {
10036 if (histGroups.find(hh->GetTitle()) == histGroups.end()) {
10037 histGroups[hh->GetTitle()] = hh;
10040 histGroups[hh->GetTitle()]->Add(hh);
10044 auto hhMin = (hh->GetMinimum() == 0) ? hh->GetMinimum(1
e-9) : hh->GetMinimum();
10045 if (!stack->
GetHists() &&
h->GetMinimum() > hhMin) {
10047 if (hhMin >= 0 && newMin < 0)
10048 newMin = hhMin * 0.99;
10049 adjustYRange(newMin,
h->GetMaximum());
10062 stack->
Add(hh, thisOpt);
10063 allTitles.insert(hh->GetTitle());
10066 stack->
Draw(
"noclear same");
10070 h->Draw(
"axissame");
10077 size_t e = std::min(allTitles.begin()->size(), allTitles.rbegin()->size());
10079 bool goodPrefix =
false;
10080 std::string commonSuffix;
10081 if (titleMatchName && ll->
GetEntries() > 1) {
10082 while (ii <
e - 1 && allTitles.begin()->at(ii) == allTitles.rbegin()->at(ii)) {
10084 if (allTitles.begin()->at(ii) ==
'_' || allTitles.begin()->at(ii) ==
' ')
10090 while (!stop && commonSuffix.size() <
size_t(
e - 1)) {
10091 commonSuffix = allTitles.begin()->substr(allTitles.begin()->length() - commonSuffix.length() - 1);
10092 for (
auto &t : allTitles) {
10094 commonSuffix = commonSuffix.substr(1);
10100 if (commonSuffix.find(
'_') == std::string::npos) {
10103 commonSuffix = commonSuffix.substr(commonSuffix.find(
'_'));
10112 std::map<std::string, std::string> reducedTitles;
10113 while (reducedTitles.size() != allTitles.size()) {
10115 std::map<std::string, int> titlesMap;
10116 for (
auto &s : allTitles) {
10117 if (reducedTitles.count(s))
10119 titlesMap[s.substr(0, jj)]++;
10121 for (
auto &s : allTitles) {
10122 if (titlesMap[s.substr(0, jj)] == 1 && (jj >= s.length() || s.at(jj) ==
' ' || s.at(jj) ==
'_')) {
10123 reducedTitles[s] = s.substr(0, jj);
10129 for (
int i = ll->
GetEntries() - 1; i >= 0; i--) {
10131 _title = _title.substr(ii < _title.size() ? ii : 0);
10132 if (!commonSuffix.empty() &&
TString(_title).
EndsWith(commonSuffix.c_str()))
10133 _title = _title.substr(0, _title.length() - commonSuffix.length());
10140 for (
auto ho : *ll) {
10141 TH1 *hh =
dynamic_cast<TH1 *
>(ho);
10144 bool createdStyle = (
xRooNode(*hh, *
this).
style(
nullptr,
false) ==
nullptr);
10146 if (createdStyle) {
10153 for (
auto ho2 : *ll) {
10154 TH1 *hh2 =
dynamic_cast<TH1 *
>(ho2);
10168 *
dynamic_cast<TAttLine *
>(hh) = *_style;
10169 *
dynamic_cast<TAttFill *
>(hh) = *_style;
10175 }
else if (!overlayExisted) {
10186 errHist->
Draw(dOpt + (dOpt.
Contains(
"LF2") ?
"e3same" :
"e2same"));
10187 double ymax = -std::numeric_limits<double>::infinity();
10188 double ymin = std::numeric_limits<double>::infinity();
10189 for (
int i = 1; i <= errHist->
GetNbinsX(); i++) {
10195 adjustYRange(
h->GetMinimum() * 0.9,
h->GetMaximum() * 1.1);
10198 if ((!auxPlotTitle.empty()) && !hasSame) {
10200 double padFrac = 0.3;
10201 auto _tmpPad =
gPad;
10202 gPad->SetBottomMargin(padFrac);
10203 auto ratioPad =
new TPad(
"auxPad",
"aux plot", 0, 0, 1, padFrac);
10204 ratioPad->SetFillColor(_tmpPad->GetFillColor());
10205 ratioPad->SetNumber(1);
10206 ratioPad->SetBottomMargin(ratioPad->GetBottomMargin() / padFrac);
10207 ratioPad->SetTopMargin(0.04);
10208 ratioPad->SetLeftMargin(
gPad->GetLeftMargin());
10209 ratioPad->SetRightMargin(
gPad->GetRightMargin());
10211 TH1 *ratioHist =
dynamic_cast<TH1 *
>((errHist) ? errHist->
Clone(
"auxHist") :
h->
Clone(
"auxHist"));
10220 auxPlotTitle.c_str()));
10223 ratioPad->SetGridy();
10225 for (
int i = 1; i <= ratioHist->
GetNbinsX(); i++) {
10233 double rHeight = 1. / padFrac;
10241#if ROOT_VERSION_CODE < ROOT_VERSION(6, 26, 00)
10250 auto _h =
dynamic_cast<TH1 *
>(ratioHist->
Clone(
"auxHist_clone"));
10252 _h->SetFillColor(0);
10258 TString::Format(
"auto h1 = (TH1*)%p; auto h2 = (TH1*)%p; if(h2->GetXaxis()->GetFirst() != "
10259 "h1->GetXaxis()->GetFirst() || h1->GetXaxis()->GetLast()!=h2->GetXaxis()->GetLast()) "
10260 "{h2->GetXaxis()->SetRange(h1->GetXaxis()->GetFirst(),h1->GetXaxis()->GetLast());if(gPad) "
10261 "{gPad->GetCanvas()->Paint();gPad->GetCanvas()->Update();}}",
10262 (
void *)ratioHist, (
void *)(
h))));
10263 ratioHist->
Draw((errHist ?
"e2" :
""));
10267 }
else if (
auto ratioPad =
dynamic_cast<TPad *
>(
gPad->GetPrimitive(
"auxPad")); hasSame && ratioPad) {
10271 if (
auto hr =
dynamic_cast<TH1 *
>(ratioPad->GetPrimitive(
"auxHist"));
10273 TString histName = hr->GetTitle();
10275 histName = histName(0, histName.
Index(
'|'));
10277 if (
auto hnom =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(histName)); hnom) {
10278 h =
dynamic_cast<TH1 *
>(
h->Clone(
h->GetName()));
10281 for (
int i = 1; i <= hnom->GetNbinsX(); i++) {
10282 double val =
h->GetBinContent(i);
10283 double err =
h->GetBinError(i);
10284 h->SetBinContent(i, std::get<0>(
auxFunctions[hr->GetYaxis()->GetTitle()])(
10285 h->GetBinContent(i), hnom->GetBinContent(i), hnom->GetBinError(i)));
10286 h->SetBinError(i, std::get<0>(
auxFunctions[hr->GetYaxis()->GetTitle()])(
10287 val + err, hnom->GetBinContent(i), hnom->GetBinError(i)) -
10288 h->GetBinContent(i));
10290 auto _tmpPad =
gPad;
10293 if (
auto existing =
dynamic_cast<TH1 *
>(ratioPad->GetPrimitive(
h->GetName())); existing) {
10298 overlayExisted =
true;
10305 double ymax = -std::numeric_limits<double>::infinity();
10306 double ymin = std::numeric_limits<double>::infinity();
10307 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
10308 ymax = std::max(
ymax,
h->GetBinContent(i) +
h->GetBinError(i));
10309 ymin = std::min(
ymin,
h->GetBinContent(i) -
h->GetBinError(i));
10338 if (
auto _pdf = get<RooAbsPdf>();
10339 !hasSame && _pdf &&
coefs().empty()) {
10342 for (
auto &
d : _dsets) {
10343 if (
d->get()->TestBit(1 << 20)) {
10362 if (
auto w = get<RooWorkspace>();
w) {
10365#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
10374 Error(
"SaveAs",
"json format workspaces only in ROOT 6.26 onwards");
10379#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
10383 for (
auto &
c :
w->components()) {
10384 c->_eocache =
nullptr;
10388 if (!
w->writeToFile(
filename, sOpt !=
"update")) {
10392 if (
auto fitDb =
dynamic_cast<TFile *
>(
gROOT->GetListOfFiles()->FindObject(
"fitDatabase"))) {
10397 auto dir =
dest->GetDirectory(source->
GetName());
10402 auto key =
dynamic_cast<TKey *
>(k);
10412 if (dir->FindKey(key->GetName()))
10415 if (strcmp(classname,
"ROOT::Fit::FitConfig") == 0) {
10417 dir->WriteObject(fc, key->GetName());
10420 TObject *obj = key->ReadObj();
10422 dir->WriteTObject(obj, key->
GetName());
10429 CopyDir(fitDb, std::make_unique<TFile>(
filename,
"UPDATE").
get());
10436#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
10438 for (
auto &
c :
w->components()) {
10439 c->setExpensiveObjectCache(
w->expensiveObjectCache());
10449 return std::numeric_limits<double>::quiet_NaN();
10456 double err = std::numeric_limits<double>::quiet_NaN();
10458 std::unique_ptr<RooAbsCollection> _snap;
10463 _pars = _fr->floatParsFinal();
10464 _pars = _fr->constPars();
10468 auto _coefs =
coefs();
10476 p->setNormRange(rangeName);
10477#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 27, 00)
10480 out *=
p->expectedEvents(*_obs.get<
RooArgList>());
10481#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
10483 p->_normSet =
nullptr;
10487 p->setNormRange(
nullptr);
10488 }
else if (
auto p2 =
dynamic_cast<RooAbsReal *
>(
get()); p2) {
10490 auto f = std::shared_ptr<RooAbsReal>(
10491 p2->createIntegral(*std::unique_ptr<RooArgSet>(p2->getObservables(*_obs.get<
RooArgList>())),
10495 out *=
f->getVal();
10498 }
else if (get<RooAbsData>()) {
10501 auto ax = (rangeName) ?
GetXaxis() :
nullptr;
10502 auto rv = (ax) ?
dynamic_cast<RooRealVar *
>(ax->GetParent()) :
nullptr;
10503 auto cv = (ax && !rv) ?
dynamic_cast<RooCategory *
>(ax->GetParent()) :
nullptr;
10505 for (
auto &
v : vals) {
10508 if (rv && !rv->inRange(ax->GetBinCenter(i), rangeName))
10510 if (cv && !cv->isStateInRange(rangeName, ax->GetBinLabel(i)))
10517 out = std::numeric_limits<double>::quiet_NaN();
10520 _pars.RooAbsCollection::operator=(*_snap);
10522 return std::make_pair(out, err);
10534 if (binStart != binEnd || !
fParent) {
10540 std::vector<double> out;
10546 std::shared_ptr<RooFitResult> fr = std::dynamic_pointer_cast<RooFitResult>(_fr.
fComp);
10549 auto _coefs =
coefs();
10559 fr = std::dynamic_pointer_cast<RooFitResult>(frn.fComp);
10562 if (!
GETDMP(fr.get(), _finalPars)) {
10586 if (!prevCov ||
size_t(prevCov->
GetNcols()) < fr->floatParsFinal().size()) {
10589 for (
int i = 0; i < prevCov->
GetNcols(); i++) {
10590 for (
int j = 0; j < prevCov->
GetNrows(); j++) {
10591 cov(i, j) = (*prevCov)(i, j);
10596 for (
auto &
p : fr->floatParsFinal()) {
10597 if (!prevCov || i >= prevCov->
GetNcols()) {
10598 cov(i, i) = pow(
dynamic_cast<RooRealVar *
>(
p)->getError(), 2);
10602 int covQualBackup = fr->covQual();
10603 fr->setCovarianceMatrix(cov);
10604 fr->setCovQual(covQualBackup);
10607 bool doBinWidth =
false;
10608 auto ax = (binStart == -1 && binEnd == -1) ?
nullptr :
GetXaxis();
10615 normSet.
add(*
dynamic_cast<RooAbsArg *
>(ax->GetParent()));
10618 if (
auto p =
dynamic_cast<RooAbsPdf *
>(o); ax && (
p || _coefs.get() || o->getAttribute(
"density"))) {
10624 binEnd = ax->GetNbins();
10629 for (
int bin = binStart; bin <= binEnd; bin++) {
10631 dynamic_cast<RooAbsLValue *
>(ax->GetParent())->setBin(bin - 1, ax->GetName());
10638#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
10640 p->_normSet =
nullptr;
10650 .getPropagatedError(*fr, normSet);
10653 res *= ax->GetBinWidth(bin);
10655 out.push_back(res);
10662 std::string cling::printValue(
const xRooNode *
v ) {
10663 if(!
v)
return "nullptr\n";
10666 size_t left =
v->size();
10669 if(!out.empty()) out +=
",";
else out +=
"{";
10670 out +=
n->GetName();
10671 if(out.length()>100 && left > 0) {
10681 return "<empty node>";
10683 return Form(
"Name: %s",
v->GetName());
#define ROOT_VERSION(a, b, c)
#define ROOT_VERSION_CODE
RooArgSet * _normSet
Pointer to set with observables used for normalization.
RooAbsData * _data
Pointer to original input dataset.
RooSetProxy _paramSet
Parameters of the test statistic (=parameters of the input function)
RooAbsReal * _func
Pointer to original input function.
virtual RooAbsTestStatistic * create(const char *name, const char *title, RooAbsReal &real, RooAbsData &data, const RooArgSet &projDeps, Configuration const &cfg)=0
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 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 data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void funcs
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
double GetBinLowEdge(Int_t bin) const override
Return low edge of bin.
double GetBinUpEdge(Int_t bin) const override
Return up edge of bin.
Int_t FindFixBin(double x) const override
Find bin number corresponding to abscissa x.
void Set(Int_t nbins, const double *xbins) override
Initialize axis with variable bins.
RooAbsRealLValue * rvar() const
void SetTitle(const char *title) override
Set the title of the TNamed.
void Set(Int_t nbins, double xmin, double xmax) override
Initialize axis with fix bins.
Int_t FindFixBin(const char *label) const override
Find bin number with label.
RooAbsLValue * var() const
const RooAbsBinning * binning() const
void Set(Int_t nbins, const float *xbins) override
Initialize axis with variable bins.
const char * GetTitle() const override
Returns title of object.
double GetBinWidth(Int_t bin) const override
Return bin width.
PadRefresher(TVirtualPad *p)
A class which maps the current values of a RooRealVar (or a set of RooRealVars) to one of a number of...
bool isBinnedDistribution(const RooArgSet &obs) const override
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
bool selfNormalized() const override
Shows if a PDF is self-normalized, which means that no attempt is made to add a normalization term.
double getSimplePropagatedError(const RooFitResult &fr, const RooArgSet &nset_in) const
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
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)
xRooNode filter(const xRooNode &range) const
void _scan_(const char *what="plr", double nToys=0, const char *xvar="", int nPointsX=0, double lowX=0, double highX=0, const char *constParValues="")
std::vector< std::shared_ptr< xRooNode > > fBrowsables
xRooNLLVar nll(const xRooNode &_data, std::initializer_list< RooCmdArg > nllOpts) const
xRooNode poi() const
List of parameters of interest: parameters marked as "of interest" These parameters have the "poi" at...
void SetName(const char *name) override
Set the name of the TNamed.
TGListTreeItem * GetTreeItem(TBrowser *b) const
void SetTitle(const char *title) override
Set the title of the TNamed.
xRooNode Multiply(const xRooNode &child, Option_t *opt="")
xRooNode Replace(const xRooNode &node)
xRooNode datasets() const
xRooNode Remove(const xRooNode &child)
xRooNode globs() const
List of global observables of this node.
xRooNode Combine(const xRooNode &rhs)
bool SetBinData(int bin, double value, const char *dataName="obsData")
xRooNode Add(const xRooNode &child, Option_t *opt="")
xRooNode(const char *type, const char *name, const char *title="")
const char * GetIconName() const override
Returns mime type name of object.
void Draw(Option_t *opt="") override
Default Draw method for all objects.
double GetBinError(int bin, const xRooNode &fr="") const
std::vector< double > GetBinErrors(int binStart=1, int binEnd=0, const xRooNode &fr="") const
bool _IsShowVars_() const
TGraph * BuildGraph(RooAbsLValue *v=nullptr, bool includeZeros=false, TVirtualPad *fromPad=nullptr) const
const std::shared_ptr< xRooNode > & at(size_t idx, bool browseResult=true) const
const char * GetNodeType() const
bool SetBinContent(int bin, double value, const char *par=nullptr, double parVal=1)
std::shared_ptr< xRooNode > operator[](size_t idx)
void Checked(TObject *obj, bool val)
void Print(Option_t *opt="") const override
Print TNamed name and title.
double GetContent() const
std::shared_ptr< T > acquireNew(Args &&...args)
std::shared_ptr< T > acquire2(Args &&...args)
xRooNode components() const
void SaveAs(const char *filename="", Option_t *option="") const override
Save this object in the file specified by filename.
xRooNode bins() const
bins of a channel or sample, or channels of a multi-channel pdf
std::shared_ptr< xRooNode > find(const std::string &name, bool browseResult=true) const
TGListTree * GetListTree(TBrowser *b) const
bool fInterrupted
appears that if was fXaxis then dialog box for SetXaxis will take as current value
xRooNode generate(const xRooNode &fr="", bool expected=false, int seed=0)
void Inspect() const override
Dump contents of this object in a graphics canvas.
std::shared_ptr< xRooNode > getBrowsable(const char *name) const
bool SetXaxis(const RooAbsBinning &binning)
RooArgList argList() const
void SetHidden(bool set=true)
std::function< xRooNode(xRooNode *)> fBrowseOperation
std::vector< double > GetBinContents(int binStart=1, int binEnd=0) const
xRooNode pp() const
List of prespecified parameters: non-floatable parameters.
xRooNode constraints() const
std::shared_ptr< xRooNode > fProvider
std::shared_ptr< TStyle > style(TObject *initObject=nullptr, bool autoCreate=true) const
xRooNode mainChild() const
xRooNode fitResult(const char *opt="") const
std::shared_ptr< TAxis > fXAxis
only here so can have char* GetRange return so can return nullptr for no range set (required for RooC...
xRooNode coords(bool setVals=true) const
xRooNode Vary(const xRooNode &child)
xRooNode Constrain(const xRooNode &child)
static std::map< std::string, std::tuple< std::function< double(double, double, double)>, bool > > auxFunctions
xRooNode pars() const
List of parameters (non-observables) of this node.
void _SetContent_(double value)
void SetFitResult(const RooFitResult *fr=nullptr)
void _ShowVars_(bool set=true)
bool IsFolder() const override
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
bool SetBinError(int bin, double value)
void _Vary_(const char *what)
xRooNode histo(const xRooNode &vars="x", const xRooNode &fr="", bool content=true, bool errors=true) const
bool SetContents(const TObject &obj)
std::shared_ptr< TObject > fComp
RooWorkspace * ws() const
The RooWorkspace this node belong to, if any.
xRooNode shallowCopy(const std::string &name, std::shared_ptr< xRooNode > parent=nullptr)
void _generate_(const char *name="", bool expected=false)
void _fit_(const char *constParValues="")
std::shared_ptr< TObject > getObject(const std::string &name, const std::string &type="") const
xRooNode np() const
List of nuisance parameters: non-constant parameters that are not marked of interest,...
xRooNode floats() const
List of parameters that are currently non-constant These parameters do not have the "Constant" attrib...
bool contains(const std::string &name) const
xRooNode reduced(const std::string &range="", bool invert=false) const
xRooNode variations() const
std::string GetPath() const
auto begin() const -> xRooNodeIterator
std::shared_ptr< xRooNode > parentPdf() const
like a parent but only for use by getObject
bool SetContent(double value)
std::shared_ptr< xRooNode > fParent
std::pair< double, double > IntegralAndError(const xRooNode &fr="", const char *rangeName=nullptr) const
xRooNode robs() const
List of regular observables of this node.
TClass * IsA() const override
xRooNode & operator=(const TObject &o)
auto end() const -> xRooNodeIterator
TH1 * BuildHistogram(RooAbsLValue *v=nullptr, bool empty=false, bool errors=false, int binStart=1, int binEnd=0, const xRooNode &fr="") const
xRooNode consts() const
List of parameters that are currently constant.
void _SetBinContent_(int bin, double value, const char *par="", double parVal=1)
std::shared_ptr< TObject > acquire(const std::shared_ptr< TObject > &arg, bool checkFactory=false, bool mustBeNew=false)
void Browse(TBrowser *b=nullptr) override
Browse object. May be overridden for another default action.
double GetBinData(int bin, const char *dataName="obsData")
xRooNode obs() const
List of observables (global and regular) of this node.
void SetRange(const char *range, double low=std::numeric_limits< double >::quiet_NaN(), double high=std::numeric_limits< double >::quiet_NaN())
bool SetData(const TObject &obj, const char *dataName="obsData")
static void SetAuxFunction(const char *title, const std::function< double(double, double, double)> &func, bool symmetrize=false)
std::shared_ptr< TObject > convertForAcquisition(xRooNode &acquirer, const char *opt="") const
double GetError(const xRooNode &fr="") const
xRooNode vars() const
List of variables (observables and parameters) of this node.
const char * GetRange() const
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
Common abstract base class for objects that represent a value and a "shape" in RooFit.
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
void SetName(const char *name) override
Set the name of the TNamed.
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Abstract base class for RooRealVar binning definitions.
virtual double highBound() const =0
virtual double lowBound() const =0
Abstract base class for objects that represent a discrete value that can be set from the outside,...
A space to attach TBranches.
const char * getLabel() const
Retrieve current label. Use getCurrentLabel() for more clarity.
Abstract container object that can hold multiple RooAbsArg objects.
RooAbsCollection * selectByAttrib(const char *name, bool value) const
Create a subset of the current collection, consisting only of those elements with the specified attri...
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
void clear()
Clear contents. If the collection is owning, it will also delete the contents.
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
bool selectCommon(const RooAbsCollection &refColl, RooAbsCollection &outColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
void setName(const char *name)
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract base class for binned and unbinned datasets.
virtual const RooArgSet * get() const
RooFit::OwningPtr< RooAbsData > reduce(const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={})
Create a reduced copy of this dataset.
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
virtual void add(const RooArgSet &row, double weight=1)=0
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.
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.
void setCovQual(Int_t val)
const TMatrixDSym & covarianceMatrix() const
Return covariance matrix.
TMatrixDSym reducedCovarianceMatrix(const RooArgList ¶ms) const
Return a reduced covariance matrix (Note that Vred is a simple sub-matrix of V, row/columns are order...
void setCovarianceMatrix(TMatrixDSym &V)
Store externally provided correlation matrix in this RooFitResult ;.
const RooArgList & constPars() const
Return list of constant parameters.
Int_t covQual() const
Return MINUIT quality code of covariance matrix.
const RooArgList & floatParsFinal() const
Return list of floating parameters after fit.
void setFinalParList(const RooArgList &list)
Fill the list of final values of the floating parameters.
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.
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.
HypoTestResult is a base class for results from hypothesis tests.
A RooAbsArg implementing string values.
Persistable container for RooFit projects.
const std::map< std::string, RooArgSet > & sets() const
bool import(const RooAbsArg &arg, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}, const RooCmdArg &arg9={})
Import a RooAbsArg object, e.g.
bool removeSet(const char *name)
Remove a named set from the workspace.
RooFactoryWSTool & factory()
Return instance to factory tool.
const Double_t * GetArray() const
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
virtual Style_t GetTitleFont() const
virtual Float_t GetLabelOffset() const
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels.
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title.
virtual Float_t GetTitleSize() const
virtual Float_t GetLabelSize() const
virtual Float_t GetTickLength() const
virtual Float_t GetTitleOffset() const
virtual void SetTickLength(Float_t length=0.03)
Set tick mark length.
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Fill Area Attributes class.
virtual Color_t GetFillColor() const
Return the fill area color.
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
virtual Font_t GetTextFont() const
Return the text font.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Class to manage histogram axis.
virtual void LabelsOption(Option_t *option="h")
Set option(s) to draw axis with labels option can be:
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Bool_t IsVariableBinSize() const
const char * GetTitle() const override
Returns title of object.
TAxis()
Default constructor.
const TArrayD * GetXbins() const
const char * GetBinLabel(Int_t bin) const
Return label for bin.
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x.
Using a TBrowser one can browse all ROOT objects.
TBrowserImp * GetBrowserImp() const
static TCanvas * MakeDefCanvas()
Static function to build a default canvas.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
void SetName(const char *name)
virtual Int_t GetEntries() const
virtual void RemoveAll(TCollection *col)
Remove all objects in collection col from this collection.
static Int_t GetColorPalette(Int_t i)
Static function returning the color number i in current palette.
static Int_t GetNumberOfColors()
Static function returning number of colors in the color palette.
Describe directory structure in memory.
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
virtual TList * GetListOfKeys() const
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=nullptr)
Set the value of a resource or create a new resource.
TExec is a utility class that can be used to execute a C++ command when some event happens in a pad.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
System file browser, used as TRootBrowser plug-in.
void AddFSDirectory(const char *entry, const char *path=nullptr, Option_t *opt="")
Add file system directory in the list tree.
A list tree is a widget that can contain a number of items arranged in a tree structure.
ROOT GUI Window base class.
virtual void SetName(const char *name)
void SetTitleOffset(Float_t titleoffset=1)
void SetLabelFont(Int_t labelfont)
void SetTitleSize(Float_t titlesize)
virtual void SetTitle(const char *title="")
Change the title of the axis.
Int_t GetLabelFont() const
Float_t GetTitleOffset() const
Float_t GetTickSize() const
void SetTickSize(Float_t ticksize)
void SetLabelSize(Float_t labelsize)
TGraph with asymmetric error bars.
virtual void SetPointError(Double_t exl, Double_t exh, Double_t eyl, Double_t eyh)
Set ex and ey values for point pointed by the mouse.
A TGraphErrors is a TGraph with error bars.
Double_t GetErrorYlow(Int_t bin) const override
It returns the error along Y at point i.
Double_t GetErrorYhigh(Int_t bin) const override
It returns the error along Y at point i.
A TGraph is an object made of two arrays X and Y with npoints each.
virtual void AddPoint(Double_t x, Double_t y)
Append a new point to the graph.
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
void SetName(const char *name="") override
Set graph name.
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
virtual Double_t GetPointY(Int_t i) const
Get y value for point i.
void SetTitle(const char *title="") override
Change (i.e.
virtual void SetPointX(Int_t i, Double_t x)
Set x value for point i.
virtual void SetEditable(Bool_t editable=kTRUE)
if editable=kFALSE, the graph cannot be modified with the mouse by default a TGraph is editable
1-D histogram with a double per channel (see TH1 documentation)
1-D histogram with a float per channel (see TH1 documentation)
TH1 is the base class of all histogram classes in ROOT.
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
void SetTitle(const char *title) override
Change/set the title.
virtual Int_t GetNbinsY() const
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
@ kNoTitle
Don't draw the histogram title.
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
TObject * FindObject(const char *name) const override
Search object named name in the list of functions.
virtual Int_t GetNbinsX() const
virtual void SetMaximum(Double_t maximum=-1111)
virtual void SetBinError(Int_t bin, Double_t error)
Set the bin Error Note that this resets the bin eror option to be of Normal Type and for the non-empt...
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
void Draw(Option_t *option="") override
Draw this histogram with options.
virtual void SetMinimum(Double_t minimum=-1111)
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
TList * GetListOfFunctions() const
void SetName(const char *name) override
Change the name of this histogram.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
virtual Bool_t Divide(TF1 *f1, Double_t c1=1)
Performs the operation: this = this/(c1*f1) if errors are defined (see TH1::Sumw2),...
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
2-D histogram with a double per channel (see TH1 documentation)
The Histogram stack class.
virtual void Add(TH1 *h, Option_t *option="")
add a new histogram to the list Only 1-d and 2-d histograms currently supported.
void Draw(Option_t *chopt="") override
Draw this multihist with its current attributes.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
virtual const char * GetClassName() const
Storage class for one entry of a TLegend.
This class displays a legend box (TPaveText) containing several legend entries.
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
void SetNColumns(Int_t nColumns)
Set the number of columns for the legend.
void SetMargin(Float_t margin)
Use the TLine constructor to create a simple line.
virtual void SetY2(Double_t y2)
virtual void SetX2(Double_t x2)
virtual void SetX1(Double_t x1)
virtual void SetY1(Double_t y1)
void Add(TObject *obj) override
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
A TMultiGraph is a collection of TGraph (or derived) objects.
virtual void Add(TGraph *graph, Option_t *chopt="")
Add a new graph to the list of graphs.
void Draw(Option_t *chopt="") override
Draw this multigraph with its current attributes.
The TNamed class is the base class for all named ROOT classes.
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
void Clear(Option_t *option="") override
Set name and title to empty strings ("").
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Mother of all ROOT objects.
virtual void Inspect() const
Dump contents of this object in a graphics canvas.
virtual const char * GetName() const
Returns name of object.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
virtual void Delete(Option_t *option="")
Delete this object.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual const char * GetTitle() const
Returns title of object.
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
@ kCanDelete
if object in a list can be deleted
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
The most important graphics class in the ROOT system.
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.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Stop()
Stop the stopwatch.
Provides iteration through tokens of a given string.
Bool_t NextToken()
Get the next token, it is stored in this TString.
Bool_t IsDec() const
Returns true if all characters in string are decimal digits (0-9).
void ToLower()
Change string to lower-case.
Int_t Atoi() const
Return integer value of string.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Double_t Atof() const
Return floating-point value contained in string.
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Int_t CountChar(Int_t c) const
Return number of times character c occurs in the string.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
TStyle objects may be created to define special styles.
void SetPaintTextFormat(const char *format="g")
Int_t GetOptTitle() const
Float_t GetLabelSize(Option_t *axis="X") const
Return label size.
Float_t GetPadRightMargin() const
Style_t GetTitleFont(Option_t *axis="X") const
Return title font.
Bool_t GetHistMinimumZero() const
Float_t GetPadLeftMargin() const
Float_t GetTitleYSize() const
Double_t GetHistTopMargin() const
Float_t GetPadBottomMargin() const
const char * GetPaintTextFormat() const
Float_t GetPadTopMargin() const
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
The TTimeStamp encapsulates seconds and ns since EPOCH.
void Add(const TTimeStamp &offset)
Add "offset" as a delta time.
const char * AsString(const Option_t *option="") const
Return the date & time as a string.
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
static TVirtualPadEditor * GetPadEditor(Bool_t load=kTRUE)
Returns the pad editor dialog. Static method.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
virtual void Modified(Bool_t flag=1)=0
virtual TList * GetListOfPrimitives() const =0
virtual void SetPad(const char *name, const char *title, Double_t xlow, Double_t ylow, Double_t xup, Double_t yup, Color_t color=35, Short_t bordersize=5, Short_t bordermode=-1)=0
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
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 Range(const char *rangeName, bool adjustNorm=true)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
Double_t Prob(Double_t chi2, Int_t ndf)
Computation of the probability for a certain Chi-squared (chi2) and number of degrees of freedom (ndf...
Double_t ChisquareQuantile(Double_t p, Double_t ndf)
Evaluate the quantiles of the chi-squared probability distribution function.
#define END_XROOFIT_NAMESPACE
void removeTopic(RooFit::MsgTopic oldTopic)
bool isNaNWithPayload() const
Test if this struct has a float packed into its mantissa.
static float unpackNaN(double val)
If val is NaN and a this NaN has been tagged as containing a payload, unpack the float from the manti...
static uint64_t sum(uint64_t i)
void(* gOldHandlerr)(int)
void addLegendEntry(TObject *o, const char *title, const char *opt)
void buildHistogramInterrupt(int signum)
auto GETACTBROWSER(TRootBrowser *b)
auto & GETWSSNAPSHOTS(RooWorkspace *w)
bool TopRightPlaceBox(TPad *p, TObject *o, double w, double h, double &xl, double &yb)
TPaveText * getPave(const char *name="labels", bool create=true, bool doPaint=false)
auto GETROOTDIR(TGFileBrowser *b)
const xRooNode * runningNode
auto GETLISTTREE(TGFileBrowser *b)
const T & _or_func(const T &a, const T &b)
TLegend * getLegend(bool create=true, bool doPaint=false)