ROOT  6.06/09
Reference Guide
RooGenProdProj.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 // BEGIN_HTML
20 //
21 // RooGenProdProj is an auxiliary class for RooProdPdf that calculates
22 // a general normalized projection of a product of non-factorizing PDFs, e.g.
23 //
24 // Int ( P1 * P2 * ....) dx
25 // P_x_xy = -------------------------------
26 // Int (P1 * P2 * ... ) dx dy
27 //
28 // Partial integrals that factorize that can be calculated are calculated
29 // analytically. Remaining non-factorizing observables are integrated numerically.
30 // END_HTML
31 //
32 
33 
34 #include "RooFit.h"
35 
36 #include "Riostream.h"
37 #include "Riostream.h"
38 #include <math.h>
39 
40 #include "RooGenProdProj.h"
41 #include "RooAbsReal.h"
42 #include "RooAbsPdf.h"
43 #include "RooErrorHandler.h"
44 #include "RooProduct.h"
45 
46 using namespace std;
47 
49 ;
50 
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Default constructor
54 
56  _compSetOwnedN(0),
57  _compSetOwnedD(0),
58  _haveD(kFALSE)
59 {
60 }
61 
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// Constructor for a normalization projection of the product of p.d.f.s _prodSet
65 /// integrated over _intSet in range isetRangeName while normalized over _normSet
66 
67 RooGenProdProj::RooGenProdProj(const char *name, const char *title, const RooArgSet& _prodSet, const RooArgSet& _intSet,
68  const RooArgSet& _normSet, const char* isetRangeName, const char* normRangeName, Bool_t doFactorize) :
69  RooAbsReal(name, title),
70  _compSetOwnedN(0),
71  _compSetOwnedD(0),
72  _compSetN("compSetN","Set of integral components owned by numerator",this,kFALSE),
73  _compSetD("compSetD","Set of integral components owned by denominator",this,kFALSE),
74  _intList("intList","List of integrals",this,kTRUE),
75  _haveD(kFALSE)
76 {
77  // Set expensive object cache to that of first item in prodSet
79 
80  // Create owners of components created in ctor
83 
84  RooAbsReal* numerator = makeIntegral("numerator",_prodSet,_intSet,*_compSetOwnedN,isetRangeName,doFactorize) ;
85  RooAbsReal* denominator = makeIntegral("denominator",_prodSet,_normSet,*_compSetOwnedD,normRangeName,doFactorize) ;
86 
87 // cout << "RooGenProdPdf::ctor(" << GetName() << ") numerator = " << numerator->GetName() << endl ;
88 // numerator->printComponentTree() ;
89 // cout << "RooGenProdPdf::ctor(" << GetName() << ") denominator = " << denominator->GetName() << endl ;
90 // denominator->printComponentTree() ;
91 
92  // Copy all components in (non-owning) set proxy
93  _compSetN.add(*_compSetOwnedN) ;
95 
96  _intList.add(*numerator) ;
97  if (denominator) {
98  _intList.add(*denominator) ;
99  _haveD = kTRUE ;
100  }
101 }
102 
103 
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// Copy constructor
107 
109  RooAbsReal(other, name),
110  _compSetOwnedN(0),
111  _compSetOwnedD(0),
112  _compSetN("compSetN","Set of integral components owned by numerator",this),
113  _compSetD("compSetD","Set of integral components owned by denominator",this),
114  _intList("intList","List of integrals",this)
115 {
116  // Explicitly remove all server links at this point
118  RooAbsArg* server ;
119  while((server=(RooAbsArg*)iter->Next())) {
120  removeServer(*server,kTRUE) ;
121  }
122  delete iter ;
123 
124  // Copy constructor
127 
130 
131  RooAbsArg* arg ;
133  while((arg=(RooAbsArg*)nIter->Next())) {
134 // cout << "ownedN elem " << arg->GetName() << "(" << arg << ")" << endl ;
135  arg->setOperMode(_operMode) ;
136  }
137  delete nIter ;
139  while((arg=(RooAbsArg*)dIter->Next())) {
140 // cout << "ownedD elem " << arg->GetName() << "(" << arg << ")" << endl ;
141  arg->setOperMode(_operMode) ;
142  }
143  delete dIter ;
144 
145  // Fill _intList
146  _haveD = other._haveD ;
147  _intList.add(*_compSetN.find(other._intList.at(0)->GetName())) ;
148  if (other._haveD) {
149  _intList.add(*_compSetD.find(other._intList.at(1)->GetName())) ;
150  }
151 }
152 
153 
154 
155 ////////////////////////////////////////////////////////////////////////////////
156 /// Destructor
157 
159 {
160  if (_compSetOwnedN) delete _compSetOwnedN ;
161  if (_compSetOwnedD) delete _compSetOwnedD ;
162 }
163 
164 
165 
166 ////////////////////////////////////////////////////////////////////////////////
167 /// Utility function to create integral over observables intSet in range isetRangeName over product of p.d.fs in compSet.
168 /// The integration is factorized into components as much as possible and done analytically as far as possible.
169 /// All component object needed to represent product integral are added as owned members to saveSet.
170 /// The return value is a RooAbsReal object representing the requested integral
171 
172 RooAbsReal* RooGenProdProj::makeIntegral(const char* name, const RooArgSet& compSet, const RooArgSet& intSet,
173  RooArgSet& saveSet, const char* isetRangeName, Bool_t doFactorize)
174 {
175  RooArgSet anaIntSet, numIntSet ;
176 
177  // First determine subset of observables in intSet that are factorizable
178  TIterator* compIter = compSet.createIterator() ;
179  TIterator* intIter = intSet.createIterator() ;
180  RooAbsPdf* pdf ;
181  RooAbsArg* arg ;
182  while((arg=(RooAbsArg*)intIter->Next())) {
183  Int_t count(0) ;
184  compIter->Reset() ;
185  while((pdf=(RooAbsPdf*)compIter->Next())) {
186  if (pdf->dependsOn(*arg)) count++ ;
187  }
188 
189  if (count==0) {
190  } else if (count==1) {
191  anaIntSet.add(*arg) ;
192  } else {
193  }
194  }
195 
196  // Determine which of the factorizable integrals can be done analytically
197  RooArgSet prodSet ;
198  numIntSet.add(intSet) ;
199 
200  compIter->Reset() ;
201  while((pdf=(RooAbsPdf*)compIter->Next())) {
202  if (doFactorize && pdf->dependsOn(anaIntSet)) {
203  RooArgSet anaSet ;
204  Int_t code = pdf->getAnalyticalIntegralWN(anaIntSet,anaSet,0,isetRangeName) ;
205  if (code!=0) {
206  // Analytical integral, create integral object
207  RooAbsReal* pai = pdf->createIntegral(anaSet,isetRangeName) ;
208  pai->setOperMode(_operMode) ;
209 
210  // Add to integral to product
211  prodSet.add(*pai) ;
212 
213  // Remove analytically integratable observables from numeric integration list
214  numIntSet.remove(anaSet) ;
215 
216  // Declare ownership of integral
217  saveSet.addOwned(*pai) ;
218  } else {
219  // Analytic integration of factorizable observable not possible, add straight pdf to product
220  prodSet.add(*pdf) ;
221  }
222  } else {
223  // Non-factorizable observables, add straight pdf to product
224  prodSet.add(*pdf) ;
225  }
226  }
227 
228  //cout << "RooGenProdProj::makeIntegral(" << GetName() << ") prodset = " << prodSet << endl ;
229 
230  // Create product of (partial) analytical integrals
231  TString prodName ;
232  if (isetRangeName) {
233  prodName = Form("%s_%s_Range[%s]",GetName(),name,isetRangeName) ;
234  } else {
235  prodName = Form("%s_%s",GetName(),name) ;
236  }
237  RooProduct* prod = new RooProduct(prodName,"product",prodSet) ;
239  prod->setOperMode(_operMode) ;
240 
241  // Declare owndership of product
242  saveSet.addOwned(*prod) ;
243 
244  // Create integral performing remaining numeric integration over (partial) analytic product
245  RooAbsReal* ret = prod->createIntegral(numIntSet,isetRangeName) ;
246 // cout << "verbose print of integral object" << endl ;
247 // ret->Print("v") ;
248  ret->setOperMode(_operMode) ;
249  saveSet.addOwned(*ret) ;
250 
251  delete compIter ;
252  delete intIter ;
253 
254  // Caller owners returned master integral object
255  return ret ;
256 }
257 
258 
259 
260 ////////////////////////////////////////////////////////////////////////////////
261 /// Calculate and return value of normalization projection
262 
264 {
265  Double_t nom = ((RooAbsReal*)_intList.at(0))->getVal() ;
266 
267  if (!_haveD) return nom ;
268 
269  Double_t den = ((RooAbsReal*)_intList.at(1))->getVal() ;
270 
271  //cout << "RooGenProdProj::eval(" << GetName() << ") nom = " << nom << " den = " << den << endl ;
272 
273  return nom / den ;
274 }
275 
276 
277 
278 ////////////////////////////////////////////////////////////////////////////////
279 /// Intercept cache mode operation changes and propagate them to the components
280 
282 {
283  // WVE use cache manager here!
284 
285  RooAbsArg* arg ;
287  while((arg=(RooAbsArg*)nIter->Next())) {
288  arg->setOperMode(_operMode) ;
289  }
290  delete nIter ;
291 
293  while((arg=(RooAbsArg*)dIter->Next())) {
294  arg->setOperMode(_operMode) ;
295  }
296  delete dIter ;
297 
299  if (_haveD) _intList.at(1)->setOperMode(Auto) ; // Denominator always stays in Auto mode (normalization integral)
300 }
301 
302 
303 
304 
305 
306 
307 
ClassImp(RooGenProdProj)
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
TIterator * serverIterator() const
Definition: RooAbsArg.h:112
virtual void Reset()=0
Basic string class.
Definition: TString.h:137
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 operModeHook()
Intercept cache mode operation changes and propagate them to the components.
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2341
Iterator abstract base class.
Definition: TIterator.h:32
RooAbsArg * first() const
virtual ~RooGenProdProj()
Destructor.
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Add element to an owning set.
Definition: RooArgSet.cxx:461
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
TIterator * createIterator(Bool_t dir=kIterForward) const
friend class RooArgSet
Definition: RooAbsArg.h:469
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
virtual Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet *normSet, const char *rangeName=0) const
Variant of getAnalyticalIntegral that is also passed the normalization set that should be applied to ...
Definition: RooAbsReal.cxx:320
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooListProxy _intList
RooGenProdProj()
Default constructor.
char * Form(const char *fmt,...)
RooArgSet * _compSetOwnedN
OperMode _operMode
Definition: RooAbsArg.h:570
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
RooSetProxy _compSetD
Double_t evaluate() const
Calculate and return value of normalization projection.
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition: RooAbsArg.h:497
RooArgSet * _compSetOwnedD
RooAbsArg * at(Int_t idx) const
Definition: RooArgList.h:84
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
RooSetProxy _compSetN
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
RooAbsReal * makeIntegral(const char *name, const RooArgSet &compSet, const RooArgSet &intSet, RooArgSet &saveSet, const char *isetRangeName, Bool_t doFactorize)
Utility function to create integral over observables intSet in range isetRangeName over product of p...
virtual TObject * Next()=0
Bool_t dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=0, Bool_t valueOnly=kFALSE) const
Test whether we depend on (ie, are served by) any object in the specified collection.
Definition: RooAbsArg.cxx:743
void setOperMode(OperMode mode, Bool_t recurseADirty=kTRUE)
Change cache operation mode to given mode.
Definition: RooAbsArg.cxx:1753
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
const Bool_t kTRUE
Definition: Rtypes.h:91
void removeServer(RooAbsArg &server, Bool_t force=kFALSE)
Unregister another RooAbsArg as a server to us, ie, declare that we no longer depend on its value and...
Definition: RooAbsArg.cxx:412
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
Definition: RooArgSet.cxx:448
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:503
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...