Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooFormulaUtils.h
Go to the documentation of this file.
1/// \cond ROOFIT_INTERNAL
2
3/*
4 * Project: RooFit
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#ifndef ROO_FORMULA_UTILS
14#define ROO_FORMULA_UTILS
15
16#include "RooArgList.h"
17#include "RooFit/EvalContext.h"
18
19#include "RooFormulaEvaluator.h"
20
21#include <list>
22#include <map>
23#include <memory>
24#include <string>
25
26class RooAbsBinning;
27class RooAbsReal;
29
30/// Free functions to translate and evaluate user-defined expressions of
31/// RooAbsArgs, as used by RooFormulaVar and RooGenericPdf and for cut
32/// expressions on datasets. See the RooFormulaVar class documentation for the
33/// supported expression dialect (name, `@i` and `x[i]` variable references,
34/// and `cat::state` category state references). processFormula() normalizes
35/// an expression to the `x[i]`-only dialect that the RooFormulaEvaluator
36/// backends understand; the other functions operate on the normalized form.
37namespace RooFormulaUtils {
38
39std::string processFormula(std::string formula, RooArgList const &varList, std::string const &callerName);
40
41std::string reconstructFormula(std::string internalRepr, RooArgList const &args,
42 const char *fixedReplacement = nullptr);
43
44std::unique_ptr<RooFormulaEvaluator> makeEvaluator(std::string const &name, std::string const &processedFormula,
45 std::string const &origFormula, RooArgList const &varList);
46
47std::unique_ptr<RooFormulaEvaluator>
48makeFormulaEvaluator(std::string const &name, std::string const &expression, RooArgList const &varList);
49
50void initFormula(std::unique_ptr<RooFormulaEvaluator> &evaluator, TString &formExpr, RooAbsCollection &actualVars,
51 RooArgList const &dependents, const char *name);
52
53RooFormulaEvaluator &ensureEvaluator(std::unique_ptr<RooFormulaEvaluator> &evaluator, TString &formExpr,
54 RooArgList const &actualVars, const char *name);
55
56std::unique_ptr<RooFormulaEvaluator> cloneEvaluator(RooFormulaEvaluator const &other, const char *newName);
57
58double evalFormula(RooFormulaEvaluator const &evaluator, RooAbsCollection const &vars, RooArgSet const *nset = nullptr);
59
61
62void printFormula(std::ostream &os, TString indent, std::string const &formula, RooArgList const &actualVars);
63
64/// Map of user-defined binnings for a piecewise-flat RooFormulaVar or
65/// RooGenericPdf, keyed by the observable's index in the formula variables.
66/// The functions below implement the binning interface of these two classes.
67using BinningMap = std::map<int, std::unique_ptr<RooAbsBinning>>;
68
70
71void setBinning(BinningMap &binnings, RooAbsReal const &caller, RooArgList const &actualVars, const char *formExpr,
72 RooAbsRealLValue const &obs, RooAbsBinning const &binning, bool checkFlatness);
73
74const RooAbsBinning *getBinning(BinningMap const &binnings, RooArgList const &actualVars, RooAbsRealLValue const &obs);
75
76bool isBinnedDistribution(BinningMap const &binnings, RooArgList const &actualVars, RooArgSet const &obs);
77
78std::list<double> *binBoundaries(BinningMap const &binnings, RooArgList const &actualVars, RooAbsRealLValue const &obs,
79 double xlo, double xhi);
80
81std::list<double> *plotSamplingHint(BinningMap const &binnings, RooArgList const &actualVars,
82 RooAbsRealLValue const &obs, double xlo, double xhi);
83
84} // namespace RooFormulaUtils
85
86#endif
87
88/// \endcond
static void indent(ostringstream &buf, int indent_level)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:142
Abstract base class for RooRealVar binning definitions.
Abstract container object that can hold multiple RooAbsArg objects.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Basic string class.
Definition TString.h:138