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