Logo ROOT   6.08/07
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 
22 RooGenericPdf is a concrete implementation of a probability density function,
23 which takes a RooArgList of servers and a C++ expression string defining how
24 its value should be calculated from the given list of servers.
25 A fully numerical integration is automatically performed to normalize the given
26 expression. RooGenericPdf uses a RooFormula object to perform the expression evaluation
27 
28 The string expression can be any valid TFormula expression referring to the
29 listed 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 
34 The latter form, while slightly less readable, is more versatile because it
35 doesn'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 
49 using namespace std;
50 
52 
53 
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Constructor with formula expression and list of input variables
57 
58 RooGenericPdf::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 
74 RooGenericPdf::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 
91 RooGenericPdf::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 
136 Bool_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 
150 Bool_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 
160 Bool_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 
174 void RooGenericPdf::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
175 {
176  RooAbsPdf::printMultiline(os,content,verbose,indent);
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 
190 void RooGenericPdf::printMetaArgs(ostream& os) const
191 {
192  os << "formula=\"" << _formExpr << "\" " ;
193 }
194 
195 
196 
197 ////////////////////////////////////////////////////////////////////////////////
198 /// Read object contents from given stream
199 
200 Bool_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 
215 void 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 
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
#define coutE(a)
Definition: RooMsgService.h:35
void printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const
Print info about this object to the specified stream.
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:1611
virtual Bool_t isValidReal(Double_t value, Bool_t printError) const
Check if given value is valid.
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
Double_t traceEval(const RooArgSet *set) const
Calculate current value of object, with error tracing wrapper.
Definition: RooAbsReal.cxx:288
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream.
RooListProxy _actualVars
Definition: RooGenericPdf.h:51
TString _formExpr
Formula engine.
Definition: RooGenericPdf.h:62
void setValueDirty() const
Definition: RooAbsArg.h:439
void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Printing interface.
Definition: RooFormula.cxx:414
RooFormula * _formula
Definition: RooGenericPdf.h:61
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
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
void printMetaArgs(std::ostream &os) const
Add formula expression as meta argument in printing interface.
Int_t getSize() const
RooFormula & formula() const
bool verbose
virtual ~RooGenericPdf()
Destructor.
TString readLine()
Read an entire line from the stream and return as TString This method recognizes the use of &#39;\&#39; in th...
static void indent(ostringstream &buf, int indent_level)
virtual Double_t evaluate() const
Calculate current value of this object.
#define ClassImp(name)
Definition: Rtypes.h:279
double Double_t
Definition: RtypesCore.h:55
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from given stream.
Double_t _value
Definition: RooAbsReal.h:389
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects...
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
virtual Bool_t redirectServersHook(const RooAbsCollection &newServerList, Bool_t mustReplaceAll, Bool_t nameChange, Bool_t isRecursive)
Propagate server changes to embedded formula object.
Bool_t setFormula(const char *formula)
Change formula expression to given expression.
RooGenericPdf is a concrete implementation of a probability density function, which takes a RooArgLis...
Definition: RooGenericPdf.h:25
RooArgSet * _normSet
Normalization integral (owned by _normMgr)
Definition: RooAbsPdf.h:302
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
const Bool_t kTRUE
Definition: Rtypes.h:91
char name[80]
Definition: TGX11.cxx:109
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52