RooAbsCachedPdf.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  *                                                                           *
00004  * Copyright (c) 2000-2005, Regents of the University of California          *
00005  *                          and Stanford University. All rights reserved.    *
00006  *                                                                           *
00007  * Redistribution and use in source and binary forms,                        *
00008  * with or without modification, are permitted according to the terms        *
00009  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00010  *****************************************************************************/
00011 
00012 #ifndef ROOABSCACHEDPDF
00013 #define ROOABSCACHEDPDF
00014 
00015 #include "RooAbsPdf.h"
00016 #include "RooRealProxy.h"
00017 #include "RooAbsReal.h"
00018 #include "RooHistPdf.h"
00019 #include "RooObjCacheManager.h"
00020 #include "RooAICRegistry.h"
00021 #include <map>
00022 class RooArgSet ;
00023 class RooChangeTracker ;
00024  
00025 class RooAbsCachedPdf : public RooAbsPdf {
00026 public:
00027 
00028   RooAbsCachedPdf() {
00029     // Default constructor
00030   } ;
00031   RooAbsCachedPdf(const char *name, const char *title, Int_t ipOrder=0);
00032   RooAbsCachedPdf(const RooAbsCachedPdf& other, const char* name=0) ;
00033   virtual ~RooAbsCachedPdf() ;
00034 
00035   virtual Double_t getVal(const RooArgSet* set=0) const ;
00036   virtual Bool_t selfNormalized() const { 
00037     // Declare p.d.f self normalized
00038     return kTRUE ; 
00039   }
00040 
00041   RooAbsPdf* getCachePdf(const RooArgSet& nset) const {
00042     // Return RooHistPdf that represents cache histogram
00043     return getCachePdf(&nset) ;
00044   }
00045   RooDataHist* getCacheHist(const RooArgSet& nset) const {
00046     // Return RooDataHist with cached values
00047     return getCacheHist(&nset) ;
00048   }
00049   RooAbsPdf* getCachePdf(const RooArgSet* nset=0) const ;
00050   RooDataHist* getCacheHist(const RooArgSet* nset=0) const ;
00051 
00052   void setInterpolationOrder(Int_t order) ;
00053   Int_t getInterpolationOrder() const { 
00054     // Set interpolation order in RooHistPdf that represent cached histogram
00055     return _ipOrder ; 
00056   }
00057 
00058   virtual Bool_t forceAnalyticalInt(const RooAbsArg& dep) const ;
00059   virtual Int_t getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& analVars, const RooArgSet* normSet, const char* rangeName=0) const ; 
00060   virtual Double_t analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName=0) const ;
00061 
00062 protected:
00063 
00064   class PdfCacheElem : public RooAbsCacheElement {
00065   public:
00066     PdfCacheElem(const RooAbsCachedPdf& self, const RooArgSet* nset) ;
00067     virtual ~PdfCacheElem()  ;
00068 
00069     // Cache management functions
00070     virtual RooArgList containedArgs(Action) ;
00071     virtual void printCompactTreeHook(std::ostream&, const char *, Int_t, Int_t) ;
00072 
00073     RooHistPdf* pdf() { return _pdf ; }
00074     RooDataHist* hist() { return _hist ; }
00075     const RooArgSet& nset() { return _nset ; }
00076     RooChangeTracker* paramTracker() { return _paramTracker ; }
00077 
00078   private:
00079     // Payload
00080     RooHistPdf*  _pdf ;
00081     RooChangeTracker* _paramTracker ;
00082     RooDataHist* _hist ;
00083     RooArgSet    _nset ;
00084     RooAbsReal*  _norm ;
00085 
00086   } ;
00087 
00088   PdfCacheElem* getCache(const RooArgSet* nset, Bool_t recalculate=kTRUE) const ;
00089   void clearCacheObject(PdfCacheElem& cache) const ;
00090 
00091   virtual const char* payloadUniqueSuffix() const { return 0 ; }
00092   
00093   friend class PdfCacheElem ;
00094   virtual const char* binningName() const { 
00095     // Return name of binning to be used for creation of cache histogram
00096     return "cache" ; 
00097   }
00098   virtual PdfCacheElem* createCache(const RooArgSet* nset) const { 
00099     // Create cache storage element
00100     return new PdfCacheElem(*this,nset) ; 
00101   }
00102   virtual const char* inputBaseName() const = 0 ;
00103   virtual RooArgSet* actualObservables(const RooArgSet& nset) const = 0 ;
00104   virtual RooArgSet* actualParameters(const RooArgSet& nset) const = 0 ;
00105   virtual RooAbsArg& pdfObservable(RooAbsArg& histObservable) const { return histObservable ; }
00106   virtual void fillCacheObject(PdfCacheElem& cache) const = 0 ;
00107 
00108   mutable RooObjCacheManager _cacheMgr ; // The cache manager  
00109   Int_t _ipOrder ; // Interpolation order for cache histograms 
00110  
00111   TString cacheNameSuffix(const RooArgSet& nset) const ;
00112   virtual TString histNameSuffix() const { return TString("") ; }
00113   void disableCache(Bool_t flag) { 
00114     // Flag to disable caching mechanism
00115     _disableCache = flag ; 
00116   }
00117 
00118   mutable RooAICRegistry _anaReg ; //! Registry for analytical integration codes
00119   class AnaIntConfig {
00120   public:
00121     RooArgSet _allVars ;
00122     RooArgSet _anaVars ;
00123     const RooArgSet* _nset ;
00124     Bool_t    _unitNorm ;
00125   } ;
00126   mutable std::map<Int_t,AnaIntConfig> _anaIntMap ; //! Map for analytical integration codes
00127 
00128 
00129 
00130 private:
00131 
00132   Bool_t _disableCache ; // Flag to run object in passthrough (= non-caching mode)
00133 
00134   ClassDef(RooAbsCachedPdf,1) // Abstract base class for cached p.d.f.s
00135 };
00136  
00137 #endif

Generated on Tue Jul 5 14:25:57 2011 for ROOT_528-00b_version by  doxygen 1.5.1