25std::optional<double>
toNumber(
const std::string &str)
29 std::istringstream stream(str);
31 return (stream >>
value) && stream.eof() ? std::optional<double>{
value} : std::nullopt;
44 node << static_cast<RooConstVar const &>(arg).getVal();
50bool startsWith(std::string_view str, std::string_view prefix)
52 return str.size() >= prefix.size() && 0 == str.compare(0, prefix.size(), prefix);
55bool endsWith(std::string_view str, std::string_view suffix)
57 return str.size() >= suffix.size() && 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix);
60std::string
removeSuffix(std::string_view str, std::string_view suffix)
64 out = out.substr(0, out.length() - suffix.length());
70constexpr std::string_view literalPrefix =
"const_";
73std::string shortestNumber(
double value)
76 for (
int precision = 1; precision <= 17; ++precision) {
77 std::snprintf(buffer,
sizeof(buffer),
"%.*g", precision,
value);
78 if (std::strtod(buffer,
nullptr) ==
value) {
86std::string numberOfLiteralIdentifier(std::string_view
name)
92 for (
char c :
name.substr(literalPrefix.
size())) {
95 }
else if (
c ==
'm') {
97 }
else if (std::isdigit(
static_cast<unsigned char>(
c)) ||
c ==
'e') {
104 std::strtod(number.c_str(), &end);
105 return end == number.c_str() + number.size() ? number :
"";
116 const std::string number = shortestNumber(param.
getVal());
117 return number[0] ==
'-' ?
"(" + number +
")" : number;
125 std::string out{literalPrefix};
126 for (
char c : shortestNumber(param.
getVal())) {
129 }
else if (
c ==
'-') {
131 }
else if (
c !=
'+') {
140 return !numberOfLiteralIdentifier(
name).empty();
146 const std::string number = numberOfLiteralIdentifier(base);
147 return number.empty() ? base : number;
154 std::vector<std::size_t> nBins;
156 nBins.push_back(
static_cast<std::size_t
>(
dynamic_cast<RooAbsLValue const &
>(*var).
numBins()));
163std::size_t th1Position(std::size_t k, std::vector<std::size_t>
const &nBins)
166 std::size_t stride = 1;
167 std::vector<std::size_t> indices(nBins.size());
168 for (std::size_t j = nBins.size(); j-- > 0;) {
169 indices[j] = k % nBins[j];
172 for (std::size_t j = 0; j < nBins.size(); ++j) {
173 th1 += indices[j] * stride;
181std::unique_ptr<RooArgSet>
184 auto out = std::make_unique<RooArgSet>();
186 std::string
name = var->GetName();
187 for (std::size_t i = 0; i < histObs.
size() && i < funcObs.
size(); ++i) {
188 if (
name == histObs[i]->GetName() &&
dynamic_cast<RooAbsLValue const *
>(funcObs[i])) {
193 out->addOwned(std::unique_ptr<RooAbsArg>{
static_cast<RooAbsArg *
>(var->clone(
name.c_str()))});
200 std::vector<RooAbsReal *> out;
201 for (
int k = 0; k < func.
numBins(); ++k) {
209 const std::vector<std::size_t> nBins = numBinsPerVariable(vars);
210 std::vector<RooAbsArg *> th1Order(paramsInBinOrder.
size(),
nullptr);
211 for (std::size_t k = 0; k < paramsInBinOrder.
size(); ++k) {
212 const std::size_t t = th1Position(k, nBins);
213 if (t >= th1Order.size()) {
216 th1Order[t] = paramsInBinOrder.
at(k);
226 std::string
const &context)
230 " has a multi-dimensional binning. Documents before HS3 0.3 don't define the order "
231 "of its per-bin parameters (RooFit wrote them in TH1 order, while the bin "
232 "contents use the order of HS3 0.3, last axis fastest). Please re-export the "
233 "workspace with a newer ROOT version.");
239void sortByName(std::vector<RooCategory const *> &columns)
241 std::sort(columns.begin(), columns.end(),
249 std::vector<RooCategory const *> columns;
250 auto addColumn = [&](
RooAbsArg const &arg) {
251 auto *cat =
dynamic_cast<RooCategory const *
>(&arg);
254 ", but only a RooCategory or a RooSuperCategory of RooCategories " +
255 "can be written as the columns of a combined distribution");
257 columns.push_back(cat);
272 std::vector<RooCategory const *> columns;
274 if (
auto *cat =
dynamic_cast<RooCategory const *
>(arg)) {
275 columns.push_back(cat);
282std::vector<std::vector<std::string>>
selectionKeys(std::vector<RooCategory const *>
const &columns)
284 std::vector<std::vector<std::string>> keys{{}};
286 std::vector<std::vector<std::string>> next;
287 for (
auto const &key : keys) {
288 for (
unsigned int i = 0; i < column->size(); ++i) {
290 next.back().push_back(column->getOrdinal(i).first);
293 keys = std::move(next);
300 if (key.size() == 1) {
303 std::string label =
"{";
304 for (std::size_t i = 0; i < key.size(); ++i) {
305 label += (i == 0 ?
"" :
";") + key[i];
312 std::string out =
"[";
313 for (std::size_t i = 0; i < key.size(); ++i) {
314 out += (i == 0 ?
"\"" :
", \"") + key[i] +
"\"";
320 std::vector<std::string>
const &key)
326 std::vector<std::string> inInputOrder;
328 auto found = std::find_if(columns.begin(), columns.end(),
329 [&](
RooCategory const *
c) { return std::strcmp(c->GetName(), input->GetName()) == 0; });
330 inInputOrder.push_back(key[found - columns.begin()]);
std::optional< double > toNumber(const std::string &str)
void checkParamHistFuncOrderIsDefined(RooFit::HS3::Version const &version, RooAbsCollection const &vars, std::string const &context)
std::vector< std::vector< std::string > > selectionKeys(std::vector< RooCategory const * > const &columns)
void writeReference(JSONNode &node, RooAbsArg const &arg)
std::string transformedOriginal(std::string_view name, std::string_view suffix)
bool isLiteralIdentifier(std::string_view name)
std::string transformedBaseName(RooAbsReal const ¶m)
std::vector< RooCategory const * > selectionColumns(RooAbsCategory const &indexCat)
std::vector< RooAbsReal * > paramHistFuncParamsInBinOrder(ParamHistFunc const &func)
std::string transformedArgument(RooAbsReal const ¶m)
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)
bool endsWith(std::string_view str, std::string_view suffix)
std::string selectionLabel(std::vector< std::string > const &key)
bool isLiteralConstVar(RooAbsArg const &arg)
std::string removeSuffix(std::string_view str, std::string_view suffix)
std::unique_ptr< RooArgSet > histogramVariablesNamedAfterObservables(RooDataHist const &dh, RooArgSet const &histObs, RooArgSet const &funcObs)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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 value
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.
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
Abstract base class for objects that represent a real value and implements functionality common to al...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
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.
Joins several RooAbsCategoryLValue objects into a single category.
const char * GetName() const override
Returns name of object.