Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RooAbsCachedPdf.h
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 #ifndef ROOABSCACHEDPDF
13 #define ROOABSCACHEDPDF
14 
15 #include "RooAbsPdf.h"
16 #include "RooRealProxy.h"
17 #include "RooAbsReal.h"
18 #include "RooHistPdf.h"
19 #include "RooObjCacheManager.h"
20 #include "RooAICRegistry.h"
21 #include <map>
22 class RooArgSet ;
23 class RooChangeTracker ;
24 
25 class RooAbsCachedPdf : public RooAbsPdf {
26 public:
27 
28  RooAbsCachedPdf() {
29  // Default constructor
30  } ;
31  RooAbsCachedPdf(const char *name, const char *title, Int_t ipOrder=0);
32  RooAbsCachedPdf(const RooAbsCachedPdf& other, const char* name=0) ;
33  virtual ~RooAbsCachedPdf() ;
34 
35  virtual Double_t getValV(const RooArgSet* set=0) const ;
36  virtual Bool_t selfNormalized() const {
37  // Declare p.d.f self normalized
38  return kTRUE ;
39  }
40 
41  RooAbsPdf* getCachePdf(const RooArgSet& nset) const {
42  // Return RooHistPdf that represents cache histogram
43  return getCachePdf(&nset) ;
44  }
45  RooDataHist* getCacheHist(const RooArgSet& nset) const {
46  // Return RooDataHist with cached values
47  return getCacheHist(&nset) ;
48  }
49  RooAbsPdf* getCachePdf(const RooArgSet* nset=0) const ;
50  RooDataHist* getCacheHist(const RooArgSet* nset=0) const ;
51 
52  void setInterpolationOrder(Int_t order) ;
53  Int_t getInterpolationOrder() const {
54  // Set interpolation order in RooHistPdf that represent cached histogram
55  return _ipOrder ;
56  }
57 
58  virtual Bool_t forceAnalyticalInt(const RooAbsArg& dep) const ;
59  virtual Int_t getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& analVars, const RooArgSet* normSet, const char* rangeName=0) const ;
60  virtual Double_t analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName=0) const ;
61 
62 
63  class PdfCacheElem : public RooAbsCacheElement {
64  public:
65  PdfCacheElem(const RooAbsCachedPdf& self, const RooArgSet* nset) ;
66  virtual ~PdfCacheElem() ;
67 
68  // Cache management functions
69  virtual RooArgList containedArgs(Action) ;
70  virtual void printCompactTreeHook(std::ostream&, const char *, Int_t, Int_t) ;
71 
72  RooHistPdf* pdf() { return _pdf ; }
73  RooDataHist* hist() { return _hist ; }
74  const RooArgSet& nset() { return _nset ; }
75  RooChangeTracker* paramTracker() { return _paramTracker ; }
76 
77  private:
78  // Payload
79  RooHistPdf* _pdf ;
80  RooChangeTracker* _paramTracker ;
81  RooDataHist* _hist ;
82  RooArgSet _nset ;
83  RooAbsReal* _norm ;
84 
85  } ;
86 
87  protected:
88 
89  PdfCacheElem* getCache(const RooArgSet* nset, Bool_t recalculate=kTRUE) const ;
90  void clearCacheObject(PdfCacheElem& cache) const ;
91 
92  virtual const char* payloadUniqueSuffix() const { return 0 ; }
93 
94  friend class PdfCacheElem ;
95  virtual const char* binningName() const {
96  // Return name of binning to be used for creation of cache histogram
97  return "cache" ;
98  }
99  virtual PdfCacheElem* createCache(const RooArgSet* nset) const {
100  // Create cache storage element
101  return new PdfCacheElem(*this,nset) ;
102  }
103  virtual const char* inputBaseName() const = 0 ;
104  virtual RooArgSet* actualObservables(const RooArgSet& nset) const = 0 ;
105  virtual RooArgSet* actualParameters(const RooArgSet& nset) const = 0 ;
106  virtual RooAbsArg& pdfObservable(RooAbsArg& histObservable) const { return histObservable ; }
107  virtual void fillCacheObject(PdfCacheElem& cache) const = 0 ;
108 
109  mutable RooObjCacheManager _cacheMgr ; // The cache manager
110  Int_t _ipOrder ; // Interpolation order for cache histograms
111 
112  TString cacheNameSuffix(const RooArgSet& nset) const ;
113  virtual TString histNameSuffix() const { return TString("") ; }
114  void disableCache(Bool_t flag) {
115  // Flag to disable caching mechanism
116  _disableCache = flag ;
117  }
118 
119  mutable RooAICRegistry _anaReg ; //! Registry for analytical integration codes
120  class AnaIntConfig {
121  public:
122  RooArgSet _allVars ;
123  RooArgSet _anaVars ;
124  const RooArgSet* _nset ;
125  Bool_t _unitNorm ;
126  } ;
127  mutable std::map<Int_t,AnaIntConfig> _anaIntMap ; //! Map for analytical integration codes
128 
129 
130 
131 private:
132 
133  Bool_t _disableCache ; // Flag to run object in passthrough (= non-caching mode)
134 
135  ClassDef(RooAbsCachedPdf,1) // Abstract base class for cached p.d.f.s
136 };
137 
138 #endif