Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "RooChangeTracker.h"
22
23#include <map>
24
25class RooAbsCachedPdf : public RooAbsPdf {
26public:
27
28 // Default constructor
29 RooAbsCachedPdf() : _cacheMgr(this,10) {}
30 RooAbsCachedPdf(const char *name, const char *title, int ipOrder=0);
31 RooAbsCachedPdf(const RooAbsCachedPdf& other, const char* name=nullptr) ;
32
33 double getValV(const RooArgSet* set=nullptr) const override ;
34 bool selfNormalized() const override {
35 // Declare p.d.f self normalized
36 return true ;
37 }
38
39 RooAbsPdf* getCachePdf(const RooArgSet& nset) const {
40 // Return RooHistPdf that represents cache histogram
41 return getCachePdf(&nset) ;
42 }
43 RooDataHist* getCacheHist(const RooArgSet& nset) const {
44 // Return RooDataHist with cached values
45 return getCacheHist(&nset) ;
46 }
47 RooAbsPdf* getCachePdf(const RooArgSet* nset=nullptr) const ;
48 RooDataHist* getCacheHist(const RooArgSet* nset=nullptr) const ;
49
50 void setInterpolationOrder(int order) ;
52 // Set interpolation order in RooHistPdf that represent cached histogram
53 return _ipOrder ;
54 }
55
56 bool forceAnalyticalInt(const RooAbsArg& dep) const override ;
57 Int_t getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& analVars, const RooArgSet* normSet, const char* rangeName=nullptr) const override ;
58 double analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName=nullptr) const override ;
59
60 std::unique_ptr<RooAbsArg> compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext & ctx) const override;
61
63 public:
64 PdfCacheElem(const RooAbsCachedPdf& self, const RooArgSet* nset) ;
65
66 // Cache management functions
68 void printCompactTreeHook(std::ostream&, const char *, Int_t, Int_t) override ;
69
70 RooHistPdf* pdf() { return _pdf.get() ; }
71 RooDataHist* hist() { return _hist.get() ; }
72 const RooArgSet& nset() { return _nset ; }
74 void setUnitNorm() { pdf()->setUnitNorm(true); }
75
76 private:
77 // Payload
78 std::unique_ptr<RooHistPdf> _pdf ;
79 std::unique_ptr<RooChangeTracker> _paramTracker ;
80 std::unique_ptr<RooDataHist> _hist ;
82 std::unique_ptr<RooAbsReal> _norm ;
83
84 } ;
85
87
88 protected:
89
90 void doEval(RooFit::EvalContext &) const override;
91
92 PdfCacheElem* getCache(const RooArgSet* nset, bool recalculate=true) const ;
93
94 virtual const char* payloadUniqueSuffix() const { return nullptr ; }
95
96 friend class PdfCacheElem ;
97 virtual const char* binningName() const {
98 // Return name of binning to be used for creation of cache histogram
99 return "cache" ;
100 }
101 virtual PdfCacheElem* createCache(const RooArgSet* nset) const {
102 // Create cache storage element
103 return new PdfCacheElem(*this,nset) ;
104 }
105 virtual const char* inputBaseName() const = 0 ;
108 virtual RooAbsArg& pdfObservable(RooAbsArg& histObservable) const { return histObservable ; }
109 virtual void fillCacheObject(PdfCacheElem& cache) const = 0 ;
110
111 mutable RooObjCacheManager _cacheMgr ; //! The cache manager
112 Int_t _ipOrder ; // Interpolation order for cache histograms
113
114 std::string cacheNameSuffix(const RooArgSet& nset) const ;
115 virtual TString histNameSuffix() const { return TString("") ; }
116 void disableCache(bool flag) {
117 // Flag to disable caching mechanism
118 _disableCache = flag ;
119 }
120
121 mutable RooAICRegistry _anaReg ; ///<! Registry for analytical integration codes
123 public:
128 } ;
129 mutable std::map<Int_t,AnaIntConfig> _anaIntMap ; ///<! Map for analytical integration codes
130
131
132
133private:
134
135 bool _disableCache = false; ///< Flag to run object in passthrough (= non-caching mode)
136
137 ClassDefOverride(RooAbsCachedPdf,2) // Abstract base class for cached p.d.f.s
138};
139
140#endif
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
char name[80]
Definition TGX11.cxx:110
Utility class for operator p.d.f classes that keeps track of analytical integration codes and associa...
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
Abstract base class for objects to be stored in RooAbsCache cache manager objects.
RooArgList containedArgs(Action) override
Returns all RooAbsArg objects contained in the cache element.
std::unique_ptr< RooChangeTracker > _paramTracker
RooChangeTracker * paramTracker()
std::unique_ptr< RooAbsReal > _norm
void printCompactTreeHook(std::ostream &, const char *, Int_t, Int_t) override
Print contents of cache when printing self as part of object tree.
std::unique_ptr< RooHistPdf > _pdf
std::unique_ptr< RooDataHist > _hist
Abstract base class for p.d.f.s that need or want to cache their evaluate() output in a RooHistPdf de...
Int_t getInterpolationOrder() const
std::map< Int_t, AnaIntConfig > _anaIntMap
! Map for analytical integration codes
virtual RooAbsArg & pdfObservable(RooAbsArg &histObservable) const
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Advertises internal (analytical) integration capabilities.
double getValV(const RooArgSet *set=nullptr) const override
Implementation of getVal() overriding default implementation of RooAbsPdf.
virtual PdfCacheElem * createCache(const RooArgSet *nset) const
PdfCacheElem * getCache(const RooArgSet *nset, bool recalculate=true) const
Retrieve cache object associated with given choice of observables.
virtual RooFit::OwningPtr< RooArgSet > actualObservables(const RooArgSet &nset) const =0
RooAICRegistry _anaReg
! Registry for analytical integration codes
virtual TString histNameSuffix() const
virtual const char * binningName() const
bool forceAnalyticalInt(const RooAbsArg &dep) const override
Force RooRealIntegral to offer all our actual observable for internal integration.
virtual const char * inputBaseName() const =0
bool selfNormalized() const override
Shows if a PDF is self-normalized, which means that no attempt is made to add a normalization term.
RooAbsPdf * getCachePdf(const RooArgSet &nset) const
RooDataHist * getCacheHist(const RooArgSet &nset) const
std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const override
bool _disableCache
Flag to run object in passthrough (= non-caching mode)
virtual void fillCacheObject(PdfCacheElem &cache) const =0
RooObjCacheManager _cacheMgr
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Implements internal (analytical) integration capabilities.
Int_t _ipOrder
The cache manager.
virtual const char * payloadUniqueSuffix() const
void disableCache(bool flag)
std::string cacheNameSuffix(const RooArgSet &nset) const
Construct string with unique suffix for cache objects based on observable names that define cache con...
void doEval(RooFit::EvalContext &) const override
Base function for computing multiple values of a RooAbsReal.
void setInterpolationOrder(int order)
Change the interpolation order that is used in RooHistPdf cache representation smoothing the RooDataH...
virtual RooFit::OwningPtr< RooArgSet > actualParameters(const RooArgSet &nset) const =0
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Meta object that tracks value changes in a given set of RooAbsArgs by registering itself as value cli...
Container class to hold N-dimensional binned data.
Definition RooDataHist.h:40
const RooArgSet * get() const override
Get bin centre of current bin.
Definition RooDataHist.h:82
A propability density function sampled from a multidimensional histogram.
Definition RooHistPdf.h:30
void setUnitNorm(bool flag)
Definition RooHistPdf.h:78
Implementation of a RooCacheManager<RooAbsCacheElement> that specializes in the storage of cache elem...
Basic string class.
Definition TString.h:139
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
Definition Config.h:35