File indexing completed on 2025-01-18 10:11:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
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
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
0036 return true ;
0037 }
0038
0039 RooAbsPdf* getCachePdf(const RooArgSet& nset) const {
0040
0041 return getCachePdf(&nset) ;
0042 }
0043 RooDataHist* getCacheHist(const RooArgSet& nset) const {
0044
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
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
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
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
0099 return "cache" ;
0100 }
0101 virtual PdfCacheElem* createCache(const RooArgSet* nset) const {
0102
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 ;
0112 Int_t _ipOrder ;
0113
0114 std::string cacheNameSuffix(const RooArgSet& nset) const ;
0115 virtual TString histNameSuffix() const { return TString("") ; }
0116 void disableCache(bool flag) {
0117
0118 _disableCache = flag ;
0119 }
0120
0121 mutable RooAICRegistry _anaReg ;
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 ;
0130
0131
0132
0133 private:
0134
0135 bool _disableCache = false;
0136
0137 ClassDefOverride(RooAbsCachedPdf,2)
0138 };
0139
0140 #endif