Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooCachedPdf.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 RooCachedPdf.cxx
14\class RooCachedPdf
15\ingroup Roofitcore
16
17Implementation of RooAbsCachedPdf that can cache
18any external RooAbsPdf input function provided in the constructor.
19**/
20
21#include "Riostream.h"
22
23#include "RooAbsPdf.h"
24#include "RooCachedPdf.h"
25#include "RooAbsReal.h"
26#include "RooMsgService.h"
27#include "RooDataHist.h"
28#include "RooHistPdf.h"
29
30using namespace std;
31
33
34
35////////////////////////////////////////////////////////////////////////////////
36/// Constructor taking name, title and function to be cached. To control
37/// granularity of the binning of the cache histogram set the desired properties
38/// in the binning named "cache" in the observables of the function. The dimensions
39/// of the cache are automatically matched to the number of observables used
40/// in each use context. Multiple cache in different observable may exists
41/// simultaneously if the cached p.d.f is used with multiple observable
42/// configurations simultaneously
43
44RooCachedPdf::RooCachedPdf(const char *name, const char *title, RooAbsPdf& _pdf) :
45 RooAbsCachedPdf(name,title),
46 pdf("pdf","pdf",this,_pdf),
47 _cacheObs("cacheObs","cacheObs",this,false,false)
48 {
49 }
50
51
52
53////////////////////////////////////////////////////////////////////////////////
54/// Constructor taking name, title and function to be cached and
55/// fixed choice of variable to cache. To control granularity of the
56/// binning of the cache histogram set the desired properties in the
57/// binning named "cache" in the observables of the function.
58/// If the fixed set of cache observables does not match the observables
59/// defined in the use context of the p.d.f the cache is still filled
60/// completely. Ee.g. when it is specified to cache x and p and only x
61/// is a observable in the given use context the cache histogram will
62/// store sampled values for all values of observable x and parameter p.
63/// In such a mode of operation the cache will also not be recalculated
64/// if the observable p changes
65
66RooCachedPdf::RooCachedPdf(const char *name, const char *title, RooAbsPdf& _pdf, const RooArgSet& cacheObs) :
67 RooAbsCachedPdf(name,title),
68 pdf("pdf","pdf",this,_pdf),
69 _cacheObs("cacheObs","cacheObs",this,false,false)
70 {
71 _cacheObs.add(cacheObs) ;
72 }
73
74
75
76////////////////////////////////////////////////////////////////////////////////
77/// Copy constructor
78
79RooCachedPdf::RooCachedPdf(const RooCachedPdf& other, const char* name) :
80 RooAbsCachedPdf(other,name),
81 pdf("pdf",this,other.pdf),
82 _cacheObs("cacheObs",this,other._cacheObs)
83 {
84 }
85
86////////////////////////////////////////////////////////////////////////////////
87/// Update contents of cache histogram by resampling the input p.d.f. Note that
88/// the cache is filled with normalized p.d.f values so that the RooHistPdf
89/// that represents the cache contents can be explicitly declared as self normalized
90/// eliminating the need for superfluous numeric calculations of unit normalization.s
91
93{
94
95 if (cache.hist()->get()->size()>1) {
96 coutP(Eval) << "RooCachedPdf::fillCacheObject(" << GetName() << ") filling multi-dimensional cache" ;
97 }
98
99 // Update contents of histogram
100 (const_cast<RooAbsPdf &>(static_cast<RooAbsPdf const&>(pdf.arg()))).fillDataHist(cache.hist(),&cache.nset(),1.0,false,true) ;
101
102 if (cache.hist()->get()->size()>1) {
103 ccoutP(Eval) << endl ;
104 }
105
106 cache.pdf()->setUnitNorm(true) ;
107}
108
109
110
111////////////////////////////////////////////////////////////////////////////////
112/// Defer preferred scan order to cached pdf preference
113
115{
116 pdf.arg().preferredObservableScanOrder(obs,orderedObs) ;
117}
118
119
120
121////////////////////////////////////////////////////////////////////////////////
122/// If this pdf is operated with a fixed set of observables, return
123/// the subset of the fixed observables that are actual dependents
124/// of the external input p.d.f. If this p.d.f is operated without
125/// a fixed set of cache observables, return the actual observables
126/// of the external input p.d.f given the choice of observables defined
127/// in nset
128
130{
131 if (!_cacheObs.empty()) {
133 }
134
135 return pdf->getObservables(nset);
136}
137
138
139
140////////////////////////////////////////////////////////////////////////////////
141/// If this p.d.f is operated with a fixed set of observables, return
142/// all variables of the external input p.d.f that are not one of
143/// the cache observables. If this p.d.f is operated in automatic mode,
144/// return the parameters of the external input p.d.f
145
147{
148 return pdf.arg().getParameters(_cacheObs.empty() ? nset : _cacheObs) ;
149}
150
151
#define coutP(a)
#define ccoutP(a)
#define ClassImp(name)
Definition Rtypes.h:377
char name[80]
Definition TGX11.cxx:110
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.
Abstract base class for p.d.f.s that need or want to cache their evaluate() output in a RooHistPdf de...
Storage_t::size_type size() const
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
RooDataHist * fillDataHist(RooDataHist *hist, const RooArgSet *nset, double scaleFactor, bool correctForBinVolume=false, bool showProgress=false) const
Fill a RooDataHist with values sampled from this function at the bin centers.
virtual void preferredObservableScanOrder(const RooArgSet &obs, RooArgSet &orderedObs) const
Interface method for function objects to indicate their preferred order of observables for scanning t...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Implementation of RooAbsCachedPdf that can cache any external RooAbsPdf input function provided in th...
RooRealProxy pdf
Proxy to p.d.f being cached.
RooSetProxy _cacheObs
Observable to be cached.
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...
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...
void preferredObservableScanOrder(const RooArgSet &obs, RooArgSet &orderedObs) const override
Defer preferred scan order to cached pdf preference.
void fillCacheObject(PdfCacheElem &cachePdf) const override
Update contents of cache histogram by resampling the input p.d.f.
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...
const RooArgSet * get() const override
Get bin centre of current bin.
Definition RooDataHist.h:76
void setUnitNorm(bool flag)
Definition RooHistPdf.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:35