Loading [MathJax]/extensions/tex2jax.js
ROOT  6.06/09
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
RooCachedReal.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 // RooCachedReal is an implementation of RooAbsCachedReal that can cache
16 // any external RooAbsReal input function provided in the constructor.
17 // END_HTML
18 //
19 
20 #include "Riostream.h"
21 
22 #include "RooAbsPdf.h"
23 #include "RooCachedReal.h"
24 #include "RooAbsReal.h"
25 #include "RooAbsCategory.h"
26 #include "RooMsgService.h"
27 #include "RooDataHist.h"
28 #include "RooHistPdf.h"
29 #include "RooChangeTracker.h"
30 
31 using namespace std;
32 
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
41 
42 RooCachedReal::RooCachedReal(const char *name, const char *title, RooAbsReal& _func) :
43  RooAbsCachedReal(name,title),
44  func("func","func",this,_func),
45  _useCdfBoundaries(kFALSE),
46  _cacheSource(kFALSE)
47  {
48  // Choose same expensive object cache as input function
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 RooCachedReal::RooCachedReal(const char *name, const char *title, RooAbsReal& _func, const RooArgSet& cacheObs) :
69  RooAbsCachedReal(name,title),
70  func("func","func",this,_func),
71  _cacheObs("cacheObs","cacheObs",this,kFALSE,kFALSE),
72  _useCdfBoundaries(kFALSE),
73  _cacheSource(kFALSE)
74  {
75  _cacheObs.add(cacheObs) ;
76 
77  // Choose same expensive object cache as input function
79  }
80 
81 
82 
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Copy constructor
86 
87 RooCachedReal::RooCachedReal(const RooCachedReal& other, const char* name) :
88  RooAbsCachedReal(other,name),
89  func("func",this,other.func),
90  _cacheObs("cacheObs",this,other._cacheObs),
91  _useCdfBoundaries(other._useCdfBoundaries),
92  _cacheSource(other._cacheSource)
93  {
94  }
95 
96 
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Destructor
100 
102 {
103 }
104 
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Interface function to create an internal cache object that represent
108 /// each cached function configuration. This interface allows to create and
109 /// return a class derived from RooAbsCachedReal::FuncCacheElem so that
110 /// a derived class fillCacheObject implementation can utilize extra functionality
111 /// defined in such a derived cache class
112 
114 {
116  if (_cacheSource) {
117  ret->setCacheSource(kTRUE) ;
118  }
119  return ret ;
120 }
121 
122 
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Update contents of cache histogram by resampling the input function
126 
128 {
129  unsigned nDim = cache.hist()->get()->getSize();
130  if (nDim>1) {
131  RooFIter iter = cache.hist()->get()->fwdIterator();
132  RooAbsArg* arg ;
133  unsigned nCat(0);
134  while((arg=iter.next())) if (dynamic_cast<RooAbsCategory*>(arg)) ++nCat;
135  if (nDim>nCat+1) {
136  coutP(Eval) << "RooCachedReal::fillCacheObject(" << GetName() << ") filling "
137  << nCat << " + " << nDim-nCat <<" dimensional cache (" << cache.hist()->numEntries() << " points)" <<endl;
138  }
139  }
140 
141  // Make deep clone of self and attach to dataset observables
142  if (!cache.sourceClone()) {
143  RooAbsArg* sourceClone = func.arg().cloneTree() ;
144  cache.setSourceClone((RooAbsReal*)sourceClone) ;
145  cache.sourceClone()->recursiveRedirectServers(*cache.hist()->get()) ;
147  }
148 
149  // Iterator over all bins of RooDataHist and fill weights
150  for (Int_t i=0 ; i<cache.hist()->numEntries() ; i++) {
151  const RooArgSet* obs = cache.hist()->get(i) ;
152  Double_t binVal = cache.sourceClone()->getVal(obs) ;
153  cache.hist()->set(binVal) ;
154  }
155 
156  // Delete source clone if we don't cache it
157  if (!cache.cacheSource()) {
158  cache.setSourceClone(0) ;
159  }
160 
162 
163 }
164 
165 
166 
167 ////////////////////////////////////////////////////////////////////////////////
168 /// If this pdf is operated with a fixed set of observables, return
169 /// the subset of the fixed observables that are actual dependents
170 /// of the external input p.d.f. If this p.d.f is operated without
171 /// a fixed set of cache observables, return the actual observables
172 /// of the external input p.d.f given the choice of observables defined
173 /// in nset
174 
176 {
177  if (_cacheObs.getSize()>0) {
178  return func.arg().getObservables(_cacheObs) ;
179  }
180 
181  return func.arg().getObservables(nset) ;
182 }
183 
184 
185 
186 ////////////////////////////////////////////////////////////////////////////////
187 /// If this p.d.f is operated with a fixed set of observables, return
188 /// all variables of the external input p.d.f that are not one of
189 /// the cache observables. If this p.d.f is operated in automatic mode,
190 /// return the parameters of the external input p.d.f
191 
193 {
194  if (_cacheObs.getSize()>0) {
195  return func.arg().getParameters(_cacheObs) ;
196  }
197  return func.arg().getParameters(nset) ;
198 }
199 
200 
202 {
203  if (operMode()==ADirty) {
205  }
206 }
207 
208 
209 
210 
RooFIter fwdIterator() const
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Definition: RooAbsArg.h:194
void set(Double_t weight, Double_t wgtErr=-1)
Increment the weight of the bin enclosing the coordinates given by 'row' by the specified amount...
virtual RooAbsArg * cloneTree(const char *newname=0) const
Clone tree expression of objects.
Definition: RooAbsArg.cxx:2295
virtual FuncCacheElem * createCache(const RooArgSet *nset) const
Interface function to create an internal cache object that represent each cached function configurati...
int Int_t
Definition: RtypesCore.h:41
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...
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
RooExpensiveObjectCache & expensiveObjectCache() const
Definition: RooAbsArg.cxx:2341
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 ~RooCachedReal()
Destructor.
Bool_t _useCdfBoundaries
Definition: RooCachedReal.h:68
virtual void fillCacheObject(FuncCacheElem &cacheFunc) const
Update contents of cache histogram by resampling the input function.
RooArgSet parameters() const
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
RooChangeTracker * paramTracker()
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
RooRealProxy func
Definition: RooCachedReal.h:66
virtual FuncCacheElem * createCache(const RooArgSet *nset) const
Interface function to create an internal cache object that represent each cached function configurati...
RooSetProxy _cacheObs
Definition: RooCachedReal.h:67
void setCdfBoundaries(Bool_t flag)
Definition: RooHistFunc.h:60
RooAbsArg * absArg() const
Definition: RooArgProxy.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
ClassImp(RooCachedReal)
RooAbsArg * next()
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition: RooAbsArg.h:497
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
double func(double *x, double *p)
Definition: stressTF1.cxx:213
virtual Int_t numEntries() const
Return the number of bins.
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...
#define name(a, b)
Definition: linkTestLib0.cpp:5
Bool_t _cacheSource
Definition: RooCachedReal.h:69
void setSourceClone(RooAbsReal *newSource)
OperMode operMode() const
Definition: RooAbsArg.h:399
void setOperMode(OperMode mode, Bool_t recurseADirty=kTRUE)
Change cache operation mode to given mode.
Definition: RooAbsArg.cxx:1753
Int_t getSize() const
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
Bool_t recursiveRedirectServers(const RooAbsCollection &newServerList, Bool_t mustReplaceAll=kFALSE, Bool_t nameChange=kFALSE, Bool_t recurseInNewSet=kTRUE)
Definition: RooAbsArg.cxx:1087
const Bool_t kTRUE
Definition: Rtypes.h:91
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...