Logo ROOT  
Reference Guide
RooFFTConvPdf.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 ROOFFTCONVPDF
13#define ROOFFTCONVPDF
14
15#include "RooAbsCachedPdf.h"
16#include "RooRealProxy.h"
17#include "RooSetProxy.h"
18#include "RooAbsReal.h"
19#include "RooHistPdf.h"
20#include "TVirtualFFT.h"
21
22class RooRealVar;
23
24///PDF for the numerical (FFT) convolution of two PDFs.
26public:
27
29 // coverity[UNINIT_CTOR]
30 } ;
31 RooFFTConvPdf(const char *name, const char *title, RooRealVar& convVar, RooAbsPdf& pdf1, RooAbsPdf& pdf2, Int_t ipOrder=2);
32 RooFFTConvPdf(const char *name, const char *title, RooAbsReal& pdfConvVar, RooRealVar& convVar, RooAbsPdf& pdf1, RooAbsPdf& pdf2, Int_t ipOrder=2);
33 RooFFTConvPdf(const RooFFTConvPdf& other, const char* name=0) ;
34 TObject* clone(const char* newname) const override { return new RooFFTConvPdf(*this,newname); }
35 ~RooFFTConvPdf() override ;
36
37 void setShift(double val1, double val2) { _shift1 = val1 ; _shift2 = val2 ; }
39 const RooArgSet& cacheObservables() const { return _cacheObs ; }
40
41 /// Return value of buffer fraction applied in FFT calculation array beyond either
42 /// end of the observable domain to reduce cyclical effects
43 double bufferFraction() const {
44 return _bufFrac ;
45 }
46
47 enum BufStrat { Extend=0, Mirror=1, Flat=2 } ;
48 /// Return the strategy currently used to fill the buffer:
49 /// 'Extend' means is that the input p.d.f convolution observable range is widened to include the buffer range
50 /// 'Flat' means that the buffer is filled with the p.d.f. value at the boundary of the observable range
51 /// 'Mirror' means that the buffer is filled with a mirror image of the p.d.f. around the convolution observable boundary
53 return _bufStrat ;
54 }
56 void setBufferFraction(double frac) ;
57
58 void printMetaArgs(std::ostream& os) const override ;
59
60 // Propagate maximum value estimate of pdf1 as convolution can only result in lower max values
61 Int_t getMaxVal(const RooArgSet& vars) const override { return _pdf1.arg().getMaxVal(vars) ; }
62 double maxVal(Int_t code) const override { return _pdf1.arg().maxVal(code) ; }
63
64
65protected:
66
67 RooRealProxy _x ; ///< Convolution observable
68 RooRealProxy _xprime ; ///< Input function representing value of convolution observable
69 RooRealProxy _pdf1 ; ///< First input p.d.f
70 RooRealProxy _pdf2 ; ///< Second input p.d.f
71 RooSetProxy _params ; ///< Effective parameters of this p.d.f.
72
73 void calcParams() ;
74 bool redirectServersHook(const RooAbsCollection& newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override ;
75
76 std::vector<double> scanPdf(RooRealVar& obs, RooAbsPdf& pdf, const RooDataHist& hist, const RooArgSet& slicePos, Int_t& N, Int_t& N2, Int_t& zeroBin, double shift) const ;
77
78 class FFTCacheElem : public PdfCacheElem {
79 public:
80 FFTCacheElem(const RooFFTConvPdf& self, const RooArgSet* nset) ;
81
83
84 std::unique_ptr<TVirtualFFT> fftr2c1;
85 std::unique_ptr<TVirtualFFT> fftr2c2;
86 std::unique_ptr<TVirtualFFT> fftc2r;
87
88 std::unique_ptr<RooAbsPdf> pdf1Clone;
89 std::unique_ptr<RooAbsPdf> pdf2Clone;
90
91 std::unique_ptr<RooAbsBinning> histBinning;
92 std::unique_ptr<RooAbsBinning> scanBinning;
93 };
94
95 friend class FFTCacheElem ;
96
97 double evaluate() const override { RooArgSet dummy(_x.arg()) ; return getVal(&dummy) ; } ; // dummy
98 const char* inputBaseName() const override ;
99 RooArgSet* actualObservables(const RooArgSet& nset) const override ;
100 RooArgSet* actualParameters(const RooArgSet& nset) const override ;
101 RooAbsArg& pdfObservable(RooAbsArg& histObservable) const override ;
102 void fillCacheObject(PdfCacheElem& cache) const override ;
103 void fillCacheSlice(FFTCacheElem& cache, const RooArgSet& slicePosition) const ;
104
105 PdfCacheElem* createCache(const RooArgSet* nset) const override ;
106 TString histNameSuffix() const override ;
107
108 // mutable std:: map<const RooHistPdf*,CacheAuxInfo*> _cacheAuxInfo ; //! Auxilary Cache information (do not persist)
109 double _bufFrac ; // Sampling buffer size as fraction of domain size
110 BufStrat _bufStrat ; // Strategy to fill the buffer
111
112 double _shift1 ;
113 double _shift2 ;
114
115 RooAbsGenContext* genContext(const RooArgSet &vars, const RooDataSet *prototype=0,
116 const RooArgSet* auxProto=0, bool verbose= false) const override ;
117
118 friend class RooConvGenContext ;
119 RooSetProxy _cacheObs ; ///< Non-convolution observables that are also cached
120
121private:
122
123 void prepareFFTBinning(RooRealVar& convVar) const;
124
125 ClassDefOverride(RooFFTConvPdf,1) // Convolution operator p.d.f based on numeric Fourier transforms
126};
127
128#endif
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
#define N
char name[80]
Definition: TGX11.cxx:110
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
RooAbsCachedPdf is the abstract base class for p.d.f.s that need or want to cache their evaluate() ou...
friend class PdfCacheElem
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
RooAbsGenContext is the abstract base class for generator contexts of RooAbsPdf objects.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:64
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:94
virtual double maxVal(Int_t code) const
Return maximum value for set of observables identified by code assigned in getMaxVal.
virtual Int_t getMaxVal(const RooArgSet &vars) const
Advertise capability to determine maximum value of function for given set of observables.
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:57
void removeAll() override
Remove all argument inset using remove(const RooAbsArg&).
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
RooConvGenContext is an efficient implementation of the generator context specific for RooAbsAnaConvP...
The RooDataHist is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:45
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:55
std::unique_ptr< TVirtualFFT > fftr2c2
Definition: RooFFTConvPdf.h:85
std::unique_ptr< TVirtualFFT > fftc2r
Definition: RooFFTConvPdf.h:86
RooArgList containedArgs(Action) override
Returns all RooAbsArg objects contained in the cache element.
std::unique_ptr< RooAbsPdf > pdf2Clone
Definition: RooFFTConvPdf.h:89
FFTCacheElem(const RooFFTConvPdf &self, const RooArgSet *nset)
Clone input pdf and attach to dataset.
std::unique_ptr< RooAbsBinning > histBinning
Definition: RooFFTConvPdf.h:91
std::unique_ptr< RooAbsBinning > scanBinning
Definition: RooFFTConvPdf.h:92
std::unique_ptr< RooAbsPdf > pdf1Clone
Definition: RooFFTConvPdf.h:88
std::unique_ptr< TVirtualFFT > fftr2c1
Definition: RooFFTConvPdf.h:84
PDF for the numerical (FFT) convolution of two PDFs.
Definition: RooFFTConvPdf.h:25
double maxVal(Int_t code) const override
Return maximum value for set of observables identified by code assigned in getMaxVal.
Definition: RooFFTConvPdf.h:62
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override
calcParams() ;
RooSetProxy _params
Effective parameters of this p.d.f.
Definition: RooFFTConvPdf.h:71
TObject * clone(const char *newname) const override
Definition: RooFFTConvPdf.h:34
BufStrat _bufStrat
void calcParams()
(Re)calculate effective parameters of this p.d.f.
BufStrat bufferStrategy() const
Return the strategy currently used to fill the buffer: 'Extend' means is that the input p....
Definition: RooFFTConvPdf.h:52
void setBufferFraction(double frac)
Change the size of the buffer on either side of the observable range to frac times the size of the ra...
RooArgSet * actualObservables(const RooArgSet &nset) const override
Return the observables to be cached given the normalization set nset.
double bufferFraction() const
Return value of buffer fraction applied in FFT calculation array beyond either end of the observable ...
Definition: RooFFTConvPdf.h:43
TString histNameSuffix() const override
Suffix for cache histogram (added in addition to suffix for cache name)
void setCacheObservables(const RooArgSet &obs)
Definition: RooFFTConvPdf.h:38
void prepareFFTBinning(RooRealVar &convVar) const
Try to improve the binning and inform user if possible.
void fillCacheSlice(FFTCacheElem &cache, const RooArgSet &slicePosition) const
Fill a slice of cachePdf with the output of the FFT convolution calculation.
RooRealProxy _xprime
Input function representing value of convolution observable.
Definition: RooFFTConvPdf.h:68
std::vector< double > scanPdf(RooRealVar &obs, RooAbsPdf &pdf, const RooDataHist &hist, const RooArgSet &slicePos, Int_t &N, Int_t &N2, Int_t &zeroBin, double shift) const
Scan the values of 'pdf' in observable 'obs' using the bin values stored in 'hist' at slice position ...
RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype=0, const RooArgSet *auxProto=0, bool verbose=false) const override
Create appropriate generator context for this convolution.
RooRealProxy _pdf1
First input p.d.f.
Definition: RooFFTConvPdf.h:69
RooRealProxy _x
Convolution observable.
Definition: RooFFTConvPdf.h:67
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition: RooFFTConvPdf.h:97
const RooArgSet & cacheObservables() const
Definition: RooFFTConvPdf.h:39
const char * inputBaseName() const override
Return base name component for cache components in this case 'PDF1_CONV_PDF2'.
RooAbsArg & pdfObservable(RooAbsArg &histObservable) const override
Return p.d.f.
Int_t getMaxVal(const RooArgSet &vars) const override
Advertise capability to determine maximum value of function for given set of observables.
Definition: RooFFTConvPdf.h:61
~RooFFTConvPdf() override
Destructor.
void setShift(double val1, double val2)
Definition: RooFFTConvPdf.h:37
RooRealProxy _pdf2
Second input p.d.f.
Definition: RooFFTConvPdf.h:70
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooNumConvPdf to more intuitively reflect the contents of the p...
void setBufferStrategy(BufStrat bs)
Change strategy to fill the overflow buffer on either side of the convolution observable range.
PdfCacheElem * createCache(const RooArgSet *nset) const override
Return specialized cache subclass for FFT calculations.
void fillCacheObject(PdfCacheElem &cache) const override
Fill the contents of the cache the FFT convolution output.
friend class FFTCacheElem
Definition: RooFFTConvPdf.h:95
RooArgSet * actualParameters(const RooArgSet &nset) const override
Return the parameters on which the cache depends given normalization set nset.
RooSetProxy _cacheObs
Non-convolution observables that are also cached.
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
const T & arg() const
Return reference to object held in proxy.
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:136