15#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
17#define protected public
38#define GETWS(a) a->_myws
39#define GETWSSETS(w) w->_namedSets
40#define GETWSSNAPSHOTS(w) w->_snapshots
41#define GETACTBROWSER(b) b->fActBrowser
42#define GETROOTDIR(b) b->fRootDir
43#define GETLISTTREE(b) b->fListTree
44#define GETDMP(o,m) o->m
71#define GETDMP(o,m) (*(void**)(((unsigned char*)o) + o->Class()->GetDataMemberOffset(#m)))
115#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
119#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
143xRooNode::InteractiveObject *xRooNode::gIntObj =
nullptr;
144std::map<std::string, std::tuple<std::function<
double(
double,
double,
double)>,
bool>> xRooNode::auxFunctions;
145void xRooNode::SetAuxFunction(
const char *title,
const std::function<
double(
double,
double,
double)> &func,
148 auxFunctions[title] = std::make_tuple(func, symmetrize);
159xRooNode::xRooNode(
const char *classname,
const char *
name,
const char *title)
164#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
167 xRooNode(*
w, std::make_shared<xRooNode>()).sterilize();
173 if (
auto a = get<TNamed>();
a)
178xRooNode::xRooNode(
const char *
name,
const std::shared_ptr<TObject> &comp,
const std::shared_ptr<xRooNode> &parent)
179 :
TNamed(
name,
""), fComp(comp), fParent(parent)
187#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
188 fComp = std::make_shared<RooWorkspace>(
"workspace",
name);
193 Error(
"xRooNode",
"Error reading json workspace %s",
name);
198 Error(
"xRooNode",
"json format workspaces available only in ROOT 6.26 onwards");
204 auto _file = std::make_shared<TFile>(
209 auto keys = _file->GetListOfKeys();
211 for (
auto &&k : *keys) {
217#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
218 dynamic_cast<RooWorkspace *>(ws)->_embeddedDataList.Delete();
220 xRooNode(*ws, std::make_shared<xRooNode>()).sterilize();
226 fParent = std::make_shared<xRooNode>(
234 }
else if (pathName.EndsWith(
".root") || pathName.EndsWith(
".json")) {
239 if (
auto _ws = get<RooWorkspace>(); _ws && (!parent || parent->get<
TFile>())) {
246 for (
auto f : *
gROOT->GetListOfFiles()) {
247 if ((
dynamic_cast<TFile *
>(
f)->GetVersion() / 100) > (
gROOT->GetVersionInt() / 100)) {
248 Warning(
"xRooNode",
"There is file open with version %d > current version %d ... results may be wrong",
249 dynamic_cast<TFile *
>(
f)->GetVersion(),
gROOT->GetVersionInt());
255 for (
auto &
d : _ws->allData()) {
256 for (
auto &
a : *
d->get()) {
257 if (
auto v = _ws->var(
a->GetName());
v)
258 v->setAttribute(
"obs");
259 else if (
auto c = _ws->cat(
a->GetName());
c)
260 c->setAttribute(
"obs");
263 checkCount +=
d->TestBit(1 << 20);
266 if (checkCount == 0 && !_ws->allData().empty())
267 _ws->allData().back()->SetBit(1 << 20,
true);
270 for (
auto s : *_set) {
272 _ws->var(s->GetName())->setStringAttribute(
"nominal",
TString::Format(
"%f",
v->getVal()));
280 if (k ==
"globalObservables" ||
TString(k).
EndsWith(
"_GlobalObservables")) {
283 s->setAttribute(
"obs");
284 s->setAttribute(
"global");
289 s->setAttribute(
"poi");
293 if (!_v->hasRange(
"physical")) {
294 _v->
setRange(
"physical", 0, std::numeric_limits<double>::infinity());
296 if (_v->getMin() >= 0)
302 if (!_allGlobs.
empty() &&
GETWSSETS(_ws).count(
"globalObservables") == 0) {
303 _ws->defineSet(
"globalObservables", _allGlobs);
308 if (!_ws->allPdfs().empty()) {
309 std::vector<RooRealVar *> noErrorPars;
310 for (
auto &
p : pars()) {
315 noErrorPars.push_back(
v);
317 if (!noErrorPars.empty()) {
320 for (
auto &
a : *this) {
321 if (
a->fFolder ==
"!models") {
323 auto fr =
a->fitResult(
"prefit");
325 for (
auto &
v : noErrorPars) {
326 if (
auto arg =
dynamic_cast<RooRealVar *
>(_fr->floatParsFinal().find(
v->GetName()));
327 arg && arg->hasError()) {
328 v->setError(arg->getError());
340 if (strlen(GetTitle()) == 0) {
356 (comp.InheritsFrom(
"RooAbsArg") && dynamic_cast<const
RooAbsArg *>(&comp)->getStringAttribute(
"alias"))
357 ? dynamic_cast<const
RooAbsArg *>(&comp)->getStringAttribute(
"alias")
366 if (
auto a = std::dynamic_pointer_cast<RooAbsArg>(comp);
a &&
a->getStringAttribute(
"alias"))
367 return a->getStringAttribute(
"alias");
369 return comp->GetName();
387 if (
auto o = get<RooAbsReal>(); o) {
388 if (o->isSelectedComp() && !val) {
391 o->setAttribute(
"hidden");
392 }
else if (!o->isSelectedComp() && !val) {
397 o->setAttribute(
"hidden",
false);
400 item->CheckItem(!o->getAttribute(
"hidden"));
401 if (o->isSelectedComp())
404 item->SetColor(
kGray);
408 if (
auto o =
get(); o) {
410 o->SetBit(1 << 20, val);
411 if (
auto fr = get<RooFitResult>(); fr) {
412 if (
auto _ws =
ws(); _ws) {
415 _allVars = fr->floatParsFinal();
416 _allVars = fr->constPars();
417 for (
auto &i : fr->floatParsInit()) {
423 for (
auto oo : _ws->allGenericObjects()) {
424 if (
auto ffr =
dynamic_cast<RooFitResult *
>(oo); ffr && ffr != fr) {
425 ffr->ResetBit(1 << 20);
429 _ws->allVars() = fr->floatParsInit();
433 if (
auto first = item->GetParent()->GetFirstChild()) {
435 if (
first->HasCheckBox()) {
437 first->CheckItem(_obj->get() && _obj->get()->TestBit(1 << 20));
448 static bool blockBrowse =
false;
452 auto b2 =
dynamic_cast<TBrowser *
>(
gROOT->GetListOfBrowsers()->Last());
453 if (!b2 || !b2->GetBrowserImp()) {
459 b2 =
new TBrowser(
"nodeBrowser",
this,
"RooFit Browser");
461 }
else if (strcmp(b2->GetName(),
"nodeBrowser") == 0) {
463 b2->BrowseObject(
this);
486 if (
auto first = item->GetFirstChild()) {
488 if (
first->HasCheckBox()) {
490 first->CheckItem(_obj->get() &&
491 (_obj->get()->TestBit(1 << 20) ||
501 if (
auto s = get<TStyle>()) {
502 s->SetFillAttributes();
507 Draw(
b->GetDrawOption());
508 }
catch (
const std::exception &
e) {
514 bool hasFolders =
false;
516 for (
auto &
c : *
this) {
517 if (!
c->fFolder.empty()) {
526 auto _folders =
find(
".folders");
528 _folders = emplace_back(std::make_shared<xRooNode>(
".folders",
nullptr, *
this));
531 for (
auto &
v : *
this) {
532 if (
v->fFolder !=
"" && !_folders->find(
v->fFolder)) {
533 _folders->emplace_back(std::make_shared<xRooNode>(
v->fFolder.c_str(),
nullptr, *
this));
537 for (
auto &
v : *_folders) {
540 _name = _name(1, _name.
Length());
541 b->Add(
v.get(), _name);
545 for (
auto &
v : *
this) {
546 if (hasFolders && !
v->fFolder.empty())
548 if (strcmp(
v->GetName(),
".folders") == 0)
551 if (
v->get<
RooAbsPdf>() && get<RooSimultaneous>())
555 _name = _name(strlen(
v->get()->ClassName()) + 2, _name.
Length());
563 :
v->get()->GetName());
564 }
else if (
v->get() && !
v->get<
TFile>() && !
TString(
v->GetName()).BeginsWith(
'/'))
566 if (
auto _type =
v->GetNodeType(); strlen(_type)) {
574 TString nameSave(
v->TNamed::GetName());
575 TString titleSave(
v->TNamed::GetTitle());
576 if (
auto o =
v->get(); o)
577 v->TNamed::SetNameTitle(o->GetName(), o->ClassName());
578 b->Add(
v.get(), _name, _checked);
579 if (
auto o =
v->get(); o)
580 v->TNamed::SetNameTitle(nameSave, titleSave);
581 if (_checked != -1) {
582 dynamic_cast<TQObject *
>(
b->GetBrowserImp())
583 ->Connect(
"Checked(TObject *, Bool_t)",
ClassName(),
v.get(),
"Checked(TObject *, Bool_t)");
585 v->GetTreeItem(
b)->SetColor(
kRed);
609 TString nameSave(
v->TNamed::GetName());
610 TString titleSave(
v->TNamed::GetTitle());
611 if (
auto o =
v->get(); o)
612 v->TNamed::SetNameTitle(o->GetName(), o->ClassName());
613 b->Add(
v.get(), _name, -1);
614 if (
auto o =
v->get(); o)
615 v->TNamed::SetNameTitle(nameSave, titleSave);
618 b->SetSelected(
this);
631 auto v = std::make_shared<xRooNode>(
vars());
642 if (strcmp(
b->GetName(),
".vars") == 0)
665 if (
auto v = var();
v)
666 return v->getBinWidth(bin - 1, GetName());
671 if (
auto v = rvar();
v)
672 return v->getBinning(GetName()).binLow(bin - 1);
677 if (
auto v = rvar();
v)
678 return v->getBinning(GetName()).binHigh(bin - 1);
684 return (binning() && strlen(binning()->GetTitle())) ? binning()->GetTitle() : GetParent()->GetTitle();
691 dynamic_cast<TNamed *
>(GetParent())->SetTitle(title);
697 v->setBinning(
RooBinning(nbins, xbins), GetName());
702 std::vector<double> bins(nbins + 1);
703 for (
int i = 0; i <= nbins; i++)
704 bins.at(i) = xbins[i];
705 return Set(nbins, &bins[0]);
728 if (
auto _owned =
find(
".memory"); _owned) {
729 for (
auto &o : *_owned) {
730 if (
name == o->GetName()) {
731 if (
type.empty() || o->get()->InheritsFrom(
type.c_str()))
740 while (!_provider && _parent) {
741 _provider = _parent->fProvider;
742 _parent = _parent->fParent;
745 return _provider->getObject(
name,
type);
748 std::shared_ptr<TObject> out;
749 if (
auto arg =
ws()->arg(
name.c_str()); arg) {
750 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
751 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
756 if (
auto arg =
ws()->
data(
name.c_str()); arg) {
757 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
758 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
763 if (
auto arg =
ws()->genobj(
name.c_str()); arg) {
764 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
765 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
770 if (
auto arg =
ws()->embeddedData(
name.c_str()); arg) {
771 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
772 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
793 if (
auto a = get<RooAbsArg>();
a &&
a->isFundamental())
798 auto o = get<RooAbsReal>();
802 if (
auto xName = o->getStringAttribute(
"xvar"); xName) {
811 if (_parentX && (o->dependsOn(*
dynamic_cast<RooAbsArg *
>(_parentX->GetParent())) ||
vars().
size() == 0)) {
813 }
else if (
auto _obs =
obs(); !_obs.empty()) {
814 for (
auto &
v : _obs) {
823 }
else if (
auto _pars =
pars(); !_pars.empty()) {
824 for (
auto &
v : _pars) {
840 if (o !=
dynamic_cast<TObject *
>(
x)) {
845 TString binningName = o->getStringAttribute(
"binning");
846 auto _bnames =
x->getBinningNames();
847 bool hasBinning =
false;
848 for (
auto &
b : _bnames) {
849 if (
b == binningName) {
857 Warning(
"GetXaxis",
"Binning %s not defined on %s - clearing", binningName.
Data(),
859 o->setStringAttribute(
"binning",
nullptr);
863 if (binningName ==
"" && o !=
dynamic_cast<TObject *
>(
x)) {
865 auto __bnames =
x->getBinningNames();
866 for (
auto &
b : __bnames) {
869 if (
b == o->GetName()) {
870 binningName = o->GetName();
874 if (binningName ==
"") {
880 (std::list<double> *)(
nullptr),
881 o->binBoundaries(*
dynamic_cast<RooAbsRealLValue *
>(
x), -std::numeric_limits<double>::infinity(),
882 std::numeric_limits<double>::infinity()));
884 std::vector<double> _bins;
885 for (
auto &
b : *
bins) {
886 if (_bins.empty() || std::abs(_bins.back() -
b) > 1
e-5 * _bins.back())
889 fXAxis = std::make_shared<Axis2>(_bins.size() - 1, &_bins[0]);
892 _v->setBinning(
RooBinning(_bins.size() - 1, &_bins[0], o->GetName()), o->
GetName());
893 _v->getBinning(o->GetName())
898 binningName = o->GetName();
900 }
else if (_parentX) {
902 binningName = _parentX->GetName();
909 if (
r->getBinning(binningName).isUniform()) {
910 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName),
r->getMin(binningName),
r->getMax(binningName));
912 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName),
r->getBinning(binningName).array());
915 std::vector<double>
bins = {};
916 for (
int i = 0; i <=
x->numBins(binningName); i++)
918 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName), &
bins[0]);
920 for (
int i = 0; i <
x->numBins(binningName); i++) {
926 fXAxis->SetName(binningName);
933 if (
auto o =
get(); o) {
934 if (o->InheritsFrom(
"RooWorkspace"))
936 if (o->InheritsFrom(
"RooAbsData"))
938 if (o->InheritsFrom(
"RooSimultaneous"))
941 if (o->InheritsFrom(
"RooProdPdf"))
943 if (o->InheritsFrom(
"RooRealSumPdf") || o->InheritsFrom(
"RooAddPdf"))
946 if (o->InheritsFrom(
"RooFitResult")) {
947 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitRooFitResult",
true)) {
948 gClient->GetMimeTypeList()->AddType(
"xRooFitRooFitResult",
"xRooFitRooFitResult",
"package.xpm",
949 "package.xpm",
"->Browse()");
951 return "xRooFitRooFitResult";
953 if (o->InheritsFrom(
"RooRealVar") || o->InheritsFrom(
"RooCategory")) {
954 if (get<RooAbsArg>()->getAttribute(
"obs")) {
955 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitObs",
true)) {
956 gClient->GetMimeTypeList()->AddType(
"xRooFitObs",
"xRooFitObs",
"x_pic.xpm",
"x_pic.xpm",
"->Browse()");
958 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitGlobs",
true)) {
959 gClient->GetMimeTypeList()->AddType(
"xRooFitGlobs",
"xRooFitGlobs",
"z_pic.xpm",
"z_pic.xpm",
962 return (get<RooAbsArg>()->getAttribute(
"global") ?
"xRooFitGlobs" :
"xRooFitObs");
966 if (o->InheritsFrom(
"TStyle")) {
967 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitTStyle",
true)) {
968 gClient->GetMimeTypeList()->AddType(
"xRooFitTStyle",
"xRooFitTStyle",
"bld_colorselect.xpm",
969 "bld_colorselect.xpm",
"->Browse()");
971 return "xRooFitTStyle";
973 if (o->InheritsFrom(
"RooConstVar")) {
979 return "TMethodBrowsable-leaf";
981 if (o->InheritsFrom(
"RooStats::HistFactory::FlexibleInterpVar"))
982 return "TBranchElement-folder";
985 _ax && (
a->isBinnedDistribution(*
dynamic_cast<RooAbsArg *
>(_ax->GetParent())) ||
987 std::unique_ptr<std::list<double>>(
a->binBoundaries(
988 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
989 std::numeric_limits<double>::infinity()))))) {
994 return o->ClassName();
1005 if (o->InheritsFrom(
"RooStats::HistFactory::FlexibleInterpVar"))
1007 if (o->InheritsFrom(
"PiecewiseInterpolation"))
1009 if (o->InheritsFrom(
"RooHistFunc"))
1010 return (
dynamic_cast<RooAbsArg *
>(o)->getAttribute(
"density")) ?
"ConstDensityHisto" :
"ConstHisto";
1011 if (o->InheritsFrom(
"RooBinWidthFunction"))
1013 if (o->InheritsFrom(
"ParamHistFunc"))
1015 if (o->InheritsFrom(
"RooRealVar"))
1017 if (o->InheritsFrom(
"RooConstVar"))
1025 xRooNode out(
".coords",
nullptr, *
this);
1027 auto _p = std::shared_ptr<xRooNode>(
const_cast<xRooNode *
>(
this), [](
xRooNode *) {});
1030 if (
auto pos = pName.
Index(
'='); pos != -1) {
1031 if (
auto _obs = _p->getObject<
RooAbsArg>(pName(0, pos)); _obs) {
1034 _cat->setLabel(pName(pos + 1, pName.
Length()));
1035 }
else if (
auto _var =
dynamic_cast<RooAbsRealLValue *
>(_obs.get()); _var) {
1039 out.emplace_back(std::make_shared<xRooNode>(_obs->GetName(), _obs, _p));
1041 throw std::runtime_error(
"Unknown observable, could not find");
1053 }
catch (
const std::exception &
e) {
1062 }
catch (
const std::exception &
e) {
1071 if (strcmp(
GetName(),
".factors") == 0 || strcmp(
GetName(),
".constraints") == 0 ||
1072 strcmp(
GetName(),
".components") == 0) {
1078 pdf =
p->pdfList().find(
child.GetName());
1081 auto i =
p->pdfList().index(*pdf);
1083#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
1084 const_cast<RooArgList&
>(
p->pdfList()).remove(*pdf);
1085#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
1086 p->_pdfNSetList.erase(
p->_pdfNSetList.begin() + i);
1088 auto nset =
p->_pdfNSetList.At(i);
1089 p->_pdfNSetList.Remove(nset);
1092 if (
p->_extendedIndex == i)
1093 p->_extendedIndex = -1;
1094 else if (
p->_extendedIndex > i)
1095 p->_extendedIndex--;
1107 arg = p2->components().find(
child.GetName());
1111#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
1112 p2->_compRSet.remove(*arg);
1114 const_cast<RooArgList&
>(p2->realComponents()).remove(*arg);
1116 p2->removeServer(*arg,
true);
1121 bool removed =
false;
1124 c->constraints().Remove(toRemove);
1126 }
catch (std::runtime_error &) {
1136 arg = p4->funcList().find(
child.GetName());
1140 auto idx = p4->funcList().index(arg);
1144 const_cast<RooArgList&
>(p4->funcList()).remove(*arg);
1145 p4->removeServer(*arg,
true);
1147 std::vector<RooAbsArg *> _coefs;
1148 for (
size_t ii = 0; ii < const_cast<RooArgList&>(p4->coefList()).size(); ii++) {
1149 if (ii !=
size_t(idx))
1150 _coefs.push_back(
const_cast<RooArgList&
>(p4->coefList()).
at(ii));
1152 const_cast<RooArgList&
>(p4->coefList()).removeAll();
1153 for (
auto &
a : _coefs)
1164 if (
auto w = get<RooWorkspace>();
w) {
1166 auto arg =
w->components().find(
child.GetName());
1173 if (arg->hasClients()) {
1174 throw std::runtime_error(
1175 TString::Format(
"Cannot remove %s from workspace %s, because it has dependencies - first remove from those",
1178 const_cast<RooArgSet&
>(
w->components()).remove(*arg);
1181 }
else if (get<RooProduct>() || get<RooProdPdf>()) {
1183 }
else if (get<RooRealSumPdf>()) {
1187 throw std::runtime_error(
"Removal not implemented for this type of object");
1196 ~AutoUpdater() {
n.browse(); }
1199 AutoUpdater xxx(*
this);
1202 bool considerType(sOpt ==
"+");
1218 if (strcmp(
GetName(),
".factors") == 0) {
1221 }
else if (strcmp(
GetName(),
".components") == 0) {
1224 }
else if (strcmp(
GetName(),
".variations") == 0) {
1227 }
else if (strcmp(
GetName(),
".constraints") == 0) {
1239 }
else if (strcmp(
GetName(),
".datasets()") == 0) {
1244 throw std::runtime_error(
1245 "Datasets can only be created for pdfs or workspaces (except if generated dataset, then must be pdf)");
1248 if (sOpt ==
"asimov" || sOpt ==
"toy") {
1250 auto _fr = std::dynamic_pointer_cast<const RooFitResult>(
fParent->fitResult().fComp);
1251 if (strlen(_fr->GetName()) == 0)
1252 std::const_pointer_cast<RooFitResult>(_fr)->SetName(
TUUID().AsString());
1254 if (strlen(
child.GetName()))
1255 asi.first->SetName(
child.GetName());
1257 _ws->import(*asi.first);
1259 if (!_ws->obj(_fr->GetName())) {
1263#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
1264 _ws->saveSnapshot(asi.first->GetName(), *asi.second,
1268 _tmp.
add(*asi.second);
1269 _ws->saveSnapshot(asi.first->GetName(), _tmp,
true);
1275 auto _obs =
fParent->obs().argList();
1277 std::unique_ptr<RooAbsCollection> _globs(_obs.selectByAttrib(
"global",
true));
1279 _obs.remove(*_globs);
1285 _obs.add(*
dynamic_cast<RooAbsArg *
>(ax->GetParent()));
1288 if (
auto _d = _ws->data(
child.GetName()); _d) {
1291 l.remove(*_d->get(),
true,
true);
1295 throw std::runtime_error(
"Cannot extend dataset with new columns");
1306 if (
auto __d = _ws->data(
child.GetName()))
1307 __d->SetBit(1 << 20, _ws->allData().size() == 1);
1315 auto out = std::shared_ptr<TObject>(_ws->data(
child.GetName()), [](
TObject *) {});
1324 throw std::runtime_error(
"Cannot create dataset");
1329 throw std::runtime_error(
"Cannot add to null object with no parentage");
1331 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(
child), [](
TObject *) {}));
1336 std::rethrow_exception(std::current_exception());
1341 throw std::runtime_error(
"No object");
1345 if (
auto p = get<RooAbsData>();
p) {
1348 throw std::runtime_error(
"Can only add histogram to data");
1352 throw std::runtime_error(
"Could not find pdf");
1353 auto _ax = _pdf->GetXaxis();
1355 throw std::runtime_error(
"Cannot determine binning to add data");
1364 l.remove(*
p->get(),
true,
true);
1368 throw std::runtime_error(
"Cannot extend dataset with new columns");
1374 for (
int i = 1; i <= _h->GetNbinsX(); i++) {
1375 dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent())->setVal(_h->GetBinCenter(i));
1376 p->add(
obs, _h->GetBinContent(i));
1384 const_cast<RooArgList&
>(
p->coefList()).add(*acquire<RooRealVar>(
"1",
"1", 1));
1385 const_cast<RooArgList&
>(
p->pdfList()).add(*std::dynamic_pointer_cast<RooAbsReal>(out));
1390 if (
auto p = get<RooRealSumPdf>();
p) {
1391 std::shared_ptr<TObject> out;
1392 auto cc =
child.fComp;
1393 bool isConverted = (cc !=
child.convertForAcquisition(*
this, sOpt));
1396 if (!
child.fComp && getObject<RooAbsReal>(
child.GetName())) {
1397 Info(
"Add",
"Adding existing function %s to %s",
child.GetName(),
p->
GetName());
1398 out = getObject<RooAbsReal>(
child.GetName());
1401 if (!out && !
child.fComp) {
1402 std::shared_ptr<RooAbsArg>
_func;
1413 std::make_unique<TH1D>(
child.GetName(),
child.GetTitle(), _ax->GetNbins(), _ax->binning()->array());
1415 h->GetXaxis()->SetName(
TString::Format(
"%s;%s", _ax->GetParent()->GetName(), _ax->GetName()));
1418 }
else if (_obs.size() == 1) {
1422 TString binningName =
p->getStringAttribute(
"binning");
1423 for (
auto &
b : _bnames) {
1431 auto h = std::make_unique<TH1D>(
child.GetName(),
child.GetTitle(), _x->numBins(binningName),
1432 _x->getBinningPtr(binningName)->array());
1434 h->GetXaxis()->SetName(
1440 throw std::runtime_error(
"Unsupported creation of new component in SumPdf for this many obs");
1450 if (
auto _f = std::dynamic_pointer_cast<RooHistFunc>(
1455 if (_f->getAttribute(
"autodensity")) {
1457 for (
int i = 0; i < _f->dataHist().numEntries(); i++) {
1458 auto bin_pars = _f->dataHist().get(i);
1459 _f->dataHist().set(*bin_pars, _f->dataHist().weight() / _f->dataHist().binVolume(*bin_pars));
1461 _f->setAttribute(
"autodensity",
false);
1462 _f->setValueDirty();
1471 Info(
"Add",
"Created %s factor RooHistFunc::%s for %s",
1472 _f->getAttribute(
"density") ?
"densityhisto" :
"histo", _f->GetName(),
p->
GetName());
1475 if (
auto _f = std::dynamic_pointer_cast<RooAbsReal>(out); _f) {
1483 if (
auto _boundaries = std::unique_ptr<std::list<double>>(_f->binBoundaries(
1484 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
1485 std::numeric_limits<double>::infinity()));
1486 !_boundaries && _ax->GetNbins() > 0) {
1487#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
1488 Warning(
"Add",
"Adding unbinned function %s to binned %s - will wrap it in a RooBinSamplingPdf",
1490 auto sumPdf = acquireNew<RooRealSumPdf>(
TString::Format(
"%s_pdfWrapper", _f->GetName()), _f->GetTitle(),
1491 *_f, *acquire<RooRealVar>(
"1",
"1", 1),
true);
1492 sumPdf->setStringAttribute(
"alias", _f->getStringAttribute(
"alias"));
1493 if (!sumPdf->getStringAttribute(
"alias"))
1494 sumPdf->setStringAttribute(
"alias", out->GetName());
1495 _f = acquireNew<RooBinSamplingPdf>(
TString::Format(
"%s_binned", _f->GetName()), _f->GetTitle(),
1497 _f->setStringAttribute(
"alias", std::dynamic_pointer_cast<RooAbsArg>(out)->getStringAttribute(
"alias"));
1498 if (!_f->getStringAttribute(
"alias"))
1499 _f->setStringAttribute(
"alias", out->GetName());
1501 throw std::runtime_error(
1502 "unsupported addition of unbinned function to binned model - please upgrade to at least ROOT 6.24");
1507 const_cast<RooArgList&
>(
p->coefList()).add(*acquire<RooRealVar>(
"1",
"1", 1));
1510 if (!
p->getStringAttribute(
"binning"))
1511 p->setStringAttribute(
"binning", _f->getStringAttribute(
"binning"));
1514 if (
auto gf =
p->getStringAttribute(
"global_factors"); gf) {
1517 auto fac = getObject<RooAbsReal>(pattern.
Data());
1519 throw std::runtime_error(
TString::Format(
"Could not find global factor %s", pattern.
Data()));
1527 }
else if (
auto p2 = get<RooProdPdf>(); p2) {
1534 bool tooMany(
false);
1547 }
else if (!tooMany) {
1548 auto out = this->
operator[](
"samples")->Add(child);
1554 bool tooMany(
false);
1556 if (
auto _p = pp->get<
RooAddPdf>(); _p) {
1567 }
else if (!tooMany) {
1568 auto out = this->
operator[](
"components")->Add(child);
1572 }
else if (
auto s = get<RooSimultaneous>(); s) {
1580 }
else if (
auto w = get<RooWorkspace>();
w) {
1581 child.convertForAcquisition(*
this);
1588 if (!
child.empty() ||
child.fFolder ==
"!models") {
1591 std::string catName =
"channelCat";
1592 if (!
child.empty()) {
1593 if (
TString ss =
child.at(0)->GetName(); ss.Contains(
"=")) {
1594 catName = ss(0, ss.Index(
'='));
1597 auto _cat = acquire<RooCategory>(catName.c_str(), catName.c_str());
1598 _cat->setAttribute(
"obs");
1599 auto out = acquireNew<RooSimultaneous>(
child.GetName(),
child.GetTitle(), *_cat);
1600 Info(
"Add",
"Created model RooSimultaneous::%s in workspace %s", out->GetName(),
w->GetName());
1605 if (sOpt ==
"model") {
1607 if (get<RooWorkspace>()) {
1611 }
else if (sOpt ==
"channel") {
1613 if (get<RooSimultaneous>()) {
1615 }
else if (get<RooWorkspace>()) {
1616 std::shared_ptr<TObject> out;
1617 child.convertForAcquisition(*
this);
1620 else if (!
child.fComp) {
1621 out = acquireNew<RooProdPdf>(
child.GetName(),
1623 Info(
"Add",
"Created channel RooProdPdf::%s in workspace %s", out->GetName(),
get()->
GetName());
1627 }
else if (sOpt ==
"sample" || sOpt ==
"func") {
1628 if (get<RooProdPdf>()) {
1631 return _mainChild.Add(
child, sOpt ==
"func" ?
"func" :
"");
1633 return (*
this)[
"samples"]->Add(
child, sOpt ==
"func" ?
"func" :
"");
1636 }
else if (sOpt ==
"dataset") {
1637 if (get<RooWorkspace>()) {
1639 return (*this).datasets().Add(
child);
1646 if (get<RooSimultaneous>()) {
1650 }
else if (get<RooProduct>() || get<RooProdPdf>()) {
1696 if (
auto a = get<RooAbsArg>()) {
1697 a->setAttribute(
"hidden", set);
1706 auto a = get<RooAbsArg>();
1708 return a->getAttribute(
"hidden");
1715 if (
get() == rhs.
get()) {
1765 if (
auto s = get<RooSimultaneous>(); s) {
1766 auto chans =
bins();
1767 if (!chans.empty()) {
1773 for (
auto &
c : chans) {
1775 cName = cName(cName.
Index(
'=') + 1, cName.
Length());
1778 c->shallowCopy(
name +
"_" +
c->get()->GetName(), std::shared_ptr<xRooNode>(&out, [](
xRooNode *) {}));
1779 pdf->addPdf(*
dynamic_cast<RooAbsPdf *
>(c_copy.get()), cName);
1784 }
else if (
auto p =
dynamic_cast<RooProdPdf *
>(o);
p) {
1786 std::shared_ptr<RooProdPdf> pdf = std::dynamic_pointer_cast<RooProdPdf>(
1790 auto newMain = std::dynamic_pointer_cast<RooAbsArg>(
1791 out.
acquire(std::shared_ptr<TObject>(
main->Clone((
name +
"_pdf").c_str()))));
1792 pdf->replaceServer(*pdf->pdfList().find(
main->GetName()), *newMain,
true,
true);
1793 const_cast<RooArgList&
>(pdf->pdfList()).replace(*pdf->pdfList().find(
main->GetName()), *newMain);
1827 if (
get() &&
get() !=
this) {
1830 (get<RooAbsArg>() && (get<RooAbsArg>()->isFundamental() || get<RooConstVar>() || get<RooAbsData>())) ||
1831 get<RooProduct>()) {
1833 auto _snap = std::unique_ptr<RooAbsCollection>(_deps.snapshot());
1836 if (
auto _fr = get<RooFitResult>(); _fr &&
dynamic_cast<RooStringVar *
>(_fr->constPars().
find(
".log"))) {
1837 std::cout <<
"Minimization Logs:" << std::endl;
1838 std::cout << dynamic_cast<RooStringVar *>(_fr->constPars().find(
".log"))->getVal() << std::endl;
1840 _deps.assignValueOnly(*_snap);
1844 }
else if (!
get()) {
1845 std::cout << std::endl;
1849 std::vector<std::string> folderNames;
1850 for (
auto &k : *
this) {
1851 if (std::find(folderNames.begin(), folderNames.end(), k->fFolder) == folderNames.end()) {
1852 folderNames.push_back(k->fFolder);
1855 for (
auto &
f : folderNames) {
1859 for (
int j = 0; j <
indent; j++)
1861 std::cout <<
f << std::endl;
1864 for (
auto &k : *
this) {
1865 if (k->fFolder !=
f) {
1869 for (
int j = 0; j < iindent; j++)
1871 std::cout << i++ <<
") " << k->GetName() <<
" : ";
1875 auto _deps = k->coords(
false).argList();
1876 auto _snap = std::unique_ptr<RooAbsCollection>(_deps.snapshot());
1878 k->get()->Print(sOpt);
1879 _deps.assignValueOnly(*_snap);
1881 std::cout << k->get()->ClassName() <<
"::" << k->get()->GetName() << std::endl;
1883 k->Print(sOpt +
TString::Format(
"depth=%dindent=%d", depth - 1, iindent + 1));
1886 std::cout <<
" NULL " << std::endl;
1895 if (
auto v = get<RooRealVar>();
v) {
1898 double mean = std::numeric_limits<double>::quiet_NaN();
1899 double sigma = mean;
1908 mean = std::numeric_limits<double>::quiet_NaN();
1911 constrType =
"normal";
1912 }
else if (constrType ==
"normal") {
1915 }
else if (constrType ==
"gaussian") {
1919 throw std::runtime_error(
"No error on parameter for gaussian constraint");
1922 constrType =
"normal";
1923 }
else if (constrType ==
"poisson") {
1925 throw std::runtime_error(
"No error on parameter for poisson constraint");
1927 sigma = pow(
v->getVal() /
v->getError(), 2);
1930 if (constrType ==
"poisson") {
1932 double tau_val =
sigma;
1933 auto globs = acquire<RooRealVar>(
Form(
"globs_%s",
v->GetName()),
Form(
"globs_%s",
v->GetName()),
1934 v->getVal() * tau_val, (
v->getVal() - 5 *
v->getError()) * tau_val,
1935 (
v->getVal() + 5 *
v->getError()) * tau_val);
1936 globs->setConstant();
1937 globs->setAttribute(
"obs");
1938 globs->setAttribute(
"global");
1940 auto tau = acquireNew<RooConstVar>(
TString::Format(
"tau_%s",
v->GetName()),
"", tau_val);
1941 auto constr = acquireNew<RooPoisson>(
1950 v->setError(mean / sqrt(tau_val));
1951 Info(
"Constrain",
"Added poisson constraint pdf RooPoisson::%s (tau=%g) for %s", out->GetName(), tau_val,
1954 }
else if (constrType ==
"normal") {
1956 auto globs = acquire<RooRealVar>(
Form(
"globs_%s",
v->GetName()),
Form(
"globs_%s",
v->GetName()), mean,
1958 globs->setAttribute(
"obs");
1959 globs->setAttribute(
"global");
1960 globs->setConstant();
1963 auto constr = acquireNew<RooGaussian>(
1969 Info(
"Constrain",
"Added gaussian constraint pdf RooGaussian::%s (mean=%g,sigma=%g) for %s", out->GetName(),
1976 auto _me = get<RooAbsArg>();
1978 throw std::runtime_error(
"Cannot constrain non arg");
1981 if (!
p->dependsOn(*_me)) {
1982 throw std::runtime_error(
"Constraint does not depend on constrainee");
1991 throw std::runtime_error(
"Nowhere to put constraint");
1997 for (
auto &
c : *
x) {
2003 return x->Multiply(
child);
2005 return x->Add(
child,
"+");
2018 ~AutoUpdater() {
n.browse(); }
2021 AutoUpdater xxx(*
this);
2028 auto o = std::dynamic_pointer_cast<RooAbsReal>(
acquire(
child.fComp));
2051 ?
fParent->mainChild()->GetName()
2056 binFactors =
fParent->factors().find(
"binFactors");
2058 throw std::runtime_error(
2065 for (
auto &
b : binFactors->bins()) {
2066 auto p = acquireNew<RooProduct>(
TString::Format(
"%s_bin%d", binFactors->get()->GetName(), i),
2068 p->setStringAttribute(
"alias",
TString::Format(
"%s=%g", binFactors->GetXaxis()->GetParent()->GetName(),
2069 binFactors->GetXaxis()->GetBinCenter(i)));
2076 auto _bin = binFactors->bins().at(
fBinNumber - 1);
2077 if (
auto phf = binFactors->get<
ParamHistFunc>(); phf && _bin) {
2078#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2083 if (strcmp(_bin->GetName(),
"1") == 0) {
2085 for (
int i = 0; i < pSet.
getSize(); i++) {
2087 all.
add(*pSet.
at(i));
2094 _bin->fBinNumber = -1;
2095 return _bin->Multiply(
child, opt);
2123 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(
child), [](
TObject *) {}));
2128 std::rethrow_exception(std::current_exception());
2136 if (
auto o = getObject<RooAbsReal>(
child.GetName())) {
2140 Info(
"Multiply",
"Scaled %s by existing factor %s::%s",
2143 }
else if (sOpt ==
"norm") {
2146 Info(
"Multiply",
"Scaled %s by new norm factor %s",
2149 }
else if (sOpt ==
"shape" || sOpt ==
"histo" || sOpt ==
"blankshape") {
2154 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
2155 h->SetBinContent(i, 1);
2160 h->SetTitle(
child.GetTitle());
2165 Info(
"Multiply",
"Scaled %s by new %s factor %s",
2169 }
else if (sOpt ==
"overall") {
2170 auto out =
Multiply(acquireNew<RooStats::HistFactory::FlexibleInterpVar>(
2171 child.GetName(),
child.GetTitle(),
RooArgList(), 1, std::vector<double>(), std::vector<double>()));
2173 Info(
"Multiply",
"Scaled %s by new overall factor %s",
2176 }
else if (sOpt ==
"func" &&
ws()) {
2181 Info(
"Multiply",
"Scaled %s by new func factor %s",
2187 if (
auto h =
child.get<
TH1>();
h && strlen(
h->GetOption()) == 0 && strlen(opt) > 0) {
2191 if (
auto w = get<RooWorkspace>();
w) {
2193 std::shared_ptr<TObject> out;
2194 child.convertForAcquisition(*
this);
2200 if (strcmp(
GetName(),
".coefs") == 0) {
2203 for (
size_t i = 0; i <
p->pdfList().size(); i++) {
2205 auto coefs =
p->coefList().at(i);
2214 for (
size_t j = 0; j <
p->coefList().size(); j++) {
2216 oldCoefs.
add(*newCoefs);
2218 oldCoefs.add(*
p->coefList().at(j));
2220 const_cast<RooArgList&
>(
p->coefList()).removeAll();
2221 const_cast<RooArgList&
>(
p->coefList()).add(oldCoefs);
2228 throw std::runtime_error(
"this coefs case is not supported");
2231 if (
auto p = get<RooProduct>();
p) {
2232 std::shared_ptr<TObject> out;
2233 auto cc =
child.fComp;
2234 bool isConverted = (
child.convertForAcquisition(*
this) != cc);
2239 if (
auto _f = std::dynamic_pointer_cast<RooHistFunc>(
2241 _f && _f->getAttribute(
"autodensity")) {
2243 bool hasDensity =
false;
2251 if (_f->getAttribute(
"density")) {
2254 for (
int i = 0; i < _f->dataHist().numEntries(); i++) {
2255 auto bin_pars = _f->dataHist().get(i);
2256 _f->dataHist().set(*bin_pars, _f->dataHist().weight() / _f->dataHist().binVolume(*bin_pars));
2258 _f->setValueDirty();
2265 _f->setAttribute(
"autodensity",
false);
2269 Info(
"Multiply",
"Created %s factor %s in %s",
2273 Info(
"Multiply",
"Created shape factor %s in %s",
child->GetName(),
p->
GetName());
2276 if (
auto _f = std::dynamic_pointer_cast<RooAbsReal>(out); _f) {
2277#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2278 p->_compRSet.add(*_f);
2280 const_cast<RooArgList&
>(
p->realComponents()).add(*_f);
2286 for (
auto &_par : _out.
pars()) {
2289 for (
auto &_constr : _par->constraints()) {
2290 if (strcmp(s, _constr->get()->GetName()) == 0) {
2297 Info(
"Multiply",
"Pulling in %s boundConstraint: %s", _par->GetName(), s);
2298 auto _pdf = getObject<RooAbsPdf>(s);
2300 throw std::runtime_error(
"Couldn't find boundConstraint");
2302 _par->Constrain(_pdf);
2309 }
else if (
auto p2 = get<RooProdPdf>(); p2) {
2311 std::shared_ptr<TObject> out;
2312 child.convertForAcquisition(*
this);
2321 std::shared_ptr<RooAbsPdf> _pdf;
2322 if (!
child.get() && strcmp(
child.GetName(),
"components") == 0) {
2323 auto _sumpdf = acquireNew<RooAddPdf>(
Form(
"%s_%s", p2->GetName(),
child.GetName()),
2324 (strlen(
child.GetTitle()) && strcmp(
child.GetTitle(),
child.GetName()))
2330 auto _sumpdf = acquireNew<RooRealSumPdf>(
2331 Form(
"%s_%s", p2->GetName(),
child.GetName()),
2335 _sumpdf->setFloor(
true);
2338 _pdf->setStringAttribute(
"alias",
child.GetName());
2340 _pdf->setStringAttribute(
"xvar", p2->getStringAttribute(
"xvar"));
2341 _pdf->setStringAttribute(
"binning", p2->getStringAttribute(
"binning"));
2343 Info(
"Multiply",
"Created %s::%s in channel %s", _pdf->ClassName(), _pdf->GetName(), p2->GetName());
2348 if (
auto _pdf = std::dynamic_pointer_cast<RooAbsPdf>(out); _pdf) {
2349#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2350 const_cast<RooArgList&
>(p2->pdfList()).add(*_pdf);
2351#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
2352 p2->_pdfNSetList.emplace_back(std::make_unique<RooArgSet>(
"nset"));
2356 if (!p2->canBeExtended() && _pdf->canBeExtended()) {
2357 p2->_extendedIndex = p2->_pdfList.size() - 1;
2370 }
else if (
auto p3 = get<RooRealSumPdf>(); p3) {
2372 std::shared_ptr<TObject> out;
2373 child.convertForAcquisition(*
this);
2379 TString s = p3->getStringAttribute(
"global_factors");
2382 s += out->GetName();
2383 p3->setStringAttribute(
"global_factors", s);
2386 "Flagged %s as a global factor in channel %s (is applied to all current and future samples in the channel)",
2387 out->GetName(), p3->GetName());
2398 std::set<RooAbsArg *> cl;
2399 for (
auto &arg : p5->clients()) {
2405 if (cl.size() > 1) {
2410 Warning(
"Multiply",
"Scaling %s that has multiple clients", p5->GetName());
2416 for (
auto &
a : p5->attributes())
2417 new_p->setAttribute(
a.c_str());
2418 for (
auto &
a : p5->stringAttributes())
2419 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
2420 if (!new_p->getStringAttribute(
"alias"))
2421 new_p->setStringAttribute(
"alias", p5->GetName());
2423 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
2424 for (
auto arg : cl) {
2425 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
2433 if (!
child.get() && strlen(opt) == 0)
2436 throw std::runtime_error(
2438 (!
child.get() && strlen(opt) == 0) ?
" (forgot to specify factor type?)" :
""));
2447 ~AutoUpdater() {
n.browse(); }
2450 AutoUpdater xxx(*
this);
2455 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(
child), [](
TObject *) {}));
2460 std::rethrow_exception(std::current_exception());
2472 std::string label =
child.GetName();
2473 if (
auto pos = label.find(
"="); pos != std::string::npos)
2474 label = label.substr(pos + 1);
2475 if (!s->indexCat().hasLabel(label)) {
2478 std::shared_ptr<TObject> out;
2479 child.convertForAcquisition(*
this);
2482 else if (!
child.fComp) {
2483 out = acquireNew<RooProdPdf>(
TString::Format(
"%s_%s", s->GetName(), label.c_str()),
2485 Info(
"Vary",
"Created channel RooProdPdf::%s in model %s", out->GetName(), s->GetName());
2488 if (
auto _pdf = std::dynamic_pointer_cast<RooAbsPdf>(out); _pdf) {
2489 s->addPdf(*_pdf, label.c_str());
2497 }
else if (
auto p = get<RooStats::HistFactory::FlexibleInterpVar>();
p) {
2500 child.convertForAcquisition(*
this);
2502 if (!_c &&
child.get()) {
2503 throw std::runtime_error(
"Only pure consts can be set as variations of a flexible interpvar");
2505#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2506 double value = (_c ? _c->getVal() :
p->_nominal);
2507 double nomVal =
p->_nominal;
2509 double value = (_c ? _c->getVal() :
p->nominal());
2510 double nomVal =
p->nominal();
2514 if (cName ==
"nominal") {
2519 throw std::runtime_error(
"unsupported variation form");
2521 std::string parName = cName(0, cName.
Index(
'='));
2523 if (parVal != 1 && parVal != -1) {
2524 throw std::runtime_error(
"unsupported variation magnitude");
2526 bool high = parVal > 0;
2528 if (parName.empty()) {
2537 if (!
p->findServer(*
v)) {
2538#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2539 p->_paramList.add(*
v);
2540 p->_low.push_back(0);
2541 p->_high.push_back(0);
2542 p->_interpCode.push_back(4);
2545 const_cast<std::vector<double>&
>(
p->low()).push_back(0);
2546 const_cast<std::vector<double>&
>(
p->high()).push_back(0);
2547 const_cast<std::vector<int>&
>(
p->interpolationCodes()).push_back(4);
2549 v->setAttribute(
Form(
"SYMMETRIC%s_%s", high ?
"+" :
"-",
GetName()));
2554 if (
v->getAttribute(
Form(
"SYMMETRIC+_%s",
GetName()))) {
2555 p->setLow(*
v, 2 * nomVal -
value);
2557 v->setAttribute(
Form(
"SYMMETRIC-_%s",
GetName()),
false);
2560 if (
v->getAttribute(
Form(
"SYMMETRIC-_%s",
GetName()))) {
2561 p->setHigh(*
v, 2 * nomVal -
value);
2563 v->setAttribute(
Form(
"SYMMETRIC+_%s",
GetName()),
false);
2571 }
else if (
auto p2 = get<PiecewiseInterpolation>(); p2) {
2574 throw std::runtime_error(
"unsupported variation form");
2578 if (parVal != 1 && parVal != -1) {
2579 throw std::runtime_error(
"unsupported variation magnitude");
2581#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2584 throw std::runtime_error(
2585 TString::Format(
"Interpolating %s instead of RooHistFunc", p2->_nominal.absArg()->ClassName()));
2590 throw std::runtime_error(
2591 TString::Format(
"Interpolating %s instead of RooHistFunc", p2->nominalHist()->ClassName()));
2597 for (
auto par : p2->paramList()) {
2598 if (parName == par->GetName()) {
2599 f =
dynamic_cast<RooHistFunc *
>((parVal > 0 ? p2->highList() : p2->lowList()).
at(i));
2600 otherf =
dynamic_cast<RooHistFunc *
>((parVal > 0 ? p2->lowList() : p2->highList()).
at(i));
2608 auto v = acquire<RooRealVar>(parName, parName, -5, 5);
2612 std::shared_ptr<RooHistFunc> up(
static_cast<RooHistFunc *
>(
f->Clone(
Form(
"%s_%s_up",
f->GetName(), parName.
Data()))));
2613 std::shared_ptr<RooHistFunc> down(
static_cast<RooHistFunc *
>(
f->Clone(
Form(
"%s_%s_down",
f->GetName(), parName.
Data()))));
2615#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2616 std::unique_ptr<RooDataHist>
h1(
static_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", up->GetName()))));
2617 std::unique_ptr<RooDataHist> h2(
static_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", down->GetName()))));
2618 up->_dataHist =
dynamic_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", up->GetName())));
2619 down->_dataHist =
dynamic_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", down->GetName())));
2622 down->cloneAndOwnDataHist(
TString::Format(
"hist_%s", down->GetName()));
2624 auto ups = std::dynamic_pointer_cast<RooHistFunc>(
acquire(up,
false,
true));
2625 auto downs = std::dynamic_pointer_cast<RooHistFunc>(
acquire(down,
false,
true));
2626#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2627 p2->_highSet.add(*ups.get());
2628 p2->_lowSet.add(*downs.get());
2629 p2->_interpCode.push_back(4);
2630 p2->_paramSet.add(*
v);
2632 const_cast<RooArgList&
>(p2->highList()).add(*ups.get());
2633 const_cast<RooArgList&
>(p2->lowList()).add(*downs.get());
2634 const_cast<std::vector<int>&
>(p2->interpolationCodes()).push_back(4);
2637 p2->setValueDirty();
2638 f = ((parVal > 0) ? ups : downs).
get();
2639 otherf = ((parVal > 0) ? downs : ups).
get();
2641 f->setStringAttribute(
"symmetrizes", otherf->
GetName());
2642 f->setStringAttribute(
"symmetrize_nominal", nomf->
GetName());
2661 }
else if (
auto p3 = get<RooConstVar>(); p3) {
2664 if (p3->getAttribute(
"RooRealConstant_Factory_Object")) {
2665 throw std::runtime_error(
"Cannot vary pure constants");
2671 std::set<RooAbsArg *> cl;
2672 for (
auto &arg : p3->clients()) {
2677 if (cl.size() > 1) {
2682 Warning(
"Vary",
"Varying %s that has multiple clients", p3->GetName());
2685 p3->setStringAttribute(
"origName", p3->GetName());
2687 p3->SetName(
Form(
"%s_nominal", p3->GetName()));
2689 auto new_p = acquireNew<RooStats::HistFactory::FlexibleInterpVar>(
n, p3->GetTitle(),
RooArgList(), p3->getVal(),
2690 std::vector<double>(), std::vector<double>());
2693 for (
auto &
a : p3->attributes())
2694 new_p->setAttribute(
a.c_str());
2695 for (
auto &
a : p3->stringAttributes())
2696 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
2699 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
2700 for (
auto arg : cl) {
2701 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
2707 }
else if (
auto p4 = get<RooAbsReal>(); p4) {
2711 std::set<RooAbsArg *> cl;
2712 for (
auto &arg : p4->clients()) {
2717 if (cl.size() > 1) {
2722 Warning(
"Vary",
"Varying %s that has multiple clients", p4->GetName());
2725 p4->setStringAttribute(
"origName", p4->GetName());
2727 p4->SetName(
Form(
"%s_nominal", p4->GetName()));
2732 for (
auto &
a : p4->attributes())
2733 new_p->setAttribute(
a.c_str());
2734 for (
auto &
a : p4->stringAttributes())
2735 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
2738 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
2739 for (
auto arg : cl) {
2740 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
2781 if (
auto a = get<RooAbsArg>();
a && strcmp(
a->GetName(),
GetName()) && !
a->getStringAttribute(
"alias")) {
2782 a->setStringAttribute(
"alias",
GetName());
2785 throw std::runtime_error(
"Cannot determine type");
2790 if (
auto h =
dynamic_cast<const TH1 *
>(&o);
h) {
2801 bool _isData = get<RooAbsData>();
2807 throw std::runtime_error(
"no xaxis");
2808 auto _v =
dynamic_cast<RooRealVar *
>(ax->GetParent());
2811 _b.
b =
dynamic_cast<RooAbsBinning *
>(_v->getBinningPtr(0)->Clone());
2812 if (
h->GetXaxis()->IsVariableBinSize()) {
2813 _v->setBinning(
RooBinning(
h->GetNbinsX(),
h->GetXaxis()->GetXbins()->GetArray()));
2815 _v->setBinning(
RooUniformBinning(
h->GetXaxis()->GetXmin(),
h->GetXaxis()->GetXmax(),
h->GetNbinsX()));
2821 for (
int bin = 1; bin <=
h->GetNbinsX(); bin++) {
2829 if (!_isData &&
h->GetSumw2N() && !
SetBinError(bin,
h->GetBinError(bin)))
2830 throw std::runtime_error(
"Failed setting stat error");
2834 }
else if (
auto _c =
dynamic_cast<const RooConstVar *
>(&o); _c) {
2836 if (
auto a = get<RooAbsArg>();
2837 (
a &&
a->isFundamental()) || get<RooConstVar>() || get<RooStats::HistFactory::FlexibleInterpVar>()) {
2843 throw std::runtime_error(
"Assignment failed");
2870 auto _pars =
pars();
2874 auto idx = pattern.
Index(
'=');
2877 (idx == -1) ? std::numeric_limits<double>::quiet_NaN() :
TString(pattern(idx + 1, pattern.
Length())).
Atof();
2878 for (
auto p : _pars.argList()) {
2880 p->setAttribute(
"Constant",
true);
2885 auto _nll =
nll(datasetName);
2886 _nll.fitConfigOptions()->SetValue(
"LogSize", 65536);
2887 _nll.fitConfig()->MinimizerOptions().SetPrintLevel(0);
2888 auto fr = _nll.minimize();
2891 throw std::runtime_error(
"Fit Failed");
2893 if (fr->status() != 0)
2899 }
catch (
const std::exception &
e) {
2908 datasets().
Add(datasetName, expected ?
"asimov" :
"toy");
2909 }
catch (
const std::exception &
e) {
2919 }
catch (
const std::exception &
e) {
2929 throw std::runtime_error(
"Failed to SetContent");
2930 }
catch (
const std::exception &
e) {
2944 std::shared_ptr<TH1D>
h;
2945 auto _b =
dynamic_cast<Axis2 *
>(ax)->binning();
2948 if (_b->isUniform()) {
2955 h->GetXaxis()->SetName(
TString::Format(
"%s;%s", ax->GetParent()->GetName(), ax->GetName()));
2963 if (get<RooProduct>()) {
2967 if (get<RooAbsData>()) {
2968 if (
auto _data = get<RooDataSet>(); _data) {
2971 throw std::runtime_error(
"Cannot determine binning to fill data");
2973 if (_ax->GetNbins() < bin)
2974 throw std::out_of_range(
TString::Format(
"%s range %s only has %d bins", _ax->GetParent()->GetName(),
2975 _ax->GetName(), _ax->GetNbins()));
2980 for (
auto _c :
coords()) {
2984 cut +=
TString::Format(
"%s==%d", _cat->GetName(), _cat->getCurrentIndex());
2987 throw std::runtime_error(
"SetBinContent of data: Unsupported coordinate type");
2994 TString cut2 =
TString::Format(
"%s >= %f && %s < %f", _ax->GetParent()->GetName(), _ax->GetBinLowEdge(bin),
2995 _ax->GetParent()->GetName(), _ax->GetBinUpEdge(bin));
3025 l.remove(*_data->get(),
true,
true);
3030 _data->addColumn(*
x);
3040 for (
auto &o :
obs) {
3042 if (
auto dv =
dynamic_cast<RooRealVar *
>(_data->get()->find(
v->GetName())); dv) {
3043 if (
v->getMin() < dv->getMin())
3044 dv->setMin(
v->getMin());
3045 if (
v->getMax() > dv->getMax())
3046 dv->setMax(
v->getMax());
3049 if (
auto dc =
dynamic_cast<RooCategory *
>(_data->get()->find(
c->GetName())); dc) {
3050 if (!dc->hasLabel(
c->getCurrentLabel())) {
3051 dc->defineType(
c->getCurrentLabel(),
c->getCurrentIndex());
3059 if (
auto _nentries = std::unique_ptr<RooAbsData>(_data->reduce(cutFormula))->numEntries();
3060 _nentries != _ax->GetNbins()) {
3063 if (_nentries > 0) {
3064 Info(
"SetBinContent",
"Binning %s in channel: %s",
GetName(), cut.
Data());
3065 auto _reduced = std::unique_ptr<RooAbsData>(_data->reduce(icutFormula));
3067 for (
int j = 0; j < _reduced->numEntries(); j++) {
3068 auto _obs = _reduced->get(j);
3069 _data->add(*_obs, _reduced->weight());
3072 for (
int i = 1; i <= _ax->GetNbins(); i++) {
3076 dynamic_cast<RooAbsLValue *
>(_ax->GetParent())->setBin(i - 1, _ax->GetName());
3077 _data->add(
obs, _contents.
at(i - 1));
3082 if (std::unique_ptr<RooAbsData>(_data->reduce(cutFormula2))->numEntries() > 0) {
3083 auto _reduced = std::unique_ptr<RooAbsData>(_data->reduce(icutFormula2));
3085 for (
int j = 0; j < _reduced->numEntries(); j++) {
3086 auto _obs = _reduced->get(j);
3087 _data->add(*_obs, _reduced->weight());
3090 dynamic_cast<RooAbsLValue *
>(_ax->GetParent())->setBin(bin - 1, _ax->GetName());
3094 }
else if (get<RooDataHist>()) {
3095 throw std::runtime_error(
"RooDataHist not supported yet");
3099 if (
auto _varies =
variations(); !_varies.empty() || (par && strlen(par))) {
3100 if (!par || strlen(par) == 0) {
3101 return _varies[
"nominal"]->SetBinContent(bin,
value, par, parVal);
3102 }
else if (
auto it = _varies.find(
Form(
"%s=%g", par, parVal)); it) {
3103 return it->SetBinContent(bin,
value);
3115 if (!par || strlen(par) == 0) {
3128 if (strcmp(
c->GetName(),
Form(
"%g",
c->getVal())) == 0) {
3131#if ROOT_VERSION_CODE < ROOT_VERSION(6, 24, 00)
3144 auto bin_pars =
f->dataHist().get(bin - 1);
3145 if (
f->getAttribute(
"density")) {
3146 value /=
f->dataHist().binVolume(*bin_pars);
3148 f->dataHist().set(*bin_pars,
value);
3151 if (
auto otherfName =
f->getStringAttribute(
"symmetrized_by"); otherfName) {
3153 f->setStringAttribute(
"symmetrized_by",
nullptr);
3154 if (
auto x = getObject<RooAbsArg>(otherfName);
x) {
3155 x->setStringAttribute(
"symmetrizes",
nullptr);
3156 x->setStringAttribute(
"symmetrize_nominal",
nullptr);
3158 }
else if (
auto otherfName2 =
f->getStringAttribute(
"symmetrizes"); otherfName2) {
3159 auto nomf = getObject<RooHistFunc>(
f->getStringAttribute(
"symmetrize_nominal"));
3160 auto otherf = getObject<RooHistFunc>(otherfName2);
3161 if (nomf && otherf) {
3162 otherf->dataHist().set(*bin_pars, 2 * nomf->dataHist().weight(bin - 1) -
value);
3163 otherf->setValueDirty();
3170 f2->setNominal(
value);
3184 if (get<RooProduct>()) {
3188 if (
auto _varies =
variations(); !_varies.empty()) {
3189 return _varies[
"nominal"]->SetBinError(bin,
value);
3204 while (_prodParent && !_prodParent->get<
RooProduct>() && !_prodParent->get<
RooAbsPdf>()) {
3206 _prodParent.reset();
3209 _prodParent = _prodParent->fParent;
3212 (_prodParent && !_prodParent->get<
RooAbsPdf>()) ? _prodParent->factors().find(
"statFactor") :
nullptr;
3213 auto f_stat = (_f_stat) ? _f_stat->get<
ParamHistFunc>() :
nullptr;
3214 if (_f_stat && _f_stat->get() && !f_stat) {
3215 throw std::runtime_error(
"stat factor must be a paramhistfunc");
3224 for (
auto &
p :
xRooNode(
"tmp", *
f, std::shared_ptr<xRooNode>(
nullptr)).
vars()) {
3229 auto h = std::unique_ptr<TH1>(
f->dataHist().createHistogram(parNames
3236 h->SetName(
"statFactor");
3238 h->SetOption(
"blankshape");
3241 auto toMultiply =
this;
3245 f_stat =
dynamic_cast<ParamHistFunc *
>(toMultiply->Multiply(*h).get());
3247 throw std::runtime_error(
"Failed creating stat shapeFactor");
3253 TString prefix =
f->getStringAttribute(
"statPrefix");
3254 if (
value && prefix ==
"") {
3258 while (_p && !(_p->get()->InheritsFrom(
"RooRealSumPdf") || _p->get()->InheritsFrom(
"RooAddPdf") ||
3259 _p->get()->InheritsFrom(
"RooWorkspace") || _p->get()->InheritsFrom(
"RooAddition"))) {
3264 auto newVar = (
value == 0) ? getObject<RooRealVar>(
"1")
3265 : acquire<RooRealVar>(
Form(
"%s_bin%d", prefix.
Data(), bin),
3266 Form(
"%s_bin%d", prefix.
Data(), bin), 1);
3267#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3272 auto var =
dynamic_cast<RooRealVar *
>(&pSet[bin - 1]);
3274 if (newVar.get() != var) {
3278 for (
int i = 0; i < pSet.
getSize(); i++) {
3280 all.
add(*pSet.
at(i));
3291 if (strcmp(rrv->GetName(),
"1") != 0) {
3292 TString origName = (
f->getStringAttribute(
"origName")) ?
f->getStringAttribute(
"origName") :
GetName();
3294 auto bin_pars =
f->dataHist().get(bin - 1);
3295 auto _binContent =
f->dataHist().weight();
3296 if (
f->getAttribute(
"density")) {
3297 _binContent *=
f->dataHist().binVolume(*bin_pars);
3302 for (
auto &[s, sv] : rrv->stringAttributes()) {
3303 if (s.find(
"sumw_") == 0) {
3305 }
else if (s.find(
"sumw2_") == 0) {
3309 if (sumw2 && sumw2 != std::numeric_limits<double>::infinity()) {
3310 double tau = pow(sumw, 2) / sumw2;
3311 rrv->setError((tau < 1
e-15) ? 1e15 : ( 1. / sqrt(tau)));
3312 rrv->setConstant(
false);
3314 auto _constr =
v.constraints();
3316 if (_constr.empty()) {
3317 rrv->setStringAttribute(
"boundConstraint", _constr.Add(
"poisson").get()->GetName());
3319 auto _glob = _constr.at(0)->obs().at(0)->get<
RooRealVar>();
3322 double _min = tau * (1. - 5. * sqrt(1. / tau));
3323 double _max = tau * (1. + 5. * sqrt(1. / tau));
3324 _glob->setRange(_min, _max);
3326 _constr.at(0)->args().at(0)->SetBinContent(0, tau);
3327 rrv->setStringAttribute(
"boundConstraint", _constr.at(0)->get()->GetName());
3329 rrv->setRange(std::max((1. - 5. * sqrt(1. / tau)), 1
e-15), 1. + 5. * sqrt(1. / tau));
3332 if (
auto _constr =
v.constraints(); !_constr.empty()) {
3333 v.constraints().Remove(*_constr.at(0));
3338 rrv->setConstant(sumw2 == 0);
3352 }
catch (std::out_of_range &) {
3359 if (
auto _w = get<RooWorkspace>(); _w)
3361 if (
auto a = get<RooAbsArg>();
a &&
GETWS(
a)) {
3372 xRooNode out(
".constraints",
nullptr, *
this);
3381 for (
auto &
c :
n.bins()) {
3382 if (
auto oo = getConstraint(*
c.get(), par,
nullptr); oo) {
3389 for (
auto p : _ws->allPdfs()) {
3392 if (
p->dependsOn(par)) {
3393 out.emplace_back(std::make_shared<xRooNode>(par.GetName(), *
p, *
this));
3399 return getConstraint(*
n.fParent.get(), par,
n.get<
RooAbsPdf>());
3401 for (
auto p : o->pdfList()) {
3404 if (
p->dependsOn(par)) {
3405 out.emplace_back(std::make_shared<xRooNode>(par.GetName(), *
p, *
this));
3411 for (
auto &
p :
vars()) {
3415 if (
v->getAttribute(
"Constant"))
3417 if (
v->getAttribute(
"obs"))
3419 getConstraint(*
this, *
v, get<RooAbsPdf>());
3427 auto it = out.
begin();
3428 while (it != out.
end()) {
3429 bool removeIt =
false;
3430 for (
auto &
c : out) {
3431 if (
c.get() == it->get())
3435 std::set<std::string> parNames;
3436 std::string _cName =
c->GetName();
3438 parNames.insert(_cName.substr(0, _cName.find(
';')));
3439 _cName = _cName.substr(_cName.find(
';') + 1);
3440 }
while (_cName.find(
';') != std::string::npos);
3441 parNames.insert(_cName);
3442 _cName = it->get()->GetName();
3444 parNames.insert(_cName.substr(0, _cName.find(
';')));
3445 _cName = _cName.substr(_cName.find(
';') + 1);
3446 }
while (_cName.find(
';') != std::string::npos);
3447 parNames.insert(_cName);
3449 for (
auto &
x : parNames) {
3450 if (!_cName.empty())
3454 c->TNamed::SetName(_cName.c_str());
3466 if (get<RooAbsArg>() && get<RooAbsArg>()->isFundamental()) {
3467 for (
auto &o : out) {
3468 o->TNamed::SetName(o->get()->GetName());
3482 sName =
TString(
"factory:") + sName;
3486 if (
auto h = get<TH1>();
h) {
3488 std::map<std::string, std::string> stringAttrs;
3490 auto pos = sOpt2.
Index(
"=");
3491 auto start = sOpt2.
Index(
";") + 1;
3497 stringAttrs[sOpt2(start, pos - start)] = sOpt2(pos + 1,
end - pos - 1);
3503 origName = origName(1, origName.
Length());
3506 newObjName(1, newObjName.
Length());
3512 TString varName =
h->GetXaxis()->GetName();
3513 std::string binningName = newObjName.
Data();
3514 if (
auto pos = varName.Index(
';'); pos != -1) {
3515 binningName = varName(pos + 1, varName.Length());
3516 varName = varName(0, pos);
3519 if (varName ==
"xaxis" &&
3521 if (
auto ax = acquirer.
GetXaxis(); ax) {
3522 varName = ax->GetParent()->GetName();
3524 binningName = ax->GetName();
3525 }
else if (acquirer.
obs().size() == 1)
3526 varName = acquirer.
obs().
at(0)->get()->GetName();
3528 auto x = acquirer.
acquire<
RooRealVar>(varName,
h->GetXaxis()->GetTitle(),
h->GetXaxis()->GetXmin(),
3529 h->GetXaxis()->GetXmax());
3530 if (
x->getMin() >
h->GetXaxis()->GetXmin())
3531 x->setMin(
h->GetXaxis()->GetXmin());
3532 if (
x->getMax() <
h->GetXaxis()->GetXmax())
3533 x->setMax(
h->GetXaxis()->GetXmax());
3534 if (!
x->hasBinning(binningName.c_str())) {
3535 if (
h->GetXaxis()->IsVariableBinSize()) {
3536 x->setBinning(
RooBinning(
h->GetNbinsX(),
h->GetXaxis()->GetXbins()->GetArray()), binningName.c_str());
3539 RooUniformBinning(
h->GetXaxis()->GetXmin(),
h->GetXaxis()->GetXmax(),
h->GetXaxis()->GetNbins()),
3540 binningName.c_str());
3542 x->getBinning(binningName.c_str()).
SetTitle(
h->GetXaxis()->GetTitle());
3543 if (
x->getBinningNames().size() == 2) {
3545 x->setBinning(
x->getBinning(binningName.c_str()));
3549 if (
x->getBinning(binningName.c_str()).numBins() !=
h->GetNbinsX()) {
3550 throw std::runtime_error(
3551 TString::Format(
"binning mismatch for binning %s of %s", binningName.c_str(),
x->GetName()));
3555 std::shared_ptr<RooAbsArg> _f;
3561 for (
auto &[k,
v] : stringAttrs) {
3564 x->setAttribute(
"obs",
true);
3565 }
else if (sOpt2.
Contains(
"shape")) {
3567 for (
int i = 0; i <
x->getBinning(binningName.c_str()).numBins(); i++) {
3568 std::shared_ptr<RooRealVar> arg;
3569 if (sOpt2.
Contains(
"blankshape")) {
3575 if (
h->GetMinimumStored() != -1111 ||
h->GetMaximumStored() != -1111) {
3577 h->GetBinContent(i + 1),
h->GetMinimumStored(),
3578 h->GetMaximumStored());
3581 h->GetBinContent(i + 1));
3588 auto tmp =
dynamic_cast<RooAbsBinning *
>(
x->getBinningPtr(0)->Clone());
3589 x->setBinning(
x->getBinning(binningName.c_str()));
3591#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3592 dynamic_cast<ParamHistFunc *
>(_f.get())->_paramSet.setName(
"paramSet");
3596 x->setBinning(*tmp);
3598 for (
auto &[k,
v] : stringAttrs) {
3599 _f->setStringAttribute(k.c_str(),
v.c_str());
3603 binningName.c_str() );
3605 throw std::runtime_error(
"Couldn't make data hist");
3610 f->setAttribute(
"autodensity");
3613 for (
auto &[k,
v] : stringAttrs) {
3614 _f->setStringAttribute(k.c_str(),
v.c_str());
3618 _f->setStringAttribute(
"xvar",
x->GetName());
3619 _f->setStringAttribute(
"binning", binningName.c_str());
3620 if (strcmp(_f->GetName(), origName.
Data()) && !_f->getStringAttribute(
"alias"))
3621 _f->setStringAttribute(
"alias", origName);
3624 xRooNode tmp(
h->GetName(), _f, acquirer);
3626 _f = std::dynamic_pointer_cast<RooAbsArg>(tmp.
fComp);
3629 _f->setStringAttribute(
"xvar",
x->GetName());
3630 _f->setStringAttribute(
"binning", binningName.c_str());
3633 if (strcmp(_f->GetName(), origName.
Data()) && !_f->getStringAttribute(
"alias"))
3634 _f->setStringAttribute(
"alias", origName);
3651 auto arg = get<RooAbsArg>();
3652 if (!initObject && !arg) {
3660 if (arg->getStringAttribute(
"style"))
3661 t = arg->getStringAttribute(
"style");
3666 std::shared_ptr<TStyle>
style;
3668 if (!
gROOT->GetStyle(t)) {
3669 if ((
style = getObject<TStyle>(t.
Data()))) {
3677 if (
auto x =
dynamic_cast<TAttLine *
>(initObject))
3679 if (
auto x =
dynamic_cast<TAttFill *
>(initObject))
3681 if (
auto x =
dynamic_cast<TAttMarker *
>(initObject))
3689 if (arg && !arg->getStringAttribute(
"style")) {
3690 arg->setStringAttribute(
"style",
style->GetName());
3696std::shared_ptr<TObject>
xRooNode::acquire(
const std::shared_ptr<TObject> &arg,
bool checkFactory,
bool mustBeNew)
3701 return fParent->acquire(arg, checkFactory, mustBeNew);
3705 if (_ws && (
get() == _ws || _ws->arg(
GetName()) || (arg && strcmp(arg->GetName(),
GetName()) == 0))) {
3708 if (
auto a =
dynamic_cast<RooAbsArg *
>(arg.get());
a) {
3709 auto out_arg = _ws->arg(
a->GetName());
3710 TString aName = arg->GetName();
3712 while (out_arg && mustBeNew) {
3714 out_arg = _ws->arg(
a->GetName());
3716 if (aName !=
a->GetName())
3717 Warning(
"acquire",
"Renaming to %s",
a->GetName());
3721 if (
auto res = _ws->factory(arg->GetName()); res) {
3728 Info(
"acquire",
"A copy of %s has been added to workspace %s",
a->GetName(), _ws->GetName());
3734 std::set<std::string> setNames;
3737 setNames.insert(aa.first);
3740 for (
auto &aa : setNames)
3743 out_arg = _ws->arg(
a->GetName());
3746 return std::shared_ptr<TObject>(out_arg, [](
TObject *) {});
3747 }
else if (
auto a2 =
dynamic_cast<RooAbsData *
>(arg.get()); a2) {
3753 return std::shared_ptr<TObject>(_ws->embeddedData(arg->GetName()), [](
TObject *) {});
3754 }
else if (arg->InheritsFrom(
"RooFitResult") || arg->InheritsFrom(
"TTree") || arg->IsA() ==
TStyle::Class()) {
3755 if (_ws->import(*arg.get(),
true )) {
3775 return std::shared_ptr<TObject>(_ws->genobj(arg->GetName()), [](
TObject *) {});
3782 auto out =
fProvider->getObject(arg->GetName(), arg->ClassName());
3786 auto _owned =
find(
".memory");
3788 _owned = emplace_back(std::make_shared<xRooNode>(
".memory",
nullptr, *
this));
3792 for (
auto &
r : *_owned) {
3793 if (strcmp(
r->GetName(), arg->GetName()) == 0 && strcmp(
r->get()->ClassName(), arg->ClassName()) == 0) {
3798 std::cout <<
GetName() <<
" taking over " << arg->ClassName() <<
"::" << arg->GetName() << std::endl;
3800 return _owned->emplace_back(std::make_shared<xRooNode>(arg->GetName(), arg, *
this))->fComp;
3828 auto _deps =
vars();
3840 auto a = get<RooAbsArg>();
3842 throw std::runtime_error(
"Cannot SetXaxis of non-arg");
3844 auto _x = acquire<RooRealVar>(
name, title, low, high);
3845 _x->setBinning(binning,
a->
GetName());
3846 _x->getBinning(
a->GetName()).SetTitle(title);
3847 if (_x->getBinningNames().size() == 2) {
3849 _x->setBinning(_x->getBinning(
a->GetName()));
3854 if (_x->getMax() < high)
3856 if (_x->getMin() > low)
3860 if (!_deps.find(
name) && get<RooAbsPdf>()) {
3862 _x->setAttribute(
"obs");
3865 a->setStringAttribute(
"xvar", _x->GetName());
3866 a->setStringAttribute(
"binning",
a->GetName());
3875 return at(
name,
false) !=
nullptr;
3876 }
catch (std::out_of_range &) {
3883 std::string partname = (
name.find(
'/') != std::string::npos) ?
name.substr(0,
name.find(
'/')) :
name;
3885 : get<RooSimultaneous>();
3886 std::string extra = (_s) ? _s->indexCat().GetName() :
"";
3887 for (
auto &
child : *
this) {
3889 (_obj &&
name == _obj->GetName()) || (_obj && partname == _obj->GetName()) ||
3890 (!extra.empty() && ((extra +
"=" +
name) ==
child->GetName() ||
3891 (extra +
"=" + partname) ==
child->GetName()))) {
3895 return child->at(
name.substr(partname.length() + 1));
3901 for (
auto &child2 :
x.browse()) {
3902 if (
auto _obj = child2->get();
name == child2->GetName() || partname == child2->GetName() ||
3903 (_obj &&
name == _obj->GetName()) || (_obj && partname == _obj->GetName())) {
3906 if (partname !=
name &&
name != child2->GetName()) {
3907 return child2->at(
name.substr(partname.length() + 1));
3916 auto child2 =
at(s.Atoi());
3917 if (partname !=
name) {
3918 return child2->at(
name.substr(partname.length() + 1));
3922 throw std::out_of_range(
name +
" does not exist");
3927 std::string partname = (
name.find(
'/') != std::string::npos) ?
name.substr(0,
name.find(
'/')) :
name;
3930 : get<RooSimultaneous>();
3931 std::string extra = (_s) ? _s->indexCat().GetName() :
"";
3932 for (
auto &
child : *
this) {
3935 ((extra +
"=" +
name) ==
child->GetName() || (extra +
"=" + partname) ==
child->GetName()))) {
3938 return child->operator[](
name.substr(partname.length() + 1));
3944 for (
auto &child2 :
x.browse()) {
3945 if (
name == child2->GetName() || partname == child2->GetName()) {
3947 if (partname !=
name &&
name != child2->GetName()) {
3948 return child2->operator[](
name.substr(partname.length() + 1));
3955 auto out = std::make_shared<xRooNode>(partname.c_str(),
nullptr, *
this);
3956 if (partname !=
name) {
3957 return out->operator[](
name.substr(partname.length() + 1));
3965 for (
auto o : *
gROOT->GetListOfBrowsers()) {
3967 if (!
b || !
b->GetBrowserImp())
3974 if (!
b->GetBrowserImp())
3989 for (
auto o : *
gROOT->GetListOfBrowsers()) {
3991 if (!
b || !
b->GetBrowserImp())
3998 if (
b->GetBrowserImp()) {
4003 if (
auto item =
GETLISTTREE(_b)->FindItemByObj(_root,
const_cast<xRooNode *
>(
this)); item) {
4014 if (
auto a = get<RooAbsArg>();
a)
4015 a->setStringAttribute(
"alias",
name);
4016 for (
auto o : *
gROOT->GetListOfBrowsers()) {
4017 if (
auto b =
dynamic_cast<TBrowser *
>(o);
b) {
4019 item->SetText(
name);
4031 auto findByObj = [&](
const std::shared_ptr<xRooNode> &
n) {
4032 for (
auto &
c : *
this) {
4033 if (
c->get() ==
n->get() && strcmp(
n->GetName(),
c->GetName()) == 0)
4036 return std::shared_ptr<xRooNode>(
nullptr);
4039 auto appendChildren = [&](
const xRooNode &
n) {
4042 if (
auto existing = findByObj(
c); existing) {
4044 existing->fFolder =
c->fFolder;
4048 if (
TString(
c->GetName()) !=
".coef")
4054 for (
auto &
c : *
this) {
4055 if (strlen(
c->GetName()) > 0 && (
c->GetName()[0] ==
'.')) {
4059 if (strcmp(
c->GetName(),
"!.pars") == 0) {
4070 size_t addedChildren = 0;
4074 if (get<RooWorkspace>()) {
4075 addedChildren += appendChildren(
datasets());
4089 addedChildren += appendChildren(
components());
4090 if (!get<RooWorkspace>())
4091 addedChildren += appendChildren(
factors());
4092 addedChildren += appendChildren(
variations());
4093 if (get<ParamHistFunc>() || get<RooSimultaneous>())
4094 addedChildren += appendChildren(
bins());
4095 if (get<RooAbsData>())
4096 addedChildren += appendChildren(
obs());
4099 if (
auto arg = get<RooAbsArg>(); arg && addedChildren == 0) {
4100 for (
int i = 0; i < arg->numProxies(); i++) {
4101 auto _proxy = arg->getProxy(i);
4103 auto c = std::make_shared<xRooNode>(
TString::Format(
".%s", _proxy->name()), *(
a->absArg()), *
this);
4104 if (
auto existing = findByObj(
c); existing) {
4106 existing->fFolder =
c->fFolder;
4111 for (
auto a2 : *s) {
4112 auto c = std::make_shared<xRooNode>(*a2, *
this);
4113 c->fFolder = std::string(
"!.") + _proxy->name();
4114 if (
auto existing = findByObj(
c); existing) {
4116 existing->fFolder =
c->fFolder;
4136 while (it !=
end()) {
4137 if (it->get()->fTimes == 0) {
4138 for (
auto o : *
gROOT->GetListOfBrowsers()) {
4140 if (
b &&
b->GetBrowserImp()) {
4149 if (
auto item =
GETLISTTREE(_b)->FindItemByObj(_root,
this); item) {
4184 xRooNode out(
".obs", std::make_shared<RooArgList>(), *
this);
4186 for (
auto o :
vars()) {
4189 out.emplace_back(o);
4197 xRooNode out(
".globs", std::make_shared<RooArgList>(), *
this);
4199 for (
auto o :
obs()) {
4202 out.emplace_back(o);
4210 xRooNode out(
".robs", std::make_shared<RooArgList>(), *
this);
4212 for (
auto o :
obs()) {
4215 out.emplace_back(o);
4223 xRooNode out(
".pars", std::make_shared<RooArgList>(), *
this);
4225 for (
auto o :
vars()) {
4228 out.emplace_back(o);
4236 xRooNode out(
".args", std::make_shared<RooArgList>(), *
this);
4238 for (
auto o :
pars()) {
4241 out.emplace_back(o);
4249 xRooNode out(
".floats", std::make_shared<RooArgList>(), *
this);
4251 for (
auto o :
pars()) {
4254 out.emplace_back(o);
4262 xRooNode out(
".poi", std::make_shared<RooArgList>(), *
this);
4264 for (
auto o :
pars()) {
4267 out.emplace_back(o);
4275 xRooNode out(
".np", std::make_shared<RooArgList>(), *
this);
4277 for (
auto o :
pars()) {
4281 out.emplace_back(o);
4289 xRooNode out(
".vars", std::make_shared<RooArgList>(), *
this);
4291 if (
auto p = get<RooAbsArg>();
p) {
4295 p->leafNodeServerList(&allLeafs);
4296 for (
auto &
c : allLeafs) {
4299 out.emplace_back(std::make_shared<xRooNode>(*
c, *
this));
4300 if (
c->getAttribute(
"global"))
4301 out.back()->fFolder =
"!globs";
4302 else if (
c->getAttribute(
"obs"))
4303 out.back()->fFolder =
"!obs";
4305 out.back()->fFolder =
"!consts";
4307 out.back()->fFolder =
"!pars";
4310 }
else if (
auto p2 = get<RooAbsData>(); p2) {
4311 for (
auto a : *p2->get()) {
4312 a->setAttribute(
"obs");
4313 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
4318 a->setAttribute(
"obs");
4319 a->setAttribute(
"global");
4320 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
4323 }
else if (
auto _ws =
ws(); _ws) {
4325 for (
auto a : *_globs2) {
4326 a->setAttribute(
"obs");
4327 a->setAttribute(
"global");
4328 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
4332 for (
auto &_g : _gl->second) {
4333 auto _clone = std::shared_ptr<RooAbsArg>(
dynamic_cast<RooAbsArg *
>(_g->Clone(_g->GetName())));
4334 if (
auto v = std::dynamic_pointer_cast<RooAbsRealLValue>(_clone);
v && _g->getStringAttribute(
"nominal"))
4335 v->setVal(
TString(_g->getStringAttribute(
"nominal")).
Atof());
4336 out.emplace_back(std::make_shared<xRooNode>(_clone, *
this));
4341 std::unique_ptr<RooAbsCollection> _globs3(
fParent->obs().argList().selectByAttrib(
"global",
true));
4344 for (
auto &_g : *_globs3) {
4345 auto _clone = std::shared_ptr<RooAbsArg>(
dynamic_cast<RooAbsArg *
>(_g->Clone(_g->GetName())));
4346 if (
auto v = std::dynamic_pointer_cast<RooAbsRealLValue>(_clone);
v && _g->getStringAttribute(
"nominal"))
4347 v->setVal(
TString(_g->getStringAttribute(
"nominal")).
Atof());
4348 out.emplace_back(std::make_shared<xRooNode>(_clone, *
this));
4353 }
else if (
auto w = get<RooWorkspace>();
w) {
4354 for (
auto a :
w->allVars()) {
4355 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
4359 for (
auto a :
w->allCats()) {
4360 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
4369 xRooNode out(
".components",
nullptr, *
this);
4371 if (
auto p = get<RooAddPdf>();
p) {
4372 for (
auto &o :
p->pdfList()) {
4373 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
4375 }
else if (
auto p2 = get<RooRealSumPdf>(); p2) {
4389 for (
auto &o : p2->funcList()) {
4390 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
4392 }
else if (
auto p3 = get<RooAddition>(); p3) {
4393 for (
auto &o : p3->list()) {
4394 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
4472 else if (
auto p5 = get<RooWorkspace>(); p5) {
4473 for (
auto &o : p5->components()) {
4476 bool hasClients =
false;
4477 for (
auto &
c : o->clients())
4478 if (!
c->InheritsFrom(
"RooRealIntegral")) {
4484 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
4485 if (o->InheritsFrom(
"RooAbsPdf"))
4486 out.back()->fFolder =
"!models";
4488 out.back()->fFolder =
"!scratch";
4490 for (
auto &o : p5->allGenericObjects()) {
4494 s = s(0, s.
Index(
';'));
4495 if (
auto _pdf = out.
find(s.
Data()); _pdf) {
4497 out.emplace_back(std::make_shared<xRooNode>(fr->GetName(), *fr, _pdf));
4504 out.emplace_back(std::make_shared<xRooNode>(fr->GetName(), *fr, *
this));
4506 out.back()->fFolder =
"!fits";
4536 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
4537 out.back()->fFolder =
"!objects";
4543 if (k.find(
"CACHE_") == 0)
4545 out.emplace_back(std::make_shared<xRooNode>(k.c_str(),
v, *
this));
4546 out.back()->fFolder =
"!sets";
4552 while ((snap = (
RooArgSet *)iter->Next())) {
4553 out.emplace_back(std::make_shared<xRooNode>(*snap, *
this));
4554 out.back()->fFolder =
"!snapshots";
4560 out.emplace_back(
c);
4567 out.emplace_back(
c);
4578 xRooNode out(
".bins",
nullptr, *
this);
4580 if (
auto p = get<RooSimultaneous>();
p) {
4581 for (
auto &
c :
p->indexCat()) {
4582 auto pp =
p->getPdf(
c.first.c_str());
4588 }
else if (
auto phf = get<ParamHistFunc>(); phf) {
4590#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
4591 auto& pSet = phf->_paramSet;
4593 auto& pSet = phf->paramList();
4595 for (
auto par : pSet) {
4596 out.emplace_back(std::make_shared<xRooNode>(*par, *
this));
4597 out.back()->fBinNumber = i;
4600 }
else if (
auto ax =
GetXaxis(); ax) {
4601 for (
int i = 1; i <= ax->GetNbins(); i++) {
4603 std::vector<RooAbsArg *> _factors;
4607 for (
auto &ss :
f->bins()[i - 1]->factors())
4608 _factors.push_back(ss->get<
RooAbsArg>());
4610 _factors.push_back(
f->bins()[i - 1]->get<
RooAbsArg>());
4613 out.emplace_back(std::make_shared<xRooNode>(
4614 TString::Format(
"%s=%g", ax->GetParent()->GetName(), ax->GetBinCenter(i)),
4615 _factors.empty() ? nullptr
4619 for (
auto f : _factors) {
4620#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
4626 out.back()->fBinNumber = i;
4642 for (
auto &o :
p->funcList()) {
4644 coefs.add(*
p->coefList().at(i));
4650 for (
auto &o : p2->pdfList()) {
4652 coefs.add(*p2->coefList().at(i));
4658 xRooNode out(
".coefs",
coefs.empty() ?
nullptr : std::make_shared<RooAddition>(
".coefs",
"Coefficients of",
coefs),
4668 xRooNode out(
".factors",
nullptr, *
this);
4670 if (
auto p = get<RooProdPdf>();
p) {
4672 if (
auto a = _main.get<
RooRealSumPdf>();
a && !
a->getStringAttribute(
"alias"))
4673 a->setStringAttribute(
"alias",
"samples");
4675 a2->setStringAttribute(
"alias",
"components");
4676 int _npdfs =
p->pdfList().size();
4677 for (
auto &o :
p->pdfList()) {
4678 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
4679 if (_npdfs > 5 && o != _main.get())
4680 out.back()->fFolder =
"!constraints";
4682 }
else if (
auto p2 = get<RooProduct>(); p2) {
4683 for (
auto &o : p2->components()) {
4684 if (o->InheritsFrom(
"RooProduct")) {
4688 out.emplace_back(std::make_shared<xRooNode>(
n->GetName(),
n->fComp, *
this));
4691 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
4694 }
else if (
auto w = get<RooWorkspace>();
w) {
4699 for (
auto a :
w->allFunctions()) {
4700 if (_obs.contains(*
a))
4703 for (
auto c :
a->clients()) {
4705 if (
c->InheritsFrom(
"RooProduct"))
4709 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
4714 auto _coefs =
coefs();
4715 if (!_coefs.empty()) {
4716 if (_coefs.size() == 1) {
4717 if (strcmp(_coefs.at(0)->GetName(),
"1") != 0 &&
4718 strcmp(_coefs.at(0)->GetName(),
"ONE") != 0) {
4719 out.emplace_back(std::make_shared<xRooNode>(
".coef", *_coefs.at(0)->get(), *
this));
4722 out.emplace_back(std::make_shared<xRooNode>(_coefs));
4765 xRooNode out(
".variations",
nullptr, *
this);
4776 if (
auto p2 = get<PiecewiseInterpolation>(); p2) {
4777#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
4778 out.emplace_back(std::make_shared<xRooNode>(
"nominal", p2->_nominal.arg(), *
this));
4780 out.emplace_back(std::make_shared<xRooNode>(
"nominal", *(p2->nominalHist()), *
this));
4782 for (
size_t i = 0; i < p2->paramList().
size(); i++) {
4784 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p2->paramList().at(i)->GetName()),
4785 *p2->highList().at(i), *
this));
4786 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p2->paramList().at(i)->GetName()),
4787 *p2->lowList().at(i), *
this));
4789 }
else if (
auto p3 = get<RooStats::HistFactory::FlexibleInterpVar>(); p3) {
4790#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
4791 out.emplace_back(std::make_shared<xRooNode>(
"nominal",
RooFit::RooConst(p3->_nominal), *
this));
4792 for (
size_t i = 0; i < p3->_paramList.size(); i++) {
4793 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p3->_paramList.at(i)->GetName()),
4795 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p3->_paramList.at(i)->GetName()),
4799 out.emplace_back(std::make_shared<xRooNode>(
"nominal",
RooFit::RooConst(p3->nominal()), *
this));
4800 for (
size_t i = 0; i < p3->variables().
size(); i++) {
4801 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p3->variables().at(i)->GetName()),
4803 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p3->variables().at(i)->GetName()),
4808 }
else if (
auto p4 = get<ParamHistFunc>(); p4) {
4827 for (
auto &k : *
this) {
4836 xRooNode out(
".datasets()",
nullptr, *
this);
4839 if (
auto _ws = get<RooWorkspace>(); _ws) {
4840 for (
auto &
d : _ws->allData()) {
4841 out.emplace_back(std::make_shared<xRooNode>(*
d, *
this));
4842 out.back()->fFolder =
"!datasets";
4844 }
else if (
auto __ws =
ws(); __ws) {
4845 if (get<RooAbsPdf>()) {
4850 auto a =
dynamic_cast<RooAbsArg *
>(ax->GetParent());
4855 if (std::unique_ptr<RooAbsCollection>(
d->obs().argList().selectCommon(_obs))->size() == _obs.
size()) {
4857 out.emplace_back(std::make_shared<xRooNode>(
d->fComp, *
this));
4877 if (
auto fr = get<RooFitResult>(); fr) {
4881 if (
auto theData = get<RooDataSet>(); theData) {
4883 TH1 *theHist =
nullptr;
4888 theHist =
dynamic_cast<TH1 *
>(o);
4901 auto vo =
dynamic_cast<TObject *
>(
v);
4902 if (
v &&
obs().
find(vo->GetName())) {
4906 TString::Format(
"my temp hist;%s", strlen(vo->GetTitle()) ? vo->GetTitle() : vo->GetName()),
4907 cat->numTypes(), 0, cat->numTypes());
4908 for (
int i = 0; i < cat->numTypes(); i++) {
4915 TString::Format(
"my temp hist;%s", strlen(vo->GetTitle()) ? vo->GetTitle() : vo->GetName()),
4916 v->numBins(),
v->getBinningPtr(
nullptr)->lowBound(),
v->getBinningPtr(
nullptr)->highBound());
4919 throw std::runtime_error(
"Cannot draw dataset without parent PDF");
4922 theHist = _parentPdf->BuildHistogram(
v,
true);
4932 auto nHist = std::unique_ptr<TH1>((
TH1 *)theHist->
Clone(
"nEntries"));
4937 dataGraph->SetName(
GetName());
4938 dataGraph->SetTitle(strlen(theData->GetTitle()) ? theData->GetTitle() : theData->GetName());
4944 dataGraph->SetMarkerStyle(20);
4956 dataGraph->SetTitle(
TString::Format(
"%s = %f", dataGraph->GetTitle(), dataGraph->GetPointX(0)));
4969 auto _pos = pName.
Index(
'=');
4971 int nevent = theData->numEntries();
4972 for (
int i = 0; i < nevent; i++) {
4975 for (
auto _c : _coords) {
4977 if (cat->getIndex() != theData->get()->getCatIndex(cat->GetName())) {
4985 cat && cat->
getLabel() != pName(_pos + 1, pName.Length())) {
5001 theHist->
Fill((
x) ? xvar->
getVal() : 0.5, theData->weight());
5002 nHist->Fill((
x) ? xvar->
getVal() : 0.5, 1);
5010 for (
int i = 0; i < theHist->
GetNbinsX(); i++) {
5011 if (includeZeros || nHist->GetBinContent(i + 1)) {
5014 dataGraph->SetPoint(dataGraph->GetN(),
5021 dataGraph->SetPointError(dataGraph->GetN() - 1, xErr, xErr,
5032 dataGraph->GetHistogram()->GetXaxis()->Set(theHist->
GetNbinsX(), 0, theHist->
GetNbinsX());
5033 for (
int i = 1; i <= theHist->
GetNbinsX(); i++)
5034 dataGraph->GetHistogram()->GetXaxis()->SetBinLabel(i, theHist->
GetXaxis()->
GetBinLabel(i));
5059 auto _style =
style(dataGraph);
5060 *
dynamic_cast<TAttLine *
>(dataGraph) = *_style;
5061 *
dynamic_cast<TAttFill *
>(dataGraph) = *_style;
5062 *
dynamic_cast<TAttMarker *
>(dataGraph) = *_style;
5067 throw std::runtime_error(
"Cannot build graph");
5073 if (
auto _w =
ws(); _w) {
5075 for (
auto o : _w->allGenericObjects()) {
5077 _fr->ResetBit(1 << 20);
5080 res->SetBit(1 << 20);
5082 auto allVars = _w->allVars();
5087 throw std::runtime_error(
5088 "Not supported yet");
5102 throw std::runtime_error(
"Not a RooFitResult");
5108 if (get<RooFitResult>())
5110 if (get<RooAbsData>()) {
5111 if (
auto _fr =
find(
".fitResult"); _fr)
5113#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
5115 if (get<RooDataSet>() && get<RooDataSet>()->weightVar() &&
5116 get<RooDataSet>()->weightVar()->getStringAttribute(
"fitResult")) {
5117 return xRooNode(getObject<const RooFitResult>(get<RooDataSet>()->weightVar()->getStringAttribute(
"fitResult")),
5125 if (sOpt ==
"prefit") {
5131 std::unique_ptr<RooArgList> _pars(
dynamic_cast<RooArgList *
>(
pars().
argList().selectByAttrib(
"Constant",
false)));
5132 auto fr = std::make_shared<RooFitResult>(
"prefitResult",
"Prefit");
5133 fr->setFinalParList(*_pars);
5134 for (
auto &
p : fr->floatParsFinal()) {
5138 if (
auto s = _v->getStringAttribute(
"nominal"); s)
5141 std::shared_ptr<xRooNode> pConstr;
5142 for (
auto &
c : _constr) {
5151 double prefitVal = 0, prefitError = 0;
5152 for (
auto &_d : pConstr->vars()) {
5153 if (strcmp(
p->
GetName(), _d->get()->GetName()) == 0)
5157 prefitVal = prefitError;
5158 prefitError = _c->getVal();
5159 }
else if (prefitError == 0)
5160 prefitError = _d->get<
RooAbsReal>()->getVal();
5165 if (pConstr->get<
RooGaussian>() && pConstr->browse().find(
".sigma")) {
5166 prefitError = pConstr->find(
".sigma")->get<
RooAbsReal>()->getVal();
5172 prefitVal /= prefitError;
5174 prefitError = 1. / sqrt(prefitError);
5176 if (!_v->getStringAttribute(
"nominal"))
5177 _v->setVal(prefitVal);
5178 _v->setError(prefitError);
5186 auto _globs =
globs();
5187 _args.add(_globs.argList());
5188 fr->setConstParList(_args);
5189 std::unique_ptr<RooArgList> _snap(
dynamic_cast<RooArgList *
>(_pars->snapshot()));
5190 for (
auto &
p : *_snap) {
5191 if (
auto atr =
p->getStringAttribute(
"initVal"); atr &&
dynamic_cast<RooRealVar *
>(
p))
5194 fr->setInitParList(*_snap);
5199 if (
auto _w =
ws(); _w) {
5200 for (
auto o : _w->allGenericObjects()) {
5204 for (
auto p :
pars()) {
5208 if (_fr->floatParsFinal().find(
p->
GetName()) ||
5209 std::abs(_fr->constPars().getRealValue(
p->
GetName(), std::numeric_limits<double>::quiet_NaN()) -
5215 if (_fr->constPars().find(
p->
GetName()) ||
5217 _fr->floatParsFinal().getRealValue(
p->
GetName(), std::numeric_limits<double>::quiet_NaN()) -
5226 std::unique_ptr<RooArgList> _pars(
5228 auto fr = std::make_shared<RooFitResult>(
"");
5230 fr->setFinalParList(*_pars);
5233 auto cov = _fr->reducedCovarianceMatrix(*_pars);
5234 fr->setCovarianceMatrix(cov);
5239 auto _globs =
globs();
5240 _args.add(_globs.argList());
5241 fr->setConstParList(_args);
5242 std::unique_ptr<RooArgList> _snap(
dynamic_cast<RooArgList *
>(_pars->snapshot()));
5243 for (
auto &
p : *_snap) {
5244 if (
auto atr =
p->getStringAttribute(
"initVal"); atr &&
dynamic_cast<RooRealVar *
>(
p))
5247 fr->setInitParList(*_snap);
5250 return xRooNode(*_fr, std::make_shared<xRooNode>(*_w, std::make_shared<xRooNode>()));
5256 if (
auto fr = getObject<RooFitResult>(
".fitResult"); fr) {
5261 std::unique_ptr<RooArgList> _pars(
dynamic_cast<RooArgList *
>(
pars().
argList().selectByAttrib(
"Constant",
false)));
5262 auto fr = std::make_shared<RooFitResult>(
"");
5264 fr->setFinalParList(*_pars);
5269 for (
int i = 0; i < prevCov->
GetNcols(); i++) {
5270 for (
int j = 0; j < prevCov->
GetNrows(); j++) {
5271 cov(i, j) = (*prevCov)(i, j);
5276 for (
auto &
p : fr->floatParsFinal()) {
5277 if (!prevCov || i >= prevCov->
GetNcols()) {
5278 cov(i, i) = pow(
dynamic_cast<RooRealVar *
>(
p)->getError(), 2);
5282 int covQualBackup = fr->covQual();
5283 fr->setCovarianceMatrix(cov);
5284 fr->setCovQual(covQualBackup);
5288 auto _globs =
globs();
5289 _args.add(_globs.argList());
5290 fr->setConstParList(_args);
5291 std::unique_ptr<RooArgList> _snap(
dynamic_cast<RooArgList *
>(_pars->snapshot()));
5292 for (
auto &
p : *_snap) {
5293 if (
auto atr =
p->getStringAttribute(
"initVal"); atr &&
dynamic_cast<RooRealVar *
>(
p))
5296 fr->setInitParList(*_snap);
5317 if (!std::isnan(low) && !std::isnan(high) && get<RooRealVar>()) {
5318 if (range && strlen(range))
5319 get<RooRealVar>()->setRange(range, low, high);
5321 get<RooRealVar>()->setRange(low, high);
5324 if (
auto o = get<RooAbsArg>(); o)
5325 o->setStringAttribute(
"range", range);
5332 std::string &out =
fRange;
5333 if (
auto o = get<RooAbsArg>(); o && o->getStringAttribute(
"range"))
5334 out = o->getStringAttribute(
"range");
5336 while (out.empty() && _parent) {
5337 if (
auto o = _parent->get<
RooAbsArg>(); o && o->getStringAttribute(
"range"))
5338 out = o->getStringAttribute(
"range");
5339 _parent = _parent->fParent;
5352 for (
auto &i : nllOpts)
5354 return nll(_data,
l);
5360 if (!get<RooAbsPdf>())
5364 if (get<RooSimultaneous>()) {
5365 std::string selected;
5366 bool hasDeselected =
false;
5367 for (
auto c :
bins()) {
5369 hasDeselected =
true;
5372 cName = cName(cName.Index(
'=') + 1, cName.Length());
5373 if (!selected.empty())
5375 selected += cName.Data();
5385 if (strlen(_data.
GetName()) == 0) {
5388 std::dynamic_pointer_cast<const RooFitResult>(
fitResult().
fComp),
true);
5389 _d = std::make_shared<xRooNode>(asi.first, *
this);
5391 std::make_shared<xRooNode>(
".globs", std::const_pointer_cast<RooAbsCollection>(asi.second), *_d));
5395 return nll(*_d, opts);
5398 auto _globs = _data.
globs();
5411 for (
int i = 0; i < opts.
GetSize(); i++) {
5414 if (strcmp(opts.
At(i)->
GetName(),
"GlobalObservables") == 0) {
5417 _opts->Add(opts.
At(i)->
Clone(
nullptr));
5425 std::dynamic_pointer_cast<RooAbsData>(_data.
fComp), *_opts);
5523 auto rangeName = (_range.empty()) ?
GetRange() : _range;
5524 if (!rangeName.empty()) {
5525 std::vector<TString> patterns;
5528 patterns.emplace_back(pattern);
5530 if (
auto s = get<RooSimultaneous>(); s) {
5535 for (
auto &
c :
bins()) {
5537 cName = cName(cName.
Index(
'=') + 1, cName.
Length());
5538 _cat.setLabel(cName);
5539 bool matchAny =
false;
5540 for (
auto &
p : patterns) {
5545 if (_cat.hasRange(
p) && _cat.inRange(
p)) {
5559 std::vector<TObject *>
funcs;
5561 bool matchAny =
false;
5562 for (
auto &
p : patterns) {
5569 funcs.push_back(
c->get());
5575 }
else if (
auto fr = get<RooFitResult>()) {
5581 for (
auto c : _pars) {
5582 bool matchAny =
false;
5583 for (
auto &
p : patterns) {
5593 _pars.remove(_remPars,
true);
5595 auto _tmp = fr->reducedCovarianceMatrix(_pars);
5596 int covQualBackup = fr->covQual();
5597 fr->setCovarianceMatrix(_tmp);
5598 fr->setCovQual(covQualBackup);
5599 const_cast<RooArgList&
>(fr->floatParsFinal()).remove(_remPars,
true);
5602 }
else if (!
get() || get<RooArgList>()) {
5604 xRooNode out(get<RooArgList>() ? std::make_shared<RooArgList>() : std::shared_ptr<TObject>(
nullptr),
fParent);
5605 for (
auto c : *
this) {
5606 bool matchAny =
false;
5607 for (
auto &
p : patterns) {
5624 return get<RooArgList>() ?
xRooNode(std::make_shared<RooArgList>(),
fParent) : *
this;
5705 :
RooAbsPdf(
Form(
"exp_%s",
f.GetName())), fFunc(
"func",
"func", this,
f), fCoef(
"coef",
"coef", this)
5708 fCoef.setArg(*coef);
5709 fExpectedEventsMode = expEvMode;
5713 :
RooAbsPdf(other,
name), fFunc(
"func", this, other.fFunc), fCoef(
"coef", this, other.fCoef),
5714 fExpectedEventsMode(other.fExpectedEventsMode)
5721 return fFunc->binBoundaries(obs, xlo, xhi);
5726 return (fExpectedEventsMode ? 1. : fFunc) *
5740 fpf_stripped.
add(*frv);
5747 std::unique_ptr<RooArgSet> errorParams{cloneFunc->
getObservables(fpf_stripped)};
5749 std::unique_ptr<RooArgSet> nset =
5755 std::vector<int> fpf_idx;
5757 RooAbsArg *par = errorParams->find(fpf[i].GetName());
5759 paramList.
add(*par);
5760 fpf_idx.push_back(i);
5764 std::vector<Double_t> plusVar, minusVar;
5770 for (
Int_t ivar = 0; ivar < paramList.
getSize(); ivar++) {
5775 Double_t errVal = sqrt(V(ivar, ivar));
5778 ((
RooRealVar *)paramList.
at(ivar))->setVal(cenVal + errVal);
5779 plusVar.push_back((fExpectedEventsMode ? 1. : cloneFunc->
getVal(&*nset)) *
5783 ((
RooRealVar *)paramList.
at(ivar))->setVal(cenVal - errVal);
5784 minusVar.push_back((fExpectedEventsMode ? 1. : cloneFunc->
getVal(&*nset)) *
5791 std::vector<double> errVec(paramList.
getSize());
5792 for (
int i = 0; i < paramList.
getSize(); i++) {
5793 errVec[i] = sqrt(V(i, i));
5794 for (
int j = i; j < paramList.
getSize(); j++) {
5795 C(i, j) = V(i, j) / sqrt(V(i, i) * V(j, j));
5802 for (
unsigned int j = 0; j < plusVar.size(); j++) {
5803 F[j] = (plusVar[j] - minusVar[j]) / 2;
5817 bool fExpectedEventsMode =
false;
5825 std::cout <<
"Got signal " << signum << std::endl;
5826 if (signum == SIGINT) {
5827 std::cout <<
"Keyboard interrupt while building histogram" << std::endl;
5837 auto _doSterilize = [](
RooAbsArg *obj) {
5839 for(
int i=0;i<obj->numCaches();i++) {
5845 p->setNormRange(
nullptr);
5871 obj->setValueDirty();
5874 if (
auto w = get<RooWorkspace>();
w) {
5876 for (
auto &
c :
w->components()) {
5886 auto itr =
a->clientIterator();
5888 while ((obj = itr->Next())) {
5889 _doSterilize(
dynamic_cast<RooAbsArg *
>(obj));
5902 auto rar = get<RooAbsReal>();
5918 h =
new TH1D(rar->GetName(), rar->GetTitle(), 1, 0, 1);
5919 h->GetXaxis()->SetBinLabel(1, rar->GetName());
5920 h->GetXaxis()->SetName(rar->GetName());
5928 h =
new TH1D(rar->GetName(), rar->GetTitle(), 1, 0, 1);
5930 h->GetXaxis()->SetBinLabel(1, rar->GetName());
5931 h->SetBinContent(1, rar->getVal());
5933 h->SetBinError(1,
x->getError());
5934 h->SetMaximum(
x->hasMax() ?
x->getMax()
5935 : (
h->GetBinContent(1) + std::max(std::abs(
h->GetBinContent(1) * 0.1), 50.)));
5936 h->SetMinimum(
x->hasMin() ?
x->getMin()
5937 : (
h->GetBinContent(1) - std::max(std::abs(
h->GetBinContent(1) * 0.1), 50.)));
5942 TString binningName = (_ax && _ax->GetParent() ==
x) ? _ax->GetName() : rar->getStringAttribute(
"binning");
5943 if (binningName ==
"")
5944 binningName = rar->GetName();
5945 if (
x->hasBinning(binningName)) {
5946 if (
x->getBinning(binningName).isUniform()) {
5947 h =
new TH1D(rar->GetName(), rar->GetTitle(),
x->numBins(binningName) <= 0 ? 100 :
x->numBins(binningName),
5948 x->getMin(binningName),
x->getMax(binningName));
5950 h =
new TH1D(rar->GetName(), rar->GetTitle(),
x->numBins(binningName),
x->getBinning(binningName).array());
5952 h->GetXaxis()->SetTitle(
x->getBinning(binningName).GetTitle());
5953 }
else if (
auto _boundaries =
5954 _or_func( (std::list<double> *)(
nullptr),
5955 rar->binBoundaries(*
x, -std::numeric_limits<double>::infinity(),
5956 std::numeric_limits<double>::infinity()));
5958 std::vector<double> _bins;
5959 for (
auto &
b : *_boundaries) {
5960 if (_bins.empty() || std::abs(_bins.back() -
b) > 1
e-5 * _bins.back())
5963 h =
new TH1D(rar->GetName(), rar->GetTitle(), _bins.size() - 1, &_bins[0]);
5965 }
else if (!
x->hasMax() || !
x->hasMin()) {
5967 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(),
x->getVal() * 0.2,
x->getVal() * 5);
5969 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(),
x->getBinning().array());
5973 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(rar->GetName()), 0,
v->numBins(rar->GetName()));
5979 if (
auto s =
style(); s) {
5984 if (strlen(
h->GetXaxis()->GetTitle()) == 0)
5991 if (!
GETDMP(fr,_finalPars)) {
6020 for (
int i = 0; i < prevCov->
GetNcols(); i++) {
6021 for (
int j = 0; j < prevCov->
GetNrows(); j++) {
6022 cov(i, j) = (*prevCov)(i, j);
6028 if (!prevCov || i >= prevCov->
GetNcols()) {
6029 cov(i, i) = pow(
dynamic_cast<RooRealVar *
>(p2)->getError(), 2);
6033 int covQualBackup = fr->
covQual();
6043 int covQualBackup = fr->
covQual();
6056 binEnd =
h->GetNbinsX();
6057 bool needBinWidth =
false;
6059 auto _coefs =
coefs();
6060 if ((
p || !_coefs.empty() || rar->getAttribute(
"density")) &&
x) {
6062 needBinWidth =
true;
6064 std::unique_ptr<RooArgSet> snap(normSet.
snapshot());
6066 std::vector<double> lapTimes;
6067 bool warned =
false;
6068 for (
int i = std::max(1, binStart); i <= std::min(
h->GetNbinsX(), binEnd); i++) {
6071 x->setVal(
h->GetBinCenter(i));
6074 double r = rar->getVal(normSet);
6075 if (
r && !_coefs.empty()) {
6079 r *=
h->GetBinWidth(i);
6081 if (
p &&
p->canBeExtended()) {
6082 r *= (
p->expectedEvents(normSet));
6084 h->SetBinContent(i,
r);
6092#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
6094 p->_normSet =
nullptr;
6097 res = rar->getPropagatedError(*fr, normSet);
6100 res *=
c->getVal(normSet);
6104 res *=
h->GetBinWidth(i);
6106 h->SetBinError(i, res);
6109 lapTimes.push_back(timeIt.
RealTime());
6110 double time_estimate =
6111 (lapTimes.size() > 1)
6112 ? (
h->GetNbinsX() * (std::accumulate(lapTimes.begin() + 1, lapTimes.end(), 0.) / (lapTimes.size() - 1)))
6114 if (!warned && (lapTimes.at(0) > 10 || (lapTimes.size() > 2 && time_estimate > 60.))) {
6116 t2.
Add(time_estimate);
6117 Warning(
"BuildHistogram",
"Building this histogram will take until %s", t2.
AsString());
6127 Warning(
"BuildHistogram",
"Skipping errors for remaining bins");
6141 h->GetYaxis()->SetTitle(rar->getStringAttribute(
"units"));
6142 }
else if (
p->canBeExtended()) {
6143 h->GetYaxis()->SetTitle(
"Events");
6145 h->GetYaxis()->SetTitle(
"Probability Mass");
6147 h->GetYaxis()->SetMaxDigits(3);
6159 return std::numeric_limits<double>::quiet_NaN();
6160 return node->GetBinContent(bin);
6166 if (binStart != binEnd || !
fParent) {
6171 std::vector<double> out;
6172 if (get<RooAbsData>()) {
6176 for (
int i = binStart - 1; i <
g->GetN() && (binEnd == 0 || i < binEnd); i++) {
6177 out.push_back(
g->GetPointY(i));
6188 binEnd =
h->GetNbinsX();
6189 for (
int i = binStart; i <= binEnd; i++) {
6190 out.push_back(
h->GetBinContent(i));
6198 if (
auto a = get<RooAbsArg>();
a) {
6200 for (
auto &
l :
a->servers()) {
6220 if (
auto o =
get(); o)
6228#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
6231 for (
int i = 0; i <
p->fCGnx; i++) {
6232 for (
int j = 0; j <
p->fCGny; j++) {
6233 p->fCollideGrid[i + j *
p->fCGnx] =
kTRUE;
6236 p->FillCollideGrid(o);
6240 Int_t nxmax =
p->fCGnx - iw - 1 -
p->fCGnx *
p->GetRightMargin();
6241 Int_t nymax =
p->fCGny - ih - 1 -
p->fCGny *
p->GetTopMargin();
6243 for (
Int_t j = nymax; j >= 0; j--) {
6244 for (
Int_t i = nxmax; i >= 0; i--) {
6245 if (
p->Collide(i, j, iw, ih)) {
6256 return p->PlaceBox(o,
w,
h, xl, yb,
"trw");
6262 if (
auto p =
dynamic_cast<TLegend *
>(
gPad->GetPrimitive(
"legend"));
p) {
6264 double w =
p->GetX2NDC() -
p->GetX1NDC(),
h =
p->GetY2NDC() -
p->GetY1NDC();
6266 gPad->PaintModified();
6270 x = std::max(
x, (
gPad->GetLeftMargin() + 0.02));
6271 y = std::max(
y, (
gPad->GetBottomMargin() + 0.02));
6272 x = std::min(
x, (1. -
gPad->GetRightMargin() - 0.02) -
w);
6273 y = std::min(
y, (1. -
gPad->GetTopMargin() - 0.02) -
h);
6274 h = std::min(
h, (1. -
gPad->GetTopMargin() - 0.02) -
y);
6275 w = std::min(
w, (1. -
gPad->GetRightMargin() - 0.02) -
x);
6287 while ((
p !=
p->GetMother()) && (
p =
p->GetMother())) {
6288 if (
auto q =
dynamic_cast<TVirtualPad *
>(
p->GetPrimitive(
"legend"));
q) {
6296 if (
p && strcmp(
p->
GetName(),
"legend") == 0) {
6297 if (
l =
dynamic_cast<TLegend *
>(
p->GetPrimitive(
"legend"));
l || !create)
6301 gPad->GetBottomMargin());
6305 l =
new TLegend(0.6, 1. -
gPad->GetTopMargin() - 0.08, 1. -
gPad->GetRightMargin(),
6306 1. -
gPad->GetTopMargin() - 0.08);
6307 l->SetBorderSize(0);
6313 l->SetName(
"legend");
6315 l->ConvertNDCtoPad();
6326 for (
auto a : *
l->GetListOfPrimitives()) {
6327 if (!strcmp(
dynamic_cast<TLegendEntry *
>(
a)->GetLabel(), title))
6330 if (
l->GetListOfPrimitives()->GetEntries() > 20)
6333 l->AddEntry(o, title, opt);
6334 if (
auto nObj =
l->GetListOfPrimitives()->GetEntries(); nObj > 0) {
6336 int nn =
l->GetNColumns();
6338 if (nObj > 1 && (nObj % nn) == 1) {
6339 l->SetNColumns(
l->GetNColumns() + 1);
6340 }
else if (nObj <= nn && nObj >=
l->GetNColumns() *
l->GetNColumns()) {
6341 l->SetY1NDC(
l->GetY2NDC() - 0.05 *
gPad->GetHNDC() * nObj);
6357 fPad->GetCanvas()->Update();
6377 [](
double a,
double b,
double) {
6380 if (
b == 0 &&
a == 0)
6387 [](
double n,
double b,
double sigma) {
6391 t0 = 2. * (((
n == 0) ? 0 :
n * log(
n /
b)) - (
n -
b));
6394 double b_hathat = 0.5 * (
b - sigma2 + sqrt(pow(
b - sigma2, 2) + 4 *
n * sigma2));
6397 t0 = 2. * (((
n == 0) ? 0 :
n * log(
n / b_hathat)) + b_hathat -
n + pow(
b - b_hathat, 2) / (2. * sigma2));
6401 return (
n >=
b) ? sqrt(t0) : -sqrt(t0);
6418 }
else if (get<RooAbsPdf>()) {
6420 forceNames = sOpt(sOpt2.
Index(
"force") + 5, sOpt2.
Length());
6421 sOpt = sOpt(0, sOpt2.
Index(
"force"));
6422 sOpt2 = sOpt2(0, sOpt2.
Index(
"force"));
6424 throw std::runtime_error(
"Can only compute forces with PDFs");
6427 bool hasOverlay = sOpt2.
Contains(
"overlay");
6431 overlayName = sOpt(sOpt2.
Index(
"overlay") + 7, sOpt2.
Length());
6432 sOpt = sOpt(0, sOpt2.
Index(
"overlay"));
6433 sOpt2 = sOpt2(0, sOpt2.
Index(
"overlay"));
6438 sOpt +=
"auxSignif";
6440 std::string auxPlotTitle =
"";
6451 bool hasSame = sOpt.
Contains(
"same");
6453 bool hasGoff = sOpt.
Contains(
"goff");
6455 bool hasFR = sOpt.
Contains(
"pull");
6457 bool hasText = sOpt.
Contains(
"text");
6458 bool hasErrorOpt = sOpt.
Contains(
"e");
6462 if (auxPlotTitle ==
"Signif")
6469 TH1 *hAxis =
nullptr;
6472 auto clearPad = []() {
6474 if (
gPad->GetNumber() == 0) {
6486 if (!hasSame || !pad) {
6497 if (hAxis =
dynamic_cast<TH1 *
>(o); hAxis)
6513 auto adjustYRange = [&](
double min,
double max,
TH1 *hh =
nullptr,
bool symmetrize =
false) {
6521 double ymin = hh->GetMinimum();
6522 double ymax = hh->GetMaximum();
6523 if (hh->GetMaximumStored() == -1111)
6525 if (hh->GetMinimumStored() == -1111) {
6535 if (hh->GetSumw2()) {
6536 double smallestErrDown3 = -std::numeric_limits<double>::infinity();
6537 double smallestErrUp3 = std::numeric_limits<double>::infinity();
6538 for (
int i = 1; i <= hh->GetNbinsX(); i++) {
6539 smallestErrDown3 = std::max(smallestErrDown3, hh->GetBinContent(i) - 3 * hh->GetBinError(i));
6540 smallestErrUp3 = std::min(smallestErrUp3, hh->GetBinContent(i) + 3 * hh->GetBinError(i));
6542 max = std::max(max, smallestErrUp3);
6543 min = std::min(min, smallestErrDown3);
6545 bool change =
false;
6557 double down = hh->GetBinContent(1) -
ymin;
6558 double up =
ymax - hh->GetBinContent(1);
6560 ymax = hh->GetBinContent(1) + down;
6562 ymin = hh->GetBinContent(1) - up;
6564 if (hh == hAxis && pad && !pad->
GetLogy() &&
ymin > 0 && (log10(
ymax) - log10(max)) >= 3) {
6568 if (hh == hAxis && pad &&
ymin == 0 && pad->
GetLogy()) {
6571 hh->SetMinimum(
ymin);
6572 hh->SetMaximum(
ymax);
6573 hh->GetYaxis()->Set(1,
ymin,
ymax);
6580 double ymax = -std::numeric_limits<double>::infinity();
6581 double ymin = std::numeric_limits<double>::infinity();
6582 for (
int i = 0; i <
gr->
GetN(); i++) {
6606 gPad->GetFrame()->SetFillStyle(1001);
6607 gPad->SetTopMargin(0);
6608 gPad->SetBottomMargin(0);
6609 gPad->SetName(
"pull");
6614 throw std::runtime_error(
"Couldn't find pull graph");
6616 pullGraph->SetName(
"nominal");
6620 for (
auto i = 0; i < pullGraph->GetN(); i++) {
6622 g->
SetName(pullGraph->GetHistogram()->GetXaxis()->GetBinLabel(i + 1));
6625 Warning(
"Draw",
"Found a non-var in the floatParsFinal list: %s - this shouldn't happen",
g->GetName());
6629 "%s=%g +/- %s [%g,%g]", strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName(), _p->getVal(),
6630 _p->hasAsymError() ?
TString::Format(
"(%g,%g)", _p->getAsymErrorHi(), _p->getAsymErrorLo()).
Data()
6632 pullGraph->GetHistogram()->GetBinContent(i + 1), pullGraph->GetHistogram()->GetBinError(i + 1)));
6633 g->SetPoint(0, pullGraph->GetPointX(i), pullGraph->GetPointY(i));
6634 g->SetPointEYhigh(0, pullGraph->GetErrorYhigh(i));
6635 g->SetPointEYlow(0, pullGraph->GetErrorYlow(i));
6636 g->SetEditable(
true);
6637 g->SetHighlight(
true);
6638 g->SetMarkerStyle(20);
6639 g->SetMarkerSize(0.5);
6647 _thisClone->AppendPad();
6651 gPad->GetCanvas()->ToggleEventStatus();
6659 if (
auto _simPdf = get<RooSimultaneous>(); _simPdf) {
6661 auto _channels =
bins();
6662 for (
auto &_v : _channels) {
6663 if (!_v->IsHidden())
6690 dynamic_cast<TPad *
>(pad)->DivideSquare(_size, 1
e-9, 1
e-9);
6696 std::vector<TString> chanPatterns;
6697 if (_range && strlen(_range)) {
6700 chanPatterns.emplace_back(pattern);
6703 for (
auto &_v : _channels) {
6710 chanVar.setLabel(cName);
6711 bool inRange = chanPatterns.empty();
6712 for (
auto &
p : chanPatterns)
6713 if (chanVar.inRange(
p)) {
6720 gPad->SetLeftMargin(std::min(
gPad->GetLeftMargin() * (1. /
gPad->GetWNDC()), 0.3));
6730 if (!
get() || get<RooArgList>()) {
6735 for (
auto &_v : *
this) {
6738 if (strcmp(
GetName(),
".vars") == 0) {
6742 if (strcmp(_v->get()->GetName(),
"1") == 0 || strcmp(_v->get()->GetName(),
"ONE") == 0 ||
6745 if (_v->get()->InheritsFrom(
"RooConstVar"))
6756 dynamic_cast<TPad *
>(pad)->DivideSquare(_size, 1
e-9, 1
e-9);
6759 for (
auto &_v : *
this) {
6762 if (strcmp(
GetName(),
".vars") == 0) {
6766 if (strcmp(_v->get()->GetName(),
"1") == 0 || strcmp(_v->get()->GetName(),
"ONE") == 0 ||
6769 if (_v->get()->InheritsFrom(
"RooConstVar"))
6778 gPad->SetLeftMargin(std::min(
gPad->GetLeftMargin() * (1. /
gPad->GetWNDC()), 0.3));
6796 if (
auto fr = get<RooFitResult>(); fr) {
6799 auto hist = fr->correlationHist(fr->GetName());
6800 hist->SetTitle(fr->GetTitle());
6805 hist->GetXaxis()->SetTickSize(0);
6806 hist->GetYaxis()->SetTickSize(0);
6817 std::vector<TString> graphLabels;
6820 ugraph->
SetTitle(
"Fit Result Pulls");
6821 std::vector<TString> ugraphLabels;
6822 std::map<std::string, double> scale;
6823 std::map<std::string, double>
offset;
6824 for (
auto &
p : fr->floatParsFinal()) {
6833 std::shared_ptr<xRooNode> pConstr;
6836 for (
auto &
c : _constr) {
6851 if (pConstr->get<
RooPoisson>() && pConstr->find(
".x")) {
6852 std::string xName = pConstr->find(
".x")->get()->
GetName();
6853 prefitVal = pConstr->find(
".x")->get<
RooAbsReal>()->getVal();
6854 for (
auto &_d : pConstr->vars()) {
6855 if (strcmp(
p->
GetName(), _d->get()->GetName()) == 0)
6857 if (xName == _d->get()->GetName())
6859 prefitError = _d->get<
RooAbsReal>()->getVal();
6862 prefitVal /= prefitError;
6864 prefitError = 1. / sqrt(prefitError);
6865 }
else if (
auto _g = pConstr->get<
RooGaussian>(); _g) {
6866 prefitError = (pConstr->find(
".sigma")) ? pConstr->find(
".sigma")->get<
RooAbsReal>()->getVal() : 0;
6868 (pConstr->find(
".x")) ? pConstr->find(
".x")->get<
RooAbsReal>()->getVal() : 0;
6869 if (pConstr->find(
".x") &&
6872 prefitVal = pConstr->find(
".mean")->get<
RooAbsReal>()->getVal();
6876 if (prefitError == 0)
6877 prefitError =
dynamic_cast<RooRealVar *
>(fr->floatParsInit().find(
p->
GetName()))->getError();
6878 if (prefitError == 0) {
6879 Warning(
"Draw",
"failed to determine prefit error of %s, using post-fit error",
p->
GetName());
6880 prefitError = _v->getError();
6882 out->
SetPoint(out->
GetN(), out->
GetN(), (_v->getVal() - prefitVal) / prefitError);
6884 (_v->getErrorHi()) / prefitError);
6885 graphLabels.push_back(
p->
GetName());
6890 if (prefitError == 0) {
6892 prefitError = (std::max({_v->getMax() - _v->getVal(), _v->getVal() - _v->getMin(), 4.}) / 4);
6893 ugraph->
SetPoint(ugraph->
GetN(), ugraph->
GetN(), (_v->getVal() - prefitVal) / prefitError);
6894 ugraph->
SetPointError(ugraph->
GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
6895 (_v->getErrorHi()) / prefitError);
6896 ugraphLabels.push_back(
p->
GetName());
6898 out->
SetPoint(out->
GetN(), out->
GetN(), (_v->getVal() - prefitVal) / prefitError);
6900 (_v->getErrorHi()) / prefitError);
6901 graphLabels.push_back(
p->
GetName());
6908 if (prefitError == 0) {
6909 prefitError = (std::max({_v->getMax() - _v->getVal(), _v->getVal() - _v->getMin(), 4.}) / 4);
6911 ugraph->
SetPoint(ugraph->
GetN(), ugraph->
GetN(), (_v->getVal() - prefitVal) / prefitError);
6912 ugraph->
SetPointError(ugraph->
GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
6913 (_v->getErrorHi()) / prefitError);
6914 ugraphLabels.push_back(
p->
GetName());
6922 for (
int i = 0; i < ugraph->
GetN(); i++)
6924 int nUnconstrained = ugraph->
GetN();
6927 tmpList.
Add(ugraph);
6928 graph->Merge(&tmpList);
6933 graph->SetMarkerStyle(20);
6934 graph->SetMarkerSize(0.5);
6939 -0.5, std::max(
graph->GetN(), 1) - 0.5);
6940 hist->SetStats(
false);
6944 for (
auto &
l : graphLabels) {
6945 hist->GetXaxis()->SetBinLabel(i++,
l);
6947 for (
auto &
l : ugraphLabels) {
6948 hist->GetXaxis()->SetBinLabel(i++,
l);
6950 hist->SetMaximum(4);
6951 hist->SetMinimum(-4);
6953 hist->GetXaxis()->LabelsOption(
"v");
6954 hist->GetYaxis()->SetNdivisions(8, 0, 0);
6955 hist->GetYaxis()->SetTitle(
"(#hat{#theta}-#theta_{i})/#sigma_{i}");
6960 gPad->Divide(1, 1, 1
e-9, 1
e-9);
6962 gPad->SetBottomMargin(0.4);
6964 auto pNamesHist =
dynamic_cast<TH1F *
>(hist->Clone(
"pnames"));
6965 pNamesHist->
Sumw2();
6966 pNamesHist->SetDirectory(0);
6968 for (
int ii = 1; ii <=
graph->GetN(); ii++) {
6969 auto _p = fr->floatParsFinal().find(hist->GetXaxis()->GetBinLabel(ii));
6970 pNamesHist->SetBinContent(ii,
offset[_p->GetName()]);
6971 pNamesHist->SetBinError(ii, scale[_p->GetName()]);
6972 hist->GetXaxis()->SetBinLabel(ii, strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName());
6977 for (
int ii = 2; ii >= 1; ii--) {
6980 pullBox->SetPoint(0, -0.5, 0);
6981 pullBox->SetPoint(1, hist->GetNbinsX() - 0.5 - nUnconstrained, 0);
6982 pullBox->SetPointError(0, 0, ii);
6983 pullBox->SetPointError(1, 0, ii);
6987 auto pullLine =
new TGraph;
6989 pullLine->SetPoint(0, -0.5, 0);
6990 pullLine->SetPoint(1, hist->GetNbinsX() - 0.5 - nUnconstrained, 0);
6991 pullLine->SetLineStyle(2);
6992 pullLine->SetEditable(
false);
6993 pullLine->Draw(
"l");
6994 if (nUnconstrained > 0) {
6997 pullLine->SetPoint(0,
graph->GetN() - 0.5 - nUnconstrained, -100);
6998 pullLine->SetPoint(1,
graph->GetN() - 0.5 - nUnconstrained, 100);
6999 pullLine->SetLineStyle(2);
7000 pullLine->SetEditable(
false);
7001 pullLine->Draw(
"l");
7003 auto minMax = graphMinMax(
graph);
7004 adjustYRange(minMax.first, minMax.second);
7006 graph->SetEditable(
false);
7007 graph->SetHistogram(pNamesHist);
7021 for (
auto c : s->bins()) {
7022 auto _pad =
dynamic_cast<TPad *
>(
gPad->GetPrimitive(
c->GetName()));
7025 auto ds =
c->datasets().find(
GetName());
7037 if (!s && hasSame) {
7040 bool doneDraw =
false;
7041 for (
auto o : *
gPad->GetListOfPrimitives()) {
7056 auto dataGraph =
BuildGraph(
v,
false, (!s && hasSame) ?
gPad :
nullptr);
7064 dataGraph->Draw(
"Az0p");
7065 addLegendEntry(dataGraph, strlen(dataGraph->GetTitle()) ? dataGraph->GetTitle() :
GetName(),
"pEX0");
7071 bool noPoint =
false;
7074 for (
auto o : *
gPad->GetListOfPrimitives()) {
7075 if (
auto h =
dynamic_cast<TH1 *
>(o);
7076 h && strcmp(
h->GetXaxis()->GetName(),
dynamic_cast<TObject *
>(
v)->
GetName()) == 0) {
7077 dataGraph->SetPointY(0,
h->Interpolate(dataGraph->GetPointX(0)));
7084 if (
auto _pad =
dynamic_cast<TPad *
>(
gPad->FindObject(
"auxPad")); _pad) {
7085 if (
auto h =
dynamic_cast<TH1 *
>(_pad->GetPrimitive(
"auxHist"));
h) {
7088 histName = histName(0, histName.
Index(
'|'));
7089 if (
auto mainHist =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(histName));
7093 auto ratioGraph =
dynamic_cast<TGraphAsymmErrors *
>(dataGraph->Clone(dataGraph->GetName()));
7095 for (
int i = 0; i < ratioGraph->GetN(); i++) {
7096 double val = ratioGraph->GetPointY(i);
7097 double nom = mainHist->GetBinContent(i + 1);
7098 double nomerr = mainHist->GetBinError(i + 1);
7099 ratioGraph->SetPointY(
7100 i, std::get<0>(
auxFunctions[
h->GetYaxis()->GetTitle()])(ratioGraph->GetPointY(i), nom, nomerr));
7101 ratioGraph->SetPointEYhigh(i, std::get<0>(
auxFunctions[
h->GetYaxis()->GetTitle()])(
7102 val + ratioGraph->GetErrorYhigh(i), nom, nomerr) -
7103 ratioGraph->GetPointY(i));
7104 ratioGraph->SetPointEYlow(i, ratioGraph->GetPointY(i) -
7106 val - ratioGraph->GetErrorYlow(i), nom, nomerr));
7110 while (i < ratioGraph->GetN()) {
7111 if (ratioGraph->GetPointY(i) == 0 && ratioGraph->GetErrorYhigh(i) == 0 &&
7112 ratioGraph->GetErrorYlow(i) == 0)
7113 ratioGraph->RemovePoint(i);
7117 auto _tmpPad =
gPad;
7119 ratioGraph->Draw(
"z0psame");
7120 auto minMax = graphMinMax(ratioGraph);
7121 adjustYRange(minMax.first, minMax.second,
h, std::get<1>(
auxFunctions[
h->GetYaxis()->GetTitle()]));
7127 dataGraph->Draw(
"z0p same");
7128 addLegendEntry((noPoint) ?
nullptr : dataGraph, strlen(dataGraph->GetTitle()) ? dataGraph->GetTitle() :
GetName(),
7129 noPoint ?
"" :
"pEX0");
7132 adjustYRange(minMax.first, minMax.second);
7148 gr->
Draw(hasSame ?
"P" :
"AP");
7152 if (forceNames !=
"") {
7155 bool _drawn =
false;
7161 for (
auto &
d : _dsets) {
7162 if (!
d->get()->TestBit(1 << 20))
7166 auto _obs =
d->obs();
7167 auto x = _obs.find((
v) ?
dynamic_cast<TObject *
>(
v)->
GetName() : emptyHist->GetXaxis()->GetName());
7171 for (
int i = 0; i < nevent; i++) {
7174 for (
const auto &_c : _coords) {
7176 if (cat->getIndex() != theData->get()->getCatIndex(cat->GetName())) {
7186 auto val = _nll.pars()->getRealValue(initPar->GetName());
7187 auto nllVal = _nll.getEntryVal(i);
7188 _nll.pars()->setRealValue(initPar->GetName(), initPar->getVal());
7189 auto nllVal2 = _nll.getEntryVal(i);
7190 _nll.pars()->setRealValue(initPar->GetName(), val);
7194 auto val = _nll.pars()->getRealValue(initPar->GetName());
7195 auto _extTerm = _nll.extendedTerm();
7196 _nll.pars()->setRealValue(initPar->GetName(), initPar->getVal());
7197 auto _extTerm2 = _nll.extendedTerm();
7198 _nll.pars()->setRealValue(initPar->GetName(), val);
7199 for (
int i = 1; i <= emptyHist->GetNbinsX(); i++) {
7200 emptyHist->SetBinContent(i, emptyHist->GetBinContent(i) + (_extTerm2 - _extTerm) / emptyHist->GetNbinsX());
7201 emptyHist->SetBinError(i, 0);
7203 emptyHist->GetYaxis()->SetTitle(
"log (L(#theta)/L(#theta_{0}))");
7204 emptyHist->Draw(_drawn ?
"same" :
"");
7210 auto rar = get<RooAbsReal>();
7221 v = getObject<RooAbsLValue>(
h->GetXaxis()->GetName()).get();
7223 if (
h->GetXaxis()->IsAlphanumeric()) {
7229 gPad->SetGrid(0, 0);
7231 gPad->SetGrid(1, 1);
7235 rar->getAttribute(
"BinnedLikelihood") ||
7237 std::unique_ptr<std::list<double>>(rar->binBoundaries(*
dynamic_cast<RooAbsRealLValue *
>(
vv),
7238 -std::numeric_limits<double>::infinity(),
7239 std::numeric_limits<double>::infinity()))))
7242 if (dOpt ==
"LF2" && !
components().empty()) {
7245 bool allHist =
true;
7260 gROOT->SetEditHistograms(
true);
7262 gROOT->SetEditHistograms(
false);
7275 bool hasError(
false);
7276 for (
int i = 0; i <
h->GetSumw2N(); i++) {
7277 if (
h->GetSumw2()->At(i)) {
7288 if (!hasSame &&
h->GetYaxis()->GetTitleFont() % 10 == 2) {
7289 h->GetYaxis()->SetTitleOffset(1.);
7292 TH1 *errHist =
nullptr;
7295 h->SetFillColor(
h->GetLineColor());
7296 h->SetMarkerStyle(0);
7297 errHist =
dynamic_cast<TH1 *
>(
h->Clone(
Form(
"%s_err",
h->GetName())));
7299 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
7300 h->SetBinError(i, 0);
7312 auto _hist = (errHist) ? errHist :
h;
7313 auto hCopy = (errHist) ?
nullptr :
h->Clone();
7314 _hist->GetListOfFunctions()->Add(node);
7315 _hist->GetListOfFunctions()->Add(
new TExec(
7318 "gROOT->SetEditHistograms(true);auto h = dynamic_cast<TH1*>(gPad->GetPrimitive(\"%s\")); if(h) { if(auto n "
7319 "= dynamic_cast<xRooNode*>(h->GetListOfFunctions()->FindObject(\"%s\")); n && "
7320 "n->TestBit(TObject::kNotDeleted) && n->get<RooRealVar>()->getVal() != h->GetBinContent(1)) {double range "
7321 "= h->GetMaximum()-h->GetMinimum(); h->SetBinContent(1, "
7322 "TString::Format(\"%%.2g\",int(h->GetBinContent(1)/(range*0.01))*range*0.01).Atof());n->SetContents( "
7323 "h->GetBinContent(1) ); for(auto pp : *h->GetListOfFunctions()) if(auto hh = "
7324 "dynamic_cast<TH1*>(pp))hh->SetBinContent(1,h->GetBinContent(1));} gPad->Modified();gPad->Update(); }",
7325 _hist->GetName(), node->GetName())));
7331 _hist->GetListOfFunctions()->Add(hCopy,
"TEXT HIST same");
7332 _hist->SetBinError(1, 0);
7334 _hist->SetStats(
false);
7335 _hist->Draw(((errHist) ?
"e2" :
""));
7340 bool overlayExisted =
false;
7343 if (
auto existing =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(
h->GetName())); existing) {
7348 overlayExisted =
true;
7350 TString oldStyle = (rar && rar->getStringAttribute(
"style")) ? rar->getStringAttribute(
"style") :
"";
7351 h->SetTitle(overlayName);
7377 rar->setStringAttribute(
"style",oldStyle==
"" ?
nullptr : oldStyle.
Data());
7390 h->Draw(dOpt + sOpt);
7393 if (!hasOverlay && (rar->InheritsFrom(
"RooRealSumPdf") || rar->InheritsFrom(
"RooAddPdf"))) {
7398 std::map<std::string, int> colorByTitle;
7399 std::set<std::string> allTitles;
7400 bool titleMatchName =
true;
7401 std::map<std::string, TH1 *> histGroups;
7402 std::vector<TH1 *> hhs;
7409 for (
auto &
c : *comps) {
7410 if (
c->fFolder ==
"!.coeffs")
7413 if (!
coefs.empty()) {
7415 std::shared_ptr<TH1> prevHist((
TH1 *)
h->Clone());
7418 std::unique_ptr<RooAbsReal>
f(
dynamic_cast<RooAbsReal *
>(comps->get()->Clone(
"tmpCopy")));
7420 Form(
"ORIGNAME:%s",
c->GetName()));
7421 f->redirectServers(
RooArgSet(zero),
false,
true);
7425 if (strlen(hh->GetTitle()) == 0)
7427 titleMatchName &= (
TString(
c->GetName()) == hh->GetTitle() ||
7429 std::shared_ptr<TH1> nextHist((
TH1 *)hh->Clone());
7430 hh->Add(prevHist.get(), -1.);
7433 prevHist = nextHist;
7438 auto hh = samp->BuildHistogram(
v);
7440 if (strlen(hh->GetTitle()) == 0)
7441 hh->SetTitle(samp->GetName());
7442 titleMatchName &= (
TString(samp->GetName()) == hh->GetTitle() ||
7446 for (
auto &hh : hhs) {
7448 if (histGroups.find(hh->GetTitle()) == histGroups.end()) {
7449 histGroups[hh->GetTitle()] = hh;
7452 histGroups[hh->GetTitle()]->Add(hh);
7456 auto hhMin = (hh->GetMinimum() == 0) ? hh->GetMinimum(1
e-9) : hh->GetMinimum();
7457 if (!stack->
GetHists() &&
h->GetMinimum() > hhMin) {
7459 if (hhMin >= 0 && newMin < 0)
7460 newMin = hhMin * 0.99;
7461 adjustYRange(newMin,
h->GetMaximum());
7463 if (
auto it = colorByTitle.find(hh->GetTitle()); it != colorByTitle.end()) {
7464 hh->SetFillColor(it->second);
7466 if (hh->GetFillColor() == 0) {
7467 hh->SetFillColor((count++) % 100);
7469 colorByTitle[hh->GetTitle()] = hh->GetFillColor();
7481 stack->
Add(hh, thisOpt);
7482 allTitles.insert(hh->GetTitle());
7485 stack->
Draw(
"noclear same");
7486 h->Draw(
"axissame");
7493 size_t e = std::min(allTitles.begin()->size(), allTitles.rbegin()->size());
7495 bool goodPrefix =
false;
7496 std::string commonSuffix;
7497 if (titleMatchName && ll->
GetEntries() > 1) {
7498 while (ii <
e - 1 && allTitles.begin()->at(ii) == allTitles.rbegin()->at(ii)) {
7500 if (allTitles.begin()->at(ii) ==
'_' || allTitles.begin()->at(ii) ==
' ')
7506 while (!stop && commonSuffix.size() <
size_t(
e - 1)) {
7507 commonSuffix = allTitles.begin()->substr(allTitles.begin()->length() - commonSuffix.length() - 1);
7508 for (
auto &t : allTitles) {
7510 commonSuffix = commonSuffix.substr(1);
7516 if (commonSuffix.find(
'_') == std::string::npos)
7519 commonSuffix = commonSuffix.substr(commonSuffix.find(
'_'));
7527 std::map<std::string, std::string> reducedTitles;
7528 while (reducedTitles.size() != allTitles.size()) {
7530 std::map<std::string, int> titlesMap;
7531 for (
auto &s : allTitles) {
7532 if (reducedTitles.count(s))
7534 titlesMap[s.substr(0, jj)]++;
7536 for (
auto &s : allTitles) {
7537 if (titlesMap[s.substr(0, jj)] == 1 && (jj >= s.length() || s.at(jj) ==
' ' || s.at(jj) ==
'_')) {
7538 reducedTitles[s] = s.substr(0, jj);
7544 for (
int i = ll->
GetEntries() - 1; i >= 0; i--) {
7546 _title = _title.substr(ii < _title.size() ? ii : 0);
7547 if (!commonSuffix.empty() &&
TString(_title).
EndsWith(commonSuffix.c_str()))
7548 _title = _title.substr(0, _title.length() - commonSuffix.length());
7553 std::shared_ptr<TStyle> _style;
7555 if (!
gROOT->GetStyle(_title.c_str())) {
7556 if ((_style = getObject<TStyle>(_title))) {
7558 gROOT->GetListOfStyles()->Add(_style.get());
7563 acquireNew<TStyle>(_title.c_str(),
TString::Format(
"Style for %s component", _title.c_str()));
7567 gROOT->GetListOfStyles()->Add(_style.get());
7570 _style = std::shared_ptr<TStyle>(
gROOT->GetStyle(_title.c_str()), [](
TStyle *) {});
7574 *
dynamic_cast<TAttLine *
>(ll->
At(i)) = *_style;
7575 *
dynamic_cast<TAttFill *
>(ll->
At(i)) = *_style;
7581 }
else if (!overlayExisted) {
7586 if (rar->InheritsFrom(
"RooAbsPdf") &&
7587 !(rar->InheritsFrom(
"RooRealSumPdf") || rar->InheritsFrom(
"RooAddPdf"))) {
7590 rar->leafNodeServerList(&s);
7604 ss +=
TString::Format(
"%s=%g", strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName(), _v->getVal());
7617 errHist->
Draw(dOpt + (dOpt.
Contains(
"LF2") ?
"e3same" :
"e2same"));
7618 double ymax = -std::numeric_limits<double>::infinity();
7619 double ymin = std::numeric_limits<double>::infinity();
7620 for (
int i = 1; i <= errHist->
GetNbinsX(); i++) {
7626 adjustYRange(
h->GetMinimum() * 0.9,
h->GetMaximum() * 1.1);
7629 if ((!auxPlotTitle.empty()) && !hasSame) {
7631 double padFrac = 0.3;
7632 auto _tmpPad =
gPad;
7633 gPad->SetBottomMargin(padFrac);
7634 auto ratioPad =
new TPad(
"auxPad",
"aux plot", 0, 0, 1, padFrac);
7635 ratioPad->SetFillColor(_tmpPad->GetFillColor());
7636 ratioPad->SetNumber(1);
7637 ratioPad->SetBottomMargin(ratioPad->GetBottomMargin() / padFrac);
7638 ratioPad->SetTopMargin(0.04);
7639 ratioPad->SetLeftMargin(
gPad->GetLeftMargin());
7640 ratioPad->SetRightMargin(
gPad->GetRightMargin());
7642 TH1 *ratioHist =
dynamic_cast<TH1 *
>((errHist) ? errHist->
Clone(
"auxHist") :
h->
Clone(
"auxHist"));
7650 auxPlotTitle.c_str()));
7653 ratioPad->SetGridy();
7655 for (
int i = 1; i <= ratioHist->
GetNbinsX(); i++) {
7663 double rHeight = 1. / padFrac;
7671#if ROOT_VERSION_CODE < ROOT_VERSION(6, 26, 00)
7679 ratioHist->
Draw((errHist ?
"e2" :
""));
7681 auto _h =
dynamic_cast<TH1 *
>(ratioHist->
Clone(
"auxHist_clone"));
7683 _h->Draw(
"histsame");
7687 }
else if (
auto ratioPad =
dynamic_cast<TPad *
>(
gPad->GetPrimitive(
"auxPad")); hasSame && ratioPad) {
7691 if (
auto hr =
dynamic_cast<TH1 *
>(ratioPad->GetPrimitive(
"auxHist"));
7693 TString histName = hr->GetTitle();
7695 histName = histName(0, histName.
Index(
'|'));
7697 if (
auto hnom =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(histName)); hnom) {
7698 h =
dynamic_cast<TH1 *
>(
h->Clone(
h->GetName()));
7700 for (
int i = 1; i <= hnom->GetNbinsX(); i++) {
7701 double val =
h->GetBinContent(i);
7702 double err =
h->GetBinError(i);
7703 h->SetBinContent(i, std::get<0>(
auxFunctions[hr->GetYaxis()->GetTitle()])(
7704 h->GetBinContent(i), hnom->GetBinContent(i), hnom->GetBinError(i)));
7705 h->SetBinError(i, std::get<0>(
auxFunctions[hr->GetYaxis()->GetTitle()])(
7706 val + err, hnom->GetBinContent(i), hnom->GetBinError(i)) -
7707 h->GetBinContent(i));
7709 auto _tmpPad =
gPad;
7712 if (
auto existing =
dynamic_cast<TH1 *
>(ratioPad->GetPrimitive(
h->GetName())); existing) {
7717 overlayExisted =
true;
7724 double ymax = -std::numeric_limits<double>::infinity();
7725 double ymin = std::numeric_limits<double>::infinity();
7726 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
7727 ymax = std::max(
ymax,
h->GetBinContent(i) +
h->GetBinError(i));
7728 ymin = std::min(
ymin,
h->GetBinContent(i) -
h->GetBinError(i));
7757 if (!hasSame && get<RooAbsPdf>()) {
7760 for (
auto &
d : _dsets) {
7761 if (
d->get()->TestBit(1 << 20)) {
7780 if (
auto w = get<RooWorkspace>();
w) {
7783#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
7792 Error(
"SaveAs",
"json format workspaces only in ROOT 6.26 onwards");
7797#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
7801 for (
auto &
c :
w->components()) {
7802 c->_eocache =
nullptr;
7806 if (!
w->writeToFile(
filename, sOpt !=
"update")) {
7811#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
7813 for (
auto &
c :
w->components()) {
7814 c->setExpensiveObjectCache(
w->expensiveObjectCache());
7824 return std::numeric_limits<double>::quiet_NaN();
7831 double err = std::numeric_limits<double>::quiet_NaN();
7833 std::unique_ptr<RooAbsCollection> _snap;
7838 _pars = _fr->floatParsFinal();
7839 _pars = _fr->constPars();
7843 auto _coefs =
coefs();
7845 out =
c->getVal(_obs);
7851 p->setNormRange(rangeName);
7852 out *=
p->expectedEvents(_obs);
7853#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
7855 p->_normSet =
nullptr;
7859 p->setNormRange(
nullptr);
7860 }
else if (
auto p2 =
dynamic_cast<RooAbsReal *
>(
get()); p2) {
7862 auto f = std::shared_ptr<RooAbsReal>(p2->createIntegral(*std::unique_ptr<RooArgSet>(p2->getObservables(_obs)),
7868 }
else if (get<RooAbsData>()) {
7871 auto ax = (rangeName) ?
GetXaxis() :
nullptr;
7872 auto rv = (ax) ?
dynamic_cast<RooRealVar *
>(ax->GetParent()) :
nullptr;
7873 auto cv = (ax && !rv) ?
dynamic_cast<RooCategory *
>(ax->GetParent()) :
nullptr;
7875 for (
auto &
v : vals) {
7878 if (rv && !rv->inRange(ax->GetBinCenter(i), rangeName))
7880 if (cv && !cv->isStateInRange(rangeName, ax->GetBinLabel(i)))
7887 out = std::numeric_limits<double>::quiet_NaN();
7890 _pars.RooAbsCollection::operator=(*_snap);
7892 return std::make_pair(out, err);
7897 std::vector<double> out;
7903 std::shared_ptr<RooFitResult> fr = std::dynamic_pointer_cast<RooFitResult>(_fr.
fComp);
7912 if (!
GETDMP(fr.get(),_finalPars)) {
7937 if (!prevCov ||
size_t(prevCov->
GetNcols()) < fr->floatParsFinal().size()) {
7940 for (
int i = 0; i < prevCov->
GetNcols(); i++) {
7941 for (
int j = 0; j < prevCov->
GetNrows(); j++) {
7942 cov(i, j) = (*prevCov)(i, j);
7947 for (
auto &
p : fr->floatParsFinal()) {
7948 if (!prevCov || i >= prevCov->
GetNcols()) {
7949 cov(i, i) = pow(
dynamic_cast<RooRealVar *
>(
p)->getError(), 2);
7953 int covQualBackup = fr->covQual();
7954 fr->setCovarianceMatrix(cov);
7955 fr->setCovQual(covQualBackup);
7958 auto _coefs =
coefs();
7960 bool doBinWidth =
false;
7961 auto ax = (binStart == -1 && binEnd == -1) ?
nullptr :
GetXaxis();
7967 normSet.
add(*
dynamic_cast<RooAbsArg *
>(ax->GetParent()));
7970 if (
auto p =
dynamic_cast<RooAbsPdf *
>(o); ax && (
p || _coefs.get() || o->getAttribute(
"density"))) {
7976 binEnd = ax->GetNbins();
7980 for (
int bin = binStart; bin <= binEnd; bin++) {
7982 dynamic_cast<RooAbsLValue *
>(ax->GetParent())->setBin(bin - 1, ax->GetName());
7989#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
7991 p->_normSet =
nullptr;
7994 res = o->getPropagatedError(*fr, normSet);
7997 res *=
c->getVal(normSet);
8001 res *= ax->GetBinWidth(bin);
#define ROOT_VERSION(a, b, c)
#define ROOT_VERSION_CODE
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
static void indent(ostringstream &buf, int indent_level)
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
winID h TVirtualViewer3D TVirtualGLPainter p
winID h TVirtualViewer3D vv
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t 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
void Set(Int_t nbins, const Float_t *xbins) override
Initialize axis with variable bins.
void Set(Int_t nbins, const Double_t *xbins) override
Initialize axis with variable bins.
Int_t FindFixBin(Double_t x) const override
Find bin number corresponding to abscissa x.
Double_t GetBinUpEdge(Int_t bin) const override
Return up edge of bin.
RooAbsRealLValue * rvar() const
void SetTitle(const char *title) override
Set the title of the TNamed.
Double_t GetBinLowEdge(Int_t bin) const override
Return low edge of bin.
void Set(Int_t nbins, Double_t xmin, Double_t 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
const char * GetTitle() const override
Returns title of object.
Double_t 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_t isBinnedDistribution(const RooArgSet &obs) const override
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
PdfWrapper(RooAbsPdf &f, RooAbsReal *coef, bool expEvMode=false)
PdfWrapper(const PdfWrapper &other, const char *name=0)
Double_t getSimplePropagatedError(const RooFitResult &fr, const RooArgSet &nset_in) const
virtual TObject * clone(const char *newname) const override
std::list< Double_t > * binBoundaries(RooAbsRealLValue &obs, Double_t xlo, Double_t xhi) const override
Retrieve bin boundaries if this distribution is binned in obs.
The PiecewiseInterpolation is a class that can morph distributions into each other,...
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
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.
virtual RooAbsArg * cloneTree(const char *newname=nullptr) const
Clone tree expression of objects.
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
virtual double highBound() const =0
virtual double lowBound() const =0
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
A space to attach TBranches.
const char * getLabel() const
Retrieve current label. Use getCurrentLabel() for more clarity.
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
Int_t getSize() const
Return the number of elements in the collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooFIter fwdIterator() const
One-time forward iterator.
Storage_t::size_type size() const
void clear()
Clear contents. If the collection is owning, it will also delete the contents.
void setName(const char *name)
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsData is the common abstract base class for binned and unbinned datasets.
virtual const RooArgSet * get() const
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Abstract base class for objects that are lvalues, i.e.
virtual std::list< std::string > getBinningNames() const =0
virtual double expectedEvents(const RooArgSet *nset) const
Return expected number of events to be used in calculation of extended likelihood.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
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)
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
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.
RooArgProxy is the abstract interface for RooAbsArg proxy classes.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Class RooBinning is an implements RooAbsBinning in terms of an array of boundary values,...
RooCategory is an object to represent discrete states.
bool defineType(const std::string &label)
Define a state with given name.
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
static const RooCmdArg & none()
Return reference to null argument.
RooConstVar represent a constant real-valued object.
The RooDataHist is a container class to hold N-dimensional binned data.
RooDataSet is a container class to hold unbinned data.
A one-time forward iterator working on RooLinkedList or RooAbsCollection.
RooAbsArg * next()
Return next element or nullptr if at end.
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.
Int_t status() const
Return MINUIT status code.
void setFinalParList(const RooArgList &list)
Fill the list of final values of the floating parameters.
static std::shared_ptr< RooLinkedList > createNLLOptions()
static xRooNLLVar createNLL(const std::shared_ptr< RooAbsPdf > pdf, const std::shared_ptr< RooAbsData > data, const RooLinkedList &nllOpts)
static std::pair< std::shared_ptr< RooAbsData >, std::shared_ptr< const RooAbsCollection > > generateFrom(RooAbsPdf &pdf, const std::shared_ptr< const RooFitResult > &fr, bool expected=false, int seed=0)
void _Add_(const char *name, const char *opt)
void SetTitle(const char *title) override
Set the title of the TNamed.
xRooNLLVar nll(const xRooNode &_data, std::initializer_list< RooCmdArg > nllOpts) const
void SetName(const char *name) override
Set the name of the TNamed.
auto end() const -> decltype(std::vector< std::shared_ptr< xRooNode > >::end())
TGListTreeItem * GetTreeItem(TBrowser *b) const
xRooNode Multiply(const xRooNode &child, Option_t *opt="")
xRooNode datasets() const
xRooNode Remove(const xRooNode &child)
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 Combine(const xRooNode &rhs)
std::shared_ptr< T > acquireNew(Args &&...args)
bool SetBinData(int bin, double value, const char *dataName="obsData")
bool fInterrupted
appears that if was fXaxis then dialog box for SetXaxis will take as current value
xRooNode Add(const xRooNode &child, Option_t *opt="")
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
void _ShowVars_(Bool_t set=kTRUE)
bool _IsShowVars_() const
TGraph * BuildGraph(RooAbsLValue *v=nullptr, bool includeZeros=false, TVirtualPad *fromPad=nullptr) const
std::shared_ptr< xRooNode > find(const std::string &name) const
const char * GetNodeType() const
bool SetBinContent(int bin, double value, const char *par=nullptr, double parVal=1)
void Checked(TObject *obj, bool val)
void Print(Option_t *opt="") const override
Print TNamed name and title.
xRooNode components() const
void SaveAs(const char *filename="", Option_t *option="") const override
Save this object in the file specified by filename.
const std::shared_ptr< xRooNode > & at(size_t idx, bool browseResult=true) const
TGListTree * GetListTree(TBrowser *b) const
void Inspect() const override
Dump contents of this object in a graphics canvas.
auto begin() const -> decltype(std::vector< std::shared_ptr< xRooNode > >::begin())
bool SetXaxis(const RooAbsBinning &binning)
RooArgList argList() const
void _fitTo_(const char *datasetName="", const char *constParValues="")
std::shared_ptr< xRooNode > fProvider
std::vector< double > GetBinContents(int binStart=1, int binEnd=0) const
xRooNode constraints() const
xRooNode mainChild() const
xRooNode fitResult(const char *opt="") const
std::shared_ptr< TObject > fComp
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
void SetFitResult(const RooFitResult *fr=nullptr)
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)
bool SetContents(const TObject &obj)
void _Vary_(const char *what)
RooWorkspace * ws() const
xRooNode shallowCopy(const std::string &name, std::shared_ptr< xRooNode > parent=nullptr)
void _generate_(const char *name="", bool expected=false)
TH1 * BuildHistogram(RooAbsLValue *v=nullptr, bool empty=false, bool errors=false, int binStart=1, int binEnd=0) const
std::shared_ptr< TObject > getObject(const std::string &name, const std::string &type="") const
std::shared_ptr< TStyle > style(TObject *initObject=nullptr) const
void SetHidden(Bool_t set=kTRUE)
bool contains(const std::string &name) const
std::vector< std::shared_ptr< xRooNode > > fBrowsables
xRooNode variations() const
std::shared_ptr< xRooNode > operator[](size_t idx)
std::string GetPath() const
std::shared_ptr< xRooNode > parentPdf() const
like a parent but only for use by getObject
std::pair< double, double > IntegralAndError(const xRooNode &fr="", const char *rangeName=nullptr) const
xRooNode & operator=(const TObject &o)
void _SetBinContent_(int bin, double value, const char *par="", double parVal=1)
std::shared_ptr< TObject > acquire(const std::shared_ptr< TObject > &arg, bool checkFactory=false, bool mustBeNew=false)
xRooNode(const char *type, const char *name, const char *title="")
xRooNode reduced(const std::string &range="") const
void _SetContents_(double value)
std::function< xRooNode(xRooNode *)> fBrowseOperation
void Browse(TBrowser *b=nullptr) override
Browse object. May be overridden for another default action.
double GetBinData(int bin, const char *dataName="obsData")
TClass * IsA() const override
void SetRange(const char *range, double low=std::numeric_limits< double >::quiet_NaN(), double high=std::numeric_limits< double >::quiet_NaN())
static void SetAuxFunction(const char *title, const std::function< double(double, double, double)> &func, bool symmetrize=false)
std::shared_ptr< TObject > convertForAcquisition(xRooNode &acquirer, const char *opt="") const
const char * GetRange() const
std::shared_ptr< xRooNode > fParent
RooHistFunc implements a real-valued function sampled from a multidimensional histogram.
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
TObject * At(int index) const
Return object stored in sequential position given by index.
TIterator * MakeIterator(bool forward=true) const
Create a TIterator for this list.
static RooMsgService & instance()
Return reference to singleton instance.
StreamConfig & getStream(Int_t id)
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
Class RooObjCacheManager is an implementation of class RooCacheManager<RooAbsCacheElement> and specia...
RooProdPdf is an efficient implementation of a product of PDFs of the form.
A RooProduct represents the product of a given set of RooAbsReal objects.
The class RooRealSumPdf implements a PDF constructed from a sum of functions:
RooRealVar represents a variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
void setError(double value)
void setRange(const char *name, double min, double max)
Set a fit or plotting range.
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
RooStringVar is a RooAbsArg implementing string values.
The RooWorkspace is a persistable container for RooFit projects.
const std::map< std::string, RooArgSet > & sets() const
bool removeSet(const char *name)
Remove a named set from the workspace.
RooFactoryWSTool & factory()
Return instance to factory tool.
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
virtual Style_t GetTitleFont() const
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title.
virtual Float_t GetTitleSize() const
virtual Float_t GetLabelSize() const
virtual Float_t GetTickLength() const
virtual Float_t GetTitleOffset() const
virtual void SetTickLength(Float_t length=0.03)
Set tick mark length.
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Fill Area Attributes class.
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Class to manage histogram axis.
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
const char * GetTitle() const override
Returns title of object.
TAxis()
Default constructor.
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.
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.
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 a suite of consecutive data records (TKey instances) with a well defined format.
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.
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 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 Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
void SetTitle(const char *title) override
Change (i.e.
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.
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.
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.
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.
Storage class for one entry of a TLegend.
This class displays a legend box (TPaveText) containing several legend entries.
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.
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 void Delete(Option_t *option="")
Delete this object.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual const char * GetTitle() const
Returns title of object.
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
@ kCanDelete
if object in a list can be deleted
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
The most important graphics class in the ROOT system.
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
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")
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...
static TVirtualPadEditor * GetPadEditor(Bool_t load=kTRUE)
Returns the pad editor dialog. Static method.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
virtual void Modified(Bool_t flag=1)=0
virtual TList * GetListOfPrimitives() const =0
virtual void SetPad(const char *name, const char *title, Double_t xlow, Double_t ylow, Double_t xup, Double_t yup, Color_t color=35, Short_t bordersize=5, Short_t bordermode=-1)=0
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
void Draw(Option_t *option="") override=0
Default Draw method for all objects.
const char * GetName() const override=0
Returns name of object.
virtual TVirtualPad * GetPad(Int_t subpadnumber) const =0
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)=0
virtual Int_t GetLogy() const =0
virtual void SetLogy(Int_t value=1)=0
virtual TObject * GetPrimitive(const char *name) const =0
virtual void SetBorderSize(Short_t bordersize)=0
virtual void SetName(const char *name)=0
TClass * IsA() const override
RooCmdArg RecycleConflictNodes(bool flag=true)
RooConstVar & RooConst(double val)
RooCmdArg Embedded(bool flag=true)
RooCmdArg GlobalObservables(Args_t &&... argsOrArgSet)
RooCmdArg Range(const char *rangeName, bool adjustNorm=true)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
Double_t Prob(Double_t chi2, Int_t ndf)
Computation of the probability for a certain Chi-squared (chi2) and number of degrees of freedom (ndf...
Double_t ChisquareQuantile(Double_t p, Double_t ndf)
Evaluate the quantiles of the chi-squared probability distribution function.
#define BEGIN_XROOFIT_NAMESPACE
#define END_XROOFIT_NAMESPACE
void removeTopic(RooFit::MsgTopic oldTopic)
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 GETWSSNAPSHOTS(RooWorkspace *w)
auto GETACTBROWSER(TRootBrowser *b)
auto GETROOTDIR(TGFileBrowser *b)
const xRooNode * runningNode
auto GETLISTTREE(TGFileBrowser *b)
const T & _or_func(const T &a, const T &b)
Bool_t TopRightPlaceBox(TPad *p, TObject *o, Double_t w, Double_t h, Double_t &xl, Double_t &yb)
TLegend * getLegend(bool create=true, bool doPaint=false)