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
17Implementation 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 std::endl;
33
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
42RooCachedReal::RooCachedReal(const char *name, const char *title, RooAbsReal& _func) :
44 func("func","func",this,_func),
45 _useCdfBoundaries(false),
46 _cacheSource(false)
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
68RooCachedReal::RooCachedReal(const char *name, const char *title, RooAbsReal& _func, const RooArgSet& cacheObs) :
70 func("func","func",this,_func),
71 _cacheObs("cacheObs","cacheObs",this,false,false),
72 _useCdfBoundaries(false),
73 _cacheSource(false)
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
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/// Interface function to create an internal cache object that represent
98/// each cached function configuration. This interface allows to create and
99/// return a class derived from RooAbsCachedReal::FuncCacheElem so that
100/// a derived class fillCacheObject implementation can utilize extra functionality
101/// defined in such a derived cache class
102
104{
106 if (_cacheSource) {
107 ret->setCacheSource(true) ;
108 }
109 return ret ;
110}
111
112
113
114////////////////////////////////////////////////////////////////////////////////
115/// Update contents of cache histogram by resampling the input function
116
118{
119 unsigned nDim = cache.hist()->get()->size();
120 if (nDim>1) {
121 unsigned nCat(0);
122 for(RooAbsArg * arg : *cache.hist()->get()) {
123 if (dynamic_cast<RooAbsCategory*>(arg)) ++nCat;
124 }
125 if (nDim>nCat+1) {
126 coutP(Eval) << "RooCachedReal::fillCacheObject(" << GetName() << ") filling "
127 << nCat << " + " << nDim-nCat <<" dimensional cache (" << cache.hist()->numEntries() << " points)" <<endl;
128 }
129 }
130
131 // Make deep clone of self and attach to dataset observables
132 if (!cache.sourceClone()) {
133 RooAbsArg* sourceClone = func.arg().cloneTree() ;
134 cache.setSourceClone(static_cast<RooAbsReal*>(sourceClone)) ;
135 cache.sourceClone()->recursiveRedirectServers(*cache.hist()->get()) ;
137 }
138
139 // Iterator over all bins of RooDataHist and fill weights
140 for (Int_t i=0 ; i<cache.hist()->numEntries() ; i++) {
141 const RooArgSet* obs = cache.hist()->get(i) ;
142 double binVal = cache.sourceClone()->getVal(obs) ;
143 cache.hist()->set(i, binVal, 0.);
144 }
145
146 // Delete source clone if we don't cache it
147 if (!cache.cacheSource()) {
148 cache.setSourceClone(nullptr) ;
149 }
150
152
153}
154
155
156
157////////////////////////////////////////////////////////////////////////////////
158/// If this pdf is operated with a fixed set of observables, return
159/// the subset of the fixed observables that are actual dependents
160/// of the external input p.d.f. If this p.d.f is operated without
161/// a fixed set of cache observables, return the actual observables
162/// of the external input p.d.f given the choice of observables defined
163/// in nset
164
166{
167 return func->getObservables(_cacheObs.empty() ? nset : _cacheObs);
168}
169
170
171
172////////////////////////////////////////////////////////////////////////////////
173/// If this p.d.f is operated with a fixed set of observables, return
174/// all variables of the external input p.d.f that are not one of
175/// the cache observables. If this p.d.f is operated in automatic mode,
176/// return the parameters of the external input p.d.f
177
179{
180 return func->getParameters(_cacheObs.empty() ? nset : _cacheObs);
181}
182
183
185{
186 if (operMode()==ADirty) {
188 }
189}
#define coutP(a)
#define ClassImp(name)
Definition Rtypes.h:382
char name[80]
Definition TGX11.cxx:110
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:79
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.
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
Definition RooAbsArg.h:475
OperMode operMode() const
Query the operation mode of this node.
Definition RooAbsArg.h:456
RooChangeTracker * paramTracker()
void setSourceClone(RooAbsReal *newSource)
Abstract base class for functions that need or want to cache their evaluate() output in a RooHistFunc...
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.
Storage_t::size_type size() const
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
RooAbsArg * absArg() const
Return pointer to contained argument.
Definition RooArgProxy.h:46
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Implementation of RooAbsCachedReal that can cache any external RooAbsReal input function provided in ...
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.
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:82
void setCdfBoundaries(bool flag)
Set use of special boundary conditions for c.d.f.s.
Definition RooHistFunc.h:80
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:35