Logo ROOT  
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 \file RooCachedPdf.cxx
14 \class RooCachedPdf
15 \ingroup Roofitcore
16 
17 RooCachedPdf is an implementation of RooAbsCachedPdf that can cache
18 any external RooAbsPdf input function provided in the constructor.
19 **/
20 
21 #include "Riostream.h"
22 
23 #include "RooAbsPdf.h"
24 #include "RooCachedPdf.h"
25 #include "RooAbsReal.h"
26 #include "RooMsgService.h"
27 #include "RooDataHist.h"
28 #include "RooHistPdf.h"
29 
30 using namespace std;
31 
33  ;
34 
35 
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Constructor taking name, title and function to be cached. To control
39 /// granularity of the binning of the cache histogram set the desired properties
40 /// in the binning named "cache" in the observables of the function. The dimensions
41 /// of the cache are automatically matched to the number of observables used
42 /// in each use context. Multiple cache in different observable may exists
43 /// simultanously if the cached p.d.f is used with multiple observable
44 /// configurations simultaneously
45 
46 RooCachedPdf::RooCachedPdf(const char *name, const char *title, RooAbsPdf& _pdf) :
47  RooAbsCachedPdf(name,title),
48  pdf("pdf","pdf",this,_pdf),
49  _cacheObs("cacheObs","cacheObs",this,kFALSE,kFALSE)
50  {
51  }
52 
53 
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Constructor taking name, title and function to be cached and
57 /// fixed choice of variable to cache. To control granularity of the
58 /// binning of the cache histogram set the desired properties in the
59 /// binning named "cache" in the observables of the function.
60 /// If the fixed set of cache observables does not match the observables
61 /// defined in the use context of the p.d.f the cache is still filled
62 /// completely. Ee.g. when it is specified to cache x and p and only x
63 /// is a observable in the given use context the cache histogram will
64 /// store sampled values for all values of observable x and parameter p.
65 /// In such a mode of operation the cache will also not be recalculated
66 /// if the observable p changes
67 
68 RooCachedPdf::RooCachedPdf(const char *name, const char *title, RooAbsPdf& _pdf, const RooArgSet& cacheObs) :
69  RooAbsCachedPdf(name,title),
70  pdf("pdf","pdf",this,_pdf),
71  _cacheObs("cacheObs","cacheObs",this,kFALSE,kFALSE)
72  {
73  _cacheObs.add(cacheObs) ;
74  }
75 
76 
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// Copy constructor
80 
81 RooCachedPdf::RooCachedPdf(const RooCachedPdf& other, const char* name) :
82  RooAbsCachedPdf(other,name),
83  pdf("pdf",this,other.pdf),
84  _cacheObs("cacheObs",this,other._cacheObs)
85  {
86  }
87 
88 
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// Destructor
92 
94 {
95 }
96 
97 
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// Update contents of cache histogram by resampling the input p.d.f. Note that
101 /// the cache is filled with normalized p.d.f values so that the RooHistPdf
102 /// that represents the cache contents can be explicitly declared as self normalized
103 /// eliminating the need for superfluous numeric calculations of unit normalization.s
104 
106 {
107 
108  if (cache.hist()->get()->getSize()>1) {
109  coutP(Eval) << "RooCachedPdf::fillCacheObject(" << GetName() << ") filling multi-dimensional cache" ;
110  }
111 
112  // Update contents of histogram
113  ((RooAbsPdf&)pdf.arg()).fillDataHist(cache.hist(),&cache.nset(),1.0,kFALSE,kTRUE) ;
114 
115  if (cache.hist()->get()->getSize()>1) {
116  ccoutP(Eval) << endl ;
117  }
118 
119  cache.pdf()->setUnitNorm(kTRUE) ;
120 }
121 
122 
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Defer preferred scan order to cached pdf preference
126 
128 {
129  pdf.arg().preferredObservableScanOrder(obs,orderedObs) ;
130 }
131 
132 
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 /// If this pdf is operated with a fixed set of observables, return
136 /// the subset of the fixed observables that are actual dependents
137 /// of the external input p.d.f. If this p.d.f is operated without
138 /// a fixed set of cache observables, return the actual observables
139 /// of the external input p.d.f given the choice of observables defined
140 /// in nset
141 
143 {
144  if (_cacheObs.getSize()>0) {
145  return pdf.arg().getObservables(_cacheObs) ;
146  }
147 
148  return pdf.arg().getObservables(nset) ;
149 }
150 
151 
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// If this p.d.f is operated with a fixed set of observables, return
155 /// all variables of the external input p.d.f that are not one of
156 /// the cache observables. If this p.d.f is operated in automatic mode,
157 /// return the parameters of the external input p.d.f
158 
160 {
161  if (_cacheObs.getSize()>0) {
162  return pdf.arg().getParameters(_cacheObs) ;
163  }
164  return pdf.arg().getParameters(nset) ;
165 }
166 
167 
RooCachedPdf::actualParameters
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...
Definition: RooCachedPdf.cxx:159
RooCachedPdf
Definition: RooCachedPdf.h:20
RooSetProxy::add
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...
Definition: RooSetProxy.cxx:165
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooAbsReal.h
RooMsgService.h
RooTemplateProxy::arg
const T & arg() const
Return reference to object held in proxy.
Definition: RooTemplateProxy.h:271
RooAbsCachedPdf::PdfCacheElem::pdf
RooHistPdf * pdf()
Definition: RooAbsCachedPdf.h:72
coutP
#define coutP(a)
Definition: RooMsgService.h:31
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
RooDataHist::get
virtual const RooArgSet * get() const
Definition: RooDataHist.h:78
RooCachedPdf::RooCachedPdf
RooCachedPdf()
Definition: RooCachedPdf.h:31
RooAbsArg::getParameters
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:546
RooCachedPdf::preferredObservableScanOrder
virtual void preferredObservableScanOrder(const RooArgSet &obs, RooArgSet &orderedObs) const
Defer preferred scan order to cached pdf preference.
Definition: RooCachedPdf.cxx:127
RooCachedPdf.h
RooAbsPdf.h
RooCachedPdf::actualObservables
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...
Definition: RooCachedPdf.cxx:142
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooDataHist.h
RooAbsCachedPdf::PdfCacheElem::hist
RooDataHist * hist()
Definition: RooAbsCachedPdf.h:73
RooCachedPdf::fillCacheObject
virtual void fillCacheObject(PdfCacheElem &cachePdf) const
Update contents of cache histogram by resampling the input p.d.f.
Definition: RooCachedPdf.cxx:105
ccoutP
#define ccoutP(a)
Definition: RooMsgService.h:39
RooAbsReal::fillDataHist
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.
Definition: RooAbsReal.cxx:1229
RooCachedPdf::_cacheObs
RooSetProxy _cacheObs
Definition: RooCachedPdf.h:57
RooAbsCachedPdf
Definition: RooAbsCachedPdf.h:25
RooAbsCachedPdf::PdfCacheElem
Definition: RooAbsCachedPdf.h:63
RooHistPdf.h
RooAbsArg::getObservables
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Return the observables of this pdf given a set of observables.
Definition: RooAbsArg.h:294
RooCachedPdf::pdf
RooRealProxy pdf
Definition: RooCachedPdf.h:56
name
char name[80]
Definition: TGX11.cxx:110
RooAbsReal::preferredObservableScanOrder
virtual void preferredObservableScanOrder(const RooArgSet &obs, RooArgSet &orderedObs) const
Interface method for function objects to indicate their preferred order of observables for scanning t...
Definition: RooAbsReal.cxx:3947
RooCachedPdf::~RooCachedPdf
virtual ~RooCachedPdf()
Destructor.
Definition: RooCachedPdf.cxx:93
RooAbsPdf
Definition: RooAbsPdf.h:40
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
RooFit::Eval
@ Eval
Definition: RooGlobalFunc.h:68
Riostream.h
RooHistPdf::setUnitNorm
void setUnitNorm(Bool_t flag)
Definition: RooHistPdf.h:68
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:171
RooAbsCachedPdf::PdfCacheElem::nset
const RooArgSet & nset()
Definition: RooAbsCachedPdf.h:74
RooArgSet
Definition: RooArgSet.h:28