47#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
49#define protected public
70#define GETWS(a) a->_myws
71#define GETWSSETS(w) w->_namedSets
72#define GETWSSNAPSHOTS(w) w->_snapshots
73#define GETACTBROWSER(b) b->fActBrowser
74#define GETROOTDIR(b) b->fRootDir
75#define GETLISTTREE(b) b->fListTree
76#define GETDMP(o, m) o->m
101 return a->workspace();
109 return w->getSnapshots();
113 return b->GetActBrowser();
117 return b->GetRootDir();
121 return b->GetListTree();
123#define GETDMP(o, m) \
124 *reinterpret_cast<void **>(reinterpret_cast<unsigned char *>(o) + o->Class()->GetDataMemberOffset(#m))
176#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
180#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
184#if ROOT_VERSION_CODE > ROOT_VERSION(6, 37, 00)
214#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
220xRooNode::InteractiveObject *xRooNode::gIntObj =
nullptr;
221std::map<std::string, std::tuple<std::function<
double(
double,
double,
double)>,
bool>> xRooNode::auxFunctions;
225 auxFunctions[title] = std::make_tuple(func, symmetrize);
244xRooNode::xRooNode(
const char *classname,
const char *
name,
const char *title)
250#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
251 w->_embeddedDataList.Delete();
253 xRooNode(*w, std::make_shared<xRooNode>()).sterilize();
259 if (
auto a = get<TNamed>();
a)
272 if (!
gSystem->AccessPathName(pathName)) {
275#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
276 fComp = std::make_shared<RooWorkspace>(
"workspace",
name);
281 Error(
"xRooNode",
"Error reading json workspace %s",
name);
286 Error(
"xRooNode",
"json format workspaces available only in ROOT 6.26 onwards");
292 auto _file = std::make_shared<TFile>(
297 auto keys = _file->GetListOfKeys();
299 for (
auto &&k : *keys) {
305#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
306 dynamic_cast<RooWorkspace *>(ws)->_embeddedDataList.Delete();
308 xRooNode(*ws, std::make_shared<xRooNode>()).sterilize();
314 fParent = std::make_shared<xRooNode>(
322 }
else if (pathName.EndsWith(
".root") || pathName.EndsWith(
".json")) {
323 throw std::runtime_error(TString::Format(
"%s does not exist", name));
327 if (
auto _ws = get<RooWorkspace>(); _ws && (!parent || parent->get<
TFile>())) {
340 for (
auto f : *
gROOT->GetListOfFiles()) {
341 if ((
dynamic_cast<TFile *
>(
f)->GetVersion() / 100) > (
gROOT->GetVersionInt() / 100)) {
342 Warning(
"xRooNode",
"There is file open with version %d > current version %d ... results may be wrong",
343 dynamic_cast<TFile *
>(
f)->GetVersion(),
gROOT->GetVersionInt());
352 for (
auto col : *
colors) {
353 if (!
gROOT->GetListOfColors()->FindObject(col->GetName())) {
354 gROOT->GetListOfColors()->Add(
gROOT->GetListOfColors()->IsOwner() ? col->Clone() : col);
364 for (
auto &
d : _ws->allData()) {
365 for (
auto &
a : *
d->get()) {
366 if (
auto v = _ws->var(
a->GetName());
v) {
367 v->setAttribute(
"obs");
368 }
else if (
auto c = _ws->cat(
a->GetName());
c) {
369 c->setAttribute(
"obs");
373 checkCount +=
d->TestBit(1 << 20);
376 if (checkCount == 0 && !_ws->allData().empty())
377 _ws->allData().back()->SetBit(1 << 20,
true);
379 if (
auto _set =
dynamic_cast<RooArgSet *
>(
GETWSSNAPSHOTS(_ws).find(
"NominalParamValues")); _set) {
380 for (
auto s : *_set) {
381 if (
auto v =
dynamic_cast<RooRealVar *
>(s);
v) {
382 _ws->var(s->GetName())->setStringAttribute(
"nominal",
TString::Format(
"%f",
v->getVal()));
390 if (k ==
"globalObservables" || TString(k).
EndsWith(
"_GlobalObservables")) {
393 s->setAttribute(
"obs");
394 s->setAttribute(
"global");
396 }
else if (TString(k).
EndsWith(
"_Observables")) {
397 const_cast<RooArgSet &
>(
v).setAttribAll(
"obs");
398 }
else if (TString(k).
EndsWith(
"_POI")) {
400 s->setAttribute(
"poi");
401 auto _v =
dynamic_cast<RooRealVar *
>(s);
411 }
else if (TString(k).
EndsWith(
"_NuisParams")) {
412 const_cast<RooArgSet &
>(
v).setAttribAll(
"np");
415 if (!_allGlobs.
empty() &&
GETWSSETS(_ws).count(
"globalObservables") == 0) {
416 _ws->defineSet(
"globalObservables", _allGlobs);
421 if (!_ws->allPdfs().empty()) {
422 std::set<RooRealVar *> noErrorPars;
423 std::string parNames;
424 for (
auto &p : np()) {
425 auto v = p->get<RooRealVar>();
428 if (!
v->hasError()) {
429 noErrorPars.insert(
v);
430 if (!parNames.empty())
432 parNames +=
v->GetName();
435 if (!noErrorPars.empty()) {
437 "Inferring initial errors of %d parameters (%s%s) (give all nuisance parameters an error to avoid "
439 int(noErrorPars.size()), (*noErrorPars.begin())->GetName(), (noErrorPars.size() > 1) ?
",..." :
"");
440 if (
gEnv->GetValue(
"XRooFit.SkipInitParErrorInference",
false)) {
441 Warning(
"xRooNode",
"Skipping because XRooFit.SkipInitParErrorInference=true. This is expert-only, you should fix your workspaces!");
445 for (
auto &
a : *
this) {
446 if (noErrorPars.empty()) {
449 if (
a->fFolder ==
"!pdfs") {
451 auto fr =
a->floats().reduced(parNames).fitResult(
"prefit");
452 if (
auto _fr = fr.get<RooFitResult>(); _fr) {
453 std::set<RooRealVar *> foundPars;
454 for (
auto &
v : noErrorPars) {
455 if (
auto arg =
dynamic_cast<RooRealVar *
>(_fr->floatParsFinal().find(
v->GetName()));
456 arg && arg->hasError()) {
457 v->setError(arg->getError());
461 for (
auto &
v : foundPars) {
462 noErrorPars.erase(
v);
474 if (strlen(GetTitle()) == 0) {
491 (comp.
InheritsFrom(
"RooAbsArg") && dynamic_cast<const
RooAbsArg *>(&comp)->getStringAttribute(
"alias"))
492 ? dynamic_cast<const
RooAbsArg *>(&comp)->getStringAttribute(
"alias")
501 if (
auto a = std::dynamic_pointer_cast<RooAbsArg>(comp);
a &&
a->getStringAttribute(
"alias"))
502 return a->getStringAttribute(
"alias");
504 return comp->GetName();
517 bool isBool = (
v ==
"TRUE" ||
v ==
"FALSE");
519 if (value ==
nullptr ||
v ==
"NULLPTR") {
520 if (
a->getAttribute(
name))
521 a->setAttribute(
name,
false);
522 else if (
a->getStringAttribute(
name))
523 a->setStringAttribute(
name,
nullptr);
526 a->setAttribute(
name, (
v ==
"TRUE"));
528 a->setStringAttribute(
name, value);
537 for (
auto a : *
gROOT->GetListOfBrowsers()) {
540 if (
auto bi =
dynamic_cast<TRootBrowser *
>(
b->GetBrowserImp())) {
541 if (
auto fb =
dynamic_cast<TGFileBrowser *
>(bi->GetActBrowser())) {
559 if (o->isSelectedComp() && !val) {
562 o->setAttribute(
"hidden");
563 }
else if (!o->isSelectedComp() && !val) {
568 o->setAttribute(
"hidden",
false);
571 item->CheckItem(!o->getAttribute(
"hidden"));
572 if (o->isSelectedComp()) {
575 item->SetColor(
kGray);
580 if (
auto o =
get(); o) {
582 o->SetBit(1 << 20, val);
584 if (
auto _ws =
ws(); _ws) {
587 if (fr->numStatusHistory() && !_ws->genobj(fr->GetName())) {
589 if (
auto wfr =
dynamic_cast<RooFitResult *
>(_ws->genobj(fr->GetName()))) {
594 _allVars = fr->floatParsFinal();
595 _allVars = fr->constPars();
596 for (
auto &i : fr->floatParsInit()) {
602 for (
auto oo : _ws->allGenericObjects()) {
603 if (
auto ffr =
dynamic_cast<RooFitResult *
>(oo); ffr && ffr != fr) {
604 ffr->ResetBit(1 << 20);
608 _ws->allVars() = fr->floatParsInit();
612 for (
auto a : *
gROOT->GetListOfBrowsers()) {
623 if (
auto first = p->GetParent()->GetFirstChild()) {
625 if (first->HasCheckBox()) {
626 auto _obj =
static_cast<xRooNode *
>(first->GetUserData());
627 first->CheckItem(_obj->get() && _obj->get()->TestBit(1 << 20));
629 }
while ((first = first->GetNextSibling()));
634 if (
auto bi =
dynamic_cast<TRootBrowser *
>(
b->GetBrowserImp())) {
635 if (
auto fb =
dynamic_cast<TGFileBrowser *
>(bi->GetActBrowser())) {
641 if (
auto first = i->GetFirstChild()) {
643 if (first->IsOpen() &&
644 (
TString(first->GetText()) ==
"poi" ||
TString(first->GetText()) ==
"np")) {
645 fb->DoubleClicked(first, 0);
648 }
while ((first = first->GetNextSibling()));
666 static bool blockBrowse =
false;
670 auto b2 =
dynamic_cast<TBrowser *
>(
gROOT->GetListOfBrowsers()->Last());
671 if (!b2 || !b2->GetBrowserImp()) {
673 gEnv->SetValue(
"X11.UseXft",
"no");
674 gEnv->SetValue(
"X11.Sync",
"no");
675 gEnv->SetValue(
"X11.FindBestVisual",
"no");
676 gEnv->SetValue(
"Browser.Name",
"TRootBrowser");
677 gEnv->SetValue(
"Canvas.Name",
"TRootCanvas");
678 b2 =
new TBrowser(
"nodeBrowser",
this,
"RooFit Browser");
680 }
else if (strcmp(b2->GetName(),
"nodeBrowser") == 0) {
682 b2->BrowseObject(
this);
687 _b->AddFSDirectory(
"Workspaces",
nullptr,
"SetRootDir");
688 _b->GotoDir(
nullptr);
699 if (
auto first = item->GetFirstChild()) {
701 if (first->HasCheckBox()) {
702 auto _obj =
static_cast<xRooNode *
>(first->GetUserData());
703 first->CheckItem(_obj->get() &&
704 (_obj->get()->TestBit(1 << 20) ||
707 }
while ((first = first->GetNextSibling()));
720 fBrowsables.push_back(std::make_shared<xRooNode>(
".Draw(\"pull\")",
nullptr, *
this));
721 fBrowsables.push_back(std::make_shared<xRooNode>(
".Draw(\"corr10colztext\")",
nullptr, *
this));
722 if (std::unique_ptr<RooAbsCollection>(_fr->floatParsFinal().selectByAttrib(
"poi",
true))->size() == 1) {
723 fBrowsables.push_back(std::make_shared<xRooNode>(
".Draw(\"impact\")",
nullptr, *
this));
730 s->SetFillAttributes();
737 Draw(
b->GetDrawOption());
739 }
catch (
const std::exception &
e) {
742 (
gROOT->GetListOfBrowsers()->At(0))
745 "Exception",
e.what(),
750 bool hasFolders =
false;
752 for (
auto &
c : *
this) {
753 if (!
c->fFolder.empty()) {
762 auto _folders =
find(
".folders");
764 _folders = emplace_back(std::make_shared<xRooNode>(
".folders",
nullptr, *
this));
767 for (
auto &
v : *
this) {
768 if (!
v->fFolder.empty() && !_folders->find(
v->fFolder,
false)) {
769 _folders->emplace_back(std::make_shared<xRooNode>(
v->fFolder.c_str(),
nullptr, *
this));
773 for (
auto &
v : *_folders) {
776 _name = _name(1, _name.
Length());
777 b->Add(
v.get(), _name);
781 for (
auto &
v : *
this) {
782 if (hasFolders && !
v->fFolder.empty())
784 if (strcmp(
v->GetName(),
".folders") == 0)
787 int _checked = (
v->get<
RooAbsData>() || _fr) ?
v->get()->TestBit(1 << 20) : -1;
788 if (_fr && ((_fr->status() == 0 && _fr->numStatusHistory() == 0) || (_fr->floatParsFinal().empty()))) {
793 _checked = !
v->get<
RooAbsArg>()->getAttribute(
"hidden");
796 _name = _name(strlen(
v->get()->ClassName()) + 2, _name.
Length());
804 :
v->get()->GetName());
808 if (
auto _type =
v->GetNodeType(); strlen(_type)) {
816 for (
size_t i = 0; i < fv->dependents().
size(); i++) {
822 for (
size_t i = 0; i < gv->dependents().
size(); i++) {
828 std::set<int> interpCodes;
829 for(
auto&
c : pi->interpolationCodes()) interpCodes.insert(
c);
830 if(interpCodes.size()==1) { _name +=
TString::Format(
" [InterpCode=%d]",*interpCodes.begin()); }
833 std::set<int> interpCodes;
834 for(
auto&
c : fiv->interpolationCodes()) interpCodes.insert(
c==4 ? 5 :
c);
835 if(interpCodes.size()==1) { _name +=
TString::Format(
" [InterpCode=%d]",*interpCodes.begin()); }
839 TString nameSave(
v->TNamed::GetName());
840 TString titleSave(
v->TNamed::GetTitle());
841 if (
auto o =
v->get(); o)
842 v->TNamed::SetNameTitle(o->GetName(), o->ClassName());
843 b->Add(
v.get(), _name, _checked);
844 if (
auto o =
v->get(); o)
845 v->TNamed::SetNameTitle(nameSave, titleSave);
846 if (_checked != -1) {
847 dynamic_cast<TQObject *
>(
b->GetBrowserImp())
848 ->
Connect(
"Checked(TObject *, bool)",
ClassName(),
v.get(),
"Checked(TObject *, bool)");
851 if (_fr->status() || _fr->covQual() != 3) {
852 v->GetTreeItem(
b)->SetColor((_fr->numStatusHistory() && !_fr->floatParsFinal().empty()) ?
kRed :
kBlue);
853 }
else if (_fr->numStatusHistory() == 0) {
854 v->GetTreeItem(
b)->SetColor(
kGray);
857 if ((
v->fFolder ==
"!np" ||
v->fFolder ==
"!poi")) {
859 v->GetTreeItem(
b)->SetColor(
kGray);
861 v->GetTreeItem(
b)->ClearColor();
865 if (
auto fits = _htr->GetFitInfo()) {
866 for (
int i = 0; i < fits->numEntries(); i++) {
868 if (fits->get(i)->getCatIndex(
"type") != 5 && fits->get(i)->getRealValue(
"status") != 0) {
869 v->GetTreeItem(
b)->SetColor(
kRed);
874 v->GetTreeItem(
b)->SetColor(
kBlue);
901 if (_name ==
".memory")
903 TString nameSave(
v->TNamed::GetName());
904 TString titleSave(
v->TNamed::GetTitle());
905 if (
auto o =
v->get(); o)
906 v->TNamed::SetNameTitle(o->GetName(), o->ClassName());
907 b->Add(
v.get(), _name, -1);
908 if (
auto o =
v->get(); o)
909 v->TNamed::SetNameTitle(nameSave, titleSave);
912 b->SetSelected(
this);
925 auto v = std::make_shared<xRooNode>(
vars());
936 if (strcmp(
b->GetName(),
".vars") == 0)
959 if (
auto v =
var();
v)
960 return v->getBinWidth(bin - 1,
GetName());
966 return (bin ==
v->getBinning(
GetName()).numBins() + 1) ?
v->getBinning(
GetName()).binHigh(bin - 2)
967 :
v->getBinning(
GetName()).binLow(bin - 1);
974 return (bin == 0) ?
v->getBinning(
GetName()).binLow(bin) :
v->getBinning(
GetName()).binHigh(bin - 1);
991 void Set(
Int_t nbins,
const double *xbins)
override
999 std::vector<double> bins(nbins + 1);
1000 for (
int i = 0; i <= nbins; i++)
1001 bins.at(i) = xbins[i];
1002 return Set(nbins, &bins[0]);
1025 if (
auto _owned =
find(
".memory"); _owned) {
1026 for (
auto &o : *_owned) {
1027 if (
name == o->GetName()) {
1028 if (
type.empty() || o->get()->InheritsFrom(
type.c_str()))
1037 while (!_provider && _parent) {
1038 _provider = _parent->fProvider;
1039 _parent = _parent->fParent;
1042 return _provider->getObject(
name,
type);
1045 std::shared_ptr<TObject> out;
1046 if (
auto arg =
ws()->arg(
name.c_str()); arg) {
1047 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
1048 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
1053 if (
auto arg =
ws()->data(
name.c_str()); arg) {
1054 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
1055 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
1060 if (
auto arg =
ws()->genobj(
name.c_str()); arg) {
1061 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
1062 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
1067 if (
auto arg =
ws()->embeddedData(
name.c_str()); arg) {
1068 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
1069 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
1075 auto _tmp = std::shared_ptr<TObject>(arg, [](
TObject *) {});
1076 if (!
type.empty() && arg->InheritsFrom(
type.c_str()))
1086 arg->treeNodeServerList(&nodes);
1087 if (
auto server = nodes.
find(
name.c_str())) {
1088 return std::shared_ptr<TObject>(server, [](
TObject *) {});
1115 if (
auto xName = o->getStringAttribute(
"xvar"); xName) {
1125 (o->dependsOn(*
dynamic_cast<RooAbsArg *
>(_parentX->GetParent())) ||
vars().empty())) {
1127 }
else if (
auto _obs =
obs(); !_obs.empty()) {
1128 for (
auto &
v : _obs) {
1137 }
else if (
auto _pars =
pars(); !_pars.empty()) {
1138 for (
auto &
v : _pars) {
1164 TString binningName = o->getStringAttribute(
"binning");
1165 auto _bnames =
x->getBinningNames();
1166 bool hasBinning =
false;
1167 for (
auto &
b : _bnames) {
1168 if (
b == binningName) {
1176 Warning(
"GetXaxis",
"Binning %s not defined on %s - clearing", binningName.
Data(),
1177 dynamic_cast<TObject *
>(
x)->GetName());
1178 o->setStringAttribute(
"binning",
nullptr);
1182 if (binningName ==
"" && o !=
dynamic_cast<TObject *
>(
x)) {
1184 auto __bnames =
x->getBinningNames();
1185 for (
auto &
b : __bnames) {
1188 if (
b == o->GetName()) {
1189 binningName = o->GetName();
1193 if (binningName ==
"") {
1199 (std::list<double> *)(
nullptr),
1201 ? o->binBoundaries(*
dynamic_cast<RooAbsRealLValue *
>(
x), -std::numeric_limits<double>::infinity(),
1202 std::numeric_limits<double>::infinity())
1205 std::vector<double> _bins;
1206 for (
auto &
b : *
bins) {
1207 if (_bins.empty() || std::abs(_bins.back() -
b) > 1
e-5 * _bins.back())
1210 fXAxis = std::make_shared<Axis2>(_bins.size() - 1, &_bins[0]);
1212 if (
auto _v =
dynamic_cast<RooRealVar *
>(
x); _v) {
1213 _v->setBinning(
RooBinning(_bins.size() - 1, &_bins[0], o->GetName()), o->
GetName());
1214 _v->getBinning(o->GetName())
1219 binningName = o->GetName();
1221 }
else if (_parentX) {
1223 binningName = _parentX->GetName();
1230 if (
r->getBinning(binningName).isUniform()) {
1231 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName),
r->getMin(binningName),
r->getMax(binningName));
1233 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName),
r->getBinning(binningName).array());
1235 }
else if (
auto cat =
dynamic_cast<RooCategory *
>(
x)) {
1236 std::vector<double>
bins = {};
1237 for (
int i = 0; i <=
x->numBins(binningName); i++)
1239 fXAxis = std::make_shared<Axis2>(
x->numBins(binningName), &
bins[0]);
1242 std::map<int, std::string> cats;
1243 for (
auto &
c : *cat) {
1244 if (cat->isStateInRange(binningName,
c.first.c_str())) {
1245 cats[
c.second] =
c.first;
1248 for (
auto &[
_, label] : cats) {
1249 fXAxis->SetBinLabel(i++, label.c_str());
1254 fXAxis->SetName(binningName);
1261 if (
auto o =
get(); o) {
1262 if (o->InheritsFrom(
"RooWorkspace"))
1264 if (o->InheritsFrom(
"RooAbsData"))
1266 if (o->InheritsFrom(
"RooSimultaneous"))
1269 if (o->InheritsFrom(
"RooProdPdf"))
1271 if (o->InheritsFrom(
"RooRealSumPdf") || o->InheritsFrom(
"RooAddPdf"))
1274 if (o->InheritsFrom(
"RooFitResult")) {
1275 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitRooFitResult",
true)) {
1276 gClient->GetMimeTypeList()->AddType(
"xRooFitRooFitResult",
"xRooFitRooFitResult",
"package.xpm",
1277 "package.xpm",
"->Browse()");
1279 return "xRooFitRooFitResult";
1281 if (o->InheritsFrom(
"RooRealVar") || o->InheritsFrom(
"RooCategory")) {
1283 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitObs",
true)) {
1284 gClient->GetMimeTypeList()->AddType(
"xRooFitObs",
"xRooFitObs",
"x_pic.xpm",
"x_pic.xpm",
"->Browse()");
1286 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitGlobs",
true)) {
1287 gClient->GetMimeTypeList()->AddType(
"xRooFitGlobs",
"xRooFitGlobs",
"z_pic.xpm",
"z_pic.xpm",
1290 return (
get<RooAbsArg>()->getAttribute(
"global") ?
"xRooFitGlobs" :
"xRooFitObs");
1294 if (o->InheritsFrom(
"TStyle")) {
1295 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitTStyle",
true)) {
1296 gClient->GetMimeTypeList()->AddType(
"xRooFitTStyle",
"xRooFitTStyle",
"bld_colorselect.xpm",
1297 "bld_colorselect.xpm",
"->Browse()");
1299 return "xRooFitTStyle";
1301 if (o->InheritsFrom(
"RooConstVar")) {
1307 return "TMethodBrowsable-leaf";
1309 if (o->InheritsFrom(
"RooStats::HypoTestInverterResult")) {
1310 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitScanStyle",
true)) {
1311 gClient->GetMimeTypeList()->AddType(
"xRooFitScanStyle",
"xRooFitScanStyle",
"f2_s.xpm",
"f2_s.xpm",
1314 return "xRooFitScanStyle";
1316 if (o->InheritsFrom(
"RooStats::HypoTestResult")) {
1317 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitTestStyle",
true)) {
1318 gClient->GetMimeTypeList()->AddType(
"xRooFitTestStyle",
"xRooFitTestStyle",
"diamond.xpm",
"diamond.xpm",
1321 return "xRooFitTestStyle";
1323 if (o->InheritsFrom(
"RooStats::HistFactory::FlexibleInterpVar"))
1324 return "TBranchElement-folder";
1325 if (o->InheritsFrom(
"RooAbsPdf")) {
1326 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitPDFStyle",
true)) {
1327 gClient->GetMimeTypeList()->AddType(
"xRooFitPDFStyle",
"xRooFitPDFStyle",
"pdf.xpm",
"pdf.xpm",
1330 return "xRooFitPDFStyle";
1332 if (o->InheritsFrom(
"RooStats::ModelConfig")) {
1333 if (!
gClient->GetMimeTypeList()->GetIcon(
"xRooFitMCStyle",
true)) {
1334 gClient->GetMimeTypeList()->AddType(
"xRooFitMCStyle",
"xRooFitMCStyle",
"app_t.xpm",
"app_t.xpm",
1337 return "xRooFitMCStyle";
1341 _ax && (
a->isBinnedDistribution(*
dynamic_cast<RooAbsArg *
>(_ax->GetParent())) ||
1343 std::unique_ptr<std::list<double>>(
a->binBoundaries(
1344 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
1345 std::numeric_limits<double>::infinity()))))) {
1350 return o->ClassName();
1362 if(rrs->getAttribute(
"BinnedLikelihood"))
return "BinnedLikelihood";
1365 if (o->InheritsFrom(
"RooStats::HistFactory::FlexibleInterpVar"))
1367 if (o->InheritsFrom(
"PiecewiseInterpolation")) {
1369 bool isHisto =
true;
1377 return (
dynamic_cast<RooAbsArg *
>(o)->getAttribute(
"density")) ?
"HistoDensity" :
"Histo";
1379 return (
dynamic_cast<RooAbsArg *
>(o)->getAttribute(
"density")) ?
"VariedDensity" :
"Varied";
1382 if (o->InheritsFrom(
"RooHistFunc"))
1383 return (
dynamic_cast<RooAbsArg *
>(o)->getAttribute(
"density")) ?
"SimpleDensity" :
"Simple";
1384 if (o->InheritsFrom(
"RooBinWidthFunction"))
1386 if (o->InheritsFrom(
"ParamHistFunc"))
1388 if (o->InheritsFrom(
"RooRealVar"))
1390 if (o->InheritsFrom(
"RooConstVar"))
1398 xRooNode out(
".coords",
nullptr, *
this);
1400 auto _p = std::shared_ptr<xRooNode>(
const_cast<xRooNode *
>(
this), [](
xRooNode *) {});
1431 if (
pos > 0 && pName(
pos - 1) ==
'<') {
1436 pName = pName(0, pName.
Index(
'<'));
1439 _obs->setVal((high + low) / 2.);
1441 _obs->setStringAttribute(
1442 "coordRange",
"coordRange");
1444 out.emplace_back(std::make_shared<xRooNode>(_obs->GetName(), _obs, _p));
1449 }
else if (
auto _obs = _p->getObject<
RooAbsArg>(pName(0,
pos)); _obs) {
1452 _cat->setLabel(pName(
pos + 1, pName.
Length()));
1453 }
else if (
auto _var =
dynamic_cast<RooAbsRealLValue *
>(_obs.get()); _var) {
1457 out.emplace_back(std::make_shared<xRooNode>(_obs->GetName(), _obs, _p));
1459 throw std::runtime_error(
"Unknown observable, could not find");
1471 }
catch (
const std::exception &
e) {
1480 }
catch (
const std::exception &
e) {
1489 if (strcmp(
GetName(),
".poi") == 0) {
1495 throw std::runtime_error(
TString::Format(
"%s is not a poi", toRemove.GetName()));
1497 toRemove.get<
RooAbsArg>()->setAttribute(
"poi",
false);
1500 }
else if (strcmp(
GetName(),
".factors") == 0 || strcmp(
GetName(),
".constraints") == 0 ||
1501 strcmp(
GetName(),
".components") == 0) {
1507 pdf = p->pdfList().find(child.
GetName());
1510 auto i = p->pdfList().index(*pdf);
1512#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
1514#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
1515 p->_pdfNSetList.erase(p->_pdfNSetList.begin() + i);
1517 auto nset = p->_pdfNSetList.At(i);
1518 p->_pdfNSetList.Remove(nset);
1521 if (p->_extendedIndex == i)
1522 p->_extendedIndex = -1;
1523 else if (p->_extendedIndex > i)
1524 p->_extendedIndex--;
1536 arg = p2->components().find(child.
GetName());
1540#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
1541 p2->_compRSet.remove(*arg);
1545 p2->removeServer(*arg,
true);
1550 bool removed =
false;
1553 c->constraints().Remove(toRemove);
1555 }
catch (std::runtime_error &) {
1565 arg = p4->funcList().find(child.
GetName());
1569 auto idx = p4->funcList().index(arg);
1574 p4->removeServer(*arg,
true);
1576 std::vector<RooAbsArg *> _coefs;
1577 for (
size_t ii = 0; ii < const_cast<RooArgList &>(p4->coefList()).size(); ii++) {
1578 if (ii !=
size_t(idx))
1579 _coefs.push_back(
const_cast<RooArgList &
>(p4->coefList()).
at(ii));
1582 for (
auto &
a : _coefs)
1593 arg = p5->pdfList().find(child.
GetName());
1597 auto idx = p5->pdfList().index(arg);
1602 p5->removeServer(*arg,
true);
1604 std::vector<RooAbsArg *> _coefs;
1605 for (
size_t ii = 0; ii < const_cast<RooArgList &>(p5->coefList()).size(); ii++) {
1606 if (ii !=
size_t(idx))
1607 _coefs.push_back(
const_cast<RooArgList &
>(p5->coefList()).
at(ii));
1610 for (
auto &
a : _coefs)
1621 arg = p6->list().find(child.
GetName());
1626 p6->removeServer(*arg,
true);
1634 auto arg = w->components().find(child.
GetName());
1641 if (arg->hasClients()) {
1642 throw std::runtime_error(
1643 TString::Format(
"Cannot remove %s from workspace %s, because it has dependencies - first remove from those",
1655 throw std::runtime_error(
"Removal not implemented for object type " +
1665 ~AutoUpdater() {
n.browse(); }
1668 AutoUpdater xxx(*
this);
1671 bool considerType(sOpt ==
"+");
1676 return fParent->Add(child, opt);
1687 if (strcmp(
GetName(),
".factors") == 0) {
1689 return fParent->Multiply(child, opt);
1690 }
else if (strcmp(
GetName(),
".components") == 0) {
1692 return fParent->Add(child, opt);
1693 }
else if (strcmp(
GetName(),
".variations") == 0) {
1696 }
else if (strcmp(
GetName(),
".constraints") == 0) {
1698 return fParent->Constrain(child);
1702 }
else if ((strcmp(
GetName(),
".globs") == 0)) {
1705 out->setAttribute(
"obs");
1706 out->setAttribute(
"global");
1709 throw std::runtime_error(
"Failed to add global observable");
1710 }
else if ((strcmp(
GetName(),
".poi") == 0)) {
1713 out->setAttribute(
"poi");
1717 auto res =
fParent->Add(child);
1721 throw std::runtime_error(
"Failed to add parameter of interest");
1728 }
else if (strcmp(
GetName(),
".datasets()") == 0) {
1731 if (
find(_data->GetName())) {
1732 throw std::runtime_error(
TString::Format(
"Cannot add dataset %s, already exists for %s. If intending to "
1733 "combine datasets, please add directly to dataset",
1743 throw std::runtime_error(
1744 "Datasets can only be created for pdfs or workspaces (except if generated dataset, then must be pdf)");
1747 if (sOpt ==
"asimov" || sOpt ==
"toy") {
1749 auto _fr =
fParent->fitResult();
1750 if (strlen(_fr->GetName()) == 0) {
1753 auto ds =
fParent->generate(_fr, sOpt ==
"asimov");
1754 if (strlen(child.
GetName())) {
1765 }
else if (!_ws->obj(_fr->GetName())) {
1771 auto parentObs =
fParent->obs();
1772 auto _obs = parentObs.argList();
1774 std::unique_ptr<RooAbsCollection> _globs(_obs.selectByAttrib(
"global",
true));
1776 _obs.remove(*_globs);
1781 if (
auto ax =
GetXaxis(); ax &&
dynamic_cast<RooAbsArg *
>(ax->GetParent())->getAttribute(
"obs")) {
1782 _obs.add(*
dynamic_cast<RooAbsArg *
>(ax->GetParent()));
1785 if (
auto _d = _ws->data(child.
GetName()); _d) {
1788 l.remove(*_d->get(),
true,
true);
1792 throw std::runtime_error(
"Cannot extend dataset with new columns");
1803 if (
auto __d = _ws->data(child.
GetName()))
1804 __d->SetBit(1 << 20, _ws->allData().size() == 1);
1812 auto out = std::shared_ptr<TObject>(_ws->data(child.
GetName()), [](
TObject *) {});
1821 throw std::runtime_error(
"Cannot create dataset");
1826 throw std::runtime_error(
"Cannot add to null object with no parentage");
1828 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(child), [](
TObject *) {}));
1833 std::rethrow_exception(std::current_exception());
1838 throw std::runtime_error(
"No object");
1844 bb->Add(child, opt);
1848 throw std::runtime_error(
"Can only add datasets to a dataset");
1853 auto _globs =
globs();
1854 for (
auto &glob : child.
globs()) {
1855 if (
auto g = _globs.find(glob->GetName()); !
g) {
1857 }
else if (
g->GetContent() != glob->GetContent()) {
1858 Warning(
"Add",
"Global observable %s=%g in dataset %s mismatches %s value %g ... ignoring latter",
1859 g->GetName(),
g->GetContent(),
GetName(), child.
GetName(), glob->GetContent());
1863 if (
auto _dglobs = p->getGlobalObservables()) {
1866 for (
auto g : _globs)
1869 p->setGlobalObservables(globsToAdd);
1873 std::set<std::pair<RooAbsCategory *, RooCategory *>> cats;
1875 for (
auto col : *_data->get()) {
1876 if (!p->get()->contains(*col)) {
1877 ds->addColumn(*col);
1882 throw std::runtime_error(
1883 TString::Format(
"unexpected type for regular observable: %s", col->GetName()));
1885 bool iMatches =
true;
1886 for (
const auto &nameIdx : *
c) {
1887 if (!
c2->hasLabel(nameIdx.first) && !
c2->hasIndex(nameIdx.second)) {
1889 c2->defineType(nameIdx.first, nameIdx.second);
1890 }
else if (
c2->lookupIndex(nameIdx.first) != nameIdx.second) {
1896 cats.insert({
c,
c2});
1903 for (
int i = 0; i < _data->numEntries(); i++) {
1904 auto row = _data->get(i);
1905 auto w = _data->weight();
1906 ds->get()->assign(*row);
1907 for (
auto [
c,
c2] : cats) {
1908 c2->setLabel(row->getCatLabel(
c->GetName()));
1910 ds->add(*ds->get(), w);
1914 ds->SetTitle(
TString(ds->GetTitle()) +
" + " + _data->GetTitle());
1919 if(
auto _ds =
dynamic_cast<RooDataSet*
>(p); _arg && _ds) {
1921 _ds->addColumn(*_arg);
1922 _arg->setAttribute(
"obs");
1925 auto _h = child.
get<
TH1>();
1927 throw std::runtime_error(
"Can only add histogram or var/expr or dataset to data");
1931 throw std::runtime_error(
"Could not find pdf");
1932 auto _ax = _pdf->GetXaxis();
1934 throw std::runtime_error(
"Cannot determine binning to add data");
1943 l.remove(*p->get(),
true,
true);
1947 throw std::runtime_error(
"Cannot extend dataset with new columns");
1954 for (
auto &o :
obs) {
1956 if (
auto dv =
dynamic_cast<RooRealVar *
>(p->get()->find(
v->GetName())); dv) {
1957 if (
v->getMin() < dv->getMin())
1958 dv->setMin(
v->getMin());
1959 if (
v->getMax() > dv->getMax())
1960 dv->setMax(
v->getMax());
1963 if (
auto dc =
dynamic_cast<RooCategory *
>(p->get()->find(
c->GetName())); dc) {
1964 for (
const auto &nameIdx : *
c) {
1965 if (!dc->hasLabel(nameIdx.first)) {
1966 dc->defineType(nameIdx.first, nameIdx.second);
1973 for (
int i = 1; i <= _h->GetNbinsX(); i++) {
1975 if (!_h->GetXaxis()->GetBinLabel(i)) {
1976 throw std::runtime_error(
1977 TString::Format(
"Categorical observable %s requires bin labels", _ax->GetParent()->GetName()));
1978 }
else if (!cat->hasLabel(_h->GetXaxis()->GetBinLabel(i))) {
1979 throw std::runtime_error(
TString::Format(
"Categorical observable %s does not have label %s",
1980 _ax->GetParent()->GetName(), _h->GetXaxis()->GetBinLabel(i)));
1982 cat->setLabel(_h->GetXaxis()->GetBinLabel(i));
1987 p->add(
obs, _h->GetBinContent(i));
1994 auto cc = child.
fComp;
2000 auto _pdf = std::dynamic_pointer_cast<RooAbsPdf>(out);
2002 throw std::runtime_error(
"Something went wrong with pdf acquisition");
2009 if (
auto _boundaries = std::unique_ptr<std::list<double>>(_p->binBoundaries(
2010 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
2011 std::numeric_limits<double>::infinity()));
2012 !_boundaries && _ax->GetNbins() > 0) {
2013#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
2014 Warning(
"Add",
"Adding unbinned pdf %s to binned %s - will wrap with RooBinSamplingPdf(...)",
2018 _p->setStringAttribute(
"alias", std::dynamic_pointer_cast<RooAbsArg>(out)->getStringAttribute(
"alias"));
2019 if (!_p->getStringAttribute(
"alias"))
2020 _p->setStringAttribute(
"alias", out->GetName());
2022 throw std::runtime_error(
2023 "unsupported addition of unbinned pdf to binned model - please upgrade to at least ROOT 6.24");
2029 if (!(_pdf->canBeExtended() && p->coefList().empty())) {
2033 if (_pdf->canBeExtended()) {
2035 std::cout <<
" warning " << _pdf->GetName() <<
" wont be correctly normalized" << std::endl;
2045 for (
auto i = p->coefList().size(); i < p->pdfList().
size(); i++) {
2049 TString::Format(
"Expected Events of %s", p->pdfList().at(i)->GetTitle()),
2050 *
static_cast<RooAbsPdf *
>(p->pdfList().at(i))));
2056 *
reinterpret_cast<bool *
>(
reinterpret_cast<unsigned char *
>(p) +
2057 p->Class()->GetDataMemberOffset(
"_allExtendable")) =
false;
2058 *
reinterpret_cast<bool *
>(
reinterpret_cast<unsigned char *
>(p) +
2059 p->Class()->GetDataMemberOffset(
"_haveLastCoef")) =
true;
2068 bool tooMany(
false);
2080 return xRooNode(*_pdf, *
this).Add(child);
2081 }
else if (!tooMany) {
2086 _sumpdf.get<
RooAbsArg>()->setStringAttribute(
"alias",
"samples");
2087 return _sumpdf.Add(child);
2093 std::shared_ptr<TObject> out;
2094 auto cc = child.
fComp;
2098 if (std::dynamic_pointer_cast<TH1>(cc) && !
TString(cc->GetOption()).
Contains(
"nostyle")) {
2099 xRooNode(out, *
this).styles(cc.get());
2103 Info(
"Add",
"Adding existing function %s to %s", child.
GetName(), p->GetName());
2107 if (!out && !child.
fComp) {
2108 std::shared_ptr<RooAbsArg> _func;
2116 std::unique_ptr<TH1D>
h;
2119 h = std::make_unique<TH1D>(child.
GetName(), child.
GetTitle(), _ax->GetNbins(),
2120 _ax->binning()->array());
2122 h->GetXaxis()->SetName(
TString::Format(
"%s;%s", _ax->GetParent()->GetName(), _ax->GetName()));
2124 _func = std::dynamic_pointer_cast<RooAbsArg>(
acquire(
xRooNode(*h).convertForAcquisition(*
this)));
2125 }
else if (_obs.size() == 1) {
2129 TString binningName = p->getStringAttribute(
"binning");
2130 for (
auto &
b : _bnames) {
2131 if (
b == p->GetName()) {
2132 binningName = p->GetName();
2136 std::unique_ptr<TH1D>
h;
2139 h = std::make_unique<TH1D>(child.
GetName(), child.
GetTitle(), _x->numBins(binningName),
2140 _x->getBinningPtr(binningName)->array());
2142 h->GetXaxis()->SetName(
2145 _func = std::dynamic_pointer_cast<RooAbsArg>(
acquire(
xRooNode(*h).convertForAcquisition(*
this)));
2146 Info(
"Add",
"Created SimpleDensity factor %s (xaxis=%s) for %s", _func->GetName(), _obs.at(0)->GetName(),
2149 throw std::runtime_error(
"Unsupported creation of new component in SumPdf for this many obs");
2155 _func->setStringAttribute(
"alias", child.
GetName());
2159 if (
auto _f = std::dynamic_pointer_cast<RooHistFunc>(
2163 _f->setAttribute(
"density");
2164 if (_f->getAttribute(
"autodensity")) {
2166 for (
int i = 0; i < _f->dataHist().numEntries(); i++) {
2167 auto bin_pars = _f->dataHist().get(i);
2168 _f->dataHist().set(*bin_pars, _f->dataHist().weight(i) / _f->dataHist().binVolume(*bin_pars));
2170 _f->setAttribute(
"autodensity",
false);
2171 _f->setValueDirty();
2180 Info(
"Add",
"Created %s factor RooHistFunc::%s for %s",
2181 _f->getAttribute(
"density") ?
"SimpleDensity" :
"Simple", _f->GetName(), p->GetName());
2185 if (
auto _p = std::dynamic_pointer_cast<RooAbsPdf>(out); _p) {
2189 TString newName(p->GetName());
2191 newName +=
"_components";
2192 Warning(
"Add",
"converting samples to components");
2197 if (
auto _boundaries = std::unique_ptr<std::list<double>>(_p->binBoundaries(
2198 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
2199 std::numeric_limits<double>::infinity()));
2200 !_boundaries && _ax->GetNbins() > 0) {
2201#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
2202 Warning(
"Add",
"Adding unbinned pdf %s to binned %s - will wrap with RooBinSamplingPdf(...)",
2206 _p->setStringAttribute(
"alias", std::dynamic_pointer_cast<RooAbsArg>(out)->getStringAttribute(
"alias"));
2207 if (!_p->getStringAttribute(
"alias"))
2208 _p->setStringAttribute(
"alias", out->GetName());
2210 throw std::runtime_error(
2211 "unsupported addition of unbinned pdf to binned model - please upgrade to at least ROOT 6.24");
2218 if (!_p->canBeExtended()) {
2227 if (
auto _f = std::dynamic_pointer_cast<RooAbsReal>(out); _f) {
2236 if (
auto _boundaries = std::unique_ptr<std::list<double>>(_f->binBoundaries(
2237 *
dynamic_cast<RooAbsRealLValue *
>(_ax->GetParent()), -std::numeric_limits<double>::infinity(),
2238 std::numeric_limits<double>::infinity()));
2239 !_boundaries && _ax->GetNbins() > 0) {
2240#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 24, 00)
2243 "Adding unbinned function %s to binned %s - will wrap with RooRealSumPdf(RooBinSamplingPdf(...))",
2247 sumPdf->setStringAttribute(
"alias", _f->getStringAttribute(
"alias"));
2248 if (!sumPdf->getStringAttribute(
"alias"))
2249 sumPdf->setStringAttribute(
"alias", out->GetName());
2252 _f->setStringAttribute(
"alias", std::dynamic_pointer_cast<RooAbsArg>(out)->getStringAttribute(
"alias"));
2253 if (!_f->getStringAttribute(
"alias"))
2254 _f->setStringAttribute(
"alias", out->GetName());
2256 throw std::runtime_error(
2257 "unsupported addition of unbinned function to binned model - please upgrade to at least ROOT 6.24");
2265 if (!p->getStringAttribute(
"binning"))
2266 p->setStringAttribute(
"binning", _f->getStringAttribute(
"binning"));
2269 if (
auto gf = p->getStringAttribute(
"global_factors"); gf) {
2274 throw std::runtime_error(
TString::Format(
"Could not find global factor %s", pattern.
Data()));
2283 p->setStringAttribute(
"xvar",
nullptr);
2295 bool tooMany(
false);
2307 return xRooNode(*_pdf, *
this).Add(child);
2308 }
else if (!tooMany) {
2309 auto out = this->
operator[](
"components")->Add(child);
2317 bool tooMany(
false);
2326 }
else if (
auto _p2 =
pp->get<
RooAddPdf>(); _p2) {
2328 for (
auto &_pdfa :
pp->components()) {
2341 return xRooNode(*_pdf, *
this).Add(child);
2342 }
else if (_backup) {
2344 return xRooNode(*_backup, *
this).Add(child);
2345 }
else if (!tooMany) {
2346 auto out = this->
operator[](
"samples")->Add(child);
2349 p2->setStringAttribute(
"xvar",
nullptr);
2363 *
this, child.
get() ?
"" :
"func" );
2367 if (!w->import(*_d)) {
2370 std::unique_ptr<RooAbsCollection>(w->allVars().selectCommon(*_d->get()))->setAttribAll(
"obs");
2372 if (_d->getGlobalObservables()) {
2373 std::unique_ptr<RooAbsCollection>
globs(w->allVars().selectCommon(*_d->getGlobalObservables()));
2374 globs->setAttribAll(
"obs");
2375 globs->setAttribAll(
"global");
2379 throw std::runtime_error(
2390 if (!child.empty() || child.
fFolder ==
"!pdfs") {
2393 std::string catName =
"channelCat";
2394 if (!child.empty()) {
2395 if (
TString ss = child.
at(0)->GetName(); ss.Contains(
"=")) {
2396 catName = ss(0, ss.Index(
'='));
2400 _cat->setAttribute(
"obs");
2402 Info(
"Add",
"Created pdf RooSimultaneous::%s in workspace %s", out->GetName(), w->GetName());
2406 if (coll->isOwning()) {
2408 }
else if (child.
ws() !=
ws()) {
2416 if (sOpt ==
"pdf") {
2422 }
else if (sOpt ==
"channel") {
2427 std::shared_ptr<TObject> out;
2431 }
else if (!child.
fComp) {
2434 Info(
"Add",
"Created channel RooProdPdf::%s in workspace %s", out->GetName(),
get()->
GetName());
2438 }
else if (sOpt ==
"sample" || sOpt ==
"func") {
2442 return _mainChild.Add(child, sOpt ==
"func" ?
"func" :
"");
2444 return (*
this)[
"samples"]->Add(child, sOpt ==
"func" ?
"func" :
"");
2447 }
else if (sOpt ==
"dataset") {
2450 return (*this).datasets().Add(child);
2508 a->setAttribute(
"hidden",
set);
2519 return a->getAttribute(
"hidden");
2526 if (
get() == rhs.
get()) {
2538 std::set<std::string> pdfs;
2540 if ((*
this)[
"pdfs"]->
find(
c->GetName())) {
2541 pdfs.insert(
c->GetName());
2545 Warning(
"Combine",
"No pdfs will be combined. Please check and/or rename pdfs to match");
2547 std::stringstream s;
2548 for (
auto &p : pdfs)
2550 Info(
"Combine",
"pdfs that will be combined: %s", s.str().c_str());
2553 std::set<std::string> _np;
2555 for (
auto &
c : rhs.
np()) {
2556 if (mynp.find(
c->GetName())) {
2557 _np.insert(
c->GetName());
2561 Warning(
"Combine",
"No correlated np");
2563 std::stringstream s;
2566 Info(
"Combine",
"np that will be shared (correlated): %s", s.str().c_str());
2568 std::set<std::string> _poi;
2570 for (
auto &
c : rhs.
poi()) {
2571 if (mypoi.find(
c->GetName())) {
2572 _poi.insert(
c->GetName());
2576 Warning(
"Combine",
"No correlated poi");
2578 std::stringstream s;
2579 for (
auto &p : _poi)
2581 Info(
"Combine",
"poi that will be shared (correlated): %s", s.str().c_str());
2600 (
c->fFolder ==
"!scratch" ||
c->fFolder ==
"!sets" ||
c->fFolder ==
"!snapshots" ||
c->fFolder ==
"!models"))
2604 Info(
"Combine",
"Combining %s into %s",
c->GetPath().c_str(),
_c->GetPath().c_str());
2606 _c->Combine(*
c,
true);
2610 Info(
"Combine",
"Adding %s into %s",
c->GetPath().c_str(),
GetPath().c_str());
2613 }
catch (std::exception &
e) {
2614 Warning(
"Combine",
"Could not combine %s into %s",
c->GetPath().c_str(),
GetPath().c_str());
2623 Info(
"Combine",
"Combining %s into %s",
f->GetPath().c_str(), _f->GetPath().c_str());
2625 _f->Combine(*
f,
true);
2628 Info(
"Combine",
"Multiplying %s into %s",
f->GetPath().c_str(),
GetPath().c_str());
2637 if (
c->fFolder ==
"!sets") {
2639 Info(
"Combine",
"Extending set %s",
c->GetName());
2642 Info(
"Combine",
"Defining set %s",
c->GetName());
2652 Info(
"Combine",
"Combining %s into %s", ds->GetPath().c_str(), _ds->GetPath().c_str());
2657 Info(
"Combine",
"Adding %s into %s", ds->GetPath().c_str(),
GetPath().c_str());
2667 Info(
"Combine",
"Combining variation %s into %s",
v->GetPath().c_str(), _v->GetPath().c_str());
2669 _v->Combine(*
v,
true);
2672 Info(
"Combine",
"Varying %s into %s",
v->GetPath().c_str(),
GetPath().c_str());
2680 for (
auto &
b : rhs.
bins()) {
2681 if (
auto _b =
bins().
find(
b->GetName()); _b) {
2682 Info(
"Combine",
"Combining %s into %s",
b->GetPath().c_str(), _b->GetPath().c_str());
2683 _b->Combine(*
b,
true);
2685 Info(
"Combine",
"Extending with %s into %s",
b->GetPath().c_str(),
GetPath().c_str());
2710 auto chans =
bins();
2711 if (!chans.empty()) {
2717 for (
auto &
c : chans) {
2719 cName = cName(cName.
Index(
'=') + 1, cName.
Length());
2722 c->shallowCopy(
name +
"_" +
c->get()->GetName(), std::shared_ptr<xRooNode>(&out, [](
xRooNode *) {}));
2723 pdf->addPdf(*
dynamic_cast<RooAbsPdf *
>(c_copy.get()), cName);
2728 }
else if (
auto p =
dynamic_cast<RooProdPdf *
>(o); p) {
2730 std::shared_ptr<RooProdPdf> pdf =
2731 std::dynamic_pointer_cast<RooProdPdf>(out.
acquire(std::shared_ptr<TObject>(p->Clone()),
false,
2736 std::dynamic_pointer_cast<RooAbsArg>(out.
acquire(std::shared_ptr<TObject>(
main->Clone()),
false,
true));
2737 std::cout << newMain <<
" " << newMain->GetName() << std::endl;
2752 static std::unique_ptr<cout_redirect> capture;
2753 std::string captureStr;
2754 bool doCapture =
false;
2755 if (!capture &&
gROOT->FromPopUp()) {
2756 capture = std::make_unique<cout_redirect>(captureStr);
2779 if (
get() &&
get() !=
this) {
2784 auto _snap = std::unique_ptr<RooAbsCollection>(_deps.snapshot());
2788 std::cout <<
"Minimization Logs:" << std::endl;
2789 std::cout << dynamic_cast<RooStringVar *>(_fr->constPars().find(
".log"))->getVal() << std::endl;
2791 _deps.assignValueOnly(*_snap);
2803 for (
size_t i = 0; i < fv->dependents().
size(); i++) {
2809 for (
size_t i = 0; i < gv->dependents().
size(); i++) {
2815 std::set<int> interpCodes;
2816 for(
auto&
c : pi->interpolationCodes()) interpCodes.insert(
c);
2817 if(interpCodes.size()==1) { _suffix +=
TString::Format(
" [InterpCode=%d]",*interpCodes.begin()); }
2820 std::set<int> interpCodes;
2821 for(
auto&
c : fiv->interpolationCodes()) interpCodes.insert(
c==4 ? 5 :
c);
2822 if(interpCodes.size()==1) { _suffix +=
TString::Format(
" [InterpCode=%d]",*interpCodes.begin()); }
2827 }
else if (!
get()) {
2828 std::cout << std::endl;
2832 std::vector<std::string> folderNames;
2833 for (
auto &k : *
this) {
2834 if (std::find(folderNames.begin(), folderNames.end(), k->fFolder) == folderNames.end()) {
2835 folderNames.push_back(k->fFolder);
2838 for (
auto &
f : folderNames) {
2842 for (
int j = 0; j <
indent; j++)
2844 std::cout <<
f << std::endl;
2847 for (
auto &k : *
this) {
2848 if (k->fFolder !=
f) {
2852 for (
int j = 0; j < iindent; j++)
2854 std::cout << i++ <<
") " << k->GetName() <<
" : ";
2858 auto _deps = k->coords(
false).argList();
2859 auto _snap = std::unique_ptr<RooAbsCollection>(_deps.snapshot());
2861 k->get()->Print(sOpt);
2862 _deps.assignValueOnly(*_snap);
2865 if (
auto _type = k->GetNodeType(); strlen(_type)) {
2873 for (
size_t j = 0; j < fv->dependents().
size(); j++) {
2879 for (
size_t j = 0; j < gv->dependents().
size(); j++) {
2885 std::set<int> interpCodes;
2886 for(
auto&
c : pi->interpolationCodes()) interpCodes.insert(
c);
2887 if(interpCodes.size()==1) { _suffix +=
TString::Format(
" [InterpCode=%d]",*interpCodes.begin()); }
2890 std::set<int> interpCodes;
2891 for(
auto&
c : fiv->interpolationCodes()) interpCodes.insert(
c==4 ? 5 :
c);
2892 if(interpCodes.size()==1) { _suffix +=
TString::Format(
" [InterpCode=%d]",*interpCodes.begin()); }
2894 std::cout << k->get()->ClassName() <<
"::" << k->get()->GetName() << _suffix.
Data() << std::endl;
2897 k->Print(sOpt +
TString::Format(
"depth=%dindent=%d", depth - 1, iindent + 1));
2900 std::cout <<
" NULL " << std::endl;
2906 size_t lastBreak = 0;
2907 std::string captureStrWithBreaks;
2908 for (
size_t i = 0; i < captureStr.size(); i++) {
2909 captureStrWithBreaks += captureStr[i];
2910 if (captureStr[i] ==
'\n') {
2913 if (i - lastBreak > 150) {
2914 captureStrWithBreaks +=
'\n';
2919 (
gROOT->GetListOfBrowsers()->At(0))
2920 ?
dynamic_cast<TGWindow *
>(
static_cast<TBrowser *
>(
gROOT->GetListOfBrowsers()->At(0))->GetBrowserImp())
2923 captureStrWithBreaks.c_str());
2934 double mean = std::numeric_limits<double>::quiet_NaN();
2935 double sigma = mean;
2944 mean = std::numeric_limits<double>::quiet_NaN();
2947 constrType =
"normal";
2948 }
else if (constrType ==
"normal") {
2951 }
else if (constrType ==
"gaussian") {
2955 throw std::runtime_error(
"No error on parameter for gaussian constraint");
2958 constrType =
"normal";
2959 }
else if (constrType ==
"poisson") {
2961 throw std::runtime_error(
"No error on parameter for poisson constraint");
2963 sigma = pow(
v->getVal() /
v->getError(), 2);
2966 if (constrType ==
"poisson") {
2968 double tau_val =
sigma;
2970 v->getVal() * tau_val, (
v->getVal() - 5 *
v->getError()) * tau_val,
2971 (
v->getVal() + 5 *
v->getError()) * tau_val);
2972 globs->setConstant();
2973 globs->setAttribute(
"obs");
2974 globs->setAttribute(
"global");
2986 v->setError(mean / sqrt(tau_val));
2987 Info(
"Constrain",
"Added poisson constraint pdf RooPoisson::%s (tau=%g) for %s", out->GetName(), tau_val,
2990 }
else if (constrType ==
"normal") {
2994 globs->setAttribute(
"obs");
2995 globs->setAttribute(
"global");
2996 globs->setConstant();
3005 Info(
"Constrain",
"Added gaussian constraint pdf RooGaussian::%s (mean=%g,sigma=%g) for %s", out->GetName(),
3014 throw std::runtime_error(
"Cannot constrain non arg");
3017 if (!p->dependsOn(*_me)) {
3018 throw std::runtime_error(
"Constraint does not depend on constrainee");
3027 throw std::runtime_error(
"Nowhere to put constraint");
3030 auto childGlobs = child.
globs();
3031 if (!childGlobs.empty()) {
3032 for (
auto d :
x->datasets()) {
3036 d->get<
RooAbsData>()->setGlobalObservables(newGlobs);
3042 if (k ==
"globalObservables" ||
TString(k).
EndsWith(
"_GlobalObservables")) {
3051 for (
auto &
c : *
x) {
3057 return x->Multiply(child);
3059 return x->Add(child,
"+");
3072 ~AutoUpdater() {
n.browse(); }
3075 AutoUpdater xxx(*
this);
3082 auto o = std::dynamic_pointer_cast<RooAbsReal>(
acquire(child.
fComp));
3095 binFactors =
xRooNode(*c).factors().find(
"binFactors");
3105 ?
fParent->mainChild()->GetName()
3109 .SetName(
"binFactors");
3110 binFactors =
fParent->factors().find(
"binFactors");
3112 throw std::runtime_error(
3119 for (
auto &
b : binFactors->bins()) {
3122 p->setStringAttribute(
"alias",
TString::Format(
"%s=%g", binFactors->GetXaxis()->GetParent()->GetName(),
3123 binFactors->GetXaxis()->GetBinCenter(i)));
3130 auto _bin = binFactors->bins().at(
fBinNumber - 1);
3131 if (
auto phf = binFactors->get<
ParamHistFunc>(); phf && _bin) {
3132#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3137 if (strcmp(_bin->GetName(),
"1") == 0) {
3139 for (std::size_t i = 0; i < pSet.
size(); i++) {
3141 all.
add(*pSet.
at(i));
3149 _bin->fBinNumber = -1;
3150 return _bin->Multiply(child, opt);
3178 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(child), [](
TObject *) {}));
3183 std::rethrow_exception(std::current_exception());
3195 Info(
"Multiply",
"Scaled %s by existing factor %s::%s",
3199 }
else if (sOpt ==
"const") {
3202 Info(
"Multiply",
"Scaled %s by new const factor %s",
3206 }
else if (sOpt ==
"norm") {
3213 Info(
"Multiply",
"Scaled %s by new norm factor %s",
3222 Info(
"Multiply",
"Scaled %s by new norm factor %s",
3226 }
else if (sOpt ==
"shape" || sOpt ==
"simple" || sOpt ==
"blankshape") {
3231 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
3232 h->SetBinContent(i, 1);
3242 Info(
"Multiply",
"Scaled %s by new %s factor %s",
3247 }
else if (sOpt ==
"overall") {
3251 Info(
"Multiply",
"Scaled %s by new overall factor %s",
3255 }
else if (sOpt ==
"func" &&
ws()) {
3260 Info(
"Multiply",
"Scaled %s by new func factor %s",
3267 if (
auto h = child.
get<
TH1>();
h && strlen(
h->GetOption()) == 0 && strlen(opt) > 0) {
3273 std::shared_ptr<TObject> out;
3280 if (strcmp(
GetName(),
".coef") == 0) {
3285 if (p->coefList().empty() && !p->pdfList().empty()) {
3286 for (
auto _pdf : p->pdfList()) {
3292 Info(
"Multiply",
"Created RooExtendedBinding coefficients for all pdfs of %s so that can multiply coef",
3294 *
reinterpret_cast<bool *
>(
reinterpret_cast<unsigned char *
>(p) +
3295 p->Class()->GetDataMemberOffset(
"_allExtendable")) =
false;
3296 *
reinterpret_cast<bool *
>(
reinterpret_cast<unsigned char *
>(p) +
3297 p->Class()->GetDataMemberOffset(
"_haveLastCoef")) =
true;
3299 for (
size_t i = 0; i < p->pdfList().
size(); i++) {
3301 auto coefs = p->coefList().at(i);
3302 if (!
coefs->InheritsFrom(
"RooProduct")) {
3304 if (!(strcmp(
coefs->GetName(),
"1") == 0 || strcmp(
coefs->GetName(),
"ONE") == 0))
3310 for (
size_t j = 0; j < p->coefList().
size(); j++) {
3312 oldCoefs.add(*newCoefs);
3314 oldCoefs.add(*p->coefList().at(j));
3319 coefs = newCoefs.get();
3327 for (
size_t i = 0; i < p2->funcList().
size(); i++) {
3329 auto coefs = p2->coefList().at(i);
3330 if (!
coefs->InheritsFrom(
"RooProduct")) {
3332 if (!(strcmp(
coefs->GetName(),
"1") == 0 || strcmp(
coefs->GetName(),
"ONE") == 0))
3338 for (
size_t j = 0; j < p2->coefList().
size(); j++) {
3340 oldCoefs.add(*newCoefs);
3342 oldCoefs.add(*p2->coefList().at(j));
3347 coefs = newCoefs.get();
3353 throw std::runtime_error(
"this coefs case is not supported");
3357 std::shared_ptr<TObject> out;
3358 auto cc = child.
fComp;
3364 if (
auto _f = std::dynamic_pointer_cast<RooHistFunc>(
3366 _f && _f->getAttribute(
"autodensity")) {
3368 bool hasDensity =
false;
3376 if (_f->getAttribute(
"density")) {
3379 for (
int i = 0; i < _f->dataHist().numEntries(); i++) {
3380 auto bin_pars = _f->dataHist().get(i);
3381 _f->dataHist().set(*bin_pars, _f->dataHist().weight(i) / _f->dataHist().binVolume(*bin_pars));
3383 _f->setValueDirty();
3390 _f->setAttribute(
"autodensity",
false);
3394 Info(
"Multiply",
"Created %s factor %s in %s",
3398 Info(
"Multiply",
"Created Shape factor %s in %s", child->
GetName(), p->GetName());
3401 if (
auto _f = std::dynamic_pointer_cast<RooAbsReal>(out); _f) {
3402#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3403 p->_compRSet.add(*_f);
3411 for (
auto &_par : _out.
pars()) {
3414 for (
auto &_constr : _par->constraints()) {
3415 if (strcmp(s, _constr->get()->GetName()) == 0) {
3422 Info(
"Multiply",
"Pulling in %s boundConstraint: %s", _par->GetName(), s);
3425 throw std::runtime_error(
"Couldn't find boundConstraint");
3427 _par->Constrain(_pdf);
3436 std::shared_ptr<TObject> out;
3446 std::shared_ptr<RooAbsPdf> _pdf;
3447 if (!child.
get() && strcmp(child.
GetName(),
"components") == 0) {
3460 _sumpdf->setFloor(
true);
3463 _pdf->setStringAttribute(
"alias", child.
GetName());
3465 _pdf->setStringAttribute(
"xvar", p2->getStringAttribute(
"xvar"));
3466 _pdf->setStringAttribute(
"binning", p2->getStringAttribute(
"binning"));
3468 Info(
"Multiply",
"Created %s::%s in channel %s", _pdf->ClassName(), _pdf->GetName(), p2->GetName());
3473 if (
auto _pdf = std::dynamic_pointer_cast<RooAbsPdf>(out); _pdf) {
3474#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3476#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
3477 p2->_pdfNSetList.emplace_back(std::make_unique<RooArgSet>(
"nset"));
3479 p->_pdfNSetList.Add(
new RooArgSet(
"nset"));
3481 if (!p2->canBeExtended() && _pdf->canBeExtended()) {
3482 p2->_extendedIndex = p2->_pdfList.size() - 1;
3493 std::shared_ptr<TObject> out;
3500 TString s = p3->getStringAttribute(
"global_factors");
3503 s += out->GetName();
3504 p3->setStringAttribute(
"global_factors", s);
3507 "Flagged %s as a global factor in channel %s (is applied to all current and future samples in the channel)",
3508 out->GetName(), p3->GetName());
3519 std::set<RooAbsArg *> cl;
3520 for (
auto &arg : p5->clients()) {
3526 if (cl.size() > 1) {
3531 Warning(
"Multiply",
"Scaling %s that has multiple clients", p5->GetName());
3537 for (
auto &
a : p5->attributes())
3538 new_p->setAttribute(
a.c_str());
3539 for (
auto &
a : p5->stringAttributes())
3540 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
3541 if (!new_p->getStringAttribute(
"alias"))
3542 new_p->setStringAttribute(
"alias", p5->GetName());
3544 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
3545 for (
auto arg : cl) {
3546 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
3554 if (!child.
get() && strlen(opt) == 0)
3557 throw std::runtime_error(
3559 (!child.
get() && strlen(opt) == 0) ?
" (forgot to specify factor type?)" :
""));
3567 throw std::runtime_error(
"Only replacement of RooAbsArg is supported");
3576 new_p = std::dynamic_pointer_cast<RooAbsArg>(out).get();
3578 std::set<RooAbsArg *> cl;
3579 for (
auto &arg : p5->clients()) {
3587 if (cl.size() > 1) {
3592 std::stringstream clientList;
3594 clientList <<
c->GetName() <<
",";
3595 Warning(
"Replace",
"Replacing %s in all clients: %s", p5->GetName(), clientList.str().c_str());
3599 new_p->setAttribute(
Form(
"ORIGNAME:%s", p5->GetName()));
3600 for (
auto arg : cl) {
3605 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
3616 ~AutoUpdater() {
n.browse(); }
3619 AutoUpdater xxx(*
this);
3624 auto _ref = emplace_back(std::shared_ptr<xRooNode>(&
const_cast<xRooNode &
>(child), [](
TObject *) {}));
3629 std::rethrow_exception(std::current_exception());
3636 return p.Vary(child);
3641 std::string label = child.
GetName();
3642 if (
auto pos = label.find(
'=');
pos != std::string::npos)
3643 label = label.substr(
pos + 1);
3644 if (!s->indexCat().hasLabel(label)) {
3649 if (
auto bb = _ds->getBrowsable(
".sourceds")) {
3652 auto dsCat = _ds->robs()[s->indexCat().GetName()]->get<
RooCategory>();
3654 throw std::runtime_error(
TString::Format(
"Failed to find %s regular observable in %s dataset",
3655 s->indexCat().GetName(), _ds->GetName()));
3663 std::shared_ptr<TObject> out;
3667 }
else if (!child.
fComp) {
3670 Info(
"Vary",
"Created channel RooProdPdf::%s in model %s", out->GetName(), s->GetName());
3673 if (
auto _pdf = std::dynamic_pointer_cast<RooAbsPdf>(out); _pdf) {
3676 std::set<RooAbsData *> dsToUpdate;
3678 if (
auto bb = _ds->getBrowsable(
".sourceds")) {
3685 if (!dsToUpdate.empty()) {
3687 _pdf->leafNodeServerList(&leafs);
3688 std::unique_ptr<RooAbsCollection> globals(leafs.
selectByAttrib(
"global",
true));
3689 for (
auto _ds : dsToUpdate) {
3692 globs.addClone(*_ds->getGlobalObservables());
3693 for (
auto &aa : *globals) {
3694 if (!
globs.contains(*aa)) {
3695 globs.addClone(*aa);
3696 alist += std::string(aa->GetName()) +
",";
3699 if (!alist.empty()) {
3700 Warning(
"Vary",
"Adding %s to global observables of %s", alist.c_str(), _ds->GetName());
3701 _ds->setGlobalObservables(
globs);
3706 s->addPdf(*_pdf, label.c_str());
3720 if (!
_c && child.
get()) {
3721 throw std::runtime_error(
"Only pure consts can be set as variations of a flexible interpvar");
3723#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3724 double value = (
_c ?
_c->getVal() : p->_nominal);
3725 double nomVal = p->_nominal;
3727 double value = (
_c ?
_c->getVal() : p->nominal());
3728 double nomVal = p->nominal();
3732 if (cName ==
"nominal") {
3733 p->setNominal(value);
3737 throw std::runtime_error(
"unsupported variation form");
3739 std::string parName = cName(0, cName.
Index(
'='));
3741 if (parVal != 1 && parVal != -1) {
3742 throw std::runtime_error(
"unsupported variation magnitude");
3744 bool high = parVal > 0;
3746 if (parName.empty()) {
3747 p->setNominal(value);
3755 if (!p->findServer(*
v)) {
3756#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3757 p->_paramList.add(*
v);
3758 p->_low.push_back(0);
3759 p->_high.push_back(0);
3760 p->_interpCode.push_back(4);
3763 const_cast<std::vector<double> &
>(p->low()).push_back(0);
3764 const_cast<std::vector<double> &
>(p->high()).push_back(0);
3765 const_cast<std::vector<int> &
>(p->interpolationCodes()).push_back(4);
3767 v->setAttribute(
Form(
"SYMMETRIC%s_%s", high ?
"+" :
"-",
GetName()));
3771 p->setHigh(*
v, value);
3772 if (
v->getAttribute(
Form(
"SYMMETRIC+_%s",
GetName()))) {
3773 p->setLow(*
v, 2 * nomVal - value);
3775 v->setAttribute(
Form(
"SYMMETRIC-_%s",
GetName()),
false);
3777 p->setLow(*
v, value);
3778 if (
v->getAttribute(
Form(
"SYMMETRIC-_%s",
GetName()))) {
3779 p->setHigh(*
v, 2 * nomVal - value);
3781 v->setAttribute(
Form(
"SYMMETRIC+_%s",
GetName()),
false);
3792 throw std::runtime_error(
"unsupported variation form");
3796 if (parVal != 1 && parVal != -1) {
3797 throw std::runtime_error(
"unsupported variation magnitude");
3799#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3802 throw std::runtime_error(
3803 TString::Format(
"Interpolating %s instead of RooHistFunc", p2->_nominal.absArg()->ClassName()));
3808 throw std::runtime_error(
3809 TString::Format(
"Interpolating %s instead of RooHistFunc", p2->nominalHist()->ClassName()));
3815 for (
auto par : p2->paramList()) {
3816 if (parName == par->GetName()) {
3817 f =
dynamic_cast<RooHistFunc *
>((parVal > 0 ? p2->highList() : p2->lowList()).at(i));
3818 otherf =
dynamic_cast<RooHistFunc *
>((parVal > 0 ? p2->lowList() : p2->highList()).at(i));
3823 if (i == p2->paramList().size() && !child.
get<
RooAbsReal>()) {
3830 std::shared_ptr<RooHistFunc> up(
3832 std::shared_ptr<RooHistFunc> down(
3835#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3836 std::unique_ptr<RooDataHist>
h1(
3837 static_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", up->GetName()))));
3838 std::unique_ptr<RooDataHist> h2(
3839 static_cast<RooDataHist *
>(
f->dataHist().Clone(
Form(
"hist_%s", down->GetName()))));
3841 down->_dataHist =
dynamic_cast<RooDataHist *
>(
f->dataHist().
Clone(
Form(
"hist_%s", down->GetName())));
3844 down->cloneAndOwnDataHist(
TString::Format(
"hist_%s", down->GetName()));
3846 auto ups = std::dynamic_pointer_cast<RooHistFunc>(
acquire(up,
false,
true));
3847 auto downs = std::dynamic_pointer_cast<RooHistFunc>(
acquire(down,
false,
true));
3848#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3849 p2->_highSet.add(*ups.get());
3850 p2->_lowSet.add(*downs.get());
3851 p2->_interpCode.push_back(4);
3852 p2->_paramSet.add(*
v);
3856 const_cast<std::vector<int> &
>(p2->interpolationCodes()).push_back(4);
3859 p2->setValueDirty();
3860 f = ((parVal > 0) ? ups : downs).
get();
3861 otherf = ((parVal > 0) ? downs : ups).
get();
3863 f->setStringAttribute(
"symmetrizes", otherf->
GetName());
3864 f->setStringAttribute(
"symmetrize_nominal", nomf->
GetName());
3883#if ROOT_VERSION_CODE > ROOT_VERSION(6, 37, 00)
3887 throw std::runtime_error(
"unsupported variation form");
3893 if (!pmr->indexCategory()->hasLabel(parVal.
Data())) {
3896 auto idx = pmr->indexCategory()->lookupIndex(parVal.
Data());
3898 throw std::runtime_error(
"Invalid index");
3904 if (pmr->getModelList().empty()) {
3905 throw std::runtime_error(
"No real function given for variation, and no nominal function to clone");
3907 _c = std::dynamic_pointer_cast<RooAbsReal>(
3908 acquire(std::shared_ptr<TObject>(pmr->getModelList().at(0)->Clone(
3912 _c->setStringAttribute(
"alias", child.
GetName());
3922 if (p3->getAttribute(
"RooRealConstant_Factory_Object")) {
3923 throw std::runtime_error(
"Cannot vary pure constants");
3929 std::set<RooAbsArg *> cl;
3930 for (
auto &arg : p3->clients()) {
3935 if (cl.size() > 1) {
3940 Warning(
"Vary",
"Varying %s that has multiple clients", p3->GetName());
3943 p3->setStringAttribute(
"origName", p3->GetName());
3945 p3->SetName(
Form(
"%s_nominal", p3->GetName()));
3948 std::vector<double>(), std::vector<double>());
3951 for (
auto &
a : p3->attributes())
3952 new_p->setAttribute(
a.c_str());
3953 for (
auto &
a : p3->stringAttributes())
3954 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
3957 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
3958 for (
auto arg : cl) {
3959 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
3969 std::set<RooAbsArg *> cl;
3970 for (
auto &arg : p4->clients()) {
3975 if (cl.size() > 1) {
3980 Warning(
"Vary",
"Varying %s that has multiple clients", p4->GetName());
3983 p4->setStringAttribute(
"origName", p4->GetName());
3985 p4->SetName(
Form(
"%s_nominal", p4->GetName()));
3987#if ROOT_VERSION_CODE > ROOT_VERSION(6, 37, 00)
3988 std::shared_ptr<RooAbsArg> new_p;
3994 if (parVal != 1 && parVal != -1) {
3998 throw std::runtime_error(
"Failed to acquire categorical index for RooMultiReal");
4001 if (idxCat->numTypes() == 0) {
4002 idxCat->defineType(
"nominal");
4004 Info(
"Vary",
"Creating a RooMultiReal with category %s", idxCat->GetName());
4006 n, p4->GetTitle(), *idxCat,
4008 const_cast<RooListProxy &
>(newFunc->getModelList()).add(*p4);
4021 for (
auto &
a : p4->attributes())
4022 new_p->setAttribute(
a.c_str());
4023 for (
auto &
a : p4->stringAttributes())
4024 new_p->setStringAttribute(
a.first.c_str(),
a.second.c_str());
4027 new_p->setAttribute(
Form(
"ORIGNAME:%s", old_p->GetName()));
4028 for (
auto arg : cl) {
4029 arg->redirectServers(
RooArgSet(*new_p),
false,
true);
4071 a->setStringAttribute(
"alias",
GetName());
4074 throw std::runtime_error(
"Cannot determine type");
4079 if (
auto h =
dynamic_cast<const TH1 *
>(&o);
h) {
4096 throw std::runtime_error(
"no xaxis");
4097 auto _v =
dynamic_cast<RooRealVar *
>(ax->GetParent());
4101 if (
h->GetXaxis()->IsVariableBinSize()) {
4102 _v->setBinning(
RooBinning(
h->GetNbinsX(),
h->GetXaxis()->GetXbins()->GetArray()));
4104 _v->setBinning(
RooUniformBinning(
h->GetXaxis()->GetXmin(),
h->GetXaxis()->GetXmax(),
h->GetNbinsX()));
4110 for (
int bin = 1; bin <=
h->GetNbinsX(); bin++) {
4118 if (!_isData &&
h->GetSumw2N() && !
SetBinError(bin,
h->GetBinError(bin)))
4119 throw std::runtime_error(
"Failed setting stat error");
4135 throw std::runtime_error(
"Assignment failed");
4165 auto _pars =
pars();
4168 std::map<RooAbsRealLValue *, double> valsToSet;
4170 auto idx = pattern.
Index(
'=');
4173 (idx == -1) ? std::numeric_limits<double>::quiet_NaN() :
TString(pattern(idx + 1, pattern.
Length())).
Atof();
4174 bool foundArg =
false;
4175 for (
auto p : _pars.argList()) {
4178 p->setAttribute(
"Constant",
true);
4179 if (!std::isnan(val)) {
4187 throw std::runtime_error(std::string(
"Unrecognised parameter: ") + pat.
Data());
4195 auto idx = pattern2.
Index(
'=');
4198 if (
auto o = defaultOpts->FindObject(pat)) {
4199 defaultOpts->Remove(o);
4203 val.
IsAlpha() ? val :
nullptr));
4209 for (
auto &
d : _dsets) {
4210 if (
d->get()->TestBit(1 << 20)) {
4211 dsetName =
d->get()->GetName();
4215 auto _nll =
nll(dsetName.
Data(), *defaultOpts);
4217 for (
auto [p,
v] : valsToSet) {
4220 _nll.fitConfigOptions()->SetValue(
"LogSize", 65536);
4221 _nll.fitConfig()->MinimizerOptions().SetPrintLevel(0);
4222 auto fr = _nll.minimize();
4225 throw std::runtime_error(
"Fit Failed");
4228 for (
unsigned int i = 0; i < fr->numStatusHistory(); i++) {
4229 statusCodes +=
TString::Format(
"\n%s = %d", fr->statusLabelHistory(i), fr->statusCodeHistory(i));
4232 (
gROOT->GetListOfBrowsers()->At(0))
4233 ?
dynamic_cast<TGWindow *
>(
static_cast<TBrowser *
>(
gROOT->GetListOfBrowsers()->At(0))->GetBrowserImp())
4236 if (_nll.fOpts->find(
"GoF")) {
4237 gofResult =
TString::Format(
"GoF p-value = %g (mainTerm = %g)\n", fr->constPars().getRealValue(
".pgof"),fr->constPars().getRealValue(
".mainterm_pgof"));
4239 if (fr->status() != 0) {
4240 new TGMsgBox(
gClient->GetRoot(), w,
"Fit Finished with Bad Status Code",
4241 TString::Format(
"%s\nData = %s\nFit Status Code = %d\nCov Quality = %d\n%s-------------%s",
4242 fr->GetName(), dsetName.
Data(), fr->status(), fr->covQual(), gofResult.
Data(),
4243 statusCodes.
Data()),
4245 }
else if (fr->covQual() != 3 && _nll.fitConfig()->ParabErrors()) {
4246 new TGMsgBox(
gClient->GetRoot(), w,
"Fit Finished with Bad Covariance Quality",
4247 TString::Format(
"%s\nData = %s\nFit Status Code = %d\nCov Quality = %d\n%s-------------%s",
4248 fr->GetName(), dsetName.
Data(), fr->status(), fr->covQual(), gofResult.
Data(),
4249 statusCodes.
Data()),
4253 TString::Format(
"%s\nData = %s\nFit Status Code = %d\nCov Quality = %d\n%s-------------%s",
4254 fr->GetName(), dsetName.
Data(), fr->status(), fr->covQual(), gofResult.
Data(),
4255 statusCodes.
Data()));
4258 for (
auto a : *
gROOT->GetListOfBrowsers()) {
4269 if (
auto bi =
dynamic_cast<TRootBrowser *
>(
b->GetBrowserImp())) {
4270 if (
auto fb =
dynamic_cast<TGFileBrowser *
>(bi->GetActBrowser())) {
4271 fb->DoubleClicked(p, 0);
4272 if (
auto first = p->GetFirstChild()) {
4274 if (first->IsOpen() &&
TString(first->GetText()) ==
"fits") {
4275 fb->DoubleClicked(first, 0);
4277 }
while ((first = first->GetNextSibling()));
4287 }
catch (
const std::exception &
e) {
4290 (
gROOT->GetListOfBrowsers()->At(0))
4300 datasets().
Add(datasetName, expected ?
"asimov" :
"toy");
4303 for (
auto a : *
gROOT->GetListOfBrowsers()) {
4314 if (
auto bi =
dynamic_cast<TRootBrowser *
>(
b->GetBrowserImp())) {
4315 if (
auto fb =
dynamic_cast<TGFileBrowser *
>(bi->GetActBrowser())) {
4316 fb->DoubleClicked(p, 0);
4317 if (
auto first = p->GetFirstChild()) {
4319 if (first->IsOpen() &&
TString(first->GetText()) ==
"datasets") {
4320 fb->DoubleClicked(first, 0);
4322 }
while ((first = first->GetNextSibling()));
4332 }
catch (
const std::exception &
e) {
4335 (
gROOT->GetListOfBrowsers()->At(0))
4338 "Exception",
e.what(),
4344 double highX ,
const char *constParValues,
4345 const char *options)
4354 for (
auto &
d : _dsets) {
4355 if (
d->get()->TestBit(1 << 20)) {
4356 dsetName =
d->get()->GetName();
4360 auto _pars =
pars();
4361 std::unique_ptr<RooAbsCollection> snap(_pars.argList().snapshot());
4364 auto idx = pattern.
Index(
'=');
4367 (idx == -1) ? std::numeric_limits<double>::quiet_NaN() :
TString(pattern(idx + 1, pattern.
Length())).
Atof();
4368 bool foundArg =
false;
4369 for (
auto par : _pars.argList()) {
4372 par->setAttribute(
"Constant",
true);
4373 if (!std::isnan(val)) {
4379 throw std::runtime_error(std::string(
"Unrecognised parameter: ") + pat.
Data());
4387 auto idx = pattern2.
Index(
'=');
4390 if (
auto o = defaultOpts->FindObject(pat)) {
4391 defaultOpts->Remove(o);
4395 val.
IsAlpha() ? val :
nullptr));
4406 hs.SetTitle(sWhat +
" scan" + ((dsetName !=
"") ?
TString::Format(
" [data=%s]", dsetName.
Data()) :
""));
4407 int scanStatus = hs.scan(sWhat +
" visualize", nBinsX, lowX, highX);
4408 if (scanStatus != 0) {
4411 (
gROOT->GetListOfBrowsers()->At(0))
4414 "Scan Finished with Bad Status Code",
4415 TString::Format(
"%s\nData = %s\nScan Status Code = %d", hs.GetName(), dsetName.
Data(), scanStatus),
4419 if (
auto res = hs.result())
4423 _pars.argList() = *snap;
4426 for (
auto a : *
gROOT->GetListOfBrowsers()) {
4437 if (
auto bi =
dynamic_cast<TRootBrowser *
>(
b->GetBrowserImp())) {
4438 if (
auto fb =
dynamic_cast<TGFileBrowser *
>(bi->GetActBrowser())) {
4439 fb->DoubleClicked(p, 0);
4440 if (
auto first = p->GetFirstChild()) {
4442 if (first->IsOpen() &&
TString(first->GetText()) ==
"scans") {
4443 fb->DoubleClicked(first, 0);
4445 }
while ((first = first->GetNextSibling()));
4456 }
catch (
const std::exception &
e) {
4459 (
gROOT->GetListOfBrowsers()->At(0))
4469 SetBinContent(bin, value, strlen(par) > 0 ? par :
nullptr, parVal);
4470 }
catch (
const std::exception &
e) {
4479#if ROOT_VERSION_CODE > ROOT_VERSION(6, 29, 00)
4484 for (
auto a : *
this) {
4491 for (
auto c : args) {
4497 f.SetParName(i,
c->GetName());
4499 f.SetParLimits(i,
v->getMin(),
v->getMax());
4500 if (
v->isConstant())
4501 f.FixParameter(i,
v->getVal());
4503 f.SetParameter(i,
v->getVal());
4504 f.SetParError(i,
v->getError());
4515 (
gROOT->GetListOfBrowsers()->At(0))
4521 for (i = 0; i <
f.GetNpar(); i++) {
4522 auto c = args.
find(
f.GetParName(i));
4525 v->setVal(
f.GetParameter(i));
4527 f.GetParLimits(i, low, high);
4529 v->setConstant(low);
4531 v->setRange(low, high);
4541 throw std::runtime_error(
"Failed to SetContent");
4542 }
catch (
const std::exception &
e) {
4556 std::shared_ptr<TH1D>
h;
4557 auto _b =
dynamic_cast<Axis2 *
>(ax)->binning();
4558 if (_b->isUniform()) {
4565 h->SetOption(
"nostyle");
4566 h->GetXaxis()->SetName(
TString::Format(
"%s;%s", ax->GetParent()->GetName(), ax->GetName()));
4575 return factors()[
GetName()]->SetBinContent(bin, value, par, parVal);
4580 auto _ax = (bin) ?
GetXaxis() :
nullptr;
4582 throw std::runtime_error(
"Cannot determine binning to fill data");
4584 if (_ax && _ax->GetNbins() < bin) {
4585 throw std::out_of_range(
TString::Format(
"%s range %s only has %d bins", _ax->GetParent()->GetName(),
4586 _ax->GetName(), _ax->GetNbins()));
4596 cut +=
TString::Format(
"%s==%d", _cat->GetName(), _cat->getCurrentIndex());
4603 TString::Format(
"%s>=%f&&%s<%f", _rv->GetName(), _rv->getMin(_rv->getStringAttribute(
"coordRange")),
4604 _rv->GetName(), _rv->getMax(_rv->getStringAttribute(
"coordRange")));
4607 throw std::runtime_error(
"SetBinContent of data: Unsupported coordinate type");
4616 cut2 =
TString::Format(
"%s >= %f && %s < %f", _ax->GetParent()->GetName(), _ax->GetBinLowEdge(bin),
4617 _ax->GetParent()->GetName(), _ax->GetBinUpEdge(bin));
4649 l.remove(*_data->get(),
true,
true);
4654 _data->addColumn(*
x);
4664 for (
auto &o :
obs) {
4666 if (
auto dv =
dynamic_cast<RooRealVar *
>(_data->get()->find(
v->GetName())); dv) {
4667 if (
v->getMin() < dv->getMin())
4668 dv->setMin(
v->getMin());
4669 if (
v->getMax() > dv->getMax())
4670 dv->setMax(
v->getMax());
4673 if (
auto dc =
dynamic_cast<RooCategory *
>(_data->get()->find(
c->GetName())); dc) {
4674 if (!dc->hasLabel(
c->getCurrentLabel())) {
4675 dc->defineType(
c->getCurrentLabel(),
c->getCurrentIndex());
4684 if (
auto _nentries = std::unique_ptr<RooAbsData>(_data->reduce(cutFormula))->numEntries();
4685 _nentries != _ax->GetNbins()) {
4688 if (_nentries > 0) {
4689 Info(
"SetBinContent",
"Binning %s in channel: %s",
GetName(), cut.
Data());
4690 auto _reduced = std::unique_ptr<RooAbsData>(_data->reduce(icutFormula));
4692 for (
int j = 0; j < _reduced->numEntries(); j++) {
4693 auto _obs = _reduced->get(j);
4694 _data->add(*_obs, _reduced->weight());
4697 for (
int i = 1; i <= _ax->GetNbins(); i++) {
4702 _data->add(
obs, _contents.at(i - 1));
4707 if (std::unique_ptr<RooAbsData>(_data->reduce(cutFormula2))->numEntries() > 0) {
4708 auto _reduced = std::unique_ptr<RooAbsData>(_data->reduce(icutFormula2));
4710 for (
int j = 0; j < _reduced->numEntries(); j++) {
4711 auto _obs = _reduced->get(j);
4712 _data->add(*_obs, _reduced->weight());
4717 _data->add(
obs, value);
4719 return bb->SetBinContent(bin, value, par, parVal);
4723 throw std::runtime_error(
"RooDataHist not supported yet");
4727 if (
auto _varies =
variations(); !_varies.empty() || (par && strlen(par))) {
4728 if (!par || strlen(par) == 0) {
4729 return _varies[
"nominal"]->SetBinContent(bin, value, par, parVal);
4730 }
else if (
auto it = _varies.find(
Form(
"%s=%g", par, parVal)); it) {
4731 return it->SetBinContent(bin, value);
4742 if (
auto p =
dynamic_cast<RooRealVar *
>(o); p) {
4743 if (!par || strlen(par) == 0) {
4744 if (p->getMax() < value)
4746 if (p->getMin() > value)
4756 if (strcmp(
c->GetName(),
Form(
"%g",
c->getVal())) == 0) {
4757 c->SetNameTitle(
Form(
"%g", value),
Form(
"%g", value));
4759#if ROOT_VERSION_CODE < ROOT_VERSION(6, 24, 00)
4762 c->changeVal(value);
4772 auto bin_pars =
f->dataHist().get(bin - 1);
4773 if (
f->getAttribute(
"density")) {
4774 value /=
f->dataHist().binVolume(*bin_pars);
4776 f->dataHist().set(*bin_pars, value);
4779 if (
auto otherfName =
f->getStringAttribute(
"symmetrized_by"); otherfName) {
4781 f->setStringAttribute(
"symmetrized_by",
nullptr);
4783 x->setStringAttribute(
"symmetrizes",
nullptr);
4784 x->setStringAttribute(
"symmetrize_nominal",
nullptr);
4786 }
else if (
auto otherfName2 =
f->getStringAttribute(
"symmetrizes"); otherfName2) {
4789 if (nomf && otherf) {
4790 otherf->dataHist().set(*bin_pars, 2 * nomf->dataHist().weight(bin - 1) - value);
4791 otherf->setValueDirty();
4798 f2->setNominal(value);
4807 push_back(std::make_shared<xRooNode>(data));
4809 auto node =
datasets()[data.GetName()];
4814 return node->SetBinContent(bin, value);
4821 push_back(std::make_shared<xRooNode>(data));
4823 auto node =
datasets()[data.GetName()];
4828 return node->SetContents(obj);
4839 if (
auto _varies =
variations(); !_varies.empty()) {
4840 return _varies[
"nominal"]->SetBinError(bin, value);
4855 while (_prodParent && !_prodParent->get<
RooProduct>() && !_prodParent->get<
RooAbsPdf>()) {
4857 _prodParent.reset();
4860 _prodParent = _prodParent->fParent;
4863 (_prodParent && !_prodParent->get<
RooAbsPdf>()) ? _prodParent->factors().find(
"statFactor") :
nullptr;
4864 auto f_stat = (_f_stat) ? _f_stat->get<
ParamHistFunc>() :
nullptr;
4865 if (_f_stat && _f_stat->get() && !f_stat) {
4866 throw std::runtime_error(
"stat factor must be a paramhistfunc");
4875 for (
auto &p :
xRooNode(
"tmp", *
f, std::shared_ptr<xRooNode>(
nullptr)).
vars()) {
4878 parNames += p->get()->GetName();
4880 auto h = std::unique_ptr<TH1>(
f->dataHist().createHistogram(parNames
4887 h->SetName(
"statFactor");
4889 h->SetOption(
"blankshape");
4892 auto toMultiply =
this;
4896 f_stat =
dynamic_cast<ParamHistFunc *
>(toMultiply->Multiply(*h).get());
4898 throw std::runtime_error(
"Failed creating stat shapeFactor");
4904 TString prefix =
f->getStringAttribute(
"statPrefix");
4905 if (value && prefix ==
"") {
4909 while (_p && !(_p->get()->InheritsFrom(
"RooRealSumPdf") || _p->get()->InheritsFrom(
"RooAddPdf") ||
4910 _p->get()->InheritsFrom(
"RooWorkspace") || _p->get()->InheritsFrom(
"RooAddition"))) {
4917 Form(
"#gamma^{%s}_{%d}", prefix.
Data(), bin), 1);
4918#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
4923 auto var =
dynamic_cast<RooRealVar *
>(&pSet[bin - 1]);
4925 if (newVar.get() != var) {
4929 for (std::size_t i = 0; i < pSet.
size(); i++) {
4930 if (
int(i) != bin - 1) {
4931 all.
add(*pSet.
at(i));
4940 xRooNode v((value == 0) ? *var : *newVar, *
this);
4942 if (strcmp(rrv->GetName(),
"1") != 0) {
4943 TString origName = (
f->getStringAttribute(
"origName")) ?
f->getStringAttribute(
"origName") :
GetName();
4945 auto bin_pars =
f->dataHist().get(bin - 1);
4946 auto _binContent =
f->dataHist().weight(bin-1);
4947 if (
f->getAttribute(
"density")) {
4948 _binContent *=
f->dataHist().binVolume(*bin_pars);
4953 for (
auto &[s, sv] : rrv->stringAttributes()) {
4954 if (s.find(
"sumw_") == 0) {
4956 }
else if (s.find(
"sumw2_") == 0) {
4960 if (sumw2 && sumw2 != std::numeric_limits<double>::infinity()) {
4961 double tau = pow(sumw, 2) / sumw2;
4962 rrv->setError((tau < 1
e-15) ? 1e15 : ( 1. / sqrt(tau)));
4963 rrv->setConstant(
false);
4965 auto _constr =
v.constraints();
4967 if (_constr.empty()) {
4968 rrv->setStringAttribute(
"boundConstraint", _constr.Add(
"poisson").get()->GetName());
4970 auto _glob = _constr.at(0)->obs().at(0)->get<
RooRealVar>();
4973 double _min = tau * (1. - 5. * sqrt(1. / tau));
4974 double _max = tau * (1. + 5. * sqrt(1. / tau));
4975 _glob->setRange(_min, _max);
4977 _constr.at(0)->pp().at(0)->SetBinContent(0, tau);
4978 rrv->setStringAttribute(
"boundConstraint", _constr.at(0)->get()->GetName());
4980 rrv->setRange(std::max((1. - 5. * sqrt(1. / tau)), 1
e-15), 1. + 5. * sqrt(1. / tau));
4983 if (
auto _constr =
v.constraints(); !_constr.empty()) {
4984 v.constraints().Remove(*_constr.at(0));
4989 rrv->setConstant(sumw2 == 0);
5001 auto res =
find(
name, browseResult);
5003 throw std::out_of_range(
name +
" does not exist");
5025 xRooNode out(
".constraints",
nullptr, *
this);
5028 getConstraint = [&](
const xRooNode &
n,
RooAbsArg &par, std::set<RooAbsPdf *> ignore) {
5030 if (ignore.count(_pdf))
5032 ignore.insert(_pdf);
5038 for (
auto &
c :
n.bins()) {
5039 if (
auto oo = getConstraint(*
c, par, ignore); oo) {
5049 for (
auto p : _ws->allPdfs()) {
5050 if (ignore.count(
static_cast<RooAbsPdf *
>(p)))
5052 if (p->dependsOn(par)) {
5053 out.emplace_back(std::make_shared<xRooNode>(par.GetName(), *p, *
this));
5059 return getConstraint(*
n.fParent, par, ignore);
5061 for (
auto p : o->pdfList()) {
5062 if (ignore.count(
static_cast<RooAbsPdf *
>(p)))
5064 if (p->dependsOn(par)) {
5065 out.emplace_back(std::make_shared<xRooNode>(par.GetName(), *p, *
this));
5071 for (
auto &p :
vars()) {
5077 if (
v->getAttribute(
"obs"))
5087 auto it = out.std::vector<std::shared_ptr<xRooNode>>
::begin();
5088 while (it != out.std::vector<std::shared_ptr<xRooNode>>
::end()) {
5089 bool removeIt =
false;
5090 for (
auto &
c : out) {
5091 if (
c.get() == it->get())
5095 std::set<std::string> parNames;
5096 std::string _cName =
c->GetName();
5098 parNames.insert(_cName.substr(0, _cName.find(
';')));
5099 _cName = _cName.substr(_cName.find(
';') + 1);
5100 }
while (_cName.find(
';') != std::string::npos);
5101 parNames.insert(_cName);
5102 _cName = it->get()->GetName();
5104 parNames.insert(_cName.substr(0, _cName.find(
';')));
5105 _cName = _cName.substr(_cName.find(
';') + 1);
5106 }
while (_cName.find(
';') != std::string::npos);
5107 parNames.insert(_cName);
5109 for (
auto &
x : parNames) {
5110 if (!_cName.empty())
5114 c->TNamed::SetName(_cName.c_str());
5128 for (
auto &o : out) {
5129 o->TNamed::SetName(o->get()->GetName());
5143 sName =
TString(
"factory:") + sName;
5149 std::map<std::string, std::string> stringAttrs;
5164 origName = origName(1, origName.
Length());
5167 newObjName(1, newObjName.
Length());
5174 TString varName =
h->GetXaxis()->GetName();
5175 std::string binningName = newObjName.
Data();
5177 binningName = varName(
pos + 1, varName.
Length());
5178 varName = varName(0,
pos);
5181 if (varName ==
"xaxis" &&
5183 if (
auto ax = acquirer.
GetXaxis(); ax) {
5184 varName = ax->GetParent()->GetName();
5186 binningName = ax->GetName();
5187 }
else if (acquirer.
obs().size() == 1)
5188 varName = acquirer.
obs().
at(0)->get()->GetName();
5191 h->GetXaxis()->GetXmax());
5192 if (
x->getMin() >
h->GetXaxis()->GetXmin())
5193 x->setMin(
h->GetXaxis()->GetXmin());
5194 if (
x->getMax() <
h->GetXaxis()->GetXmax())
5195 x->setMax(
h->GetXaxis()->GetXmax());
5196 if (!
x->hasBinning(binningName.c_str())) {
5197 if (
h->GetXaxis()->IsVariableBinSize()) {
5198 x->setBinning(
RooBinning(
h->GetNbinsX(),
h->GetXaxis()->GetXbins()->GetArray()), binningName.c_str());
5201 RooUniformBinning(
h->GetXaxis()->GetXmin(),
h->GetXaxis()->GetXmax(),
h->GetXaxis()->GetNbins()),
5202 binningName.c_str());
5204 x->getBinning(binningName.c_str()).SetTitle(
h->GetXaxis()->GetTitle());
5205 if (
x->getBinningNames().size() == 2) {
5207 x->setBinning(
x->getBinning(binningName.c_str()));
5211 if (
x->getBinning(binningName.c_str()).numBins() !=
h->GetNbinsX()) {
5212 throw std::runtime_error(
5213 TString::Format(
"binning mismatch for binning %s of %s", binningName.c_str(),
x->GetName()));
5217 std::shared_ptr<RooAbsArg> _f;
5223 for (
auto &[k,
v] : stringAttrs) {
5224 _f->setStringAttribute(k.c_str(),
v.c_str());
5226 x->setAttribute(
"obs",
true);
5227 }
else if (sOpt2.
Contains(
"shape")) {
5229 for (
int i = 0; i <
x->getBinning(binningName.c_str()).numBins(); i++) {
5230 std::shared_ptr<RooAbsArg> arg;
5231 if (sOpt2.
Contains(
"blankshape")) {
5236 }
else if (
h->GetMinimumStored() != -1111 ||
h->GetMaximumStored() != -1111) {
5239 h->GetBinContent(i + 1),
h->GetMinimumStored(),
5240 h->GetMaximumStored());
5244 h->GetBinContent(i + 1));
5252 x->setBinning(
x->getBinning(binningName.c_str()));
5254#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
5260 x->setBinning(*tmp);
5262 for (
auto &[k,
v] : stringAttrs) {
5263 _f->setStringAttribute(k.c_str(),
v.c_str());
5267 binningName.c_str() );
5269 throw std::runtime_error(
"Couldn't make data hist");
5274 f->setAttribute(
"autodensity");
5277 for (
auto &[k,
v] : stringAttrs) {
5278 _f->setStringAttribute(k.c_str(),
v.c_str());
5282 _f->setStringAttribute(
"xvar",
x->GetName());
5283 _f->setStringAttribute(
"binning", binningName.c_str());
5284 if (strcmp(_f->GetName(), origName.
Data()) && !_f->getStringAttribute(
"alias"))
5285 _f->setStringAttribute(
"alias", origName);
5288 xRooNode tmp(
h->GetName(), _f, acquirer);
5290 _f = std::dynamic_pointer_cast<RooAbsArg>(tmp.
fComp);
5293 _f->setStringAttribute(
"xvar",
x->GetName());
5294 _f->setStringAttribute(
"binning", binningName.c_str());
5297 if (strcmp(_f->GetName(), origName.
Data()) && !_f->getStringAttribute(
"alias"))
5298 _f->setStringAttribute(
"alias", origName);
5317 return std::dynamic_pointer_cast<TStyle>(
styles(initObject, autoCreate).
fComp);
5325 if (!initObject && !arg && !
gROOT->GetStyle(t)) {
5329 std::unique_ptr<TObject> argInitObject;
5334 if (arg->getStringAttribute(
"style")) {
5335 t = arg->getStringAttribute(
"style");
5336 }
else if (autoCreate) {
5338 argInitObject = std::make_unique<TH1D>(
GetName(),
GetTitle(), 1, 0, 1);
5339 initObject = argInitObject.get();
5345 std::shared_ptr<TStyle>
style;
5347 if (!
gROOT->GetStyle(t)) {
5358 if (
auto x =
dynamic_cast<TAttLine *
>(initObject))
5360 if (
auto x =
dynamic_cast<TAttFill *
>(initObject))
5362 if (
auto x =
dynamic_cast<TAttMarker *
>(initObject))
5370 if (arg && !arg->getStringAttribute(
"style")) {
5371 arg->setStringAttribute(
"style",
style->GetName());
5377std::shared_ptr<TObject>
xRooNode::acquire(
const std::shared_ptr<TObject> &arg,
bool checkFactory,
bool mustBeNew)
5382 return fParent->acquire(arg, checkFactory, mustBeNew);
5386 if (_ws && (
get() == _ws || _ws->arg(
GetName()) || (arg && strcmp(arg->GetName(),
GetName()) == 0))) {
5389 if (
auto a =
dynamic_cast<RooAbsArg *
>(arg.get());
a) {
5390 auto out_arg = _ws->arg(
a->GetName());
5391 TString aName = arg->GetName();
5393 while (out_arg && mustBeNew) {
5395 out_arg = _ws->arg(
a->GetName());
5397 if (aName !=
a->GetName())
5398 Warning(
"acquire",
"Renaming to %s",
a->GetName());
5402 if (
auto res = _ws->factory(arg->GetName()); res) {
5409 Info(
"acquire",
"A copy of %s has been added to workspace %s",
a->GetName(), _ws->GetName());
5415 std::set<std::string> setNames;
5418 setNames.insert(aa.first);
5421 for (
auto &aa : setNames)
5423 out_arg = _ws->arg(
a->GetName());
5424 if (
GETWS(out_arg) != _ws) {
5425 out_arg->setWorkspace(*_ws);
5431 out_arg->leafNodeServerList(&leafs);
5432 std::unique_ptr<RooAbsCollection> globals(leafs.
selectByAttrib(
"global",
true));
5433 for (
auto &aa : *globals) {
5434 if (!
globs->contains(*aa)) {
5441 return std::shared_ptr<TObject>(out_arg, [](
TObject *) {});
5442 }
else if (
auto a2 =
dynamic_cast<RooAbsData *
>(arg.get()); a2) {
5448 return std::shared_ptr<TObject>(_ws->embeddedData(arg->GetName()), [](
TObject *) {});
5449 }
else if (arg->InheritsFrom(
"TNamed")) {
5453 out_arg = fr->
Clone();
5458 TString aName = arg->GetName();
5459 out_arg = _ws->genobj(arg->GetName());
5461 while (aNamed && out_arg && mustBeNew) {
5463 out_arg = _ws->genobj(aNamed->
GetName());
5466 if (aName != arg->GetName()) {
5467 Warning(
"acquire",
"Renaming to %s", arg->GetName());
5469 if (_ws->import(*arg,
false )) {
5473 out_arg = _ws->genobj(arg->GetName());
5478 return std::shared_ptr<TObject>(out_arg, [](
TObject *) {});
5485 auto out =
fProvider->getObject(arg->GetName(), arg->ClassName());
5489 auto _owned =
find(
".memory");
5491 _owned = emplace_back(std::make_shared<xRooNode>(
".memory",
nullptr, *
this));
5496 for (
auto &
r : *_owned) {
5497 if (strcmp(
r->GetName(), arg->GetName()) == 0 && strcmp(
r->get()->ClassName(), arg->ClassName()) == 0) {
5503 std::cout <<
GetName() <<
" taking over " << arg->ClassName() <<
"::" << arg->GetName() << std::endl;
5505 return _owned->emplace_back(std::make_shared<xRooNode>(arg->GetName(), arg, *
this))->fComp;
5533 auto _deps =
vars();
5547 throw std::runtime_error(
"Cannot SetXaxis of non-arg");
5550 _x->setBinning(binning,
a->GetName());
5551 _x->getBinning(
a->GetName()).SetTitle(title);
5552 if (_x->getBinningNames().size() == 2) {
5554 _x->setBinning(_x->getBinning(
a->GetName()));
5559 if (_x->getMax() < high)
5561 if (_x->getMin() > low)
5567 _x->setAttribute(
"obs");
5570 a->setStringAttribute(
"xvar", _x->GetName());
5571 a->setStringAttribute(
"binning",
a->GetName());
5581 if (ax->IsVariableBinSize()) {
5582 return SetXaxis(ax->GetName(), ax->GetTitle(), ax->GetNbins(), ax->GetXbins()->GetArray());
5584 return SetXaxis(ax->GetName(), ax->GetTitle(), ax->GetNbins(), ax->GetXmin(), ax->GetXmax());
5590 return find(
name,
false) !=
nullptr;
5595 std::string partname = (
name.find(
'/') != std::string::npos) ?
name.substr(0,
name.find(
'/')) :
name;
5598 std::string extra = (_s) ? _s->indexCat().GetName() :
"";
5599 for (
auto &child : *
this) {
5600 if (
auto _obj = child->get();
name == child->GetName() || partname == child->GetName() ||
5601 (_obj &&
name == _obj->GetName()) || (_obj && partname == _obj->GetName()) ||
5602 (!extra.empty() && ((extra +
"=" +
name) == child->GetName() ||
5603 (extra +
"=" + partname) == child->GetName()))) {
5606 if (partname !=
name &&
name != child->GetName()) {
5607 return child->at(
name.substr(partname.length() + 1));
5611 if (partname.find(
'.') != 0) {
5613 if (
auto x =
mainChild();
x && strcmp(child->GetName(),
x.GetName()) == 0) {
5615 for (
auto &child2 :
x.browse()) {
5616 if (
auto _obj = child2->get();
name == child2->GetName() || partname == child2->GetName() ||
5617 (_obj &&
name == _obj->GetName()) ||
5618 (_obj && partname == _obj->GetName())) {
5621 if (partname !=
name &&
name != child2->GetName()) {
5622 return child2->at(
name.substr(partname.length() + 1));
5632 auto child2 =
at(s.Atoi());
5633 if (partname !=
name) {
5634 return child2->at(
name.substr(partname.length() + 1));
5641 auto out = std::make_shared<xRooNode>(obj, *
this);
5652 std::string partname = (
name.find(
'/') != std::string::npos) ?
name.substr(0,
name.find(
'/')) :
name;
5656 std::string extra = (_s) ? _s->indexCat().GetName() :
"";
5657 std::shared_ptr<xRooNode> folderNode;
5658 for (
auto &child : *
this) {
5659 if (
name == child->GetName() || partname == child->GetName() ||
5661 ((extra +
"=" +
name) == child->GetName() || (extra +
"=" + partname) == child->GetName()))) {
5663 if (partname !=
name &&
name != child->GetName()) {
5664 return child->operator[](
name.substr(partname.length() + 1));
5668 if (
auto x =
mainChild(); strcmp(child->GetName(),
x.GetName()) == 0) {
5670 for (
auto &child2 :
x.browse()) {
5671 if (
name == child2->GetName() || partname == child2->GetName()) {
5673 if (partname !=
name &&
name != child2->GetName()) {
5674 return child2->operator[](
name.substr(partname.length() + 1));
5680 if (child->fFolder == (std::string(
"!") + partname)) {
5682 folderNode = std::make_shared<xRooNode>(child->fFolder.c_str(),
nullptr, *
this);
5683 folderNode->push_back(child);
5687 if (partname !=
name) {
5688 return folderNode->operator[](
name.substr(partname.length() + 1));
5694 auto child2 =
at(s.Atoi());
5695 if (partname !=
name) {
5696 return child2->operator[](
name.substr(partname.length() + 1));
5700 auto out = std::make_shared<xRooNode>(partname.c_str(),
nullptr, *
this);
5703 out->SetName(
"!pdfs");
5705 if (partname !=
name) {
5706 return out->operator[](
name.substr(partname.length() + 1));
5714 for (
auto o : *
gROOT->GetListOfBrowsers()) {
5716 if (!
b || !
b->GetBrowserImp())
5723 if (!
b->GetBrowserImp())
5739 for (
auto o : *
gROOT->GetListOfBrowsers()) {
5741 if (!
b || !
b->GetBrowserImp())
5748 if (
b->GetBrowserImp()) {
5754 if (
auto item =
GETLISTTREE(_b)->FindItemByObj(_root,
const_cast<xRooNode *
>(
this)); item) {
5766 a->setStringAttribute(
"alias",
name);
5767 for (
auto o : *
gROOT->GetListOfBrowsers()) {
5768 if (
auto b =
dynamic_cast<TBrowser *
>(o);
b) {
5770 item->SetText(
name);
5793 auto findByObj = [&](
const std::shared_ptr<xRooNode> &
n) {
5794 std::vector<std::shared_ptr<xRooNode>> &nn = *
this;
5795 for (
auto &
c : nn) {
5796 if (
c->get() ==
n->get() && strcmp(
n->GetName(),
c->GetName()) == 0)
5799 return std::shared_ptr<xRooNode>(
nullptr);
5802 auto appendChildren = [&](
const xRooNode &
n) {
5804 const std::vector<std::shared_ptr<xRooNode>> &nn(
n);
5805 for (
auto &
c : nn) {
5806 if (
auto existing = findByObj(
c); existing) {
5808 existing->fFolder =
c->fFolder;
5818 const std::vector<std::shared_ptr<xRooNode>> &nn2(*
this);
5819 for (
auto &
c : nn2) {
5820 if (strlen(
c->GetName()) > 0 && (
c->GetName()[0] ==
'.')) {
5824 if (strcmp(
c->GetName(),
"!.pars") == 0) {
5835 size_t addedChildren = 0;
5840 addedChildren += appendChildren(
datasets());
5854 addedChildren += appendChildren(
components());
5856 addedChildren += appendChildren(
factors());
5858 auto _coefs =
coefs();
5859 if (_coefs.get() && strcmp(_coefs->GetName(),
"1") != 0 && strcmp(_coefs->GetName(),
"ONE") != 0) {
5860 if (_coefs.size() == 1 && _coefs.get<
RooAddition>()) {
5861 if (strcmp(_coefs.at(0)->GetName(),
"1") != 0 &&
5862 strcmp(_coefs.at(0)->GetName(),
"ONE") != 0) {
5863 auto coef = std::make_shared<xRooNode>(
".coef", *_coefs.at(0)->get(), *
this);
5864 if (
auto existing = findByObj(coef); existing) {
5866 existing->fFolder = _coefs.at(0)->fFolder;
5872 if (
auto existing =
find(_coefs.GetName()); existing) {
5874 existing->fFolder = _coefs.fFolder;
5876 emplace_back(std::make_shared<xRooNode>(_coefs));
5880 addedChildren += appendChildren(
variations());
5882 addedChildren += appendChildren(
bins());
5884 addedChildren += appendChildren(
obs());
5888 for (
int i = 0; i < arg->numProxies(); i++) {
5889 auto _proxy = arg->getProxy(i);
5891 auto c = std::make_shared<xRooNode>(
TString::Format(
".%s", _proxy->name()), *(
a->absArg()), *
this);
5892 if (
auto existing = findByObj(
c); existing) {
5894 existing->fFolder =
c->fFolder;
5899 for (
auto &child : *
this) {
5900 if (strcmp(child->GetName(),
c->GetName()) == 0) {
5907 for (
auto a2 : *s) {
5908 auto c = std::make_shared<xRooNode>(*a2, *
this);
5909 if (arg->numProxies() != 1) {
5910 c->fFolder = std::string(
"!.") +
5913 if (
auto existing = findByObj(
c); existing) {
5915 existing->fFolder =
c->fFolder;
5935 if (strcmp(
c->GetName(),
".memory") == 0 &&
c->get<
xRooHypoSpace>()) {
5943 fBrowsables.emplace_back(std::make_shared<xRooNode>(
".memory", std::make_shared<xRooHypoSpace>(ir), *
this));
5950 for (
auto a : _axes) {
5951 if (
a != _axes.first())
5954 TString::Format(
"%s=%g",
a->GetName(), hp.coords->getRealValue(
a->GetName(), ir->GetXValue(i)));
5956 auto hpn = emplace_back(std::make_shared<xRooNode>(coordString, hp.hypoTestResult, hs));
5958 hpn->fBrowsables.emplace_back(std::make_shared<xRooNode>(
5964 std::vector<std::shared_ptr<xRooNode>> &nn = *
this;
5965 for (
auto &
c : nn) {
5988 std::make_shared<xRooNLLVar::xRooHypoPoint>(std::dynamic_pointer_cast<RooStats::HypoTestResult>(
fComp));
5989 fBrowsables.emplace_back(std::make_shared<xRooNode>(
".memory", shp, *
this));
5995 if (
auto fit = hp->
ufit()) {
5996 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"ufit");
5999 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"cfit_null");
6002 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"cfit_alt");
6004 if (
auto fit = hp->
gfit()) {
6005 fits.emplace_back(std::make_shared<xRooNode>(fit, *
this))->TNamed::SetName(
"gfit");
6007 if (
auto asi = hp->
asimov()) {
6008 auto asiP = fits.emplace_back(std::make_shared<xRooNode>(
6009 asi->hypoTestResult ? asi->hypoTestResult : std::make_shared<RooStats::HypoTestResult>(asi->result()),
6011 asiP->TNamed::SetName(
"asimov");
6012 asiP->fBrowsables.emplace_back(std::make_shared<xRooNode>(
".memory", asi, asiP));
6014 appendChildren(fits);
6018 auto it = std::vector<std::shared_ptr<xRooNode>>
::begin();
6019 while (it != std::vector<std::shared_ptr<xRooNode>>
::end()) {
6020 if (it->get()->fTimes == 0) {
6021 for (
auto o : *
gROOT->GetListOfBrowsers()) {
6023 if (
b &&
b->GetBrowserImp()) {
6032 if (
auto item =
GETLISTTREE(_b)->FindItemByObj(_root,
this); item) {
6070 xRooNode out(
".obs", std::make_shared<RooArgList>(), *
this);
6072 for (
auto o :
vars()) {
6075 out.emplace_back(o);
6086 xRooNode out(
".globs", std::make_shared<RooArgList>(), *
this);
6088 for (
auto o :
obs()) {
6091 out.emplace_back(o);
6102 xRooNode out(
".robs", std::make_shared<RooArgList>(), *
this);
6104 for (
auto o :
obs()) {
6107 out.emplace_back(o);
6122 xRooNode out(
".pars", std::make_shared<RooArgList>(), *
this);
6124 for (
auto o :
vars()) {
6127 out.emplace_back(o);
6138 xRooNode out(
".consts", std::make_shared<RooArgList>(), *
this);
6140 for (
auto o :
pars()) {
6143 out.emplace_back(o);
6155 xRooNode out(
".floats", std::make_shared<RooArgList>(), *
this);
6157 for (
auto o :
pars()) {
6160 out.emplace_back(o);
6172 xRooNode out(
".poi", std::make_shared<RooArgList>(), *
this);
6174 for (
auto o :
pars()) {
6177 out.emplace_back(o);
6189 xRooNode out(
".np", std::make_shared<RooArgList>(), *
this);
6191 for (
auto o :
pars()) {
6196 out.emplace_back(o);
6207 xRooNode out(
".pp", std::make_shared<RooArgList>(), *
this);
6209 for (
auto o :
pars()) {
6213 out.emplace_back(o);
6224 xRooNode out(
".vars", std::make_shared<RooArgList>(), *
this);
6227 for (
auto &
x : *
this) {
6228 for (
auto &
y :
x->vars()) {
6240 p->leafNodeServerList(&allLeaves);
6241 for (
auto &
c : allLeaves) {
6243 if (!
c->getAttribute(
"global")) {
6245 out.emplace_back(std::make_shared<xRooNode>(*
c, *
this));
6247 if (
c->getAttribute(
"global")) {
6248 _globs.emplace_back(std::make_shared<xRooNode>(*
c, *
this));
6249 _globs.back()->fFolder =
"!globs";
6250 }
else if (
c->getAttribute(
"obs")) {
6251 out.back()->fFolder =
"!robs";
6252 }
else if (
c->getAttribute(
"poi")) {
6253 out.back()->fFolder =
"!poi";
6254 }
else if (
c->getAttribute(
"np") ||
6256 out.back()->fFolder =
"!np";
6258 out.back()->fFolder =
"!floats";
6260 out.back()->fFolder =
"!pp";
6264 for (
auto g : _globs) {
6266 out.emplace_back(
g);
6269 for (
auto a : *p2->get()) {
6270 a->setAttribute(
"obs");
6271 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
6274 if (
auto _dglobs = p2->getGlobalObservables()) {
6275 for (
auto &
a : *_dglobs) {
6276 a->setAttribute(
"obs");
6277 a->setAttribute(
"global");
6278 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
6283 a->setAttribute(
"obs");
6284 a->setAttribute(
"global");
6285 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
6288 }
else if (
auto _ws =
ws(); _ws) {
6290 for (
auto a : *_globs2) {
6291 a->setAttribute(
"obs");
6292 a->setAttribute(
"global");
6293 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
6297 for (
auto &_g : _gl->second) {
6298 auto _clone = std::shared_ptr<RooAbsArg>(
dynamic_cast<RooAbsArg *
>(_g->Clone(_g->GetName())));
6299 if (
auto v = std::dynamic_pointer_cast<RooAbsRealLValue>(_clone);
v && _g->getStringAttribute(
"nominal"))
6300 v->setVal(
TString(_g->getStringAttribute(
"nominal")).
Atof());
6301 out.emplace_back(std::make_shared<xRooNode>(_clone, *
this));
6309 for (
auto &_g : *_globs3) {
6310 auto _clone = std::shared_ptr<RooAbsArg>(
dynamic_cast<RooAbsArg *
>(_g->Clone(_g->GetName())));
6311 if (
auto v = std::dynamic_pointer_cast<RooAbsRealLValue>(_clone);
v && _g->getStringAttribute(
"nominal"))
6312 v->setVal(
TString(_g->getStringAttribute(
"nominal")).
Atof());
6313 out.emplace_back(std::make_shared<xRooNode>(_clone, *
this));
6319 for (
auto a : w->allVars()) {
6320 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
6324 for (
auto a : w->allCats()) {
6325 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
6334 xRooNode out(
".components",
nullptr, *
this);
6338 std::set<RooAbsArg *> donePdfs;
6339 for (
auto &o : p->pdfList()) {
6340 if (donePdfs.count(o))
6342 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
6359 std::set<RooAbsArg *> doneFuncs;
6360 for (
auto &o : p2->funcList()) {
6361 if (doneFuncs.count(o))
6363 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
6364 doneFuncs.insert(o);
6367 for (
auto &o : p3->list()) {
6368 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
6371 for (
auto &
a : *p4) {
6372 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
6375 for (
auto &o : p5->components()) {
6378 bool hasClients =
false;
6379 for (
auto &
c : o->clients()) {
6380 if (!
c->InheritsFrom(
"RooRealIntegral") && p5 ==
GETWS(
c)) {
6387 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
6388 if (o->InheritsFrom(
"RooAbsPdf")) {
6389 out.back()->fFolder =
"!pdfs";
6391 out.back()->fFolder =
"!scratch";
6394 for (
auto &o : p5->allGenericObjects()) {
6398 s = s(0, s.
Index(
';'));
6399 if (
auto _pdf = out.
find(s.
Data()); _pdf) {
6401 out.emplace_back(std::make_shared<xRooNode>(fr->GetName(), *fr, _pdf));
6408 out.emplace_back(std::make_shared<xRooNode>(fr->GetName(), *fr, *
this));
6410 out.back()->fFolder =
"!fits";
6412 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
6413 if (strcmp(out.back()->get()->
ClassName(),
"TStyle") == 0) {
6414 out.back()->fFolder =
"!styles";
6415 }
else if (strcmp(out.back()->get()->
ClassName(),
"RooStats::HypoTestInverterResult") == 0) {
6416 out.back()->fFolder =
"!scans";
6417 }
else if (strcmp(out.back()->get()->
ClassName(),
"RooStats::ModelConfig") == 0) {
6418 out.back()->fFolder =
"!models";
6420 out.back()->fFolder =
"!objects";
6427 if (k.find(
"CACHE_") == 0)
6429 out.emplace_back(std::make_shared<xRooNode>(k.c_str(),
v, *
this));
6430 out.back()->fFolder =
"!sets";
6436 while ((snap = iter->Next())) {
6437 out.emplace_back(std::make_shared<xRooNode>(*snap, *
this));
6438 out.back()->fFolder =
"!snapshots";
6443 out.emplace_back(std::make_shared<xRooNode>(
".pdf", *mc->GetPdf(), *
this));
6445 if (mc->GetExternalConstraints()) {
6446 out.emplace_back(std::make_shared<xRooNode>(
".extCons", *mc->GetExternalConstraints(), *
this));
6452 out.emplace_back(
c);
6459 out.emplace_back(
c);
6473 xRooNode out(
".bins",
nullptr, *
this);
6476 std::map<int, std::shared_ptr<xRooNode>> cats;
6477 for (
auto &
c : p->indexCat()) {
6478 auto pp = p->getPdf(
c.first.c_str());
6482 std::make_shared<xRooNode>(
TString::Format(
"%s=%s", p->indexCat().GetName(),
c.first.c_str()), *
pp, *
this);
6484 for (
auto &[
_,
n] : cats)
6485 out.emplace_back(
n);
6488#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
6489 auto &pSet = phf->_paramSet;
6491 auto &pSet = phf->paramList();
6493 for (
auto par : pSet) {
6494 out.emplace_back(std::make_shared<xRooNode>(*par, *
this));
6495 out.back()->fBinNumber = i;
6498 }
else if (
auto ax =
GetXaxis(); ax) {
6499 for (
int i = 1; i <= ax->GetNbins(); i++) {
6501 std::vector<RooAbsArg *> _factors;
6505 for (
auto &ss :
f->bins()[i - 1]->factors())
6506 _factors.push_back(ss->get<
RooAbsArg>());
6508 _factors.push_back(
f->bins()[i - 1]->get<
RooAbsArg>());
6512 out.emplace_back(std::make_shared<xRooNode>(
6513 TString::Format(
"%g<=%s<%g", ax->GetBinLowEdge(i), ax->GetParent()->GetName(), ax->GetBinLowEdge(i + 1)),
6514 _factors.empty() ?
nullptr
6518 for (
auto f : _factors) {
6519#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
6525 out.back()->fBinNumber = i;
6539 auto parentCoefs =
fParent->coefs(
true);
6550 std::make_shared<RooProduct>(
".recursiveCoefs",
6555 auto mem = out.emplace_back(std::make_shared<xRooNode>(
".memory",
nullptr, *
this));
6556 mem->emplace_back(std::make_shared<xRooNode>(ourCoefs));
6557 mem->emplace_back(std::make_shared<xRooNode>(parentCoefs));
6561 bool isResidual =
false;
6569 if (!parent->fComp) {
6570 while (!parent->fComp && parent->fParent) {
6571 parent = parent->fParent;
6574 parent = parent->fParent;
6580 for (
auto &o : p->funcList()) {
6582 if (i >= p->coefList().size()) {
6584 coefs.add(p->coefList());
6586 coefs.add(*p->coefList().at(i));
6591 }
else if (
auto p2 = parent->get<
RooAddPdf>(); p2) {
6593 if (p2->coefList().empty()) {
6598 for (
auto &o : p2->pdfList()) {
6600 if (i >= p2->coefList().size()) {
6602 coefs.add(p2->coefList());
6604 coefs.add(*p2->coefList().at(i));
6615 auto coefSum =
coefs.empty()
6618 : std::make_shared<RooAddition>((isResidual) ?
".sumOfCoefs" :
".coefs",
6619 "Coefficients of",
coefs));
6620 xRooNode out(
".coef", coefSum ? std::dynamic_pointer_cast<RooAbsArg>(std::make_shared<RooFormulaVar>(
6621 ".coef",
"1-sum(otherCoefs)",
"1. - @0", *coefSum))
6623 if (coefSum &&
coefs.size() != 1) {
6624 out.emplace_back(std::make_shared<xRooNode>(
".memory",
nullptr, *
this))
6626 std::make_shared<xRooNode>(
".sumOfCoefs", coefSum, out));
6628 if (!
coefs.empty()) {
6632 }
else if (
coefs.size() == 1) {
6634 if (!
coefs.empty()) {
6643 xRooNode out(
".coefs", coefSum, *
this);
6653 xRooNode out(
".factors",
nullptr, *
this);
6657 if (
auto a = _main.get<
RooRealSumPdf>();
a && !
a->getStringAttribute(
"alias")) {
6658 a->setStringAttribute(
"alias",
"samples");
6660 a2->setStringAttribute(
"alias",
"components");
6662 int _npdfs = p->pdfList().size();
6663 for (
auto &o : p->pdfList()) {
6664 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
6665 if (_npdfs > 5 && o != _main.get() && out.back()->robs().size() == 0)
6666 out.back()->fFolder =
"!constraints";
6669 for (
auto &o : p2->components()) {
6670 if (o->InheritsFrom(
"RooProduct")) {
6672 auto x =
xRooNode(
"tmp", *o, *
this).factors();
6674 out.emplace_back(std::make_shared<xRooNode>(
n->GetName(),
n->fComp, *
this));
6677 out.emplace_back(std::make_shared<xRooNode>(*o, *
this));
6686 for (
auto a : w->allFunctions()) {
6687 if (_obs.contains(*
a))
6690 for (
auto c :
a->clients()) {
6692 if (
c->InheritsFrom(
"RooProduct")) {
6698 out.emplace_back(std::make_shared<xRooNode>(*
a, *
this));
6742 xRooNode out(
".variations",
nullptr, *
this);
6755#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
6756 out.emplace_back(std::make_shared<xRooNode>(
"nominal", p2->_nominal.arg(), *
this));
6758 out.emplace_back(std::make_shared<xRooNode>(
"nominal", *(p2->nominalHist()), *
this));
6760 for (
size_t i = 0; i < p2->paramList().
size(); i++) {
6762 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p2->paramList().at(i)->GetName()),
6763 *p2->highList().at(i), *
this));
6764 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p2->paramList().at(i)->GetName()),
6765 *p2->lowList().at(i), *
this));
6768#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
6769 out.emplace_back(std::make_shared<xRooNode>(
"nominal",
RooFit::RooConst(p3->_nominal), *
this));
6770 for (
size_t i = 0; i < p3->_paramList.size(); i++) {
6771 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p3->_paramList.at(i)->GetName()),
6773 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p3->_paramList.at(i)->GetName()),
6777 out.emplace_back(std::make_shared<xRooNode>(
"nominal",
RooFit::RooConst(p3->nominal()), *
this));
6778 for (
size_t i = 0; i < p3->variables().
size(); i++) {
6779 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=1", p3->variables().at(i)->GetName()),
6781 out.emplace_back(std::make_shared<xRooNode>(
TString::Format(
"%s=-1", p3->variables().at(i)->GetName()),
6805 for (
auto &k : *
this) {
6814 xRooNode out(
".datasets()",
nullptr, *
this);
6820 for (
auto &
d : _ws->allData()) {
6821 out.emplace_back(std::make_shared<xRooNode>(*
d, *
this));
6822 out.back()->fFolder =
"!datasets";
6839 cut +=
TString::Format(
"%s==%d", _cat->GetName(), _cat->getCurrentIndex());
6847 cut +=
TString::Format(
"%s>=%f&&%s<%f", _rv->GetName(), _rv->getMin(_rv->getStringAttribute(
"coordRange")),
6848 _rv->GetName(), _rv->getMax(_rv->getStringAttribute(
"coordRange")));
6853 throw std::runtime_error(
"datasets(): Unsupported coordinate type");
6858 bool hasMissing =
false;
6860 for (
auto cat : s->indexCat()) {
6861 if (!s->getPdf(cat.first.c_str())) {
6866 extraCut +=
TString::Format(
"%s==%d", s->indexCat().GetName(), cat.second);
6872 cut +=
"(" + extraCut +
")";
6873 cutobs.
add(s->indexCat());
6877 if (
auto ax =
GetXaxis(); ax &&
dynamic_cast<RooAbsArg *
>(ax->GetParent())->getAttribute(
"obs")) {
6878 auto a =
dynamic_cast<RooAbsArg *
>(ax->GetParent());
6882 for (
auto &child : *
this) {
6884 _datasets.push_back(child);
6886 if (
auto __ws =
ws(); __ws) {
6889 _datasets.push_back(
d);
6893 for (
auto &
d : _datasets) {
6894 if (std::unique_ptr<RooAbsCollection>(
d->obs().argList().selectCommon(_obs))->size() == _obs.
size()) {
6901 out.emplace_back(std::make_shared<xRooNode>(
6906 out.back()->get<
RooAbsData>()->setGlobalObservables(*std::unique_ptr<RooAbsCollection>(
6908 if (
d->get()->TestBit(1 << 20))
6909 out.back()->get()->
SetBit(1 << 20);
6911 out.back()->fBrowsables.emplace_back(std::make_shared<xRooNode>(
".sourceds",
d->fComp, *
this));
6913 out.emplace_back(std::make_shared<xRooNode>(
d->fComp, *
this));
6936 if (
b && strcmp(
b->GetName(),
name) == 0)
6951 TH1 *theHist =
nullptr;
6956 theHist =
dynamic_cast<TH1 *
>(o);
6958 theHist =
static_cast<TH1 *
>(theHist->
Clone());
6969 auto vo =
dynamic_cast<TObject *
>(
v);
6970 if (
v &&
obs().
find(vo->GetName())) {
6974 TString::Format(
"my temp hist;%s", strlen(vo->GetTitle()) ? vo->GetTitle() : vo->GetName()),
6975 cat->numTypes(), 0, cat->numTypes());
6977 std::map<int, std::string> cats;
6978 for (
auto &
c : *cat) {
6979 cats[
c.second] =
c.first;
6981 for (
auto &[
_, label] : cats) {
6985 auto _binning =
v->getBinningPtr(
nullptr);
6986 if (_binning->isUniform()) {
6989 TString::Format(
"my temp hist;%s", strlen(vo->GetTitle()) ? vo->GetTitle() : vo->GetName()),
6990 v->numBins(), _binning->lowBound(), _binning->highBound());
6994 TString::Format(
"my temp hist;%s", strlen(vo->GetTitle()) ? vo->GetTitle() : vo->GetName()),
6995 v->numBins(), _binning->array());
6999 throw std::runtime_error(
"Cannot draw dataset without parent PDF");
7002 theHist = _parentPdf->BuildHistogram(
v,
true);
7008 TH1 *xPos =
static_cast<TH1 *
>(theHist->
Clone(
"xPos"));
7010 TH1 *xPos2 =
static_cast<TH1 *
>(theHist->
Clone(
"xPos2"));
7012 auto nHist = std::unique_ptr<TH1>(
static_cast<TH1 *
>(theHist->
Clone(
"nEntries")));
7017 dataGraph->SetName(
GetName());
7018 dataGraph->SetTitle(strlen(theData->GetTitle()) ? theData->GetTitle() : theData->GetName());
7024 dataGraph->SetMarkerStyle(20);
7026 dataGraph->SetMarkerSize(
gStyle->GetMarkerSize());
7039 dataGraph->SetTitle(
TString::Format(
"%s = %f", dataGraph->GetTitle(), dataGraph->GetPointX(0)));
7052 auto _pos = pName.
Index(
'=');
7054 int nevent = theData->numEntries();
7055 for (
int i = 0; i < nevent; i++) {
7058 for (
auto _c : _coords) {
7060 if (cat->getIndex() != theData->get()->getCatIndex(cat->GetName())) {
7066 if (!rv->inRange(theData->get()->getRealValue(rv->GetName()), rv->getStringAttribute(
"coordRange"))) {
7090 theHist->
Fill((
x) ? xvar->
getVal() : 0.5, theData->weight());
7091 nHist->Fill((
x) ? xvar->
getVal() : 0.5, 1);
7099 for (
int i = 0; i < theHist->
GetNbinsX(); i++) {
7100 if (includeZeros || nHist->GetBinContent(i + 1)) {
7103 dataGraph->SetPoint(dataGraph->GetN(),
7108 xErr = (xErr <= 0) ? 0. : sqrt(xErr);
7111 dataGraph->SetPointError(dataGraph->GetN() - 1, xErr, xErr,
7123 dataGraph->GetHistogram()->GetXaxis()->Set(theHist->
GetNbinsX(), 0, theHist->
GetNbinsX());
7124 for (
int i = 1; i <= theHist->
GetNbinsX(); i++)
7125 dataGraph->GetHistogram()->GetXaxis()->SetBinLabel(i, theHist->
GetXaxis()->
GetBinLabel(i));
7150 auto _styleNode =
styles(dataGraph);
7151 if (
auto _style = _styleNode.get<
TStyle>()) {
7152 *
dynamic_cast<TAttLine *
>(dataGraph) = *_style;
7153 *
dynamic_cast<TAttFill *
>(dataGraph) = *_style;
7154 *
dynamic_cast<TAttMarker *
>(dataGraph) = *_style;
7159 throw std::runtime_error(
"Cannot build graph");
7165 if (
auto _w =
ws(); _w) {
7167 for (
auto o : _w->allGenericObjects()) {
7169 _fr->ResetBit(1 << 20);
7172 res->SetBit(1 << 20);
7174 auto allVars = _w->allVars();
7179 throw std::runtime_error(
"Not supported yet");
7193 throw std::runtime_error(
"Not a RooFitResult");
7202 if (
auto _fr =
find(
".fitResult"); _fr)
7204#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
7216 if (sOpt ==
"prefit") {
7223 auto _coefs =
coefs();
7229 std::unique_ptr<RooArgList> _pars(
dynamic_cast<RooArgList *
>(
pars().
argList().selectByAttrib(
"Constant",
false)));
7230 auto fr = std::make_shared<RooFitResult>(
"prefitResult",
"Prefit");
7231 fr->setFinalParList(*_pars);
7232 for (
auto &p : fr->floatParsFinal()) {
7236 if (
auto s = _v->getStringAttribute(
"nominal"); s)
7239 std::shared_ptr<xRooNode> pConstr;
7240 for (
auto &
c : _constr) {
7243 bool isServer =
true;
7247 if (strcmp(s->GetName(), p->GetName()) == 0) {
7262 double prefitVal = 0;
7263 double prefitError = 0;
7264 for (
auto &_d : pConstr->vars()) {
7265 if (strcmp(p->GetName(), _d->get()->GetName()) == 0)
7269 prefitVal = prefitError;
7270 prefitError =
_c->getVal();
7271 }
else if (prefitError == 0) {
7272 prefitError = _d->get<
RooAbsReal>()->getVal();
7278 if (pConstr->get<
RooGaussian>() && pConstr->browse().find(
".sigma")) {
7279 prefitError = pConstr->find(
".sigma")->get<
RooAbsReal>()->getVal();
7285 prefitVal /= prefitError;
7287 prefitError = 1. / sqrt(prefitError);
7289 if (!_v->getStringAttribute(
"nominal"))
7290 _v->setVal(prefitVal);
7291 _v->setError(prefitError);
7300 auto _globs =
globs();
7301 _args.add(_globs.argList());
7302 fr->setConstParList(_args);
7303 std::unique_ptr<RooArgList> _snap(
dynamic_cast<RooArgList *
>(_pars->snapshot()));
7304 for (
auto &p : *_snap) {
7305 if (
auto atr = p->getStringAttribute(
"initVal"); atr &&
dynamic_cast<RooRealVar *
>(p))
7308 fr->setInitParList(*_snap);
7313 if (
auto _w =
ws(); _w) {
7314 auto checkFr = [&](
TObject *o) {
7320 for (
auto p :
pars()) {
7323 if (_fr->floatParsFinal().find(p->GetName()) ||
7325 std::abs(_fr->constPars().getRealValue(p->GetName(), std::numeric_limits<double>::quiet_NaN()) -
7329 _fr->constPars().getCatIndex(p->GetName(), std::numeric_limits<int>().max()))) {
7334 if (!_fr->floatParsFinal().find(p->GetName())) {
7337 std::abs(_fr->floatParsFinal().getRealValue(p->GetName(),
7338 std::numeric_limits<double>::quiet_NaN()) -
7342 _fr->floatParsFinal().getCatIndex(p->GetName(), std::numeric_limits<int>().max()))) {
7351 RooArgList existingFloats(_fr->floatParsFinal());
7352 existingFloats.
remove(newConsts,
true,
true );
7353 auto cov = _fr->reducedCovarianceMatrix(existingFloats);
7354 if (!newFloats.
empty()) {
7356 size_t oldSize = existingFloats.
size();
7357 cov.ResizeTo(oldSize + newFloats.
size(), oldSize + newFloats.
size());
7358 for (
size_t i = 0; i < newFloats.
size(); i++) {
7359 existingFloats.
add(*newFloats.
at(i));
7362 cov(oldSize + i, oldSize + i) = std::pow(
v->getError(), 2);
7366 existingConsts.
remove(newFloats,
true,
true);
7367 existingConsts.
add(newConsts);
7374 auto fr = std::make_shared<RooFitResult>(
TString::Format(
"%s-dirty", _fr->GetName()));
7375 fr->setFinalParList(existingFloats);
7376 fr->setConstParList(existingConsts);
7377 fr->setCovarianceMatrix(cov);
7378 fr->setInitParList(_fr->floatParsInit());
7383 return xRooNode(*_fr, std::make_shared<xRooNode>(*_w, std::make_shared<xRooNode>()));
7388 for (
auto o : _w->allGenericObjects()) {
7389 auto out = checkFr(o);
7394 auto out = checkFr(o);
7407 auto _coefs =
coefs();
7413 std::unique_ptr<RooArgList> _pars(
dynamic_cast<RooArgList *
>(
pars().
argList().selectByAttrib(
"Constant",
false)));
7414 auto fr = std::make_shared<RooFitResult>(
TUUID().AsString());
7416 fr->setFinalParList(*_pars);
7422 for (
int i = 0; i < prevCov->
GetNcols(); i++) {
7423 for (
int j = 0; j < prevCov->
GetNrows(); j++) {
7424 cov(i, j) = (*prevCov)(i, j);
7429 for (
auto &p : fr->floatParsFinal()) {
7430 if (!prevCov || i >= prevCov->
GetNcols()) {
7432 cov(i, i) = pow(
v->getError(), 2);
7439 int covQualBackup = fr->covQual();
7440 fr->setCovarianceMatrix(cov);
7441 fr->setCovQual(covQualBackup);
7446 auto _globs =
globs();
7447 _args.add(_globs.argList());
7448 fr->setConstParList(_args);
7449 std::unique_ptr<RooArgList> _snap(
dynamic_cast<RooArgList *
>(_pars->snapshot()));
7450 for (
auto &p : *_snap) {
7451 if (
auto atr = p->getStringAttribute(
"initVal"); atr &&
dynamic_cast<RooRealVar *
>(p))
7454 fr->setInitParList(*_snap);
7476 if (range && strlen(range)) {
7484 o->setStringAttribute(
"range", range);
7491 std::string &out =
fRange;
7492 if (
auto o =
get<RooAbsArg>(); o && o->getStringAttribute(
"range"))
7493 out = o->getStringAttribute(
"range");
7495 while (out.empty() && _parent) {
7497 out = o->getStringAttribute(
"range");
7498 _parent = _parent->fParent;
7518 for (
auto opt : *defaultOpts) {
7521 for (
auto &i : nllOpts) {
7522 if (
auto o =
l.FindObject(i.GetName())) {
7523 Info(
"nll",
"Overriding NLL Option: %s", o->GetName());
7529 return nll(_data,
l);
7541 std::shared_ptr<xRooNode> mainModel;
7547 throw std::runtime_error(
TString::Format(
"Workspace has multiple models, you must specify which to "
7548 "generate with (found at least %s and %s)",
7549 mainModel->GetName(),
c->GetName()));
7554 return mainModel->generate(fr, expected, seed);
7562 std::string selected;
7564 bool hasDeselected =
false;
7565 for (
auto c :
bins()) {
7567 cName = cName(cName.
Index(
'=') + 1, cName.
Length());
7569 hasDeselected =
true;
7571 if (!fromds.empty())
7573 fromds += cName.
Data();
7576 if (!selected.empty())
7578 selected += cName.
Data();
7581 if (hasDeselected) {
7582 std::string dsetName =
"";
7583 if (!fromds.empty()) {
7586 for (
auto &
d : _dsets) {
7587 if (
d->get()->TestBit(1 << 20)) {
7588 dsetName =
d->get()->GetName();
7592 if (dsetName.empty()) {
7593 throw std::runtime_error(
7594 "Need at least one dataset selected (SetChecked) to use for deselected regions");
7598 if (!fromds.empty()) {
7601 result.
SetName(
TString(result.GetName()) +
"_and_" + dsetName.c_str());
7617 auto _globs =
globs();
7618 bool missingGlobs(
false);
7619 for (
auto glob : _globs) {
7620 if (!_fr->constPars().find(*glob->get<
RooAbsArg>())) {
7621 missingGlobs =
true;
7626 std::unique_ptr<RooFitResult> newFr;
7628 newFr = std::make_unique<RooFitResult>(*_fr);
7629 for (
auto glob : _globs) {
7630 if (!newFr->constPars().find(*glob->get<
RooAbsArg>())) {
7638 auto _pars =
pars();
7639 bool missingPars(
false);
7640 for (
auto par : _pars) {
7643 if (!_fr->constPars().find(*par->get<
RooAbsArg>()) && !_fr->floatParsFinal().find(*par->get<
RooAbsArg>())) {
7650 newFr = std::make_unique<RooFitResult>(*_fr);
7651 for (
auto par : _pars) {
7654 if (!newFr->constPars().find(*par->get<
RooAbsArg>()) &&
7655 !newFr->floatParsFinal().find(*par->get<
RooAbsArg>())) {
7673 if (mc->GetExternalConstraints()) {
7675 for (
auto o : opts) {
7676 optsWithConstraints.
Add(o->Clone(
nullptr));
7679 return xRooNode(*mc->GetPdf(),
fParent).nll(_data, optsWithConstraints);
7688 std::shared_ptr<xRooNode> mainPdf, mainModel, otherPdf;
7690 if (
c->get<RooAbsPdf>()) {
7696 }
else if (
c->get<RooStats::ModelConfig>()) {
7700 throw std::runtime_error(
TString::Format(
"Workspace has multiple models, you must specify which to "
7701 "build nll with (found at least %s and %s)",
7702 mainModel->GetName(),
c->GetName()));
7707 return mainModel->nll(_data, opts);
7710 throw std::runtime_error(
TString::Format(
"Workspace has multiple pdfs, you must specify which to "
7711 "build nll with (found at least %s and %s)",
7712 mainPdf->GetName(), otherPdf->GetName()));
7714 return mainPdf->nll(_data, opts);
7722 std::string selected;
7723 bool hasDeselected =
false;
7724 for (
auto c :
bins()) {
7725 if (!
c->get<RooAbsReal>()->isSelectedComp()) {
7726 hasDeselected =
true;
7728 TString cName(
c->GetName());
7729 cName = cName(cName.Index(
'=') + 1, cName.Length());
7730 if (!selected.empty())
7732 selected += cName.Data();
7739 if (!_data.
get<RooAbsData>()) {
7742 if (strlen(_data.
GetName()) == 0) {
7745 _d = std::make_shared<xRooNode>(asi.first, *
this);
7748 std::make_shared<xRooNode>(
".globs", std::const_pointer_cast<RooAbsCollection>(asi.second), *_d));
7753 return nll(*_d, opts);
7758 me.push_back(std::make_shared<xRooNode>(_data));
7759 return nll(*me.datasets().at(_data.
GetName()), opts);
7762 auto _globs = _data.
globs();
7764 auto _opts = std::shared_ptr<RooLinkedList>(
new RooLinkedList, [](RooLinkedList *
l) {
7769 RooArgSet _globsSet(_globs.argList());
7775 for (
int i = 0; i < opts.GetSize(); i++) {
7776 if (strlen(opts.At(i)->GetName()) == 0)
7778 if (strcmp(opts.At(i)->GetName(),
"GlobalObservables") == 0) {
7781 _opts->Add(opts.At(i)->Clone(
nullptr));
7789 std::dynamic_pointer_cast<RooAbsData>(_data.
fComp), *_opts);
7887 auto rangeName = (_range.empty()) ?
GetRange() : _range;
7888 if (!rangeName.empty()) {
7889 std::vector<TString> patterns;
7892 patterns.emplace_back(pattern);
7899 for (
auto &
c :
bins()) {
7901 cName = cName(cName.
Index(
'=') + 1, cName.
Length());
7902 _cat.setLabel(cName);
7903 bool matchAny =
false;
7904 for (
auto &p : patterns) {
7909 if (_cat.hasRange(p) && _cat.inRange(p)) {
7914 if ((matchAny && !invert) || (!matchAny && invert)) {
7923 std::vector<TObject *> funcs;
7925 bool matchAny =
false;
7926 for (
auto &p : patterns) {
7932 if (!((matchAny && !invert) || (!matchAny && invert)))
7933 funcs.push_back(
c->get());
7935 for (
auto &
c : funcs)
7937 if (!funcs.empty()) {
7939 _pdf->setFloor(
false);
7951 for (
auto c : _pars) {
7952 bool matchAny =
false;
7953 for (
auto &p : patterns) {
7959 if (!((matchAny && !invert) || (!matchAny && invert))) {
7963 _pars.
remove(_remPars,
true);
7965 auto _tmp = fr->reducedCovarianceMatrix(_pars);
7966 int covQualBackup = fr->covQual();
7967 fr->setCovarianceMatrix(_tmp);
7968 fr->setCovQual(covQualBackup);
7969 const_cast<RooArgList &
>(fr->floatParsFinal())
7978 bool notAllArgs =
false;
7979 bool isVars = (strcmp(
GetName(),
".vars") == 0);
7980 for (
auto c : *
this) {
7981 nobs += (
c->fFolder ==
"!robs" ||
c->fFolder ==
"!globs");
7982 bool matchAny =
false;
7983 for (
auto &p : patterns) {
7985 (isVars && p ==
"x" && (
c->fFolder ==
"!robs" ||
c->fFolder ==
"!globs") && nobs == 1)) {
7990 if ((matchAny && !invert) || (!matchAny && invert)) {
8089 return static_cast<RooAbsPdf *
>(
intpdf.absArg())->expectedEvents(nset);
8103 RooArgList **pars =
nullptr,
bool asymHi =
false,
bool asymLo =
false)
8109 if (
auto rrv =
dynamic_cast<const RooRealVar *
>(&
f); rrv) {
8110 if (
auto frrrv =
dynamic_cast<RooRealVar *
>(fr.
floatParsFinal().
find(*rrv)); frrrv) {
8114 return rrv->getErrorHi();
8115 }
else if (asymLo) {
8116 return rrv->getErrorLo();
8118 return rrv->getError();
8122 RooArgList *_pars = (pars) ? *pars : nullptr;
8126 RooArgSet allParamsInAbsReal;
8127 f.getParameters(&nset, allParamsInAbsReal);
8129 _pars =
new RooArgList;
8132 auto rrvInAbsReal =
static_cast<RooRealVar
const *
>(allParamsInAbsReal.
find(*rrvFitRes));
8135 if (rrvFitRes->getError() <= std::abs(rrvFitRes->getVal()) * std::numeric_limits<double>::epsilon())
8144 if (std::abs(rrvInAbsReal->getVal() - rrvFitRes->getVal()) > 0.01 * rrvFitRes->getError()) {
8145 std::stringstream errMsg;
8146 errMsg <<
"RooAbsReal::getPropagatedError(): the parameters of the RooAbsReal don't have"
8147 <<
" the same values as in the fit result! The logic of getPropagatedError is broken in this case."
8148 <<
" \n " << rrvInAbsReal->GetName() <<
" : " << rrvInAbsReal->getVal() <<
" vs "
8149 << rrvFitRes->getVal();
8151 throw std::runtime_error(errMsg.str());
8154 _pars->
add(*rrvInAbsReal);
8167 double nomVal =
f.getVal(nset);
8169 for (std::size_t ivar = 0; ivar < _pars->
size(); ivar++) {
8171 auto &rrv =
static_cast<RooRealVar &
>((*_pars)[ivar]);
8172 auto *frrrv =
static_cast<RooRealVar *
>(fr.
floatParsFinal().find(rrv));
8174 double cenVal = rrv.getVal();
8175 double plusVar, minusVar, errVal;
8177 if (asymHi || asymLo) {
8178 errVal = frrrv->getErrorHi();
8179 rrv.setVal(cenVal + errVal);
8180 plusVar =
f.getVal(nset);
8181 errVal = frrrv->getErrorLo();
8182 rrv.setVal(cenVal + errVal);
8183 minusVar =
f.getVal(nset);
8186 plusVar = std::max(plusVar, minusVar);
8187 minusVar = 2 * nomVal - plusVar;
8190 minusVar = std::min(plusVar, minusVar);
8191 plusVar = 2 * nomVal - minusVar;
8194 errVal =
sqrt(V(ivar, ivar));
8196 rrv.setVal(cenVal + errVal);
8197 plusVar =
f.getVal(nset);
8199 rrv.setVal(cenVal - errVal);
8200 minusVar =
f.getVal(nset);
8202 F[ivar] = (plusVar - minusVar) * 0.5;
8216 std::vector<double> errVec(_pars->
size());
8217 for (std::size_t i = 0; i < _pars->
size(); i++) {
8218 errVec[i] = std::sqrt(V(i, i));
8219 for (std::size_t j = i; j < _pars->
size(); j++) {
8220 C(i, j) = V(i, j) / std::sqrt(V(i, i) * V(j, j));
8226 double sum =
F * (
C *
F);
8242 fFunc(
"func",
"func", this,
f),
8243 fCoef(
"coef",
"coef", this),
8244 fExpPdf(
"expPdf",
"expPdf", this)
8249 fCoef.setArg(*coef);
8251 if (expPdf && expPdf->canBeExtended() && !(coef &&
dynamic_cast<RooAddPdf *
>(expPdf))) {
8252 fExpPdf.setArg(*expPdf);
8254 _p && _p->canBeExtended() && !(coef &&
dynamic_cast<RooAddPdf *
>(_p))) {
8272 return fFunc->binBoundaries(obs, xlo, xhi);
8290#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 28, 00)
8292 if (std::isnan(oo)) {
8302 auto rrvInAbsReal =
static_cast<RooRealVar const *
>(allParamsInAbsReal.
find(*rrvFitRes));
8306 if (rrvFitRes->namePtr() ==
namePtr())
8310 if (!rrvFitRes->hasError() ||
8311 rrvFitRes->getError() <= std::abs(rrvFitRes->getVal()) * std::numeric_limits<double>::epsilon())
8320 if (std::abs(rrvInAbsReal->getVal() - rrvFitRes->getVal()) > 0.01 * rrvFitRes->getError()) {
8321 std::stringstream errMsg;
8323 <<
"RooAbsReal::getPropagatedError(): the parameters of the RooAbsReal don't have"
8324 <<
" the same values as in the fit result! The logic of getPropagatedError is broken in this case.";
8326 throw std::runtime_error(errMsg.str());
8329 paramList.
add(*rrvInAbsReal);
8331 if (paramList.
empty())
8334 std::vector<double> plusVar;
8335 std::vector<double> minusVar;
8336 plusVar.reserve(paramList.
size());
8337 minusVar.reserve(paramList.
size());
8343 for (std::size_t ivar = 0; ivar < paramList.
size(); ivar++) {
8345 auto &rrv =
static_cast<RooRealVar &
>(paramList[ivar]);
8347 double cenVal = rrv.getVal();
8348 double errVal = sqrt(V(ivar, ivar));
8360 rrv.setVal(cenVal + errVal);
8361 plusVar.push_back(
getVal(nset_in));
8364 rrv.setVal(cenVal - errVal);
8365 minusVar.push_back(
getVal(nset_in));
8366#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
8390 std::vector<double> errVec(paramList.
size());
8391 for (std::size_t i = 0; i < paramList.
size(); i++) {
8392 errVec[i] = std::sqrt(V(i, i));
8393 for (std::size_t j = i; j < paramList.
size(); j++) {
8394 C(i, j) = V(i, j) / std::sqrt(V(i, i) * V(j, j));
8401 for (
unsigned int j = 0; j < plusVar.size(); j++) {
8402 F[j] = (plusVar[j] - minusVar[j]) / 2;
8406 double sum =
F * (C *
F);
8416 if (frv->getError() > 1
e-20) {
8417 fpf_stripped.
add(*frv);
8432 std::vector<int> fpf_idx;
8433 for (
Int_t i = 0; i < fpf.
size(); i++) {
8436 paramList.
add(*par);
8437 fpf_idx.push_back(i);
8441 std::vector<double> plusVar, minusVar;
8447 for (
Int_t ivar = 0; ivar < paramList.
size(); ivar++) {
8451 double cenVal = rrv.
getVal();
8452 double errVal = sqrt(V(ivar, ivar));
8455 ((
RooRealVar *)paramList.
at(ivar))->setVal(cenVal + errVal);
8458 plusVar.push_back(cloneFunc->
getVal(nset));
8461 ((
RooRealVar *)paramList.
at(ivar))->setVal(cenVal - errVal);
8464 minusVar.push_back(cloneFunc->
getVal(nset));
8472 std::vector<double> errVec(paramList.
size());
8473 for (
int i = 0; i < paramList.
size(); i++) {
8474 errVec[i] = sqrt(V(i, i));
8475 for (
int j = i; j < paramList.
size(); j++) {
8476 C(i, j) = V(i, j) / sqrt(V(i, i) * V(j, j));
8483 for (
unsigned int j = 0; j < plusVar.size(); j++) {
8484 F[j] = (plusVar[j] - minusVar[j]) / 2;
8488 double sum =
F * (C *
F);
8510 std::cout <<
"Got signal " << signum << std::endl;
8511 if (signum == SIGINT) {
8512 std::cout <<
"Keyboard interrupt while building histogram" << std::endl;
8522 auto _doSterilize = [](
RooAbsArg *obj) {
8525 for (
int i = 0; i < obj->numCaches(); i++) {
8531 p->setNormRange(p->normRange());
8533#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
8538 p->setProxyNormSet(
nullptr);
8539 p->_lastNSet =
nullptr;
8542 obj->setValueDirty();
8546 for (
auto &
c : w->components()) {
8565 nClients =
a->clients().size();
8566 for (
auto obj :
a->clients()) {
8568 if (
a->clients().size() != nClients) {
8573 }
while (
a->clients().size() != nClients);
8580 bool errorsLo,
int nErrorToys)
const
8583 if (!
vars.fComp && strlen(
vars.GetName())) {
8592 out.
fComp = std::shared_ptr<TH1>(
8593 BuildHistogram(
nullptr, !content, errors, -1, -1, fr, errorsHi, errorsLo, nErrorToys,
nullptr, !stack,
false));
8594 }
else if (
vars.size() == 1) {
8596 out.
fComp = std::shared_ptr<TH1>(
8597 BuildHistogram(
v, !content, errors, 1, 0, fr, errorsHi, errorsLo, nErrorToys,
nullptr, !stack,
true));
8599 throw std::runtime_error(
"multi-dim histo not yet supported");
8611 bool errorsHi,
bool errorsLo,
int nErrorToys,
TH1 *templateHist,
bool nostack,
8612 bool setInterp)
const
8627 if (binStart != -1 || binEnd != -1) {
8639 h =
new TH1D(rar->GetName(), rar->GetTitle(), 1, 0, 1);
8640 h->GetXaxis()->SetBinLabel(1, rar->GetName());
8641 h->GetXaxis()->SetTimeFormat(rar->GetName());
8646 bool setTitle =
false;
8651 h =
static_cast<TH1 *
>(templateHist->
Clone(rar->GetName()));
8653 if (
h->GetListOfFunctions())
8654 h->GetListOfFunctions()->Clear();
8655 h->SetTitle(rar->GetTitle());
8662 h =
new TH1D(rar->GetName(), rar->GetTitle(), 1, 0, 1);
8665 h->GetXaxis()->SetBinLabel(1, rar->GetName());
8666 h->SetBinContent(1, rar->getVal());
8667 if (
x->getError()) {
8668 h->SetBinError(1,
x->getError());
8669 h->SetFillStyle(3005);
8670 h->SetFillColor(
h->GetLineColor());
8672 h->SetMaximum(
x->hasMax() ?
x->getMax()
8673 : (
h->GetBinContent(1) + std::max(std::abs(
h->GetBinContent(1) * 0.1), 50.)));
8674 h->SetMinimum(
x->hasMin() ?
x->getMin()
8675 : (
h->GetBinContent(1) - std::max(std::abs(
h->GetBinContent(1) * 0.1), 50.)));
8678 h->SetMarkerSize(0);
8679 h->SetMarkerStyle(0);
8684 TString binningName = (_ax && _ax->GetParent() ==
x) ? _ax->GetName() : rar->getStringAttribute(
"binning");
8685 if (binningName ==
"")
8686 binningName = rar->GetName();
8687 if (
x->hasBinning(binningName)) {
8688 if (
x->getBinning(binningName).isUniform()) {
8690 h =
new TH1D(rar->GetName(), rar->GetTitle(),
x->numBins(binningName) <= 0 ? 100 :
x->numBins(binningName),
8691 x->getMin(binningName),
x->getMax(binningName));
8694 h =
new TH1D(rar->GetName(), rar->GetTitle(),
x->numBins(binningName),
x->getBinning(binningName).array());
8696 h->GetXaxis()->SetTitle(
x->getBinning(binningName).GetTitle());
8698 }
else if (
auto _boundaries =
8699 _or_func( (std::list<double> *)(
nullptr),
8700 rar->binBoundaries(*
x, -std::numeric_limits<double>::infinity(),
8701 std::numeric_limits<double>::infinity()));
8703 std::vector<double> _bins;
8704 for (
auto &
b : *_boundaries) {
8705 if (_bins.empty() || std::abs(_bins.back() -
b) > 1
e-5 * _bins.back())
8709 h =
new TH1D(rar->GetName(), rar->GetTitle(), _bins.size() - 1, &_bins[0]);
8711 }
else if (!
x->hasMax() || !
x->hasMin()) {
8714 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(),
x->getVal() * 0.2,
x->getVal() * 5);
8717 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(),
x->getBinning().array());
8723 h =
new TH1D(rar->GetName(), rar->GetTitle(),
v->numBins(rar->GetName()), 0,
v->numBins(rar->GetName()));
8727 std::map<int, std::string> cats;
8728 for (
auto &
c : *cat) {
8729 cats[
c.second] =
c.first;
8731 for (
auto &[
_, label] : cats) {
8732 h->GetXaxis()->SetBinLabel(i++, label.c_str());
8737 if (
auto o =
dynamic_cast<TObject *
>(
v); o && !setTitle) {
8738 h->GetXaxis()->SetTitle(o->GetTitle());
8742 if (
h->GetXaxis()->IsAlphanumeric()) {
8751 if (
auto s =
styles(
nullptr,
false); s) {
8752 auto _style = s.get<
TStyle>();
8753 static_cast<TAttLine &
>(*h) = *_style;
8754 static_cast<TAttFill &
>(*h) = *_style;
8757 if (strlen(
h->GetXaxis()->GetTitle()) == 0)
8758 h->GetXaxis()->SetTitle(vv->
GetTitle());
8759 auto p =
dynamic_cast<RooAbsPdf *
>(rar);
8766 if (empty && !errors) {
8772 auto _coefs =
coefs();
8784 frn = frn.reduced(_fr.
GetName());
8787 if (!
GETDMP(fr, _finalPars)) {
8800 for (
int i = 0; i < prevCov->
GetNcols(); i++) {
8801 for (
int j = 0; j < prevCov->
GetNrows(); j++) {
8802 cov(i, j) = (*prevCov)(i, j);
8808 if (!prevCov || i >= prevCov->
GetNcols()) {
8809 cov(i, i) = pow(
dynamic_cast<RooRealVar *
>(p2)->getError(), 2);
8813 int covQualBackup = fr->
covQual();
8824 int covQualBackup = fr->
covQual();
8832 bool hasErrors =
false;
8850 binEnd =
h->GetNbinsX();
8852 bool needBinWidth =
false;
8855 if (
x && (p || _coefs.get() || rar->getAttribute(
"density"))) {
8857 needBinWidth =
true;
8861 spdf && spdf->
canBeExtended() && !spdf->getFloor() && !_coefs.get()) {
8873 for (
auto o : _obs) {
8875 rr->removeMin();rr->removeMax();
8876 rr->setStringAttribute(
"coordRange",
nullptr);
8881 rr->removeMin();rr->removeMax();
8882 rr->setStringAttribute(
"coordRange",
nullptr);
8892 bool hasRange =
false;
8893 for (
auto o : normSet) {
8895 rr && (rr->getStringAttribute(
"coordRange")) && strlen(rr->getStringAttribute(
"coordRange"))) {
8905 for (
auto pdf :
bins()) {
8912 dynamic_cast<RooAbsPdf *
>(_pdf)->setNormRange(
"coordRange");
8914 newrar->addPdf(*_pdf, pdf->coords()[s->indexCat().GetName()]->get<
RooCategory>()->
getLabel());
8918 rar = p->createProjection(
8922 dynamic_cast<RooAbsPdf *
>(rar)->setNormRange(
"coordRange");
8926 p->setNormRange(
"coordRange");
8931 rar = std::unique_ptr<RooAbsReal>{rar->createIntegral(
8937 std::unique_ptr<RooAbsReal>{rar->createIntegral(*_obs.get<
RooArgList>() )}
8943 bool scaleExpected = (p && p->canBeExtended() && !_coefs.get());
8949 if (!nostack && p && p->canBeExtended() && _coefs.get()) {
8955 std::unique_ptr<RooArgSet> snap(normSet.
snapshot());
8957 std::vector<double> lapTimes;
8958 bool warned =
false;
8959 if (binStart == -1 && binEnd == -1) {
8964 std::unique_ptr<RooAbsCollection> errorParsSnap;
8974 TString clNameNoNamespace = rar->ClassName();
8975 clNameNoNamespace = clNameNoNamespace(clNameNoNamespace.
Last(
':') + 1, clNameNoNamespace.
Length());
8976 setInterp = (clNameNoNamespace.
Contains(
"Hist") || vvv->
isCategory() || rar->isBinnedDistribution(*vvv) ||
8977 h->GetNbinsX() == 1 || rar->getAttribute(
"BinnedLikelihood") ||
8979 std::unique_ptr<std::list<double>>(rar->binBoundaries(*
dynamic_cast<RooAbsRealLValue *
>(vvv),
8980 -std::numeric_limits<double>::infinity(),
8981 std::numeric_limits<double>::infinity()))))
8984 if (
auto d =
dynamic_cast<RooHistFunc *
>(rar);
d && !
d->isBinnedDistribution(*vvv) &&
h->GetNbinsX() != 1) {
8990 bool allHist =
true;
8992 TString _clName = s->get()->ClassName();
8993 _clName = _clName(_clName.
Last(
':') + 1, _clName.
Length());
8994 if (!(s->get() && _clName.
Contains(
"Hist"))) {
9012 auto l =
static_cast<TH1 *
>(
h->Clone(
"nominal"));
9015 h->GetListOfFunctions()->Add(
l, (setInterp) ?
"lsame" :
"histsame");
9016 h->SetOption(setInterp ?
"e3" :
"e2");
9019 h->SetMarkerSize(0);
9020 h->SetFillStyle(3005);
9021 h->SetFillColor(
h->GetLineColor());
9024 if (nErrorToys > 0) {
9033 errorPars->
add(*par);
9036 errorParsSnap.reset(errorPars->
snapshot());
9037 auto l =
static_cast<TH1 *
>(
h->Clone(
"toys"));
9040 h->GetListOfFunctions()->Add(
9043 if (errorsLo || errorsHi)
9047 for (
int toy = 0; toy < (nErrorToys + 1); toy++) {
9063 if (_vv->getError() == 0)
9068 for (
int i = std::max(1, binStart); i <= std::min(
h->GetNbinsX(), binEnd); i++) {
9071 x->setVal(
h->GetBinCenter(i));
9073 cat->setLabel(
h->GetXaxis()->GetBinLabel(i));
9077 if (
x && !
x->inRange(
"coordRange"))
9081 if (!empty || toy > 0) {
9082 r = rar->getVal(p ? &normSet :
nullptr);
9083#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
9088 if (
r && _coefs.get()) {
9092 r *=
h->GetBinWidth(i);
9094 if (scaleExpected) {
9097 r *= (p->expectedEvents(normSet));
9100 h->SetBinContent(i,
r);
9105 bool doAsym = (errorsHi && errorsLo);
9116 &errorPars, errorsHi, errorsLo);
9117#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
9119 p->_normSet =
nullptr;
9131 *fr, {}, &errorPars, errorsHi,
9137 res *=
h->GetBinWidth(i);
9139 h->SetBinError(i, res);
9147 &errorPars, errorsHi, errorsLo);
9152 *fr, {}, &errorPars, errorsHi, errorsLo);
9155 res *=
h->GetBinWidth(i);
9160 h->SetBinContent(i,
h->GetBinContent(i) + (res -
h->GetBinError(i)) * 0.5);
9161 h->SetBinError(i, (res +
h->GetBinError(i)) * 0.5);
9165 lapTimes.push_back(timeIt.
RealTime());
9166 double time_estimate =
9167 (lapTimes.size() > 1)
9168 ? (
h->GetNbinsX() * (std::accumulate(lapTimes.begin() + 1, lapTimes.end(), 0.) / (lapTimes.size() - 1)))
9170 if (!warned && (lapTimes.at(0) > 10 || (lapTimes.size() > 2 && time_estimate > 60.))) {
9172 t2.
Add(time_estimate);
9173 Warning(
"BuildHistogram",
"Building this histogram will take until %s", t2.
AsString());
9183 Warning(
"BuildHistogram",
"Skipping errors for remaining bins");
9201 *errorPars = *errorParsSnap;
9208 if (errorsLo && errorsHi) {
9209 auto nomHist =
static_cast<TH1 *
>(
h->FindObject(
"nominal"));
9212 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
9213 std::vector<double> vals;
9214 vals.reserve(nErrorToys);
9215 for (
int j = 1; j < (nErrorToys + 1); j++) {
9219 double upVal, downVal;
9220 if (errorsLo || errorsHi) {
9221 std::sort(vals.begin(), vals.end());
9225 downVal = 2. *
h->GetBinContent(i) - upVal;
9227 upVal = 2. *
h->GetBinContent(i) - downVal;
9230 upVal =
h->GetBinContent(i) +
err;
9231 downVal =
h->GetBinContent(i) -
err;
9233 h->SetBinContent(i, (upVal + downVal) * 0.5);
9234 h->SetBinError(i, (upVal - downVal) * 0.5);
9239 std::vector<RooAbsArg *> extra;
9242 for (
auto _pdf : s->servers()) {
9244 extra.push_back(_pdf);
9247 extra.push_back(rar);
9250 for (
auto a : extra)
9256 if (!p && !rar->getAttribute(
"density") && !needBinWidth) {
9257 h->GetYaxis()->SetTitle(rar->getStringAttribute(
"units"));
9258 }
else if ((p && p->canBeExtended()) || (!p && needBinWidth)) {
9259 h->GetYaxis()->SetTitle(
"Events");
9261 h->GetYaxis()->SetTitle(
"Probability Mass");
9263 h->GetYaxis()->SetMaxDigits(3);
9272 auto hCopy =
static_cast<TH1 *
>(
h->Clone(
"copy"));
9276 hCopy->SetStats(
false);
9277 h->GetListOfFunctions()->Add(hCopy,
TString(
h->GetOption()) +
"same");
9278 h->GetListOfFunctions()->Add(hCopy,
"axissame");
9279 TString dOpt = (setInterp) ?
"LF2" :
"";
9292 std::map<std::string, int> colorByTitle;
9293 std::set<std::string> allTitles;
9294 bool titleMatchName =
true;
9295 std::map<std::string, TH1 *> histGroups;
9296 std::vector<TH1 *> hhs;
9297 std::set<std::pair<size_t,TH1*>> ordered_hhs;
9298 std::set<TH1 *> histsWithBadTitles;
9304 if (!rarNode->components().empty()) {
9305 auto comps = rarNode->components()[0];
9306 for (
auto &
c : *comps) {
9307 if (
c->fFolder ==
"!.coeffs" ||
c->fFolder ==
"!.coeffpars")
9311 if (!cms_coefs.
empty()) {
9313 std::shared_ptr<TH1> prevHist(
static_cast<TH1 *
>(
h->Clone()));
9320 std::unique_ptr<RooAbsReal> forig(
9321 dynamic_cast<RooAbsReal *
>(rarNode->components()[0]->get()->
Clone(
"tmpCopy0")));
9322 for (
auto c : cms_coefs) {
9326 forig->redirectServers(
RooArgSet(zero),
false,
true);
9327 std::unique_ptr<RooAbsReal>
f(
dynamic_cast<RooAbsReal *
>(forig->Clone(
"tmpCopy")));
9331 auto hh =
xRooNode(*
f, *
this).BuildHistogram(
v);
9332 hh->SetName(
c->GetName());
9335 if (strlen(hh->GetTitle()) == 0) {
9336 hh->SetTitle(
c->GetName());
9340 hh->SetTitle(
TString(
TString(hh->GetTitle())(idx+6,strlen(hh->GetTitle()))));
9342 histsWithBadTitles.insert(hh);
9343 }
else if (strcmp(hh->GetName(), hh->GetTitle()) == 0) {
9344 histsWithBadTitles.insert(hh);
9346 titleMatchName &= (
TString(
c->GetName()) == hh->GetTitle() ||
9348 std::shared_ptr<TH1> nextHist(
static_cast<TH1 *
>(hh->Clone()));
9349 hh->Add(prevHist.get(), -1.);
9352 hh->TH1::Reset(
"ICE");
9353 ordered_hhs.insert(std::pair(ordered_hhs.size(),hh));
9354 prevHist = nextHist;
9360 for (
auto &chan :
bins()) {
9361 TString chanName(chan->GetName());
9362 chanName = chanName(chanName.
Index(
"=") + 1, chanName.
Length());
9363 auto samps = chan->mainChild();
9366 for (
auto &samp : samps.components()) {
9367 auto hh =
static_cast<TH1 *
>(
h->Clone(samp->GetName()));
9369 hh->SetTitle(samp->GetTitle());
9370 if (strlen(hh->GetTitle()) == 0) {
9371 hh->SetTitle(samp->GetName());
9372 histsWithBadTitles.insert(hh);
9373 }
else if (strcmp(hh->GetName(), hh->GetTitle()) == 0) {
9374 histsWithBadTitles.insert(hh);
9376 hh->SetTitle(
TString(hh->GetTitle())
9379 titleMatchName &= (
TString(samp->GetName()) == hh->GetTitle() ||
9381 hh->SetBinContent(hh->GetXaxis()->FindFixBin(chanName), samp->GetContent());
9382 ordered_hhs.insert(std::pair(ordered_hhs.size(),hh));
9386 for (
auto &samp : rarNode->components()) {
9387 auto hh = samp->BuildHistogram(
9388 v, empty,
false , binStart, binEnd, _fr,
false,
false, 0,
h,
true,
9390 hh->SetName(samp->GetName());
9394 if (strlen(hh->GetTitle()) == 0) {
9395 hh->SetTitle(samp->GetName());
9396 histsWithBadTitles.insert(hh);
9397 }
else if (strcmp(hh->GetName(), hh->GetTitle()) == 0) {
9398 histsWithBadTitles.insert(hh);
9400 titleMatchName &= (
TString(samp->GetName()) == hh->GetTitle() ||
9406 for(
auto& [
_,hh] : ordered_hhs) {
9411 for (
auto &hh : hhs) {
9412 allTitles.insert(hh->GetTitle());
9417 size_t e = std::min(allTitles.begin()->size(), allTitles.rbegin()->size());
9419 bool goodPrefix =
false;
9420 std::string commonSuffix;
9421 if (titleMatchName && hhs.size() > 1) {
9422 while (ii <
e - 1 && allTitles.begin()->at(ii) == allTitles.rbegin()->at(ii)) {
9424 if (allTitles.begin()->at(ii) ==
'_' || allTitles.begin()->at(ii) ==
' ')
9430 while (!stop && commonSuffix.size() <
size_t(
e - 1)) {
9431 commonSuffix = allTitles.begin()->substr(allTitles.begin()->length() - commonSuffix.length() - 1);
9432 for (
auto &
tt : allTitles) {
9434 commonSuffix = commonSuffix.substr(1);
9440 if (commonSuffix.find(
'_') == std::string::npos) {
9443 commonSuffix = commonSuffix.substr(commonSuffix.find(
'_'));
9452 std::map<std::string, std::string> reducedTitles;
9453 while (reducedTitles.size() != allTitles.size()) {
9455 std::map<std::string, int> titlesMap;
9456 for (
auto &s : allTitles) {
9457 if (reducedTitles.count(s))
9459 titlesMap[s.substr(0, jj)]++;
9461 for (
auto &s : allTitles) {
9462 if (titlesMap[s.substr(0, jj)] == 1 && (jj >= s.length() || s.at(jj) ==
' ' || s.at(jj) ==
'_')) {
9463 reducedTitles[s] = s.substr(0, jj);
9469 for (
auto ritr = hhs.rbegin(); ritr != hhs.rend(); ++ritr) {
9470 if (!histsWithBadTitles.count((*ritr))) {
9473 auto _title = (hhs.size() > 5) ? reducedTitles[(*ritr)->GetTitle()] : (*ritr)->GetTitle();
9474 _title = _title.substr(ii < _title.size() ? ii : 0);
9475 if (!commonSuffix.empty() &&
TString(_title).
EndsWith(commonSuffix.c_str()))
9476 _title = _title.substr(0, _title.length() - commonSuffix.length());
9477 (*ritr)->SetTitle(_title.c_str());
9481 for (
auto &hh : hhs) {
9483 if (histGroups.find(hh->GetTitle()) == histGroups.end()) {
9484 histGroups[hh->GetTitle()] = hh;
9487 histGroups[hh->GetTitle()]->Add(hh);
9492 auto hhMin = (hh->GetMinimum() == 0) ? hh->GetMinimum(1
e-9) : hh->GetMinimum();
9493 if (!stack->
GetHists() &&
h->GetMinimum() > hhMin) {
9494 auto newMin = hhMin - (
h->GetMaximum() - hhMin) *
gStyle->GetHistTopMargin();
9495 if (hhMin >= 0 && newMin < 0)
9496 newMin = hhMin * 0.99;
9510 stack->
Add(hh, thisOpt);
9513 h->GetListOfFunctions()->AddFirst(stack,
"noclear same");
9525 for (
auto ho : *ll) {
9526 TH1 *hh =
dynamic_cast<TH1 *
>(ho);
9529 bool createdStyle = (
xRooNode(*hh, *
this).styles(
nullptr,
false).get<
TStyle>() ==
nullptr);
9543 for (
auto ho2 : *ll) {
9544 TH1 *hh2 =
dynamic_cast<TH1 *
>(ho2);
9547 auto _styleNode =
xRooNode(*hh2, *
this).styles(hh2,
false);
9548 auto _style = _styleNode.get<
TStyle>();
9557 auto _styleNode =
xRooNode(*hh, *
this).styles(hh);
9558 if (
auto _style = _styleNode.get<
TStyle>()) {
9559 *
dynamic_cast<TAttLine *
>(hh) = *_style;
9560 *
dynamic_cast<TAttFill *
>(hh) = *_style;
9580 push_back(std::make_shared<xRooNode>(data));
9588 return std::numeric_limits<double>::quiet_NaN();
9589 return node->GetBinContent(bin);
9595 if (binStart != binEnd || !
fParent) {
9600 std::vector<double> out;
9609 if (binStart == binEnd && binStart == -1) {
9612 for (
int i = 0; i <
g->GetN(); i++)
9613 integral +=
g->GetPointY(i);
9614 out.push_back(integral);
9618 for (
int i = binStart - 1; i <
g->GetN() && (binEnd == 0 || i < binEnd); i++) {
9619 out.push_back(
g->GetPointY(i));
9625 bool doIntegral =
false;
9626 if (binStart == binEnd && binStart == -1) {
9636 binEnd =
h->GetNbinsX();
9640 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
9641 tot +=
h->GetBinContent(i);
9645 for (
int i = binStart; i <= binEnd; i++) {
9646 out.push_back(
h->GetBinContent(i));
9657 for (
auto &
l :
a->servers()) {
9658 if (
l->getAttribute(
"MAIN_MEASUREMENT") ||
l->InheritsFrom(
"RooRealSumPdf") ||
l->InheritsFrom(
"RooAddPdf")) {
9666 if (strcmp(
l->GetName(),
GetName()) == 0) {
9677 if (
auto o =
get(); o) {
9686#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
9690 for (
int i = 0; i < p->
fCGnx; i++) {
9691 for (
int j = 0; j < p->
fCGny; j++) {
9702 for (
Int_t j = nymax; j >= 0; j--) {
9703 for (
Int_t i = nxmax; i >= 0; i--) {
9704 if (p->
Collide(i, j, iw, ih)) {
9715 return p->
PlaceBox(o, w,
h, xl, yb,
"trw");
9723 gPad->PaintModified();
9729 auto l =
new TPaveText(
gPad->GetLeftMargin() + 0.02, 1. -
gPad->GetTopMargin() - 0.08, 0.6,
9730 1. -
gPad->GetTopMargin() - 0.08);
9731 l->SetBorderSize(0);
9732 if (
l->GetTextSize() == 0)
9733 l->SetTextSize(
gStyle->GetTitleYSize());
9740 l->ConvertNDCtoPad();
9746 if (
auto p =
dynamic_cast<TLegend *
>(
gPad->GetPrimitive(
"legend")); p) {
9749 double w = p->GetX2NDC() - p->GetX1NDC();
9750 double h = p->GetY2NDC() - p->GetY1NDC();
9752 gPad->PaintModified();
9756 x = std::max(
x, (
gPad->GetLeftMargin() + 0.02));
9757 y = std::max(
y, (
gPad->GetBottomMargin() + 0.02));
9758 x = std::min(
x, (1. -
gPad->GetRightMargin() - 0.02) - w);
9759 y = std::min(
y, (1. -
gPad->GetTopMargin() - 0.02) -
h);
9760 h = std::min(
h, (1. -
gPad->GetTopMargin() - 0.02) -
y);
9761 w = std::min(w, (1. -
gPad->GetRightMargin() - 0.02) -
x);
9773 while ((p != p->GetMother()) && (p = p->GetMother())) {
9774 if (
auto q =
dynamic_cast<TVirtualPad *
>(p->GetPrimitive(
"legend"));
q) {
9782 if (p && strcmp(p->GetName(),
"legend") == 0) {
9783 if (
l =
dynamic_cast<TLegend *
>(p->GetPrimitive(
"legend"));
l || !create)
9787 gPad->GetBottomMargin());
9788 l->SetBorderSize(1);
9792 l =
new TLegend(0.6, 1. -
gPad->GetTopMargin() - 0.08, 0.75, 1. -
gPad->GetTopMargin() - 0.08);
9793 l->SetBorderSize(0);
9795 if (
l->GetTextSize() == 0) {
9796 l->SetTextSize(
gStyle->GetTitleYSize());
9797 l->SetTextFont(
gStyle->GetTitleFont(
"Y"));
9803 l->SetName(
"legend");
9805 l->ConvertNDCtoPad();
9812 auto i = s.find(
"\n");
9813 if (i == std::string::npos) {
9816 return std::string(
"#splitline{") + s.substr(0, i) +
"}{" +
formatLegendString(s.substr(i + 1)) +
"}";
9825 for (
auto a : *
l->GetListOfPrimitives()) {
9829 if (
l->GetListOfPrimitives()->GetEntries() > 20)
9834 l->GetListOfPrimitives()->RemoveLast();
9835 l->GetListOfPrimitives()->AddFirst(
e);
9836 if (
auto nObj =
l->GetListOfPrimitives()->GetEntries(); nObj > 0) {
9838 int nn =
l->GetNColumns();
9840 if (nObj > 1 && (nObj % nn) == 1) {
9841 l->SetNColumns(
l->GetNColumns() + 1);
9842 if (
l->GetBorderSize() == 0) {
9843 l->SetX1NDC(
l->GetX2NDC() - 0.15 *
l->GetNColumns());
9846 if (
l->GetBorderSize() == 0) {
9847 l->SetY1NDC(
l->GetY2NDC() - 0.05 *
gPad->GetHNDC() * std::ceil((
double(nObj) /
l->GetNColumns())));
9863 fPad->GetCanvas()->Paint();
9864 fPad->GetCanvas()->Update();
9865#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
9866 fPad->GetCanvas()->ResetUpdated();
9881 if (
gROOT->FromPopUp()) {
9882 gROOT->SetFromPopUp(
false);
9885 }
catch (
const std::exception &
e) {
9888 (
gROOT->GetListOfBrowsers()->At(0))
9891 "Exception",
e.what(),
9894 gROOT->SetFromPopUp(
true);
9922 auto _dsets =
fParent->datasets();
9925 for (
auto &
d : _dsets) {
9926 if (
d->get()->TestBit(1 << 20)) {
9927 dsetName =
d->get()->GetName();
9932 hs.limits(
"cls visualize");
9933 hs.SetName(
TUUID().AsString());
9944 [](
double a,
double b,
double) {
9947 if (
b == 0 &&
a == 0)
9954 [](
double n,
double b,
double sigma) {
9958 t0 = 2. * (((
n == 0) ? 0 :
n * log(
n /
b)) - (
n -
b));
9961 double b_hathat = 0.5 * (
b - sigma2 + sqrt(pow(
b - sigma2, 2) + 4 *
n * sigma2));
9964 t0 = 2. * (((
n == 0) ? 0 :
n * log(
n / b_hathat)) + b_hathat -
n + pow(
b - b_hathat, 2) / (2. * sigma2));
9968 return (
n >=
b) ? sqrt(t0) : -sqrt(t0);
9976 std::vector<double> xPoints;
9979 int _idx = sOpt2.
Index(
"x=");
9980 int _eidx = sOpt2.
Index(
';', _idx);
9981 TString varPart = sOpt(_idx + 2, (_eidx < 0 ? sOpt2.
Length() : _eidx) - (_idx + 2));
9984 if (
auto _idx2 = varPart.
Index(
"("); _idx2 > 0) {
9985 varName = varPart(0, _idx2);
9995 }
else if (ii == 1) {
9997 }
else if (ii == 2) {
10005 for (
double x = min;
x <= max;
x += (max - min) / (nBins - 1)) {
10006 xPoints.push_back(
x);
10008 }
else if (nBins == 1)
10009 xPoints.push_back((min + max) / 2.);
10015 if (xPoints.empty() && !
obs().
find(varName.
Data()) &&
10018 for (
int i = 0; i <
v->numBins(
GetName()); i++) {
10024 sOpt2 =
TString(sOpt2(0, _idx)) + sOpt2(_idx + 2 + varPart.
Length() + 1, sOpt2.
Length());
10038 forceNames = sOpt(sOpt2.
Index(
"force") + 5, sOpt2.
Length());
10039 sOpt = sOpt(0, sOpt2.
Index(
"force"));
10040 sOpt2 = sOpt2(0, sOpt2.
Index(
"force"));
10042 Error(
"Draw",
"Can only compute forces with PDFs");
10046 bool hasOverlay = sOpt2.
Contains(
"overlay");
10050 overlayName = sOpt(sOpt2.
Index(
"overlay") + 7, sOpt2.
Length());
10051 sOpt = sOpt(0, sOpt2.
Index(
"overlay"));
10052 sOpt2 = sOpt2(0, sOpt2.
Index(
"overlay"));
10055 sOpt +=
"auxRatio";
10057 sOpt +=
"auxSignif";
10059 std::string auxPlotTitle;
10070 bool nostack = sOpt.
Contains(
"nostack");
10072 bool hasSame = sOpt.
Contains(
"same");
10074 bool hasGoff = sOpt.
Contains(
"goff");
10078 bool hasText = sOpt.
Contains(
"text");
10079 bool hasTexte = sOpt.
Contains(
"texte");
10080 bool hasErrorOpt = sOpt.
Contains(
"e");
10084 }
else if (hasText) {
10087 if (auxPlotTitle ==
"Signif")
10088 hasErrorOpt =
true;
10094 TH1 *hAxis =
nullptr;
10096 auto clearPad = []() {
10098 if (
gPad->GetNumber() == 0) {
10099 gPad->SetBottomMargin(
gStyle->GetPadBottomMargin());
10100 gPad->SetTopMargin(
gStyle->GetPadTopMargin());
10101 gPad->SetLeftMargin(
gStyle->GetPadLeftMargin());
10102 gPad->SetRightMargin(
gStyle->GetPadRightMargin());
10110 if (!hasSame || !pad) {
10121 if (hAxis =
dynamic_cast<TH1 *
>(o); hAxis)
10141 auto adjustYRange = [&](
double min,
double max,
TH1 *hh =
nullptr,
bool symmetrize =
false) {
10145 max +=
gStyle->GetHistTopMargin() * (max - min);
10147 min = std::max(min * 0.9, min -
gStyle->GetHistTopMargin() * (max - min));
10149 double ymin = hh->GetMinimum();
10150 double ymax = hh->GetMaximum();
10151 if (hh->GetMaximumStored() == -1111)
10153 if (hh->GetMinimumStored() == -1111) {
10154 if (
gStyle->GetHistMinimumZero() &&
ymax >= 0) {
10156 }
else if (
ymin < 0) {
10164 if (hh->GetSumw2()) {
10165 double smallestErrDown3 = -std::numeric_limits<double>::infinity();
10166 double smallestErrUp3 = std::numeric_limits<double>::infinity();
10167 for (
int i = 1; i <= hh->GetNbinsX(); i++) {
10168 smallestErrDown3 = std::max(smallestErrDown3, hh->GetBinContent(i) - 3 * hh->GetBinError(i));
10169 smallestErrUp3 = std::min(smallestErrUp3, hh->GetBinContent(i) + 3 * hh->GetBinError(i));
10171 max = std::max(max, smallestErrUp3);
10172 min = std::min(min, smallestErrDown3);
10174 bool change =
false;
10186 double down = hh->GetBinContent(1) -
ymin;
10187 double up =
ymax - hh->GetBinContent(1);
10189 ymax = hh->GetBinContent(1) + down;
10191 ymin = hh->GetBinContent(1) - up;
10194 if (hh == hAxis && pad && !pad->
GetLogy() &&
ymin > 0 && (log10(
ymax) - log10(max)) >= 3) {
10198 if (hh == hAxis && pad &&
ymin == 0 && pad->
GetLogy()) {
10203 hh->SetMinimum(
ymin);
10204 hh->SetMaximum(
ymax);
10205 hh->GetYaxis()->Set(1,
ymin,
ymax);
10206 hh->SetAxisRange(
ymin,
ymax,
"Y");
10212 double ymax = -std::numeric_limits<double>::infinity();
10213 double ymin = std::numeric_limits<double>::infinity();
10214 for (
int i = 0; i <
gr->GetN(); i++) {
10215 ymax = std::max(
ymax,
gr->GetPointY(i) +
gr->GetErrorYhigh(i));
10216 ymin = std::min(
ymin,
gr->GetPointY(i) -
gr->GetErrorYlow(i));
10218 return std::make_pair(
ymin,
ymax);
10221 if (!xPoints.empty()) {
10230 for (
auto &
x : xPoints) {
10241 out->
Draw(
TString(hasSame ?
"L" :
"AL") + (hasErrorOpt ?
"3" :
""));
10262 gPad->GetFrame()->SetFillStyle(1001);
10263 gPad->SetTopMargin(0);
10264 gPad->SetBottomMargin(0);
10265 gPad->SetName(
"pull");
10269 Error(
"Draw",
"Couldn't find pull graph");
10272 pullGraph->
SetName(
"nominal");
10276 auto scaleHist =
static_cast<TH1 *
>(pullGraph->FindObject(
"scales"));
10278 throw std::runtime_error(
"Could not find scales in fit result");
10280 for (
auto i = 0; i < pullGraph->GetN(); i++) {
10282 g->SetName(scaleHist->GetXaxis()->GetBinLabel(i + 1));
10285 Warning(
"Draw",
"Found a non-var in the floatParsFinal list: %s - this shouldn't happen",
g->GetName());
10289 "%s=%g +/- %s [%g,%g]", strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName(), _p->getVal(),
10290 _p->hasAsymError() ?
TString::Format(
"(%g,%g)", _p->getAsymErrorHi(), _p->getAsymErrorLo()).Data()
10292 scaleHist->GetBinContent(i + 1), scaleHist->GetBinError(i + 1)));
10293 g->SetPoint(0, pullGraph->GetPointX(i), pullGraph->GetPointY(i));
10294 g->SetPointEYhigh(0, pullGraph->GetErrorYhigh(i));
10295 g->SetPointEYlow(0, pullGraph->GetErrorYlow(i));
10296 g->SetEditable(
true);
10297 g->SetHighlight(
true);
10298 g->SetMarkerStyle(20);
10299 g->SetMarkerSize(0.5);
10307 _thisClone->AppendPad();
10321 _simPdf && !(
v && strcmp(_simPdf->indexCat().GetName(),
dynamic_cast<TObject *
>(
v)->GetName()) == 0)) {
10322 auto _channels =
bins();
10324 for (
auto &_v : _channels) {
10325 if (!_v->IsHidden())
10356 int ncols = _simPdf->getStringAttribute(
"ncols") ?
TString(_simPdf->getStringAttribute(
"ncols")).
Atoi() : 0;
10358 dynamic_cast<TPad *
>(pad)->Divide(ncols, std::ceil(
double(_size) / ncols), 1
e-9, 1
e-9);
10360 dynamic_cast<TPad *
>(pad)->DivideSquare(_size, 1
e-9, 1
e-9);
10363 auto _pad = pad->
GetPad(_size);
10366 _pad->SetPad(_pad->GetXlowNDC(), _pad->GetYlowNDC(), 1.0, _pad->GetYlowNDC() + _pad->GetHNDC());
10379 std::vector<TString> chanPatterns;
10380 if (_range && strlen(_range)) {
10383 chanPatterns.emplace_back(pattern);
10386 for (
auto &_v : _channels) {
10387 if (_v->IsHidden())
10393 chanVar.setLabel(cName);
10394 bool inRange = chanPatterns.empty();
10395 for (
auto &p : chanPatterns) {
10396 if (chanVar.inRange(p)) {
10403 if (!hasSame && _size > 1 && (
gStyle->GetTitleFont(
"Y") % 10) == 3)
10404 gPad->SetLeftMargin(std::min(
gPad->GetLeftMargin() * (1. /
gPad->GetWNDC()), 0.3));
10419 for (
auto &_v : *
this) {
10420 if (_v->IsHidden())
10422 if (strcmp(
GetName(),
".vars") == 0) {
10426 if (strcmp(_v->get()->GetName(),
"1") == 0 || strcmp(_v->get()->GetName(),
"ONE") == 0 ||
10429 if (_v->get()->InheritsFrom(
"RooConstVar"))
10440 dynamic_cast<TPad *
>(pad)->DivideSquare(_size, 1
e-9, 1
e-9);
10443 for (
auto &_v : *
this) {
10444 if (_v->IsHidden())
10446 if (strcmp(
GetName(),
".vars") == 0) {
10450 if (strcmp(_v->get()->GetName(),
"1") == 0 || strcmp(_v->get()->GetName(),
"ONE") == 0 ||
10453 if (_v->get()->InheritsFrom(
"RooConstVar"))
10461 if (!hasSame && _size > 1 && (
gStyle->GetTitleFont(
"Y") % 10) == 3)
10462 gPad->SetLeftMargin(std::min(
gPad->GetLeftMargin() * (1. /
gPad->GetWNDC()), 0.3));
10477 _mainChild.Draw(opt);
10491 TH2 *hist =
nullptr;
10492 if (numCorrs < fr->correlationMatrix().GetNcols()) {
10494 std::set<std::pair<double, size_t>> maxCorrs;
10496 double maxCorr = 0;
10502 maxCorrs.insert({maxCorr, i});
10504 std::vector<size_t> topN;
10506 for (
auto itr = maxCorrs.rbegin(); itr != maxCorrs.rend(); ++itr) {
10507 topN.push_back(itr->second);
10513 numCorrs, 0, numCorrs, numCorrs, 0, numCorrs);
10514 for (
size_t i = 0; i < topN.size(); i++) {
10517 for (
size_t j = 0; j < topN.size(); j++) {
10534 gStyle->SetPaintTextFormat(
".1f");
10539 gStyle->SetPaintTextFormat(
b);
10540 gPad->SetGrid(1, 1);
10551 std::string poiName;
10554 poiName = sOpt3(sOpt3.
Index(
"breakdown:") + 10, sOpt3.
Length());
10557 if (_poi->empty()) {
10558 throw std::runtime_error(
"No floating poi in the fit");
10559 }
else if (_poi->size() != 1) {
10560 throw std::runtime_error(
"Multiple poi in the fit");
10562 poiName = _poi->first()->GetName();
10566 throw std::runtime_error(
TString::Format(
"Cannot find parameter %s", poiName.c_str()));
10568 std::set<std::string> groups;
10572 }
else if (p->getStringAttribute(
"group")) {
10573 groups.insert(p->getStringAttribute(
"group"));
10575 groups.insert(p->GetTitle());
10582 TString::Format(
"%s: %g #pm %g",
poi->GetTitle(), roundedVal.first, roundedVal.second),
10583 groups.size() + 1);
10586 roundedVal.second *= .1;
10594 for (
auto group : groups) {
10596 double variance = pow(
dynamic_cast<RooRealVar *
>(
poi)->getError(), 2);
10600 }
else if ((p->getStringAttribute(
"group") &&
group == p->getStringAttribute(
"group")) ||
10601 (!p->getStringAttribute(
"group") &&
group == p->GetTitle())) {
10606 int idx =
pars.index(poiName.c_str());
10608 if (reducedVar > variance) {
10609 Warning(
"Draw",
"breakdown group %s variance bigger than preceding?",
group.c_str());
10615 std::pair(sqrt(variance - reducedVar), roundedVal.second));
10643 out->
SetTitle(
"Fit Result Pulls");
10644 std::vector<TString> graphLabels;
10647 ugraph->
SetTitle(
"Fit Result Pulls");
10648 std::vector<TString> ugraphLabels;
10649 std::map<std::string, double> scale;
10650 std::map<std::string, double> offset;
10656 if (std::isnan(_v->getErrorHi()) || std::isnan(_v->getErrorLo())) {
10657 Warning(
"Draw",
"%s error is invalid", _v->GetName());
10662 double prefitError = 0;
10663 double prefitVal = 0;
10664 double customScale = 0;
10667 prefitError = ip->getError();
10668 prefitVal = ip->getVal();
10671 std::shared_ptr<xRooNode> pConstr;
10674 if (_vv->hasRange(
"pullScale")) {
10675 customScale = (_vv->getMax(
"pullScale") - _vv->getMin(
"pullScale")) / 2.;
10677 auto _constr =
xRooNode(_vv, *
this).constraints();
10678 for (
auto &
c : _constr) {
10681 bool isServer =
true;
10685 if (strcmp(s->GetName(), p->GetName()) == 0) {
10706 if (pConstr->get<
RooPoisson>() && pConstr->find(
".x")) {
10707 std::string xName = pConstr->find(
".x")->get()->GetName();
10708 prefitVal = pConstr->find(
".x")->get<
RooAbsReal>()->getVal();
10709 for (
auto &_d : pConstr->vars()) {
10710 if (strcmp(p->GetName(), _d->get()->GetName()) == 0)
10712 if (xName == _d->get()->GetName())
10715 prefitError = _d->get<
RooAbsReal>()->getVal();
10717 if (fr->
constPars().
find(pConstr->find(
".x")->get()->GetName())) {
10722 prefitVal /= prefitError;
10724 prefitError = 1. / sqrt(prefitError);
10725 }
else if (
auto _g = pConstr->get<
RooGaussian>(); _g) {
10727 (pConstr->find(
".sigma")) ? pConstr->find(
".sigma")->get<
RooAbsReal>()->getVal() : prefitError;
10729 (pConstr->find(
".x")) ? pConstr->find(
".x")->get<
RooAbsReal>()->getVal() : 0;
10730 if (pConstr->find(
".x") && fr->
constPars().
find(pConstr->find(
".x")->get()->GetName())) {
10734 if (pConstr->find(
".x") &&
10735 strcmp(p->GetName(), pConstr->find(
".x")->get<
RooAbsReal>()->
GetName()) == 0) {
10737 prefitVal = pConstr->find(
".mean")->get<
RooAbsReal>()->getVal();
10738 if (fr->
constPars().
find(pConstr->find(
".mean")->get()->GetName())) {
10746 prefitError = customScale;
10747 if (prefitError == 0) {
10748 Warning(
"Draw",
"failed to determine prefit error of %s, using post-fit error", p->GetName());
10749 prefitError = _v->getError();
10751 out->
SetPoint(out->
GetN(), out->
GetN(), (_v->getVal() - prefitVal) / prefitError);
10753 (_v->getErrorHi()) / prefitError);
10754 graphLabels.push_back(p->GetName());
10755 scale[p->GetName()] = prefitError;
10756 offset[p->GetName()] = prefitVal;
10760 prefitError = customScale;
10761 if (prefitError == 0) {
10763 prefitError = (std::max({_v->getMax() - _v->getVal(), _v->getVal() - _v->getMin(), 4.}) / 4);
10764 ugraph->
SetPoint(ugraph->
GetN(), ugraph->
GetN(), (_v->getVal() - prefitVal) / prefitError);
10765 ugraph->
SetPointError(ugraph->
GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
10766 (_v->getErrorHi()) / prefitError);
10767 ugraphLabels.push_back(p->GetName());
10769 out->
SetPoint(out->
GetN(), out->
GetN(), (_v->getVal() - prefitVal) / prefitError);
10771 (_v->getErrorHi()) / prefitError);
10772 graphLabels.push_back(p->GetName());
10774 scale[p->GetName()] = prefitError;
10775 offset[p->GetName()] = prefitVal;
10780 prefitError = customScale;
10781 if (prefitError == 0) {
10782 prefitError = (std::max({_v->getMax() - _v->getVal(), _v->getVal() - _v->getMin(), 4.}) / 4);
10784 ugraph->
SetPoint(ugraph->
GetN(), ugraph->
GetN(), (_v->getVal() - prefitVal) / prefitError);
10785 ugraph->
SetPointError(ugraph->
GetN() - 1, 0, 0, (-_v->getErrorLo()) / prefitError,
10786 (_v->getErrorHi()) / prefitError);
10787 ugraphLabels.push_back(p->GetName());
10788 scale[p->GetName()] = prefitError;
10789 offset[p->GetName()] = prefitVal;
10795 for (
int i = 0; i < ugraph->
GetN(); i++)
10796 ugraph->
SetPointX(i, i + graph->GetN());
10797 int nUnconstrained = ugraph->
GetN();
10800 tmpList.
Add(ugraph);
10801 graph->Merge(&tmpList);
10804 for (
auto &
l : ugraphLabels) {
10805 graphLabels.push_back(
l);
10809 graph->SetMarkerStyle(20);
10810 graph->SetMarkerSize(0.5);
10812 graph->SetMaximum(4);
10813 graph->SetMinimum(-4);
10815 bool doHorizontal =
10818 std::vector<std::pair<double, std::string>>
covariances;
10819 std::string poiName;
10820 double maxImpact = 0;
10824 poiName = sOpt3(sOpt3.
Index(
"impact:") + 7, sOpt3.
Length());
10827 if (_poi->empty()) {
10828 throw std::runtime_error(
"No floating poi in the fit");
10829 }
else if (_poi->size() != 1) {
10830 throw std::runtime_error(
"Multiple poi in the fit");
10832 poiName = _poi->first()->GetName();
10836 throw std::runtime_error(
TString::Format(
"Cannot find parameter %s", poiName.c_str()));
10847 for (
auto &label : graphLabels) {
10853 [&](std::pair<double, std::string> i, std::pair<double, std::string> j) {
10854 return doHorizontal ? (std::abs(i.first) < std::abs(j.first))
10855 : (std::abs(i.first) > std::abs(j.first));
10859 std::vector<TString> sortedLabels;
10860 maxImpact = (doHorizontal) ?
covariances.back().first
10863 if (
c.second ==
poi->GetName()) {
10867 c.first *= 4. / (maxImpact * 1.2);
10868 sortedLabels.push_back(
c.second);
10870 for (; i < graphLabels.size(); i++) {
10871 if (graphLabels[i] ==
c.second) {
10875 sortedGraph.
AddPoint(sortedGraph.
GetN(), graph->GetPointY(i));
10876 sortedGraph.
SetPointError(sortedGraph.
GetN() - 1, 0, 0, graph->GetErrorYlow(i), graph->GetErrorYhigh(i));
10881 tmpList2.
Add(&sortedGraph);
10882 graph->Merge(&tmpList2);
10884 graphLabels = sortedLabels;
10885 graph->SetTitle(
"Fit Result Impact");
10890 if (doHorizontal) {
10892 std::max(graph->GetN(), 1) - 0.5);
10894 for (
auto &
l : graphLabels) {
10897 if (!graphLabels.empty())
10901 hist =
new TH2D(
GetName(), fr->
GetTitle(), std::max(graph->GetN(), 1), -0.5, std::max(graph->GetN(), 1) - 0.5,
10904 for (
auto &
l : graphLabels) {
10907 if (!graphLabels.empty())
10915 auto histCopy =
dynamic_cast<TH1 *
>(hist->
Clone(
".axis"));
10918 auto _axis = (doHorizontal ? histCopy->GetYaxis() : histCopy->GetXaxis());
10921 graph->GetHistogram()->GetXaxis()->Set(std::max(graph->GetN(), 1), -0.5, std::max(graph->GetN(), 1) - 0.5);
10922 for (
int ii = 1; ii <= _axis->GetNbins(); ii++) {
10923 graph->GetHistogram()->GetXaxis()->SetBinLabel(ii, _axis->GetBinLabel(ii));
10937 auto oldPad =
gPad;
10938 gPad->Divide(1, 1, 1
e-9, 1
e-9);
10941 if (doHorizontal) {
10942 gPad->SetLeftMargin(0.4);
10944 gPad->SetBottomMargin(0.4);
10947 auto pNamesHist =
dynamic_cast<TH1F *
>(graph->GetHistogram()->
Clone(
"scales"));
10948 pNamesHist->
Sumw2();
10949 pNamesHist->SetDirectory(
nullptr);
10951 for (
int ii = 1; ii <= graph->GetN(); ii++) {
10953 pNamesHist->SetBinContent(ii, offset[_p->GetName()]);
10954 pNamesHist->SetBinError(ii, scale[_p->GetName()]);
10955 _axis->SetBinLabel(ii, strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName());
10961 for (
int ii = 2; ii >= 1; ii--) {
10965 pullBox->SetPoint(0, (doHorizontal) ? -ii : -0.5, (doHorizontal) ? -0.5 : 0);
10966 pullBox->SetPoint(1, (doHorizontal) ? ii : (_axis->GetNbins() - 0.5 - nUnconstrained),
10967 (doHorizontal) ? -0.5 : 0);
10968 pullBox->SetPointError(0, 0, (doHorizontal) ? (_axis->GetNbins() - nUnconstrained) : ii);
10969 pullBox->SetPointError(1, 0, (doHorizontal) ? (_axis->GetNbins() - nUnconstrained) : ii);
10973 auto pullLine =
new TGraph;
10974 pullLine->
SetName(
"0sigmaLine");
10976 pullLine->SetPoint(0, -0.5, 0);
10977 pullLine->SetPoint(1, _axis->GetNbins() - 0.5, 0);
10978 pullLine->SetLineStyle(2);
10979 pullLine->SetEditable(
false);
10983 if (nUnconstrained > 0) {
10985 pullLine->
SetName(
"dividerLine");
10987 pullLine->SetPoint(0, graph->GetN() - 0.5 - nUnconstrained, -100);
10988 pullLine->SetPoint(1, graph->GetN() - 0.5 - nUnconstrained, 100);
10989 pullLine->SetLineStyle(2);
10990 pullLine->SetEditable(
false);
10996 new TPaveText(
gPad->GetLeftMargin(), 1. -
gPad->GetTopMargin(), 1. -
gPad->GetRightMargin(), 0.98,
"NDCNB");
11004 std::string covQualTxt;
11006 case -1: covQualTxt =
"Unknown";
break;
11007 case 0: covQualTxt =
"Not calculated";
break;
11008 case 1: covQualTxt =
"Approximate";
break;
11009 case 2: covQualTxt =
"Forced Positive-Definite";
break;
11010 case 3: covQualTxt =
"Accurate";
break;
11015 std::string statusCodes;
11024 gPad->SetTicks(0, 0);
11026 if (doHorizontal) {
11028 if (
int(
gPad->GetCanvas()->GetWh()) < pNamesHist->GetNbinsX() * 15) {
11029 gPad->GetCanvas()->SetCanvasSize(
gPad->GetCanvas()->GetWw(), pNamesHist->GetNbinsX() * 15);
11033 double factor = 475. /
gPad->GetCanvas()->GetWh();
11034 gPad->SetTopMargin(
gStyle->GetPadTopMargin() * factor);
11035 gPad->SetBottomMargin(
gStyle->GetPadBottomMargin() * factor);
11038 new TGaxis(_axis->GetXmin(), -4, _axis->GetXmin(), 4, -1.2 * maxImpact, 1.2 * maxImpact, 510,
"-S");
11040 if (doHorizontal) {
11062 for (
int tt = 0;
tt < 2;
tt++) {
11063 auto impact =
static_cast<TH1 *
>(
11066 impact->GetYaxis()->SetTitle(
TString::Format(
"#Delta%s/#sigma", poiName.c_str()));
11067 impact->SetBarWidth(0.9);
11068 impact->SetBarOffset(0.05);
11069 impact->SetLineColor(
kBlack);
11070 impact->SetFillColor(
kAzure - 4);
11071 impact->SetFillStyle(
tt == 0 ? 3013 : 1001);
11073 static_cast<TH1 *
>(impact->Clone(
TString::Format(
"%s_impact-",
tt == 0 ?
"prefit" :
"postfit")));
11075 impact2->SetFillColor(
kCyan);
11076 for (
int ii = 1; ii <= pNamesHist->GetNbinsX(); ii++) {
11078 if (
c.second != pNamesHist->GetXaxis()->GetBinLabel(ii))
11082 impact->SetBinContent(ii, ((
tt == 0 && !vv_init->hasError()) || !vv->hasError())
11084 :
c.first * vv->getError() / vv->getErrorHi() *
11085 (
tt == 0 ? (vv_init->getErrorHi() / vv->getErrorHi()) : 1.));
11086 impact2->SetBinContent(ii, ((
tt == 0 && !vv_init->hasError()) || !vv->hasError())
11088 :
c.first * vv->getError() / vv->getErrorLo() *
11089 (
tt == 0 ? (vv_init->getErrorLo() / vv->getErrorLo()) : 1.));
11096 for (
int ii = -1; ii <= 1; ii++) {
11097 auto pullLine =
new TGraph;
11100 pullLine->SetPoint(0, -0.5, ii);
11101 pullLine->SetPoint(1, hist->
GetNbinsY() - 0.5, ii);
11102 pullLine->SetLineStyle(2);
11103 pullLine->SetEditable(
false);
11108 new TLegend(0.02, doHorizontal ? (1. - 0.22 * factor) : 0.02, 0.27, (doHorizontal ? 1. : 0.24));
11118 leg1->
AddEntry(hist->
FindObject(
"prefit_impact+"),
"#theta = #hat{#theta}+#Delta#theta",
"f");
11119 leg1->
AddEntry(hist->
FindObject(
"prefit_impact-"),
"#theta = #hat{#theta}-#Delta#theta",
"f");
11122 leg1->
AddEntry(hist->
FindObject(
"postfit_impact+"),
"#theta = #hat{#theta}+#Delta#theta",
"f");
11123 leg1->
AddEntry(hist->
FindObject(
"postfit_impact-"),
"#theta = #hat{#theta}-#Delta#theta",
"f");
11126 if (
gStyle->GetOptTitle()) {
11129 new TPaveText(
gPad->GetLeftMargin(), 1. -
gPad->AbsPixeltoY(14), 1. -
gPad->GetRightMargin(), 1.,
"NDC");
11130 title->ConvertNDCtoPad();
11131 title->SetY1NDC(1. -
gPad->GetTopMargin() * 0.6);
11132 title->SetY2NDC(1);
11133 title->SetTextSize(
11134 (title->GetTextFont() % 10 > 2)
11136 : ((
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(10 / factor)) / (
gPad->GetY2() -
gPad->GetY1())));
11137 title->SetFillStyle(0);
11138 title->SetBorderSize(0);
11139 title->AddText(histCopy->GetTitle());
11144 graph->SetEditable(
false);
11145 pNamesHist->SetLineWidth(0);
11146 pNamesHist->SetMarkerSize(0);
11147 pNamesHist->SetMarkerStyle(0);
11148 graph->GetListOfFunctions()->Add(pNamesHist,
"same");
11149 if (doHorizontal) {
11152 for (
int p = 0; p < graph->GetN(); p++) {
11153 graph->SetPoint(p, graph->GetPointY(p), graph->GetPointX(p));
11154 graph->SetPointError(p, graph->GetErrorYlow(p), graph->GetErrorYhigh(p), graph->GetErrorXlow(p),
11155 graph->GetErrorXhigh(p));
11158 if (
f->InheritsFrom(
"TH1")) {
11167 else if (
auto g =
dynamic_cast<TGraph *
>(
f)) {
11168 for (
int p = 0; p <
g->GetN(); p++) {
11169 g->SetPoint(p,
g->GetPointY(p),
g->GetPointX(p));
11172 }
else if (
auto l =
dynamic_cast<TLine *
>(
f)) {
11173 l->SetX1(
l->GetY1());
11174 l->SetX2(
l->GetY2());
11175 l->SetY1(_axis->GetXmax());
11176 l->SetY2(_axis->GetXmax());
11184 for (
size_t i = 0; i < ugraphLabels.size(); i++) {
11185 int bin = pNamesHist->GetNbinsX() - ugraphLabels.size() + i + 1;
11189 auto x = graph->GetPointX(graph->GetN() - ugraphLabels.size() + i);
11190 auto y = graph->GetPointY(graph->GetN() - ugraphLabels.size() + i) +
11191 graph->GetErrorYhigh(graph->GetN() - ugraphLabels.size() + i);
11195 t->SetTextSize(0.025);
11196 t->SetTextAngle(90);
11197 graph->GetListOfFunctions()->Add(t);
11201 graph->SetName(
"pulls");
11206 histCopy->Draw((sOpt.
Contains(
"impact") && !doHorizontal)
11210 hist->
Draw(
"same");
11222 auto hh =
dynamic_cast<TH1 *
>(histCopy->Clone(
".axiscopy"));
11226 (sOpt.
Contains(
"impact") && !doHorizontal)
11240 bool doneDraw =
false;
11241 for (
auto c : s->bins()) {
11242 auto _pad =
dynamic_cast<TPad *
>(
gPad->GetPrimitive(
c->GetName()));
11247 c->push_back(std::make_shared<xRooNode>(*
this));
11248 auto ds =
c->datasets().find(
GetName());
11249 c->resize(
c->size() - 1);
11251 std::cout <<
" no ds " <<
GetName() <<
" - this should never happen!" << std::endl;
11266 if (!s && hasSame) {
11269 bool doneDraw =
false;
11270 for (
auto o : *
gPad->GetListOfPrimitives()) {
11285 auto dataGraph =
BuildGraph(
v,
false, (!s && hasSame) ?
gPad :
nullptr);
11290 dataGraph->SetMarkerSize(dataGraph->GetMarkerSize() *
gPad->GetWNDC());
11295 for (
int i = 0; i < dataGraph->GetN(); i++)
11296 tot += dataGraph->GetPointY(i);
11297 dataGraph->Scale(1. / tot);
11302 dataGraph->Draw(
"Az0p");
11303 addLegendEntry(dataGraph, strlen(dataGraph->GetTitle()) ? dataGraph->GetTitle() :
GetName(),
"pEX0");
11309 bool noPoint =
false;
11310 if (
v &&
dynamic_cast<RooAbsArg *
>(
v)->getAttribute(
"global") && dataGraph->GetN() == 1) {
11312 for (
auto o : *
gPad->GetListOfPrimitives()) {
11313 if (
auto h =
dynamic_cast<TH1 *
>(o);
11314 h && strcmp(
h->GetXaxis()->GetName(),
dynamic_cast<TObject *
>(
v)->GetName()) == 0) {
11315 dataGraph->SetPointY(0,
h->Interpolate(dataGraph->GetPointX(0)));
11322 if (
auto _pad =
dynamic_cast<TPad *
>(
gPad->FindObject(
"auxPad")); _pad) {
11323 if (
auto h =
dynamic_cast<TH1 *
>(_pad->GetPrimitive(
"auxHist"));
h) {
11326 histName = histName(0, histName.
Index(
'|'));
11327 if (
auto mainHist =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(histName));
11331 auto ratioGraph =
dynamic_cast<TGraphAsymmErrors *
>(dataGraph->Clone(dataGraph->GetName()));
11333 for (
int i = 0; i < ratioGraph->GetN(); i++) {
11334 double val = ratioGraph->GetPointY(i);
11335 int binNum = mainHist->FindFixBin(ratioGraph->GetPointX(i));
11336 double nom = mainHist->GetBinContent(binNum);
11337 double nomerr = mainHist->GetBinError(binNum);
11339 std::get<0>(
auxFunctions[
h->GetYaxis()->GetTitle()])(ratioGraph->GetPointY(i), nom, nomerr);
11340 double yup = std::get<0>(
auxFunctions[
h->GetYaxis()->GetTitle()])(val + ratioGraph->GetErrorYhigh(i),
11343 double ydown = yval - std::get<0>(
auxFunctions[
h->GetYaxis()->GetTitle()])(
11344 val - ratioGraph->GetErrorYlow(i), nom, nomerr);
11345 if (!std::isnan(yval)) {
11346 ratioGraph->SetPointY(i, yval);
11347 if (!std::isnan(yup))
11348 ratioGraph->SetPointEYhigh(i, yup);
11349 if (!std::isnan(ydown))
11350 ratioGraph->SetPointEYlow(i, ydown);
11355 while (i < ratioGraph->GetN()) {
11356 if (ratioGraph->GetPointY(i) == 0 && ratioGraph->GetErrorYhigh(i) == 0 &&
11357 ratioGraph->GetErrorYlow(i) == 0) {
11358 ratioGraph->RemovePoint(i);
11363 auto _tmpPad =
gPad;
11365 ratioGraph->Draw(
"z0psame");
11366 auto minMax = graphMinMax(ratioGraph);
11367 adjustYRange(minMax.first, minMax.second,
h, std::get<1>(
auxFunctions[
h->GetYaxis()->GetTitle()]));
11373 dataGraph->Draw(
"z0p same");
11374 addLegendEntry((noPoint) ?
nullptr : dataGraph, strlen(dataGraph->GetTitle()) ? dataGraph->GetTitle() :
GetName(),
11375 noPoint ?
"" :
"pEX0");
11378 adjustYRange(minMax.first, minMax.second);
11394 gr->Draw(hasSame ?
"P" :
"AP");
11398 if (forceNames !=
"") {
11401 bool _drawn =
false;
11402 auto _coords =
coords();
11407 std::vector<double> valuesToDo = {initPar->getVal()};
11408 if (initPar->hasError() || initPar->hasAsymError()) {
11409 valuesToDo.push_back(initPar->getVal() + initPar->getErrorLo());
11410 valuesToDo.push_back(initPar->getVal() + initPar->getErrorHi());
11413 for (
auto valueToDo : valuesToDo) {
11415 for (
auto &
d : _dsets) {
11416 if (!
d->get()->TestBit(1 << 20))
11420 auto _obs =
d->obs();
11421 auto x = _obs.find((
v) ?
dynamic_cast<TObject *
>(
v)->
GetName() : emptyHist->GetXaxis()->GetName());
11422 auto _nll =
nll(
d);
11425 for (
int i = 0; i < nevent; i++) {
11427 bool _skip =
false;
11428 for (
const auto &
_c : _coords) {
11430 if (cat->getIndex() != theData->get()->getCatIndex(cat->GetName())) {
11440 auto val = _nll.pars()->getRealValue(initPar->GetName());
11442 _nll.pars()->setRealValue(initPar->GetName(), valueToDo);
11443 auto nllVal = _nll.getEntryVal(i);
11444 _nll.pars()->setRealValue(initPar->GetName(), initPar->getVal());
11445 auto nllVal2 = _nll.getEntryVal(i);
11446 _nll.pars()->setRealValue(initPar->GetName(), val);
11452 auto val = _nll.pars()->getRealValue(initPar->GetName());
11454 _nll.pars()->setRealValue(initPar->GetName(), valueToDo);
11455 auto _extTerm = _nll.extendedTermVal();
11456 _nll.pars()->setRealValue(initPar->GetName(), initPar->getVal());
11457 auto _extTerm2 = _nll.extendedTermVal();
11458 _nll.pars()->setRealValue(initPar->GetName(), val);
11459 for (
int i = 1; i <= emptyHist->GetNbinsX(); i++) {
11460 emptyHist->SetBinContent(i,
11461 emptyHist->GetBinContent(i) + (_extTerm2 - _extTerm) / emptyHist->GetNbinsX());
11462 emptyHist->SetBinError(i, 0);
11464 emptyHist->GetYaxis()->SetTitle(
"log (L(#theta)/L(#theta_{0}))");
11465 emptyHist->SetTitle(
TString::Format(
"#theta = %g", (ii > 1) ? valueToDo : val));
11467 emptyHist->SetLineColor(
kBlack);
11469 emptyHist->SetLineColor(
kRed);
11470 }
else if (ii == 3) {
11471 emptyHist->SetLineColor(
kBlue);
11473 emptyHist->Draw(_drawn ?
"same" :
"");
11490 rarNode =
find(
".pdf").
get();
11495 if (!nostack && !hasOverlay &&
11505 auto h =
BuildHistogram(
v,
false, hasErrorOpt, 1, 0,
"",
false,
false, 0,
nullptr, nostack,
true );
11517 :
h->GetXaxis()->GetName())
11520 if (
h->GetXaxis()->IsAlphanumeric()) {
11522 h->GetXaxis()->SetName(
"xaxis");
11528 if (rar->InheritsFrom(
"RooAbsPdf") && !(rar->InheritsFrom(
"RooRealSumPdf") || rar->InheritsFrom(
"RooAddPdf") ||
11529 rar->InheritsFrom(
"RooSimultaneous"))) {
11532 rar->leafNodeServerList(&s);
11539 for (
auto _p : s) {
11546 ss +=
TString::Format(
"%s=%g", strlen(_p->GetTitle()) ? _p->GetTitle() : _p->GetName(), _v->getVal());
11547 if (_v->hasError()) {
11558 gPad->SetGrid(0, 0);
11560 gPad->SetGrid(1, 1);
11565 h->SetFillStyle(0);
11614 gROOT->SetEditHistograms(
true);
11616 gROOT->SetEditHistograms(
false);
11627 h->SetMarkerSize(
gStyle->GetLabelSize(
"Z") / (0.02 *
gPad->GetHNDC()));
11630 bool hasError(
false);
11631 for (
int i = 0; i <
h->GetSumw2N(); i++) {
11632 if (
h->GetSumw2()->At(i)) {
11643 if (!hasSame &&
h->GetYaxis()->GetTitleFont() % 10 == 2) {
11644 h->GetYaxis()->SetTitleOffset(1.);
11647 TH1 *errHist =
nullptr;
11652 if(rar->getAttribute(
"Logy")) {
11661 auto _hist = (errHist) ? errHist :
h;
11662 auto hCopy = (errHist) ?
nullptr :
dynamic_cast<TH1 *
>(
h->Clone());
11666 hCopy->SetDirectory(
nullptr);
11669 _hist->GetListOfFunctions()->Add(
new TExec(
11672 "gROOT->SetEditHistograms(true);auto h = dynamic_cast<TH1*>(gPad->GetPrimitive(\"%s\")); if(h) { double "
11673 "range= h->GetMaximum()-h->GetMinimum(); if(auto n "
11674 "= dynamic_cast<xRooNode*>(h->GetListOfFunctions()->FindObject(\"%s\")); n && "
11675 "n->TestBit(TObject::kNotDeleted) && n->get<RooRealVar>()->getVal() != h->GetBinContent(1)) {"
11676 "h->SetBinContent(1, "
11677 "TString::Format(\"%%.2g\",int(h->GetBinContent(1)/(range*0.01))*range*0.01).Atof());n->SetContent( "
11678 "h->GetBinContent(1) ); for(auto pp : *h->GetListOfFunctions()) if(auto hh = "
11679 "dynamic_cast<TH1*>(pp))hh->SetBinContent(1,h->GetBinContent(1));} if(h->GetBinContent(1)==0.) "
11680 "h->SetBinContent(1,range*0.005); gPad->Modified();gPad->Update(); }",
11681 _hist->GetName(), node->GetName())));
11687 hCopy->SetFillStyle(0);
11688 _hist->GetListOfFunctions()->Add(hCopy,
"TEXT HIST same");
11691 _hist->SetStats(
false);
11698 bool overlayExisted =
false;
11701 if (
auto existing =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(
h->GetName())); existing) {
11706 overlayExisted =
true;
11708 TString oldStyle = (rar && rar->getStringAttribute(
"style")) ? rar->getStringAttribute(
"style") :
"";
11709 h->SetTitle(overlayName);
11715 h->SetFillStyle(0);
11738 rar->setStringAttribute(
"style", oldStyle ==
"" ?
nullptr : oldStyle.
Data());
11739 if (
auto _style = _styleNode.get<
TStyle>()) {
11744 h->Draw(dOpt ==
"LF2" ?
"e3" : dOpt);
11767 if (
auto stack =
dynamic_cast<THStack *
>(
h->FindObject(
"stack"))) {
11769 TObjLink *lnk = stack->GetHists()->FirstLink();
11774 if (lnk == stack->GetHists()->FirstLink() &&
h->GetMinimum() > hhMin) {
11775 auto newMin = hhMin - (
h->GetMaximum() - hhMin) *
gStyle->GetHistTopMargin();
11776 if (hhMin >= 0 && newMin < 0)
11777 newMin = hhMin * 0.99;
11778 adjustYRange(newMin,
h->GetMaximum());
12050 }
else if (!overlayExisted) {
12061 errHist->
Draw(dOpt + (dOpt.
Contains(
"LF2") ?
"e3same" :
"e2same"));
12062 double ymax = -std::numeric_limits<double>::infinity();
12063 double ymin = std::numeric_limits<double>::infinity();
12064 for (
int i = 1; i <= errHist->
GetNbinsX(); i++) {
12070 adjustYRange(
h->GetMinimum() * 0.9,
h->GetMaximum() * 1.1);
12073 if ((!auxPlotTitle.empty()) && !hasSame) {
12075 double padFrac = 0.3;
12076 auto _tmpPad =
gPad;
12077 gPad->SetBottomMargin(padFrac);
12078 auto ratioPad =
new TPad(
"auxPad",
"aux plot", 0, 0, 1, padFrac);
12079 ratioPad->SetFillColor(_tmpPad->GetFillColor());
12080 ratioPad->SetNumber(1);
12081 ratioPad->SetBottomMargin(ratioPad->GetBottomMargin() / padFrac);
12082 ratioPad->SetTopMargin(0.04);
12083 ratioPad->SetLeftMargin(
gPad->GetLeftMargin());
12084 ratioPad->SetRightMargin(
gPad->GetRightMargin());
12086 TH1 *ratioHist =
dynamic_cast<TH1 *
>((errHist) ? errHist->
Clone(
"auxHist") :
h->Clone(
"auxHist"));
12087 ratioHist->
Reset();
12097 auxPlotTitle.c_str()));
12100 ratioPad->SetGridy();
12102 for (
int i = 1; i <= ratioHist->
GetNbinsX(); i++) {
12110 double rHeight = (1. - padFrac) / padFrac;
12118#if ROOT_VERSION_CODE < ROOT_VERSION(6, 26, 00)
12127 auto _h =
dynamic_cast<TH1 *
>(ratioHist->
Clone(
"auxHist_clone"));
12129 _h->SetFillColor(0);
12135 TString::Format(
"auto h1 = (TH1*)%p; auto h2 = (TH1*)%p; if(h2->GetXaxis()->GetFirst() != "
12136 "h1->GetXaxis()->GetFirst() || h1->GetXaxis()->GetLast()!=h2->GetXaxis()->GetLast()) "
12137 "{h2->GetXaxis()->SetRange(h1->GetXaxis()->GetFirst(),h1->GetXaxis()->GetLast());if(gPad) "
12138 "{gPad->GetCanvas()->Paint();gPad->GetCanvas()->Update();}}",
12139 (
void *)ratioHist, (
void *)(
h))));
12140 ratioHist->
Draw((errHist ?
"e2" :
""));
12144 }
else if (
auto ratioPad =
dynamic_cast<TPad *
>(
gPad->GetPrimitive(
"auxPad")); hasSame && ratioPad) {
12148 if (
auto hr =
dynamic_cast<TH1 *
>(ratioPad->GetPrimitive(
"auxHist"));
12150 TString histName = hr->GetTitle();
12152 histName = histName(0, histName.
Index(
'|'));
12154 if (
auto hnom =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(histName)); hnom) {
12155 h =
dynamic_cast<TH1 *
>(
h->Clone(
h->GetName()));
12156 h->SetDirectory(
nullptr);
12158 for (
int i = 1; i <= hnom->GetNbinsX(); i++) {
12159 double val =
h->GetBinContent(i);
12160 double err =
h->GetBinError(i);
12161 h->SetBinContent(i, std::get<0>(
auxFunctions[hr->GetYaxis()->GetTitle()])(
12162 h->GetBinContent(i), hnom->GetBinContent(i), hnom->GetBinError(i)));
12163 h->SetBinError(i, std::get<0>(
auxFunctions[hr->GetYaxis()->GetTitle()])(
12164 val +
err, hnom->GetBinContent(i), hnom->GetBinError(i)) -
12165 h->GetBinContent(i));
12167 auto _tmpPad =
gPad;
12170 if (
auto existing =
dynamic_cast<TH1 *
>(ratioPad->GetPrimitive(
h->GetName())); existing) {
12175 overlayExisted =
true;
12182 double ymax = -std::numeric_limits<double>::infinity();
12183 double ymin = std::numeric_limits<double>::infinity();
12184 for (
int i = 1; i <=
h->GetNbinsX(); i++) {
12185 ymax = std::max(
ymax,
h->GetBinContent(i) +
h->GetBinError(i));
12186 ymin = std::min(
ymin,
h->GetBinContent(i) -
h->GetBinError(i));
12216 !hasSame && _pdf &&
coefs(
true).empty()) {
12219 for (
auto &
d : _dsets) {
12220 if (
d->get()->TestBit(1 << 20)) {
12241 if (sFilename.
Contains(
".root:")) {
12243 sFilename = sFilename(0, sFilename.
Index(
".root:") + 5);
12251 auto addedPdf =
ws.Add(*
this);
12256 mc.
SetPdf(addedPdf->GetName());
12268 w->import(*
gROOT->GetListOfColors(),
true);
12270 if (sFilename.
EndsWith(
".json")) {
12271#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00)
12275 Info(
"SaveAs",
"%s saved to %s", w->GetName(), sFilename.
Data());
12277 Error(
"SaveAs",
"Unable to save to %s", sFilename.
Data());
12280 Error(
"SaveAs",
"json format workspaces only in ROOT 6.26 onwards");
12285#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
12289 for (
auto &
c : w->components()) {
12290 c->_eocache =
nullptr;
12294#if ROOT_VERSION_CODE < ROOT_VERSION(6, 38, 00)
12295 if (!w->writeToFile(sFilename, sOpt !=
"update")) {
12297 if (w->writeToFile(sFilename, sOpt !=
"update")) {
12299 Info(
"SaveAs",
"%s saved to %s", w->GetName(), sFilename.
Data());
12305 auto dir = dest->GetDirectory(source->
GetName());
12307 dir = dest->mkdir(source->
GetName());
12310 auto key =
dynamic_cast<TKey *
>(k);
12311 const char *classname = key->GetClassName();
12320 if (dir->FindKey(key->GetName()))
12323 if (strcmp(classname,
"ROOT::Fit::FitConfig") == 0) {
12325 dir->WriteObject(fc, key->GetName());
12328 TObject *obj = key->ReadObj();
12330 dir->WriteTObject(obj, key->
GetName());
12337 if (
gROOT->GetListOfFiles()) {
12338 for (
auto key : *
gROOT->GetListOfFiles()) {
12339 if (
auto fitDb =
dynamic_cast<TMemFile *
>(key);
12341 CopyDir(fitDb, std::make_unique<TFile>(sFilename,
"UPDATE").
get());
12342 Info(
"SaveAs",
"Saved %s to %s", fitDb->GetName(), sFilename.
Data());
12347 Error(
"SaveAs",
"Unable to save to %s", sFilename.
Data());
12349#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
12351 for (
auto &
c : w->components()) {
12352 c->setExpensiveObjectCache(w->expensiveObjectCache());
12360 auto res =
GetBinErrors(bin, bin, fr, nToys, errorsHi, errorsLo);
12362 return std::numeric_limits<double>::quiet_NaN();
12368 std::vector<double> out;
12369 out.reserve(
size());
12370 for (
auto child : *
this) {
12371 out.push_back(child->GetContent());
12389 auto _pars =
pars();
12394 for (
int m = 0;
m < rho.GetNrows();
m++) {
12395 auto p_m =
dynamic_cast<RooRealVar *
>(_fr->floatParsFinal().
at(
m));
12401 auto tmp = _p->
getVal();
12402 _p->setVal(p_m->getVal() + p_m->getErrorHi());
12404 _p->setVal(p_m->getVal() + p_m->getErrorLo());
12407 for (
int n = 0;
n < rho.GetNrows();
n++) {
12408 auto p_n =
dynamic_cast<RooRealVar *
>(_fr->floatParsFinal().
at(
n));
12414 auto tmp2 = _p2->
getVal();
12415 _p2->setVal(p_n->getVal() + p_n->getErrorHi());
12416 auto nu_n = (p_n == p_m) ? nu_m :
contents();
12417 _p2->setVal(p_n->getVal() + p_n->getErrorLo());
12418 auto nu_n2 = (p_n == p_m) ? nu_m2 :
contents();
12420 for (
int i = 0; i < out.
GetNrows(); i++) {
12421 for (
int j = 0; j < out.
GetNrows(); j++) {
12422 out(i, j) += 0.25 * (nu_m[i] - nu_m2[i]) * rho(
m,
n) * (nu_n[j] - nu_n2[j]);
12430std::pair<double, double>
12434 double err = std::numeric_limits<double>::quiet_NaN();
12436 std::unique_ptr<RooAbsCollection> _snap;
12441 _pars = _fr->floatParsFinal();
12442 _pars = _fr->constPars();
12447 auto _coefs =
coefs();
12449 out =
c->getVal(sobs);
12455 p->setNormRange(rangeName);
12456#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 27, 00)
12459 out *= p->expectedEvents(*_obs.get<
RooArgList>());
12460#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
12462 p->_normSet =
nullptr;
12466 p->setNormRange(
nullptr);
12467 }
else if (
auto p2 =
dynamic_cast<RooAbsReal *
>(
get()); p2) {
12469 auto f = std::shared_ptr<RooAbsReal>(
12470 p2->createIntegral(*std::unique_ptr<RooArgSet>(p2->getObservables(*_obs.get<
RooArgList>())),
12474 out *=
f->getVal();
12475 err =
xRooNode(pr, *
this).GetBinError(-1, fr, nToys, errorsHi, errorsLo);
12480 auto ax = (rangeName) ?
GetXaxis() :
nullptr;
12481 auto rv = (ax) ?
dynamic_cast<RooRealVar *
>(ax->GetParent()) :
nullptr;
12482 auto cv = (ax && !rv) ?
dynamic_cast<RooCategory *
>(ax->GetParent()) :
nullptr;
12484 for (
auto &
v : vals) {
12487 if (rv && !rv->inRange(ax->GetBinCenter(i), rangeName))
12489 if (cv && !cv->isStateInRange(rangeName, ax->GetBinLabel(i)))
12496 out = std::numeric_limits<double>::quiet_NaN();
12499 _pars.RooAbsCollection::operator=(*_snap);
12501 return std::make_pair(out,
err);
12514 if (binStart != binEnd || !
fParent) {
12520 std::vector<double> out;
12522 auto _hist =
BuildHistogram(
nullptr,
true,
true, binStart, binEnd, _fr, errorHi, errorLo, nToys);
12526 binEnd = _hist->GetNbinsX();
12527 }
else if (binEnd == binStart && binEnd == -1) {
12531 for (
int bin = binStart; bin <= binEnd; bin++) {
12532 out.push_back(((errorLo && !errorHi) ? (-1.) : 1.) *
12533 _hist->GetBinError(bin));
12658std::string cling::printValue(
const xRooNode *
v)
12661 return "nullptr\n";
12664 size_t left =
v->size();
12665 for (
auto n : *
v) {
12671 out +=
n->GetName();
12672 if (out.length() > 100 && left > 0) {
12678 out = std::string(
Form(
"<%s> %s",
v->get() ?
v->get()->ClassName() :
"nullptr",
v->GetName())) + out;
12683 return "<nullptr>";
12685 return Form(
"<%s> %s",
v->get() ?
v->get()->ClassName() :
"nullptr",
v->GetName());
#define ROOT_VERSION(a, b, c)
#define ROOT_VERSION_CODE
RooCollectionProxy< RooArgList > RooListProxy
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
RooTemplateProxy< RooAbsReal > RooRealProxy
Compatibility typedef replacing the old RooRealProxy class.
int Int_t
Signed integer 4 bytes (int).
const char Option_t
Option string (const char).
static void indent(ostringstream &buf, int indent_level)
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
TMatrixTSym< Double_t > TMatrixDSym
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
TVectorT< Double_t > TVectorD
double GetBinLowEdge(Int_t bin) const override
Return low edge of bin.
double GetBinUpEdge(Int_t bin) const override
Return up edge of bin.
Int_t FindFixBin(double x) const override
Find bin number corresponding to abscissa x.
TAxis()
Default constructor.
void Set(Int_t nbins, const double *xbins) override
Initialize axis with variable bins.
RooAbsRealLValue * rvar() const
void SetTitle(const char *title) override
Set the title of the TNamed.
void Set(Int_t nbins, double xmin, double xmax) override
Initialize axis with fix bins.
Int_t FindFixBin(const char *label) const override
Find bin number with label.
RooAbsLValue * var() const
const RooAbsBinning * binning() const
void Set(Int_t nbins, const float *xbins) override
Initialize axis with variable bins.
const char * GetTitle() const override
Returns title of object.
double GetBinWidth(Int_t bin) const override
Return bin width.
PadRefresher(TVirtualPad *p)
A class which maps the current values of a RooRealVar (or a set of RooRealVars) to one of a number of...
RooListProxy _paramSet
interpolation parameters
bool isBinnedDistribution(const RooArgSet &obs) const override
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
bool selfNormalized() const override
Shows if a PDF is self-normalized, which means that no attempt is made to add a normalization term.
double getSimplePropagatedError(const RooFitResult &fr, const RooArgSet &nset_in) const
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
TObject * clone(const char *newname) const override
std::list< double > * binBoundaries(RooAbsRealLValue &obs, double xlo, double xhi) const override
Retrieve bin boundaries if this distribution is binned in obs.
PdfWrapper(const PdfWrapper &other, const char *name=nullptr)
PdfWrapper(RooAbsReal &f, RooAbsReal *coef, bool expEvMode=false, RooAbsPdf *expPdf=nullptr)
The PiecewiseInterpolation is a class that can morph distributions into each other,...
static xRooNLLVar createNLL(const std::shared_ptr< RooAbsPdf > pdf, const std::shared_ptr< RooAbsData > data, const RooLinkedList &nllOpts)
static std::shared_ptr< RooLinkedList > createNLLOptions()
static std::pair< double, double > matchPrecision(const std::pair< double, double > &in)
static std::pair< std::shared_ptr< RooAbsData >, std::shared_ptr< const RooAbsCollection > > generateFrom(RooAbsPdf &pdf, const RooFitResult &fr, bool expected=false, int seed=0)
std::shared_ptr< xRooHypoPoint > asimov(bool readOnly=false)
std::shared_ptr< const RooFitResult > ufit(bool readOnly=false)
std::shared_ptr< const RooFitResult > cfit_null(bool readOnly=false)
void Draw(Option_t *opt="") override
Default Draw method for all objects.
std::shared_ptr< const RooFitResult > cfit_alt(bool readOnly=false)
std::shared_ptr< const RooFitResult > gfit()
void Draw(Option_t *opt="") override
Default Draw method for all objects.
This xRooNLLVar object has several special methods, e.g.
xRooHypoSpace hypoSpace(const char *parName, int nPoints, double low, double high, double alt_value=std::numeric_limits< double >::quiet_NaN(), const xRooFit::Asymptotics::PLLType &pllType=xRooFit::Asymptotics::Unknown, int tsType=0)
The xRooNode class is designed to wrap over a TObject and provide functionality to aid with interacti...
void _Add_(const char *name, const char *opt)
TH1 * BuildHistogram(RooAbsLValue *v=nullptr, bool empty=false, bool errors=false, int binStart=1, int binEnd=0, const xRooNode &fr="", bool errorsHi=false, bool errorsLo=false, int nErrorToys=0, TH1 *templateHist=nullptr, bool nostack=true, bool setInterp=false) const
xRooNode filter(const xRooNode &range) const
std::vector< std::shared_ptr< xRooNode > > fBrowsables
xRooNLLVar nll(const xRooNode &_data, std::initializer_list< RooCmdArg > nllOpts) const
xRooNode poi() const
List of parameters of interest: parameters marked as "of interest" These parameters have the "poi" at...
void SetName(const char *name) override
Set the name of the TNamed.
TGListTreeItem * GetTreeItem(TBrowser *b) const
void SetTitle(const char *title) override
Set the title of the TNamed.
xRooNode Multiply(const xRooNode &child, Option_t *opt="")
xRooNode Replace(const xRooNode &node)
bool SetData(const TObject &obj, const xRooNode &data="obsData")
xRooNode datasets() const
xRooNode Remove(const xRooNode &child)
xRooNode globs() const
List of global observables of this node.
xRooNode Add(const xRooNode &child, Option_t *opt="")
xRooNode(const char *type, const char *name, const char *title="")
const char * GetIconName() const override
Returns mime type name of object.
void Draw(Option_t *opt="") override
Default Draw method for all objects.
bool _IsShowVars_() const
TGraph * BuildGraph(RooAbsLValue *v=nullptr, bool includeZeros=false, TVirtualPad *fromPad=nullptr) const
const std::shared_ptr< xRooNode > & at(size_t idx, bool browseResult=true) const
const char * GetNodeType() const
void _fit_(const char *constParValues="", const char *options="GoF")
bool SetBinContent(int bin, double value, const char *par=nullptr, double parVal=1)
std::shared_ptr< xRooNode > operator[](size_t idx)
void Checked(TObject *obj, bool val)
void Print(Option_t *opt="") const override
Print TNamed name and title.
double GetContent() const
std::shared_ptr< T > acquireNew(Args &&...args)
std::shared_ptr< T > acquire2(Args &&...args)
xRooNode components() const
void SaveAs(const char *filename="", Option_t *option="") const override
Save this object in the file specified by filename.
xRooNode bins() const
bins of a channel or sample, or channels of a multi-channel pdf
std::shared_ptr< xRooNode > find(const std::string &name, bool browseResult=true) const
TGListTree * GetListTree(TBrowser *b) const
xRooNode styles(TObject *initObject=nullptr, bool autoCreate=true) const
xRooNode generate(const xRooNode &fr="", bool expected=false, int seed=0)
void Inspect() const override
Dump contents of this object in a graphics canvas.
std::shared_ptr< xRooNode > getBrowsable(const char *name) const
bool SetXaxis(const RooAbsBinning &binning)
double GetBinError(int bin, const xRooNode &fr="", int nToys=0, bool errorsHi=false, bool errorsLo=false) const
RooArgList argList() const
bool SetBinData(int bin, double value, const xRooNode &data="obsData")
void SetHidden(bool set=true)
std::function< xRooNode(xRooNode *)> fBrowseOperation
std::vector< double > GetBinContents(int binStart=1, int binEnd=0) const
xRooNode pp() const
List of prespecified parameters: non-floatable parameters.
double GetError(const xRooNode &fr="", int nToys=0, bool errorsHi=false, bool errorsLo=false) const
xRooNode constraints() const
std::shared_ptr< xRooNode > fProvider
! like a parent but only for use by getObject
std::shared_ptr< TStyle > style(TObject *initObject=nullptr, bool autoCreate=true) const
xRooNode mainChild() const
xRooNode fitResult(const char *opt="") const
std::shared_ptr< TAxis > fXAxis
! appears that if was fXaxis then dialog box for SetXaxis will take as current value
xRooNode coords(bool setVals=true) const
xRooNode Vary(const xRooNode &child)
xRooNode Constrain(const xRooNode &child)
static std::map< std::string, std::tuple< std::function< double(double, double, double)>, bool > > auxFunctions
xRooNode pars() const
List of parameters (non-observables) of this node.
void _SetContent_(double value)
void SetFitResult(const RooFitResult *fr=nullptr)
void _ShowVars_(bool set=true)
xRooNode coefs(bool recurse=false) const
bool IsFolder() const override
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
double GetBinData(int bin, const xRooNode &data="obsData")
bool SetBinError(int bin, double value)
void _Vary_(const char *what)
bool SetContents(const TObject &obj)
std::shared_ptr< TObject > fComp
!
std::pair< double, double > IntegralAndError(const xRooNode &fr="", const char *rangeName=nullptr, int nToys=0, bool errorsHi=false, bool errorsLo=false) const
std::vector< double > contents() const
RooWorkspace * ws() const
The RooWorkspace this node belong to, if any.
xRooNode shallowCopy(const std::string &name, std::shared_ptr< xRooNode > parent=nullptr)
void _generate_(const char *name="", bool expected=false)
std::shared_ptr< TObject > getObject(const std::string &name, const std::string &type="") const
xRooNode np() const
List of nuisance parameters: non-constant parameters that are not marked of interest,...
xRooNode Combine(const xRooNode &rhs, bool silent=false)
xRooNode floats() const
List of parameters that are currently non-constant These parameters do not have the "Constant" attrib...
bool contains(const std::string &name) const
xRooNode reduced(const std::string &range="", bool invert=false) const
xRooNode variations() const
std::string GetPath() const
std::vector< double > GetBinErrors(int binStart=1, int binEnd=0, const xRooNode &fr="", int nToys=0, bool errorsHi=false, bool errorsLo=false) const
auto begin() const -> xRooNodeIterator
std::shared_ptr< xRooNode > parentPdf() const
bool SetContent(double value)
void _scan_(const char *what="plr", double nToys=0, const char *xvar="", int nPointsX=0, double lowX=0, double highX=0, const char *constParValues="", const char *options="")
std::shared_ptr< xRooNode > fParent
!
xRooNode robs() const
List of regular observables of this node.
TClass * IsA() const override
xRooNode & operator=(const TObject &o)
auto end() const -> xRooNodeIterator
xRooNode consts() const
List of parameters that are currently constant.
void _SetBinContent_(int bin, double value, const char *par="", double parVal=1)
std::shared_ptr< TObject > acquire(const std::shared_ptr< TObject > &arg, bool checkFactory=false, bool mustBeNew=false)
void _SetAttribute_(const char *name, const char *value=nullptr)
xRooNode histo(const xRooNode &vars="x", const xRooNode &fr="", bool content=true, bool errors=true, bool stack=true, bool errorsHi=false, bool errorsLo=false, int nErrorToys=0) const
void Browse(TBrowser *b=nullptr) override
Browse object. May be overridden for another default action.
xRooNode obs() const
List of observables (global and regular) of this node.
void SetRange(const char *range, double low=std::numeric_limits< double >::quiet_NaN(), double high=std::numeric_limits< double >::quiet_NaN())
static void SetAuxFunction(const char *title, const std::function< double(double, double, double)> &func, bool symmetrize=false)
std::shared_ptr< TObject > convertForAcquisition(xRooNode &acquirer, const char *opt="") const
xRooNode vars() const
List of variables (observables and parameters) of this node.
const char * GetRange() const
TMatrixDSym covariances(const xRooNode &fr="") const
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
Common abstract base class for objects that represent a value and a "shape" in RooFit.
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
TClass * IsA() const override
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
virtual bool isCategory() const
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
const RefCountList_t & servers() const
List of all servers of this object.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
const RefCountList_t & clients() const
List of all clients of this object.
virtual bool isIdentical(const RooAbsArg &other, bool assumeSameType=false) const =0
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset?
RooAbsArg()
Default constructor.
Abstract base class for RooRealVar binning definitions.
virtual double highBound() const =0
virtual double lowBound() const =0
Abstract base class for objects that represent a discrete value that can be set from the outside,...
A space to attach TBranches.
virtual value_type getCurrentIndex() const
Return index number of current state.
const char * getLabel() const
Retrieve current label. Use getCurrentLabel() for more clarity.
Int_t numTypes(const char *=nullptr) const
Return number of types defined (in range named rangeName if rangeName!=nullptr).
Abstract container object that can hold multiple RooAbsArg objects.
RooAbsCollection * selectByAttrib(const char *name, bool value) const
Create a subset of the current collection, consisting only of those elements with the specified attri...
double getRealValue(const char *name, double defVal=0.0, bool verbose=false) const
Get value of a RooAbsReal stored in set with given name.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
Storage_t const & get() const
Const access to the underlying stl container.
RooAbsCollection & assignValueOnly(const RooAbsCollection &other, bool forceIfSizeOne=false)
Sets the value of any argument in our set that also appears in the other set.
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
Storage_t::size_type size() const
bool setRealValue(const char *name, double newVal=0.0, bool verbose=false)
Set value of a RooAbsRealLValue stored in set with given name to newVal No error messages are printed...
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
bool selectCommon(const RooAbsCollection &refColl, RooAbsCollection &outColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
std::string contentsString() const
Return comma separated list of contained object names as STL string.
void setName(const char *name)
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract base class for binned and unbinned datasets.
RooFit::OwningPtr< RooAbsData > reduce(const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Create a reduced copy of this dataset.
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
RooArgSet const * getGlobalObservables() const
Returns snapshot of global observables stored in this data.
Abstract base class for objects that are lvalues, i.e.
virtual std::list< std::string > getBinningNames() const =0
virtual void setBin(Int_t ibin, const char *rangeName=nullptr)=0
Abstract interface for all probability density functions.
TString _normRange
Normalization range.
RooArgSet const * _normSet
! Normalization set with for above integral
bool canBeExtended() const
If true, PDF can provide extended likelihood term.
RooAbsPdf()
Default constructor.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
virtual void setVal(double value)=0
Set the current value of the object. Needs to be overridden by implementations.
bool hasRange(const char *name) const override
Check if variable has a binning with given name.
Context to temporarily change the error logging mode as long as the context is alive.
Abstract base class for objects that represent a real value and implements functionality common to al...
bool isSelectedComp() const
If true, the current pdf is a selected component (for use in plotting).
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
double getPropagatedError(const RooFitResult &fr, const RooArgSet &nset={}) const
Propagates parameter uncertainties to an uncertainty estimate for this RooAbsReal.
Efficient implementation of a sum of PDFs of the form.
Calculates the sum of a set of RooAbsReal terms, or when constructed with two sets,...
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Abstract interface for RooAbsArg proxy classes.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
RooArgSet * selectByAttrib(const char *name, bool value) const
Use RooAbsCollection::selectByAttrib(), but return as RooArgSet.
Implements a RooAbsBinning in terms of an array of boundary values, posing no constraints on the choi...
Object to represent discrete states.
bool defineType(const std::string &label)
Define a state with given name.
Named container for two doubles, two integers two object points and three string pointers that can be...
static const RooCmdArg & none()
Return reference to null argument.
Represents a constant real-valued object.
Container class to hold N-dimensional binned data.
Container class to hold unbinned data.
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
TMatrixDSym conditionalCovarianceMatrix(const RooArgList ¶ms) const
Return a reduced covariance matrix, which is calculated as.
void setCovQual(Int_t val)
const TMatrixDSym & covarianceMatrix() const
Return covariance matrix.
Int_t statusCodeHistory(UInt_t icycle) const
const RooArgList & floatParsInit() const
Return list of floating parameters before fit.
TMatrixDSym reducedCovarianceMatrix(const RooArgList ¶ms) const
Return a reduced covariance matrix (Note that Vred is a simple sub-matrix of V, row/columns are order...
const RooArgList & randomizePars() const
Generate random perturbations of the final parameters using the covariance matrix.
void setCovarianceMatrix(TMatrixDSym &V)
Store externally provided correlation matrix in this RooFitResult ;.
double edm() const
Return estimated distance to minimum.
const RooArgList & constPars() const
Return list of constant parameters.
const char * statusLabelHistory(UInt_t icycle) const
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
Int_t covQual() const
Return MINUIT quality code of covariance matrix.
TH2 * correlationHist(const char *name="correlation_matrix") const
Return TH2D of correlation matrix.
const RooArgList & floatParsFinal() const
Return list of floating parameters after fit.
Int_t status() const
Return MINUIT status code.
void setFinalParList(const RooArgList &list)
Fill the list of final values of the floating parameters.
UInt_t numStatusHistory() const
const TMatrixDSym & correlationMatrix() const
Return correlation matrix ;.
double minNll() const
Return minimized -log(L) value.
Implementation of a probability density function that takes a RooArgList of servers and a C++ express...
A real-valued function sampled from a multidimensional histogram.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
virtual void Add(TObject *arg)
TIterator * MakeIterator(bool forward=true) const
Create a TIterator for this list.
static RooMsgService & instance()
Return reference to singleton instance.
StreamConfig & getStream(Int_t id)
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
Implementation of a RooCacheManager<RooAbsCacheElement> that specializes in the storage of cache elem...
Efficient implementation of a product of PDFs of the form.
Represents the product of a given set of RooAbsReal objects.
RooRealProxy intpdf
p.d.f that is integrated
RooProjectedPdf()
Default constructor.
const RooAbsReal * getProjection(const RooArgSet *iset, const RooArgSet *nset, const char *rangeName, int &code) const
Retrieve object representing projection integral of input p.d.f over observables iset,...
RooSetProxy intobs
observables that p.d.f is integrated over
Implements a PDF constructed from a sum of functions:
Variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
void setRange(const char *name, double min, double max, bool shared=true)
Set a fit or plotting range.
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
const RooAbsCategoryLValue & indexCat() const
HypoTestResult is a base class for results from hypothesis tests.
< A class that holds configuration information for a model using a workspace as a store
void SetParametersOfInterest(const RooArgSet &set)
Specify parameters of interest.
void SetObservables(const RooArgSet &set)
Specify the observables.
void SetPdf(const RooAbsPdf &pdf)
Set the Pdf, add to the workspace if not already there.
void SetNuisanceParameters(const RooArgSet &set)
Specify the nuisance parameters (parameters that are not POI).
void SetGlobalObservables(const RooArgSet &set)
Specify the global observables.
A RooAbsArg implementing string values.
Persistable container for RooFit projects.
bool removeSet(const char *name)
Remove a named set from the workspace.
RooFactoryWSTool & factory()
Return instance to factory tool.
bool import(const RooAbsArg &arg, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}, const RooCmdArg &arg9={})
Import a RooAbsArg object, e.g.
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 void SetTickSize(Float_t size=0.03)
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.
virtual Color_t GetFillColor() const
Return the fill area color.
virtual Style_t GetFillStyle() const
Return the fill area style.
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
virtual Color_t GetLineColor() const
Return the line color.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Float_t GetRightMargin() const
Float_t GetTopMargin() const
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Class to manage histogram axis.
virtual void LabelsOption(Option_t *option="h")
Set option(s) to draw axis with labels option can be:
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Bool_t IsAlphanumeric() const
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.
virtual const char * GetTimeFormatOnly() const
Return only the time format from the string fTimeFormat.
virtual TObject * GetParent() const
Using a TBrowser one can browse all ROOT objects.
TBrowserImp * GetBrowserImp() const
static TCanvas * MakeDefCanvas()
Static function to build a default canvas.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
void SetName(const char *name)
virtual Int_t GetEntries() const
virtual void RemoveAll(TCollection *col)
Remove all objects in collection col from this collection.
static void InitializeColors()
static Int_t GetNumberOfColors()
static Int_t GetColorPalette(Int_t i)
TDirectory::TContext keeps track and restore the current directory.
Describe directory structure in memory.
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
virtual TList * GetListOfKeys() const
TExec is a utility class that can be used to execute a C++ command when some event happens in a pad.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Create a dialog for fit function parameter settings.
System file browser, used as TRootBrowser plug-in.
A list tree is a widget that can contain a number of items arranged in a tree structure.
ROOT GUI Window base class.
virtual void ImportAxisAttributes(TAxis *axis)
virtual void SetTitle(const char *title="")
virtual void SetPointError(Double_t exl, Double_t exh, Double_t eyl, Double_t eyh)
virtual void SetPointEYhigh(Int_t i, Double_t eyh)
virtual void SetPointEYlow(Int_t i, Double_t eyl)
Double_t GetErrorYlow(Int_t i) const override
virtual void AddPoint(Double_t x, Double_t y)
Append a new point to the graph.
virtual void SetPointX(Int_t i, Double_t x)
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
virtual void SetEditable(Bool_t editable=kTRUE)
virtual TH1F * GetHistogram() const
void SetName(const char *name="") override
Set the name of the TNamed.
void Draw(Option_t *chopt="") override
Default Draw method for all objects.
void SetTitle(const char *title="") override
Set the title of the TNamed.
1-D histogram with a double per channel (see TH1 documentation)
1-D histogram with a float per channel (see TH1 documentation)
TH1 is the base class of all histogram classes in ROOT.
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
void SetTitle(const char *title) override
Change/set the title.
virtual Int_t GetNbinsY() const
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
@ kNoTitle
Don't draw the histogram title.
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
TObject * FindObject(const char *name) const override
Search object named name in the list of functions.
virtual Int_t GetNbinsX() const
virtual void SetMaximum(Double_t maximum=-1111)
virtual Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="")
Performs the operation: this = this + c1*f1 if errors are defined (see TH1::Sumw2),...
virtual void SetBinError(Int_t bin, Double_t error)
Set the bin Error Note that this resets the bin eror option to be of Normal Type and for the non-empt...
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
void Draw(Option_t *option="") override
Draw this histogram with options.
virtual void SetMinimum(Double_t minimum=-1111)
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
TList * GetListOfFunctions() const
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
virtual Bool_t Divide(TF1 *f1, Double_t c1=1)
Performs the operation: this = this/(c1*f1) if errors are defined (see TH1::Sumw2),...
virtual Double_t GetMinimum(Double_t minval=-FLT_MAX) const
Return minimum value larger than minval of bins in the range, unless the value has been overridden by...
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
2-D histogram with a double per channel (see TH1 documentation)
Service class for 2-D histogram classes.
Int_t Fill(Double_t) override
Invalid Fill method.
virtual void Add(TH1 *h, Option_t *option="")
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Storage class for one entry of a TLegend.
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
void SetNColumns(Int_t nColumns)
void SetMargin(Float_t margin)
Use the TLine constructor to create a simple line.
void Add(TObject *obj) override
A TMemFile is like a normal TFile except that it reads and writes only from memory.
virtual void Add(TGraph *graph, Option_t *chopt="")
void Draw(Option_t *chopt="") override
Default Draw method for all objects.
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).
Wrapper around a TObject so it can be stored in a TList.
TObject * GetObject() const
Mother of all ROOT objects.
virtual void Inspect() const
Dump contents of this object in a graphics canvas.
Bool_t TestBit(UInt_t f) const
virtual const char * GetName() const
Returns name of object.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual TObject * DrawClone(Option_t *option="") const
Draw a clone of this object in the current selected pad with: gROOT->SetSelectedPad(c1).
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
virtual void Delete(Option_t *option="")
Delete this object.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual const char * GetTitle() const
Returns title of object.
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
TObject()
TObject constructor.
@ 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.
void FillCollideGrid(TObject *o)
Initialise the grid used to find empty space when adding a box (Legend) in a pad.
Bool_t PlaceBox(TObject *o, Double_t w, Double_t h, Double_t &xl, Double_t &yb, Option_t *option="lb") override
Place a box in NDC space.
Int_t fCGnx
! Size of the collide grid along x
Bool_t Collide(Int_t i, Int_t j, Int_t w, Int_t h)
Check if a box of size w and h collide some primitives in the pad at position i,j.
std::vector< Bool_t > fCollideGrid
! Grid used to find empty space when adding a box (Legend) in a pad
Int_t fCGny
! Size of the collide grid along y
virtual void SetMargin(Float_t margin=0.05)
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
virtual void SetName(const char *name="")
virtual void SetBorderSize(Int_t bordersize=4)
Sets the border size of the TPave box and shadow.
void SetEntryVal(Int_t, Double_t)
void SetEntryFillColor(Int_t, Int_t)
void SetEntryLabel(Int_t, const char *text="Slice")
void Draw(Option_t *option="l") override
Default Draw method for all objects.
This is the ROOT implementation of the Qt object communication mechanism (see also http://www....
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Regular expression class.
This class creates a ROOT object browser, constituted by three main tabs.
Sequenceable collection abstract base class.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Stop()
Stop the stopwatch.
Provides iteration through tokens of a given string.
Bool_t NextToken()
Get the next token, it is stored in this TString.
Bool_t IsDec() const
Returns true if all characters in string are decimal digits (0-9).
void ToLower()
Change string to lower-case.
Int_t Atoi() const
Return integer value of string.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Double_t Atof() const
Return floating-point value contained in string.
Bool_t IsFloat() const
Returns kTRUE if string contains a floating point or integer number.
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 IsAlpha() const
Returns true if all characters in string are alphabetic.
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Int_t CountChar(Int_t c) const
Return number of times character c occurs in the string.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
TStyle objects may be created to define special styles.
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 TList * GetListOfPrimitives() const =0
virtual void SetPad(const char *name, const char *title, Double_t xlow, Double_t ylow, Double_t xup, Double_t yup, Color_t color=35, Short_t bordersize=5, Short_t bordermode=-1)=0
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
const char * GetName() const override=0
Returns name of object.
virtual TVirtualPad * GetPad(Int_t subpadnumber) const =0
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)=0
virtual Int_t GetLogy() const =0
virtual void SetLogy(Int_t value=1)=0
virtual TObject * GetPrimitive(const char *name) const =0
virtual void SetBorderSize(Short_t bordersize)=0
virtual void SetName(const char *name)=0
double evaluate() const override
Evaluate projected p.d.f.
TObject * clone(const char *newname) const override
double expectedEvents(const RooArgSet *nset) const override
Return expected number of events to be used in calculation of extended likelihood.
ExtendMode extendMode() const override
Returns ability of PDF to provide extended likelihood terms.
RooProjectedPdf()
Default constructor.
RooCmdArg RecycleConflictNodes(bool flag=true)
RooConstVar & RooConst(double val)
RooCmdArg Embedded(bool flag=true)
RooCmdArg WeightVar(const char *name="weight", bool reinterpretAsWeight=false)
RooCmdArg GlobalObservables(Args_t &&... argsOrArgSet)
RooCmdArg ExternalConstraints(const RooArgSet &constraintPdfs)
RooCmdArg Range(const char *rangeName, bool adjustNorm=true)
int main(int argc, char **argv)
if(pos!=-1) leafTypeName.Remove(pos)
double gaussian_cdf(double x, double sigma=1, double x0=0)
Alternative name for same function.
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
The namespace of The Lean Mean C++ Option Parser.
bool EndsWith(std::string_view string, std::string_view suffix)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
static constexpr auto NumIntegration
Alias of MsgLevel::NumericIntegration for backwards compatibility.
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
constexpr Double_t C()
Velocity of light in .
Double_t Prob(Double_t chi2, Int_t ndf)
Double_t ChisquareQuantile(Double_t p, Double_t ndf)
Double_t StdDev(Long64_t n, const T *a, const Double_t *w=nullptr)
#define BEGIN_XROOFIT_NAMESPACE
#define END_XROOFIT_NAMESPACE
void removeTopic(RooFit::MsgTopic oldTopic)
bool isNaNWithPayload() const
Test if this struct has a float packed into its mantissa.
static float unpackNaN(double val)
If val is NaN and a this NaN has been tagged as containing a payload, unpack the float from the manti...
static uint64_t sum(uint64_t i)
void(* gOldHandlerr)(int)
void addLegendEntry(TObject *o, const char *title, const char *opt)
void buildHistogramInterrupt(int signum)
auto GETACTBROWSER(TRootBrowser *b)
auto & GETWSSNAPSHOTS(RooWorkspace *w)
bool TopRightPlaceBox(TPad *p, TObject *o, double w, double h, double &xl, double &yb)
TPaveText * getPave(const char *name="labels", bool create=true, bool doPaint=false)
std::string formatLegendString(const std::string &s)
auto GETROOTDIR(TGFileBrowser *b)
const xRooNode * runningNode
auto GETLISTTREE(TGFileBrowser *b)
const T & _or_func(const T &a, const T &b)
double new_getPropagatedError(const RooAbsReal &f, const RooFitResult &fr, const RooArgSet &nset={}, RooArgList **pars=nullptr, bool asymHi=false, bool asymLo=false)
TLegend * getLegend(bool create=true, bool doPaint=false)