30#include "RConfigure.h"
32#ifdef ROOFIT_HS3_WITH_RYML
108bool isNumber(
const std::string &str)
111 for (
char const &
c : str) {
112 if (std::isdigit(
c) == 0 &&
c !=
'.' && !(
first && (
c ==
'-' ||
c ==
'+')))
134RooRealVar *RooJSONFactoryWSTool::request<RooRealVar>(
const std::string &objname,
const std::string &requestAuthor)
139 if (
irootnode().has_child(
"variables")) {
152RooAbsPdf *RooJSONFactoryWSTool::request<RooAbsPdf>(
const std::string &objname,
const std::string &requestAuthor)
170RooAbsReal *RooJSONFactoryWSTool::request<RooAbsReal>(
const std::string &objname,
const std::string &requestAuthor)
182 if (isNumber(objname))
193 if (
irootnode().has_child(
"variables")) {
202 if (
irootnode().has_child(
"functions")) {
216void logInputArgumentsError(std::stringstream &&ss)
238 }
else if (val.
is_seq()) {
240 this->
bounds.push_back(val[i].val_float());
254 for (
const auto &ns : p[
"namespaces"].
children()) {
255 if (prefix.size() > 0)
260 if (trailing_underscore && prefix.size() > 0)
267inline void genIndicesHelper(std::vector<std::vector<int>> &combinations, std::vector<int> &curr_comb,
268 const std::vector<int> &vars_numbins,
size_t curridx)
270 if (curridx == vars_numbins.size()) {
272 combinations.push_back(std::vector<int>(curr_comb));
274 for (
int i = 0; i < vars_numbins[curridx]; ++i) {
275 curr_comb[curridx] = i;
276 ::genIndicesHelper(combinations, curr_comb, vars_numbins, curridx + 1);
281std::string containerName(
RooAbsArg *elem)
283 std::string contname =
"functions";
287 contname =
"variables";
295 std::unique_ptr<const RooJSONFactoryWSTool::Importer>
f,
bool topPriority)
298 vec.insert(topPriority ?
vec.begin() :
vec.end(), std::move(
f));
306 vec.insert(topPriority ?
vec.begin() :
vec.end(), std::move(
f));
314 for (
size_t i = element.second.size(); i > 0; --i) {
315 auto *imp = element.second[i - 1].get();
316 std::string
name(
typeid(*imp).name());
317 if (
name.find(needle) != std::string::npos) {
318 element.second.erase(element.second.begin() + i - 1);
330 for (
size_t i = element.second.size(); i > 0; --i) {
331 auto *imp = element.second[i - 1].get();
332 std::string
name(
typeid(*imp).name());
333 if (
name.find(needle) != std::string::npos) {
334 element.second.erase(element.second.begin() + i - 1);
345 for (
const auto &ePtr :
x.second) {
347 auto const &
e = *ePtr;
348 std::cout <<
x.first <<
"\t" <<
typeid(
e).
name() << std::endl;
355 for (
const auto &ePtr :
x.second) {
357 auto const &
e = *ePtr;
358 std::cout <<
x.first->GetName() <<
"\t" <<
typeid(
e).
name() << std::endl;
373 if (
n.has_child(
"dict") &&
n[
"dict"].is_map()) {
374 for (
const auto &attr :
n[
"dict"].children()) {
378 if (
n.has_child(
"tags") &&
n[
"tags"].is_seq()) {
379 for (
const auto &attr :
n[
"tags"].children()) {
384inline bool checkRegularBins(
const TAxis &ax)
388 for (
int i = 0; i <= ax.
GetNbins(); ++i) {
404 for (
int i = 0; i <= ax.
GetNbins(); ++i) {
419 std::stringstream expression;
420 std::string classname(
ex.tclass->GetName());
421 size_t colon = classname.find_last_of(
":");
422 if (colon < classname.size()) {
423 expression << classname.substr(colon + 1);
425 expression << classname;
427 expression <<
"::" <<
name <<
"(";
429 for (
auto k :
ex.arguments) {
436 }
else if (k ==
"false") {
440 std::stringstream err;
441 err <<
"factory expression for class '" <<
ex.tclass->GetName() <<
"', which expects key '" << k
442 <<
"' missing from input for object '" <<
name <<
"', skipping.";
448 for (
const auto &
x : p[k].children()) {
452 std::string obj(
x.val());
458 std::string obj(p[k].val());
464 return expression.str();
474 std::ifstream infile(fname);
475 if (!infile.is_open()) {
476 std::cerr <<
"unable to read file '" << fname <<
"'" << std::endl;
482 for (
const auto &cl :
n.children()) {
484 if (!cl.has_child(
"class")) {
485 std::cerr <<
"error in file '" << fname <<
"' for entry '" << key <<
"': 'class' key is required!"
489 std::string classname(cl[
"class"].val());
492 std::cerr <<
"unable to find class " << classname <<
", skipping." << std::endl;
496 if (!cl.has_child(
"arguments")) {
497 std::cerr <<
"class " << classname <<
" seems to have no arguments attached, skipping" << std::endl;
500 for (
const auto &arg : cl[
"arguments"].children()) {
501 ex.arguments.push_back(arg.val());
503 if (
c->InheritsFrom(RooAbsPdf::Class())) {
504 pdfFactoryExpressions[key] =
ex;
505 }
else if (
c->InheritsFrom(RooAbsReal::Class())) {
506 funcFactoryExpressions[key] =
ex;
508 std::cerr <<
"class " << classname <<
" seems to not inherit from any suitable class, skipping"
513 }
catch (
const std::exception &
ex) {
514 std::cout <<
"caught" << std::endl;
515 std::cerr <<
"unable to load factory expressions: " <<
ex.what() << std::endl;
528 std::cout << it.first;
529 std::cout <<
" " << it.second.tclass->
GetName();
530 for (
auto v : it.second.arguments) {
531 std::cout <<
" " <<
v;
533 std::cout << std::endl;
536 std::cout << it.first;
537 std::cout <<
" " << it.second.tclass->GetName();
538 for (
auto v : it.second.arguments) {
539 std::cout <<
" " <<
v;
541 std::cout << std::endl;
547 std::vector<std::vector<int>> combinations;
548 std::vector<int> vars_numbins;
549 vars_numbins.reserve(vars.
size());
550 for (
const auto *absv : static_range_cast<RooRealVar *>(vars)) {
551 vars_numbins.push_back(absv->numBins());
553 std::vector<int> curr_comb(vars.
size());
554 ::genIndicesHelper(combinations, curr_comb, vars_numbins, 0);
560 auto &observables =
n[
"observables"];
561 observables.set_map();
562 auto &
x = observables[varnames[0]];
563 writeAxis(
x, *(
h.GetXaxis()));
564 if (
h.GetDimension() > 1) {
565 auto &
y = observables[varnames[1]];
566 writeAxis(
y, *(
h.GetYaxis()));
567 if (
h.GetDimension() > 2) {
568 auto &z = observables[varnames[2]];
569 writeAxis(z, *(
h.GetZaxis()));
578 auto &weights =
n[
"counts"];
581 n[
"errors"].set_seq();
586 for (
int i = 1; i <=
h.GetNbinsX(); ++i) {
587 if (
h.GetDimension() == 1) {
588 weights.append_child() <<
h.GetBinContent(i);
593 for (
int j = 1; j <=
h.GetNbinsY(); ++j) {
594 if (
h.GetDimension() == 2) {
595 weights.append_child() <<
h.GetBinContent(i, j);
597 n[
"errors"].append_child()
601 for (
int k = 1; k <=
h.GetNbinsZ(); ++k) {
602 weights.append_child() <<
h.GetBinContent(i, j, k);
604 n[
"errors"].append_child()
623 std::ifstream infile(fname);
624 if (!infile.is_open()) {
625 std::cerr <<
"unable to read file '" << fname <<
"'" << std::endl;
631 for (
const auto &cl :
n.children()) {
635 std::cerr <<
"unable to find class " << classname <<
", skipping." << std::endl;
638 if (!cl.has_child(
"type")) {
639 std::cerr <<
"class " << classname <<
"has not type key set, skipping" << std::endl;
642 if (!cl.has_child(
"proxies")) {
643 std::cerr <<
"class " << classname <<
"has no proxies identified, skipping" << std::endl;
646 ex.
type = cl[
"type"].val();
647 for (
const auto &k : cl[
"proxies"].children()) {
649 std::string val(k.val());
650 ex.proxies[key] = val;
655 }
catch (
const std::exception &
ex) {
656 std::cerr <<
"unable to load export keys: " <<
ex.what() << std::endl;
670 std::cout << it.first->GetName() <<
": " << it.second.type;
671 for (
const auto &kv : it.second.proxies) {
672 std::cout <<
" " << kv.first <<
"=" << kv.second;
674 std::cout << std::endl;
686 for (
const auto &t :
n.children()) {
691 }
else if (
n.is_map()) {
692 return n.has_child(elem.c_str());
701 if (!
find(
n, elem)) {
702 n.append_child() << elem;
710 auto &dict =
n[
"dict"];
713 dict[it.first] << it.second;
717 auto &tags =
n[
"tags"];
727 auto &var =
n[
v->GetName()];
732 var[
"value"] << cv->
getVal();
733 var[
"const"] <<
true;
735 var[
"value"] << rrv->
getVal();
736 if (rrv->
getMin() > -1e30) {
737 var[
"min"] << rrv->
getMin();
739 if (rrv->
getMax() < 1e30) {
740 var[
"max"] << rrv->
getMax();
746 var[
"nbins"] << rrv->
numBins();
755 for (
auto *arg : allElems) {
759 if (
v->InheritsFrom(RooRealVar::Class()) ||
v->InheritsFrom(RooConstVar::Class())) {
778 }
else if (func->
InheritsFrom(RooAbsCategory::Class())) {
792 for (
auto &exp : it->second) {
796 if (!exp->exportObject(
this, func, elem)) {
799 if (exp->autoExportDependants()) {
804 }
catch (
const std::exception &
ex) {
805 std::cerr <<
"error exporting " << func->Class()->
GetName() <<
" " << func->
GetName() <<
": " <<
ex.what()
806 <<
". skipping." << std::endl;
816 std::cerr <<
"unable to export class '" << cl->
GetName() <<
"' - no export keys available!" << std::endl;
817 std::cerr <<
"there are several possible reasons for this:" << std::endl;
818 std::cerr <<
" 1. " << cl->
GetName() <<
" is a custom class that you or some package you are using added."
820 std::cerr <<
" 2. " << cl->
GetName()
821 <<
" is a ROOT class that nobody ever bothered to write a serialization definition for."
823 std::cerr <<
" 3. something is wrong with your setup, e.g. you might have called "
824 "RooJSONFactoryWSTool::clearExportKeys() and/or never successfully read a file defining these "
825 "keys with RooJSONFactoryWSTool::loadExportKeys(filename)"
827 std::cerr <<
"either way, please make sure that:" << std::endl;
828 std::cerr <<
" 3: you are reading a file with export keys - call RooJSONFactoryWSTool::printExportKeys() to "
829 "see what is available"
831 std::cerr <<
" 2 & 1: you might need to write a serialization definition yourself. check "
832 "https://github.com/root-project/root/blob/master/roofit/hs3/README.md to "
833 "see how to do this!"
842 elem[
"type"] << dict->second.type;
845 for (
size_t i = 0; i < nprox; ++i) {
848 std::string pname(p->
name());
852 auto k = dict->second.proxies.find(pname);
853 if (k == dict->second.proxies.end()) {
854 std::cerr <<
"failed to find key matching proxy '" << pname <<
"' for type '" << dict->second.type
855 <<
"', skipping" << std::endl;
861 auto &items = elem[k->second];
864 items.append_child() <<
e->
GetName();
869 elem[k->second] <<
r->arg().
GetName();
880 for (
auto *arg : allElems) {
895 for (
const auto &p :
n.children()) {
923 std::stringstream ss;
924 ss <<
"RooJSONFactoryWSTool() function node " +
name +
" is not a map!";
925 logInputArgumentsError(std::move(ss));
929 if (prefix.size() > 0)
932 std::stringstream ss;
933 ss <<
"RooJSONFactoryWSTool() no type given for function '" <<
name <<
"', skipping." << std::endl;
934 logInputArgumentsError(std::move(ss));
938 bool toplevel =
false;
943 std::string functype(p[
"type"].val());
951 for (
auto &imp : it->second) {
952 ok = isPdf ? imp->importPdf(
this, p) : imp->importFunction(
this, p);
958 auto expr = isPdf ? pdfFactoryExpressions.find(functype) : funcFactoryExpressions.find(functype);
959 if (expr != (isPdf ? pdfFactoryExpressions.end() : funcFactoryExpressions.end())) {
960 std::string expression = ::generate(expr->second, p,
this);
962 std::stringstream ss;
963 ss <<
"RooJSONFactoryWSTool() failed to create " << expr->second.tclass->GetName() <<
" '" <<
name
964 <<
"', skipping. expression was\n"
965 << expression << std::endl;
966 logInputArgumentsError(std::move(ss));
969 std::stringstream ss;
970 ss <<
"RooJSONFactoryWSTool() no handling for type '" << functype <<
"' implemented, skipping."
972 <<
"there are several possible reasons for this:\n"
973 <<
" 1. " << functype <<
" is a custom type that is not available in RooFit.\n"
974 <<
" 2. " << functype
975 <<
" is a ROOT class that nobody ever bothered to write a deserialization definition for.\n"
976 <<
" 3. something is wrong with your setup, e.g. you might have called "
977 "RooJSONFactoryWSTool::clearFactoryExpressions() and/or never successfully read a file defining "
978 "these expressions with RooJSONFactoryWSTool::loadFactoryExpressions(filename)\n"
979 <<
"either way, please make sure that:\n"
980 <<
" 3: you are reading a file with factory expressions - call "
981 "RooJSONFactoryWSTool::printFactoryExpressions() "
982 "to see what is available\n"
983 <<
" 2 & 1: you might need to write a deserialization definition yourself. check "
984 "https://github.com/root-project/root/blob/master/roofit/hs3/README.md to see "
987 logInputArgumentsError(std::move(ss));
993 std::stringstream err;
994 err <<
"something went wrong importing function '" <<
name <<
"'.";
997 ::importAttributes(func, p);
999 if (isPdf && toplevel) {
1007 }
catch (
const std::exception &
ex) {
1008 std::stringstream ss;
1009 ss <<
"RooJSONFactoryWSTool(): error importing " <<
name <<
": " <<
ex.what() <<
". skipping." << std::endl;
1010 logInputArgumentsError(std::move(ss));
1021 obs.
add(*weight,
true);
1023 for (
int i = 0; i < hist.
numEntries(); ++i) {
1024 data->add(*hist.
get(i), hist.
weight(i));
1046 std::map<std::string, std::unique_ptr<RooAbsData>> dataMap;
1050 for (
const auto &p :
n.children()) {
1063 }
else if (p.
has_child(
"coordinates")) {
1069 vars.
add(*weightVar,
true);
1071 auto &coords = p[
"coordinates"];
1072 auto &weights = p[
"weights"];
1073 if (coords.num_children() != weights.num_children()) {
1076 if (!coords.is_seq()) {
1079 for (
size_t i = 0; i < coords.num_children(); ++i) {
1080 auto &point = coords[i];
1081 if (!point.is_seq()) {
1084 if (point.num_children() != varlist.
size()) {
1087 for (
size_t j = 0; j < point.num_children(); ++j) {
1089 v->
setVal(point[j].val_float());
1091 data->add(vars, weights[i].val_float());
1093 dataMap[
name] = std::move(data);
1097 auto catname = p[
"index"].
val();
1100 std::stringstream ss;
1101 ss <<
"RooJSONFactoryWSTool() failed to retrieve channel category " << catname << std::endl;
1102 logInputArgumentsError(std::move(ss));
1105 allVars.
add(*channelCat,
true);
1106 std::stack<std::unique_ptr<RooDataSet>> ownedDataSets;
1107 std::map<std::string, RooDataSet *> datasets;
1108 for (
const auto &subd : subMap) {
1109 allVars.
add(*subd.second->get(),
true);
1110 if (subd.second->InheritsFrom(RooDataHist::Class())) {
1112 datasets[subd.first] = ownedDataSets.top().get();
1114 datasets[subd.first] =
static_cast<RooDataSet *
>(subd.second.get());
1118 allVars.
add(*weightVar,
true);
1124 std::stringstream ss;
1125 ss <<
"RooJSONFactoryWSTool() failed to create dataset " <<
name << std::endl;
1126 logInputArgumentsError(std::move(ss));
1142 for (
const auto &obs : observables) {
1143 if (obs->InheritsFrom(RooAbsCategory::Class())) {
1146 " has several category observables!");
1157 std::unique_ptr<TList> dataList{ds->
split(*(cat),
true)};
1160 std::string(cat->
GetName()) +
"'");
1162 for (
RooAbsData *absData : static_range_cast<RooAbsData *>(*dataList)) {
1168 auto &obs =
output[
"observables"];
1171 auto &weights =
output[
"counts"];
1175 weights.append_child() << dh->
weight();
1185 std::map<RooRealVar *, std::vector<double>> obs_values;
1188 for (
const auto &obs : observables) {
1190 obs_values[rv].push_back(rv->
getVal());
1193 for (
auto &obs_it : obs_values) {
1194 auto &vals = obs_it.second;
1195 double v0 = vals[0];
1196 bool is_const_val = std::all_of(vals.begin(), vals.end(), [
v0](
double v) { return v == v0; });
1198 reduced_obs.
add(*(obs_it.first),
true);
1202 reduced_obs.
add(observables);
1204 if (reduced_obs.
size() > 0) {
1205 auto &obsset =
output[
"observables"];
1214 auto &coordinates =
output[
"coordinates"];
1215 coordinates.set_seq();
1216 auto &point = coordinates.append_child();
1218 for (
const auto &obs : reduced_obs) {
1220 point.append_child() << rv->
getVal();
1223 weights.append_child() << ds->
weight();
1237 for (
auto v : vars) {
1238 std::string
name(
v.first);
1249 for (
auto *arg : args) {
1283std::unique_ptr<RooDataHist>
1288 if (varlist.
size() == 0) {
1289 std::string obsname =
"obs_x_" + namecomp;
1293 if (!
n.has_child(
"counts"))
1295 if (!
n[
"counts"].is_seq())
1297 auto &counts =
n[
"counts"];
1298 if (counts.num_children() != bins.size())
1300 (
int)counts.num_children(), (
int)(bins.size())));
1301 auto dh = std::make_unique<RooDataHist>((
"dataHist_" + namecomp).c_str(), namecomp.c_str(), varlist);
1303 std::vector<double> initVals;
1304 for (
auto &
v : varlist) {
1305 v->setDirtyInhibit(
true);
1308 for (
size_t ibin = 0; ibin < bins.size(); ++ibin) {
1309 for (
size_t i = 0; i < bins[ibin].size(); ++i) {
1313 dh->add(varlist, counts[ibin].val_float());
1316 for (
size_t i = 0; i < varlist.
size(); ++i) {
1319 v->setDirtyInhibit(
false);
1326std::map<std::string, RooJSONFactoryWSTool::Var>
1329 std::map<std::string, RooJSONFactoryWSTool::Var> vars;
1332 if (
n.has_child(
"observables")) {
1333 auto &observables =
n[
"observables"];
1334 if (!observables.is_map())
1336 if (observables.has_child(
"nbins")) {
1339 for (
const auto &p : observables.children()) {
1356 for (
const auto &p :
n.children()) {
1366 std::string mcname =
"ModelConfig";
1368 if (p[
"dict"].has_child(
"ModelConfig")) {
1369 mcname = p[
"dict"][
"ModelConfig"].
val();
1384 std::unique_ptr<RooArgSet> pdfVars{pdf.
getVariables()};
1386 if (!pdfVars->find(*var))
1388 if (var->getAttribute(
"observable")) {
1389 observables.
add(*var,
true);
1391 if (var->getAttribute(
"np")) {
1392 nps.
add(*var,
true);
1394 if (var->getAttribute(
"poi")) {
1395 pois.
add(*var,
true);
1397 if (var->getAttribute(
"glob")) {
1398 globs.
add(*var,
true);
1406 std::stringstream ss;
1407 ss <<
"RooJSONFactoryWSTool() object '" << mcname <<
"' in workspace is not of type RooStats::ModelConfig!"
1409 logInputArgumentsError(std::move(ss));
1420 for (
const auto &p :
n.children()) {
1434 std::stringstream ss;
1435 ss <<
"RooJSONFactoryWSTool() node '" <<
name <<
"' is not a map, skipping." << std::endl;
1436 logInputArgumentsError(std::move(ss));
1441 ::importAttributes(&
v, p);
1450 v.setVal(p[
"value"].val_float());
1452 v.setMin(p[
"min"].val_float());
1454 v.setMax(p[
"max"].val_float());
1456 v.setBins(p[
"nbins"].val_int());
1460 v.setError(p[
"err"].val_float());
1462 v.setConstant(p[
"const"].val_bool());
1464 v.setConstant(
false);
1475 "cannot export dependents without a valid root node, only call within the context of 'exportAllObjects'");
1482 auto servers(source->
servers());
1483 for (
auto s : servers) {
1484 auto &container =
n[containerName(s)];
1485 container.set_map();
1495 if (
n.has_child(
"variables")) {
1498 if (
n.has_child(
"functions")) {
1501 if (
n.has_child(
"pdfs")) {
1508 std::stringstream ss;
1509 if (
n.is_container() &&
n.has_child(
"name")) {
1510 ss <<
n[
"name"].val();
1511 }
else if (
n.has_key()) {
1522 std::vector<RooStats::ModelConfig *> mcs;
1523 std::vector<RooAbsPdf *> toplevel;
1526 if (obj->InheritsFrom(RooStats::ModelConfig::Class())) {
1528 auto &vars =
n[
"variables"];
1535 auto &tags = vars[
v->GetName()][
"tags"];
1546 auto &tags = vars[
v->GetName()][
"tags"];
1557 auto &tags = vars[
v->GetName()][
"tags"];
1567 auto &tags = vars[
v->GetName()][
"tags"];
1577 if (!pdf->hasClients() || pdf->getAttribute(
"toplevel")) {
1579 for (
const auto &mc : mcs) {
1580 if (mc->GetPdf() == pdf)
1584 toplevel.push_back(
static_cast<RooAbsPdf *
>(pdf));
1588 auto &data =
n[
"data"];
1594 auto &snapshots =
n[
"snapshots"];
1595 snapshots.set_map();
1596 auto &coll = snapshots[snsh->
GetName()];
1600 for (
const auto &mc : mcs) {
1601 auto &pdfs =
n[
"pdfs"];
1605 auto &node = pdfs[pdf->
GetName()];
1607 auto &tags = node[
"tags"];
1611 auto &dict = node[
"dict"];
1613 dict[
"ModelConfig"] << mc->GetName();
1615 for (
const auto &pdf : toplevel) {
1616 auto &pdfs =
n[
"pdfs"];
1619 auto &node = pdfs[pdf->GetName()];
1621 auto &tags = node[
"tags"];
1623 if (!pdf->getAttribute(
"toplevel"))
1625 auto &dict = node[
"dict"];
1627 if (toplevel.size() + mcs.size() == 1) {
1628 dict[
"ModelConfig"] <<
"ModelConfig";
1630 dict[
"ModelConfig"] << std::string(pdf->GetName()) +
"_modelConfig";
1639 std::stringstream ss(s);
1646 std::stringstream ss(s);
1653 std::stringstream ss;
1661 std::stringstream ss;
1679 std::ofstream out(filename.c_str());
1680 if (!out.is_open()) {
1681 std::stringstream ss;
1682 ss <<
"RooJSONFactoryWSTool() invalid output file '" << filename <<
"'." << std::endl;
1683 logInputArgumentsError(std::move(ss));
1702 std::ofstream out(filename.c_str());
1703 if (!out.is_open()) {
1704 std::stringstream ss;
1705 ss <<
"RooJSONFactoryWSTool() invalid output file '" << filename <<
"'." << std::endl;
1706 logInputArgumentsError(std::move(ss));
1715 gROOT->ProcessLine(
"using namespace RooStats::HistFactory;");
1718 if (
n.has_child(
"data")) {
1719 auto data = this->
loadData(n[
"data"]);
1720 for (
const auto &
d : data) {
1727 for (
const auto &snsh :
n[
"snapshots"].children()) {
1729 if (
name ==
"fromJSON")
1732 for (
const auto &var : snsh.children()) {
1754 }
catch (
const std::exception &
ex) {
1755 std::cerr <<
"unable to import JSON: " <<
ex.what() << std::endl;
1764 std::ifstream infile(filename.c_str());
1765 if (!infile.is_open()) {
1766 std::stringstream ss;
1767 ss <<
"RooJSONFactoryWSTool() invalid input file '" << filename <<
"'." << std::endl;
1768 logInputArgumentsError(std::move(ss));
1780 }
catch (
const std::exception &
ex) {
1781 std::cerr <<
"unable to import JSON: " <<
ex.what() << std::endl;
1789 std::ifstream infile(filename.c_str());
1790 if (!infile.is_open()) {
1791 std::stringstream ss;
1792 ss <<
"RooJSONFactoryWSTool() invalid input file '" << filename <<
"'." << std::endl;
1793 logInputArgumentsError(std::move(ss));
1820 return _pdfFactoryExpressions;
1826 return _funcFactoryExpressions;
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
const std::set< std::string > & attributes() const
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
const RefCountList_t & servers() const
List of all servers of this object.
const std::map< std::string, std::string > & stringAttributes() const
Int_t numProxies() const
Return the number of registered proxies.
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
RooAbsProxy * getProxy(Int_t index) const
Return the nth proxy from the proxy list.
Bool_t isConstant() const
Check if the "Constant" attribute is set.
RooAbsCategory is the base class for objects that represent a discrete value with a finite number of ...
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Storage_t::size_type size() const
const char * GetName() const
Returns name of object.
RooAbsData is the common abstract base class for binned and unbinned datasets.
virtual const RooArgSet * get() const
virtual TList * split(const RooAbsCategory &splitCat, Bool_t createEmptyDataSets=kFALSE) const
Split dataset into subsets based on states of given splitCat in this dataset.
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
RooAbsProxy is the abstact interface for proxy classes.
virtual const char * name() const
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
virtual void setBin(Int_t ibin, const char *rangeName=0)
Set value to center of bin 'ibin' of binning 'rangeName' (or of default binning if no range is specif...
virtual Int_t numBins(const char *rangeName=0) const
void setConstant(Bool_t value=kTRUE)
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
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.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooCategory is an object to represent discrete states.
RooConstVar represent a constant real-valued object.
The RooDataHist is a container class to hold N-dimensional binned data.
double weight(std::size_t i) const
Return weight of i-th bin.
Int_t numEntries() const override
Return the number of bins.
const RooArgSet * get() const override
Get bin centre of current bin.
RooDataSet is a container class to hold unbinned data.
virtual const RooArgSet * get(Int_t index) const override
Return RooArgSet with coordinates of event 'index'.
virtual Double_t weight() const override
Return event weight of current event.
virtual std::string val() const =0
virtual bool has_child(std::string const &) const =0
virtual size_t num_children() const =0
virtual bool is_seq() const =0
virtual float val_float() const
virtual int val_int() const
virtual JSONNode & append_child()=0
virtual children_view children()
virtual bool is_map() const =0
RooListProxy is the concrete proxy for RooArgList objects.
static RooMsgService & instance()
Return reference to singleton instance.
std::ostream & log(const RooAbsArg *self, RooFit::MsgLevel level, RooFit::MsgTopic facility, Bool_t forceSkipPrefix=kFALSE)
Log error message associated with RooAbsArg object self at given level and topic.
RooRealVar represents a variable that can be changed from the outside.
void setMin(const char *name, Double_t value)
Set minimum of name range to given value.
void setBins(Int_t nBins, const char *name=0)
Create a uniform binning under name 'name' for this variable.
void setMax(const char *name, Double_t value)
Set maximum of name range to given value.
virtual void setVal(Double_t value)
Set value of variable to 'value'.
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
virtual void SetObservables(const RooArgSet &set)
Specify the observables.
const RooArgSet * GetGlobalObservables() const
get RooArgSet for global observables (return NULL if not existing)
virtual void SetParametersOfInterest(const RooArgSet &set)
Specify parameters of interest.
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return NULL if not existing)
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return NULL if not existing)
virtual void SetGlobalObservables(const RooArgSet &set)
Specify the global observables.
virtual void SetWS(RooWorkspace &ws) override
Set a workspace that owns all the necessary components for the analysis.
const RooArgSet * GetObservables() const
get RooArgSet for observables (return NULL if not existing)
virtual void SetNuisanceParameters(const RooArgSet &set)
Specify the nuisance parameters (parameters that are not POI).
virtual void SetPdf(const RooAbsPdf &pdf)
Set the Pdf, add to the the workspace if not already there.
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
std::list< RooAbsData * > allData() const
Return list of all dataset in the workspace.
RooArgSet allVars() const
Return set with all variable objects.
Bool_t import(const RooAbsArg &arg, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg())
Import a RooAbsArg object, e.g.
RooAbsReal * function(const char *name) const
Retrieve function (RooAbsReal) with given name. Note that all RooAbsPdfs are also RooAbsReals....
RooCategory * cat(const char *name) const
Retrieve discrete variable (RooCategory) with given name. A null pointer is returned if not found.
RooArgSet allPdfs() const
Return set with all probability density function objects.
std::list< TObject * > allGenericObjects() const
Return list of all generic objects in the workspace.
RooLinkedList const & getSnapshots() const
Bool_t saveSnapshot(const char *name, const char *paramNames)
Save snapshot of values and attributes (including "Constant") of given parameters.
Bool_t loadSnapshot(const char *name)
Load the values and attributes of the parameters in the snapshot saved with the given name.
RooRealVar * var(const char *name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
RooFactoryWSTool & factory()
Return instance to factory tool.
TObject * obj(const char *name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
Class to manage histogram axis.
Bool_t IsVariableBinSize() const
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
TClass instances represent classes, structs and namespaces in the ROOT type system.
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.
TH1 is the base class of all histogram classes in ROOT.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual Node & rootnode() override
virtual const char * GetTitle() const
Returns title of object.
virtual const char * GetName() const
Returns name of object.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
const char * Data() const
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
RooCmdArg RecycleConflictNodes(Bool_t flag=kTRUE)
RooCmdArg Silence(Bool_t flag=kTRUE)
RooCmdArg WeightVar(const char *name, Bool_t reinterpretAsWeight=kFALSE)
RooCmdArg Index(RooCategory &icat)
RooCmdArg Import(const char *state, TH1 &histo)
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
static void output(int code)