Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooResolutionModel.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/**
19 * \class RooResolutionModel
20 * RooResolutionModel is the base class for PDFs that represent a
21 * resolution model that can be convoluted with a physics model of the form
22 * \f[
23 * \mathrm{Phys}(x,a,b) = \sum_k \mathrm{coef}_k(a) * \mathrm{basis}_k(x,b)
24 * \f]
25 * where basis_k are a limited number of functions in terms of the variable
26 * to be convoluted and coef_k are coefficients independent of the convolution
27 * variable.
28 *
29 * Classes derived from RooResolutionModel implement
30 * \f[
31 * R_k(x,\bar{b},\bar{c}) = \int \mathrm{basis}_k(x',\bar{b}) * \mathrm{resModel}(x-x',\bar{c}) \; \mathrm{d} x',
32 * \f]
33 * which RooAbsAnaConvPdf uses to construct the pdf for [ Phys (x) R ] :
34 * \f[
35 * \mathrm{PDF}(x,\bar a, \bar b, \bar c) = \sum_k \mathrm{coef}_k(\bar a) * R_k(x, \bar b, \bar c)
36 * \f]
37 *
38 * A minimal implementation of a RooResolutionModel consists of a
39 * ```
40 * Int_t basisCode(const char* name)
41 * ```
42 * function indicating which basis functions this resolution model supports, and
43 * ```
44 * double evaluate(),
45 * ```
46 * which should implement the resolution model (optionally convoluted with one of the
47 * supported basis functions). RooResolutionModel objects can be used as regular
48 * PDFs (They inherit from RooAbsPdf), or as resolution model convoluted with
49 * a basis function. The implementation of evaluate() can identify the requested
50 * mode using basisCode(). If zero, the regular PDF value
51 * should be calculated. If non-zero, the model's value convoluted with the
52 * basis function identified by the code should be calculated.
53 *
54 * Optionally, analytical integrals can be advertised and implemented, in the
55 * same way as done for regular PDFS (see RooAbsPdf for further details).
56 * Also in getAnalyticalIntegral() / analyticalIntegral(), the implementation
57 * should use basisCode() to determine for which scenario the integral is
58 * requested.
59 *
60 * The choice of basis returned by basisCode() is guaranteed not to change
61 * during the lifetime of a RooResolutionModel object.
62 *
63 */
64
65#include "RooResolutionModel.h"
66#include "RooMsgService.h"
67
68#include <ostream>
69
70using std::endl, std::ostream;
71
72
73
74////////////////////////////////////////////////////////////////////////////////
75/// Constructor with convolution variable 'x'.
76/// The convolution variable needs to be convertible to real values, and be able
77/// to give information about its range. This is supported by e.g. RooRealVar or RooLinearVar, which
78/// accepts offsetting and scaling an observable.
80 : RooAbsPdf(name, title), x("x", "Dependent or convolution variable", this, _x), _basisCode(0), _ownBasis(false)
81{
82
83}
84
85
86
87////////////////////////////////////////////////////////////////////////////////
88/// Copy constructor
89
91 : RooAbsPdf(other, name), x("x", this, other.x), _basisCode(other._basisCode), _ownBasis(false)
92{
93 if (other._basis) {
94 _basis = static_cast<RooFormulaVar*>(other._basis->Clone()) ;
95 _ownBasis = true ;
96 //_basis = other._basis ;
97 }
98
99 if (_basis) {
100 for (RooAbsArg * basisServer : _basis->servers()) {
101 addServer(*basisServer,true,false) ;
102 }
103 }
104}
105
106
107
108////////////////////////////////////////////////////////////////////////////////
109/// Destructor
110
112{
113 if (_ownBasis && _basis) {
114 delete _basis ;
115 }
116}
117
118
119
120////////////////////////////////////////////////////////////////////////////////
121/// Return identity formula pointer
122
124{
125 static RooFormulaVar identity("identity","1",RooArgSet(""));
126 return &identity;
127}
128
129
130
131////////////////////////////////////////////////////////////////////////////////
132/// Instantiate a clone of this resolution model representing a convolution with given
133/// basis function. The owners object name is incorporated in the clones name
134/// to avoid multiple convolution objects with the same name in complex PDF structures.
135///
136/// Note: The 'inBasis' formula expression must be a RooFormulaVar that encodes the formula
137/// in the title of the object and this expression must be an exact match against the
138/// implemented basis function strings (see derived class implementation of method basisCode()
139/// for those strings
140
142{
143 // Check that primary variable of basis functions is our convolution variable
144 if (inBasis->getParameter(0) != x.absArg()) {
145 coutE(InputArguments) << "RooResolutionModel::convolution(" << GetName() << "," << this
146 << ") convolution parameter of basis function and PDF don't match" << std::endl
147 << "basis->findServer(0) = " << inBasis->findServer(0) << std::endl
148 << "x.absArg() = " << x.absArg() << std::endl ;
149 return nullptr ;
150 }
151
152 if (basisCode(inBasis->GetTitle())==0) {
153 coutE(InputArguments) << "RooResolutionModel::convolution(" << GetName() << "," << this
154 << ") basis function '" << inBasis->GetTitle() << "' is not supported." << std::endl ;
155 return nullptr ;
156 }
157
158 TString newName(GetName()) ;
159 newName.Append("_conv_") ;
160 newName.Append(inBasis->GetName()) ;
161 newName.Append("_[") ;
162 newName.Append(owner->GetName()) ;
163 newName.Append("]") ;
164
165 RooResolutionModel* conv = static_cast<RooResolutionModel*>(clone(newName)) ;
166
167 TString newTitle(conv->GetTitle()) ;
168 newTitle.Append(" convoluted with basis function ") ;
169 newTitle.Append(inBasis->GetName()) ;
170 conv->SetTitle(newTitle.Data()) ;
171
172 conv->changeBasis(inBasis) ;
173
174 return conv ;
175}
176
177
178
179////////////////////////////////////////////////////////////////////////////////
180/// Change the basis function we convolute with.
181/// For one-time use by convolution() only.
182
184{
185 // Remove client-server link to old basis
186 if (_basis) {
187 for (RooAbsArg* basisServer : _basis->servers()) {
188 removeServer(*basisServer) ;
189 }
190
191 if (_ownBasis) {
192 delete _basis ;
193 }
194 }
195 _ownBasis = false ;
196
197 // Change basis pointer and update client-server link
198 _basis = inBasis ;
199 if (_basis) {
200 for (RooAbsArg* basisServer : _basis->servers()) {
201 addServer(*basisServer,true,false) ;
202 }
203 }
204
205 _basisCode = inBasis?basisCode(inBasis->GetTitle()):0 ;
206}
207
208
209
210////////////////////////////////////////////////////////////////////////////////
211/// Return the convolution variable of the selection basis function.
212/// This is, by definition, the first parameter of the basis function
213
215{
216 // Convolution variable is by definition first server of basis function
217 return *static_cast<RooRealVar const*>(*basis().servers().begin());
218}
219
220
221////////////////////////////////////////////////////////////////////////////////
222/// Modified version of RooAbsPdf::getValF(). If used as regular PDF,
223/// call RooAbsPdf::getValF(), otherwise return unnormalized value
224/// regardless of specified normalization set
225
226double RooResolutionModel::getValV(const RooArgSet* nset) const
227{
228 if (!_basis) return RooAbsPdf::getValV(nset) ;
229
230 // Return value of object. Calculated if dirty, otherwise cached value is returned.
231 if (isValueDirty()) {
232 _value = evaluate() ;
233
234 // WVE insert traceEval traceEval
235 if (_verboseDirty) cxcoutD(Tracing) << "RooResolutionModel(" << GetName() << ") value = " << _value << std::endl ;
236
239 }
240
241 return _value ;
242}
243
244
245
246////////////////////////////////////////////////////////////////////////////////
247/// Forward redirectServers call to our basis function, which is not connected to either resolution
248/// model or the physics model.
249
250bool RooResolutionModel::redirectServersHook(const RooAbsCollection& newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive)
251{
252 if (!_basis) {
253 _norm = nullptr ;
254 return false ;
255 }
256
257 RooFormulaVar* newBasis = static_cast<RooFormulaVar*>(newServerList.find(_basis->GetName())) ;
258 if (newBasis) {
259
260 if (_ownBasis) {
261 delete _basis ;
262 }
263
264 _basis = newBasis ;
265 _ownBasis = false ;
266 }
267
268 _basis->redirectServers(newServerList,mustReplaceAll,nameChange) ;
269
270 return (mustReplaceAll && !newBasis) || RooAbsPdf::redirectServersHook(newServerList, mustReplaceAll, nameChange, isRecursive);
271}
272
273
274
275////////////////////////////////////////////////////////////////////////////////
276/// Floating point error checking and tracing for given float value
277
278//bool RooResolutionModel::traceEvalHook(double value) const
279//{
280// // check for a math error or negative value
281// return TMath::IsNaN(value) ;
282//}
283
284
285
286////////////////////////////////////////////////////////////////////////////////
287/// Return the list of servers used by our normalization integral
288
293
294
295
296////////////////////////////////////////////////////////////////////////////////
297/// Return the integral of this PDF over all elements of 'nset'.
298
299double RooResolutionModel::getNorm(const RooArgSet* nset) const
300{
301 if (!nset) {
302 return getVal() ;
303 }
304
305 syncNormalization(nset,false) ;
306 if (_verboseEval>1) cxcoutD(Tracing) << ClassName() << "::getNorm(" << GetName()
307 << "): norm(" << _norm << ") = " << _norm->getVal() << std::endl ;
308
309 double ret = _norm->getVal() ;
310 return ret ;
311}
312
313
314
315////////////////////////////////////////////////////////////////////////////////
316/// Print info about this object to the specified stream. In addition to the info
317/// from RooAbsArg::printStream() we add:
318///
319/// Shape : value, units, plot range
320/// Verbose : default binning and print label
321
322void RooResolutionModel::printMultiline(ostream& os, Int_t content, bool verbose, TString indent) const
323{
324 RooAbsPdf::printMultiline(os,content,verbose,indent) ;
325
326 if(verbose) {
327 os << indent << "--- RooResolutionModel ---" << std::endl;
328 os << indent << "basis function = " ;
329 if (_basis) {
331 } else {
332 os << "<none>" << std::endl ;
333 }
334 }
335}
336
#define cxcoutD(a)
#define coutE(a)
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition TGX11.cxx:142
@ kName
@ kTitle
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
void removeServer(RooAbsArg &server, bool force=false)
Unregister another RooAbsArg as a server to us, ie, declare that we no longer depend on its value and...
static bool _verboseDirty
Definition RooAbsArg.h:602
bool redirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool isRecursionStep=false)
Replace all direct servers of this object with the new servers in newServerList.
void clearValueDirty() const
Definition RooAbsArg.h:521
const RefCountList_t & servers() const
List of all servers of this object.
Definition RooAbsArg.h:145
void addServer(RooAbsArg &server, bool valueProp=true, bool shapeProp=false, std::size_t refCount=1)
Register another RooAbsArg as a server to us, ie, declare that we depend on it.
bool isValueDirty() const
Definition RooAbsArg.h:335
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
Definition RooAbsArg.h:88
void clearShapeDirty() const
Definition RooAbsArg.h:522
void leafNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=nullptr, bool recurseNonDerived=false) const
Fill supplied list with all leaf nodes of the arg tree, starting with ourself as top node.
RooAbsArg * findServer(const char *name) const
Return server of this with name name. Returns nullptr if not found.
Definition RooAbsArg.h:147
Abstract container object that can hold multiple RooAbsArg objects.
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:32
virtual bool syncNormalization(const RooArgSet *dset, bool adjustProxies=true) const
Verify that the normalization integral cached with this PDF is valid for given set of normalization o...
double getValV(const RooArgSet *set=nullptr) const override
Return current value, normalized by integrating over the observables in nset.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print multi line detailed information of this RooAbsPdf.
RooAbsReal * _norm
! Normalization integral (owned by _normMgr)
Definition RooAbsPdf.h:313
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursiveStep) override
Hook function intercepting redirectServer calls.
static Int_t _verboseEval
Definition RooAbsPdf.h:308
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:107
double _value
Cache for current value of object.
Definition RooAbsReal.h:541
virtual double evaluate() const =0
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
RooAbsArg * absArg() const
Return pointer to contained argument.
Definition RooArgProxy.h:46
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
RooAbsArg * getParameter(const char *name) const
Return pointer to parameter with given name.
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,...
Variable that can be changed from the outside.
Definition RooRealVar.h:37
RooResolutionModel is the base class for PDFs that represent a resolution model that can be convolute...
~RooResolutionModel() override
Destructor.
double getValV(const RooArgSet *nset=nullptr) const override
Modified version of RooAbsPdf::getValF().
virtual void changeBasis(RooFormulaVar *basis)
Change the basis function we convolute with.
virtual Int_t basisCode(const char *name) const =0
virtual RooResolutionModel * convolution(RooFormulaVar *basis, RooAbsArg *owner) const
Instantiate a clone of this resolution model representing a convolution with given basis function.
double getNorm(const RooArgSet *nset=nullptr) const override
Return the integral of this PDF over all elements of 'nset'.
static RooFormulaVar * identity()
Return identity formula pointer.
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override
Forward redirectServers call to our basis function, which is not connected to either resolution model...
const RooRealVar & basisConvVar() const
Return the convolution variable of the selection basis function.
bool _ownBasis
Flag indicating ownership of _basis.
virtual void normLeafServerList(RooArgSet &list) const
Floating point error checking and tracing for given float value.
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override
Print info about this object to the specified stream.
Int_t _basisCode
Identifier code for selected basis function.
TObject * clone(const char *newname=nullptr) const override=0
RooResolutionModel()=default
RooFormulaVar * _basis
Basis function convolved with this resolution model.
const RooFormulaVar & basis() const
RooTemplateProxy< RooAbsRealLValue > x
Dependent/convolution variable.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:226
Basic string class.
Definition TString.h:137
const char * Data() const
Definition TString.h:385
TString & Append(const char *cs)
Definition TString.h:582
Double_t x[n]
Definition legend1.C:17