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 "RooAbsPdf.h"
22#include "RooCachedReal.h"
23#include "RooAbsReal.h"
24#include "RooAbsCategory.h"
25#include "RooMsgService.h"
26#include "RooDataHist.h"
27#include "RooHistPdf.h"
28#include "RooChangeTracker.h"
29
30#include <ostream>
31
32using std::endl;
33
34////////////////////////////////////////////////////////////////////////////////
35/// Constructor taking name, title and function to be cached. To control
36/// granularity of the binning of the cache histogram set the desired properties
37/// in the binning named "cache" in the observables of the function
38
39RooCachedReal::RooCachedReal(const char *name, const char *title, RooAbsReal &_func)
40 : RooAbsCachedReal(name, title), func("func", "func", this, _func), _useCdfBoundaries(false), _cacheSource(false)
41{
42 // Choose same expensive object cache as input function
44}
45
46
47
48////////////////////////////////////////////////////////////////////////////////
49/// Constructor taking name, title and function to be cached and
50/// fixed choice of variable to cache. To control granularity of the
51/// binning of the cache histogram set the desired properties in the
52/// binning named "cache" in the observables of the function.
53/// If the fixed set of cache observables does not match the observables
54/// defined in the use context of the p.d.f the cache is still filled
55/// completely. Ee.g. when it is specified to cache x and p and only x
56/// is a observable in the given use context the cache histogram will
57/// store sampled values for all values of observable x and parameter p.
58/// In such a mode of operation the cache will also not be recalculated
59/// if the observable p changes
60
61RooCachedReal::RooCachedReal(const char *name, const char *title, RooAbsReal& _func, const RooArgSet& cacheObs) :
63 func("func","func",this,_func),
64 _cacheObs("cacheObs","cacheObs",this,false,false),
65 _useCdfBoundaries(false),
66 _cacheSource(false)
67 {
69
70 // Choose same expensive object cache as input function
72 }
73
74
75
76
77////////////////////////////////////////////////////////////////////////////////
78/// Copy constructor
79
82 func("func",this,other.func),
83 _cacheObs("cacheObs",this,other._cacheObs),
84 _useCdfBoundaries(other._useCdfBoundaries),
85 _cacheSource(other._cacheSource)
86 {
87 }
88
89////////////////////////////////////////////////////////////////////////////////
90/// Interface function to create an internal cache object that represent
91/// each cached function configuration. This interface allows to create and
92/// return a class derived from RooAbsCachedReal::FuncCacheElem so that
93/// a derived class fillCacheObject implementation can utilize extra functionality
94/// defined in such a derived cache class
95
97{
99 if (_cacheSource) {
100 ret->setCacheSource(true) ;
101 }
102 return ret ;
103}
104
105
106
107////////////////////////////////////////////////////////////////////////////////
108/// Update contents of cache histogram by resampling the input function
109
111{
112 unsigned nDim = cache.hist()->get()->size();
113 if (nDim>1) {
114 unsigned nCat(0);
115 for(RooAbsArg * arg : *cache.hist()->get()) {
116 if (dynamic_cast<RooAbsCategory*>(arg)) ++nCat;
117 }
118 if (nDim>nCat+1) {
119 coutP(Eval) << "RooCachedReal::fillCacheObject(" << GetName() << ") filling "
120 << nCat << " + " << nDim-nCat <<" dimensional cache (" << cache.hist()->numEntries() << " points)" << std::endl;
121 }
122 }
123
124 // Make deep clone of self and attach to dataset observables
125 if (!cache.sourceClone()) {
126 RooAbsArg* sourceClone = func.arg().cloneTree() ;
127 cache.setSourceClone(static_cast<RooAbsReal*>(sourceClone)) ;
128 cache.sourceClone()->recursiveRedirectServers(*cache.hist()->get()) ;
130 }
131
132 // Iterator over all bins of RooDataHist and fill weights
133 for (Int_t i=0 ; i<cache.hist()->numEntries() ; i++) {
134 const RooArgSet* obs = cache.hist()->get(i) ;
135 double binVal = cache.sourceClone()->getVal(obs) ;
136 cache.hist()->set(i, binVal, 0.);
137 }
138
139 // Delete source clone if we don't cache it
140 if (!cache.cacheSource()) {
141 cache.setSourceClone(nullptr) ;
142 }
143
145
146}
147
148
149
150////////////////////////////////////////////////////////////////////////////////
151/// If this pdf is operated with a fixed set of observables, return
152/// the subset of the fixed observables that are actual dependents
153/// of the external input p.d.f. If this p.d.f is operated without
154/// a fixed set of cache observables, return the actual observables
155/// of the external input p.d.f given the choice of observables defined
156/// in nset
157
162
163
164
165////////////////////////////////////////////////////////////////////////////////
166/// If this p.d.f is operated with a fixed set of observables, return
167/// all variables of the external input p.d.f that are not one of
168/// the cache observables. If this p.d.f is operated in automatic mode,
169/// return the parameters of the external input p.d.f
170
175
176
178{
179 if (operMode()==ADirty) {
181 }
182}
#define coutP(a)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:142
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
RooExpensiveObjectCache & expensiveObjectCache() const
bool recursiveRedirectServers(const RooAbsCollection &newSet, 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:418
OperMode operMode() const
Query the operation mode of this node.
Definition RooAbsArg.h:398
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.
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:63
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:107
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:78
const T & arg() const
Return reference to object held in proxy.
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
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