Logo ROOT   6.18/05
Reference Guide
RooEffProd.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, NIKHEF
7 * GR, Gerhard Raven, NIKHEF/VU *
8 * *
9 * Redistribution and use in source and binary forms, *
10 * with or without modification, are permitted according to the terms *
11 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
12 *****************************************************************************/
13
14
15/////////////////////////////////////////////////////////////////////////////////////
16/// \class RooEffProd
17/// The class RooEffProd implements the product of a PDF with an efficiency function.
18/// The normalization integral of the product is calculated numerically, but the
19/// event generation is handled by a specialized generator context that implements
20/// the event generation in a more efficient for cases where the PDF has an internal
21/// generator that is smarter than accept reject.
22///
23
24#include "RooFit.h"
25#include "RooEffProd.h"
26#include "RooEffGenContext.h"
27#include "RooNameReg.h"
28#include "RooRealVar.h"
29
30using namespace std;
31
33 ;
34
35
36
37////////////////////////////////////////////////////////////////////////////////
38/// Constructor of a a production of p.d.f inPdf with efficiency
39/// function inEff.
40
41RooEffProd::RooEffProd(const char *name, const char *title,
42 RooAbsPdf& inPdf, RooAbsReal& inEff) :
43 RooAbsPdf(name,title),
44 _cacheMgr(this,10),
45 _pdf("pdf","pre-efficiency pdf", this,inPdf),
46 _eff("eff","efficiency function",this,inEff),
47 _nset(0),
48 _fixedNset(0)
49{
50}
51
52
53
54
55////////////////////////////////////////////////////////////////////////////////
56/// Copy constructor
57
58RooEffProd::RooEffProd(const RooEffProd& other, const char* name) :
59 RooAbsPdf(other, name),
60 _cacheMgr(other._cacheMgr,this),
61 _pdf("pdf",this,other._pdf),
62 _eff("acc",this,other._eff),
63 _nset(0),
64 _fixedNset(0)
65{
66}
67
68
69
70
71////////////////////////////////////////////////////////////////////////////////
72/// Destructor
73
75{
76}
77
78
79
80////////////////////////////////////////////////////////////////////////////////
81/// Return p.d.f. value normalized over given set of observables
82
84{
85 _nset = _fixedNset ? _fixedNset : set ;
86 return RooAbsPdf::getValV(set) ;
87}
88
89
90
91
92////////////////////////////////////////////////////////////////////////////////
93/// Calculate and return 'raw' unnormalized value of p.d.f
94
96{
97 return eff()->getVal() * pdf()->getVal(_nset);
98}
99
100
101
102////////////////////////////////////////////////////////////////////////////////
103/// Return specialized generator context for RooEffProds that implements generation
104/// in a more efficient way than can be done for generic correlated products
105
107 const RooArgSet* auxProto, Bool_t verbose) const
108{
109 assert(pdf()!=0);
110 assert(eff()!=0);
111 return new RooEffGenContext(*this,*pdf(),*eff(),vars,prototype,auxProto,verbose) ;
112}
113
114
115
116
117
118////////////////////////////////////////////////////////////////////////////////
119/// Return internal integration capabilities of the p.d.f. Given a set 'allVars' for which
120/// integration is requested, returned the largest subset for which internal (analytical)
121/// integration is implemented (in argument analVars). The return value is a unique integer
122/// code that identifies the integration configuration (integrated observables and range name).
123///
124/// This implementation in RooEffProd catches all integrals without normalization and reroutes them
125/// through a custom integration routine that properly accounts for the use of normalized p.d.f.
126/// in the evaluate() expression, which breaks the default RooAbsPdf normalization handling
127
129 const RooArgSet* normSet, const char* rangeName) const
130{
131
132 // No special handling required if a normalization set is given
133 if (normSet && normSet->getSize()>0) {
134 return 0 ;
135 }
136 // No special handling required if running with a fixed normalization set
137 if (_fixedNset) {
138 return 0 ;
139 }
140
141 // Special handling of integrals w/o normalization set. We need to pass _a_ normalization set
142 // to pdf().getVal(nset) in evaluate() because for certain p.d.fs the shape depends on the
143 // chosen normalization set. This functions correctly automatically for plain getVal() calls,
144 // however when the (numeric) normalization is calculated, getVal() is called without any normalization
145 // set causing the normalization to be calculated for a possibly different shape. To fix that
146 // integrals over a RooEffProd without normalization setup are explicitly handled here. These integrals
147 // are calculated using a clone of the RooEffProd that has a fixed normalization set passed to the
148 // underlying p.d.f regardless of the normalization set passed to getVal(). Here the set of observables
149 // over which is integrated is passed.
150
151 // Declare that we can analytically integrate all requested observables
152 analVars.add(allVars) ;
153
154 // Check if cache was previously created
155 Int_t sterileIndex(-1) ;
156 CacheElem* cache = (CacheElem*) _cacheMgr.getObj(&allVars,&allVars,&sterileIndex,RooNameReg::ptr(rangeName)) ;
157 if (cache) {
158 return _cacheMgr.lastIndex()+1;
159 }
160
161 // Construct cache with clone of p.d.f that has fixed normalization set that is passed to input pdf
162 cache = new CacheElem ;
163 cache->_intObs.addClone(allVars) ;
164 cache->_clone = (RooEffProd*) clone(Form("%s_clone",GetName())) ;
165 cache->_clone->_fixedNset = &cache->_intObs ;
166 cache->_int = cache->_clone->createIntegral(cache->_intObs,rangeName) ;
167
168 // Store cache and return index as code
169 Int_t code = _cacheMgr.setObj(&allVars,&allVars,(RooAbsCacheElement*)cache,RooNameReg::ptr(rangeName)) ;
170
171 return code+1 ;
172}
173
174
175
176
177
178////////////////////////////////////////////////////////////////////////////////
179/// Return value of integral identified by code, which should be a return value of getAnalyticalIntegralWN,
180/// Code zero is always handled and signifies no integration (return value is normalized p.d.f. value)
181
182Double_t RooEffProd::analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* /*rangeName*/) const
183{
184 // Return analytical integral defined by given scenario code
185
186 // No integration scenario
187 if (code==0) {
188 return getVal(normSet) ;
189 }
190
191 // Partial integration scenarios
192 CacheElem* cache = (CacheElem*) _cacheMgr.getObjByIndex(code-1) ;
193
194 return cache->_int->getVal() ;
195}
196
197
198
199
200////////////////////////////////////////////////////////////////////////////////
201/// Report all RooAbsArg derived objects contained in Cache Element (used in function optimization and
202/// and server redirect management of the cache)
203
205{
206 RooArgList ret(_intObs) ;
207 ret.add(*_int) ;
208 ret.add(*_clone) ;
209 return ret ;
210}
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
#define ClassImp(name)
Definition: Rtypes.h:365
char name[80]
Definition: TGX11.cxx:109
char * Form(const char *fmt,...)
RooAbsCacheElement is the abstract base class for objects to be stored in RooAbsCache cache manager o...
Int_t getSize() const
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
RooAbsGenContext is the abstract base class for generator contexts of RooAbsPdf objects.
friend class CacheElem
Definition: RooAbsPdf.h:328
friend class RooEffGenContext
Definition: RooAbsPdf.h:291
virtual Double_t getValV(const RooArgSet *set=0) const
Return current value, normalized by integrating over the observables in nset.
Definition: RooAbsPdf.cxx:267
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:81
RooAbsReal * createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Create an object that represents the integral of the function over one or more observables listed in ...
Definition: RooAbsReal.cxx:531
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
virtual void addClone(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling addOwned() for each element in the source...
Definition: RooArgSet.h:96
T * getObj(const RooArgSet *nset, Int_t *sterileIndex=0, const TNamed *isetRangeName=0)
T * getObjByIndex(Int_t index) const
Int_t lastIndex() const
Int_t setObj(const RooArgSet *nset, T *obj, const TNamed *isetRangeName=0)
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:31
RooEffProd * _clone
Definition: RooEffProd.h:62
RooAbsReal * _int
Definition: RooEffProd.h:63
virtual RooArgList containedArgs(Action)
Report all RooAbsArg derived objects contained in Cache Element (used in function optimization and an...
Definition: RooEffProd.cxx:204
The class RooEffProd implements the product of a PDF with an efficiency function.
Definition: RooEffProd.h:20
virtual ~RooEffProd()
Destructor.
Definition: RooEffProd.cxx:74
virtual RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype, const RooArgSet *auxProto, Bool_t verbose) const
Return specialized generator context for RooEffProds that implements generation in a more efficient w...
Definition: RooEffProd.cxx:106
virtual Double_t evaluate() const
Calculate and return 'raw' unnormalized value of p.d.f.
Definition: RooEffProd.cxx:95
const RooAbsPdf * pdf() const
Definition: RooEffProd.h:44
const RooArgSet * _nset
Definition: RooEffProd.h:73
RooArgSet * _fixedNset
Normalization set to be used in evaluation.
Definition: RooEffProd.h:75
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=0) const
Return internal integration capabilities of the p.d.f.
Definition: RooEffProd.cxx:128
virtual TObject * clone(const char *newname) const
Definition: RooEffProd.h:28
RooObjCacheManager _cacheMgr
Definition: RooEffProd.h:67
const RooAbsReal * eff() const
Definition: RooEffProd.h:48
Double_t analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=0) const
Return value of integral identified by code, which should be a return value of getAnalyticalIntegralW...
Definition: RooEffProd.cxx:182
virtual Double_t getValV(const RooArgSet *set=0) const
Return p.d.f. value normalized over given set of observables.
Definition: RooEffProd.cxx:83
static const TNamed * ptr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
Definition: RooNameReg.cxx:104
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47