Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
HS3Parser.cxx
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Jonas Rembser, CERN, Nov 2026
5 *
6 * Copyright (c) 2026, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13#include "HS3Schema.h"
14#include "JSONIOUtils.h"
15
16#include <algorithm>
17#include <cctype>
18#include <charconv>
19#include <cmath>
20#include <limits>
21#include <exception>
22#include <sstream>
23
25
26namespace RooFit {
27namespace HS3 {
28
29constexpr auto supportedVersion = "0.3";
30
31namespace {
32
33// Single source of truth for the mapping between the structured HS3 interpolation
34// descriptors and the RooFit integer codes of PiecewiseInterpolation and
35// FlexibleInterpVar. A code of `kUnrepresentable` means the descriptor cannot be
36// expressed by that class: FlexibleInterpVar internally remaps code 4 to code 5,
37// so it has no additive-linear or multiplicative-linear poly6 variant.
38struct InterpolationCodes {
39 Interpolation descriptor;
42};
43
44constexpr int kUnrepresentable = -1;
45
46// clang-format off
47constexpr InterpolationCodes interpolationTable[]{
51 {additivePolynomialLinear, 4, kUnrepresentable},
53 {multiplicativePolynomialLinear, 6, kUnrepresentable},
54};
55// clang-format on
56
57int codeForClass(InterpolationCodes const &row, InterpolationClass interpolationClass)
58{
59 return interpolationClass == InterpolationClass::Piecewise ? row.piecewise : row.flexible;
60}
61
62} // namespace
63
64std::optional<Interpolation> interpolationFromCode(int code, InterpolationClass interpolationClass)
65{
66 // Code 3 was historically an unimplemented alias of code 2 for both classes,
67 // and FlexibleInterpVar treats code 5 identically to its canonical code 4.
68 if (code == 3) {
69 code = 2;
70 }
71 if (interpolationClass == InterpolationClass::Flexible && code == 5) {
72 code = 4;
73 }
74 for (auto const &row : interpolationTable) {
75 const int rowCode = codeForClass(row, interpolationClass);
76 if (rowCode != kUnrepresentable && rowCode == code) {
77 return row.descriptor;
78 }
79 }
80 return std::nullopt;
81}
82
83std::optional<int> codeFromInterpolation(Interpolation const &interpolation, InterpolationClass interpolationClass)
84{
85 for (auto const &row : interpolationTable) {
86 const int rowCode = codeForClass(row, interpolationClass);
87 if (rowCode != kUnrepresentable && row.descriptor == interpolation) {
88 return rowCode;
89 }
90 }
91 return std::nullopt;
92}
93
94bool hasErrors(Diagnostics const &diagnostics)
95{
96 return std::any_of(diagnostics.begin(), diagnostics.end(),
97 [](Diagnostic const &d) { return d.severity == Diagnostic::Severity::Error; });
98}
99
100std::string Cursor::path() const
101{
102 if (!_parent) {
103 return "";
104 }
105 std::string out = _parent->path();
106 if (_key) {
107 if (!out.empty()) {
108 out += ".";
109 }
110 out += _key;
111 return out;
112 }
113 out += "[" + std::to_string(_index) + "]";
114 if (_node.is_map() && _node.has_child("name") && !_node["name"].is_container() && !_node["name"].is_null()) {
115 out += "(" + _node["name"].val() + ")";
116 }
117 return out;
118}
119
120void Cursor::error(std::string const &message) const
121{
123}
124
125void Cursor::warning(std::string const &message) const
126{
128}
129
130std::size_t Cursor::numErrors() const
131{
132 return std::count_if(_diagnostics.begin(), _diagnostics.end(),
133 [](Diagnostic const &d) { return d.severity == Diagnostic::Severity::Error; });
134}
135
136Reader::Reader(Cursor const &cursor) : _cursor{cursor}, _nErrorsBefore{cursor.numErrors()} {}
137
138bool Reader::has(const char *key)
139{
140 if (!_cursor.node().has_child(key)) {
141 return false;
142 }
143 if (std::find(_seen.begin(), _seen.end(), key) == _seen.end()) {
144 _seen.emplace_back(key);
145 }
146 return true;
147}
148
150{
151 JSONNode const &node = _cursor.node();
152 // There is nothing to report if all components were read, and after an error it would only be noise.
153 if (!node.is_map() || node.num_children() == _seen.size() || _cursor.numErrors() != _nErrorsBefore) {
154 return;
155 }
156 for (JSONNode const &child : node.children()) {
157 const std::string key = child.key();
158 if (std::find(_seen.begin(), _seen.end(), key) == _seen.end()) {
159 _cursor.warning("unknown component \"" + key + "\" is ignored");
160 }
161 }
162}
163
164void readValue(Cursor const &c, std::string &out)
165{
166 if (c.node().is_container() || c.node().is_null()) {
167 c.error("must be a string");
168 return;
169 }
170 out = c.node().val();
171}
172
173void readValue(Cursor const &c, double &out)
174{
175 if (!c.node().is_number()) {
176 c.error("must be a number");
177 return;
178 }
179 out = c.node().val_double();
180}
181
182void readValue(Cursor const &c, int &out)
183{
184 // Read through double, such that an integer that is encoded as a JSON float like 1e6 is accepted.
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");
188 return;
189 }
190 out = static_cast<int>(value);
191}
192
193void readValue(Cursor const &c, bool &out)
194{
195 if (std::optional<bool> value = c.node().try_val_bool()) {
196 out = *value;
197 } else {
198 c.error("must be a boolean");
199 }
200}
201
202bool parseVersion(std::string const &version, Version &out)
203{
204 std::size_t pos = 0;
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]))) {
208 ++pos;
209 }
210 // Reject empty and absurdly long numbers, which std::stoi could not represent.
211 if (pos == begin || pos - begin > 9) {
212 return false;
213 }
214 number = std::stoi(version.substr(begin, pos - begin));
215 return true;
216 };
217 Version parsed;
218 if (!readNumber(parsed.major) || pos >= version.size() || version[pos] != '.') {
219 return false;
220 }
221 ++pos;
222 if (!readNumber(parsed.minor)) {
223 return false;
224 }
225 if (pos < version.size() && version[pos] == '.') {
226 ++pos;
227 if (!readNumber(parsed.patch)) {
228 parsed.patch = 0;
229 }
230 }
231 out = parsed;
232 return true;
233}
234
235namespace {
236
237// Read a bound of an axis. Infinite bounds are written as null.
238void readBound(Reader &ar, const char *key, std::optional<double> &out, double valueIfNull)
239{
240 if (!ar.has(key)) {
241 return;
242 }
243 Cursor c{ar.cursor().node()[key], ar.cursor(), key};
244 if (c.node().is_null()) {
245 out = valueIfNull;
246 return;
247 }
248 out.emplace();
249 readValue(c, *out);
250}
251
252constexpr double infinity = std::numeric_limits<double>::infinity();
253
254// Read bin edges, which must be at least two strictly ascending numbers.
255void readEdges(Reader &ar, std::string const &axisName, std::vector<double> &edges)
256{
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");
261 return;
262 }
263 readValue(c, edges);
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");
267 return;
268 }
269 }
270 if (edges.size() < 2) {
271 c.error(context + "contain at least two values");
272 }
273}
274
275} // namespace
276
278{
279 ar("name", p.name);
280 ar("version", p.version);
281}
282
283void describe(Reader &ar, DomainAxis &axis)
284{
285 ar("name", axis.name);
286 if (ar.has(fixedValueKey)) {
287 // The domain of the parameter is the set with this single value: no range, binning or categories.
288 for (const char *key : {"min", "max", "nbins", "edges", "categories"}) {
289 if (ar.has(key)) {
290 ar.cursor().error("the axis '" + axis.name + "' has \"" + fixedValueKey + "\" and \"" + key +
291 "\", which exclude each other");
292 }
293 }
294 // Not read as an optional component, for which null would be the same as leaving it out.
295 ar(fixedValueKey, axis.fixedValue.emplace());
296 return;
297 }
298 readBound(ar, "min", axis.min, -infinity);
299 readBound(ar, "max", axis.max, infinity);
300 if (ar.has("edges")) {
301 // Not necessarily ascending, because RooFit also writes parameterized ranges as edges.
302 EdgesBinning binning;
303 ar("edges", binning.edges);
304 if (!binning.edges.empty()) {
305 if (!axis.min) {
306 axis.min = binning.edges.front();
307 }
308 if (!axis.max) {
309 axis.max = binning.edges.back();
310 }
311 }
312 axis.binning = std::move(binning);
313 } else if (ar.has("nbins")) {
314 RegularBinning binning;
315 ar("nbins", binning.nbins);
316 if (binning.nbins != 0) {
317 axis.binning = binning;
318 }
319 }
320}
321
323{
324 ar("name", axis.name);
325 readBound(ar, "min", axis.min, -infinity);
326 readBound(ar, "max", axis.max, infinity);
327}
328
329void describe(Reader &ar, BinnedAxis &axis)
330{
331 ar("name", axis.name);
332 if (ar.has("edges")) {
333 EdgesBinning binning;
334 readEdges(ar, axis.name, binning.edges);
335 if (binning.edges.size() >= 2) {
336 axis.min = binning.edges.front();
337 axis.max = binning.edges.back();
338 }
339 // The standard requires "min" and "max" also for irregular binnings, which older versions of RooFit didn't write.
340 std::optional<double> min;
341 std::optional<double> max;
342 ar("min", min);
343 ar("max", 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\"");
346 }
347 if (ar.has("nbins")) {
348 ar.cursor().error("axis '" + axis.name + "' must not have both \"edges\" and \"nbins\"");
349 }
350 axis.binning = std::move(binning);
351 return;
352 }
353 ar("min", axis.min);
354 ar("max", axis.max);
355 RegularBinning binning;
356 ar("nbins", binning.nbins);
357 axis.binning = binning;
358}
359
360// A categorical axis (HS3 #108) has unique non-empty labels, and no range or binning.
362{
363 ar("name", axis.name);
364 for (const char *key : {"min", "max", "nbins", "edges"}) {
365 if (ar.has(key)) {
366 ar.cursor().error("the axis '" + axis.name + "' is categorical and must not have \"" + key + "\"");
367 }
368 }
369 ar.has("categories");
370 JSONNode const &labels = ar.cursor().node()["categories"];
371 if (!labels.is_seq() || labels.num_children() == 0) {
372 ar.cursor().error("the axis '" + axis.name + "': \"categories\" must be a non-empty list of strings");
373 return;
374 }
375 for (JSONNode const &label : labels.children()) {
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");
378 return;
379 }
380 if (std::find(axis.categories.begin(), axis.categories.end(), label.val()) != axis.categories.end()) {
381 ar.cursor().error("the axis '" + axis.name + "': the category \"" + label.val() + "\" is listed twice");
382 return;
383 }
384 axis.categories.push_back(label.val());
385 }
386}
387
388namespace {
389
390// The kind of an axis is determined by its components.
391template <class ContinuousAxis_t>
392void readAxis(Cursor const &c, std::variant<ContinuousAxis_t, CategoricalAxis> &out)
393{
394 if (!c.node().is_map()) {
395 c.error("must be a struct");
396 return;
397 }
398 Reader reader{c};
399 // A fixed axis is not categorical. That it has no categories is checked when it is read.
400 if (reader.has("categories") && !(std::is_same_v<ContinuousAxis_t, DomainAxis> && reader.has(fixedValueKey))) {
401 CategoricalAxis axis;
402 describe(reader, axis);
403 out = std::move(axis);
404 } else {
405 ContinuousAxis_t axis;
406 describe(reader, axis);
407 out = std::move(axis);
408 }
409}
410
411} // namespace
412
413void readValue(Cursor const &c, std::variant<DomainAxis, CategoricalAxis> &out)
414{
415 readAxis(c, out);
416}
417
418void readValue(Cursor const &c, std::variant<ContinuousAxis, CategoricalAxis> &out)
419{
420 readAxis(c, out);
421}
422
423void readValue(Cursor const &c, std::variant<BinnedAxis, CategoricalAxis> &out)
424{
425 readAxis(c, out);
426}
427
428void describe(Reader &ar, Domain &domain)
429{
430 ar("name", domain.name);
431 std::string type;
432 if (ar.has("type")) {
433 ar("type", type);
434 }
435 if (type != "product_domain") {
436 ar.cursor().error("only domains of type \"product_domain\" are currently supported!");
437 return;
438 }
439 ar.list("axes", domain.axes);
440}
441
443{
444 if (!c.node().is_map()) {
445 c.error("must be a struct");
446 return;
447 }
448 Reader ar{c};
449 ar("name", p.name);
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();
454 } else {
455 std::string label;
456 readValue(crsr, label);
457 p.value = std::move(label);
458 }
459 }
460 std::optional<bool> isConst;
461 ar("const", isConst);
462 p.isConst = isConst.value_or(false);
463 ar("err", p.error);
464 ar("relErr", p.relError);
465 ar("nbins", p.nbins);
466}
467
469{
470 ar("name", point.name);
471 ar.list("parameters", point.parameters);
472}
473
475{
476 ar("value", data.value);
477 ar("uncertainty", data.uncertainty);
478 ar.list("axes", data.axes);
479}
480
482{
483 ar.list("axes", data.axes);
484 ar("weights", data.weights);
485 data.hasEntriesUncertainties = ar.has("entries_uncertainties");
486
487 if (!ar.has("entries")) {
488 ar.cursor().error("does not define the required component \"entries\"");
489 return;
490 }
491 Cursor entries{ar.cursor().node()["entries"], ar.cursor(), "entries"};
492 if (!entries.node().is_seq()) {
493 entries.error("key 'entries' is not a list!");
494 return;
495 }
496 if (data.weights && data.weights->size() != entries.node().num_children()) {
497 ar.cursor().error("inconsistent number of entries and weights!");
498 return;
499 }
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};
504 if (!row.is_seq()) {
505 rowCursor.error("coordinate point '" + std::to_string(iRow) + "' is not a list!");
506 return;
507 }
508 if (row.num_children() != data.axes.size()) {
509 rowCursor.error("inconsistent number of entries and observables!");
510 return;
511 }
512 std::size_t iAxis = 0;
513 for (JSONNode const &value : row.children()) {
514 Cursor valueCursor{value, rowCursor, iAxis};
515 if (auto const *category = std::get_if<CategoricalAxis>(&data.axes[iAxis])) {
516 std::string label;
517 readValue(valueCursor, label);
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 + "'");
521 return;
522 }
523 data.entries.push_back(static_cast<double>(std::distance(category->categories.begin(), found)));
524 } else {
525 double coordinate = 0.0;
526 readValue(valueCursor, coordinate);
527 data.entries.push_back(coordinate);
528 }
529 ++iAxis;
530 }
531 ++iRow;
532 }
533}
534
535void describe(Reader &ar, GaussianUncertainty &uncertainty)
536{
537 if (ar.has("type")) {
538 std::string type;
539 ar("type", type);
540 if (type != "gaussian_uncertainty") {
541 ar.cursor().error("unsupported type of uncertainty '" + type + "'");
542 }
543 }
544 ar("sigma", uncertainty.sigma);
545 if (ar.has("correlation")) {
546 Cursor c{ar.cursor().node()["correlation"], ar.cursor(), "correlation"};
547 // Besides a matrix, it can be the number 0 to indicate that there is no correlation.
548 if (c.node().is_seq()) {
549 readValue(c, uncertainty.correlation);
550 } else if (!c.node().is_number() || c.node().val_double() != 0.0) {
551 c.error("must be a matrix or 0");
552 }
553 }
554}
555
557{
558 ar.list("axes", data.axes);
559 ar("contents", data.contents);
560 ar("uncertainty", data.uncertainty);
561 // RooFit extension: older versions read the errors like in the samples of a HistFactory distribution.
562 if (ar.has("errors")) {
563 Cursor errors{ar.cursor().node()["errors"], ar.cursor(), "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();
568 readValue(errors, data.uncertainty->sigma);
569 }
570 }
571}
572
573// A combined data set. Only the structure is checked here: the columns and keys are checked against the domains by the
574// validation, and the sub-data sets when the data set is built.
575void readCombinedData(Reader &ar, std::string const &name, CombinedData &data)
576{
577 std::string const context = "the combined data set '" + name + "'";
578 Cursor const &c = ar.cursor();
579 if (ar.has("axes")) {
580 c.error(context + " must not have \"axes\": its columns are declared by the domains");
581 return;
582 }
583 auto nonEmptyList = [&](const char *key) -> JSONNode const * {
584 if (!ar.has(key) || !c.node()[key].is_seq() || c.node()[key].num_children() == 0) {
585 return nullptr;
586 }
587 return &c.node()[key];
588 };
589 JSONNode const *columns = nonEmptyList("columns");
590 for (std::size_t i = 0; columns && i < columns->num_children(); ++i) {
591 JSONNode const &column = columns->child(i);
592 if (column.is_container() || column.val().empty()) {
593 columns = nullptr;
594 break;
595 }
596 data.columns.push_back(column.val());
597 }
598 if (!columns) {
599 c.error("\"columns\" of " + context + " must be a non-empty list of names of categorical axes");
600 return;
601 }
602 JSONNode const *components = nonEmptyList("components");
603 if (!components) {
604 c.error("\"components\" of " + context + " must be a non-empty list");
605 return;
606 }
607 for (JSONNode const &component : components->children()) {
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\"");
610 return;
611 }
612 JSONNode const &key = component["key"];
613 CombinedDataComponent &out = data.components.emplace_back();
614 if (key.is_seq() && key.num_children() == data.columns.size()) {
615 for (JSONNode const &label : key.children()) {
616 out.key.push_back(label.is_container() ? std::string{} : label.val());
617 }
618 } else {
619 c.error("every component of " + context + " must have a \"key\" with " + std::to_string(data.columns.size()) +
620 " labels, one per column");
621 return;
622 }
623 out.data.name = component["dataset"].val();
624 }
625}
626
627void readValue(Cursor const &c, Data &out)
628{
629 if (!c.node().is_map()) {
630 c.error("must be a struct");
631 return;
632 }
633 Reader ar{c};
634 ar("name", out.name);
635 std::string type;
636 ar("type", type);
637 if (type == "binned") {
638 BinnedData body;
639 describe(ar, body);
640 out.body = std::move(body);
641 } else if (type == "unbinned") {
642 UnbinnedData body;
643 describe(ar, body);
644 out.body = std::move(body);
645 } else if (type == "point") {
646 PointData body;
647 describe(ar, body);
648 out.body = std::move(body);
649 } else if (type == "combined") {
650 CombinedData body;
651 readCombinedData(ar, out.name, body);
652 out.body = std::move(body);
653 } else if (ar.has("type")) {
654 c.error("unknown type of dataset '" + type + "'");
655 }
656}
657
658void describe(Reader &ar, Likelihood &likelihood)
659{
660 ar("name", likelihood.name);
661 ar.list("aux_distributions", likelihood.auxDistributions);
662
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\"");
667 return;
668 }
669 Cursor data{ar.cursor().node()["data"], ar.cursor(), "data"};
670 if (!data.node().is_seq()) {
671 data.error("must be an array");
672 return;
673 }
674 if (data.node().num_children() != distributions.size()) {
675 ar.cursor().error("\"distributions\" and \"data\" must have the same length");
676 return;
677 }
678 likelihood.terms.reserve(distributions.size());
679 std::size_t i = 0;
680 for (JSONNode const &node : data.node().children()) {
681 LikelihoodTerm term;
682 term.distribution = std::move(distributions[i]);
683 // Older versions of RooFit used the string "0" to say that there is no dataset.
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;
686 } else {
687 DataRef ref;
688 readValue(Cursor{node, data, i}, ref);
689 term.data = std::move(ref);
690 }
691 likelihood.terms.push_back(std::move(term));
692 ++i;
693 }
694}
695
696void describe(Reader &ar, Analysis &analysis)
697{
698 ar("name", analysis.name);
699 ar("likelihood", analysis.likelihood);
700 // HS3 v0.2.9 used the singular keys "parameter_of_interest" (a list) and "domain" (a single name). They are still
701 // accepted, but the plural keys take precedence.
702 auto isLegacy = [&](const char *key, const char *legacyKey) {
703 if (ar.has(key) || !ar.has(legacyKey)) {
704 return false;
705 }
706 ar.cursor().warning(std::string("the key \"") + legacyKey + "\" of analysis '" + analysis.name +
707 "' is deprecated, please use \"" + key + "\" instead.");
708 return true;
709 };
710 ar.list(isLegacy("parameters_of_interest", "parameter_of_interest") ? "parameter_of_interest"
711 : "parameters_of_interest",
712 analysis.parametersOfInterest);
713 if (!isLegacy("domains", "domain")) {
714 ar.list("domains", analysis.domains);
715 } else if (ar.cursor().node()["domain"].is_seq()) {
716 ar.list("domain", analysis.domains);
717 } else {
718 analysis.domains.emplace_back();
719 ar("domain", analysis.domains.back());
720 }
721 ar("init", analysis.init);
722 ar("prior", analysis.prior);
723}
724
725namespace {
726
727// The strings of the interpolation types and functions in the standard.
728std::optional<InterpolationType> interpolationTypeFromString(std::string const &str)
729{
731 if (str == toString(type)) {
732 return type;
733 }
734 }
735 return std::nullopt;
736}
737
738std::optional<InterpolationFunction> interpolationFunctionFromString(std::string const &str)
739{
742 if (str == toString(function)) {
743 return function;
744 }
745 }
746 return std::nullopt;
747}
748
749} // namespace
750
752{
753 return type == InterpolationType::Add ? "add" : "mult";
754}
755
756char const *toString(InterpolationFunction function)
757{
758 switch (function) {
759 case InterpolationFunction::Poly1: return "poly1";
760 case InterpolationFunction::Poly2: return "poly2";
761 case InterpolationFunction::Poly6: return "poly6";
762 case InterpolationFunction::Exp: return "exp";
763 }
764 return "";
765}
766
768{
769 switch (type) {
770 case ConstraintType::Gauss: return "Gauss";
771 case ConstraintType::Poisson: return "Poisson";
772 case ConstraintType::LogNormal: return "LogNormal";
773 }
774 return "";
775}
776
777void readValue(Cursor const &c, Interpolation &out)
778{
779 JSONNode const &node = c.node();
780 if (!node.is_map()) {
781 c.error("must be a struct with components 'type', 'in', and 'out'");
782 return;
783 }
784 for (const char *component : {"type", "in", "out"}) {
785 if (!node.has_child(component)) {
786 c.error(std::string("does not define the required '") + component + "' component");
787 return;
788 }
789 }
790 JSONNode const &typeNode = node["type"];
791 JSONNode const &inNode = node["in"];
792 JSONNode const &outNode = node["out"];
793 if (typeNode.is_container() || typeNode.is_null() || inNode.is_container() || inNode.is_null()) {
794 c.error("components 'type' and 'in' must be strings");
795 return;
796 }
797
798 auto type = interpolationTypeFromString(typeNode.val());
799 if (!type) {
800 c.error("has unknown interpolation type '" + typeNode.val() + "'");
801 return;
802 }
803 auto in = interpolationFunctionFromString(inNode.val());
804 if (!in) {
805 c.error("has unknown interpolation function '" + inNode.val() + "'");
806 return;
807 }
808 out.type = *type;
809 out.in = *in;
810 out.out.reset();
811
812 if (!outNode.is_null()) {
813 if (outNode.is_container()) {
814 c.error("component 'out' must be a string or null");
815 return;
816 }
817 out.out = interpolationFunctionFromString(outNode.val());
818 if (!out.out) {
819 c.error("has unknown extrapolation function '" + outNode.val() + "'");
820 return;
821 }
822 }
823 Reader reader{c};
824 for (const char *component : {"type", "in", "out"}) {
825 reader.has(component);
826 }
827}
828
829namespace {
830
831// Constraints: "constraints" names the constraint distribution of each parameter, or is null for an unconstrained one.
832// Older documents give a type in "constraint", or a distribution in "constraint_name", to which upgradeDocument()
833// translated the even older forms.
834std::optional<ConstraintType> readConstraintType(Cursor const &c)
835{
836 std::string value;
837 readValue(c, value);
839 if (value == toString(type)) {
840 return type;
841 }
842 }
843 c.error("unknown constraint type '" + value + "', supported are \"Gauss\", \"Poisson\" and \"LogNormal\"");
844 return std::nullopt;
845}
846
847void readConstraint(Reader &ar, Constraint &out)
848{
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");
853 return;
854 }
855 JSONNode const &item = c.node().child(0);
856 if (item.is_null()) {
857 out = Unconstrained{};
858 return;
859 }
860 ConstraintPdf pdf;
861 readValue(Cursor{item, c, std::size_t{0}}, pdf.pdf);
862 out = std::move(pdf);
863 } else if (ar.has("constraint_name")) {
864 ConstraintPdf pdf;
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"})) {
870 out = *type;
871 }
872 }
873}
874
875void readGammaConstraint(Reader &ar, GammaConstraint &out)
876{
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");
882 return;
883 }
884 std::size_t i = 0;
885 for (JSONNode const &item : c.node().children()) {
886 constraints.pdfs.emplace_back();
887 if (!item.is_null()) {
888 constraints.pdfs.back().emplace();
889 readValue(Cursor{item, c, i}, *constraints.pdfs.back());
890 }
891 ++i;
892 }
893 out = std::move(constraints);
894 } else if (ar.has("constraint")) {
895 Cursor c{ar.cursor().node()["constraint"], ar.cursor(), "constraint"};
896 // "Const" is a RooFit extension.
897 if (!c.node().is_container() && !c.node().is_null() && c.node().val() == "Const") {
898 out = ConstantGammas{};
899 } else if (auto type = readConstraintType(c)) {
900 out = *type;
901 }
902 }
903}
904
905} // namespace
906
907// The standard doesn't require a name for modifiers, but RooFit uses it to name the objects it creates.
908void readModifierName(Reader &ar, std::string &name)
909{
910 std::optional<std::string> optionalName;
911 ar("name", optionalName);
912 name = optionalName.value_or("");
913}
914
915// The parameter of a modifier with a single parameter is given in "parameters", or in "parameter" in older documents.
916void readParameter(Reader &ar, ParameterRef &parameter)
917{
918 if (!ar.has("parameters")) {
919 ar("parameter", parameter);
920 return;
921 }
922 Cursor c{ar.cursor().node()["parameters"], ar.cursor(), "parameters"};
923 if (!c.node().is_seq() || c.node().num_children() != 1) {
924 c.error("must be an array with one entry");
925 return;
926 }
927 readValue(Cursor{c.node().child(0), c, std::size_t{0}}, parameter);
928}
929
931{
932 readModifierName(ar, m.name);
933 readParameter(ar, m.parameter);
934 readConstraint(ar, m.constraint);
935}
936
938{
939 readModifierName(ar, m.name);
940 readParameter(ar, m.parameter);
941 ar.nested("data", [&](Reader &data) {
942 data("hi", m.hi);
943 data("lo", m.lo);
944 });
945 readConstraint(ar, m.constraint);
946 ar("interpolation", m.interpolation);
947}
948
949void describe(Reader &ar, HistoSysVariation &variation)
950{
951 ar("contents", variation.contents);
952 ar("errors", variation.errors);
953}
954
956{
957 readModifierName(ar, m.name);
958 readParameter(ar, m.parameter);
959 ar.nested("data", [&](Reader &data) {
960 data("hi", m.hi);
961 data("lo", m.lo);
962 });
963 readConstraint(ar, m.constraint);
964 ar("interpolation", m.interpolation);
965}
966
968{
969 readModifierName(ar, m.name);
970 if (ar.has("parameter")) {
971 // A single name stands for one parameter per bin, which are named after it.
972 ar("parameter", m.name);
973 }
974 ar.list("parameters", m.parameters);
975 if (ar.has("data")) {
976 ar.nested("data", [&](Reader &data) { data.list("vals", m.vals); });
977 }
978 readGammaConstraint(ar, m.constraint);
979}
980
982{
983 readModifierName(ar, m.name);
984 ar.list("parameters", m.parameters);
985 readGammaConstraint(ar, m.constraint);
986}
987
989{
990 ar("name", m.name);
991}
992
993void readValue(Cursor const &c, Modifier &out)
994{
995 if (!c.node().is_map()) {
996 c.error("must be a struct");
997 return;
998 }
999 Reader ar{c};
1000 std::string type;
1001 ar("type", type);
1002 auto read = [&](auto modifier) {
1003 describe(ar, modifier);
1004 out = std::move(modifier);
1005 };
1006 if (type == "normfactor") {
1007 read(NormFactor{});
1008 } else if (type == "normsys") {
1009 read(NormSys{});
1010 } else if (type == "histosys") {
1011 read(HistoSys{});
1012 } else if (type == "shapesys" || type == "shapefactor") {
1013 read(ShapeSys{});
1014 } else if (type == "staterror") {
1015 read(StatError{});
1016 } else if (type == "custom") {
1017 read(CustomModifier{});
1018 } else if (ar.has("type")) {
1019 std::string name;
1020 if (ar.has("name")) {
1021 ar("name", name);
1022 }
1023 c.error("modifier '" + name + "' of unknown type '" + type + "'");
1024 }
1025}
1026
1027void describe(Reader &ar, Sample &sample)
1028{
1029 ar("name", sample.name);
1030 ar.nested("data", [&](Reader &data) {
1031 data("contents", sample.contents);
1032 data("errors", sample.errors);
1033 });
1034 ar.list("modifiers", sample.modifiers);
1035}
1036
1038{
1039 std::optional<double> relThreshold;
1040 ar("relThreshold", relThreshold);
1041 config.relThreshold = relThreshold.value_or(0.0);
1042 readGammaConstraint(ar, config.constraint);
1043 // Written by upgradeDocument() for older documents.
1044 std::optional<bool> impliedPoissonErrors;
1045 ar("implied_poisson_errors", impliedPoissonErrors);
1046 config.impliedPoissonErrors = impliedPoissonErrors.value_or(false);
1047}
1048
1050{
1051 if (ar.has("axes") && ar.cursor().node()["axes"].is_seq()) {
1052 for (JSONNode const &axis : ar.cursor().node()["axes"].children()) {
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");
1056 return;
1057 }
1058 }
1059 }
1060 ar("axes", dist.axes);
1061 ar("default_interpolation", dist.defaultInterpolation);
1062 ar("samples", dist.samples);
1063 if (ar.has("staterror")) {
1064 readValue(Cursor{ar.cursor().node()["staterror"], ar.cursor(), "staterror"}, dist.statError);
1065 }
1066}
1067
1068namespace {
1069
1070void readDistribution(Cursor const &c, Distribution &out, ParseOptions const &options)
1071{
1072 if (!c.node().is_map()) {
1073 c.error("must be a struct");
1074 return;
1075 }
1076 Reader ar{c};
1077 ar("name", out.name);
1078 std::string type;
1079 ar("type", type);
1080 if (options.typedHistFactory && type == "histfactory_dist") {
1081 HistFactoryDist body;
1082 describe(ar, body);
1083 out.body = std::move(body);
1084 } else {
1085 out.body = GenericObject{type, &c.node()};
1086 // The importers read the other components.
1087 for (JSONNode const &child : c.node().children()) {
1088 ar.has(child.key().c_str());
1089 }
1090 }
1091}
1092
1093} // namespace
1094
1095void readValue(Cursor const &c, Function &out)
1096{
1097 if (!c.node().is_map()) {
1098 c.error("must be a struct");
1099 return;
1100 }
1101 Reader ar{c};
1102 ar("name", out.name);
1103 ar("type", out.body.type);
1104 out.body.node = &c.node();
1105 // The importers read the other components.
1106 for (JSONNode const &child : c.node().children()) {
1107 ar.has(child.key().c_str());
1108 }
1109}
1110
1111void describe(Reader &ar, Attributes &attributes)
1112{
1113 if (ar.has("dict")) {
1114 Cursor dict{ar.cursor().node()["dict"], ar.cursor(), "dict"};
1115 if (!dict.node().is_map()) {
1116 dict.error("must be a struct");
1117 return;
1118 }
1119 for (JSONNode const &item : dict.node().children()) {
1120 readValue(Cursor{item, dict, item.key().c_str()}, attributes.dict[item.key()]);
1121 }
1122 }
1123 ar.list("tags", attributes.tags);
1124 if (ar.has("is_const_var")) {
1125 int isConstVar = 0;
1126 ar("is_const_var", isConstVar);
1127 attributes.isConstVar = isConstVar == 1;
1128 }
1129}
1130
1132{
1133 ar("index_cat", info.indexCat);
1134 ar("labels", info.labels);
1135 ar("indices", info.indices);
1136 ar("distributions", info.distributions);
1137 if (info.labels.size() != info.indices.size() || info.labels.size() != info.distributions.size()) {
1138 ar.cursor().error("mismatch in number of labels, indices and distributions!");
1139 }
1140}
1141
1143{
1144 ar("index_cat", info.indexCat);
1145 ar("labels", info.labels);
1146 ar("indices", info.indices);
1147 if (info.labels.size() != info.indices.size()) {
1148 ar.cursor().error("mismatch in number of indices and labels!");
1149 }
1150}
1151
1153{
1154 ar("mcName", info.mcName);
1155 ar("pdfName", info.pdfName);
1156 ar("combined_data_name", info.combinedDataName);
1157 ar("observables", info.observables);
1158}
1159
1160namespace {
1161
1162template <class Map_t>
1163void readMap(Reader &ar, const char *key, Map_t &out)
1164{
1165 if (!ar.has(key)) {
1166 return;
1167 }
1168 Cursor c{ar.cursor().node()[key], ar.cursor(), key};
1169 if (c.node().is_null()) {
1170 return;
1171 }
1172 if (!c.node().is_map()) {
1173 c.error("must be a struct");
1174 return;
1175 }
1176 for (JSONNode const &item : c.node().children()) {
1177 const std::string itemKey = item.key();
1178 readValue(Cursor{item, c, itemKey.c_str()}, out[itemKey]);
1179 }
1180}
1181
1182// The content of "misc" is not supposed to change the result of evaluating the model, so problems with the step widths
1183// are only warnings.
1184void readStepWidths(Cursor const &misc, std::vector<StepWidth> &out)
1185{
1186 JSONNode const *node = misc.node().find("minimization", "parameter_stepwidths");
1187 if (!node) {
1188 return;
1189 }
1190 if (!node->is_seq()) {
1191 misc.warning("minimization.parameter_stepwidths is not a sequence, skipping.");
1192 return;
1193 }
1194 for (JSONNode const &item : node->children()) {
1195 if (!item.is_map() || !item.has_child("name") || !item.has_child("step_width") ||
1196 !item["step_width"].is_number() || item["name"].is_container() || item["name"].is_null()) {
1197 misc.warning("skipping malformed parameter_stepwidths entry.");
1198 continue;
1199 }
1200 out.push_back({item["name"].val(), item["step_width"].val_double()});
1201 }
1202}
1203
1204void readMisc(Cursor const &root, RooFitInternal &out)
1205{
1206 if (!root.node().has_child("misc")) {
1207 return;
1208 }
1209 Cursor misc{root.node()["misc"], root, "misc"};
1210 if (!misc.node().is_map()) {
1211 return;
1212 }
1213 readStepWidths(misc, out.stepWidths);
1214 if (!misc.node().has_child("ROOT_internal")) {
1215 return;
1216 }
1217 Cursor internal{misc.node()["ROOT_internal"], misc, "ROOT_internal"};
1218 if (!internal.node().is_map()) {
1219 return;
1220 }
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);
1228}
1229
1230void readMetadata(Cursor const &root, Metadata &out, ParseOptions const &options)
1231{
1232 JSONNode const *metadata = root.node().find("metadata");
1233 JSONNode const *versionNode = metadata ? metadata->find("hs3_version") : nullptr;
1234 if (!versionNode) {
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"
1240 << " {\n"
1241 << " \"hs3_version\" : \"" << supportedVersion << "\"\n"
1242 << " }";
1243 root.error(ss.str());
1244 }
1245 return;
1246 }
1247 Cursor metadataCursor{*metadata, root, "metadata"};
1248 Cursor versionCursor{*versionNode, metadataCursor, "hs3_version"};
1249 if (versionNode->is_container() || versionNode->is_null() || versionNode->is_number()) {
1250 versionCursor.error(std::string("The HS3 version in the metadata must be a string, e.g. \"") + supportedVersion +
1251 "\"");
1252 return;
1253 }
1254 out.hs3Version = versionNode->val();
1255
1256 Version supported;
1257 parseVersion(supportedVersion, supported);
1258 if (!parseVersion(out.hs3Version, out.version)) {
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.");
1265 }
1266
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);
1273}
1274
1275} // namespace
1276
1277HS3Document parseDocument(JSONNode const &root, Diagnostics &diagnostics, ParseOptions const &options)
1278{
1279 HS3Document doc;
1280 Cursor cursor{root, diagnostics};
1281 readMetadata(cursor, doc.metadata, options);
1282 if (hasErrors(diagnostics)) {
1283 return doc;
1284 }
1285
1286 Reader ar{cursor};
1287 ar.has("metadata");
1288 ar.has("misc");
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");
1293 } else {
1294 std::size_t i = 0;
1295 doc.distributions.reserve(distributions.node().num_children());
1296 for (JSONNode const &item : distributions.node().children()) {
1297 doc.distributions.emplace_back();
1298 readDistribution(Cursor{item, distributions, i}, doc.distributions.back(), options);
1299 ++i;
1300 }
1301 }
1302 }
1303 ar.list("functions", doc.functions);
1304 ar.list("data", doc.data);
1305 ar.list("likelihoods", doc.likelihoods);
1306 ar.list("domains", doc.domains);
1307 ar.list("parameter_points", doc.parameterPoints);
1308 ar.list("analyses", doc.analyses);
1309 readMisc(cursor, doc.rooFit);
1310 return doc;
1311}
1312
1314{
1315 HistFactoryDist out;
1316 Cursor cursor{distribution, diagnostics};
1317 if (!distribution.is_map()) {
1318 cursor.error("must be a struct");
1319 return out;
1320 }
1321 Reader ar{cursor};
1322 ar.has("name");
1323 ar.has("type");
1324 describe(ar, out);
1325 return out;
1326}
1327
1328void readValue(Cursor const &c, NameOrNumber &out)
1329{
1330 if (c.node().is_number()) {
1331 out = c.node().val_double();
1332 } else {
1333 readValue(c, out.emplace<std::string>());
1334 }
1335}
1336
1337std::optional<Interpolation> readInterpolationCode(Cursor const &c, InterpolationClass interpolationClass)
1338{
1339 JSONNode const &node = c.node();
1340 if (node.is_container() || node.is_null() || !node.has_val()) {
1341 c.error("must be a structured interpolation or a legacy integer code");
1342 return std::nullopt;
1343 }
1344 const std::string value = node.val();
1345 int code = 0;
1346 const auto result = std::from_chars(value.data(), value.data() + value.size(), code);
1347 if (result.ec != std::errc{} || result.ptr != value.data() + value.size()) {
1348 c.error("has invalid legacy interpolation code '" + value + "'");
1349 return std::nullopt;
1350 }
1351 auto interpolation = interpolationFromCode(code, interpolationClass);
1352 if (!interpolation) {
1353 c.error(std::string("has unsupported ") +
1354 (interpolationClass == InterpolationClass::Piecewise ? "PiecewiseInterpolation" : "FlexibleInterpVar") +
1355 " code " + value);
1356 }
1357 return interpolation;
1358}
1359
1360namespace {
1361
1362// The "interpolations" of the functions "interpolation" and "interpolation0d": one for all parameters, or one per
1363// parameter. Older versions of RooFit wrote integer "interpolationCodes". Without both, the interpolation is linear.
1364void readInterpolations(Reader &ar, std::size_t nParameters, InterpolationClass interpolationClass,
1365 std::vector<Interpolation> &out)
1366{
1367 out.assign(nParameters, additivePiecewiseLinear);
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;
1372 readValue(c, interpolations);
1373 const std::size_t size = interpolations.size();
1374 if (c.numErrors() != errorsBefore) {
1375 return;
1376 }
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());
1382 } else {
1383 out = std::move(interpolations);
1384 }
1385 return;
1386 }
1387 if (!ar.has("interpolationCodes")) {
1388 return;
1389 }
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) +
1394 " parameters)");
1395 return;
1396 }
1397 std::size_t i = 0;
1398 for (JSONNode const &child : c.node().children()) {
1399 if (auto interpolation = readInterpolationCode(Cursor{child, c, i}, interpolationClass)) {
1400 out[i] = *interpolation;
1401 }
1402 ++i;
1403 }
1404}
1405
1406// The functions "interpolation" and "interpolation0d" have the variations "high" and "low" for each of the "vars".
1407template <class Function_t, class Fn>
1408Function_t parseInterpolated(JSONNode const &node, Diagnostics &diagnostics, InterpolationClass interpolationClass,
1409 Fn &&readOthers)
1410{
1411 Function_t out;
1412 Cursor cursor{node, diagnostics};
1413 if (!node.is_map()) {
1414 cursor.error("must be a struct");
1415 return out;
1416 }
1417 const std::size_t errorsBefore = cursor.numErrors();
1418 Reader ar{cursor};
1419 ar.has("name");
1420 ar.has("type");
1421 ar("nom", out.nominal);
1422 ar("vars", out.parameters);
1423 ar("high", out.high);
1424 ar("low", out.low);
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'");
1429 }
1430 readInterpolations(ar, out.parameters.size(), interpolationClass, out.interpolations);
1431 return out;
1432}
1433
1434} // namespace
1435
1436std::vector<BinnedAxis> parseBinnedAxes(JSONNode const &axes, Diagnostics &diagnostics)
1437{
1438 std::vector<BinnedAxis> out;
1439 readValue(Cursor{axes, diagnostics}, out);
1440 return out;
1441}
1442
1444{
1445 return parseInterpolated<InterpolatedFunction>(
1446 node, diagnostics, InterpolationClass::Piecewise,
1447 [](Reader &ar, InterpolatedFunction &out) { ar("positiveDefinite", out.positiveDefinite); });
1448}
1449
1451{
1452 return parseInterpolated<InterpolatedNumber>(node, diagnostics, InterpolationClass::Flexible,
1453 [](Reader &, InterpolatedNumber &) {});
1454}
1455
1456} // namespace HS3
1457} // namespace RooFit
Interpolation descriptor
Definition HS3Parser.cxx:39
int piecewise
Definition HS3Parser.cxx:40
int flexible
Definition HS3Parser.cxx:41
constexpr const char * fixedValueKey
Definition JSONIOUtils.h:70
std::string message
#define d(i)
Definition RSha256.hxx:102
#define c(i)
Definition RSha256.hxx:101
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
char name[80]
Definition TGX11.cxx:142
XID Cursor
Definition TGX11.h:36
std::string val() const
JSONNode const * find(std::string const &key) const
bool has_child(std::string const &) const
std::string key() 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
HS3::Metadata metadata
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.
Definition HS3Schema.h:32
const char * _key
Definition HS3Schema.h:54
std::size_t numErrors() const
void warning(std::string const &message) const
Detail::JSONNode const & node() const
Definition HS3Schema.h:44
std::string path() const
std::size_t _index
Definition HS3Schema.h:55
Diagnostics & _diagnostics
Definition HS3Schema.h:52
Cursor const * _parent
Definition HS3Schema.h:53
Detail::JSONNode const & _node
Definition HS3Schema.h:51
void error(std::string const &message) const
Reads the components of a struct.
Definition HS3Schema.h:59
~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
Definition HS3Schema.h:88
void nested(const char *key, Fn &&fn)
Read the components of a struct that is nested in a component.
Definition HS3Schema.h:178
std::size_t _nErrorsBefore
Definition HS3Schema.h:89
Cursor const & cursor() const
Definition HS3Schema.h:84
Cursor const & _cursor
Definition HS3Schema.h:87
void list(const char *key, std::vector< T > &field)
Read an array that can be omitted, which is equivalent to an empty one.
Definition HS3Schema.h:165
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
Definition HS3Parser.cxx:29
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 &parameter)
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.
Definition HS3Parser.cxx:64
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.
Definition HS3Parser.cxx:83
constexpr Interpolation multiplicativePolynomialLinear
bool hasErrors(Diagnostics const &diagnostics)
Whether there is a diagnostic with error severity.
Definition HS3Parser.cxx:94
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...
Definition CodegenImpl.h:73
std::optional< DistributionRef > prior
std::optional< ParameterPointRef > init
LikelihoodRef likelihood
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
The axis of binned data.
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
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::string name
std::variant< PointData, UnbinnedData, BinnedData, CombinedData > body
The axis of a domain.
Definition HS3Document.h:98
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
Definition HS3Document.h:92
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.
InterpolationType type
InterpolationFunction in
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::string name
Definition HS3Document.h:64
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....
Scales each bin by a parameter, that is constrained by the statistical uncertainty of all samples tha...
TMarker m
Definition textangle.C:8