40JSONNode &appendNamedChild(JSONNode &node, std::string
const &
name)
42 static constexpr bool useListsInsteadOfDicts =
true;
44 if (!useListsInsteadOfDicts) {
47 JSONNode &
child = node.set_seq().append_child().set_map();
54 void readVariable(
const char *
name,
double min,
double max);
61 void readVariable(
const char *
name,
double min,
double max);
66 struct ProductDomainElement {
71 std::map<std::string, ProductDomainElement> _map;
74 std::map<std::string, ProductDomain> _map;
77void Domains::readVariable(
const char *
name,
double min,
double max)
79 _map[
"default_domain"].readVariable(
name, min, max);
84 for (
auto const &domain : _map) {
85 domain.second.writeJSON(appendNamedChild(node, domain.first));
88void Domains::ProductDomain::readVariable(
const char *
name,
double min,
double max)
98 node[
"type"] <<
"product_domain";
102 for (
auto const &item : _map) {
103 auto const &
elem = item.second;
112 double w =
ax.GetXmax() -
ax.GetXmin();
113 double bw =
w /
ax.GetNbins();
114 for (
int i = 0; i <=
ax.GetNbins(); ++i) {
115 if (std::abs(
ax.GetBinUpEdge(i) - (
ax.GetXmin() + (
bw * i))) >
w * 1
e-6)
126 axis[
"nbins"] <<
ax.GetNbins();
127 axis[
"min"] <<
ax.GetXmin();
128 axis[
"max"] <<
ax.GetXmax();
130 auto &edges = axis[
"edges"];
132 for (
int i = 0; i <=
ax.GetNbins(); ++i) {
133 edges.append_child() <<
ax.GetBinUpEdge(i);
140 std::vector<std::string>
obsnames{
"obs_x_" +
c.GetName(),
"obs_y_" +
c.GetName(),
"obs_z_" +
c.GetName()};
141 obsnames.resize(
c.GetData().GetHisto()->GetDimension());
148 auto &observables = node[
"axes"].set_seq();
149 auto &
x = observables.append_child().set_map();
152 if (
h.GetDimension() > 1) {
153 auto &
y = observables.append_child().set_map();
156 if (
h.GetDimension() > 2) {
157 auto &z = observables.append_child().set_map();
168 for (
int i = 1; i <= nBins; ++i) {
170 node.append_child() << val;
178 auto &weights = node[
"contents"].set_seq();
179 JSONNode *
errors =
nullptr;
181 errors = &node[
"errors"].set_seq();
187 for (
int i = 1; i <= nBins; ++i) {
189 weights.append_child() << val;
192 errors->append_child() << err;
198 std::vector<std::string>
const &
obsnames)
202 if (!
sample.GetOverallSysList().empty()) {
203 auto &
modifiers = s[
"modifiers"].set_seq();
204 for (
const auto &sys :
sample.GetOverallSysList()) {
205 auto &node =
modifiers.append_child().set_map();
206 node[
"name"] << sys.GetName();
207 node[
"type"] <<
"normsys";
208 auto &
data = node[
"data"];
210 data[
"lo"] << sys.GetLow();
211 data[
"hi"] << sys.GetHigh();
215 if (!
sample.GetNormFactorList().empty()) {
216 auto &
modifiers = s[
"modifiers"].set_seq();
217 for (
const auto &
nf :
sample.GetNormFactorList()) {
219 mod[
"name"] <<
nf.GetName();
220 mod[
"type"] <<
"normfactor";
223 mod[
"name"] <<
"Lumi";
224 mod[
"type"] <<
"normfactor";
225 mod[
"constraint_name"] <<
"lumiConstraint";
228 if (!
sample.GetHistoSysList().empty()) {
229 auto &
modifiers = s[
"modifiers"].set_seq();
230 for (
size_t i = 0; i <
sample.GetHistoSysList().
size(); ++i) {
231 auto &sys =
sample.GetHistoSysList()[i];
232 auto &node =
modifiers.append_child().set_map();
233 node[
"name"] << sys.GetName();
234 node[
"type"] <<
"histosys";
235 auto &
data = node[
"data"].set_map();
241 if (!
sample.GetShapeSysList().empty()) {
242 auto &
modifiers = s[
"modifiers"].set_seq();
243 for (
size_t i = 0; i <
sample.GetShapeSysList().
size(); ++i) {
244 auto &sys =
sample.GetShapeSysList()[i];
245 auto &node =
modifiers.append_child().set_map();
246 node[
"name"] << sys.GetName();
247 node[
"type"] <<
"shapesys";
249 node[
"constraint"] <<
"Gauss";
251 node[
"constraint"] <<
"Poisson";
252 auto &
data = node[
"data"].set_map();
257 auto &
tags = s[
"dict"].set_map();
258 tags[
"normalizeByTheory"] <<
sample.GetNormalizeByTheory();
260 if (
sample.GetStatError().GetActivate()) {
261 RooStats::HistFactory::JSONTool::activateStatError(s);
264 auto &
data = s[
"data"];
276 ch[
"type"] <<
"histfactory_dist";
278 auto &
staterr = ch[
"statError"].set_map();
279 staterr[
"relThreshold"] <<
c.GetStatErrorConfig().GetRelErrorThreshold();
284 for (
const auto &s :
c.GetSamples()) {
289void setAttribute(JSONNode &rootnode,
const std::string &obj,
const std::string &
attrib)
291 auto node = &rootnode.get(
"misc",
"ROOT_internal",
"attributes").set_map()[obj].set_map();
292 auto &
tags = (*node)[
"tags"];
302 if (!ch.CheckHistograms())
303 throw std::runtime_error(
"unable to export histograms, please call CollectHistograms first");
308 auto &
funclist = rootnode[
"functions"];
309 for (
const auto &func :
measurement.GetFunctionObjects()) {
310 auto &
f = appendNamedChild(
funclist, func.GetName());
311 f[
"name"] << func.GetName();
312 f[
"expression"] << func.GetExpression();
313 f[
"dependents"] << func.GetDependents();
314 f[
"command"] << func.GetCommand();
318 auto &
pdflist = rootnode[
"distributions"];
320 auto &
analysisNode = appendNamedChild(rootnode[
"analyses"],
"simPdf");
321 analysisNode[
"domains"].set_seq().append_child() <<
"default_domain";
338 auto pdfName = std::string(
"model_") +
c.GetName();
342 likelihoodNode[
"data"].append_child() << std::string(
"obsData_") +
c.GetName();
347 struct VariableInfo {
349 double minVal = -5.0;
351 bool isConstant =
false;
354 std::unordered_map<std::string, VariableInfo>
variables;
356 for (
const auto &channel :
measurement.GetChannels()) {
357 for (
const auto &
sample : channel.GetSamples()) {
358 for (
const auto &norm :
sample.GetNormFactorList()) {
360 info.val = norm.GetVal();
361 info.minVal = norm.GetLow();
362 info.maxVal = norm.GetHigh();
364 for (
const auto &sys :
sample.GetOverallSysList()) {
365 variables[std::string(
"alpha_") + sys.GetName()] = VariableInfo{};
369 for (
const auto &sys :
measurement.GetConstantParams()) {
371 info.isConstant =
true;
372 bool isGamma = sys.find(
"gamma_") != std::string::npos;
388 info1.maxVal = 10 * nominal;
389 info1.isConstant =
true;
394 info2.maxVal = nominal + 10 * error;
395 info2.isConstant =
true;
398 JSONNode &
varlist = appendNamedChild(rootnode[
"parameter_points"],
"default_values")[
"parameters"];
400 std::string
const &
parname = item.first;
401 VariableInfo
const &
info = item.second;
404 v[
"value"] <<
info.val;
407 if (
info.writeDomain) {
413 auto &
child1 = rootnode.get(
"misc",
"ROOT_internal",
"combined_datasets").set_map()[
"obsData"].set_map();
414 auto &
child2 = rootnode.get(
"misc",
"ROOT_internal",
"combined_distributions").set_map()[
"simPdf"].set_map();
416 child1[
"index_cat"] <<
"channelCat";
420 child2[
"index_cat"] <<
"channelCat";
427 labels1.append_child() <<
c.GetName();
429 labels2.append_child() <<
c.GetName();
431 pdfs2.append_child() << (std::string(
"model_") +
c.GetName());
433 JSONNode &
dataOutput = appendNamedChild(rootnode[
"data"], std::string(
"obsData_") +
c.GetName());
440 auto &
modelConfigAux = rootnode.get(
"misc",
"ROOT_internal",
"ModelConfigs",
"simPdf").set_map();
453std::unique_ptr<RooFit::Detail::JSONTree> createNewJSONTree()
456 JSONNode &
n =
tree->rootnode();
458 auto &metadata =
n[
"metadata"].set_map();
461 metadata[
"hs3_version"] <<
"0.1.90";
464 auto &
rootInfo = appendNamedChild(metadata[
"packages"],
"ROOT");
476void RooStats::HistFactory::JSONTool::PrintJSON(std::ostream &os)
478 std::unique_ptr<RooFit::Detail::JSONTree>
tree = createNewJSONTree();
479 auto &rootnode =
tree->rootnode();
482 domains.writeJSON(rootnode[
"domains"]);
483 rootnode.writeJSON(os);
485void RooStats::HistFactory::JSONTool::PrintJSON(std::string
const &
filename)
491void RooStats::HistFactory::JSONTool::PrintYAML(std::ostream &os)
493 std::unique_ptr<RooFit::Detail::JSONTree>
tree = createNewJSONTree();
494 auto &rootnode =
tree->rootnode().set_map();
497 domains.writeJSON(rootnode[
"domains"]);
498 rootnode.writeYML(os);
501void RooStats::HistFactory::JSONTool::PrintYAML(std::string
const &
filename)
507void RooStats::HistFactory::JSONTool::activateStatError(JSONNode &
sampleNode)
509 auto &node =
sampleNode[
"modifiers"].set_seq().append_child().set_map();
510 node[
"name"] <<
"mcstat";
511 node[
"type"] <<
"staterror";
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
const_iterator begin() const
const_iterator end() const
virtual JSONNode & set_map()=0
static std::unique_ptr< JSONTree > create()
This class encapsulates all information for the statistical interpretation of one experiment.
The RooStats::HistFactory::Measurement class can be used to construct a model by combining multiple R...
Class to manage histogram axis.
TH1 is the base class of all histogram classes in ROOT.
virtual Int_t GetNbinsY() const
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
virtual Int_t GetNbinsZ() const
virtual Int_t GetNbinsX() const
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
std::string Name(Type type)
void variables(TString dataset, TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variables", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)