Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:16

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  *                                                                           *
0004  * Copyright (c) 2000-2005, Regents of the University of California          *
0005  *                          and Stanford University. All rights reserved.    *
0006  *                                                                           *
0007  * Redistribution and use in source and binary forms,                        *
0008  * with or without modification, are permitted according to the terms        *
0009  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
0010  *****************************************************************************/
0011 
0012 #ifndef ROOABSCACHEDPDF
0013 #define ROOABSCACHEDPDF
0014 
0015 #include "RooAbsPdf.h"
0016 #include "RooRealProxy.h"
0017 #include "RooAbsReal.h"
0018 #include "RooHistPdf.h"
0019 #include "RooObjCacheManager.h"
0020 #include "RooAICRegistry.h"
0021 #include "RooChangeTracker.h"
0022 
0023 #include <map>
0024 
0025 class RooAbsCachedPdf : public RooAbsPdf {
0026 public:
0027 
0028   // Default constructor
0029   RooAbsCachedPdf() : _cacheMgr(this,10) {}
0030   RooAbsCachedPdf(const char *name, const char *title, int ipOrder=0);
0031   RooAbsCachedPdf(const RooAbsCachedPdf& other, const char* name=nullptr) ;
0032 
0033   double getValV(const RooArgSet* set=nullptr) const override ;
0034   bool selfNormalized() const override {
0035     // Declare p.d.f self normalized
0036     return true ;
0037   }
0038 
0039   RooAbsPdf* getCachePdf(const RooArgSet& nset) const {
0040     // Return RooHistPdf that represents cache histogram
0041     return getCachePdf(&nset) ;
0042   }
0043   RooDataHist* getCacheHist(const RooArgSet& nset) const {
0044     // Return RooDataHist with cached values
0045     return getCacheHist(&nset) ;
0046   }
0047   RooAbsPdf* getCachePdf(const RooArgSet* nset=nullptr) const ;
0048   RooDataHist* getCacheHist(const RooArgSet* nset=nullptr) const ;
0049 
0050   void setInterpolationOrder(int order) ;
0051   Int_t getInterpolationOrder() const {
0052     // Set interpolation order in RooHistPdf that represent cached histogram
0053     return _ipOrder ;
0054   }
0055 
0056   bool forceAnalyticalInt(const RooAbsArg& dep) const override ;
0057   Int_t getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& analVars, const RooArgSet* normSet, const char* rangeName=nullptr) const override ;
0058   double analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName=nullptr) const override ;
0059 
0060   std::unique_ptr<RooAbsArg> compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext & ctx) const override;
0061 
0062   class PdfCacheElem : public RooAbsCacheElement {
0063   public:
0064     PdfCacheElem(const RooAbsCachedPdf& self, const RooArgSet* nset) ;
0065 
0066     // Cache management functions
0067     RooArgList containedArgs(Action) override ;
0068     void printCompactTreeHook(std::ostream&, const char *, Int_t, Int_t) override ;
0069 
0070     RooHistPdf* pdf() { return _pdf.get() ; }
0071     RooDataHist* hist() { return _hist.get() ; }
0072     const RooArgSet& nset() { return _nset ; }
0073     RooChangeTracker* paramTracker() { return _paramTracker.get() ; }
0074     void setUnitNorm() { pdf()->setUnitNorm(true); }
0075 
0076   private:
0077     // Payload
0078     std::unique_ptr<RooHistPdf>  _pdf ;
0079     std::unique_ptr<RooChangeTracker> _paramTracker ;
0080     std::unique_ptr<RooDataHist> _hist ;
0081     RooArgSet    _nset ;
0082     std::unique_ptr<RooAbsReal>  _norm ;
0083 
0084   } ;
0085 
0086   using CacheElem = PdfCacheElem;
0087 
0088   protected:
0089 
0090   void doEval(RooFit::EvalContext &) const override;
0091 
0092   PdfCacheElem* getCache(const RooArgSet* nset, bool recalculate=true) const ;
0093 
0094   virtual const char* payloadUniqueSuffix() const { return nullptr ; }
0095 
0096   friend class PdfCacheElem ;
0097   virtual const char* binningName() const {
0098     // Return name of binning to be used for creation of cache histogram
0099     return "cache" ;
0100   }
0101   virtual PdfCacheElem* createCache(const RooArgSet* nset) const {
0102     // Create cache storage element
0103     return new PdfCacheElem(*this,nset) ;
0104   }
0105   virtual const char* inputBaseName() const = 0 ;
0106   virtual RooFit::OwningPtr<RooArgSet> actualObservables(const RooArgSet& nset) const = 0 ;
0107   virtual RooFit::OwningPtr<RooArgSet> actualParameters(const RooArgSet& nset) const = 0 ;
0108   virtual RooAbsArg& pdfObservable(RooAbsArg& histObservable) const { return histObservable ; }
0109   virtual void fillCacheObject(PdfCacheElem& cache) const = 0 ;
0110 
0111   mutable RooObjCacheManager _cacheMgr ; //! The cache manager
0112   Int_t _ipOrder ; // Interpolation order for cache histograms
0113 
0114   std::string cacheNameSuffix(const RooArgSet& nset) const ;
0115   virtual TString histNameSuffix() const { return TString("") ; }
0116   void disableCache(bool flag) {
0117     // Flag to disable caching mechanism
0118     _disableCache = flag ;
0119   }
0120 
0121   mutable RooAICRegistry _anaReg ; ///<! Registry for analytical integration codes
0122   class AnaIntConfig {
0123   public:
0124     RooArgSet _allVars ;
0125     RooArgSet _anaVars ;
0126     const RooArgSet* _nset ;
0127     bool    _unitNorm ;
0128   } ;
0129   mutable std::map<Int_t,AnaIntConfig> _anaIntMap ; ///<! Map for analytical integration codes
0130 
0131 
0132 
0133 private:
0134 
0135   bool _disableCache = false; ///< Flag to run object in passthrough (= non-caching mode)
0136 
0137   ClassDefOverride(RooAbsCachedPdf,2) // Abstract base class for cached p.d.f.s
0138 };
0139 
0140 #endif