131 for (
auto const &function : doc.
functions) {
132 functions.emplace(function.name, &function);
138 if (point.name ==
"default_values") {
140 for (
auto const &
p : point.parameters) {
149 std::unordered_map<std::string, HS3::Function const *>
functions;
161 std::map<std::string, std::map<std::string, HS3::DomainAxis>>
domains;
183 std::vector<DistributionRef> channelConstraints)
185 tool.
_export->typedObject = std::move(dist);
186 tool.
_export->channelConstraints = std::move(channelConstraints);
198 for (
int i = 0; i < binning.
numBins(); ++i) {
204constexpr double inf = std::numeric_limits<double>::infinity();
205constexpr int isInfinite(
double x)
207 return (
x >= +inf) ? +1 : ((
x <= -inf) ? -1 : 0);
216 if (!isInfinite(binning.
lowBound())) {
223 if (axis.
min && axis.
max && hasBins) {
224 axis.
binning = toBinning(binning);
231void recordDomains(std::map<std::string, std::map<std::string, HS3::DomainAxis>> &domains,
RooRealVar const &var)
234 for (
auto const &
name : var.getBinningNames()) {
242void appendDomain(std::vector<HS3::Domain> &domains, std::string
const &
name,
243 std::map<std::string, HS3::DomainAxis> axes,
244 std::map<std::string, HS3::CategoricalAxis> categories = {})
246 std::map<std::string, std::variant<HS3::DomainAxis, HS3::CategoricalAxis>> sorted;
247 for (
auto &item : axes) {
248 sorted.emplace(item.first, std::move(item.second));
250 for (
auto &item : categories) {
251 sorted.emplace(item.first, std::move(item.second));
255 for (
auto &item : sorted) {
256 domain.
axes.emplace_back(std::move(item.second));
263 if (
auto const *edges = std::get_if<HS3::EdgesBinning>(&binning)) {
264 if (edges->
edges.empty()) {
268 for (
double edge : edges->edges) {
269 bins.addBoundary(edge);
272 }
else if (
int nbins = std::get<HS3::RegularBinning>(binning).nbins) {
280 if (isInfinite(*axis.
min)) {
287 if (isInfinite(*axis.
max)) {
294 applyBinning(var, *axis.
binning);
302 auto forEachAxis = [&](
auto &&fn) {
304 for (
auto const &axis : domain.axes) {
305 if (
auto const *continuous = std::get_if<HS3::DomainAxis>(&axis)) {
306 fn(domain.
name, *continuous);
314 ws.import(RooConstVar{axis.name.c_str(), axis.name.c_str(), *axis.fixedValue},
RooFit::Silence());
319 RooRealVar var{axis.name.c_str(), axis.name.c_str(), axis.min.value_or(-inf), axis.max.value_or(inf)};
321 applyBinning(var, *axis.
binning);
330 for (
auto const &axisVariant : domain.axes) {
331 auto const *axis = std::get_if<HS3::CategoricalAxis>(&axisVariant);
339 "' already exists and is not a category");
341 std::set<std::string> existingLabels;
342 for (
auto const &state : *cat) {
343 existingLabels.insert(state.first);
345 if (existingLabels != std::set<std::string>(axis->categories.begin(), axis->categories.end())) {
347 "' differ from the states of the existing category '" + axis->
name +
"'");
352 for (std::size_t i = 0; i < axis->categories.size(); ++i) {
353 cat.defineType(axis->categories[i],
static_cast<int>(i));
358 forEachAxis([&](std::string
const &domain,
HS3::DomainAxis const &axis) {
361 var->
setRange(domain.c_str(), axis.
min.value_or(-inf), axis.
max.value_or(inf));
363 applyBinning(*var, *axis.
binning, domain.c_str());
377 ImportGuard(std::vector<std::string> &stack, std::string
const &
name) : _stack{stack}
379 if (std::find(_stack.begin(), _stack.end(),
name) != _stack.end()) {
381 for (std::string
const &ancestor : _stack) {
382 chain += ancestor +
" -> ";
386 _stack.push_back(
name);
388 ~ImportGuard() { _stack.pop_back(); }
391 std::vector<std::string> &_stack;
399 for (
Diagnostic const &diagnostic : diagnostics) {
400 const std::string
text =
401 diagnostic.path.empty() ? diagnostic.message : diagnostic.path +
": " + diagnostic.message;
402 if (diagnostic.severity == Diagnostic::Severity::Error) {
403 errors += (errors.empty() ?
"" :
"\n") +
text;
408 if (!errors.empty()) {
419 if (
auto const *
value = std::get_if<double>(&*
p.value)) {
424 applyRange(
v, *range);
429 v.setError(
v.getVal() * *
p.relError);
431 v.setError(*
p.error);
432 v.setConstant(
p.isConst);
435std::string genPrefix(
const JSONNode &
p,
bool trailing_underscore)
440 if (
auto node =
p.find(
"namespaces")) {
441 for (
const auto &ns : node->children()) {
447 if (trailing_underscore && !prefix.empty())
453void genIndicesHelper(std::vector<std::vector<int>> &combinations, std::vector<int> &curr_comb,
454 const std::vector<int> &vars_numbins,
size_t curridx)
456 if (curridx == vars_numbins.size()) {
458 combinations.emplace_back(curr_comb);
460 for (
int i = 0; i < vars_numbins[curridx]; ++i) {
461 curr_comb[curridx] = i;
462 ::genIndicesHelper(combinations, curr_comb, vars_numbins, curridx + 1);
470 for (
auto const &
attr : attributes.dict) {
473 for (
auto const &tag : attributes.tags) {
481 out.
add(*args,
true);
485void collectParameterStepWidthCandidatesFromModelConfigs(
RooWorkspace const &workspace,
RooArgSet &candidates,
488 for (
TObject *obj : workspace.allGenericObjects()) {
494 addIfPresent(candidates, mc->GetParametersOfInterest());
495 addIfPresent(candidates, mc->GetNuisanceParameters());
497 addIfPresent(excluded, mc->GetObservables());
498 addIfPresent(excluded, mc->GetGlobalObservables());
499 addIfPresent(excluded, mc->GetConditionalObservables());
503void collectParameterStepWidthCandidatesFromPdfs(std::vector<RooAbsPdf *>
const &pdfs,
504 std::vector<RooAbsData *>
const &
data,
RooArgSet &candidates,
510 std::unique_ptr<RooArgSet> pdfObs{pdf->getObservables(*dataset->get())};
511 observables.
add(*pdfObs,
true);
514 if (observables.
empty()) {
519 pdf->getParameters(&observables, params);
520 candidates.
add(params,
true);
521 excluded.
add(observables,
true);
525void exportParameterStepWidths(
RooWorkspace const &workspace, std::vector<RooAbsPdf *>
const &pdfs,
526 std::vector<RooAbsData *>
const &
data, std::vector<HS3::StepWidth> &out)
531 collectParameterStepWidthCandidatesFromModelConfigs(workspace, candidates, excluded);
532 collectParameterStepWidthCandidatesFromPdfs(pdfs,
data, candidates, excluded);
537 if (excluded.
find(*arg)) {
553 auto *var =
dynamic_cast<RooRealVar *
>(workspace.
arg(stepWidth.name));
557 stepWidth.name +
"'.");
565std::vector<std::vector<int>> generateBinIndices(
const RooArgSet &vars)
567 std::vector<std::vector<int>> combinations;
568 std::vector<int> vars_numbins;
569 vars_numbins.reserve(vars.
size());
574 std::vector<int> curr_comb(vars.
size());
575 ::genIndicesHelper(combinations, curr_comb, vars_numbins, 0);
579template <
typename... Keys_t>
580JSONNode const *findRooFitInternal(
JSONNode const &node, Keys_t
const &...keys)
582 return node.
find(
"misc",
"ROOT_internal", keys...);
598void addNames(
JSONNode const &node, std::set<std::string> &out)
602 addNames(
child, out);
604 }
else if (isName(node)) {
605 out.insert(node.
val());
610JSONNode const *findInSection(
JSONNode const &rootnode,
const char *section, std::string
const &
name)
616std::string typeOf(
JSONNode const &node)
618 return node.
has_child(
"type") ? node[
"type"].
val() :
"";
622std::vector<std::string> combinedComponents(
JSONNode const &node,
const char *field)
624 std::vector<std::string> out;
625 if (
JSONNode const *components = node.
find(
"components")) {
626 for (
JSONNode const &component : components->children()) {
628 out.push_back(
name->val());
639void collectVariates(
JSONNode const &rootnode, std::string
const &
name, std::set<std::string> &out,
640 std::set<std::string> &visited)
642 if (!visited.insert(
name).second) {
645 JSONNode const *node = findInSection(rootnode,
"distributions",
name);
649 std::string
const type = typeOf(*node);
650 auto recurse = [&](std::vector<std::string>
const &parts) {
651 for (std::string
const &part : parts) {
652 collectVariates(rootnode, part, out, visited);
655 auto namesIn = [&](
const char *key) {
656 std::vector<std::string> parts;
658 for (
JSONNode const &part : list->children()) {
660 parts.push_back(part.val());
666 if (
type ==
"product_dist") {
667 recurse(namesIn(
"factors"));
668 }
else if (
type ==
"mixture_dist") {
669 recurse(namesIn(
"summands"));
670 }
else if (
type ==
"combined_dist") {
671 recurse(combinedComponents(*node,
"dist"));
672 }
else if (
type ==
"array_dist") {
673 if (
JSONNode const *components = node->
find(
"components")) {
674 for (
JSONNode const &component : components->children()) {
675 if (
JSONNode const *
x = component.find(
"x")) {
685 for (
JSONNode const &axis : axes->children()) {
686 if (
JSONNode const *axisName = axis.find(
"name")) {
687 addNames(*axisName, out);
694std::set<std::string> variatesOf(
JSONNode const &rootnode, std::string
const &
name)
696 std::set<std::string> variates;
697 std::set<std::string> visited;
698 collectVariates(rootnode,
name, variates, visited);
705std::vector<std::string> likelihoodTerms(
JSONNode const &rootnode,
JSONNode const &likelihood)
707 std::vector<std::string> terms;
708 auto add = [&](std::string
const &term) {
709 if (std::find(terms.begin(), terms.end(), term) == terms.end()) {
710 terms.push_back(term);
713 for (
const char *key : {
"distributions",
"aux_distributions"}) {
718 for (
JSONNode const &item : list->children()) {
722 std::string
const name = item.val();
723 if (
JSONNode const *node = findInSection(rootnode,
"distributions",
name)) {
724 if (typeOf(*node) ==
"combined_dist") {
725 for (std::string
const &component : combinedComponents(*node,
"dist")) {
730 }
else if (
JSONNode const *legacy = findRooFitInternal(rootnode,
"combined_distributions",
name)) {
732 for (
JSONNode const &component : components->children()) {
733 add(component.val());
741 for (std::size_t i = 0; i < terms.size(); ++i) {
742 JSONNode const *node = findInSection(rootnode,
"distributions", terms[i]);
743 if (!node || typeOf(*node) !=
"histfactory_dist" || !node->
has_child(
"samples")) {
746 for (
JSONNode const &sample : (*node)[
"samples"].children()) {
747 if (
JSONNode const *modifiers = sample.
find(
"modifiers")) {
750 std::set<std::string> names;
751 addNames(*constraints, names);
752 for (std::string
const &constraint : names) {
764using PartVariates = std::vector<std::pair<std::string, std::set<std::string>>>;
768std::vector<std::string> sharedVariates(PartVariates
const &parts, std::string
const &
what, std::string
const &context)
770 std::map<std::string, std::vector<std::string>> partsOfVariate;
771 std::vector<std::string> order;
772 for (
auto const &[part, variates] : parts) {
773 for (std::string
const &variate : variates) {
774 auto &list = partsOfVariate[variate];
776 order.push_back(variate);
778 if (std::find(list.begin(), list.end(), part) == list.end()) {
779 list.push_back(part);
783 std::vector<std::string> messages;
784 for (std::string
const &variate : order) {
785 auto const &list = partsOfVariate[variate];
786 if (list.size() < 2) {
790 for (std::size_t i = 0; i < list.size(); ++i) {
791 names += (i == 0 ?
"'" : (i + 1 == list.size() ?
"' and '" :
"', '")) + list[i];
793 messages.push_back(
"the variate '" + variate +
"' is shared by the " +
what +
" " + names +
"' of " + context);
799PartVariates combinedDataAxes(
JSONNode const &rootnode,
JSONNode const &dataset)
802 for (std::string
const &component : combinedComponents(dataset,
"dataset")) {
803 std::set<std::string> axes;
804 if (
JSONNode const *node = findInSection(rootnode,
"data", component)) {
806 for (
JSONNode const &axis : axesNode->children()) {
807 if (
JSONNode const *axisName = axis.find(
"name")) {
808 addNames(*axisName, axes);
813 parts.emplace_back(component, axes);
822std::map<std::string, std::set<std::string>> bookkeepingColumnsOfDocument(
JSONNode const &rootnode)
824 std::map<std::string, std::set<std::string>> out;
825 JSONNode const *declared = findRooFitInternal(rootnode,
"bookkeeping_columns");
826 if (!declared || !declared->
is_map()) {
829 std::set<std::string> variates;
830 if (
JSONNode const *distributions = rootnode.
find(
"distributions")) {
831 for (
JSONNode const &dist : distributions->children()) {
833 variates.insert(
v.begin(),
v.end());
836 for (
JSONNode const &entry : declared->children()) {
837 for (
JSONNode const &column : entry.children()) {
838 if (!variates.count(column.val())) {
839 out[entry.key()].insert(column.val());
849std::vector<std::string> sharedVariatesOfDocument(
JSONNode const &rootnode)
851 std::vector<std::string> messages;
852 auto append = [&](std::vector<std::string>
const &more) {
853 messages.insert(messages.end(), more.begin(), more.end());
855 std::set<std::string> inLikelihoods;
856 if (
JSONNode const *likelihoods = rootnode.
find(
"likelihoods")) {
857 for (
JSONNode const &likelihood : likelihoods->children()) {
858 for (
const char *key : {
"distributions",
"data",
"aux_distributions"}) {
860 for (
JSONNode const &item : list->children()) {
861 inLikelihoods.insert(item.val());
866 for (std::string
const &term : likelihoodTerms(rootnode, likelihood)) {
867 parts.emplace_back(term, variatesOf(rootnode, term));
872 if (
JSONNode const *distributions = rootnode.
find(
"distributions")) {
873 for (
JSONNode const &dist : distributions->children()) {
875 if (typeOf(dist) !=
"combined_dist" || inLikelihoods.count(
name)) {
879 for (std::string
const &component : combinedComponents(
dist,
"dist")) {
880 parts.emplace_back(component, variatesOf(rootnode, component));
882 append(sharedVariates(parts,
"components",
"the combined_dist '" +
name +
"'"));
887 std::map<std::string, std::set<std::string>>
const bookkeeping = bookkeepingColumnsOfDocument(rootnode);
891 if (typeOf(dataset) !=
"combined") {
894 PartVariates parts = combinedDataAxes(rootnode, dataset);
895 if (
auto found = bookkeeping.find(
name); found != bookkeeping.end()) {
896 for (
auto &part : parts) {
897 for (std::string
const &column : found->second) {
898 part.second.erase(column);
902 append(sharedVariates(parts,
"components",
"the combined data set '" +
name +
"'"));
918 std::vector<RooArgSet const *> modelConfigSets;
919 for (
TObject *obj : ws.allGenericObjects()) {
921 for (
RooArgSet const *set : {mc->GetObservables(), mc->GetParametersOfInterest(), mc->GetNuisanceParameters(),
922 mc->GetGlobalObservables(), mc->GetConditionalObservables()}) {
924 modelConfigSets.push_back(set);
929 auto usedByNothing = [&](std::string
const &
name) {
931 if (!arg || !arg->
clients().empty()) {
934 return std::none_of(modelConfigSets.begin(), modelConfigSets.end(),
935 [&](
RooArgSet const *set) { return set->find(name.c_str()) != nullptr; });
937 std::map<std::string, std::set<std::string>> columns;
939 if (typeOf(dataset) !=
"combined") {
942 std::map<std::string, int> counts;
943 for (
auto const &[component, axes] : combinedDataAxes(rootnode, dataset)) {
944 for (std::string
const &axis : axes) {
948 for (
auto const &[axis, count] : counts) {
949 if (count > 1 && usedByNothing(axis)) {
954 if (columns.empty()) {
957 JSONNode &node = rootnode[
"misc"][
"ROOT_internal"][
"bookkeeping_columns"].
set_map();
958 for (
auto const &[dataset, names] : columns) {
970void writeLikelihoodTermsOnce(
JSONNode &rootnode)
972 JSONNode const *likelihoods = rootnode.
find(
"likelihoods");
973 JSONNode const *distributions = rootnode.
find(
"distributions");
974 if (!likelihoods || !distributions) {
978 std::map<std::string, std::set<std::string>> removable;
979 for (
JSONNode const &likelihood : likelihoods->children()) {
980 std::vector<std::string>
const terms = likelihoodTerms(rootnode, likelihood);
981 for (std::string
const &term : terms) {
982 JSONNode const *node = findInSection(rootnode,
"distributions", term);
983 if (!node || typeOf(*node) !=
"product_dist" || !node->
has_child(
"factors")) {
986 std::set<std::string> factorsThatAreTerms;
987 for (
JSONNode const &factor : (*node)[
"factors"].children()) {
988 if (factor.val() != term && std::find(terms.begin(), terms.end(), factor.val()) != terms.end()) {
989 factorsThatAreTerms.insert(factor.val());
992 auto found = removable.find(term);
993 if (found == removable.end()) {
994 removable[term] = factorsThatAreTerms;
996 std::set<std::string> both;
997 std::set_intersection(found->second.begin(), found->second.end(), factorsThatAreTerms.begin(),
998 factorsThatAreTerms.end(), std::inserter(both, both.begin()));
999 found->second = both;
1004 for (
JSONNode const &dist : distributions->children()) {
1005 std::vector<std::string> used;
1006 for (
const char *key : {
"factors",
"summands"}) {
1008 for (
JSONNode const &part : parts->children()) {
1010 used.push_back(part.val());
1015 if (typeOf(dist) !=
"combined_dist") {
1016 for (std::string
const &component : combinedComponents(
dist,
"dist")) {
1017 used.push_back(component);
1020 for (std::string
const &
name : used) {
1021 removable.erase(
name);
1024 for (
auto const &[product, remove] : removable) {
1025 if (remove.empty()) {
1028 auto &node =
const_cast<JSONNode &
>(*findInSection(rootnode,
"distributions", product));
1029 std::vector<std::string> keep;
1030 for (
JSONNode const &factor : node[
"factors"].children()) {
1031 if (remove.find(factor.val()) == remove.end()) {
1032 keep.push_back(factor.val());
1038 for (std::string
const &factor : remove) {
1039 oocoutI(
nullptr, IO) <<
"RooFitHS3: '" << factor <<
"' is a factor of '" <<
product
1040 <<
"' and a term of its likelihood; it is written once, as a term of the likelihood"
1043 node[
"factors"].
clear();
1050void exportAttributes(
const RooAbsArg *arg, std::map<std::string, HS3::Attributes> &attributes)
1060 out = &attributes[arg->
GetName()];
1065 for (
const auto &it : arg->stringAttributes()) {
1067 if (it.first ==
"factory_tag" || it.first ==
"PROD_TERM_TYPE")
1070 out->
dict[it.first] = it.second;
1072 for (
auto const &
attr : arg->attributes()) {
1091 axis.
binning = toBinning(binning);
1098 return static_cast<RooConstVar const &
>(arg).getVal();
1100 return std::string{arg.
GetName()};
1105std::unique_ptr<RooRealVar> createObservable(
HS3::BinnedAxis const &axis)
1107 auto obs = std::make_unique<RooRealVar>(axis.
name.c_str(), axis.
name.c_str(), axis.
min, axis.
max);
1108 applyBinning(*obs, axis.
binning);
1113std::set<std::string> labelsOf(
RooCategory const &cat)
1115 std::set<std::string> labels;
1116 for (
auto const &state : cat) {
1117 labels.insert(state.first);
1127RooArgSet createBinnedObservables(std::vector<std::variant<HS3::BinnedAxis, HS3::CategoricalAxis>>
const &axes,
1128 RooWorkspace const &workspace, std::string
const &dataName,
1129 std::vector<std::size_t> &binOrder)
1132 std::vector<std::vector<std::size_t>> axisPositions;
1133 bool reordered =
false;
1134 for (
auto const &axisVariant : axes) {
1135 if (
auto const *axis = std::get_if<HS3::BinnedAxis>(&axisVariant)) {
1136 auto obs = createObservable(*axis);
1137 std::vector<std::size_t> positions(obs->numBins());
1138 std::iota(positions.begin(), positions.end(), 0);
1139 axisPositions.push_back(std::move(positions));
1143 auto const &axis = std::get<HS3::CategoricalAxis>(axisVariant);
1144 auto cat = std::make_unique<RooCategory>(axis.
name.c_str(), axis.
name.c_str());
1146 if (labelsOf(*wsCat) != std::set<std::string>(axis.categories.begin(), axis.categories.end())) {
1148 "' differ from those of the category '" + axis.
name +
"'");
1150 for (
unsigned int i = 0; i < wsCat->size(); ++i) {
1151 auto const &state = wsCat->getOrdinal(i);
1155 for (std::size_t i = 0; i < axis.categories.size(); ++i) {
1156 cat->
defineType(axis.categories[i],
static_cast<int>(i));
1159 std::vector<std::size_t> positions(axis.categories.size());
1160 for (std::size_t i = 0; i < positions.size(); ++i) {
1161 auto found = std::find(axis.categories.begin(), axis.categories.end(), cat->
getOrdinal(i).first);
1162 positions[i] = std::distance(axis.categories.begin(), found);
1163 reordered |= positions[i] != i;
1165 axisPositions.push_back(std::move(positions));
1172 std::size_t
total = 1;
1173 for (
auto const &positions : axisPositions) {
1174 total *= positions.size();
1176 binOrder.resize(
total);
1177 for (std::size_t k = 0; k <
total; ++k) {
1179 std::size_t rest = k;
1180 std::size_t docIndex = 0;
1181 std::size_t stride = 1;
1182 for (std::size_t j = axisPositions.size(); j-- > 0;) {
1183 const std::size_t nBins = axisPositions[j].size();
1184 docIndex += axisPositions[j][rest % nBins] * stride;
1188 binOrder[k] = docIndex;
1194std::vector<double> permute(std::vector<double>
const &values, std::vector<std::size_t>
const &order)
1196 if (order.empty() || values.size() != order.size()) {
1199 std::vector<double> out(values.size());
1200 for (std::size_t k = 0; k < order.size(); ++k) {
1201 out[k] = values[order[k]];
1211 if (!axis.
min || !axis.
max) {
1217 std::stringstream ss;
1218 ss <<
"RooFitHS3: the range [" << *axis.
min <<
", " << *axis.
max <<
"] of the axis '" << axis.
name
1219 <<
"' of the dataset '" << dataName <<
"' differs from the range [" << var.
getMin() <<
", " << var.
getMax()
1220 <<
"] of the variable.";
1229 for (
auto const &axisVariant :
input.axes) {
1230 auto const *axis = std::get_if<HS3::ContinuousAxis>(&axisVariant);
1233 auto const &catAxis = std::get<HS3::CategoricalAxis>(axisVariant);
1237 "\" could not be found in the workspace! Categorical observables are "
1238 "declared by a categorical axis in a domain.");
1240 if (labelsOf(*cat) != std::set<std::string>(catAxis.categories.begin(), catAxis.categories.end())) {
1242 "\" differ from the states of the category \"" + catAxis.name +
"\"");
1252 applyUnbinnedAxisRange(*axis,
name, *var, ranges);
1256 const std::size_t nAxes =
input.axes.size();
1257 for (std::size_t i = 0; i <
input.numEntries(); ++i) {
1258 for (std::size_t j = 0; j < nAxes; ++j) {
1259 const double value =
input.entries[i * nAxes + j];
1260 if (
auto const *catAxis = std::get_if<HS3::CategoricalAxis>(&
input.axes[j])) {
1262 static_cast<RooCategory *
>(varlist.
at(j))->setLabel(catAxis->categories[
static_cast<std::size_t
>(
value)]);
1278 if (
auto const *binned = std::get_if<HS3::BinnedData>(&
input.body)) {
1279 if (
binned->uncertainty && !
binned->uncertainty->correlation.empty()) {
1281 input.name +
"' are ignored, because RooDataHist can't store them.");
1283 std::vector<std::size_t> binOrder;
1285 std::vector<double>
sigma;
1286 if (
binned->uncertainty) {
1287 sigma = permute(
binned->uncertainty->sigma, binOrder);
1292 if (
auto const *unbinned = std::get_if<HS3::UnbinnedData>(&
input.body)) {
1293 if (
unbinned->hasEntriesUncertainties) {
1295 "' are ignored, because RooDataSet can't store them.");
1297 return createUnbinnedData(
input.name, *unbinned, workspace, ranges);
1303std::string rootVersion()
1305 std::string versionName =
gROOT->GetVersion();
1306 std::replace(versionName.begin(), versionName.end(),
'/',
'.');
1311void requirePdf(
RooAbsArg const *arg, std::string
const &
what)
1313 if (!
dynamic_cast<RooAbsPdf const *
>(arg)) {
1315 (arg ? std::string(
"a ") + arg->
ClassName() +
", not a pdf" :
"not imported"));
1327 std::vector<std::string> columnNames;
1329 columnNames.push_back(column->GetName());
1331 std::vector<std::string> dataColumns =
data.columns;
1332 std::sort(dataColumns.begin(), dataColumns.end());
1333 if (dataColumns != columnNames) {
1335 "' with the combined data set '" + dataName +
"', but their columns differ");
1338 std::set<std::map<std::string, std::string>> dataKeys;
1340 std::map<std::string, std::string> key;
1341 for (std::size_t i = 0; i <
data.columns.size(); ++i) {
1342 key[
data.columns[i]] = component.key[i];
1344 dataKeys.insert(key);
1346 auto keyToString = [&](std::map<std::string, std::string>
const &key) {
1347 std::vector<std::string> labels;
1348 for (std::string
const &column :
data.columns) {
1349 labels.push_back(key.at(column));
1353 std::set<std::map<std::string, std::string>> pdfKeys;
1354 for (std::vector<std::string>
const &labels :
selectionKeys(columns)) {
1359 std::map<std::string, std::string> key;
1360 for (std::size_t i = 0; i < columns.size(); ++i) {
1361 key[columnNames[i]] = labels[i];
1363 pdfKeys.insert(key);
1364 if (dataKeys.count(key) > 0) {
1369 "the combined data set '" + dataName +
"' has no sub-data set for the key " + keyToString(key) +
1370 " of the extended component '" + component->
GetName() +
"' of '" + simPdf.
GetName() +
1371 "'. RooFit cannot leave a component unobserved: it would add the expected number of events of the " +
1372 "component to the likelihood, see https://github.com/root-project/root/issues/24004");
1375 "' has no sub-data set for the key " + keyToString(key) +
" of the component '" +
1377 "', which RooFit treats as present and empty.");
1379 for (
auto const &key : dataKeys) {
1380 if (pdfKeys.count(key) == 0) {
1382 " of the combined data set '" + dataName +
"' is ignored, because '" +
1383 simPdf.
GetName() +
"' has no component for it.");
1399 for (std::string
const &
name : *mcInfo->observables) {
1401 observables.
add(*arg);
1404 "' (misc.ROOT_internal.ModelConfigs) does not exist");
1409 std::set<std::string> inDomains;
1410 for (
auto const &domainRef : analysis.domains) {
1412 if (domain.name != domainRef.name) {
1415 for (
auto const &axis : domain.axes) {
1416 inDomains.insert(std::visit([](
auto const &
a) -> std::string
const & {
return a.name; }, axis));
1420 for (
auto const &poi : analysis.parametersOfInterest) {
1421 inDomains.insert(poi.name);
1424 for (std::string
const &variate : variates) {
1429 if (inDomains.count(variate) || arg->
isConstant()) {
1432 observables.
add(*arg);
1433 list += (list.empty() ?
"'" :
", '") + variate +
"'";
1435 if (!list.empty()) {
1436 oocoutI(
nullptr, IO) <<
"RooFitHS3: no data set of the likelihood of the analysis '" << analysis.
name
1437 <<
"' gives its observables; they are the variates of the likelihood that are neither in a "
1438 "domain of the analysis nor constant: "
1439 << list << std::endl;
1444 std::vector<std::unique_ptr<RooAbsData>> &datasets, std::set<std::string>
const &bookkeepingColumns,
1445 std::set<std::string>
const &variates)
1448 std::string
const &analysisName = analysis.
name;
1452 std::string mcname = mcInfo && mcInfo->
mcName ? *mcInfo->
mcName : analysisName;
1453 if (workspace.
obj(mcname))
1458 mc->
SetWS(workspace);
1461 [&](
HS3::Likelihood const &
l) { return l.name == analysis.likelihood.name; });
1463 throw std::runtime_error(
"likelihood node not found!");
1467 auto checkPdf = [&](
RooAbsArg const *arg, std::string
const &
name, std::string
const &
what) {
1468 requirePdf(arg,
"the " +
what +
" '" +
name +
"' of analysis '" + analysisName +
"'");
1471 for (
auto const &term : likelihood.terms) {
1472 checkPdf(workspace.
arg(term.distribution.name), term.distribution.name,
"distribution");
1478 std::vector<std::unique_ptr<RooArgSet>> trees;
1479 for (
auto const &term : likelihood.terms) {
1480 RooAbsPdf *listed = workspace.
pdf(term.distribution.name);
1481 trees.push_back(listed ? std::unique_ptr<RooArgSet>{listed->
getComponents()} :
nullptr);
1483 auto isConstraintTermOfOthers = [&](
RooAbsArg const &term, std::size_t self) {
1484 auto isPartOf = [&term](
RooArgSet const &tree) {
1485 if (tree.find(term.
GetName())) {
1489 if (
auto const *array =
dynamic_cast<RooProdPdf const *
>(&term)) {
1490 for (
RooAbsArg const *component : array->pdfList()) {
1491 if (tree.find(component->
GetName())) {
1499 for (std::size_t i = 0; i < trees.size(); ++i) {
1500 if (i != self && trees[i] && isPartOf(*trees[i])) {
1511 std::string
const modelPdfName = mcInfo && mcInfo->
pdfName ? *mcInfo->
pdfName :
"";
1512 std::unique_ptr<RooArgSet> modelTree;
1513 if (
RooAbsPdf const *modelPdf = workspace.
pdf(modelPdfName);
1514 modelPdf && std::any_of(likelihood.
terms.begin(), likelihood.
terms.end(),
1515 [&](
auto const &term) { return term.distribution.name == modelPdfName; })) {
1516 modelTree.reset(modelPdf->getComponents());
1519 auto const *dataRef = std::get_if<HS3::DataRef>(&term.data);
1520 if (!modelTree || !dataRef || modelTree->find(listed.
GetName())) {
1523 return std::any_of(datasets.begin(), datasets.end(),
1524 [&](
auto const &
d) { return d && d->GetName() == dataRef->name && d->numEntries() == 1; });
1527 std::vector<std::string> nllDistNames;
1528 std::vector<HS3::LikelihoodTerm const *> nllTerms;
1531 for (std::size_t i = 0; i < likelihood.
terms.size(); ++i) {
1532 auto const &term = likelihood.
terms[i];
1533 RooAbsPdf *listed = workspace.
pdf(term.distribution.name);
1534 if (listed && !isConstraintTermOfOthers(*listed, i) && isConstraintTermOfModel(*listed, term)) {
1535 constraintsWithData.
add(*listed);
1536 }
else if (!listed || !isConstraintTermOfOthers(*listed, i)) {
1537 nllDistNames.push_back(term.distribution.name);
1538 nllTerms.push_back(&term);
1541 auto const *dataRef = std::get_if<HS3::DataRef>(&term.data);
1545 for (
auto &
d : datasets) {
1546 if (!
d ||
d->GetName() != dataRef->name) {
1549 if (
d->numEntries() != 1) {
1550 throw std::runtime_error(
"the data set '" + dataRef->name +
"' paired with the constraint term '" +
1551 term.distribution.name +
"' must have exactly one entry");
1554 auto *var = workspace.
var(obs->GetName());
1556 if (!var || !
value) {
1558 std::string(obs->GetName()) +
"' from the data set '" + dataRef->name +
1559 "': it is not a variable of the workspace");
1564 constraintObservables.
add(*var);
1572 std::set<std::string> channelConstraints;
1573 for (
auto const &item : doc.rooFit.channelConstraints) {
1574 for (
auto const &ref : item.second) {
1575 channelConstraints.insert(ref.name);
1579 for (
auto const &aux : likelihood.auxDistributions) {
1581 if (!extConstraint) {
1584 checkPdf(extConstraint, aux.name,
"auxiliary distribution");
1586 if (channelConstraints.count(aux.name) &&
1587 std::any_of(nllDistNames.begin(), nllDistNames.end(), [&](std::string
const &distName) {
1588 RooAbsArg const *dist = workspace.arg(distName);
1589 return dist && dist->dependsOn(*extConstraint);
1593 if (isConstraintTermOfOthers(*extConstraint, likelihood.
terms.size())) {
1596 extConstraints.
add(*extConstraint);
1601 auto const *dataRef = std::get_if<HS3::DataRef>(&term.
data);
1606 for (
const auto &
d : datasets) {
1608 if (
d &&
d->GetName() == dataRef->name) {
1610 observables.
add(*
d->get(),
true);
1614 throw std::runtime_error(
"dataset '" + dataRef->name +
"' cannot be found!");
1617 for (std::string
const &column : bookkeepingColumns) {
1619 observables.
remove(*arg);
1622 if (observables.
empty()) {
1623 observablesWithoutData(doc, analysis, mcInfo, variates, workspace, observables);
1627 for (
auto const &term : likelihood.terms) {
1628 auto const *dataRef = std::get_if<HS3::DataRef>(&term.
data);
1630 if (!dataRef || !simPdf) {
1634 auto const *combined = std::get_if<HS3::CombinedData>(&
data.body);
1635 if (combined &&
data.name == dataRef->name) {
1636 checkCombinedPairing(*simPdf,
data.name, *combined);
1641 std::string
const pdfName = mcInfo && mcInfo->
pdfName ? *mcInfo->
pdfName :
"simPdf";
1647 if (nllDistNames.size() == 1) {
1649 pdf = workspace.
pdf(nllDistNames[0]);
1652 std::string simPdfName = analysisName +
"_simPdf";
1653 std::string indexCatName = analysisName +
"_categoryIndex";
1654 RooCategory indexCat{indexCatName.c_str(), indexCatName.c_str()};
1655 std::map<std::string, RooAbsPdf *> pdfMap;
1656 for (std::size_t i = 0; i < nllDistNames.size(); ++i) {
1657 indexCat.defineType(nllDistNames[i], i);
1658 pdfMap[nllDistNames[i]] = workspace.
pdf(nllDistNames[i]);
1660 RooSimultaneous simPdf{simPdfName.c_str(), simPdfName.c_str(), pdfMap, indexCat};
1662 pdf = workspace.
pdf(simPdfName);
1668 extConstraints.
add(constraintsWithData,
true);
1669 if (!extConstraints.
empty())
1670 mc->SetExternalConstraints(extConstraints);
1672 if (analysis.
prior) {
1674 checkPdf(prior, analysis.
prior->name,
"prior");
1675 mc->SetPriorPdf(
static_cast<RooAbsPdf &
>(*prior));
1680 for (
auto const &poi : analysis.parametersOfInterest) {
1684 analysisName +
"' does not exist");
1688 "' is a " + arg->
ClassName() +
", not a variable" +
1689 (
dynamic_cast<RooConstVar *
>(arg) ?
", because no domain lists it" :
""));
1691 parametersOfInterest.
add(*arg);
1694 mc->SetParametersOfInterest(parametersOfInterest);
1695 mc->SetObservables(observables);
1708 for (
RooAbsArg const *extConstraint : extConstraints) {
1711 pars.
add(extPars,
true);
1715 for (
auto const &domainRef : analysis.domains) {
1716 auto thisDomain = std::find_if(doc.
domains.begin(), doc.
domains.end(),
1717 [&](
HS3::Domain const &
d) { return d.name == domainRef.name; });
1718 if (thisDomain == doc.
domains.end())
1720 for (
auto const &axis : thisDomain->axes) {
1721 auto *wsvar = workspace.
var(std::visit([](
auto const &
a) -> std::string
const & {
return a.name; }, axis));
1723 domainPars.
add(*wsvar);
1729 for (
const auto &
p : pars) {
1730 if (mc->GetParametersOfInterest()->find(*
p))
1732 if (
p->isConstant() && !mainPars.find(*
p) && domainPars.
find(*
p)) {
1734 }
else if (domainPars.
find(*
p)) {
1739 globs.
add(constraintObservables,
true);
1740 mc->SetGlobalObservables(globs);
1741 mc->SetNuisanceParameters(nps);
1750 const std::string &initName = analysis.
init->name;
1753 std::string setName = initName;
1754 const std::string prefix = mcname +
"_";
1755 const std::string suffix =
"_snapshot";
1756 if (initName.size() >= prefix.size() + suffix.size() &&
startsWith(initName, prefix) &&
1758 setName = initName.substr(prefix.size(), initName.size() - prefix.size() - suffix.size());
1763 initSet.
setName(setName.c_str());
1764 mc->SetSnapshot(initSet);
1771void warnAboutUnusedArrayComponents(
RooWorkspace const &ws)
1774 auto const *array =
dynamic_cast<RooProdPdf const *
>(arg);
1775 if (!array || !array->getAttribute(
arrayDistTag) || array->hasClients()) {
1780 for (
RooAbsArg const *component : array->pdfList()) {
1781 bool usedElsewhere =
false;
1782 for (
RooAbsArg const *client : component->clients()) {
1783 if (client != array) {
1784 usedElsewhere =
true;
1787 if (usedElsewhere) {
1790 unused += (unused.empty() ?
"'" :
", '") + std::string(component->
GetName()) +
"'";
1793 if (used && !unused.empty()) {
1796 "' are not used by any distribution and are not part of any likelihood");
1803 for (
auto const &item : doc.rooFit.combinedDistributions) {
1804 std::string
const &combinedName = item.first;
1808 std::map<std::string, RooAbsPdf *> pdfMap;
1810 for (std::size_t iChannel = 0; iChannel < info.
labels.size(); ++iChannel) {
1811 indexCat.defineType(info.
labels[iChannel], info.
indices[iChannel]);
1814 "the distribution '" +
name +
"' of the combined distribution '" + combinedName +
"'");
1818 RooSimultaneous simPdf{combinedName.c_str(), combinedName.c_str(), pdfMap, indexCat};
1823void combineDatasets(
HS3Document const &doc, std::vector<std::unique_ptr<RooAbsData>> &datasets)
1825 for (
auto const &item : doc.rooFit.combinedDatasets) {
1826 std::string
const &combinedName = item.first;
1830 std::map<std::string, std::unique_ptr<RooAbsData>> dsMap;
1833 for (std::size_t iChannel = 0; iChannel < info.
labels.size(); ++iChannel) {
1834 auto componentName = combinedName +
"_" + info.
labels[iChannel];
1838 std::find_if(datasets.begin(), datasets.end(), [&](
auto &
d) { return d && d->GetName() == componentName; });
1839 if (found == datasets.end()) {
1842 allVars.add(*(*found)->get(),
true);
1843 dsMap.insert({info.
labels[iChannel], std::move(*found)});
1844 indexCat.defineType(info.
labels[iChannel], info.
indices[iChannel]);
1847 auto combined = std::make_unique<RooDataSet>(combinedName, combinedName, allVars,
RooFit::Import(dsMap),
1849 datasets.emplace_back(std::move(combined));
1859 std::vector<std::unique_ptr<RooAbsData>> &datasets)
1862 auto const *info = std::get_if<HS3::CombinedData>(&
input.body);
1868 std::string
const context =
"the combined data set '" +
name +
"'";
1869 std::vector<RooCategory *> columns;
1870 for (std::string
const &column : info->columns) {
1874 " is not declared by a categorical axis of a domain");
1876 columns.push_back(cat);
1880 std::vector<std::string>
const *key;
1881 std::unique_ptr<RooAbsData>
data;
1883 std::vector<Component> components;
1885 for (std::size_t i = 0; i < columns.size(); ++i) {
1886 if (!columns[i]->hasLabel(
c.key[i])) {
1888 " of a key of " + context +
" is not one of the categories of '" +
1889 columns[i]->GetName() +
"'");
1893 std::find_if(datasets.begin(), datasets.end(), [&](
auto &
d) { return d && d->GetName() == c.data.name; });
1894 if (found == datasets.end()) {
1896 " is not a data set of the document, or it is already a component of " +
1897 "another combined data set");
1899 components.push_back({&
c.key, std::move(*found)});
1909 bool weighted =
false;
1910 bool storeErrors =
false;
1912 for (
auto const &
c : components) {
1913 vars.
add(*
c.data->get(),
true);
1914 weighted |=
c.data->isWeighted();
1915 if (
auto *ds =
dynamic_cast<RooDataSet const *
>(
c.data.get()); ds && ds->isWeighted()) {
1916 weightName = ds->weightVar()->GetName();
1918 storeErrors |=
dynamic_cast<RooDataHist const *
>(
c.data.get()) !=
nullptr;
1920 std::unique_ptr<RooDataSet> combined;
1922 RooRealVar weightVar{weightName.c_str(), weightName.c_str(), 1.0};
1923 vars.
add(weightVar);
1928 combined = std::make_unique<RooDataSet>(
name.c_str(),
name.c_str(), vars);
1930 for (
auto const &
c : components) {
1931 for (std::size_t i = 0; i < columns.size(); ++i) {
1932 static_cast<RooCategory &
>(vars[columns[i]->GetName()]).setLabel((*
c.key)[i].c_str());
1934 for (
int i = 0; i <
c.data->numEntries(); ++i) {
1937 combined->add(vars,
c.data->weight(), storeErrors ?
c.data->weightError(
RooAbsData::SumW2) : 0.0);
1939 combined->add(vars);
1943 datasets.emplace_back(std::move(combined));
1948void sortByName(T &coll)
1950 std::sort(coll.begin(), coll.end(), [](
auto &
l,
auto &
r) { return strcmp(l->GetName(), r->GetName()) < 0; });
1962 for (
RooAbsArg const *client : arg.clients()) {
1976 vars.
addOwned(createObservable(axis));
1982 std::vector<double>
const &contents,
1983 std::vector<double>
const *errors)
1985 if (errors && errors->size() != contents.size()) {
1987 std::to_string(errors->size()) +
", contents=" + std::to_string(contents.size()));
1989 auto bins = generateBinIndices(vars);
1990 if (contents.size() != bins.size()) {
1992 ", bins=" + std::to_string(bins.size()));
1994 auto dh = std::make_unique<RooDataHist>(
name,
name, vars);
1997 if (errors && !errors->empty()) {
2000 for (std::size_t ibin = 0; ibin < bins.size(); ++ibin) {
2001 dh->set(ibin, contents[ibin], errors ? (*errors)[ibin] : -1);
2022 error(
"unable to stream collection " + std::string(coll.
GetName()) +
" to " + node.
key());
2057 if (str.empty() || !(std::isalpha(str[0]) || str[0] ==
'_')) {
2062 for (
char c : str) {
2064 if (!(std::isalnum(
c) ||
c ==
'_')) {
2076 std::stringstream ss;
2077 ss <<
"RooJSONFactoryWSTool() name '" <<
name <<
"' is not valid!" << std::endl
2078 <<
"Sanitize names by setting RooJSONFactoryWSTool::config().allowSanitizeNames = true." << std::endl;
2091 return n[
"name"].val();
2096 return appendNamedChild(rootNode[
"parameter_points"],
"default_values")[
"parameters"];
2100RooRealVar *RooJSONFactoryWSTool::requestImpl<RooRealVar>(
const std::string &objname)
2105 auto it =
_import->defaultValuesByName.find(objname);
2106 if (it !=
_import->defaultValuesByName.end()) {
2116RooAbsPdf *RooJSONFactoryWSTool::requestImpl<RooAbsPdf>(
const std::string &objname)
2121 auto it =
_import->distributions.find(objname);
2122 if (it !=
_import->distributions.end()) {
2128 auto function =
_import->functions.find(objname);
2129 if (function !=
_import->functions.end()) {
2139RooAbsReal *RooJSONFactoryWSTool::requestImpl<RooAbsReal>(
const std::string &objname)
2143 auto toNumOutput =
toNumber(objname);
2144 if (toNumOutput.valid)
2146 if (
RooAbsPdf *pdf = requestImpl<RooAbsPdf>(objname))
2148 if (
RooRealVar *var = requestImpl<RooRealVar>(objname))
2153 auto it =
_import->functions.find(objname);
2154 if (it !=
_import->functions.end()) {
2180 axis.
name = cv->GetName();
2187 var.
name =
v->GetName();
2188 var.
value = rrv->getVal();
2189 var.
isConst = storeConstant && (rrv->isConstant() || rrv->getMin() >= rrv->getMax());
2190 recordDomains(
_export->domains, *rrv);
2203 const std::string &formula)
2205 std::string newname = std::string(original->
GetName()) + suffix;
2207 auto &functions =
_export->doc.functions;
2208 if (std::find_if(functions.begin(), functions.end(), [&](
auto const &
f) { return f.name == newname; }) !=
2213 trafo_node[
"type"] <<
"generic";
2215 functions.push_back({newname, {
"generic",
nullptr}});
2224std::string makeValidNameOrError(std::string
const &in)
2226 if (!std::isalpha(in[0])) {
2229 std::string out = in;
2230 std::transform(out.begin(), out.end(), out.begin(), [](
char c) { return std::isalnum(c) ? c :
'_'; });
2232 oocoutW(
nullptr, ObjectHandling) <<
"RooFitHS3: changed '" << in <<
"' to '" << out <<
"' to become a valid name";
2239std::string selectionKeyName(std::vector<std::string>
const &key)
2242 for (std::string
const &label : key) {
2243 out += (out.empty() ?
"" :
"_") + makeValidNameOrError(label);
2251 std::vector<std::string> names;
2253 names.push_back(column->GetName());
2261 std::vector<RooSimultaneous const *> candidates;
2262 for (
RooAbsArg *arg : workspace.allPdfs()) {
2264 candidates.push_back(candidate);
2267 sortByName(candidates);
2269 std::vector<std::string> candidateColumns;
2271 candidateColumns.push_back(column->GetName());
2273 if (candidateColumns == columns) {
2302 std::set<std::string> &exportedObjectNames =
_export->exportedObjectNames;
2305 if (exportedObjectNames.find(
name) != exportedObjectNames.end()) {
2308 auto const &arrayOfComponent =
_export->arrayOfComponent;
2309 if (
auto found = arrayOfComponent.find(
name); found != arrayOfComponent.end() && found->second !=
name) {
2310 error(
"'" +
name +
"' is written as a component of the array distribution '" + found->second +
2311 "', but another object refers to it by its own name. Set "
2312 "RooJSONFactoryWSTool::config().exportArrayDist = false to write it on its own.");
2317 exportedObjectNames.insert(
name);
2325 DepthGuard(
int &
d) : depth{
d} { ++depth; }
2326 ~DepthGuard() { --depth; }
2342 auto const *prod =
dynamic_cast<RooProdPdf const *
>(&func);
2345 "' of an array distribution, but it is not a RooProdPdf");
2347 for (
RooAbsPdf *pdf : static_range_cast<RooAbsPdf *>(prod->pdfList())) {
2349 if (writtenIn !=
name) {
2350 error(
"cannot write '" +
name +
"' as an array distribution: its component '" + pdf->
GetName() +
2351 "' is already written as '" + writtenIn +
"'");
2360 auto &collectionNode = (*
_export->root)[isPdf ?
"distributions" :
"functions"];
2368 auto it = exporters.find(cl);
2369 if (it != exporters.end()) {
2370 for (
auto &exp : it->second) {
2373 if (!exp->exportObject(
this, &func, elem)) {
2378 elem[
"name"] <<
name;
2384 elem[
"name"] <<
name;
2387 if (!
_export->channelConstraints.empty()) {
2388 _export->doc.rooFit.channelConstraints[
name] = std::move(
_export->channelConstraints);
2390 _export->channelConstraints.clear();
2392 recordGenericObject(
_export->doc, isPdf,
name, elem);
2394 if (exp->autoExportDependants()) {
2406 std::cerr <<
"unable to export '" <<
name <<
"' of class '" << cl->
GetName()
2407 <<
"': no exporter is registered for this class, or none of them could handle the object. Check "
2408 "https://root.cern/doc/master/group__roofit__dev__docs__hs3.html to see how to write one!\n";
2418 const std::string pdfName = pdf.
GetName();
2419 auto &arrayOfComponent =
_export->arrayOfComponent;
2420 auto &arrayComponents =
_export->arrayComponents;
2421 auto &exportedObjectNames =
_export->exportedObjectNames;
2422 if (
auto it = arrayOfComponent.find(pdfName); it != arrayOfComponent.end()) {
2426 if (exportedObjectNames.find(pdfName) != exportedObjectNames.end()) {
2429 if (arrayComponents.find(arrayName) == arrayComponents.end()) {
2432 error(
"cannot write the array distribution '" + arrayName +
2433 "': the workspace has another object of that name");
2435 exportedObjectNames.insert(arrayName);
2437 arrayComponents[arrayName].push_back(&pdf);
2438 arrayOfComponent[pdfName] = arrayName;
2439 exportedObjectNames.insert(pdfName);
2447 std::set<std::string> written;
2448 auto &arrayComponents =
_export->arrayComponents;
2450 auto next = std::find_if(arrayComponents.begin(), arrayComponents.end(),
2451 [&](
auto const &item) { return written.find(item.first) == written.end(); });
2452 if (next == arrayComponents.end()) {
2455 const std::string arrayName = next->first;
2456 written.insert(arrayName);
2458 const std::vector<RooAbsPdf const *> components = next->second;
2461 recordGenericObject(
_export->doc,
true, arrayName, elem);
2462 for (
RooAbsPdf const *pdf : components) {
2478 auto found =
_export->constraintObservables.find(pdfName);
2479 return found ==
_export->constraintObservables.end() ? nullptr : &found->second;
2484 auto &out =
_export->constraintTermsOfPdf[pdfName];
2485 for (
auto const &term : terms) {
2486 if (std::find(out.begin(), out.end(), term) == out.end()) {
2487 out.push_back(term);
2497 std::vector<RooAbsPdf const *> components;
2498 if (
auto found =
_export->arrayComponents.find(term); found !=
_export->arrayComponents.end()) {
2499 components = found->second;
2501 components.push_back(pdf);
2503 std::vector<std::string> observables;
2504 for (
RooAbsPdf const *pdf : components) {
2506 if (!info || !globalObservables || !globalObservables->
find(info->observable.c_str())) {
2509 observables.push_back(info->observable);
2511 if (observables.empty()) {
2514 const std::string dataName = term +
"_data";
2515 if (!
_export->writtenConstraintData.insert(dataName).second) {
2519 error(
"cannot write the observed values of the constraint term '" + term +
"' as the data set '" + dataName +
2520 "': the workspace has a data set of that name");
2523 for (std::string
const &
name : observables) {
2526 error(
"the observable '" +
name +
"' of the constraint term '" + term +
"' is not in the workspace");
2531 axis.
min = -std::numeric_limits<double>::max();
2532 axis.
max = std::numeric_limits<double>::max();
2533 if (
auto const *rrv =
dynamic_cast<RooRealVar const *
>(var)) {
2534 if (std::isfinite(rrv->getMin())) {
2535 axis.
min = rrv->getMin();
2537 if (std::isfinite(rrv->getMax())) {
2538 axis.
max = rrv->getMax();
2541 data.axes.emplace_back(std::move(axis));
2544 _export->doc.data.push_back({dataName, std::move(
data)});
2562 elem[
"type"] <<
"combined_dist";
2563 auto &columnsNode = elem[
"columns"].
set_seq();
2568 auto &components = elem[
"components"].
set_seq();
2571 std::set<RooAbsArg const *> replaced;
2572 std::vector<RooAbsArg const *> replacements;
2576 for (std::vector<std::string>
const &key :
selectionKeys(columns)) {
2577 const std::string label =
selectionLabel(indexCat, columns, key);
2583 auto found = renamed->second.find(label);
2584 if (found != renamed->second.end()) {
2585 replaced.insert(pdf);
2586 pdf = found->second;
2587 replacements.push_back(pdf);
2590 JSONNode &component = components.append_child().set_map();
2592 component[
"dist"] << pdf->
GetName();
2596 std::vector<RooAbsArg const *> servers;
2598 if (replaced.count(server) == 0) {
2599 servers.push_back(server);
2602 servers.insert(servers.end(), replacements.begin(), replacements.end());
2613 for (
unsigned int i = 0; i < cat.
size(); ++i) {
2617 if (found !=
_export->categories.end() && found->second.categories != axis.
categories) {
2619 "' is written to the domain twice, with different states");
2659 std::string prefix = genPrefix(
p,
true);
2660 if (!prefix.empty())
2662 if (!
p.has_child(
"type")) {
2666 std::string functype(
p[
"type"].val());
2669 if (!importAllDependants) {
2674 auto it = importers.find(functype);
2676 if (it != importers.end()) {
2677 for (
auto &imp : it->second) {
2680 auto const &channelConstraints =
_import->document.rooFit.channelConstraints;
2681 auto found = channelConstraints.find(
name);
2685 ok = imp->importArg(
this,
p);
2693 "RooJSONFactoryWSTool() no handling for type '" + functype +
2694 "' implemented. Check https://root.cern/doc/master/group__roofit__dev__docs__hs3.html "
2695 "to see how to write an importer for it!");
2701 for (std::string
const &component : recorder.unreadComponents()) {
2702 warning(
"RooFitHS3: " +
name +
": unknown component \"" + component +
"\" is ignored");
2709 if (
auto const *generic = std::get_if<HS3::GenericObject>(&distribution.
body)) {
2713 std::string
const &
name = distribution.
name;
2722 auto const &channelConstraints =
_import->document.rooFit.channelConstraints;
2723 auto found = channelConstraints.find(
name);
2725 found != channelConstraints.end() ? &found->second :
nullptr);
2740 this->
importFunction((JSONTree::create(jsonString))->rootnode(), importAllDependants);
2755 obsNode[
"name"] << cat.
GetName();
2756 auto &labels = obsNode[
"categories"].
set_seq();
2757 for (
unsigned int i = 0; i < cat.
size(); ++i) {
2758 labels.append_child() << cat.
getOrdinal(i).first;
2766 obsNode[
"name"] <<
name;
2785 auto &observablesNode = output[
"axes"].
set_seq();
2788 if (
auto const *cat =
dynamic_cast<RooCategory const *
>(var)) {
2812 for (std::size_t i = 0; i <
n; ++i) {
2813 double w = contents[i];
2832 if (!
config().renameCombinedObservables) {
2835 std::vector<RooAbsData *> datasets;
2837 datasets.push_back(
data);
2839 sortByName(datasets);
2842 if (columns.empty()) {
2846 for (std::vector<std::string>
const &key :
selectionKeys(columns)) {
2847 const std::string keyName = selectionKeyName(key);
2853 component = simPdf->
getPdf(label);
2858 candidates.
add(*observables);
2862 std::vector<RooAbsArg *> observables;
2865 observables.push_back(arg);
2868 sortByName(observables);
2869 std::map<std::string, std::string> renames;
2870 for (
RooAbsArg const *obs : observables) {
2871 std::string
const newName =
2872 "obs_" + keyName + (observables.size() == 1 ?
"" :
"_" + std::string(obs->GetName()));
2873 if (newName == obs->GetName()) {
2877 error(
"can't rename the observable '" + std::string(obs->GetName()) +
"' of the data set '" +
2878 data->GetName() +
"' to '" + newName +
"': an object of that name already exists");
2880 renames[obs->GetName()] = newName;
2882 if (renames.empty()) {
2892 for (
auto const &[from, to] : renames) {
2897 auto *renamedComponent =
static_cast<RooAbsPdf *
>(customizer.build());
2920 info.
columns.push_back(column->GetName());
2926 std::unique_ptr<RooSuperCategory> superCat;
2928 std::vector<std::unique_ptr<RooAbsData>> parts;
2931 parts =
data.split(*simPdf,
true);
2932 }
else if (columns.size() == 1) {
2933 indexCat = columns.front();
2934 parts =
data.split(*indexCat,
true);
2938 inputs.
add(*column);
2940 const std::string superName = info.
name +
"_key";
2941 superCat = std::make_unique<RooSuperCategory>(superName.c_str(), superName.c_str(), inputs);
2942 indexCat = superCat.get();
2943 parts =
data.split(*indexCat,
true);
2949 std::vector<RooAbsData *> subDataSets;
2950 for (std::vector<std::string>
const &key :
selectionKeys(columns)) {
2951 std::string
const label =
selectionLabel(*indexCat, columns, key);
2952 auto found = std::find_if(parts.begin(), parts.end(), [&](
auto &
d) { return d->GetName() == label; });
2953 if (found == parts.end() || ((*found)->numEntries() == 0 && simPdf && !simPdf->
getPdf(label))) {
2956 const std::string keyName = selectionKeyName(key);
2957 const std::string subName = info.
name +
"_" + keyName;
2958 (*found)->SetName(subName.c_str());
2962 auto renames = renamesOfData->second.find(keyName);
2963 if (renames != renamesOfData->second.end()) {
2964 for (
auto const &[from, to] : renames->second) {
2965 (*found)->changeObservableName(from.c_str(), to.c_str());
2969 combined.
components.push_back({key, {subName}});
2970 subDataSets.push_back(found->get());
2972 _export->doc.data.push_back({info.
name, std::move(combined)});
2984 error(
"the data set '" + std::string(
data.GetName()) +
"' has the categorical observable '" + obs->GetName() +
2985 "', which is not a RooCategory, and can't be written as a combined data set");
2999 if (
auto weightVar = variables.find(
"weightVar")) {
3000 variables.remove(*weightVar);
3004 auto categoricalAxis = [&](
RooCategory const &cat) {
3009 for (
unsigned int i = 0; i < cat.
size(); ++i) {
3015 auto exportBinned = [&](std::size_t
n,
double const *contents) {
3017 for (
RooAbsArg const *arg : variables) {
3018 if (
auto const *cat =
dynamic_cast<RooCategory const *
>(arg)) {
3019 binned.axes.emplace_back(categoricalAxis(*cat));
3022 auto const *var =
static_cast<RooRealVar const *
>(arg);
3023 recordDomains(
_export->domains, *var);
3026 binned.contents.assign(contents, contents +
n);
3027 output.
body = std::move(binned);
3028 _export->doc.data.push_back(std::move(output));
3033 return exportBinned(dh->numEntries(), dh->weightArray());
3043 if (
data.isWeighted() && variables.size() == 1 &&
dynamic_cast<RooRealVar const *
>(variables[0]) &&
3045 bool isBinnedData =
false;
3046 auto &
x =
static_cast<RooRealVar const &
>(*variables[0]);
3047 std::vector<double> contents;
3049 for (; i <
data.numEntries(); ++i) {
3051 if (
x.getBin() != i)
3053 contents.push_back(
data.weight());
3057 if (i ==
x.getBins() &&
data.numEntries() ==
x.getBins())
3058 isBinnedData =
true;
3060 return exportBinned(contents.size(), contents.data());
3066 for (
RooAbsArg const *arg : variables) {
3067 if (
auto const *cat =
dynamic_cast<RooCategory const *
>(arg)) {
3068 unbinned.axes.emplace_back(categoricalAxis(*cat));
3071 auto const *var =
static_cast<RooRealVar const *
>(arg);
3072 recordDomains(
_export->domains, *var);
3077 std::vector<double> weightVals;
3078 bool hasNonUnityWeights =
false;
3079 for (
int i = 0; i <
data.numEntries(); ++i) {
3082 for (
RooAbsArg const *arg : variables) {
3083 if (
auto const *cat =
dynamic_cast<RooCategory const *
>(arg)) {
3086 unbinned.entries.push_back(
static_cast<RooRealVar const *
>(arg)->
getVal());
3089 if (
data.isWeighted()) {
3090 weightVals.push_back(
data.weight());
3091 if (
data.weight() != 1.)
3092 hasNonUnityWeights =
true;
3095 if (
data.isWeighted() && hasNonUnityWeights) {
3096 unbinned.weights = std::move(weightVals);
3098 output.
body = std::move(unbinned);
3099 _export->doc.data.push_back(std::move(output));
3130std::unique_ptr<RooDataHist>
3133 if (!
n.has_child(
"contents"))
3136 JSONNode const &contents =
n[
"contents"];
3141 std::vector<double> contentVals;
3142 contentVals << contents;
3144 if (!
n.has_child(
"errors")) {
3147 if (!
n[
"errors"].is_seq())
3149 std::vector<double> errorVals;
3150 errorVals <<
n[
"errors"];
3163 if (
p.value && std::holds_alternative<std::string>(*
p.value))
3165 if (!
_import->ranges.contains(
p.name)) {
3167 auto const &attributes =
_import->document.rooFit.attributes;
3168 auto found = attributes.find(
p.name);
3169 if (found != attributes.end() && found->second.isConstVar) {
3173 wsEmplace<RooConstVar>(
p.name, std::get<double>(*
p.value));
3177 RooRealVar &var = wsEmplace<RooRealVar>(
p.name, 1.);
3178 configureVariable(
_import->ranges,
p, var);
3186 warning(std::string(
"RooFitHS3: the parameter '") + var.
GetName() +
3187 "' is not listed in any domain and is not constant: HS3 requires a domain, or \"const\": true. It "
3188 "is read as a free parameter without range.");
3195 for (
const char *section : {
"functions",
"distributions"}) {
3196 if (
auto seq =
n.find(section)) {
3197 for (
const auto &
p : seq->children()) {
3205 const std::vector<CombinedData> &combDataSets,
3206 const std::vector<RooAbsData *> &singleDataSets)
3215 std::vector<std::string> columns;
3217 columns.push_back(column->GetName());
3219 for (
auto const &
data : combDataSets) {
3220 if (
data.columns == columns) {
3227 for (
auto *
data : singleDataSets) {
3229 const std::string dataName =
data->GetName();
3235 if (founddata == 0) {
3243struct ChannelConstraint {
3244 std::string channel;
3246 bool histFactory =
false;
3263std::vector<ChannelConstraint>
3265 std::function<
bool(std::string
const &)>
const &isHistFactoryChannel,
3266 std::map<std::string, RooAbsPdf const *>
const *renamed)
3270 std::unique_ptr<RooArgSet> constraints{pdf.
getAllConstraints(observables, params,
false)};
3271 std::vector<RooAbsPdf const *> channels;
3272 if (
auto const *simPdf =
dynamic_cast<RooSimultaneous const *
>(&pdf)) {
3273 for (
auto const &item : simPdf->indexCat()) {
3276 if (
auto found = renamed->find(item.first); found != renamed->end()) {
3277 component = found->second;
3281 channels.push_back(component);
3285 channels.push_back(&pdf);
3287 std::vector<ChannelConstraint> out;
3288 for (
RooAbsPdf const *channel : channels) {
3289 auto const *prod =
dynamic_cast<RooProdPdf const *
>(channel);
3293 const bool histFactory = isHistFactoryChannel(prod->GetName());
3296 bool usedElsewhere =
false;
3297 for (
RooAbsArg const *client : prod->clients()) {
3298 if (ws.
arg(client->GetName()) == client && !
dynamic_cast<RooSimultaneous const *
>(client)) {
3299 usedElsewhere =
true;
3302 if (usedElsewhere) {
3307 auto const *nested =
dynamic_cast<RooProdPdf const *
>(&term);
3308 if (!histFactory || !nested) {
3309 out.push_back({prod->GetName(), &term, histFactory});
3312 for (
RooAbsArg const *factor : nested->pdfList()) {
3313 add(
static_cast<RooAbsPdf const &
>(*factor));
3316 for (
RooAbsArg const *factor : prod->pdfList()) {
3317 if (constraints->find(*factor)) {
3318 add(
static_cast<RooAbsPdf const &
>(*factor));
3328 std::string
const *dataName)
3334 analysis.
name = analysisName;
3338 likelihood.
name = analysisName +
"_likelihood";
3347 auto addAux = [&](std::string
const &
name) {
3349 if (std::find_if(aux.begin(), aux.end(), [&](
auto const &ref) { return ref.name == name; }) == aux.end()) {
3350 aux.push_back({
name});
3359 std::vector<std::string> channels;
3360 for (
auto const &term : likelihood.
terms) {
3364 for (
auto const &item : simPdf->
indexCat()) {
3367 if (
auto found = renamed->second.find(item.first); found != renamed->second.end()) {
3368 component = found->second;
3372 channels.push_back(component->
GetName());
3377 std::vector<std::string> constraintTerms;
3378 auto addConstraintTerm = [&](std::string
const &term) {
3379 if (std::find(constraintTerms.begin(), constraintTerms.end(), term) == constraintTerms.end()) {
3380 constraintTerms.push_back(term);
3385 addConstraintTerm(constr->GetName());
3391 auto writtenByHistFactory = [&](std::string
const &channel) {
3392 std::vector<std::string> out;
3393 auto add = [&](std::string
const &
name) {
3394 if (std::find(out.begin(), out.end(),
name) == out.end()) {
3395 out.push_back(
name);
3398 if (
auto found =
_export->constraintTermsOfPdf.find(channel); found !=
_export->constraintTermsOfPdf.end()) {
3399 for (std::string
const &term : found->second) {
3404 for (
auto const &ref : found->second) {
3411 if (!observables || observables->
empty()) {
3414 for (std::string
const &channel : channels) {
3415 for (std::string
const &term : writtenByHistFactory(channel)) {
3416 addConstraintTerm(term);
3420 auto isHistFactoryChannel = [&](std::string
const &
name) {
3421 return _export->constraintTermsOfPdf.count(
name) ||
3423 return dist.name == name && std::holds_alternative<HS3::HistFactoryDist>(dist.body);
3428 std::map<std::string, std::vector<std::string>> termsOfChannel;
3430 for (ChannelConstraint
const &item :
3431 constraintsOfChannels(
_workspace, *pdf, *observables, isHistFactoryChannel,
3433 std::string term = item.constraint->GetName();
3434 if (item.histFactory) {
3435 if (
auto found =
_export->arrayOfComponent.find(term); found !=
_export->arrayOfComponent.end()) {
3436 term = found->second;
3439 auto &terms = termsOfChannel[item.channel];
3440 if (std::find(terms.begin(), terms.end(), term) == terms.end()) {
3441 terms.push_back(term);
3444 for (std::string
const &channel : channels) {
3445 std::vector<std::string>
const &found = termsOfChannel[channel];
3446 if (!isHistFactoryChannel(channel)) {
3447 for (std::string
const &term : found) {
3448 addConstraintTerm(term);
3455 std::vector<std::string>
const written = writtenByHistFactory(channel);
3456 std::set<std::string>
const writtenSet{written.begin(), written.end()};
3457 std::set<std::string>
const foundSet{found.begin(), found.end()};
3458 if (writtenSet != foundSet) {
3459 auto join = [](std::set<std::string>
const &names) {
3461 for (std::string
const &
name : names) {
3462 out += (out.empty() ?
"'" :
", '") +
name +
"'";
3464 return out.empty() ? std::string{
"none"} : out;
3466 error(
"cannot export the constraint terms of the HistFactory channel '" + channel +
3467 "': the channel writes " + join(writtenSet) +
", but RooFit finds " + join(foundSet));
3469 for (std::string
const &term : written) {
3470 addConstraintTerm(term);
3474 for (std::string
const &term : constraintTerms) {
3484 std::vector<std::string> names;
3485 names.reserve(pois->size());
3487 names.push_back(arg->
GetName());
3488 std::sort(names.begin(), names.end());
3489 for (
auto const &
name : names) {
3494 auto writeProductDomain = [&](
const char *suffix,
RooArgSet const *args) {
3495 if (!args || args->
empty())
3498 domain.
name = analysisName + suffix;
3502 for (
auto *var : static_range_cast<const RooRealVar *>(sorted)) {
3519 doc.
analyses.push_back(std::move(analysis));
3526 std::vector<std::string> names;
3528 names.push_back(arg->
GetName());
3530 std::sort(names.begin(), names.end());
3538 _export = std::make_unique<HS3::ToolExportState>();
3541 struct ExportScope {
3543 ~ExportScope() { tool.
_export.reset(); }
3544 } exportScope{*
this};
3553 std::vector<RooAbsPdf *> allpdfs;
3556 if (
auto *pdf =
dynamic_cast<RooAbsPdf *
>(arg)) {
3557 allpdfs.push_back(pdf);
3561 sortByName(allpdfs);
3565 std::vector<RooAbsReal *> allfuncs;
3568 if (
auto *func =
dynamic_cast<RooAbsReal *
>(arg)) {
3569 allfuncs.push_back(func);
3573 sortByName(allfuncs);
3585 std::vector<RooAbsData *> alldata;
3587 alldata.push_back(
d);
3589 sortByName(alldata);
3591 std::vector<RooAbsData *> singleData;
3592 std::vector<RooJSONFactoryWSTool::CombinedData> combData;
3593 for (
auto &
d : alldata) {
3598 !findMatchingSimultaneous(
_workspace, selectionColumnNames(*
d->get())))) {
3599 singleData.push_back(
d);
3621 bool do_export =
false;
3622 for (
const auto &pdf : allpdfs) {
3629 snapshotSorted.
add(*arg);
3632 snapshotSorted.
sort();
3633 std::string
name(snsh->GetName());
3634 if (
name !=
"default_values") {
3641 for (
auto const &item :
_export->categories) {
3642 if (defaultAxes.count(item.first)) {
3644 "' is categorical, but the domain already lists it as continuous");
3648 for (
auto &item :
_export->domains) {
3650 [&](
HS3::Domain const &domain) { return domain.name == item.first; })) {
3651 appendDomain(doc.
domains, item.first, std::move(item.second),
3653 : std::map<std::string, HS3::CategoricalAxis>{});
3661 validateOptions.
isExternal = [](std::string
const &) {
return false; };
3664 for (
auto &diagnostic : diagnostics) {
3665 diagnostic.severity = HS3::Diagnostic::Severity::Warning;
3666 diagnostic.message =
"the exported document is not valid: " + diagnostic.message;
3674 writeLikelihoodTermsOnce(
n);
3676 if (std::vector<std::string>
const shared = sharedVariatesOfDocument(
n); !shared.empty()) {
3677 if (!
config().allowExportSharedVariates) {
3679 for (std::string
const &
message : shared) {
3683 ". HS3 requires the terms of a likelihood and the components of a combined distribution to have "
3684 "distinct variates: give the variates their own names (e.g. 'mass_SR' and 'mass_CR' instead of "
3685 "'mass'; RooJSONFactoryWSTool::config().renameCombinedObservables does this for the observables of "
3686 "combined data sets), or set RooJSONFactoryWSTool::config().allowExportSharedVariates = true to "
3687 "write the document anyway, with a warning, and rename them in the JSON.");
3689 for (std::string
const &
message : shared) {
3691 ". HS3 requires distinct variates: the document is not valid HS3, and can't be read back before the "
3692 "variates are renamed.");
3705 std::stringstream ss(s);
3716 std::stringstream ss;
3728 std::unique_ptr<JSONTree> tree = JSONTree::create();
3731 auto &metadata =
n[
"metadata"].set_map();
3736 appendNamedChild(metadata[
"packages"],
"ROOT")[
"version"] << rootVersion();
3749 std::unique_ptr<JSONTree> tree = JSONTree::create();
3750 JSONNode &
n = tree->rootnode().set_map();
3764 std::ofstream out(
filename.c_str());
3774 auto const &attributes =
_import->document.rooFit.attributes;
3775 auto found = attributes.find(obj);
3776 if (found == attributes.end())
3778 auto const &tags = found->second.tags;
3779 return std::find(tags.begin(), tags.end(), attrib) != tags.end();
3783 _export->doc.rooFit.attributes[obj].tags.push_back(attrib);
3790 auto const &attributes =
_import->document.rooFit.attributes;
3791 auto found = attributes.find(obj);
3792 if (found == attributes.end())
3794 auto value = found->second.dict.find(attrib);
3795 return value != found->second.dict.end() ?
value->second :
"";
3798 const std::string &
value)
3800 _export->doc.rooFit.attributes[obj].dict[attrib] =
value;
3809 auto histFactoryImporters = importers.find(
"histfactory_dist");
3810 options.
typedHistFactory = histFactoryImporters != importers.end() && !histFactoryImporters->second.empty() &&
3816 std::optional<RooFit::ValidatedHS3Document> validated;
3821 validated =
HS3::validate(std::move(parsed), diagnostics, validateOptions);
3827 struct ImportScope {
3834 } importScope{*
this};
3838 _import = std::make_unique<HS3::ToolImportState>(doc);
3843 for (
auto const &
p :
_import->defaultValues->parameters) {
3847 for (
auto const &function : doc.
functions) {
3861 for (
auto const &var : point.parameters) {
3862 std::string
const *label = var.value ? std::get_if<std::string>(&*var.value) :
nullptr;
3866 }
else if (var.value) {
3867 cat->
setIndex(
static_cast<int>(std::get<double>(*var.value)));
3873 warning(
"RooFitHS3: ignoring the string value of parameter '" + var.name +
"' in parameter point '" +
3874 point.name +
"', because there is no category with that name.");
3882 rrv = &wsEmplace<RooRealVar>(var.name, 1.);
3883 configureVariable(
_import->ranges, var, *rrv);
3886 configureVariable(
_import->ranges, var, *rrv);
3898 importAttributes(arg, item.second);
3904 std::vector<std::unique_ptr<RooAbsData>> datasets;
3905 datasets.reserve(doc.
data.size());
3906 for (
auto const &
data : doc.
data) {
3908 if (!std::holds_alternative<HS3::CombinedData>(
data.body)) {
3912 assembleCombinedData(doc,
_workspace, datasets);
3918 std::set<std::string> bookkeepingColumns;
3919 for (
auto const &[dataset, columns] : bookkeepingColumnsOfDocument(
n)) {
3920 for (std::string
const &column : columns) {
3921 warning(
"RooFitHS3: the axis '" + column +
"' of the components of the combined data set '" + dataset +
3922 "' is declared as a bookkeeping column without statistical meaning (misc.ROOT_internal."
3923 "bookkeeping_columns), so it may be shared by the components, although HS3 requires distinct axes.");
3924 bookkeepingColumns.insert(column);
3927 for (std::string
const &
message : sharedVariatesOfDocument(
n)) {
3930 ". The terms of a likelihood and the components of a combined distribution or data set must have "
3931 "distinct variates.");
3934 ". HS3 0.3 requires distinct variates; the document is read anyway, since it declares an older "
3938 for (
auto const &analysis : doc.
analyses) {
3940 std::set<std::string> variates;
3943 for (
auto const &term : likelihood.
terms) {
3945 variates.insert(
v.begin(),
v.end());
3948 if (dist && typeOf(*dist) ==
"combined_dist") {
3949 if (
JSONNode const *columns = dist->find(
"columns")) {
3950 addNames(*columns, variates);
3956 importAnalysis(doc, analysis,
_workspace, datasets, bookkeepingColumns, variates);
3959 combineDatasets(doc, datasets);
3961 for (
auto const &
d : datasets) {
3964 for (
auto const &obs : *
d->get()) {
3965 if (
auto *rrv =
dynamic_cast<RooRealVar *
>(obs)) {
3966 _workspace.
var(rrv->GetName())->setBinning(rrv->getBinning());
3989 std::unique_ptr<JSONTree> tree = JSONTree::create(is);
4003 std::ifstream infile(
filename.c_str());
4004 if (!infile.is_open())
4016 if (
n.find(
"poi")) {
4019 std::string poi =
n.find(
"poi")->val();
4020 std::string pdname =
n.find(
"pdfName")->val();
4022 modelConfig.SetPdf(pdname.c_str());
4031 bool isVariable =
true;
4032 bool isData =
false;
4034 if (
n.find(
"type")) {
4036 std::string elementType =
n.find(
"type")->val();
4037 if (elementType ==
"binned" || elementType ==
"unbinned") {
4045 }
else if (isData) {
4062 if (!
value && !(min && max)) {
4063 throw std::invalid_argument(
"Invalid Syntax: Please provide either 'value' or 'min' and 'max' or both");
4066 axis.
name = elementNode[
"name"].
val();
4070 axis.
min = min->val_double();
4071 axis.
max = max->val_double();
4079 _import = std::make_unique<HS3::ToolImportState>(doc);
4080 struct ImportScope {
4082 ~ImportScope() { tool.
_import.reset(); }
4083 } importScope{*
this};
4087 configureVariable(
_import->ranges, parameter, *rrv);
4111 throw std::runtime_error(s);
4124 for (
char c : str) {
4129 case '(':
result +=
'_';
break;
4134 case '.':
result +=
"_dot_";
break;
4135 case '@':
result +=
"at";
break;
4136 case '-':
result +=
"minus";
break;
4137 case '/':
result +=
"_div_";
break;
4152 if (onlyModelConfig) {
4161 for (
auto *pdf : ws.
allPdfs()) {
4162 if (isTopLevel(*pdf, ws)) {
4168 if (isTopLevel(*func, ws)) {
4187 auto *snshSet =
dynamic_cast<RooArgSet *
>(snsh);
4189 tmpWS.
saveSnapshot(snshSet->GetName(), *snshSet,
true);
4209 auto sanitizeIfNeeded = [](
auto const &list) {
4210 for (
auto *obj : list) {
4216 sanitizeIfNeeded(tmpWS.
allVars());
4218 sanitizeIfNeeded(tmpWS.
allPdfs());
4226 for (
auto *obj : *
data->get()) {
4233 for (
auto *obj : *
data->get()) {
4239 auto *snsh =
dynamic_cast<RooArgSet *
>(snshObj);
4241 std::cerr <<
"Warning: found snapshot that is not a RooArgSet, skipping\n";
4251 for (
auto *arg : *snsh) {
4261 if (
auto *named =
dynamic_cast<TNamed *
>(obj)) {
4262 named->SetName(
sanitizeName(named->GetName()).c_str());
4264 std::cerr <<
"Warning: object " << obj->GetName() <<
" is not TNamed, cannot rename.\n";
4275 for (
auto *obs : mc->GetObservables()->get()) {
4280 for (
auto *poi : mc->GetParametersOfInterest()->get()) {
4285 for (
auto *nuis : mc->GetNuisanceParameters()->get()) {
4290 for (
auto *glob : mc->GetGlobalObservables()->get()) {
4297 std::string wsName = std::string{ws.
GetName()} +
"_sanitized";
4299 newWS.
SetName(wsName.c_str());
void writeArrayDist(JSONNode &elem, std::string const &name, std::vector< RooAbsPdf const * > const &components, std::map< std::string, std::string > const &observableOf)
std::optional< ArrayComponentInfo > arrayComponentInfo(RooAbsPdf const &pdf, std::string const *observable)
ToNumberOutput toNumber(const std::string &str)
std::vector< std::vector< std::string > > selectionKeys(std::vector< RooCategory const * > const &columns)
void writeReference(JSONNode &node, RooAbsArg const &arg)
bool isHS3VersionBefore(std::string const &version, int major, int minor)
std::vector< RooCategory const * > selectionColumns(RooAbsCategory const &indexCat)
std::string selectionKeyToString(std::vector< std::string > const &key)
bool startsWith(std::string_view str, std::string_view prefix)
bool endsWith(std::string_view str, std::string_view suffix)
std::string selectionLabel(std::vector< std::string > const &key)
bool isLiteralConstVar(RooAbsArg const &arg)
void writeAxisBinning(JSONNode &node, const RooAbsBinning &binning)
constexpr const char * arrayDistTag
static unsigned int total
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 input
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 result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void 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 modifier
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
Option_t Option_t TPoint TPoint const char text
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
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
bool isConstant() const
Check if the "Constant" attribute is set.
virtual TObject * clone(const char *newname=nullptr) const =0
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
void SetName(const char *name) override
Set the name of the TNamed.
RooFit::OwningPtr< RooArgSet > getComponents() const
Create a RooArgSet with all components (branch nodes) of the expression tree headed by this object.
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.
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
Abstract base class for RooRealVar binning definitions.
Int_t numBins() const
Return number of bins.
virtual double binLow(Int_t bin) const =0
virtual bool isUniform() const
virtual double highBound() const =0
virtual double lowBound() const =0
virtual double binHigh(Int_t bin) const =0
Abstract base class for objects that represent a discrete value that can be set from the outside,...
A space to attach TBranches.
unsigned int getCurrentOrdinalNumber() const
Return ordinal number of the current state.
const std::map< std::string, value_type >::value_type & getOrdinal(unsigned int n) const
Return name and index of the nth defined state.
std::size_t size() const
Number of states defined.
Abstract container object that can hold multiple RooAbsArg objects.
bool equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically-named contents.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
const char * GetName() const override
Returns name of object.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
Storage_t::size_type size() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
void sort(bool reverse=false)
Sort collection using std::sort and name comparison.
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.
Abstract base class for objects that are lvalues, i.e.
virtual Int_t numBins(const char *rangeName=nullptr) const =0
Abstract interface for all probability density functions.
std::unique_ptr< RooArgSet > getAllConstraints(const RooArgSet &observables, RooArgSet &constrainedParams, bool stripDisconnected=true) const
This helper function finds and collects all constraints terms of all component p.d....
bool canBeExtended() const
If true, PDF can provide extended likelihood term.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
virtual Int_t getBins(const char *name=nullptr) const
Get number of bins of currently defined range.
void setConstant(bool value=true)
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
Abstract base class for objects that represent a real value and implements functionality common to al...
double 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.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
bool containsInstance(const RooAbsArg &var) const override
Check if this exact instance is in this collection.
Implements a RooAbsBinning in terms of an array of boundary values, posing no constraints on the choi...
Object to represent discrete states.
bool setIndex(Int_t index, bool printError=true) override
Set value by specifying the index code of the desired state.
bool defineType(const std::string &label)
Define a state with given name.
bool setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
Named container for two doubles, two integers two object points and three string pointers that can be...
const char * getString(Int_t idx) const
Return string stored in slot idx.
Represents a constant real-valued object.
RooCustomizer is a factory class to produce clones of a prototype composite PDF object with the same ...
Container class to hold N-dimensional binned data.
Container class to hold unbinned data.
bool is_container() const
void fill_seq(Collection const &coll)
JSONNode & append_child()
size_t num_children() const
JSONNode const * find(std::string const &key) const
bool has_child(std::string const &) const
Records which components of a JSON map are read while it is alive, through any node of the tree.
static std::unique_ptr< JSONTree > create()
An HS3 document. It is move-only, because generic objects refer to the JSON tree that the document wa...
std::vector< HS3::Analysis > analyses
std::vector< HS3::Data > data
std::vector< HS3::Likelihood > likelihoods
std::vector< HS3::Function > functions
std::vector< HS3::ParameterPoint > parameterPoints
HS3::RooFitInternal rooFit
std::vector< HS3::Domain > domains
std::vector< HS3::Distribution > distributions
A position in the JSON tree.
Where RooFit takes the ranges of variables from: the "default_domain" if there is one,...
DomainAxis const * find(std::string const &name) const
The axis that defines the range of a variable, or null.
bool contains(std::string const &name) const
Whether any domain has the variable.
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.
Efficient implementation of a product of PDFs of the form.
Binning/range definition that only defines a range but no binning.
Variable that can be changed from the outside.
void removeMin(const char *name=nullptr)
Remove lower range limit for binning with given name. Empty name means default range.
void setVal(double value) override
Set value of variable to 'value'.
void setError(double value)
void setMin(const char *name, double value, bool shared=true)
Set minimum of name range to given value.
void setRange(const char *name, double min, double max, bool shared=true)
Set a fit or plotting range.
void setBins(Int_t nBins, const char *name=nullptr, bool shared=true)
Create a uniform binning under name 'name' for this variable.
bool hasError(bool allowZero=true) const
void setBinning(const RooAbsBinning &binning, const char *name=nullptr, bool shared=true)
Add given binning under name 'name' with this variable.
void setMax(const char *name, double value, bool shared=true)
Set maximum of name range to given value.
void removeMax(const char *name=nullptr)
Remove upper range limit for binning with given name. Empty name means default range.
const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false, bool shared=true) const override
Return binning definition with name.
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
< A class that holds configuration information for a model using a workspace as a store
const std::string & GetSnapshotName() const
get the name of the workspace snapshot saved by SetSnapshot() (empty if there is none)
const RooArgSet * GetGlobalObservables() const
get RooArgSet for global observables (return nullptr if not existing)
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return nullptr if not existing)
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return nullptr if not existing)
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 nullptr if not existing)
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)
RooAbsPdf * GetPriorPdf() const
get parameters prior pdf (return nullptr if not existing)
Persistable container for RooFit projects.
TObject * obj(RooStringView name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
const RooArgSet * getSnapshot(const char *name) const
Return the RooArgSet containing a snapshot of variables contained in the workspace.
RooAbsPdf * pdf(RooStringView name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
RooCategory * cat(RooStringView name) const
Retrieve discrete variable (RooCategory) with given name. A null pointer is returned if not found.
RooArgSet allVars() const
Return set with all variable objects.
RooArgSet argSet(RooStringView nameList) const
Return set of RooAbsArgs matching to given list of names.
RooArgSet allResolutionModels() const
Return set with all resolution model objects.
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.
const RooArgSet & components() const
RooArgSet allFunctions() const
Return set with all function objects.
RooRealVar * var(RooStringView name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
RooAbsData * data(RooStringView name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
std::list< RooAbsData * > allEmbeddedData() const
Return list of all dataset in the workspace.
bool loadSnapshot(const char *name)
Load the values and attributes of the parameters in the snapshot saved with the given name.
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.
TClass instances represent classes, structs and namespaces in the ROOT type system.
The TNamed class is the base class for all named ROOT classes.
const char * GetName() const override
Returns name of object.
virtual void SetName(const char *name)
Set the name of the TNamed.
Mother of all ROOT objects.
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 flag=true)
RooConstVar & RooConst(double val)
RooCmdArg Silence(bool flag=true)
RooCmdArg Index(RooCategory &icat)
RooCmdArg StoreError(const RooArgSet &aset)
RooCmdArg WeightVar(const char *name="weight", bool reinterpretAsWeight=false)
RooCmdArg Import(const char *state, TH1 &histo)
CoordSystem::Scalar get(DisplacementVector2D< CoordSystem, Tag > const &p)
double dist(Rotation3D const &r1, Rotation3D const &r2)
double product(DoubleArray factors, std::size_t nFactors)
Types that represent an HS3 document.
std::variant< std::string, double > NameOrNumber
A name, or a number for a constant.
void buildHistFactoryDist(RooJSONFactoryWSTool &tool, std::string const &name, HistFactoryDist const &dist, std::vector< DistributionRef > const *channelConstraints=nullptr)
Create the RooFit objects of a HistFactory distribution in the workspace of the tool.
void checkDocument(HS3Document const &doc, Diagnostics &diagnostics, ValidateOptions const &options={})
The checks of validate(), for a document that is still needed if it doesn't pass them.
std::variant< RegularBinning, EdgesBinning > Binning
constexpr char const * defaultDomainName
The domain in which RooFit writes the ranges of all variables. It is a convention of RooFit,...
std::optional< ValidatedHS3Document > validate(HS3Document doc, Diagnostics &diagnostics, ValidateOptions const &options)
Checks what can be checked without knowing how the objects are built: unique names,...
void setExportedObject(RooJSONFactoryWSTool &tool, HistFactoryDist dist, std::vector< DistributionRef > channelConstraints)
Called by the exporter of a HistFactory distribution, which is then written by the tool.
void writeDocument(Detail::JSONNode &root, HS3Document const &doc)
Writes everything but the distributions and functions, which are written one by one while they are ex...
RooArgSet createObservables(std::vector< BinnedAxis > const &axes)
Create the variables for the axes of binned data.
void importHistFactoryNode(RooJSONFactoryWSTool &tool, Detail::JSONNode const &node, std::vector< DistributionRef > const *channelConstraints)
What the built-in importer does with a HistFactory distribution, plus the constraint terms of the cha...
bool hasErrors(Diagnostics const &diagnostics)
Whether there is a diagnostic with error severity.
void writeHistFactoryDist(Detail::JSONNode &node, HistFactoryDist const &dist)
Writes a HistFactory distribution, without its name.
std::vector< Diagnostic > Diagnostics
void report(Diagnostics const &diagnostics)
Forward the warnings to the message service, and throw if there are errors.
NameOrNumber toNameOrNumber(RooAbsArg const &arg)
The name of an object, or the value of a literal constant.
void upgradeDocument(Detail::JSONNode &root, Diagnostics &diagnostics, ParseOptions const &options={})
Rewrites everything that older versions of RooFit wrote in a way that is not part of the standard int...
BinnedAxis toBinnedAxis(RooRealVar const &var)
The axis of binned data for a variable.
std::unique_ptr< RooDataHist > createDataHist(std::string const &name, RooArgSet const &vars, std::vector< double > const &contents, std::vector< double > const *errors)
Create a RooDataHist with the contents and errors. If there are no errors, it doesn't store squared w...
bool isBuiltinHistFactoryImporter(JSONIO::Importer const &importer)
Whether this is the importer that RooFit registers for HistFactory distributions, as opposed to the o...
std::vector< BinnedAxis > parseBinnedAxes(Detail::JSONNode const &axes, Diagnostics &diagnostics)
Reads the axes of binned data that doesn't come with a document.
HS3Document parseDocument(Detail::JSONNode const &root, Diagnostics &diagnostics, ParseOptions const &options={})
Reads a document.
void initialize(typename Architecture_t::Matrix_t &A, EInitialization m)
std::optional< DistributionRef > prior
std::optional< ParameterPointRef > init
std::vector< DomainRef > domains
std::vector< ParameterRef > parametersOfInterest
std::vector< std::string > tags
std::map< std::string, std::string > dict
std::vector< std::string > categories
The sub-data set of a combined data set for one key, which has one label per column.
Data sets that are selected by a key (HS3 #119). The columns are categorical axes of the domains.
std::vector< CombinedDataComponent > components
std::vector< std::string > columns
std::vector< int > indices
std::vector< std::string > labels
std::vector< std::string > labels
std::vector< DistributionRef > distributions
std::vector< int > indices
The axis of point data or unbinned data, which can't have a binning.
std::optional< double > max
std::optional< double > min
std::variant< PointData, UnbinnedData, BinnedData, CombinedData > body
std::variant< GenericObject, HistFactoryDist > body
std::optional< double > min
std::optional< double > max
std::optional< Binning > binning
std::optional< double > fixedValue
std::vector< std::variant< DomainAxis, CategoricalAxis > > axes
std::vector< double > edges
A distribution or function that is not interpreted by the document, but by the importers that are reg...
DistributionRef distribution
std::variant< DataRef, double > data
std::vector< DistributionRef > auxDistributions
std::vector< LikelihoodTerm > terms
std::optional< std::string > pdfName
std::optional< std::vector< std::string > > observables
The observables of the ModelConfig, written if no data set of the likelihood gives them.
std::optional< std::string > mcName
std::optional< std::string > combinedDataName
std::vector< ParameterValue > parameters
std::optional< std::variant< double, std::string > > value
A string selects the state of a category.
Options for upgradeDocument() and parseDocument().
bool typedHistFactory
If false, HistFactory distributions stay generic objects, because a user registered their own importe...
std::map< std::string, Attributes > attributes
std::map< std::string, std::vector< DistributionRef > > channelConstraints
The constraint terms of HistFactory distributions that no modifier names, by distribution.
std::vector< StepWidth > stepWidths
std::map< std::string, ModelConfigInfo > modelConfigs
bool strict
Whether the document has to follow the current standard, or if older conventions of RooFit are tolera...
std::function< bool(std::string const &) isExternal)
Whether a name that is not defined in the document is known in some other way, e.g....