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
75 private:
76 // Payload
77 std::unique_ptr<RooHistPdf> _pdf ;
78 std::unique_ptr<RooChangeTracker> _paramTracker ;
79 std::unique_ptr<RooDataHist> _hist ;
81 std::unique_ptr<RooAbsReal> _norm ;
82
83 } ;
84
85 protected:
86
87 void computeBatch(cudaStream_t*, double* output, size_t size, RooFit::Detail::DataMap const&) const override;
88
89 PdfCacheElem* getCache(const RooArgSet* nset, bool recalculate=true) const ;
90
91 virtual const char* payloadUniqueSuffix() const { return nullptr ; }
92
93 friend class PdfCacheElem ;
94 virtual const char* binningName() const {
95 // Return name of binning to be used for creation of cache histogram
96 return "cache" ;
97 }
98 virtual PdfCacheElem* createCache(const RooArgSet* nset) const {
99 // Create cache storage element
100 return new PdfCacheElem(*this,nset) ;
101 }
102 virtual const char* inputBaseName() const = 0 ;
105 virtual RooAbsArg& pdfObservable(RooAbsArg& histObservable) const { return histObservable ; }
106 virtual void fillCacheObject(PdfCacheElem& cache) const = 0 ;
107
108 mutable RooObjCacheManager _cacheMgr ; //! The cache manager
109 Int_t _ipOrder ; // Interpolation order for cache histograms
110
111 std::string cacheNameSuffix(const RooArgSet& nset) const ;
112 virtual TString histNameSuffix() const { return TString("") ; }
113 void disableCache(bool flag) {
114 // Flag to disable caching mechanism
115 _disableCache = flag ;
116 }
117
118 mutable RooAICRegistry _anaReg ; ///<! Registry for analytical integration codes
120 public:
125 } ;
126 mutable std::map<Int_t,AnaIntConfig> _anaIntMap ; ///<! Map for analytical integration codes
127
128
129
130private:
131
132 bool _disableCache = false; ///< Flag to run object in passthrough (= non-caching mode)
133
134 ClassDefOverride(RooAbsCachedPdf,2) // Abstract base class for cached p.d.f.s
135};
136
137#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
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:74
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()
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 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.
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
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 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
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
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
const RooArgSet * get() const override
Get bin centre of current bin.
Definition RooDataHist.h:76
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: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:43
static void output()