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(false),
47 _cacheSource(false)
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,false,false),
73 _useCdfBoundaries(false),
74 _cacheSource(false)
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
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(true) ;
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 unsigned nCat(0);
133 for(RooAbsArg * arg : *cache.hist()->get()) {
134 if (dynamic_cast<RooAbsCategory*>(arg)) ++nCat;
135 }
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 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 return func->getObservables(_cacheObs.empty() ? nset : _cacheObs);
179}
180
181
182
183////////////////////////////////////////////////////////////////////////////////
184/// If this p.d.f is operated with a fixed set of observables, return
185/// all variables of the external input p.d.f that are not one of
186/// the cache observables. If this p.d.f is operated in automatic mode,
187/// return the parameters of the external input p.d.f
188
190{
191 return func->getParameters(_cacheObs.empty() ? nset : _cacheObs);
192}
193
194
196{
197 if (operMode()==ADirty) {
199 }
200}
RooAbsReal * _func
Definition RooMinuit.h:90
#define coutP(a)
#define ClassImp(name)
Definition Rtypes.h:377
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:74
RooExpensiveObjectCache & expensiveObjectCache() const
bool recursiveRedirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
void setOperMode(OperMode mode, bool recurseADirty=true)
Set the operation mode of this node.
RooFit::OwningPtr< 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...
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition RooAbsArg.h:500
virtual RooAbsArg * cloneTree(const char *newname=nullptr) const
Clone tree expression of objects.
OperMode operMode() const
Query the operation mode of this node.
Definition RooAbsArg.h:481
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...
A space to attach TBranches.
Int_t getSize() const
Return the number of elements in the collection.
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:62
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:91
RooAbsArg * absArg() const
Return pointer to contained argument.
Definition RooArgProxy.h:47
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
RooCachedReal is an implementation of RooAbsCachedReal that can cache any external RooAbsReal input f...
bool _useCdfBoundaries
Are c.d.f boundary conditions used by the RooHistFuncs?
void fillCacheObject(FuncCacheElem &cacheFunc) const override
Update contents of cache histogram by resampling the input function.
RooFit::OwningPtr< RooArgSet > actualObservables(const RooArgSet &nset) const override
If this pdf is operated with a fixed set of observables, return the subset of the fixed observables t...
void operModeHook() override
bool _cacheSource
Keep an attached clone of the source in the cache for fast operation.
RooRealProxy func
Proxy to function being cached.
~RooCachedReal() override
Destructor.
FuncCacheElem * createCache(const RooArgSet *nset) const override
Interface function to create an internal cache object that represent each cached function configurati...
RooSetProxy _cacheObs
Variables to be cached.
RooFit::OwningPtr< RooArgSet > actualParameters(const RooArgSet &nset) const override
If this p.d.f is operated with a fixed set of observables, return all variables of the external input...
RooArgSet parameters() const
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
void set(std::size_t binNumber, double weight, double wgtErr)
Set bin content of bin that was last loaded with get(std::size_t).
const RooArgSet * get() const override
Get bin centre of current bin.
Definition RooDataHist.h:76
void setCdfBoundaries(bool flag)
Set use of special boundary conditions for c.d.f.s.
Definition RooHistFunc.h:78
const T & arg() const
Return reference to object held in proxy.
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
Definition Config.h:43