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 
17 RooAbsSelfCachedPdf is an abstract base class for probability
18 density functions whose output is cached in terms of a histogram in
19 all observables between getVal() and evaluate(). For certain
20 p.d.f.s that are very expensive to calculate it may be beneficial
21 to implement them as a RooAbsSelfCachedPdf rather than a
22 RooAbsPdf. Class RooAbsSelfCachedPdf is designed to have its
23 interface identical to that of RooAbsPdf, so any p.d.f can make use
24 of its caching functionality by merely switching its base class.
25 Existing RooAbsPdf objects can also be cached a posteriori with the
26 RooCachedPdf wrapper p.d.f. that takes any RooAbsPdf object as
27 input.
28 **/
29 
30 #include "Riostream.h"
31 
32 #include "RooFit.h"
33 #include "RooAbsSelfCachedPdf.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 RooAbsSelfCachedPdf::RooAbsSelfCachedPdf(const char *name, const char *title, Int_t ipOrder) :
49  RooAbsCachedPdf(name,title,ipOrder)
50  {
51  }
52 
53 
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Copy constructor
57 
59  RooAbsCachedPdf(other,name)
60  {
61  }
62 
63 
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// Destructor
67 
69 {
70 }
71 
72 
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Fill cache with sampling of p.d.f 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  RooAbsSelfCachedPdf* clone2 = (RooAbsSelfCachedPdf*) 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(wgt) ;
92  }
93 
94  cache.pdf()->setUnitNorm(kTRUE) ;
95 
96  delete cloneSet ;
97 }
98 
99 
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 /// Defines observables to be cached, given a set of user defined observables
103 /// Returns the subset of nset that are observables this p.d.f
104 
106 {
107  // Make list of servers
108  RooArgSet *serverSet = new RooArgSet;
109 
110  for (auto server : _serverList) {
111  serverSet->add(*server) ;
112  }
113 
114  // Return servers that are in common with given normalization set
115  return serverSet;
116 }
117 
118 
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 /// Defines parameters on which cache contents depends. Returns
122 /// subset of variables of self that is not contained in the
123 /// supplied nset
124 
126 {
127  RooArgSet *serverSet = new RooArgSet;
128 
129  for (auto server : _serverList) {
130  serverSet->add(*server) ;
131  }
132 
133  // Remove all given observables from server list
134  serverSet->remove(nset,kTRUE,kTRUE);
135 
136  return serverSet;
137 }
138 
139 
140 
141 
142 
143 
144 
RooAbsSelfCachedPdf
Definition: RooAbsSelfCachedPdf.h:21
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooAbsReal.h
RooMsgService.h
RooFit.h
RooDataHist::set
void set(Double_t weight, Double_t wgtErr=-1)
Set the weight and weight error of the bin enclosing the current (i.e.
Definition: RooDataHist.cxx:1332
RooAbsCachedPdf::PdfCacheElem::pdf
RooHistPdf * pdf()
Definition: RooAbsCachedPdf.h:72
RooAbsCachedPdf::disableCache
void disableCache(Bool_t flag)
Definition: RooAbsCachedPdf.h:114
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
RooAbsArg::_serverList
RefCountList_t _serverList
Definition: RooAbsArg.h:587
RooAbsReal::getVal
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
RooDataHist::get
virtual const RooArgSet * get() const
Definition: RooDataHist.h:78
RooAbsSelfCachedPdf::RooAbsSelfCachedPdf
RooAbsSelfCachedPdf()
Definition: RooAbsSelfCachedPdf.h:33
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:584
RooAbsCollection::find
RooAbsArg * find(const char *name) const
Find object with given name in list.
Definition: RooAbsCollection.cxx:813
RooArgSet::add
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
RooAbsSelfCachedPdf::fillCacheObject
virtual void fillCacheObject(PdfCacheElem &cache) const
Fill cache with sampling of p.d.f as defined by the evaluate() implementation.
Definition: RooAbsSelfCachedPdf.cxx:77
RooDataHist
Definition: RooDataHist.h:39
RooDataHist.h
RooAbsCachedPdf::PdfCacheElem::hist
RooDataHist * hist()
Definition: RooAbsCachedPdf.h:73
RooAbsArg::RooArgSet
friend class RooArgSet
Definition: RooAbsArg.h:579
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:1469
RooAbsCachedPdf
Definition: RooAbsCachedPdf.h:25
RooAbsCachedPdf::PdfCacheElem
Definition: RooAbsCachedPdf.h:63
RooHistPdf.h
Double_t
double Double_t
Definition: RtypesCore.h:59
RooDataHist::numEntries
virtual Int_t numEntries() const
Return the number of bins.
Definition: RooDataHist.cxx:1694
name
char name[80]
Definition: TGX11.cxx:110
RooAbsSelfCachedPdf::~RooAbsSelfCachedPdf
virtual ~RooAbsSelfCachedPdf()
Destructor.
Definition: RooAbsSelfCachedPdf.cxx:68
RooAbsSelfCachedPdf::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: RooAbsSelfCachedPdf.cxx:105
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
Riostream.h
RooAbsSelfCachedPdf::actualParameters
virtual RooArgSet * actualParameters(const RooArgSet &nset) const
Defines parameters on which cache contents depends.
Definition: RooAbsSelfCachedPdf.cxx:125
RooAbsSelfCachedPdf.h
RooHistPdf::setUnitNorm
void setUnitNorm(Bool_t flag)
Definition: RooHistPdf.h:68
RooArgSet
Definition: RooArgSet.h:28
int