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 #include "RooSpan.h"
24 
25 #include <memory>
26 #include <vector>
27 #include <string>
28 
29 namespace BatchHelpers {
30  struct RunContext;
31 }
32 class RooAbsReal;
33 
34 class RooFormula : public TNamed, public RooPrintable {
35 public:
36  // Constructors etc.
37  RooFormula() ;
38  RooFormula(const char* name, const char* formula, const RooArgList& varList, bool checkVariables = true);
39  RooFormula(const RooFormula& other, const char* name=0);
40  virtual TObject* Clone(const char* newName = nullptr) const {return new RooFormula(*this, newName);}
41 
42  ////////////////////////////////////////////////////////////////////////////////
43  /// Return list of arguments which are used in the formula.
45  Bool_t changeDependents(const RooAbsCollection& newDeps, Bool_t mustReplaceAll, Bool_t nameChange) ;
46 
47  /// Return pointer to the parameter with given name.
48  /// \return Parameter if in use, nullptr if not in use.
49  RooAbsArg* getParameter(const char* name) const {
50  return usedVariables().find(name);
51  }
52 
53  /// Return pointer to parameter at given index. This returns
54  /// irrespective of whether the parameter is in use.
55  RooAbsArg* getParameter(Int_t index) const {
56  return _origList.at(index);
57  }
58 
59  Bool_t ok() const { return _tFormula != nullptr; }
60  /// Evalute all parameters/observables, and then evaluate formula.
61  Double_t eval(const RooArgSet* nset=0) const;
62  RooSpan<double> evaluateSpan(const RooAbsReal* dataOwner, BatchHelpers::RunContext& inputData, const RooArgSet* nset = nullptr) const;
63 
64  /// DEBUG: Dump state information
65  void dump() const;
66  Bool_t reCompile(const char* newFormula) ;
67 
68 
69  virtual void printValue(std::ostream& os) const ;
70  virtual void printName(std::ostream& os) const ;
71  virtual void printTitle(std::ostream& os) const ;
72  virtual void printClassName(std::ostream& os) const ;
73  virtual void printArgs(std::ostream& os) const ;
74  void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;
75 
76  virtual void Print(Option_t *options= 0) const {
77  // Printing interface (human readable)
79  }
80 
81  std::string formulaString() const {
82  return _tFormula ? _tFormula->GetTitle() : "";
83  }
84 
85 private:
87  std::string processFormula(std::string origFormula) const;
88  RooArgList usedVariables() const;
89  std::string reconstructFormula(std::string internalRepr) const;
90  void installFormulaOrThrow(const std::string& formulaa);
91 
92  RooArgList _origList; //! Original list of dependents
93  std::vector<bool> _isCategory; //! Whether an element of the _origList is a category.
94  std::unique_ptr<TFormula> _tFormula; //! The formula used to compute values
95 
97 };
98 
99 #endif
RooFormula::installFormulaOrThrow
void installFormulaOrThrow(const std::string &formulaa)
Check that the formula compiles, and also fulfills the assumptions.
Definition: RooFormula.cxx:479
RooFormula
RooFormula internally uses ROOT's TFormula to compute user-defined expressions of RooAbsArgs.
Definition: RooFormula.h:34
RooFormula::getParameter
RooAbsArg * getParameter(const char *name) const
Return pointer to the parameter with given name.
Definition: RooFormula.h:49
Option_t
const char Option_t
Definition: RtypesCore.h:66
RooArgSet.h
RooFormula::evaluateSpan
RooSpan< double > evaluateSpan(const RooAbsReal *dataOwner, BatchHelpers::RunContext &inputData, const RooArgSet *nset=nullptr) const
Definition: RooFormula.cxx:370
RooFormula::RooFormula
RooFormula()
Default constructor coverity[UNINIT_CTOR].
Definition: RooFormula.cxx:99
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooFormula::_isCategory
std::vector< bool > _isCategory
Original list of dependents.
Definition: RooFormula.h:93
RooFormula::usedVariables
RooArgList usedVariables() const
Analyse internal formula to find out which variables are actually in use.
Definition: RooFormula.cxx:231
RooPrintable.h
RooAbsCollection::find
RooAbsArg * find(const char *name) const
Find object with given name in list.
Definition: RooAbsCollection.cxx:813
RooFormula::dump
void dump() const
DEBUG: Dump state information.
Definition: RooFormula.cxx:297
RooFormula::printTitle
virtual void printTitle(std::ostream &os) const
Print title of formula.
Definition: RooFormula.cxx:448
indent
static void indent(ostringstream &buf, int indent_level)
Definition: TClingCallFunc.cxx:87
RooAbsReal
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:61
RooArgList::at
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition: RooArgList.h:70
TString
Basic string class.
Definition: TString.h:136
RooPrintable
RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and printing methods.
Definition: RooPrintable.h:25
bool
BatchHelpers::RunContext
Data that has to be passed around when evaluating functions / PDFs.
Definition: RunContext.h:32
RooFormula::_origList
RooArgList _origList
Definition: RooFormula.h:92
RooFormula::_tFormula
std::unique_ptr< TFormula > _tFormula
Whether an element of the _origList is a category.
Definition: RooFormula.h:94
RooFormula::formulaString
std::string formulaString() const
Definition: RooFormula.h:81
BatchHelpers
Definition: RooFitComputeInterface.h:9
RooFormula::changeDependents
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:308
RooPrintable::defaultPrintContents
virtual Int_t defaultPrintContents(Option_t *opt) const
Default choice of contents to be printed (name and value)
Definition: RooPrintable.cxx:233
RooFormula::Print
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: RooFormula.h:76
RooFormula::ok
Bool_t ok() const
Definition: RooFormula.h:59
RooPrintable::defaultPrintStream
static std::ostream & defaultPrintStream(std::ostream *os=0)
Return a reference to the current default stream to use in Print().
Definition: RooPrintable.cxx:272
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooFormula::printValue
virtual void printValue(std::ostream &os) const
Print value of formula.
Definition: RooFormula.cxx:430
RooFormula::reCompile
Bool_t reCompile(const char *newFormula)
Recompile formula with new expression.
Definition: RooFormula.cxx:283
RooFormula::reconstructFormula
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:261
RooAbsCollection
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
Definition: RooAbsCollection.h:31
RooFormula::operator=
RooFormula & operator=(const RooFormula &other)
RooFormula::printName
virtual void printName(std::ostream &os) const
Print name of formula.
Definition: RooFormula.cxx:439
RooFormula::actualDependents
RooArgSet actualDependents() const
Return list of arguments which are used in the formula.
Definition: RooFormula.h:44
RooFormula::processFormula
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:156
Double_t
double Double_t
Definition: RtypesCore.h:59
RooFormula::Clone
virtual TObject * Clone(const char *newName=nullptr) const
Make a clone of an object using the Streamer facility.
Definition: RooFormula.h:40
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
RooFormula::getParameter
RooAbsArg * getParameter(Int_t index) const
Return pointer to parameter at given index.
Definition: RooFormula.h:55
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
name
char name[80]
Definition: TGX11.cxx:110
RooPrintable::printStream
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,...
Definition: RooPrintable.cxx:75
genreflex::verbose
bool verbose
Definition: rootcling_impl.cxx:133
RooFormula::printMultiline
void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Printing interface.
Definition: RooFormula.cxx:416
RooAbsArg
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
RooSpan.h
RooFormula::printClassName
virtual void printClassName(std::ostream &os) const
Print class name of formula.
Definition: RooFormula.cxx:457
RooPrintable::defaultPrintStyle
virtual StyleOption defaultPrintStyle(Option_t *opt) const
Definition: RooPrintable.cxx:241
RooFormula::eval
Double_t eval(const RooArgSet *nset=0) const
Evalute all parameters/observables, and then evaluate formula.
Definition: RooFormula.cxx:344
RooArgList.h
RooFormula::printArgs
virtual void printArgs(std::ostream &os) const
Print arguments of formula, i.e. dependents that are actually used.
Definition: RooFormula.cxx:466
RooSpan
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29
int