Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooFormula.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 *
4 * Copyright (c) 2023, CERN
5 *
6 * Redistribution and use in source and binary forms,
7 * with or without modification, are permitted according to the terms
8 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
9 */
10
11#ifndef ROO_FORMULA
12#define ROO_FORMULA
13
14#include "RooPrintable.h"
15#include "RooArgList.h"
16#include "RooArgSet.h"
17#include "RooFit/EvalContext.h"
18
19#include "TFormula.h"
20
21#include <memory>
22#include <vector>
23#include <string>
24
25class RooAbsReal;
26
27class RooFormula : public TNamed, public RooPrintable {
28public:
29 // Constructors etc.
30 RooFormula(const char *name, const char *formula, const RooArgList &varList, bool checkVariables = true);
31 RooFormula(const RooFormula &other, const char *name = nullptr);
32 TObject *Clone(const char *newName = nullptr) const override { return new RooFormula(*this, newName); }
33
34 RooFormula &operator=(const RooFormula &other) = delete;
35 RooFormula &operator=(RooFormula &&other) = delete;
36
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Return list of arguments which are used in the formula.
40 bool changeDependents(const RooAbsCollection &newDeps, bool mustReplaceAll, bool nameChange);
41
42 /// Return pointer to the parameter with given name.
43 /// \return Parameter if in use, nullptr if not in use.
44 RooAbsArg *getParameter(const char *name) const { return usedVariables().find(name); }
45
46 /// Return pointer to parameter at given index. This returns
47 /// irrespective of whether the parameter is in use.
49
50 bool ok() const { return _tFormula != nullptr; }
51 /// Evaluate all parameters/observables, and then evaluate formula.
52 double eval(const RooArgSet *nset = nullptr) const;
53 void doEval(RooFit::EvalContext &) const;
54
55 /// DEBUG: Dump state information
56 void dump() const;
57
58 void printValue(std::ostream &os) const override;
59 void printName(std::ostream &os) const override;
60 void printTitle(std::ostream &os) const override;
61 void printClassName(std::ostream &os) const override;
62 void printArgs(std::ostream &os) const override;
63 void printMultiline(std::ostream &os, Int_t contents, bool verbose = false, TString indent = "") const override;
64
65 void Print(Option_t *options = nullptr) const override
66 {
67 // Printing interface (human readable)
69 }
70
71 std::string formulaString() const { return _tFormula ? _tFormula->GetTitle() : ""; }
72 TFormula* getTFormula() const { return _tFormula.get(); }
73
74private:
75 std::string processFormula(std::string origFormula) const;
77 std::string reconstructFormula(std::string internalRepr) const;
78 void installFormulaOrThrow(const std::string &formulaa);
79
80 RooArgList _origList; ///<! Original list of dependents
81 std::vector<bool> _isCategory; ///<! Whether an element of the _origList is a category.
82 std::unique_ptr<TFormula> _tFormula; ///<! The formula used to compute values
83};
84
85#endif
const char Option_t
Definition RtypesCore.h:66
static void indent(ostringstream &buf, int indent_level)
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
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:79
Abstract container object that can hold multiple RooAbsArg objects.
RooAbsArg * find(const char *name) const
Find object with given name in list.
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
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition RooArgList.h:110
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Internally uses ROOT's TFormula to compute user-defined expressions of RooAbsArgs.
Definition RooFormula.h:27
TFormula * getTFormula() const
Definition RooFormula.h:72
std::string formulaString() const
Definition RooFormula.h:71
void printTitle(std::ostream &os) const override
Print title of formula.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Printing interface.
RooArgSet actualDependents() const
Return list of arguments which are used in the formula.
Definition RooFormula.h:39
RooArgList usedVariables() const
Analyse internal formula to find out which variables are actually in use.
RooFormula & operator=(const RooFormula &other)=delete
void Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
Definition RooFormula.h:65
bool ok() const
Definition RooFormula.h:50
void printValue(std::ostream &os) const override
Print value of formula.
void printName(std::ostream &os) const override
Print name of formula.
RooAbsArg * getParameter(const char *name) const
Return pointer to the parameter with given name.
Definition RooFormula.h:44
RooAbsArg * getParameter(Int_t index) const
Return pointer to parameter at given index.
Definition RooFormula.h:48
TObject * Clone(const char *newName=nullptr) const override
Make a clone of an object using the Streamer facility.
Definition RooFormula.h:32
void installFormulaOrThrow(const std::string &formulaa)
Check that the formula compiles, and also fulfills the assumptions.
void dump() const
DEBUG: Dump state information.
RooFormula & operator=(RooFormula &&other)=delete
std::vector< bool > _isCategory
! Whether an element of the _origList is a category.
Definition RooFormula.h:81
std::string processFormula(std::string origFormula) const
Process given formula by replacing all ordinal and name references by x[i], where i matches the posit...
double eval(const RooArgSet *nset=nullptr) const
Evaluate all parameters/observables, and then evaluate formula.
bool changeDependents(const RooAbsCollection &newDeps, bool mustReplaceAll, bool nameChange)
Change used variables to those with the same name in given list.
std::string reconstructFormula(std::string internalRepr) const
From the internal representation, construct a formula by replacing all index place holders with the n...
void printClassName(std::ostream &os) const override
Print class name of formula.
RooArgList _origList
! Original list of dependents
Definition RooFormula.h:80
void doEval(RooFit::EvalContext &) const
std::unique_ptr< TFormula > _tFormula
! The formula used to compute values
Definition RooFormula.h:82
void printArgs(std::ostream &os) const override
Print arguments of formula, i.e. dependents that are actually used.
A 'mix-in' base class that define the standard RooFit plotting and printing methods.
virtual StyleOption defaultPrintStyle(Option_t *opt) const
virtual Int_t defaultPrintContents(Option_t *opt) const
Default choice of contents to be printed (name and value)
static std::ostream & defaultPrintStream(std::ostream *os=nullptr)
Return a reference to the current default stream to use in Print().
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer,...
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