Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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\file RooCachedReal.cxx
14\class RooCachedReal
15\ingroup Roofitcore
16
17RooCachedReal is an implementation of RooAbsCachedReal that can cache
18any external RooAbsReal input function provided in the constructor.
19**/
20
21#include "Riostream.h"
22
23#include "RooAbsPdf.h"
24#include "RooCachedReal.h"
25#include "RooAbsReal.h"
26#include "RooAbsCategory.h"
27#include "RooMsgService.h"
28#include "RooDataHist.h"
29#include "RooHistPdf.h"
30#include "RooChangeTracker.h"
31
32using namespace std;
33
35 ;
36
37
38////////////////////////////////////////////////////////////////////////////////
39/// Constructor taking name, title and function to be cached. To control
40/// granularity of the binning of the cache histogram set the desired properties
41/// in the binning named "cache" in the observables of the function
42
43RooCachedReal::RooCachedReal(const char *name, const char *title, RooAbsReal& _func) :
45 func("func","func",this,_func),
46 _useCdfBoundaries(kFALSE),
47 _cacheSource(kFALSE)
48 {
49 // Choose same expensive object cache as input function
51 }
52
53
54
55
56////////////////////////////////////////////////////////////////////////////////
57/// Constructor taking name, title and function to be cached and
58/// fixed choice of variable to cache. To control granularity of the
59/// binning of the cache histogram set the desired properties in the
60/// binning named "cache" in the observables of the function.
61/// If the fixed set of cache observables does not match the observables
62/// defined in the use context of the p.d.f the cache is still filled
63/// completely. Ee.g. when it is specified to cache x and p and only x
64/// is a observable in the given use context the cache histogram will
65/// store sampled values for all values of observable x and parameter p.
66/// In such a mode of operation the cache will also not be recalculated
67/// if the observable p changes
68
69RooCachedReal::RooCachedReal(const char *name, const char *title, RooAbsReal& _func, const RooArgSet& cacheObs) :
71 func("func","func",this,_func),
72 _cacheObs("cacheObs","cacheObs",this,kFALSE,kFALSE),
73 _useCdfBoundaries(kFALSE),
74 _cacheSource(kFALSE)
75 {
76 _cacheObs.add(cacheObs) ;
77
78 // Choose same expensive object cache as input function
80 }
81
82
83
84
85////////////////////////////////////////////////////////////////////////////////
86/// Copy constructor
87
88RooCachedReal::RooCachedReal(const RooCachedReal& other, const char* name) :
89 RooAbsCachedReal(other,name),
90 func("func",this,other.func),
91 _cacheObs("cacheObs",this,other._cacheObs),
92 _useCdfBoundaries(other._useCdfBoundaries),
93 _cacheSource(other._cacheSource)
94 {
95 }
96
97
98
99////////////////////////////////////////////////////////////////////////////////
100/// Destructor
101
103{
104}
105
106
107////////////////////////////////////////////////////////////////////////////////
108/// Interface function to create an internal cache object that represent
109/// each cached function configuration. This interface allows to create and
110/// return a class derived from RooAbsCachedReal::FuncCacheElem so that
111/// a derived class fillCacheObject implementation can utilize extra functionality
112/// defined in such a derived cache class
113
115{
117 if (_cacheSource) {
118 ret->setCacheSource(kTRUE) ;
119 }
120 return ret ;
121}
122
123
124
125////////////////////////////////////////////////////////////////////////////////
126/// Update contents of cache histogram by resampling the input function
127
129{
130 unsigned nDim = cache.hist()->get()->getSize();
131 if (nDim>1) {
132 RooFIter iter = cache.hist()->get()->fwdIterator();
133 RooAbsArg* arg ;
134 unsigned nCat(0);
135 while((arg=iter.next())) if (dynamic_cast<RooAbsCategory*>(arg)) ++nCat;
136 if (nDim>nCat+1) {
137 coutP(Eval) << "RooCachedReal::fillCacheObject(" << GetName() << ") filling "
138 << nCat << " + " << nDim-nCat <<" dimensional cache (" << cache.hist()->numEntries() << " points)" <<endl;
139 }
140 }
141
142 // Make deep clone of self and attach to dataset observables
143 if (!cache.sourceClone()) {
144 RooAbsArg* sourceClone = func.arg().cloneTree() ;
145 cache.setSourceClone((RooAbsReal*)sourceClone) ;
146 cache.sourceClone()->recursiveRedirectServers(*cache.hist()->get()) ;
148 }
149
150 // Iterator over all bins of RooDataHist and fill weights
151 for (Int_t i=0 ; i<cache.hist()->numEntries() ; i++) {
152 const RooArgSet* obs = cache.hist()->get(i) ;
153 Double_t binVal = cache.sourceClone()->getVal(obs) ;
154 cache.hist()->set(i, binVal, 0.);
155 }
156
157 // Delete source clone if we don't cache it
158 if (!cache.cacheSource()) {
159 cache.setSourceClone(0) ;
160 }
161
163
164}
165
166
167
168////////////////////////////////////////////////////////////////////////////////
169/// If this pdf is operated with a fixed set of observables, return
170/// the subset of the fixed observables that are actual dependents
171/// of the external input p.d.f. If this p.d.f is operated without
172/// a fixed set of cache observables, return the actual observables
173/// of the external input p.d.f given the choice of observables defined
174/// in nset
175
177{
178 if (_cacheObs.getSize()>0) {
179 return func.arg().getObservables(_cacheObs) ;
180 }
181
182 return func.arg().getObservables(nset) ;
183}
184
185
186
187////////////////////////////////////////////////////////////////////////////////
188/// If this p.d.f is operated with a fixed set of observables, return
189/// all variables of the external input p.d.f that are not one of
190/// the cache observables. If this p.d.f is operated in automatic mode,
191/// return the parameters of the external input p.d.f
192
194{
195 if (_cacheObs.getSize()>0) {
196 return func.arg().getParameters(_cacheObs) ;
197 }
198 return func.arg().getParameters(nset) ;
199}
200
201
203{
204 if (operMode()==ADirty) {
206 }
207}
208
209
210
211
#define coutP(a)
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
char name[80]
Definition TGX11.cxx:110
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:72
RooExpensiveObjectCache & expensiveObjectCache() const
virtual RooAbsArg * cloneTree(const char *newname=0) const
Clone tree expression of objects.
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Given a set of possible observables, return the observables that this PDF depends on.
Definition RooAbsArg.h:313
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition RooAbsArg.h:521
void setOperMode(OperMode mode, Bool_t recurseADirty=kTRUE)
Set the operation mode of this node.
RooArgSet * getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Bool_t recursiveRedirectServers(const RooAbsCollection &newServerList, Bool_t mustReplaceAll=kFALSE, Bool_t nameChange=kFALSE, Bool_t recurseInNewSet=kTRUE)
Recursively replace all servers with the new servers in newSet.
OperMode operMode() const
Query the operation mode of this node.
Definition RooAbsArg.h:502
RooChangeTracker * paramTracker()
void setSourceClone(RooAbsReal *newSource)
RooAbsCachedReal is the abstract base class for functions that need or want to cache their evaluate()...
virtual FuncCacheElem * createCache(const RooArgSet *nset) const
Interface function to create an internal cache object that represent each cached function configurati...
RooAbsCategory is the base class for objects that represent a discrete value with a finite number of ...
Int_t getSize() const
RooFIter fwdIterator() const
One-time forward iterator.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:61
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:91
RooAbsArg * absArg() const
Definition RooArgProxy.h:37
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:29
RooCachedReal is an implementation of RooAbsCachedReal that can cache any external RooAbsReal input f...
virtual void fillCacheObject(FuncCacheElem &cacheFunc) const
Update contents of cache histogram by resampling the input function.
virtual FuncCacheElem * createCache(const RooArgSet *nset) const
Interface function to create an internal cache object that represent each cached function configurati...
Bool_t _cacheSource
RooRealProxy func
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...
Bool_t _useCdfBoundaries
virtual ~RooCachedReal()
Destructor.
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...
RooSetProxy _cacheObs
RooArgSet parameters() const
void set(std::size_t binNumber, double weight, double wgtErr)
Set bin content of bin that was last loaded with get(std::size_t).
Int_t numEntries() const override
Return the number of bins.
const RooArgSet * get() const override
Get bin centre of current bin.
Definition RooDataHist.h:74
A one-time forward iterator working on RooLinkedList or RooAbsCollection.
RooAbsArg * next()
Return next element or nullptr if at end.
void setCdfBoundaries(Bool_t flag)
Set use of special boundary conditions for c.d.f.s.
Definition RooHistFunc.h:65
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...
const T & arg() const
Return reference to object held in proxy.
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47