Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Domains.cxx
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Jonas Rembser, CERN, Jan 2023
5 *
6 * Copyright (c) 2023, 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 "Domains.h"
14
16#include <RooNumber.h>
17#include <RooRealVar.h>
18
20
21namespace RooFit {
22namespace JSONIO {
23namespace Detail {
24
25void Domains::readVariable(const char *name, double min, double max)
26{
27 _map["default_domain"].readVariable(name, min, max);
28}
30{
31 readVariable(var.GetName(), var.getMin(), var.getMax());
32}
34{
35 _map.at("default_domain").writeVariable(var);
36}
37
39{
40 _map["default_domain"].readJSON(*RooJSONFactoryWSTool::findNamedChild(node, "default_domain"));
41}
43{
44 for (auto const &domain : _map) {
45 domain.second.writeJSON(RooJSONFactoryWSTool::appendNamedChild(node, domain.first));
46 }
47}
48void Domains::ProductDomain::readVariable(const char *name, double min, double max)
49{
50 auto &elem = _map[name];
51
52 if (!RooNumber::isInfinite(min)) {
53 elem.hasMin = true;
54 elem.min = min;
55 }
56 if (!RooNumber::isInfinite(max)) {
57 elem.hasMax = true;
58 elem.max = max;
59 }
60}
62{
63 auto found = _map.find(var.GetName());
64 if (found != _map.end()) {
65 auto const &elem = found->second;
66 if (elem.hasMin)
67 var.setMin(elem.min);
68 if (elem.hasMax)
69 var.setMax(elem.max);
70 }
71}
73{
74 // In the future, throw an exception if the type is not product domain
75 for (auto const &varNode : node["axes"].children()) {
76 auto &elem = _map[RooJSONFactoryWSTool::name(varNode)];
77
78 if (varNode.has_child("min")) {
79 elem.min = varNode["min"].val_double();
80 elem.hasMin = true;
81 }
82 if (varNode.has_child("max")) {
83 elem.max = varNode["max"].val_double();
84 elem.hasMax = true;
85 }
86 }
87}
89{
90 node.set_map();
91 node["type"] << "product_domain";
92
93 auto &variablesNode = node["axes"];
94
95 for (auto const &item : _map) {
96 auto const &elem = item.second;
97 RooFit::Detail::JSONNode &varnode = RooJSONFactoryWSTool::appendNamedChild(variablesNode, item.first);
98 if (elem.hasMin)
99 varnode["min"] << elem.min;
100 if (elem.hasMax)
101 varnode["max"] << elem.max;
102 }
103}
104
105} // namespace Detail
106} // namespace JSONIO
107} // namespace RooFit
char name[80]
Definition TGX11.cxx:110
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
virtual JSONNode & set_map()=0
virtual children_view children()
std::map< std::string, ProductDomainElement > _map
Definition Domains.h:59
void readVariable(const char *name, double min, double max)
Definition Domains.cxx:48
void writeJSON(RooFit::Detail::JSONNode &) const
Definition Domains.cxx:88
void readJSON(RooFit::Detail::JSONNode const &)
Definition Domains.cxx:72
std::map< std::string, ProductDomain > _map
Definition Domains.h:62
void writeVariable(RooRealVar &) const
Definition Domains.cxx:33
void readVariable(const char *name, double min, double max)
Definition Domains.cxx:25
void writeJSON(RooFit::Detail::JSONNode &) const
Definition Domains.cxx:42
void readJSON(RooFit::Detail::JSONNode const &)
Definition Domains.cxx:38
static RooFit::Detail::JSONNode & appendNamedChild(RooFit::Detail::JSONNode &node, std::string const &name)
static std::string name(const RooFit::Detail::JSONNode &n)
static RooFit::Detail::JSONNode const * findNamedChild(RooFit::Detail::JSONNode const &node, std::string const &name)
static constexpr int isInfinite(double x)
Return true if x is infinite by RooNumber internal specification.
Definition RooNumber.h:34
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:40
void setMin(const char *name, double value)
Set minimum of name range to given value.
void setMax(const char *name, double value)
Set maximum of name range to given value.
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition Common.h:18