112 std::vector<double> bounds;
114 Var(
int n) : nbins(
n), min(0), max(
n) {}
118bool isNumber(
const std::string &str)
121 for (
char const &
c : str) {
122 if (std::isdigit(
c) == 0 &&
c !=
'.' && !(
first && (
c ==
'-' ||
c ==
'+')))
131 if (
auto n =
p.find(
"value"))
132 v.setVal(
n->val_double());
134 if (
auto n =
p.find(
"nbins"))
135 v.setBins(
n->val_int());
136 if (
auto n =
p.find(
"relErr"))
137 v.setError(
v.getVal() *
n->val_double());
138 if (
auto n =
p.find(
"err"))
139 v.setError(
n->val_double());
140 if (
auto n =
p.find(
"const"))
141 v.setConstant(
n->val_bool());
143 v.setConstant(
false);
148 auto paramPointsNode = rootNode.
find(
"parameter_points");
149 if (!paramPointsNode)
154 return &((*out)[
"parameters"]);
157void logInputArgumentsError(std::stringstream &&ss)
159 oocoutE(
nullptr, InputArguments) << ss.str() << std::endl;
164 if (val.
find(
"bounds")) {
165 for (
auto const &
child : val.children()) {
166 this->bounds.push_back(
child.val_double());
168 this->nbins = this->bounds.size();
169 this->min = this->bounds[0];
170 this->max = this->bounds[this->nbins - 1];
172 if (!val.
find(
"nbins"))
175 this->nbins = val[
"nbins"].
val_int();
176 if (!val.
find(
"min"))
180 if (!val.
find(
"max"))
187std::string genPrefix(
const JSONNode &
p,
bool trailing_underscore)
192 if (
auto node =
p.find(
"namespaces")) {
193 for (
const auto &ns : node->children()) {
199 if (trailing_underscore && !prefix.empty())
205void genIndicesHelper(std::vector<std::vector<int>> &combinations, std::vector<int> &curr_comb,
206 const std::vector<int> &vars_numbins,
size_t curridx)
208 if (curridx == vars_numbins.size()) {
210 combinations.emplace_back(curr_comb);
212 for (
int i = 0; i < vars_numbins[curridx]; ++i) {
213 curr_comb[curridx] = i;
214 ::genIndicesHelper(combinations, curr_comb, vars_numbins, curridx + 1);
221 if (
auto seq = node.
find(
"dict")) {
222 for (
const auto &
attr : seq->children()) {
226 if (
auto seq = node.
find(
"tags")) {
227 for (
const auto &
attr : seq->children()) {
236 std::stringstream expression;
237 std::string classname(
ex.tclass->GetName());
238 size_t colon = classname.find_last_of(
":");
239 expression << (colon < classname.size() ? classname.substr(colon + 1) : classname);
242 for (
auto k :
ex.arguments) {
243 expression << (
first ?
"::" +
name +
"(" :
",");
245 if (k ==
"true" || k ==
"false") {
246 expression << (k ==
"true" ?
"1" :
"0");
247 }
else if (!
p.has_child(k)) {
248 std::stringstream errMsg;
249 errMsg <<
"node '" <<
name <<
"' is missing key '" << k <<
"'";
251 }
else if (
p[k].is_seq()) {
252 bool firstInner =
true;
254 expression << (firstInner ?
"{" :
",") << arg->
GetName();
260 expression <<
p[k].val();
264 return expression.str();
267std::vector<std::vector<int>> generateBinIndices(
const RooArgList &vars)
269 std::vector<std::vector<int>> combinations;
270 std::vector<int> vars_numbins;
271 vars_numbins.reserve(vars.
size());
273 vars_numbins.push_back(absv->getBins());
275 std::vector<int> curr_comb(vars.
size());
276 ::genIndicesHelper(combinations, curr_comb, vars_numbins, 0);
280template <
typename... Keys_t>
281JSONNode const *findRooFitInternal(
JSONNode const &node, Keys_t
const &...keys)
283 return node.
find(
"misc",
"ROOT_internal", keys...);
286bool isLiteralConstVar(
RooAbsArg const &arg)
288 bool isRooConstVar =
dynamic_cast<RooConstVar const *
>(&arg);
289 return isRooConstVar && isNumber(arg.
GetName());
295 if (isLiteralConstVar(*arg)) {
301 auto initializeNode = [&]() {
311 bool isRooConstVar =
dynamic_cast<RooConstVar const *
>(arg);
314 (*node)[
"is_const_var"] << 1;
319 for (
const auto &it : arg->stringAttributes()) {
321 if (it.first ==
"factory_tag" || it.first ==
"PROD_TERM_TYPE")
324 (*node)[
"dict"].set_map()[it.first] << it.second;
328 for (
auto const &
attr : arg->attributes()) {
330 if (
attr ==
"SnapShot_ExtRefClone" ||
attr ==
"RooRealConstant_Factory_Object")
333 (*node)[
"tags"].set_seq().append_child() <<
attr;
342 std::map<std::string, Var> vars;
343 for (
const auto &
p : node[
"axes"].children()) {
347 for (
auto v : vars) {
348 std::string
name(
v.first);
352 std::stringstream errMsg;
353 errMsg <<
"The observable \"" <<
name <<
"\" could not be found in the workspace!";
364 std::string
const &
type =
p[
"type"].val();
365 if (
type ==
"binned") {
368 }
else if (
type ==
"unbinned") {
371 getObservables(workspace,
p, vars);
374 auto &coords =
p[
"entries"];
375 auto &weights =
p[
"weights"];
376 if (coords.num_children() != weights.num_children()) {
379 if (!coords.is_seq()) {
382 std::vector<double> weightVals;
383 for (
auto const &weight : weights.children()) {
384 weightVals.push_back(weight.val_double());
387 for (
auto const &point : coords.children()) {
388 if (!point.is_seq()) {
389 std::stringstream errMsg;
390 errMsg <<
"coordinate point '" << i <<
"' is not a list!";
393 if (point.num_children() != varlist.size()) {
397 for (
auto const &pointj : point.children()) {
398 auto *
v =
static_cast<RooRealVar *
>(varlist.at(j));
399 v->
setVal(pointj.val_double());
402 data->add(vars, weightVals[i]);
408 std::stringstream ss;
409 ss <<
"RooJSONFactoryWSTool() failed to create dataset " <<
name << std::endl;
410 logInputArgumentsError(std::move(ss));
415 RooWorkspace &workspace,
const std::vector<std::unique_ptr<RooAbsData>> &datas)
419 JSONNode const *mcAuxNode = findRooFitInternal(rootnode,
"ModelConfigs", analysisName);
421 JSONNode const *mcNameNode = mcAuxNode ? mcAuxNode->
find(
"mcName") :
nullptr;
422 std::string mcname = mcNameNode ? mcNameNode->
val() : analysisName.c_str();
423 if (workspace.
obj(mcname))
428 mc->
SetWS(workspace);
430 std::vector<std::string> nllDistNames;
431 std::vector<std::string> nllDataNames;
435 throw std::runtime_error(
"likelihood node not found!");
437 for (
auto &nameNode : (*nllNode)[
"distributions"].children()) {
438 nllDistNames.push_back(nameNode.val());
441 for (
auto &nameNode : (*nllNode)[
"aux_distributions"].children()) {
442 RooAbsArg *extConstraint = workspace.
arg(nameNode.val());
444 extConstraints.
add(*extConstraint);
448 for (
auto &nameNode : (*nllNode)[
"data"].children()) {
449 nllDataNames.push_back(nameNode.val());
450 for (
const auto &
d : datas) {
451 if (
d->GetName() == nameNode.val()) {
452 observables.
add(*
d->get());
457 JSONNode const *pdfNameNode = mcAuxNode ? mcAuxNode->
find(
"pdfName") :
nullptr;
458 std::string
const pdfName = pdfNameNode ? pdfNameNode->
val() :
"simPdf";
462 std::runtime_error(
"pdf not found!");
466 if (!extConstraints.
empty())
467 mc->SetExternalConstraints(extConstraints);
469 auto readArgSet = [&](std::string
const &
name) {
471 for (
auto const &
child : analysisNode[
name].children()) {
477 mc->SetParametersOfInterest(readArgSet(
"parameters_of_interest"));
478 mc->SetObservables(observables);
490 for (
const auto &
p : pars) {
491 if (mc->GetParametersOfInterest()->find(*
p))
493 if (
p->isConstant() && !mainPars.find(*
p))
498 mc->SetGlobalObservables(globs);
499 mc->SetNuisanceParameters(nps);
502 if (
auto found = mcAuxNode->
find(
"combined_data_name")) {
510 auto *combinedPdfInfoNode = findRooFitInternal(rootnode,
"combined_distributions");
513 if (combinedPdfInfoNode ==
nullptr) {
517 for (
auto &info : combinedPdfInfoNode->children()) {
520 std::string combinedName = info.key();
521 std::string indexCatName = info[
"index_cat"].val();
522 std::vector<std::string> labels;
523 std::vector<int> indices;
524 std::vector<std::string> pdfNames;
525 for (
auto &
n : info[
"indices"].children()) {
526 indices.push_back(
n.val_int());
528 for (
auto &
n : info[
"labels"].children()) {
529 labels.push_back(
n.val());
531 for (
auto &
n : info[
"distributions"].children()) {
532 pdfNames.push_back(
n.val());
535 RooCategory indexCat{indexCatName.c_str(), indexCatName.c_str()};
536 std::map<std::string, RooAbsPdf *> pdfMap;
538 for (std::size_t iChannel = 0; iChannel < labels.size(); ++iChannel) {
539 indexCat.
defineType(labels[iChannel], indices[iChannel]);
540 pdfMap[labels[iChannel]] = ws.
pdf(pdfNames[iChannel]);
543 RooSimultaneous simPdf{combinedName.c_str(), combinedName.c_str(), pdfMap, indexCat};
548void combineDatasets(
const JSONNode &rootnode, std::vector<std::unique_ptr<RooAbsData>> &datas)
550 auto *combinedDataInfoNode = findRooFitInternal(rootnode,
"combined_datas");
553 if (combinedDataInfoNode ==
nullptr) {
557 for (
auto &info : combinedDataInfoNode->children()) {
560 std::string combinedName = info.key();
561 std::string indexCatName = info[
"index_cat"].val();
562 std::vector<std::string> labels;
563 std::vector<int> indices;
564 for (
auto &
n : info[
"indices"].children()) {
565 indices.push_back(
n.val_int());
567 for (
auto &
n : info[
"labels"].children()) {
568 labels.push_back(
n.val());
572 std::map<std::string, std::unique_ptr<RooAbsData>> dsMap;
573 RooCategory indexCat{indexCatName.c_str(), indexCatName.c_str()};
575 for (std::size_t iChannel = 0; iChannel < labels.size(); ++iChannel) {
576 auto componentName = combinedName +
"_" + labels[iChannel];
579 std::unique_ptr<RooAbsData> &component =
580 *std::find_if(datas.begin(), datas.end(), [&](
auto &
d) { return d && d->GetName() == componentName; });
581 allVars.add(*component->get());
582 dsMap.insert({labels[iChannel], std::move(component)});
583 indexCat.defineType(labels[iChannel], indices[iChannel]);
586 auto combined = std::make_unique<RooDataSet>(combinedName.c_str(), combinedName.c_str(), allVars,
588 datas.emplace_back(std::move(combined));
593void sortByName(T &coll)
595 std::sort(coll.begin(), coll.end(), [](
auto &
l,
auto &
r) { return strcmp(l->GetName(), r->GetName()) < 0; });
608 if (isLiteralConstVar(*arg))
649 return appendNamedChild(rootNode[
"parameter_points"],
"default_values")[
"parameters"];
653RooRealVar *RooJSONFactoryWSTool::requestImpl<RooRealVar>(
const std::string &objname)
658 if (
auto node = vars->
find(objname)) {
668RooAbsPdf *RooJSONFactoryWSTool::requestImpl<RooAbsPdf>(
const std::string &objname)
683RooAbsReal *RooJSONFactoryWSTool::requestImpl<RooAbsReal>(
const std::string &objname)
687 if (isNumber(objname))
689 if (
RooAbsPdf *pdf = requestImpl<RooAbsPdf>(objname))
691 if (
RooRealVar *var = requestImpl<RooRealVar>(objname))
723 var[
"value"] << cv->getVal();
724 var[
"const"] <<
true;
726 var[
"value"] << rrv->getVal();
727 if (rrv->isConstant()) {
728 var[
"const"] << rrv->isConstant();
730 if (rrv->getBins() != 100) {
731 var[
"nbins"] << rrv->getBins();
750 if (exportedObjectNames.find(
name) != exportedObjectNames.end())
753 exportedObjectNames.insert(
name);
762 std::vector<std::string> channelNames;
763 for (
auto const &item : simPdf->indexCat()) {
764 channelNames.push_back(item.first);
768 auto &
child = infoNode[simPdf->GetName()].set_map();
769 child[
"index_cat"] << simPdf->indexCat().GetName();
771 child[
"distributions"].set_seq();
772 for (
auto const &item : simPdf->indexCat()) {
773 child[
"distributions"].append_child() << simPdf->getPdf(item.first.c_str())->GetName();
785 auto &collectionNode = (*_rootnodeOutput)[
dynamic_cast<RooAbsPdf const *
>(&func) ?
"distributions" :
"functions"];
794 auto it = exporters.find(cl);
795 if (it != exporters.end()) {
796 for (
auto &exp : it->second) {
798 if (!exp->exportObject(
this, &func, elem)) {
804 elem[
"name"] <<
name;
808 if (exp->autoExportDependants()) {
822 const auto &dict = exportKeys.find(cl);
823 if (dict == exportKeys.end()) {
824 std::cerr <<
"unable to export class '" << cl->
GetName() <<
"' - no export keys available!\n"
825 <<
"there are several possible reasons for this:\n"
826 <<
" 1. " << cl->
GetName() <<
" is a custom class that you or some package you are using added.\n"
828 <<
" is a ROOT class that nobody ever bothered to write a serialization definition for.\n"
829 <<
" 3. something is wrong with your setup, e.g. you might have called "
830 "RooFit::JSONIO::clearExportKeys() and/or never successfully read a file defining these "
831 "keys with RooFit::JSONIO::loadExportKeys(filename)\n"
832 <<
"either way, please make sure that:\n"
833 <<
" 3: you are reading a file with export keys - call RooFit::JSONIO::printExportKeys() to "
834 "see what is available\n"
835 <<
" 2 & 1: you might need to write a serialization definition yourself. check "
836 "https://github.com/root-project/root/blob/master/roofit/hs3/README.md to "
837 "see how to do this!\n";
841 elem[
"type"] << dict->second.type;
845 for (
size_t i = 0; i < nprox; ++i) {
849 std::string pname(
p->name());
853 auto k = dict->second.proxies.find(pname);
854 if (k == dict->second.proxies.end()) {
855 std::cerr <<
"failed to find key matching proxy '" << pname <<
"' for type '" << dict->second.type
856 <<
"', encountered in '" << func.
GetName() <<
"', skipping" << std::endl;
861 if (k->second.empty())
868 if (isLiteralConstVar(
r->arg()))
869 elem[k->second] <<
r->arg().getVal();
871 elem[k->second] <<
r->arg().GetName();
897 std::stringstream ss;
898 ss <<
"RooJSONFactoryWSTool() function node " +
name +
" is not a map!";
899 logInputArgumentsError(std::move(ss));
902 std::string prefix = genPrefix(
p,
true);
905 if (!
p.has_child(
"type")) {
906 std::stringstream ss;
907 ss <<
"RooJSONFactoryWSTool() no type given for function '" <<
name <<
"', skipping." << std::endl;
908 logInputArgumentsError(std::move(ss));
912 std::string functype(
p[
"type"].val());
915 if (!importAllDependants) {
920 auto it = importers.find(functype);
922 if (it != importers.end()) {
923 for (
auto &imp : it->second) {
924 ok = imp->importArg(
this,
p);
930 auto expr = factoryExpressions.find(functype);
931 if (expr != factoryExpressions.end()) {
932 std::string expression = ::generate(expr->second,
p,
this);
934 std::stringstream ss;
935 ss <<
"RooJSONFactoryWSTool() failed to create " << expr->second.tclass->GetName() <<
" '" <<
name
936 <<
"', skipping. expression was\n"
937 << expression << std::endl;
938 logInputArgumentsError(std::move(ss));
941 std::stringstream ss;
942 ss <<
"RooJSONFactoryWSTool() no handling for type '" << functype <<
"' implemented, skipping."
944 <<
"there are several possible reasons for this:\n"
945 <<
" 1. " << functype <<
" is a custom type that is not available in RooFit.\n"
946 <<
" 2. " << functype
947 <<
" is a ROOT class that nobody ever bothered to write a deserialization definition for.\n"
948 <<
" 3. something is wrong with your setup, e.g. you might have called "
949 "RooFit::JSONIO::clearFactoryExpressions() and/or never successfully read a file defining "
950 "these expressions with RooFit::JSONIO::loadFactoryExpressions(filename)\n"
951 <<
"either way, please make sure that:\n"
952 <<
" 3: you are reading a file with factory expressions - call "
953 "RooFit::JSONIO::printFactoryExpressions() "
954 "to see what is available\n"
955 <<
" 2 & 1: you might need to write a deserialization definition yourself. check "
956 "https://github.com/root-project/root/blob/master/roofit/hs3/README.md to see "
959 logInputArgumentsError(std::move(ss));
965 std::stringstream err;
966 err <<
"something went wrong importing function '" <<
name <<
"'.";
973 this->
importFunction((JSONTree::create(jsonString))->rootnode(), importAllDependants);
978 auto &observablesNode =
output[
"axes"].set_seq();
980 for (
auto *var : static_range_cast<RooRealVar *>(vars)) {
982 obsNode[
"name"] << var->GetName();
983 if (var->getBinning().isUniform()) {
984 obsNode[
"min"] << var->getMin();
985 obsNode[
"max"] << var->getMax();
986 obsNode[
"nbins"] << var->getBins();
988 auto &bounds = obsNode[
"bounds"];
990 double val = var->getBinning().binLow(0);
992 for (
int i = 0; i < var->getBinning().numBins(); ++i) {
993 val = var->getBinning().binHigh(i);
994 bounds.append_child() << val;
1005 for (std::size_t i = 0; i <
n; ++i) {
1006 double w = contents[i];
1018 auto &labels = node[
"labels"].
set_seq();
1019 auto &indices = node[
"indices"].
set_seq();
1021 for (
auto const &item : cat) {
1037 " has several category observables!");
1059 auto *combinedPdfInfoNode = findRooFitInternal(*
_rootnodeOutput,
"combined_distributions");
1060 if (combinedPdfInfoNode) {
1061 for (
auto &info : combinedPdfInfoNode->children()) {
1062 if (info[
"index_cat"].val() == cat->
GetName()) {
1072 std::unique_ptr<TList> dataList{simPdf ?
data.split(*simPdf,
true) :
data.split(*cat,
true)};
1075 for (
RooAbsData *absData : static_range_cast<RooAbsData *>(*dataList)) {
1076 absData->SetName((std::string(
data.GetName()) +
"_" + absData->GetName()).c_str());
1094 " has several category observables!");
1107 output[
"type"] <<
"binned";
1120 if (
auto weightVar = variables.find(
"weightVar")) {
1121 variables.remove(*weightVar);
1130 if (
data.isWeighted() && variables.size() == 1) {
1131 bool isBinnedData =
false;
1132 auto &
x =
static_cast<RooRealVar const &
>(*variables[0]);
1133 std::vector<double> contents;
1135 for (; i <
data.numEntries(); ++i) {
1137 if (
x.getBin() != i)
1139 contents.push_back(
data.weight());
1141 if (i ==
x.getBins())
1142 isBinnedData =
true;
1144 output[
"type"] <<
"binned";
1149 output[
"type"] <<
"unbinned";
1154 auto &coords =
output[
"entries"].set_seq();
1155 auto *weights =
data.isWeighted() ? &
output[
"weights"].set_seq() :
nullptr;
1156 for (
int i = 0; i <
data.numEntries(); ++i) {
1158 coords.append_child().fill_seq(variables, [](
auto x) {
return static_cast<RooRealVar *
>(
x)->getVal(); });
1160 weights->append_child() <<
data.weight();
1168 for (
JSONNode const &nd :
n[
"axes"].children()) {
1169 if (nd.has_child(
"bounds")) {
1170 std::vector<double> bounds;
1171 for (
auto const &bound : nd[
"bounds"].children()) {
1172 bounds.push_back(bound.val_double());
1174 auto obs = std::make_unique<RooRealVar>(nd[
"name"].val().c_str(), nd[
"name"].val().c_str(), bounds[0],
1175 bounds[bounds.size() - 1]);
1176 RooBinning bins(obs->getMin(), obs->getMax());
1178 for (
auto b : bounds) {
1181 obs->setBinning(bins);
1184 auto obs = std::make_unique<RooRealVar>(nd[
"name"].val().c_str(), nd[
"name"].val().c_str(),
1185 nd[
"min"].val_double(), nd[
"max"].val_double());
1186 obs->setBins(nd[
"nbins"].val_int());
1196std::unique_ptr<RooDataHist>
1199 if (!
n.has_child(
"contents"))
1202 JSONNode const &contents =
n[
"contents"];
1208 if (
n.has_child(
"errors")) {
1209 errors = &
n[
"errors"];
1214 auto bins = generateBinIndices(varlist);
1216 std::stringstream errMsg;
1217 errMsg <<
"inconsistent bin numbers: contents=" << contents.
num_children() <<
", bins=" << bins.size();
1220 auto dh = std::make_unique<RooDataHist>(
name.c_str(),
name.c_str(), varlist);
1221 std::vector<double> contentVals;
1223 for (
auto const &cont : contents.
children()) {
1224 contentVals.push_back(cont.val_double());
1226 std::vector<double> errorVals;
1229 for (
auto const &err : errors->
children()) {
1230 errorVals.push_back(err.val_double());
1233 for (
size_t ibin = 0; ibin < bins.size(); ++ibin) {
1234 const double err = errors ? errorVals[ibin] : -1;
1235 dh->set(ibin, contentVals[ibin], err);
1249 std::stringstream ss;
1250 ss <<
"RooJSONFactoryWSTool() node '" <<
name <<
"' is not a map, skipping.";
1251 oocoutE(
nullptr, InputArguments) << ss.str() << std::endl;
1257 if (attrNode->has_child(
"is_const_var") && (*attrNode)[
"is_const_var"].val_int() == 1) {
1258 wsEmplace<RooConstVar>(
name,
p[
"value"].val_double());
1263 configureVariable(*
_domains,
p, wsEmplace<RooRealVar>(
name, 1.));
1271 if (
JSONNode const *varsNode = getVariablesNode(
n)) {
1272 for (
const auto &
p : varsNode->children()) {
1276 if (
auto seq =
n.find(
"functions")) {
1277 for (
const auto &
p : seq->children()) {
1281 if (
auto seq =
n.find(
"distributions")) {
1282 for (
const auto &
p : seq->children()) {
1289 const std::vector<CombinedData> &combDataSets)
1292 if (pdf ==
nullptr) {
1294 <<
"RooFitHS3 only supports ModelConfigs with RooSimultaneous! Skipping ModelConfig.\n";
1298 for (std::size_t i = 0; i < std::max(combDataSets.size(), std::size_t(1)); ++i) {
1299 const bool hasdata = i < combDataSets.size();
1300 if (hasdata && !matches(combDataSets.at(i), pdf))
1303 std::string analysisName(pdf->
GetName());
1305 analysisName +=
"_" + combDataSets[i].name;
1312 std::string
const &analysisName,
1313 std::map<std::string, std::string>
const *dataComponents)
1321 analysisNode[
"likelihood"] << analysisName;
1324 nllNode[
"distributions"].set_seq();
1325 nllNode[
"data"].set_seq();
1327 for (
auto const &item : pdf->
indexCat()) {
1328 nllNode[
"distributions"].append_child() << pdf->
getPdf(item.first)->
GetName();
1329 if (dataComponents) {
1330 const auto &
d = dataComponents->find(item.first);
1331 nllNode[
"data"].append_child() <<
d->second;
1335 auto &extConstrNode = nllNode[
"aux_distributions"];
1336 extConstrNode.set_seq();
1338 extConstrNode.append_child() << constr->GetName();
1342 auto writeList = [&](
const char *
name,
RooArgSet const *args) {
1346 std::vector<std::string> names;
1347 names.reserve(args->size());
1349 names.push_back(arg->
GetName());
1350 std::sort(names.begin(), names.end());
1356 auto &modelConfigAux =
getRooFitInternal(rootnode,
"ModelConfigs", analysisName);
1357 modelConfigAux.set_map();
1358 modelConfigAux[
"pdfName"] << pdf->
GetName();
1359 modelConfigAux[
"mcName"] << mc.
GetName();
1364 _domains = std::make_unique<RooFit::JSONIO::Detail::Domains>();
1369 std::vector<RooAbsPdf *> allpdfs;
1372 if (
auto *pdf =
dynamic_cast<RooAbsPdf *
>(arg)) {
1373 allpdfs.push_back(pdf);
1377 sortByName(allpdfs);
1378 std::set<std::string> exportedObjectNames;
1384 for (std::string
const &
name : exportedObjectNames) {
1389 std::vector<RooAbsData *> alldata;
1391 alldata.push_back(
d);
1393 sortByName(alldata);
1395 std::vector<RooJSONFactoryWSTool::CombinedData> combData;
1396 for (
auto &
d : alldata) {
1399 combData.push_back(
data);
1402 for (
auto &
d : alldata) {
1419 if (exportedObjectNames.find(arg->
GetName()) != exportedObjectNames.end())
1420 snapshotSorted.
add(*arg);
1422 snapshotSorted.
sort();
1423 std::string
name(snsh->GetName());
1424 if (
name !=
"default_values") {
1437 std::stringstream ss(s);
1444 std::stringstream ss(s);
1451 std::stringstream ss;
1459 std::stringstream ss;
1467 std::unique_ptr<JSONTree>
tree = JSONTree::create();
1470 auto &metadata =
n[
"metadata"];
1474 metadata[
"hs3_version"] <<
"0.1.90";
1478 std::string versionName =
gROOT->GetVersion();
1481 std::replace(versionName.begin(), versionName.end(),
'/',
'.');
1482 rootInfo[
"version"] << versionName;
1499 std::ofstream out(
filename.c_str());
1500 if (!out.is_open()) {
1501 std::stringstream ss;
1502 ss <<
"RooJSONFactoryWSTool() invalid output file '" <<
filename <<
"'." << std::endl;
1503 logInputArgumentsError(std::move(ss));
1521 std::ofstream out(
filename.c_str());
1522 if (!out.is_open()) {
1523 std::stringstream ss;
1524 ss <<
"RooJSONFactoryWSTool() invalid output file '" <<
filename <<
"'." << std::endl;
1525 logInputArgumentsError(std::move(ss));
1533 _domains = std::make_unique<RooFit::JSONIO::Detail::Domains>();
1534 if (
auto domains =
n.find(
"domains"))
1543 if (
auto paramPointsNode =
n.find(
"parameter_points")) {
1544 for (
const auto &snsh : paramPointsNode->children()) {
1547 for (
const auto &var : snsh[
"parameters"].children()) {
1549 configureVariable(*
_domains, var, *rrv);
1563 importAttributes(arg, elem);
1573 std::vector<std::unique_ptr<RooAbsData>> datas;
1574 if (
auto dataNode =
n.find(
"data")) {
1575 for (
const auto &
p : dataNode->children()) {
1582 if (
auto analysesNode =
n.find(
"analyses")) {
1583 for (
JSONNode const &analysisNode : analysesNode->children()) {
1590 for (
auto const &
d : datas) {
1602 std::unique_ptr<JSONTree>
tree = JSONTree::create(is);
1610 std::ifstream infile(
filename.c_str());
1611 if (!infile.is_open()) {
1612 std::stringstream ss;
1613 ss <<
"RooJSONFactoryWSTool() invalid input file '" <<
filename <<
"'." << std::endl;
1614 logInputArgumentsError(std::move(ss));
1623 std::unique_ptr<JSONTree>
tree = JSONTree::create(is);
1630 std::ifstream infile(
filename.c_str());
1631 if (!infile.is_open()) {
1632 std::stringstream ss;
1633 ss <<
"RooJSONFactoryWSTool() invalid input file '" <<
filename <<
"'." << std::endl;
1634 logInputArgumentsError(std::move(ss));
1646 bool isVariable =
true;
1647 if (
n.find(
"type")) {
1662 _domains = std::make_unique<RooFit::JSONIO::Detail::Domains>();
1663 if (
auto domains =
n.find(
"domains"))
1669 JSONNode const *varsNode = getVariablesNode(
n);
1670 const auto &
p = varsNode->
child(0);
1673 auto paramPointsNode =
n.find(
"parameter_points");
1674 const auto &snsh = paramPointsNode->child(0);
1677 const auto &var = snsh[
"parameters"].child(0);
1679 configureVariable(*
_domains, var, *rrv);
1687 importAttributes(arg, elem);
1704 throw std::runtime_error(s);
std::unique_ptr< RooFit::Detail::JSONTree > varJSONString(const JSONNode &treeRoot)
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
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'.
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...
const std::set< std::string > & attributes() const
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.
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
RooAbsProxy * getProxy(Int_t index) const
Return the nth proxy from the proxy list.
A space to attach TBranches.
const std::string & lookupName(value_type index) const
Get the name corresponding to the given index.
std::size_t size() const
Number of states defined.
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
void sort(bool reverse=false)
Sort collection using std::sort and name comparison.
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsData is the common abstract base class for binned and unbinned datasets.
RooArgSet * getAllConstraints(const RooArgSet &observables, RooArgSet &constrainedParams, bool stripDisconnected=true, bool removeConstraintsFromPdf=false) const
This helper function finds and collects all constraints terms of all component p.d....
RooAbsProxy is the abstact interface for proxy classes.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Class RooBinning is an implements RooAbsBinning in terms of an array of boundary values,...
bool addBoundary(double boundary)
Add bin boundary at given value.
RooCategory is an object to represent discrete states.
bool defineType(const std::string &label)
Define a state with given name.
RooConstVar represent a constant real-valued object.
The RooDataHist is a container class to hold N-dimensional binned data.
virtual std::string val() const =0
void fill_seq(Collection const &coll)
virtual JSONNode & set_map()=0
virtual JSONNode & append_child()=0
virtual children_view children()
virtual size_t num_children() const =0
virtual JSONNode & child(size_t pos)=0
virtual JSONNode & set_seq()=0
virtual void writeJSON(std::ostream &os) const =0
virtual bool is_seq() const =0
virtual bool is_map() const =0
virtual double val_double() const
JSONNode const * find(std::string const &key) const
virtual int val_int() const
static std::unique_ptr< JSONTree > create()
void writeVariable(RooRealVar &) const
std::ostream & log(const RooAbsArg *self, RooFit::MsgLevel level, RooFit::MsgTopic facility, bool forceSkipPrefix=false)
Log error message associated with RooAbsArg object self at given level and topic.
static RooMsgService & instance()
Return reference to singleton instance.
RooRealVar represents a variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
RooSimultaneous facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
RooAbsPdf * getPdf(RooStringView catName) const
Return the p.d.f associated with the given index category name.
const RooAbsCategoryLValue & indexCat() const
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return nullptr if not existing)
void SetWS(RooWorkspace &ws) override
Set a workspace that owns all the necessary components for the analysis.
const RooArgSet * GetExternalConstraints() const
get RooArgSet for global observables (return nullptr if not existing)
RooAbsPdf * GetPdf() const
get model PDF (return nullptr if pdf has not been specified or does not exist)
The RooWorkspace is a persistable container for RooFit projects.
TObject * obj(RooStringView name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
RooAbsPdf * pdf(RooStringView name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
bool 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.
bool saveSnapshot(RooStringView, const char *paramNames)
Save snapshot of values and attributes (including "Constant") of given parameters.
RooArgSet allPdfs() const
Return set with all probability density function objects.
std::list< RooAbsData * > allData() const
Return list of all dataset in the workspace.
RooLinkedList const & getSnapshots() const
std::list< TObject * > allGenericObjects() const
Return list of all generic objects in the workspace.
RooAbsReal * function(RooStringView name) const
Retrieve function (RooAbsReal) with given name. Note that all RooAbsPdfs are also RooAbsReals....
RooAbsArg * arg(RooStringView name) const
Return RooAbsArg with given name. A null pointer is returned if none is found.
RooFactoryWSTool & factory()
Return instance to factory tool.
RooRealVar * var(RooStringView name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
TClass instances represent classes, structs and namespaces in the ROOT type system.
const char * GetName() const override
Returns name of object.
TClass * IsA() const override
Mother of all ROOT objects.
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 flag=true)
RooConstVar & RooConst(double val)
RooCmdArg Silence(bool flag=true)
RooCmdArg Index(RooCategory &icat)
RooCmdArg WeightVar(const char *name="weight", bool reinterpretAsWeight=false)
RooCmdArg Import(const char *state, TH1 &histo)
double Var(const RVec< T > &v)
Get the variance of the elements of an RVec.
ImportExpressionMap & importExpressions()
ExportKeysMap & exportKeys()
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.