ROOT  6.06/09
Reference Guide
RooCachedPdf.cxx
Go to the documentation of this file.
1  /*****************************************************************************
2  * Project: RooFit *
3  * *
4  * Copyright (c) 2000-2005, Regents of the University of California *
5  * and Stanford University. All rights reserved. *
6  * *
7  * Redistribution and use in source and binary forms, *
8  * with or without modification, are permitted according to the terms *
9  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
10  *****************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////////
13 //
14 // BEGIN_HTML
15 // RooCachedPdf is an implementation of RooAbsCachedPdf that can cache
16 // any external RooAbsPdf input function provided in the constructor.
17 // END_HTML
18 //
19 
20 #include "Riostream.h"
21 
22 #include "RooAbsPdf.h"
23 #include "RooCachedPdf.h"
24 #include "RooAbsReal.h"
25 #include "RooMsgService.h"
26 #include "RooDataHist.h"
27 #include "RooHistPdf.h"
28 
29 using namespace std;
30 
32  ;
33 
34 
35 
36 ////////////////////////////////////////////////////////////////////////////////
37 /// Constructor taking name, title and function to be cached. To control
38 /// granularity of the binning of the cache histogram set the desired properties
39 /// in the binning named "cache" in the observables of the function. The dimensions
40 /// of the cache are automatically matched to the number of observables used
41 /// in each use context. Multiple cache in different observable may exists
42 /// simultanously if the cached p.d.f is used with multiple observable
43 /// configurations simultaneously
44 
45 RooCachedPdf::RooCachedPdf(const char *name, const char *title, RooAbsPdf& _pdf) :
46  RooAbsCachedPdf(name,title),
47  pdf("pdf","pdf",this,_pdf),
48  _cacheObs("cacheObs","cacheObs",this,kFALSE,kFALSE)
49  {
50  }
51 
52 
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /// Constructor taking name, title and function to be cached and
56 /// fixed choice of variable to cache. To control granularity of the
57 /// binning of the cache histogram set the desired properties in the
58 /// binning named "cache" in the observables of the function.
59 /// If the fixed set of cache observables does not match the observables
60 /// defined in the use context of the p.d.f the cache is still filled
61 /// completely. Ee.g. when it is specified to cache x and p and only x
62 /// is a observable in the given use context the cache histogram will
63 /// store sampled values for all values of observable x and parameter p.
64 /// In such a mode of operation the cache will also not be recalculated
65 /// if the observable p changes
66 
67 RooCachedPdf::RooCachedPdf(const char *name, const char *title, RooAbsPdf& _pdf, const RooArgSet& cacheObs) :
68  RooAbsCachedPdf(name,title),
69  pdf("pdf","pdf",this,_pdf),
70  _cacheObs("cacheObs","cacheObs",this,kFALSE,kFALSE)
71  {
72  _cacheObs.add(cacheObs) ;
73  }
74 
75 
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 /// Copy constructor
79 
80 RooCachedPdf::RooCachedPdf(const RooCachedPdf& other, const char* name) :
81  RooAbsCachedPdf(other,name),
82  pdf("pdf",this,other.pdf),
83  _cacheObs("cacheObs",this,other._cacheObs)
84  {
85  }
86 
87 
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// Destructor
91 
93 {
94 }
95 
96 
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Update contents of cache histogram by resampling the input p.d.f. Note that
100 /// the cache is filled with normalized p.d.f values so that the RooHistPdf
101 /// that represents the cache contents can be explicitly declared as self normalized
102 /// eliminating the need for superfluous numeric calculations of unit normalization.s
103 
105 {
106 
107  if (cache.hist()->get()->getSize()>1) {
108  coutP(Eval) << "RooCachedPdf::fillCacheObject(" << GetName() << ") filling multi-dimensional cache" ;
109  }
110 
111  // Update contents of histogram
112  ((RooAbsPdf&)pdf.arg()).fillDataHist(cache.hist(),&cache.nset(),1.0,kFALSE,kTRUE) ;
113 
114  if (cache.hist()->get()->getSize()>1) {
115  ccoutP(Eval) << endl ;
116  }
117 
118  cache.pdf()->setUnitNorm(kTRUE) ;
119 }
120 
121 
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 /// Defer preferred scan order to cached pdf prefernece
125 
127 {
128  pdf.arg().preferredObservableScanOrder(obs,orderedObs) ;
129 }
130 
131 
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// If this pdf is operated with a fixed set of observables, return
135 /// the subset of the fixed observables that are actual dependents
136 /// of the external input p.d.f. If this p.d.f is operated without
137 /// a fixed set of cache observables, return the actual observables
138 /// of the external input p.d.f given the choice of observables defined
139 /// in nset
140 
142 {
143  if (_cacheObs.getSize()>0) {
144  return pdf.arg().getObservables(_cacheObs) ;
145  }
146 
147  return pdf.arg().getObservables(nset) ;
148 }
149 
150 
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// If this p.d.f is operated with a fixed set of observables, return
154 /// all variables of the external input p.d.f that are not one of
155 /// the cache observables. If this p.d.f is operated in automatic mode,
156 /// return the parameters of the external input p.d.f
157 
159 {
160  if (_cacheObs.getSize()>0) {
161  return pdf.arg().getParameters(_cacheObs) ;
162  }
163  return pdf.arg().getParameters(nset) ;
164 }
165 
166 
ClassImp(RooCachedPdf)
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Definition: RooAbsArg.h:194
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
const RooAbsReal & arg() const
Definition: RooRealProxy.h:43
#define coutP(a)
Definition: RooMsgService.h:33
virtual const RooArgSet * get() const
Definition: RooDataHist.h:77
virtual void preferredObservableScanOrder(const RooArgSet &obs, RooArgSet &orderedObs) const
Interface method for function objects to indicate their prefferred order of observables for scanning ...
virtual void fillCacheObject(PdfCacheElem &cachePdf) const
Update contents of cache histogram by resampling the input p.d.f.
RooSetProxy _cacheObs
Definition: RooCachedPdf.h:48
RooArgSet * getParameters(const RooAbsData *data, Bool_t stripDisconnected=kTRUE) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Definition: RooAbsArg.cxx:559
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
RooRealProxy pdf
Definition: RooCachedPdf.h:47
#define ccoutP(a)
Definition: RooMsgService.h:40
virtual ~RooCachedPdf()
Destructor.
virtual void preferredObservableScanOrder(const RooArgSet &obs, RooArgSet &orderedObs) const
Defer preferred scan order to cached pdf prefernece.
RooDataHist * fillDataHist(RooDataHist *hist, const RooArgSet *nset, Double_t scaleFactor, Bool_t correctForBinVolume=kFALSE, Bool_t showProgress=kFALSE) const
Fill a RooDataHist with values sampled from this function at the bin centers.
virtual RooArgSet * actualParameters(const RooArgSet &nset) const
If this p.d.f is operated with a fixed set of observables, return all variables of the external input...
#define name(a, b)
Definition: linkTestLib0.cpp:5
void setUnitNorm(Bool_t flag)
Definition: RooHistPdf.h:67
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
Int_t getSize() const
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual RooArgSet * actualObservables(const RooArgSet &nset) const
If this pdf is operated with a fixed set of observables, return the subset of the fixed observables t...
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...