Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooGenericPdf.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
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
17/**
18\file RooGenericPdf.cxx
19\class RooGenericPdf
20\ingroup Roofitcore
21
22Implementation of a probability density function
23that takes a RooArgList of servers and a C++ expression string defining how
24its value should be calculated from the given list of servers.
25A fully numerical integration is automatically performed to normalize the given
26expression. RooGenericPdf uses a RooFormula object to perform the expression evaluation.
27
28The string expression can be any valid TFormula expression referring to the
29listed servers either by name or by their ordinal list position. These three are
30equivalent:
31```
32 RooFormulaVar("gen", "x*y", RooArgList(x,y)) // reference by name
33 RooFormulaVar("gen", "@0*@1", RooArgList(x,y)) // reference by ordinal with @
34 RooFormulaVar("gen", "x[0]*x[1]", RooArgList(x,y)) // TFormula-builtin reference by ordinal
35```
36Note that `x[i]` is an expression reserved for TFormula. All variable references
37are automatically converted to the TFormula-native format. If a variable with
38the name `x` is given, the RooFormula interprets `x[i]` as a list position,
39but `x` without brackets as the name of a RooFit object.
40
41The last two versions, while slightly less readable, are more versatile because
42the names of the arguments are not hard coded.
43**/
44
45#include "RooGenericPdf.h"
46#include "Riostream.h"
47#include "RooStreamParser.h"
48#include "RooMsgService.h"
49#include "RooArgList.h"
50#include "RooFormula.h"
51
52using std::istream, std::ostream, std::endl;
53
54
56
61
62
63////////////////////////////////////////////////////////////////////////////////
64/// Constructor with formula expression and list of input variables
65
66RooGenericPdf::RooGenericPdf(const char *name, const char *title, const RooArgList& dependents) :
67 RooAbsPdf(name,title),
68 _actualVars("actualVars","Variables used by PDF expression",this),
69 _formExpr(title)
70{
71 if (dependents.empty()) {
72 _value = traceEval(nullptr);
73 } else {
75 _formExpr = _formula->formulaString().c_str();
77 }
78}
79
80
81
82////////////////////////////////////////////////////////////////////////////////
83/// Constructor with a name, title, formula expression and a list of variables
84
85RooGenericPdf::RooGenericPdf(const char *name, const char *title,
86 const char* inFormula, const RooArgList& dependents) :
87 RooAbsPdf(name,title),
88 _actualVars("actualVars","Variables used by PDF expression",this),
89 _formExpr(inFormula)
90{
91 if (dependents.empty()) {
92 _value = traceEval(nullptr);
93 } else {
95 _formExpr = _formula->formulaString().c_str();
97 }
98}
99
100
101
102////////////////////////////////////////////////////////////////////////////////
103/// Copy constructor
104
107 _actualVars("actualVars",this,other._actualVars),
108 _formExpr(other._formExpr)
109{
110 formula();
111}
112
113
114////////////////////////////////////////////////////////////////////////////////
115
117{
118 if (!_formula) {
120 const_cast<TString&>(_formExpr) = _formula->formulaString().c_str();
121 }
122 return *_formula ;
123}
124
125
126
127////////////////////////////////////////////////////////////////////////////////
128/// Calculate current value of this object
129
131{
132 return formula().eval(_actualVars.nset()) ;
133}
134
135
136////////////////////////////////////////////////////////////////////////////////
138{
139 formula().doEval(ctx);
140}
141
142
143////////////////////////////////////////////////////////////////////////////////
144/// Propagate server changes to embedded formula object
145
151
152
153
154////////////////////////////////////////////////////////////////////////////////
155/// Print info about this object to the specified stream.
156
157void RooGenericPdf::printMultiline(ostream& os, Int_t content, bool verbose, TString indent) const
158{
160 if (verbose) {
161 os << " --- RooGenericPdf --- " << std::endl ;
162 indent.Append(" ");
163 os << indent ;
164 formula().printMultiline(os,content,verbose,indent);
165 }
166}
167
168
169
170////////////////////////////////////////////////////////////////////////////////
171/// Add formula expression as meta argument in printing interface
172
173void RooGenericPdf::printMetaArgs(ostream& os) const
174{
175 os << "formula=\"" << _formExpr << "\" " ;
176}
177
178
180
181
182////////////////////////////////////////////////////////////////////////////////
183/// Read object contents from given stream
184
185bool RooGenericPdf::readFromStream(istream& /*is*/, bool /*compact*/, bool /*verbose*/)
186{
187 coutE(InputArguments) << "RooGenericPdf::readFromStream(" << GetName() << "): can't read" << std::endl;
188 return true;
189}
190
191
192////////////////////////////////////////////////////////////////////////////////
193/// Write object contents to given stream
194
195void RooGenericPdf::writeToStream(ostream& os, bool compact) const
196{
197 if (compact) {
198 os << getVal() << std::endl ;
199 } else {
200 os << GetTitle() ;
201 }
202}
203
205{
207}
#define coutE(a)
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition TGX11.cxx:110
Abstract container object that can hold multiple RooAbsArg objects.
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print multi line detailed information of this RooAbsPdf.
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursiveStep) override
The cache manager.
const RooArgSet * nset() const
Definition RooAbsProxy.h:52
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
double _value
Cache for current value of object.
Definition RooAbsReal.h:535
double traceEval(const RooArgSet *set) const
Calculate current value of object, with error tracing wrapper.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
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 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
void dump() const
DEBUG: Dump state information.
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.
void doEval(RooFit::EvalContext &) const
Implementation of a probability density function that takes a RooArgList of servers and a C++ express...
double evaluate() const override
Calculate current value of this object.
~RooGenericPdf() override
bool readFromStream(std::istream &is, bool compact, bool verbose=false) override
Read object contents from given stream.
const RooArgList & dependents() const
void printMetaArgs(std::ostream &os) const override
Add formula expression as meta argument in printing interface.
std::string getUniqueFuncName() const
RooListProxy _actualVars
void writeToStream(std::ostream &os, bool compact) const override
Write object contents to given stream.
RooFormula * _formula
! Formula engine
RooFormula & formula() const
TString _formExpr
Formula expression string.
void doEval(RooFit::EvalContext &) const override
Base function for computing multiple values of a RooAbsReal.
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override
Print info about this object to the specified stream.
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override
Propagate server changes to embedded formula object.
TString GetUniqueFuncName() const
Definition TFormula.h:253
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376