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