ROOT  6.06/09
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 //
14 // BEGIN_HTML
15 // RooAbsSelfCachedReal is an abstract base class for functions whose
16 // output is cached in terms of a histogram in all observables between
17 // getVal() and evaluate(). For certain p.d.f.s that are very
18 // expensive to calculate it may be beneficial to implement them as a
19 // RooAbsSelfCachedReal rather than a RooAbsReal. Class
20 // RooAbsSelfCachedReal is designed to have its interface identical to
21 // that of RooAbsReal, so any p.d.f can make use of its caching
22 // functionality by merely switching its base class. Existing
23 // RooAbsReal objects can also be cached a posteriori with the
24 // RooCachedReal wrapper function that takes any RooAbsReal object as
25 // input.
26 // END_HTML
27 //
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(wgt) ;
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 servers ;
107 
108  TIterator* siter = serverIterator() ;
109  siter->Reset() ;
110  RooAbsArg* server ;
111  while((server=(RooAbsArg*)siter->Next())) {
112  servers.add(*server) ;
113  }
114 
115  // Return servers that are in common with given normalization set
116  return (RooArgSet*) servers.selectCommon(nset) ;
117 
118 }
119 
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Defines parameters on which cache contents depends. Returns
123 /// subset of variables of self that is not contained in the
124 /// supplied nset
125 
127 {
128  // Make list of servers
129  RooArgSet *servers = new RooArgSet ;
130 
131  TIterator* siter = serverIterator() ;
132  siter->Reset() ;
133  RooAbsArg* server ;
134  while((server=(RooAbsArg*)siter->Next())) {
135  servers->add(*server) ;
136  }
137 
138  // Remove all given observables from server list
139  servers->remove(nset,kTRUE,kTRUE) ;
140 
141  return servers ;
142 }
143 
144 
145 
146 
147 
148 
149 
virtual ~RooAbsSelfCachedReal()
Destructor.
void disableCache(Bool_t flag)
TIterator * serverIterator() const
Definition: RooAbsArg.h:112
virtual void Reset()=0
RooAbsCollection * selectCommon(const RooAbsCollection &refColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
void set(Double_t weight, Double_t wgtErr=-1)
Increment the weight of the bin enclosing the coordinates given by 'row' by the specified amount...
int Int_t
Definition: RtypesCore.h:41
STL namespace.
void attachDataSet(const RooAbsData &set)
Replace server nodes with names matching the dataset variable names with those data set variables...
Definition: RooAbsArg.cxx:1496
Iterator abstract base class.
Definition: TIterator.h:32
virtual const RooArgSet * get() const
Definition: RooDataHist.h:77
ClassImp(RooAbsSelfCachedReal) RooAbsSelfCachedReal
Constructor.
virtual RooArgSet * actualObservables(const RooArgSet &nset) const
Defines observables to be cached, given a set of user defined observables Returns the subset of nset ...
friend class RooArgSet
Definition: RooAbsArg.h:469
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
virtual void fillCacheObject(FuncCacheElem &cache) const
Fill cache with sampling of function as defined by the evaluate() implementation. ...
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
double Double_t
Definition: RtypesCore.h:55
virtual Int_t numEntries() const
Return the number of bins.
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
virtual TObject * Next()=0
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual RooArgSet * actualParameters(const RooArgSet &nset) const
Defines parameters on which cache contents depends.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
Definition: RooArgSet.cxx:448