Logo ROOT  
Reference Guide
RooAbsSelfCachedPdf.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 RooAbsSelfCachedPdf.cxx
14\class RooAbsSelfCachedPdf
15\ingroup Roofitcore
16
17RooAbsSelfCachedPdf is an abstract base class for probability
18density functions whose output is cached in terms of a histogram in
19all observables between getVal() and evaluate(). For certain
20p.d.f.s that are very expensive to calculate it may be beneficial
21to implement them as a RooAbsSelfCachedPdf rather than a
22RooAbsPdf. Class RooAbsSelfCachedPdf is designed to have its
23interface identical to that of RooAbsPdf, so any p.d.f can make use
24of its caching functionality by merely switching its base class.
25Existing RooAbsPdf objects can also be cached a posteriori with the
26RooCachedPdf wrapper p.d.f. that takes any RooAbsPdf object as
27input.
28**/
29
30#include "Riostream.h"
31
32#include "RooAbsSelfCachedPdf.h"
33#include "RooAbsReal.h"
34#include "RooMsgService.h"
35#include "RooDataHist.h"
36#include "RooHistPdf.h"
37
38using namespace std ;
39
41
42
43
44////////////////////////////////////////////////////////////////////////////////
45/// Constructor
46
47RooAbsSelfCachedPdf::RooAbsSelfCachedPdf(const char *name, const char *title, Int_t ipOrder) :
48 RooAbsCachedPdf(name,title,ipOrder)
49 {
50 }
51
52
53
54////////////////////////////////////////////////////////////////////////////////
55/// Copy constructor
56
59 {
60 }
61
62
63
64////////////////////////////////////////////////////////////////////////////////
65/// Destructor
66
68{
69}
70
71
72
73////////////////////////////////////////////////////////////////////////////////
74/// Fill cache with sampling of p.d.f as defined by the evaluate() implementation
75
77{
78 RooDataHist& cacheHist = *cache.hist() ;
79
80 // Make deep clone of self in non-caching mde and attach to dataset observables
81 RooArgSet* cloneSet = (RooArgSet*) RooArgSet(*this).snapshot(kTRUE) ;
82 RooAbsSelfCachedPdf* clone2 = (RooAbsSelfCachedPdf*) cloneSet->find(GetName()) ;
83 clone2->disableCache(kTRUE) ;
84 clone2->attachDataSet(cacheHist) ;
85
86 // Iterator over all bins of RooDataHist and fill weights
87 for (Int_t i=0 ; i<cacheHist.numEntries() ; i++) {
88 const RooArgSet* obs = cacheHist.get(i) ;
89 Double_t wgt = clone2->getVal(obs) ;
90 cacheHist.set(i, wgt, 0.);
91 }
92
93 cache.pdf()->setUnitNorm(kTRUE) ;
94
95 delete cloneSet ;
96}
97
98
99
100////////////////////////////////////////////////////////////////////////////////
101/// Defines observables to be cached, given a set of user defined observables
102/// Returns the subset of nset that are observables this p.d.f
103
105{
106 // Make list of servers
107 RooArgSet *serverSet = new RooArgSet;
108
109 for (auto server : _serverList) {
110 serverSet->add(*server) ;
111 }
112
113 // Return servers that are in common with given normalization set
114 return serverSet;
115}
116
117
118
119////////////////////////////////////////////////////////////////////////////////
120/// Defines parameters on which cache contents depends. Returns
121/// subset of variables of self that is not contained in the
122/// supplied nset
123
125{
126 RooArgSet *serverSet = new RooArgSet;
127
128 for (auto server : _serverList) {
129 serverSet->add(*server) ;
130 }
131
132 // Remove all given observables from server list
133 serverSet->remove(nset,kTRUE,kTRUE);
134
135 return serverSet;
136}
137
138
139
140
141
142
143
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:375
char name[80]
Definition: TGX11.cxx:110
friend class RooArgSet
Definition: RooAbsArg.h:651
RefCountList_t _serverList
Definition: RooAbsArg.h:659
void attachDataSet(const RooAbsData &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
Definition: RooAbsArg.cxx:1630
RooAbsCachedPdf is the abstract base class for p.d.f.s that need or want to cache their evaluate() ou...
void disableCache(bool flag)
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
RooAbsArg * find(const char *name) const
Find object with given name in list.
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:93
RooAbsSelfCachedPdf is an abstract base class for probability density functions whose output is cache...
void fillCacheObject(PdfCacheElem &cache) const override
Fill cache with sampling of p.d.f as defined by the evaluate() implementation.
RooArgSet * actualParameters(const RooArgSet &nset) const override
Defines parameters on which cache contents depends.
RooArgSet * actualObservables(const RooArgSet &nset) const override
Defines observables to be cached, given a set of user defined observables Returns the subset of nset ...
~RooAbsSelfCachedPdf() override
Destructor.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
The RooDataHist is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:45
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:82
void setUnitNorm(Bool_t flag)
Definition: RooHistPdf.h:82
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47