Logo ROOT  
Reference Guide
RooFormula.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooFormula.h,v 1.34 2007/05/11 09:11:30 verkerke Exp $
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16#ifndef ROO_FORMULA
17#define ROO_FORMULA
18
19#include "RooPrintable.h"
20#include "RooArgList.h"
21#include "RooArgSet.h"
22#include "TFormula.h"
23
24#include <memory>
25#include <vector>
26#include <string>
27
28class RooFormula : public TNamed, public RooPrintable {
29public:
30 // Constructors etc.
31 RooFormula() ;
32 RooFormula(const char* name, const char* formula, const RooArgList& varList, bool checkVariables = true);
33 RooFormula(const RooFormula& other, const char* name=0);
34 virtual TObject* Clone(const char* newName = nullptr) const {return new RooFormula(*this, newName);}
35
36 ////////////////////////////////////////////////////////////////////////////////
37 /// Return list of arguments which are used in the formula.
39 Bool_t changeDependents(const RooAbsCollection& newDeps, Bool_t mustReplaceAll, Bool_t nameChange) ;
40
41 /// Return pointer to the parameter with given name.
42 /// \return Parameter if in use, nullptr if not in use.
43 RooAbsArg* getParameter(const char* name) const {
44 return usedVariables().find(name);
45 }
46
47 /// Return pointer to parameter at given index. This returns
48 /// irrespective of whether the parameter is in use.
50 return _origList.at(index);
51 }
52
53 Bool_t ok() { return _tFormula != nullptr; }
54 /// Evalute all parameters/observables, and then evaluate formula.
55 Double_t eval(const RooArgSet* nset=0) const;
56
57 /// DEBUG: Dump state information
58 void dump() const;
59 Bool_t reCompile(const char* newFormula) ;
60
61
62 virtual void printValue(std::ostream& os) const ;
63 virtual void printName(std::ostream& os) const ;
64 virtual void printTitle(std::ostream& os) const ;
65 virtual void printClassName(std::ostream& os) const ;
66 virtual void printArgs(std::ostream& os) const ;
67 void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;
68
69 virtual void Print(Option_t *options= 0) const {
70 // Printing interface (human readable)
72 }
73
74 std::string formulaString() const {
75 return _tFormula ? _tFormula->GetTitle() : "";
76 }
77
78private:
80 std::string processFormula(std::string origFormula) const;
82 std::string reconstructFormula(std::string internalRepr) const;
83 std::vector<bool> findCategoryServers(const RooAbsCollection& collection) const;
84
85 RooArgList _origList; //! Original list of dependents
86 std::vector<bool> _isCategory; //! Whether an element of the _origList is a category.
87 std::unique_ptr<TFormula> _tFormula; //! The formula used to compute values
88
90};
91
92#endif
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:326
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition: TGX11.cxx:109
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:71
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition: RooArgList.h:74
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooFormula internally uses ROOT's TFormula to compute user-defined expressions of RooAbsArgs.
Definition: RooFormula.h:28
Bool_t reCompile(const char *newFormula)
Recompile formula with new expression.
Definition: RooFormula.cxx:290
std::string formulaString() const
Definition: RooFormula.h:74
Bool_t ok()
Definition: RooFormula.h:53
RooFormula & operator=(const RooFormula &other)
virtual void printName(std::ostream &os) const
Print name of formula.
Definition: RooFormula.cxx:404
virtual void printTitle(std::ostream &os) const
Print title of formula.
Definition: RooFormula.cxx:413
virtual void printClassName(std::ostream &os) const
Print class name of formula.
Definition: RooFormula.cxx:422
RooArgSet actualDependents() const
Return list of arguments which are used in the formula.
Definition: RooFormula.h:38
RooArgList usedVariables() const
Analyse internal formula to find out which variables are actually in use.
Definition: RooFormula.cxx:227
virtual TObject * Clone(const char *newName=nullptr) const
Make a clone of an object using the Streamer facility.
Definition: RooFormula.h:34
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: RooFormula.h:69
std::vector< bool > findCategoryServers(const RooAbsCollection &collection) const
Find all input arguments which are categories, and save this information in with the names of the var...
Definition: RooFormula.cxx:276
virtual void printValue(std::ostream &os) const
Print value of formula.
Definition: RooFormula.cxx:395
RooFormula()
Default constructor coverity[UNINIT_CTOR].
Definition: RooFormula.cxx:77
Double_t eval(const RooArgSet *nset=0) const
Evalute all parameters/observables, and then evaluate formula.
Definition: RooFormula.cxx:352
RooAbsArg * getParameter(const char *name) const
Return pointer to the parameter with given name.
Definition: RooFormula.h:43
RooAbsArg * getParameter(Int_t index) const
Return pointer to parameter at given index.
Definition: RooFormula.h:49
void dump() const
DEBUG: Dump state information.
Definition: RooFormula.cxx:305
std::vector< bool > _isCategory
Original list of dependents.
Definition: RooFormula.h:86
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...
Definition: RooFormula.cxx:152
void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Printing interface.
Definition: RooFormula.cxx:381
virtual void printArgs(std::ostream &os) const
Print arguments of formula, i.e. dependents that are actually used.
Definition: RooFormula.cxx:431
std::string reconstructFormula(std::string internalRepr) const
From the internal representation, construct a formula by replacing all index place holders with the n...
Definition: RooFormula.cxx:257
RooArgList _origList
Definition: RooFormula.h:85
Bool_t changeDependents(const RooAbsCollection &newDeps, Bool_t mustReplaceAll, Bool_t nameChange)
Change used variables to those with the same name in given list.
Definition: RooFormula.cxx:316
std::unique_ptr< TFormula > _tFormula
Whether an element of the _origList is a category.
Definition: RooFormula.h:87
RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and printing methods.
Definition: RooPrintable.h:25
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=0)
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 TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:131