Logo ROOT  
Reference Guide
Go to the documentation of this file.
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
19#include "RooPrintable.h"
20#include "RooArgList.h"
21#include "RooArgSet.h"
25#include "TFormula.h"
27#include <memory>
28#include <vector>
29#include <string>
31class RooAbsReal;
33class RooFormula : public TNamed, public RooPrintable {
35 // Constructors etc.
36 RooFormula() ;
37 RooFormula(const char* name, const char* formula, const RooArgList& varList, bool checkVariables = true);
38 RooFormula(const RooFormula& other, const char* name=nullptr);
39 TObject* Clone(const char* newName = nullptr) const override {return new RooFormula(*this, newName);}
41 ////////////////////////////////////////////////////////////////////////////////
42 /// Return list of arguments which are used in the formula.
44 bool changeDependents(const RooAbsCollection& newDeps, bool mustReplaceAll, bool nameChange) ;
46 /// Return pointer to the parameter with given name.
47 /// \return Parameter if in use, nullptr if not in use.
48 RooAbsArg* getParameter(const char* name) const {
49 return usedVariables().find(name);
50 }
52 /// Return pointer to parameter at given index. This returns
53 /// irrespective of whether the parameter is in use.
55 return _origList.at(index);
56 }
58 bool ok() const { return _tFormula != nullptr; }
59 /// Evalute all parameters/observables, and then evaluate formula.
60 double eval(const RooArgSet* nset=nullptr) const;
61 RooSpan<double> evaluateSpan(const RooAbsReal* dataOwner, RooBatchCompute::RunContext& inputData, const RooArgSet* nset = nullptr) const;
62 void computeBatch(cudaStream_t*, double* output, size_t nEvents, RooFit::Detail::DataMap const&) const;
64 /// DEBUG: Dump state information
65 void dump() const;
66 bool reCompile(const char* newFormula) ;
69 void printValue(std::ostream& os) const override ;
70 void printName(std::ostream& os) const override ;
71 void printTitle(std::ostream& os) const override ;
72 void printClassName(std::ostream& os) const override ;
73 void printArgs(std::ostream& os) const override ;
74 void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent="") const override ;
76 void Print(Option_t *options= nullptr) const override {
77 // Printing interface (human readable)
79 }
81 std::string formulaString() const {
82 return _tFormula ? _tFormula->GetTitle() : "";
83 }
87 std::string processFormula(std::string origFormula) const;
89 std::string reconstructFormula(std::string internalRepr) const;
90 void installFormulaOrThrow(const std::string& formulaa);
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
const char Option_t
Definition: RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
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
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
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.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:62
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:56
RooFormula internally uses ROOT's TFormula to compute user-defined expressions of RooAbsArgs.
Definition: RooFormula.h:33
std::string formulaString() const
Definition: RooFormula.h:81
void printTitle(std::ostream &os) const override
Print title of formula.
Definition: RooFormula.cxx:550
RooFormula & operator=(const RooFormula &other)
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Printing interface.
Definition: RooFormula.cxx:518
void computeBatch(cudaStream_t *, double *output, size_t nEvents, RooFit::Detail::DataMap const &) const
Definition: RooFormula.cxx:500
RooArgSet actualDependents() const
Return list of arguments which are used in the formula.
Definition: RooFormula.h:43
RooArgList usedVariables() const
Analyse internal formula to find out which variables are actually in use.
Definition: RooFormula.cxx:319
RooSpan< double > evaluateSpan(const RooAbsReal *dataOwner, RooBatchCompute::RunContext &inputData, const RooArgSet *nset=nullptr) const
Definition: RooFormula.cxx:457
void Print(Option_t *options=nullptr) const override
Print TNamed name and title.
Definition: RooFormula.h:76
bool reCompile(const char *newFormula)
Recompile formula with new expression.
Definition: RooFormula.cxx:370
bool ok() const
Definition: RooFormula.h:58
Default constructor coverity[UNINIT_CTOR].
Definition: RooFormula.cxx:195
void printValue(std::ostream &os) const override
Print value of formula.
Definition: RooFormula.cxx:532
void printName(std::ostream &os) const override
Print name of formula.
Definition: RooFormula.cxx:541
RooAbsArg * getParameter(const char *name) const
Return pointer to the parameter with given name.
Definition: RooFormula.h:48
RooAbsArg * getParameter(Int_t index) const
Return pointer to parameter at given index.
Definition: RooFormula.h:54
TObject * Clone(const char *newName=nullptr) const override
Make a clone of an object using the Streamer facility.
Definition: RooFormula.h:39
void installFormulaOrThrow(const std::string &formulaa)
Check that the formula compiles, and also fulfills the assumptions.
Definition: RooFormula.cxx:581
void dump() const
DEBUG: Dump state information.
Definition: RooFormula.cxx:384
std::vector< bool > _isCategory
! Whether an element of the _origList is a category.
Definition: RooFormula.h:93
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:257
double eval(const RooArgSet *nset=nullptr) const
Evalute all parameters/observables, and then evaluate formula.
Definition: RooFormula.cxx:431
bool changeDependents(const RooAbsCollection &newDeps, bool mustReplaceAll, bool nameChange)
Change used variables to those with the same name in given list.
Definition: RooFormula.cxx:395
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:349
void printClassName(std::ostream &os) const override
Print class name of formula.
Definition: RooFormula.cxx:559
RooArgList _origList
! Original list of dependents
Definition: RooFormula.h:92
std::unique_ptr< TFormula > _tFormula
! The formula used to compute values
Definition: RooFormula.h:94
void printArgs(std::ostream &os) const override
Print arguments of formula, i.e. dependents that are actually used.
Definition: RooFormula.cxx:568
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=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,...
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
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:136
This struct enables passing computation data around between elements of a computation graph.
Definition: RunContext.h:32
static void output()