Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooFormula.h
Go to the documentation of this file.
1/// \cond ROOFIT_INTERNAL
2
3/*
4 * Project: RooFit
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#ifndef ROO_FORMULA
14#define ROO_FORMULA
15
16#include "RooPrintable.h"
17#include "RooArgList.h"
18#include "RooArgSet.h"
19#include "RooFit/EvalContext.h"
20
21#include "TFormula.h"
22
23#include <memory>
24#include <vector>
25#include <string>
26
27class RooAbsReal;
28
29class RooFormula : public TNamed, public RooPrintable {
30public:
31 // Constructors etc.
32 RooFormula(const char *name, const char *formula, const RooArgList &varList, bool checkVariables = true);
33 RooFormula(const RooFormula &other, const char *name = nullptr);
34 TObject *Clone(const char *newName = nullptr) const override { return new RooFormula(*this, newName); }
35
36 RooFormula &operator=(const RooFormula &other) = delete;
38
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Return list of arguments which are used in the formula.
41 RooArgSet actualDependents() const { return usedVariables(); }
43
44 /// Return pointer to the parameter with given name.
45 /// \return Parameter if in use, nullptr if not in use.
46 RooAbsArg *getParameter(const char *name) const { return usedVariables().find(name); }
47
48 /// Return pointer to parameter at given index. This returns
49 /// irrespective of whether the parameter is in use.
50 RooAbsArg *getParameter(Int_t index) const { return _origList.at(index); }
51
52 bool ok() const { return _tFormula != nullptr; }
53 /// Evaluate all parameters/observables, and then evaluate formula.
54 double eval(const RooArgSet *nset = nullptr) const;
55 void doEval(RooFit::EvalContext &) const;
56
57 /// DEBUG: Dump state information
58 void dump() const;
59
60 void printValue(std::ostream &os) const override;
61 void printName(std::ostream &os) const override;
62 void printTitle(std::ostream &os) const override;
63 void printClassName(std::ostream &os) const override;
64 void printArgs(std::ostream &os) const override;
65 void printMultiline(std::ostream &os, Int_t contents, bool verbose = false, TString indent = "") const override;
66
67 void Print(Option_t *options = nullptr) const override
68 {
69 // Printing interface (human readable)
70 printStream(defaultPrintStream(), defaultPrintContents(options), defaultPrintStyle(options));
71 }
72
73 std::string formulaString() const { return _tFormula ? _tFormula->GetTitle() : ""; }
74 TFormula* getTFormula() const { return _tFormula.get(); }
75
76private:
77 std::string processFormula(std::string origFormula) const;
79 std::string reconstructFormula(std::string internalRepr) const;
80 void installFormulaOrThrow(const std::string &formulaa);
81
82 RooArgList _origList; ///<! Original list of dependents
83 std::vector<bool> _isCategory; ///<! Whether an element of the _origList is a category.
84 std::unique_ptr<TFormula> _tFormula; ///<! The formula used to compute values
85};
86
87#endif
88
89/// \endcond
int Int_t
Definition RtypesCore.h:45
const char Option_t
Definition RtypesCore.h:66
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.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
char name[80]
Definition TGX11.cxx:110
Binding & operator=(OUT(*fun)(void))
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
Abstract container object that can hold multiple RooAbsArg objects.
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
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
A 'mix-in' base class that define the standard RooFit plotting and printing methods.
The Formula class.
Definition TFormula.h:89
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:139
void Print(std::ostream &os, const OptionType &opt)