Logo ROOT  
Reference Guide
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
62 public:
63 PdfCacheElem(const RooAbsCachedPdf& self, const RooArgSet* nset) ;
64
65 // Cache management functions
67 void printCompactTreeHook(std::ostream&, const char *, Int_t, Int_t) override ;
68
69 RooHistPdf* pdf() { return _pdf.get() ; }
70 RooDataHist* hist() { return _hist.get() ; }
71 const RooArgSet& nset() { return _nset ; }
73
74 private:
75 // Payload
76 std::unique_ptr<RooHistPdf> _pdf ;
77 std::unique_ptr<RooChangeTracker> _paramTracker ;
78 std::unique_ptr<RooDataHist> _hist ;
80 std::unique_ptr<RooAbsReal> _norm ;
81
82 } ;
83
84 protected:
85
86 void computeBatch(cudaStream_t*, double* output, size_t size, RooFit::Detail::DataMap const&) const override;
87
88 PdfCacheElem* getCache(const RooArgSet* nset, bool recalculate=true) const ;
89
90 virtual const char* payloadUniqueSuffix() const { return nullptr ; }
91
92 friend class PdfCacheElem ;
93 virtual const char* binningName() const {
94 // Return name of binning to be used for creation of cache histogram
95 return "cache" ;
96 }
97 virtual PdfCacheElem* createCache(const RooArgSet* nset) const {
98 // Create cache storage element
99 return new PdfCacheElem(*this,nset) ;
100 }
101 virtual const char* inputBaseName() const = 0 ;
102 virtual RooArgSet* actualObservables(const RooArgSet& nset) const = 0 ;
103 virtual RooArgSet* actualParameters(const RooArgSet& nset) const = 0 ;
104 virtual RooAbsArg& pdfObservable(RooAbsArg& histObservable) const { return histObservable ; }
105 virtual void fillCacheObject(PdfCacheElem& cache) const = 0 ;
106
107 mutable RooObjCacheManager _cacheMgr ; //! The cache manager
108 Int_t _ipOrder ; // Interpolation order for cache histograms
109
110 std::string cacheNameSuffix(const RooArgSet& nset) const ;
111 virtual TString histNameSuffix() const { return TString("") ; }
112 void disableCache(bool flag) {
113 // Flag to disable caching mechanism
114 _disableCache = flag ;
115 }
116
117 mutable RooAICRegistry _anaReg ; ///<! Registry for analytical integration codes
119 public:
124 } ;
125 mutable std::map<Int_t,AnaIntConfig> _anaIntMap ; ///<! Map for analytical integration codes
126
127
128
129private:
130
131 bool _disableCache = false; ///< Flag to run object in passthrough (= non-caching mode)
132
133 ClassDefOverride(RooAbsCachedPdf,2) // Abstract base class for cached p.d.f.s
134};
135
136#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
char name[80]
Definition: TGX11.cxx:110
RooAICRegistry is a utility class for operator p.d.f classes that keeps track of analytical integrati...
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:71
RooAbsCacheElement is the abstract base class for objects to be stored in RooAbsCache cache manager o...
RooArgList containedArgs(Action) override
Returns all RooAbsArg objects contained in the cache element.
std::unique_ptr< RooChangeTracker > _paramTracker
RooChangeTracker * paramTracker()
PdfCacheElem(const RooAbsCachedPdf &self, const RooArgSet *nset)
Constructor of cache object which owns RooDataHist cache histogram, RooHistPdf pdf that represents is...
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
RooAbsCachedPdf is the abstract base class for p.d.f.s that need or want to cache their evaluate() ou...
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 RooArgSet * actualParameters(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.
void computeBatch(cudaStream_t *, double *output, size_t size, RooFit::Detail::DataMap const &) const override
Base function for computing multiple values of a RooAbsReal.
RooAbsPdf * getCachePdf(const RooArgSet &nset) const
RooDataHist * getCacheHist(const RooArgSet &nset) const
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
virtual RooArgSet * actualObservables(const RooArgSet &nset) const =0
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 setInterpolationOrder(int order)
Change the interpolation order that is used in RooHistPdf cache representation smoothing the RooDataH...
friend class PdfCacheElem
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:56
RooChangeTracker is a meta object that tracks value changes in a given set of RooAbsArgs by registeri...
The RooDataHist is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:39
RooHistPdf implements a probablity density function sampled from a multidimensional histogram.
Definition: RooHistPdf.h:30
Class RooObjCacheManager is an implementation of class RooCacheManager<RooAbsCacheElement> and specia...
Basic string class.
Definition: TString.h:136
static void output()