29 std::istringstream stream(str);
31 output.
valid = (stream >> output.
value) && stream.eof();
38 bool isRooConstVar =
dynamic_cast<RooConstVar const *
>(&arg);
46 node << static_cast<RooConstVar const &>(arg).getVal();
52bool startsWith(std::string_view str, std::string_view prefix)
54 return str.size() >= prefix.size() && 0 == str.compare(0, prefix.size(), prefix);
57bool endsWith(std::string_view str, std::string_view suffix)
59 return str.size() >= suffix.size() && 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix);
62std::string
removeSuffix(std::string_view str, std::string_view suffix)
66 out = out.substr(0, out.length() - suffix.length());
77 node[
"nbins"] << binning.
numBins();
81 auto &edges = node[
"edges"].
set_seq();
83 for (
int i = 0; i < binning.
numBins(); ++i) {
84 edges.append_child() << binning.
binHigh(i);
92 auto readNumber = [&](
int &out) {
93 const std::size_t begin = pos;
94 while (pos < version.size() && std::isdigit(
static_cast<unsigned char>(version[pos]))) {
98 if (pos == begin || pos - begin > 9) {
101 out = std::stoi(version.substr(begin, pos - begin));
104 if (!readNumber(major) || pos >= version.size() || version[pos] !=
'.') {
108 return readNumber(minor);
115 int versionMajor = 0;
116 int versionMinor = 0;
120 return std::make_pair(versionMajor, versionMinor) < std::make_pair(major, minor);
127 std::vector<std::size_t> nBins;
129 nBins.push_back(
static_cast<std::size_t
>(
dynamic_cast<RooAbsLValue const &
>(*var).
numBins()));
136std::size_t th1Position(std::size_t k, std::vector<std::size_t>
const &nBins)
139 std::size_t stride = 1;
140 std::vector<std::size_t> indices(nBins.size());
141 for (std::size_t j = nBins.size(); j-- > 0;) {
142 indices[j] = k % nBins[j];
145 for (std::size_t j = 0; j < nBins.size(); ++j) {
146 th1 += indices[j] * stride;
154std::unique_ptr<RooArgSet>
157 auto out = std::make_unique<RooArgSet>();
159 std::string
name = var->GetName();
160 for (std::size_t i = 0; i < histObs.
size() && i < funcObs.
size(); ++i) {
161 if (
name == histObs[i]->GetName() &&
dynamic_cast<RooAbsLValue const *
>(funcObs[i])) {
166 out->addOwned(std::unique_ptr<RooAbsArg>{
static_cast<RooAbsArg *
>(var->clone(
name.c_str()))});
173 std::vector<RooAbsReal *> out;
174 for (
int k = 0; k < func.
numBins(); ++k) {
182 const std::vector<std::size_t> nBins = numBinsPerVariable(vars);
183 std::vector<RooAbsArg *> th1Order(paramsInBinOrder.
size(),
nullptr);
184 for (std::size_t k = 0; k < paramsInBinOrder.
size(); ++k) {
185 const std::size_t t = th1Position(k, nBins);
186 if (t >= th1Order.size()) {
189 th1Order[t] = paramsInBinOrder.
at(k);
199 std::string
const &context)
203 " has a multi-dimensional binning. Documents before HS3 0.3 don't define the order "
204 "of its per-bin parameters (RooFit wrote them in TH1 order, while the bin "
205 "contents use the order of HS3 0.3, last axis fastest). Please re-export the "
206 "workspace with a newer ROOT version.");
212void sortByName(std::vector<RooCategory const *> &columns)
214 std::sort(columns.begin(), columns.end(),
222 std::vector<RooCategory const *> columns;
223 auto addColumn = [&](
RooAbsArg const &arg) {
224 auto *cat =
dynamic_cast<RooCategory const *
>(&arg);
227 ", but only a RooCategory or a RooSuperCategory of RooCategories " +
228 "can be written as the columns of a combined distribution");
230 columns.push_back(cat);
245 std::vector<RooCategory const *> columns;
247 if (
auto *cat =
dynamic_cast<RooCategory const *
>(arg)) {
248 columns.push_back(cat);
255std::vector<std::vector<std::string>>
selectionKeys(std::vector<RooCategory const *>
const &columns)
257 std::vector<std::vector<std::string>> keys{{}};
259 std::vector<std::vector<std::string>> next;
260 for (
auto const &key : keys) {
261 for (
unsigned int i = 0; i < column->size(); ++i) {
263 next.back().push_back(column->getOrdinal(i).first);
266 keys = std::move(next);
273 if (key.size() == 1) {
276 std::string label =
"{";
277 for (std::size_t i = 0; i < key.size(); ++i) {
278 label += (i == 0 ?
"" :
";") + key[i];
285 std::string out =
"[";
286 for (std::size_t i = 0; i < key.size(); ++i) {
287 out += (i == 0 ?
"\"" :
", \"") + key[i] +
"\"";
293 std::vector<std::string>
const &key)
299 std::vector<std::string> inInputOrder;
301 auto found = std::find_if(columns.begin(), columns.end(),
302 [&](
RooCategory const *
c) { return std::strcmp(c->GetName(), input->GetName()) == 0; });
303 inInputOrder.push_back(key[found - columns.begin()]);
308std::vector<RooCategory *>
311 auto const *list = node.
find(field);
312 if (!list || !list->is_seq() || list->num_children() == 0) {
314 " must be a non-empty list of names of categorical axes");
316 std::vector<RooCategory *> columns;
318 if (
child.is_container() ||
child.val().empty()) {
320 " must be a non-empty list of names of categorical axes");
325 " is not declared by a categorical axis of a domain");
327 if (std::find(columns.begin(), columns.end(), cat) != columns.end()) {
330 columns.push_back(cat);
335std::vector<std::string>
338 auto const *keyNode = component.
find(
"key");
339 if (!keyNode || !keyNode->is_seq() || keyNode->num_children() != columns.size()) {
341 std::to_string(columns.size()) +
" labels, one per column");
343 std::vector<std::string> key;
345 for (
JSONNode const &label : keyNode->children()) {
346 if (label.is_container() || !columns[i]->hasLabel(label.val())) {
348 "' in position " + std::to_string(i) +
" of a key of " + context +
349 " is not one of the categories of '" + columns[i]->GetName() +
"'");
351 key.push_back(label.val());
ToNumberOutput toNumber(const std::string &str)
std::vector< std::vector< std::string > > selectionKeys(std::vector< RooCategory const * > const &columns)
void writeReference(JSONNode &node, RooAbsArg const &arg)
bool isHS3VersionBefore(std::string const &version, int major, int minor)
std::vector< RooCategory const * > selectionColumns(RooAbsCategory const &indexCat)
std::vector< RooAbsReal * > paramHistFuncParamsInBinOrder(ParamHistFunc const &func)
RooArgList toParamHistFuncOrder(RooArgList const ¶msInBinOrder, RooAbsCollection const &vars)
std::string selectionKeyToString(std::vector< std::string > const &key)
bool startsWith(std::string_view str, std::string_view prefix)
std::vector< RooCategory * > readSelectionColumns(RooWorkspace const &ws, JSONNode const &node, const char *field, std::string const &context)
bool endsWith(std::string_view str, std::string_view suffix)
std::string selectionLabel(std::vector< std::string > const &key)
std::vector< std::string > readSelectionKey(JSONNode const &component, std::vector< RooCategory * > const &columns, std::string const &context)
bool isLiteralConstVar(RooAbsArg const &arg)
std::string removeSuffix(std::string_view str, std::string_view suffix)
void writeAxisBinning(JSONNode &node, const RooAbsBinning &binning)
std::unique_ptr< RooArgSet > histogramVariablesNamedAfterObservables(RooDataHist const &dh, RooArgSet const &histObs, RooArgSet const &funcObs)
bool parseHS3Version(std::string const &version, int &major, int &minor)
void checkParamHistFuncOrderIsDefined(std::string const &hs3Version, RooAbsCollection const &vars, std::string const &context)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
A class which maps the current values of a RooRealVar (or a set of RooRealVars) to one of a number of...
RooAbsReal & getParameter() const
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Abstract base class for RooRealVar binning definitions.
Int_t numBins() const
Return number of bins.
virtual double binLow(Int_t bin) const =0
virtual bool isUniform() const
virtual double highBound() const =0
virtual double lowBound() const =0
virtual double binHigh(Int_t bin) const =0
A space to attach TBranches.
Abstract container object that can hold multiple RooAbsArg objects.
const char * GetName() const override
Returns name of object.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
Abstract base class for objects that are lvalues, i.e.
virtual Int_t numBins(const char *rangeName=nullptr) const =0
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Object to represent discrete states.
Represents a constant real-valued object.
Container class to hold N-dimensional binned data.
const RooArgSet * get() const override
Get bin centre of current bin.
JSONNode & append_child()
JSONNode const * find(std::string const &key) const
Joins several RooAbsCategoryLValue objects into a single category.
Persistable container for RooFit projects.
RooCategory * cat(RooStringView name) const
Retrieve discrete variable (RooCategory) with given name. A null pointer is returned if not found.
const char * GetName() const override
Returns name of object.