38struct InterpolationCodes {
44constexpr int kUnrepresentable = -1;
47constexpr InterpolationCodes interpolationTable[]{
57int codeForClass(InterpolationCodes
const &row, InterpolationClass interpolationClass)
74 for (
auto const &row : interpolationTable) {
75 const int rowCode = codeForClass(row, interpolationClass);
76 if (rowCode != kUnrepresentable && rowCode == code) {
77 return row.descriptor;
85 for (
auto const &row : interpolationTable) {
86 const int rowCode = codeForClass(row, interpolationClass);
87 if (rowCode != kUnrepresentable && row.descriptor == interpolation) {
96 return std::any_of(diagnostics.begin(), diagnostics.end(),
97 [](
Diagnostic const &
d) { return d.severity == Diagnostic::Severity::Error; });
100std::string Cursor::path()
const
113 out +=
"[" + std::to_string(
_index) +
"]";
115 out +=
"(" +
_node[
"name"].
val() +
")";
120void Cursor::error(std::string
const &
message)
const
125void Cursor::warning(std::string
const &
message)
const
130std::size_t Cursor::numErrors()
const
133 [](
Diagnostic const &
d) { return d.severity == Diagnostic::Severity::Error; });
144 _seen.emplace_back(key);
157 const std::string key =
child.key();
166 if (
c.node().is_container() ||
c.node().is_null()) {
167 c.error(
"must be a string");
170 out =
c.node().val();
175 if (!
c.node().is_number()) {
176 c.error(
"must be a number");
179 out =
c.node().val_double();
185 const double value =
c.node().is_number() ?
c.node().val_double() : 0.5;
186 if (
value != std::floor(
value) || std::abs(
value) >
static_cast<double>(std::numeric_limits<int>::max())) {
187 c.error(
"must be an integer");
190 out =
static_cast<int>(
value);
195 if (std::optional<bool>
value =
c.node().try_val_bool()) {
198 c.error(
"must be a boolean");
205 auto readNumber = [&](
int &number) {
206 const std::size_t begin = pos;
207 while (pos < version.size() && std::isdigit(
static_cast<unsigned char>(version[pos]))) {
211 if (pos == begin || pos - begin > 9) {
214 number = std::stoi(version.substr(begin, pos - begin));
218 if (!readNumber(parsed.
major) || pos >= version.size() || version[pos] !=
'.') {
222 if (!readNumber(parsed.
minor)) {
225 if (pos < version.size() && version[pos] ==
'.') {
227 if (!readNumber(parsed.
patch)) {
238void readBound(Reader &ar,
const char *key, std::optional<double> &out,
double valueIfNull)
243 Cursor c{ar.cursor().node()[key], ar.cursor(), key};
244 if (
c.node().is_null()) {
252constexpr double infinity = std::numeric_limits<double>::infinity();
255void readEdges(Reader &ar, std::string
const &axisName, std::vector<double> &edges)
257 Cursor c{ar.cursor().node()[
"edges"], ar.cursor(),
"edges"};
258 const std::string context =
"\"edges\" of axis '" + axisName +
"' must ";
259 if (!
c.node().is_seq()) {
260 c.error(context +
"be a list");
264 for (std::size_t i = 1; i < edges.size(); ++i) {
265 if (!(edges[i] > edges[i - 1])) {
266 c.error(context +
"be strictly ascending");
270 if (edges.size() < 2) {
271 c.error(context +
"contain at least two values");
280 ar(
"version",
p.version);
285 ar(
"name", axis.
name);
288 for (
const char *key : {
"min",
"max",
"nbins",
"edges",
"categories"}) {
291 "\", which exclude each other");
298 readBound(ar,
"min", axis.
min, -infinity);
299 readBound(ar,
"max", axis.
max, infinity);
300 if (ar.
has(
"edges")) {
303 ar(
"edges", binning.
edges);
304 if (!binning.
edges.empty()) {
312 axis.
binning = std::move(binning);
313 }
else if (ar.
has(
"nbins")) {
315 ar(
"nbins", binning.
nbins);
316 if (binning.
nbins != 0) {
324 ar(
"name", axis.
name);
325 readBound(ar,
"min", axis.
min, -infinity);
326 readBound(ar,
"max", axis.
max, infinity);
331 ar(
"name", axis.
name);
332 if (ar.
has(
"edges")) {
335 if (binning.
edges.size() >= 2) {
340 std::optional<double> min;
341 std::optional<double> max;
344 if ((min && *min != axis.
min) || (max && *max != axis.
max)) {
345 ar.
cursor().
error(
"\"min\" and \"max\" of axis '" + axis.
name +
"' must agree with the \"edges\"");
347 if (ar.
has(
"nbins")) {
348 ar.
cursor().
error(
"axis '" + axis.
name +
"' must not have both \"edges\" and \"nbins\"");
350 axis.
binning = std::move(binning);
356 ar(
"nbins", binning.
nbins);
363 ar(
"name", axis.
name);
364 for (
const char *key : {
"min",
"max",
"nbins",
"edges"}) {
366 ar.
cursor().
error(
"the axis '" + axis.
name +
"' is categorical and must not have \"" + key +
"\"");
369 ar.
has(
"categories");
372 ar.
cursor().
error(
"the axis '" + axis.
name +
"': \"categories\" must be a non-empty list of strings");
376 if (label.is_container() || label.is_null() || label.is_number() || label.val().empty()) {
377 ar.
cursor().
error(
"the axis '" + axis.
name +
"': the entries of \"categories\" must be non-empty strings");
381 ar.
cursor().
error(
"the axis '" + axis.
name +
"': the category \"" + label.val() +
"\" is listed twice");
391template <
class ContinuousAxis_t>
392void readAxis(
Cursor const &
c, std::variant<ContinuousAxis_t, CategoricalAxis> &out)
394 if (!
c.node().is_map()) {
395 c.error(
"must be a struct");
400 if (reader.has(
"categories") && !(std::is_same_v<ContinuousAxis_t, DomainAxis> && reader.has(
fixedValueKey))) {
401 CategoricalAxis axis;
403 out = std::move(axis);
405 ContinuousAxis_t axis;
407 out = std::move(axis);
430 ar(
"name", domain.
name);
432 if (ar.
has(
"type")) {
435 if (
type !=
"product_domain") {
436 ar.
cursor().
error(
"only domains of type \"product_domain\" are currently supported!");
444 if (!
c.node().is_map()) {
445 c.error(
"must be a struct");
450 if (ar.has(
"value")) {
451 Cursor crsr{ar.cursor().
node()[
"value"], ar.cursor(),
"value"};
452 if (crsr.node().is_number()) {
453 p.value = crsr.node().val_double();
457 p.value = std::move(label);
460 std::optional<bool> isConst;
461 ar(
"const", isConst);
462 p.isConst = isConst.value_or(
false);
464 ar(
"relErr",
p.relError);
465 ar(
"nbins",
p.nbins);
470 ar(
"name", point.
name);
476 ar(
"value",
data.value);
477 ar(
"uncertainty",
data.uncertainty);
484 ar(
"weights",
data.weights);
485 data.hasEntriesUncertainties = ar.
has(
"entries_uncertainties");
487 if (!ar.
has(
"entries")) {
488 ar.
cursor().
error(
"does not define the required component \"entries\"");
492 if (!entries.node().is_seq()) {
493 entries.
error(
"key 'entries' is not a list!");
496 if (
data.weights &&
data.weights->size() != entries.node().num_children()) {
497 ar.
cursor().
error(
"inconsistent number of entries and weights!");
500 data.entries.reserve(entries.node().num_children() *
data.axes.size());
501 std::size_t iRow = 0;
502 for (
JSONNode const &row : entries.node().children()) {
503 Cursor rowCursor{row, entries, iRow};
505 rowCursor.
error(
"coordinate point '" + std::to_string(iRow) +
"' is not a list!");
508 if (row.num_children() !=
data.axes.size()) {
509 rowCursor.error(
"inconsistent number of entries and observables!");
512 std::size_t iAxis = 0;
515 if (
auto const *category = std::get_if<CategoricalAxis>(&
data.axes[iAxis])) {
518 auto found = std::find(category->categories.begin(), category->categories.end(), label);
519 if (found == category->categories.end()) {
520 valueCursor.error(
"'" + label +
"' is not a category of the axis '" + category->name +
"'");
523 data.entries.push_back(
static_cast<double>(std::distance(category->categories.begin(), found)));
525 double coordinate = 0.0;
527 data.entries.push_back(coordinate);
537 if (ar.
has(
"type")) {
540 if (
type !=
"gaussian_uncertainty") {
544 ar(
"sigma", uncertainty.
sigma);
545 if (ar.
has(
"correlation")) {
548 if (
c.node().is_seq()) {
550 }
else if (!
c.node().is_number() ||
c.node().val_double() != 0.0) {
551 c.error(
"must be a matrix or 0");
559 ar(
"contents",
data.contents);
560 ar(
"uncertainty",
data.uncertainty);
562 if (ar.
has(
"errors")) {
564 if (!errors.node().is_seq()) {
565 errors.
error(
"errors are not in list form");
566 }
else if (!
data.uncertainty) {
567 data.uncertainty.emplace();
577 std::string
const context =
"the combined data set '" +
name +
"'";
579 if (ar.
has(
"axes")) {
580 c.
error(context +
" must not have \"axes\": its columns are declared by the domains");
583 auto nonEmptyList = [&](
const char *key) ->
JSONNode const * {
584 if (!ar.
has(key) || !
c.node()[key].is_seq() ||
c.node()[key].num_children() == 0) {
587 return &
c.node()[key];
589 JSONNode const *columns = nonEmptyList(
"columns");
590 for (std::size_t i = 0; columns && i < columns->
num_children(); ++i) {
596 data.columns.push_back(column.
val());
599 c.error(
"\"columns\" of " + context +
" must be a non-empty list of names of categorical axes");
602 JSONNode const *components = nonEmptyList(
"components");
604 c.error(
"\"components\" of " + context +
" must be a non-empty list");
608 if (!component.is_map() || !component.has_child(
"key") || !component.has_child(
"dataset")) {
609 c.error(
"every component of " + context +
" must have a \"key\" and a \"dataset\"");
612 JSONNode const &key = component[
"key"];
616 out.
key.push_back(label.is_container() ? std::string{} : label.val());
619 c.error(
"every component of " + context +
" must have a \"key\" with " + std::to_string(
data.columns.size()) +
620 " labels, one per column");
623 out.
data.
name = component[
"dataset"].val();
629 if (!
c.node().is_map()) {
630 c.error(
"must be a struct");
634 ar(
"name", out.
name);
637 if (
type ==
"binned") {
640 out.
body = std::move(body);
641 }
else if (
type ==
"unbinned") {
644 out.
body = std::move(body);
645 }
else if (
type ==
"point") {
648 out.
body = std::move(body);
649 }
else if (
type ==
"combined") {
652 out.
body = std::move(body);
653 }
else if (ar.has(
"type")) {
654 c.error(
"unknown type of dataset '" +
type +
"'");
660 ar(
"name", likelihood.
name);
663 std::vector<DistributionRef> distributions;
664 ar(
"distributions", distributions);
665 if (!ar.
has(
"data")) {
666 ar.
cursor().
error(
"does not define the required component \"data\"");
670 if (!
data.node().is_seq()) {
671 data.error(
"must be an array");
674 if (
data.node().num_children() != distributions.size()) {
675 ar.
cursor().
error(
"\"distributions\" and \"data\" must have the same length");
678 likelihood.
terms.reserve(distributions.size());
684 if (node.is_number() || (!node.is_container() && !node.is_null() && node.val() ==
"0")) {
685 term.
data = node.is_number() ? node.val_double() : 0.0;
689 term.
data = std::move(ref);
691 likelihood.
terms.push_back(std::move(term));
698 ar(
"name", analysis.
name);
702 auto isLegacy = [&](
const char *key,
const char *legacyKey) {
703 if (ar.
has(key) || !ar.
has(legacyKey)) {
706 ar.
cursor().
warning(std::string(
"the key \"") + legacyKey +
"\" of analysis '" + analysis.
name +
707 "' is deprecated, please use \"" + key +
"\" instead.");
710 ar.
list(isLegacy(
"parameters_of_interest",
"parameter_of_interest") ?
"parameter_of_interest"
711 :
"parameters_of_interest",
713 if (!isLegacy(
"domains",
"domain")) {
718 analysis.
domains.emplace_back();
719 ar(
"domain", analysis.
domains.back());
721 ar(
"init", analysis.
init);
722 ar(
"prior", analysis.
prior);
728std::optional<InterpolationType> interpolationTypeFromString(std::string
const &str)
738std::optional<InterpolationFunction> interpolationFunctionFromString(std::string
const &str)
781 c.error(
"must be a struct with components 'type', 'in', and 'out'");
784 for (
const char *component : {
"type",
"in",
"out"}) {
786 c.error(std::string(
"does not define the required '") + component +
"' component");
790 JSONNode const &typeNode = node[
"type"];
791 JSONNode const &inNode = node[
"in"];
792 JSONNode const &outNode = node[
"out"];
794 c.error(
"components 'type' and 'in' must be strings");
798 auto type = interpolationTypeFromString(typeNode.
val());
800 c.error(
"has unknown interpolation type '" + typeNode.
val() +
"'");
803 auto in = interpolationFunctionFromString(inNode.
val());
805 c.error(
"has unknown interpolation function '" + inNode.
val() +
"'");
814 c.error(
"component 'out' must be a string or null");
817 out.
out = interpolationFunctionFromString(outNode.
val());
819 c.error(
"has unknown extrapolation function '" + outNode.
val() +
"'");
824 for (
const char *component : {
"type",
"in",
"out"}) {
825 reader.
has(component);
834std::optional<ConstraintType> readConstraintType(
Cursor const &
c)
843 c.error(
"unknown constraint type '" +
value +
"', supported are \"Gauss\", \"Poisson\" and \"LogNormal\"");
847void readConstraint(Reader &ar,
Constraint &out)
849 if (ar.has(
"constraints")) {
850 Cursor c{ar.cursor().node()[
"constraints"], ar.cursor(),
"constraints"};
851 if (!
c.node().is_seq() ||
c.node().num_children() != 1) {
852 c.error(
"must be an array with one entry");
857 out = Unconstrained{};
862 out = std::move(pdf);
863 }
else if (ar.has(
"constraint_name")) {
865 ar(
"constraint_name", pdf.pdf);
866 pdf.legacyName =
true;
867 out = std::move(pdf);
868 }
else if (ar.has(
"constraint")) {
869 if (
auto type = readConstraintType(
Cursor{ar.cursor().node()[
"constraint"], ar.cursor(),
"constraint"})) {
877 if (ar.has(
"constraints")) {
878 GammaConstraintPdfs constraints;
879 Cursor c{ar.cursor().node()[
"constraints"], ar.cursor(),
"constraints"};
880 if (!
c.node().is_seq()) {
881 c.error(
"must be an array");
885 for (
JSONNode const &item :
c.node().children()) {
886 constraints.pdfs.emplace_back();
888 constraints.pdfs.back().emplace();
893 out = std::move(constraints);
894 }
else if (ar.has(
"constraint")) {
895 Cursor c{ar.cursor().node()[
"constraint"], ar.cursor(),
"constraint"};
897 if (!
c.node().is_container() && !
c.node().is_null() &&
c.node().val() ==
"Const") {
898 out = ConstantGammas{};
899 }
else if (
auto type = readConstraintType(
c)) {
910 std::optional<std::string> optionalName;
911 ar(
"name", optionalName);
912 name = optionalName.value_or(
"");
918 if (!ar.
has(
"parameters")) {
919 ar(
"parameter", parameter);
923 if (!
c.node().is_seq() ||
c.node().num_children() != 1) {
924 c.
error(
"must be an array with one entry");
934 readConstraint(ar,
m.constraint);
945 readConstraint(ar,
m.constraint);
946 ar(
"interpolation",
m.interpolation);
952 ar(
"errors", variation.
errors);
963 readConstraint(ar,
m.constraint);
964 ar(
"interpolation",
m.interpolation);
970 if (ar.
has(
"parameter")) {
972 ar(
"parameter",
m.name);
974 ar.
list(
"parameters",
m.parameters);
975 if (ar.
has(
"data")) {
978 readGammaConstraint(ar,
m.constraint);
984 ar.
list(
"parameters",
m.parameters);
985 readGammaConstraint(ar,
m.constraint);
995 if (!
c.node().is_map()) {
996 c.error(
"must be a struct");
1006 if (
type ==
"normfactor") {
1008 }
else if (
type ==
"normsys") {
1010 }
else if (
type ==
"histosys") {
1012 }
else if (
type ==
"shapesys" ||
type ==
"shapefactor") {
1014 }
else if (
type ==
"staterror") {
1016 }
else if (
type ==
"custom") {
1018 }
else if (ar.has(
"type")) {
1020 if (ar.has(
"name")) {
1023 c.error(
"modifier '" +
name +
"' of unknown type '" +
type +
"'");
1029 ar(
"name", sample.
name);
1039 std::optional<double> relThreshold;
1040 ar(
"relThreshold", relThreshold);
1044 std::optional<bool> impliedPoissonErrors;
1045 ar(
"implied_poisson_errors", impliedPoissonErrors);
1053 if (axis.is_map() && axis.has_child(
"categories")) {
1054 ar.
cursor().
error(
"the axis '" + (axis.has_child(
"name") ? axis[
"name"].val() : std::string{}) +
1055 "' is categorical, but the axes of a HistFactory prediction are binned");
1060 ar(
"axes", dist.axes);
1061 ar(
"default_interpolation", dist.defaultInterpolation);
1062 ar(
"samples", dist.samples);
1063 if (ar.
has(
"staterror")) {
1070void readDistribution(
Cursor const &
c, Distribution &out, ParseOptions
const &options)
1072 if (!
c.node().is_map()) {
1073 c.error(
"must be a struct");
1077 ar(
"name", out.name);
1080 if (options.typedHistFactory &&
type ==
"histfactory_dist") {
1081 HistFactoryDist body;
1083 out.body = std::move(body);
1085 out.body = GenericObject{
type, &
c.node()};
1088 ar.has(
child.key().c_str());
1097 if (!
c.node().is_map()) {
1098 c.error(
"must be a struct");
1102 ar(
"name", out.
name);
1107 ar.has(
child.key().c_str());
1113 if (ar.
has(
"dict")) {
1115 if (!dict.node().is_map()) {
1116 dict.
error(
"must be a struct");
1119 for (
JSONNode const &item : dict.node().children()) {
1124 if (ar.
has(
"is_const_var")) {
1126 ar(
"is_const_var", isConstVar);
1134 ar(
"labels", info.
labels);
1138 ar.
cursor().
error(
"mismatch in number of labels, indices and distributions!");
1145 ar(
"labels", info.
labels);
1148 ar.
cursor().
error(
"mismatch in number of indices and labels!");
1154 ar(
"mcName", info.
mcName);
1162template <
class Map_t>
1163void readMap(Reader &ar,
const char *key, Map_t &out)
1168 Cursor c{ar.cursor().node()[key], ar.cursor(), key};
1169 if (
c.node().is_null()) {
1172 if (!
c.node().is_map()) {
1173 c.error(
"must be a struct");
1176 for (
JSONNode const &item :
c.node().children()) {
1177 const std::string itemKey = item.
key();
1184void readStepWidths(
Cursor const &misc, std::vector<StepWidth> &out)
1186 JSONNode const *node = misc.node().find(
"minimization",
"parameter_stepwidths");
1191 misc.warning(
"minimization.parameter_stepwidths is not a sequence, skipping.");
1194 for (
JSONNode const &item : node->children()) {
1196 !item[
"step_width"].is_number() || item[
"name"].is_container() || item[
"name"].is_null()) {
1197 misc.warning(
"skipping malformed parameter_stepwidths entry.");
1200 out.push_back({item[
"name"].
val(), item[
"step_width"].val_double()});
1204void readMisc(
Cursor const &root, RooFitInternal &out)
1206 if (!root.node().has_child(
"misc")) {
1209 Cursor misc{root.node()[
"misc"], root,
"misc"};
1210 if (!misc.node().is_map()) {
1213 readStepWidths(misc, out.stepWidths);
1214 if (!misc.node().has_child(
"ROOT_internal")) {
1217 Cursor internal{misc.node()[
"ROOT_internal"], misc,
"ROOT_internal"};
1218 if (!internal.node().is_map()) {
1221 Reader ar{internal};
1222 readMap(ar,
"attributes", out.attributes);
1223 readMap(ar,
"combined_distributions", out.combinedDistributions);
1224 readMap(ar,
"combined_datasets", out.combinedDatasets);
1225 readMap(ar,
"ModelConfigs", out.modelConfigs);
1226 readMap(ar,
"histfactory_constraints", out.channelConstraints);
1227 readMap(ar,
"bookkeeping_columns", out.bookkeepingColumns);
1230void readMetadata(
Cursor const &root, Metadata &out, ParseOptions
const &options)
1232 JSONNode const *metadata = root.node().find(
"metadata");
1233 JSONNode const *versionNode = metadata ? metadata->
find(
"hs3_version") :
nullptr;
1235 if (options.requireMetadata) {
1236 std::stringstream ss;
1237 ss <<
"The HS3 version is missing in the JSON!\n"
1238 <<
"Please include the HS3 version in the metadata field, e.g.:\n"
1239 <<
" \"metadata\" :\n"
1243 root.error(ss.str());
1247 Cursor metadataCursor{*metadata, root,
"metadata"};
1248 Cursor versionCursor{*versionNode, metadataCursor,
"hs3_version"};
1250 versionCursor.error(std::string(
"The HS3 version in the metadata must be a string, e.g. \"") +
supportedVersion +
1254 out.hs3Version = versionNode->
val();
1259 versionCursor.warning(
"cannot parse hs3_version '" + out.hs3Version +
1260 "', expected a string of the form \"MAJOR.MINOR\".");
1261 }
else if (supported < Version{out.version.major, out.version.minor}) {
1262 versionCursor.warning(
"the document has hs3_version '" + out.hs3Version +
1263 "', which is newer than the version supported by this RooFit ('" +
supportedVersion +
1264 "'). Some content might not be imported correctly.");
1267 Reader ar{metadataCursor};
1268 ar.has(
"hs3_version");
1269 ar.list(
"packages", out.packages);
1270 ar.list(
"authors", out.authors);
1271 ar.list(
"publications", out.publications);
1272 ar(
"description", out.description);
1289 if (ar.has(
"distributions") && !root[
"distributions"].
is_null()) {
1290 Cursor distributions{root[
"distributions"],
cursor,
"distributions"};
1291 if (!distributions.node().is_seq()) {
1292 distributions.error(
"must be an array");
1295 doc.
distributions.reserve(distributions.node().num_children());
1296 for (
JSONNode const &item : distributions.node().children()) {
1304 ar.list(
"data", doc.
data);
1306 ar.list(
"domains", doc.
domains);
1317 if (!distribution.
is_map()) {
1318 cursor.error(
"must be a struct");
1330 if (
c.node().is_number()) {
1331 out =
c.node().val_double();
1341 c.error(
"must be a structured interpolation or a legacy integer code");
1342 return std::nullopt;
1344 const std::string
value = node.
val();
1348 c.error(
"has invalid legacy interpolation code '" +
value +
"'");
1349 return std::nullopt;
1352 if (!interpolation) {
1353 c.error(std::string(
"has unsupported ") +
1357 return interpolation;
1364void readInterpolations(Reader &ar, std::size_t nParameters, InterpolationClass interpolationClass,
1365 std::vector<Interpolation> &out)
1368 if (ar.has(
"interpolations")) {
1369 Cursor c{ar.cursor().node()[
"interpolations"], ar.cursor(),
"interpolations"};
1370 const std::size_t errorsBefore =
c.numErrors();
1371 std::vector<Interpolation> interpolations;
1373 const std::size_t
size = interpolations.size();
1374 if (
c.numErrors() != errorsBefore) {
1377 if (nParameters == 0 ?
size != 0 :
size != 1 &&
size != nParameters) {
1378 c.error(
"component 'interpolations' must contain either one descriptor or one descriptor per parameter (got " +
1379 std::to_string(
size) +
" for " + std::to_string(nParameters) +
" parameters)");
1380 }
else if (
size == 1) {
1381 out.assign(nParameters, interpolations.front());
1383 out = std::move(interpolations);
1387 if (!ar.has(
"interpolationCodes")) {
1390 Cursor c{ar.cursor().node()[
"interpolationCodes"], ar.cursor(),
"interpolationCodes"};
1391 if (!
c.node().is_seq() ||
c.node().num_children() != nParameters) {
1392 c.error(
"legacy component 'interpolationCodes' must contain one code per parameter (got " +
1393 std::to_string(
c.node().is_seq() ?
c.node().num_children() : 0) +
" for " + std::to_string(nParameters) +
1400 out[i] = *interpolation;
1407template <
class Function_t,
class Fn>
1408Function_t parseInterpolated(
JSONNode const &node,
Diagnostics &diagnostics, InterpolationClass interpolationClass,
1414 cursor.error(
"must be a struct");
1417 const std::size_t errorsBefore =
cursor.numErrors();
1421 ar(
"nom", out.nominal);
1422 ar(
"vars", out.parameters);
1423 ar(
"high", out.high);
1425 readOthers(ar, out);
1426 if (
cursor.numErrors() == errorsBefore &&
1427 (out.high.size() != out.parameters.size() || out.low.size() != out.parameters.size())) {
1428 cursor.error(
"has non-matching lengths of 'vars', 'high' and 'low'");
1430 readInterpolations(ar, out.parameters.size(), interpolationClass, out.interpolations);
1438 std::vector<BinnedAxis> out;
1445 return parseInterpolated<InterpolatedFunction>(
constexpr const char * fixedValueKey
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t cursor
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 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
bool is_container() const
size_t num_children() const
JSONNode const * find(std::string const &key) const
bool has_child(std::string const &) const
JSONNode & child(size_t pos)
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.
std::size_t numErrors() const
void warning(std::string const &message) const
Detail::JSONNode const & node() const
Diagnostics & _diagnostics
Detail::JSONNode const & _node
void error(std::string const &message) const
Reads the components of a struct.
~Reader()
Reports the components that were not read, unless reading the struct gave an error.
Reader(Cursor const &cursor)
bool has(const char *key)
Whether the struct has a component. Checking for a component counts as reading it.
std::vector< std::string > _seen
void nested(const char *key, Fn &&fn)
Read the components of a struct that is nested in a component.
std::size_t _nErrorsBefore
Cursor const & cursor() const
void list(const char *key, std::vector< T > &field)
Read an array that can be omitted, which is equivalent to an empty one.
Types that represent an HS3 document.
std::variant< std::string, double > NameOrNumber
A name, or a number for a constant.
HistFactoryDist parseHistFactoryDist(Detail::JSONNode const &distribution, Diagnostics &diagnostics)
Reads a HistFactory distribution that doesn't come with a document.
std::variant< NormFactor, NormSys, HistoSys, ShapeSys, StatError, CustomModifier > Modifier
constexpr auto supportedVersion
InterpolationClass
The RooFit classes that implement the interpolations, which encode them with integer codes.
constexpr Interpolation multiplicativePolynomialExponential
void readValue(Cursor const &c, std::string &out)
constexpr Interpolation additivePolynomialLinear
void readModifierName(Reader &ar, std::string &name)
void readParameter(Reader &ar, ParameterRef ¶meter)
void describe(Reader &ar, Package &p)
ConstraintType
The constraint types that older documents named, for which RooFit creates the constraint terms.
std::optional< Interpolation > interpolationFromCode(int code, InterpolationClass interpolationClass)
The interpolation for an integer code, or nothing if the class doesn't support the code.
char const * toString(InterpolationType type)
InterpolatedNumber parseInterpolatedNumber(Detail::JSONNode const &node, Diagnostics &diagnostics)
std::optional< Interpolation > readInterpolationCode(Cursor const &c, InterpolationClass interpolationClass)
Reads an integer interpolation code, as older versions of RooFit wrote them.
InterpolatedFunction parseInterpolatedFunction(Detail::JSONNode const &node, Diagnostics &diagnostics)
Reads the functions "interpolation" and "interpolation0d", which don't come with a document.
std::optional< int > codeFromInterpolation(Interpolation const &interpolation, InterpolationClass interpolationClass)
The integer code of an interpolation, or nothing if the class can't represent the interpolation.
constexpr Interpolation multiplicativePolynomialLinear
bool hasErrors(Diagnostics const &diagnostics)
Whether there is a diagnostic with error severity.
constexpr Interpolation multiplicativePiecewiseExponential
std::vector< Diagnostic > Diagnostics
std::variant< Unconstrained, ConstraintType, ConstantGammas, GammaConstraintPdfs > GammaConstraint
bool parseVersion(std::string const &version, Version &out)
Reads the leading "MAJOR.MINOR" and the optional ".PATCH" of an HS3 version string.
void readCombinedData(Reader &ar, std::string const &name, CombinedData &data)
std::variant< Unconstrained, ConstraintType, ConstraintPdf > Constraint
std::vector< BinnedAxis > parseBinnedAxes(Detail::JSONNode const &axes, Diagnostics &diagnostics)
Reads the axes of binned data that doesn't come with a document.
constexpr Interpolation additiveQuadraticLinear
constexpr Interpolation additivePiecewiseLinear
HS3Document parseDocument(Detail::JSONNode const &root, Diagnostics &diagnostics, ParseOptions const &options={})
Reads a document.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
std::optional< DistributionRef > prior
std::optional< ParameterPointRef > init
std::vector< DomainRef > domains
std::vector< ParameterRef > parametersOfInterest
bool isConstVar
How ROOT versions before HS3 0.3 marked named RooConstVars.
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.
std::vector< std::string > key
Data sets that are selected by a key (HS3 #119). The columns are categorical axes of the domains.
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
Multiplies the sample with a function of the document.
std::variant< PointData, UnbinnedData, BinnedData, CombinedData > 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
std::vector< std::vector< double > > correlation
Empty if there is no correlation.
std::vector< double > sigma
Detail::JSONNode const * node
std::vector< double > contents
std::optional< std::vector< double > > errors
Not in the standard, but older versions of RooFit read them.
The function "interpolation" of RooFit, implemented by PiecewiseInterpolation: a nominal function plu...
The function "interpolation0d" of RooFit, implemented by FlexibleInterpVar: a nominal value plus the ...
How a modifier of a HistFactory distribution interpolates and extrapolates its effect.
std::optional< InterpolationFunction > out
If not set, the function inside the bounds is used outside as well.
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
Options for upgradeDocument() and parseDocument().
std::vector< double > contents
std::optional< std::vector< double > > errors
std::vector< Modifier > modifiers
Scales each bin by its own parameter. The modifier type "shapesys" is a deprecated alias of "shapefac...
Settings of the staterror modifiers that apply to the whole channel. This is a RooFit extension.
bool impliedPoissonErrors
Samples without "errors" have Poisson uncertainties, as in documents before HS3 0....
GammaConstraint constraint
Scales each bin by a parameter, that is constrained by the statistical uncertainty of all samples tha...