Logo ROOT   6.18/05
Reference Guide
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
22RooGenericPdf is a concrete implementation of a probability density function,
23which 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:
30
31 RooGenericPdf("gen","x*y",RooArgList(x,y)) or
32 RooGenericPdf("gen","@0*@1",RooArgList(x,y))
33
34The latter form, while slightly less readable, is more versatile because it
35doesn't hardcode any of the variable names it expects
36**/
37
38#include "RooFit.h"
39#include "Riostream.h"
40
41#include "RooGenericPdf.h"
42#include "RooGenericPdf.h"
43#include "RooStreamParser.h"
44#include "RooMsgService.h"
45#include "RooArgList.h"
46
47
48
49using namespace std;
50
52
53
54
55////////////////////////////////////////////////////////////////////////////////
56/// Constructor with formula expression and list of input variables
57
58RooGenericPdf::RooGenericPdf(const char *name, const char *title, const RooArgList& dependents) :
59 RooAbsPdf(name,title),
60 _actualVars("actualVars","Variables used by PDF expression",this),
61 _formula(0),
62 _formExpr(title)
63{
64 _actualVars.add(dependents) ;
65
66 if (_actualVars.getSize()==0) _value = traceEval(0) ;
67}
68
69
70
71////////////////////////////////////////////////////////////////////////////////
72/// Constructor with a name, title, formula expression and a list of variables
73
74RooGenericPdf::RooGenericPdf(const char *name, const char *title,
75 const char* inFormula, const RooArgList& dependents) :
76 RooAbsPdf(name,title),
77 _actualVars("actualVars","Variables used by PDF expression",this),
78 _formula(0),
79 _formExpr(inFormula)
80{
81 _actualVars.add(dependents) ;
82
83 if (_actualVars.getSize()==0) _value = traceEval(0) ;
84}
85
86
87
88////////////////////////////////////////////////////////////////////////////////
89/// Copy constructor
90
91RooGenericPdf::RooGenericPdf(const RooGenericPdf& other, const char* name) :
92 RooAbsPdf(other, name),
93 _actualVars("actualVars",this,other._actualVars),
94 _formula(0),
95 _formExpr(other._formExpr)
96{
97}
98
99
100
101////////////////////////////////////////////////////////////////////////////////
102/// Destructor
103
105{
106 if (_formula) delete _formula ;
107}
108
109
110
111////////////////////////////////////////////////////////////////////////////////
112
114{
115 if (!_formula) {
117 }
118 return *_formula ;
119}
120
121
122
123////////////////////////////////////////////////////////////////////////////////
124/// Calculate current value of this object
125
127{
128 return formula().eval(_normSet) ;
129}
130
131
132
133////////////////////////////////////////////////////////////////////////////////
134/// Change formula expression to given expression
135
136Bool_t RooGenericPdf::setFormula(const char* inFormula)
137{
138 if (formula().reCompile(inFormula)) return kTRUE ;
139
140 _formExpr = inFormula ;
141 setValueDirty() ;
142 return kFALSE ;
143}
144
145
146
147////////////////////////////////////////////////////////////////////////////////
148/// Check if given value is valid
149
150Bool_t RooGenericPdf::isValidReal(Double_t /*value*/, Bool_t /*printError*/) const
151{
152 return kTRUE ;
153}
154
155
156
157////////////////////////////////////////////////////////////////////////////////
158/// Propagate server changes to embedded formula object
159
160Bool_t RooGenericPdf::redirectServersHook(const RooAbsCollection& newServerList, Bool_t mustReplaceAll, Bool_t nameChange, Bool_t /*isRecursive*/)
161{
162 if (_formula) {
163 return _formula->changeDependents(newServerList,mustReplaceAll,nameChange) ;
164 } else {
165 return kTRUE ;
166 }
167}
168
169
170
171////////////////////////////////////////////////////////////////////////////////
172/// Print info about this object to the specified stream.
173
175{
177 if (verbose) {
178 os << " --- RooGenericPdf --- " << endl ;
179 indent.Append(" ");
180 os << indent ;
181 formula().printMultiline(os,content,verbose,indent);
182 }
183}
184
185
186
187////////////////////////////////////////////////////////////////////////////////
188/// Add formula expression as meta argument in printing interface
189
190void RooGenericPdf::printMetaArgs(ostream& os) const
191{
192 os << "formula=\"" << _formExpr << "\" " ;
193}
194
195
196
197////////////////////////////////////////////////////////////////////////////////
198/// Read object contents from given stream
199
200Bool_t RooGenericPdf::readFromStream(istream& is, Bool_t compact, Bool_t /*verbose*/)
201{
202 if (compact) {
203 coutE(InputArguments) << "RooGenericPdf::readFromStream(" << GetName() << "): can't read in compact mode" << endl ;
204 return kTRUE ;
205 } else {
206 RooStreamParser parser(is) ;
207 return setFormula(parser.readLine()) ;
208 }
209}
210
211
212////////////////////////////////////////////////////////////////////////////////
213/// Write object contents to given stream
214
215void RooGenericPdf::writeToStream(ostream& os, Bool_t compact) const
216{
217 if (compact) {
218 os << getVal() << endl ;
219 } else {
220 os << GetTitle() ;
221 }
222}
223
224
225
#define coutE(a)
Definition: RooMsgService.h:34
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 Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition: TGX11.cxx:109
void setValueDirty() const
Definition: RooAbsArg.h:486
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
Int_t getSize() const
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Print multi line detailed information of this RooAbsPdf.
Definition: RooAbsPdf.cxx:1682
RooArgSet * _normSet
Normalization integral (owned by _normMgr)
Definition: RooAbsPdf.h:316
Double_t traceEval(const RooArgSet *set) const
Calculate current value of object, with error tracing wrapper.
Definition: RooAbsReal.cxx:311
Double_t _value
Definition: RooAbsReal.h:408
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:81
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooFormula an implementation of ROOT::v5::TFormula that interfaces it to RooAbsArg value objects.
Definition: RooFormula.h:27
Double_t eval(const RooArgSet *nset=0)
Evaluate ROOT::v5::TFormula using given normalization set to be used as observables definition passed...
Definition: RooFormula.cxx:234
void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Printing interface.
Definition: RooFormula.cxx:414
Bool_t changeDependents(const RooAbsCollection &newDeps, Bool_t mustReplaceAll, Bool_t nameChange)
Change used variables to those with the same name in given list If mustReplaceAll is true and error i...
Definition: RooFormula.cxx:191
RooGenericPdf is a concrete implementation of a probability density function, which takes a RooArgLis...
Definition: RooGenericPdf.h:25
void printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const
Print info about this object to the specified stream.
Bool_t setFormula(const char *formula)
Change formula expression to given expression.
virtual Double_t evaluate() const
Calculate current value of this object.
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream.
void printMetaArgs(std::ostream &os) const
Add formula expression as meta argument in printing interface.
RooListProxy _actualVars
Definition: RooGenericPdf.h:51
virtual Bool_t redirectServersHook(const RooAbsCollection &newServerList, Bool_t mustReplaceAll, Bool_t nameChange, Bool_t isRecursive)
Propagate server changes to embedded formula object.
RooFormula * _formula
Definition: RooGenericPdf.h:61
virtual ~RooGenericPdf()
Destructor.
virtual Bool_t isValidReal(Double_t value, Bool_t printError) const
Check if given value is valid.
RooFormula & formula() const
TString _formExpr
Formula engine.
Definition: RooGenericPdf.h:62
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from given stream.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
TString readLine()
Read an entire line from the stream and return as TString This method recognizes the use of '\' in th...
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
@ InputArguments
Definition: RooGlobalFunc.h:58