Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooAbsSelfCachedReal.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 RooAbsSelfCachedReal.cxx
14\class RooAbsSelfCachedReal
15\ingroup Roofitcore
16
17RooAbsSelfCachedReal is an abstract base class for functions whose
18output is cached in terms of a histogram in all observables between
19getVal() and evaluate(). For certain p.d.f.s that are very
20expensive to calculate it may be beneficial to implement them as a
21RooAbsSelfCachedReal rather than a RooAbsReal. Class
22RooAbsSelfCachedReal is designed to have its interface identical to
23that of RooAbsReal, so any p.d.f can make use of its caching
24functionality by merely switching its base class. Existing
25RooAbsReal objects can also be cached a posteriori with the
26RooCachedReal wrapper function that takes any RooAbsReal object as
27input.
28**/
29
30#include "Riostream.h"
31
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
47RooAbsSelfCachedReal::RooAbsSelfCachedReal(const char *name, const char *title, Int_t ipOrder) :
48 RooAbsCachedReal(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 function 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(true) ;
82 RooAbsSelfCachedReal* clone2 = (RooAbsSelfCachedReal*) cloneSet->find(GetName()) ;
83 clone2->disableCache(true) ;
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 wgt = clone2->getVal(obs) ;
90 cacheHist.set(i, wgt, 0.);
91 }
92
93 delete cloneSet ;
94}
95
96
97
98////////////////////////////////////////////////////////////////////////////////
99/// Defines observables to be cached, given a set of user defined observables
100/// Returns the subset of nset that are observables this p.d.f
101
103{
104 // Make list of servers
105 RooArgSet serverSet;
106
107 for (auto server : _serverList) {
108 serverSet.add(*server);
109 }
110
111 // Return servers that are in common with given normalization set
112 return RooFit::OwningPtr<RooArgSet>{(RooArgSet*) serverSet.selectCommon(nset)};
113
114}
115
116
117////////////////////////////////////////////////////////////////////////////////
118/// Defines parameters on which cache contents depends. Returns
119/// subset of variables of self that is not contained in the
120/// supplied nset
121
123{
124 // Make list of servers
125 RooArgSet *serverSet = new RooArgSet;
126
127 for (auto server : _serverList) {
128 serverSet->add(*server);
129 }
130
131 // Remove all given observables from server list
132 serverSet->remove(nset,true,true);
133
134 return RooFit::OwningPtr<RooArgSet>{serverSet};
135}
#define ClassImp(name)
Definition Rtypes.h:377
char name[80]
Definition TGX11.cxx:110
RefCountList_t _serverList
Definition RooAbsArg.h:629
void attachDataSet(const RooAbsData &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
RooAbsCachedReal is the abstract base class for functions that need or want to cache their evaluate()...
void disableCache(bool flag)
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
bool selectCommon(const RooAbsCollection &refColl, RooAbsCollection &outColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:91
RooAbsSelfCachedReal is an abstract base class for functions whose output is cached in terms of a his...
RooFit::OwningPtr< RooArgSet > actualParameters(const RooArgSet &nset) const override
Defines parameters on which cache contents depends.
~RooAbsSelfCachedReal() override
Destructor.
void fillCacheObject(FuncCacheElem &cache) const override
Fill cache with sampling of function as defined by the evaluate() implementation.
RooFit::OwningPtr< RooArgSet > actualObservables(const RooArgSet &nset) const override
Defines observables to be cached, given a set of user defined observables Returns the subset of nset ...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:178
The RooDataHist is a container class to hold N-dimensional binned data.
Definition RooDataHist.h:39
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
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