Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 class RooRealVar ;
22 
23 #include <map>
24 
25 ///PDF for the numerical (FFT) convolution of two PDFs.
26 class RooFFTConvPdf : public RooAbsCachedPdf {
27 public:
28 
29  RooFFTConvPdf() {
30  // coverity[UNINIT_CTOR]
31  } ;
32  RooFFTConvPdf(const char *name, const char *title, RooRealVar& convVar, RooAbsPdf& pdf1, RooAbsPdf& pdf2, Int_t ipOrder=2);
33  RooFFTConvPdf(const char *name, const char *title, RooAbsReal& pdfConvVar, RooRealVar& convVar, RooAbsPdf& pdf1, RooAbsPdf& pdf2, Int_t ipOrder=2);
34  RooFFTConvPdf(const RooFFTConvPdf& other, const char* name=0) ;
35  virtual TObject* clone(const char* newname) const { return new RooFFTConvPdf(*this,newname); }
36  virtual ~RooFFTConvPdf() ;
37 
38  void setShift(Double_t val1, Double_t val2) { _shift1 = val1 ; _shift2 = val2 ; }
39  void setCacheObservables(const RooArgSet& obs) { _cacheObs.removeAll() ; _cacheObs.add(obs) ; }
40  const RooArgSet& cacheObservables() const { return _cacheObs ; }
41 
42  Double_t bufferFraction() const {
43  // Return value of buffer fraction applied in FFT calculation array beyond either
44  // end of the observable domain to reduce cyclical effects
45  return _bufFrac ;
46  }
47 
48  enum BufStrat { Extend=0, Mirror=1, Flat=2 } ;
49  BufStrat bufferStrategy() const {
50  // Return the strategy currently used to fill the buffer:
51  // 'Extend' means is that the input p.d.f convolution observable range is widened to include the buffer range
52  // 'Flat' means that the buffer is filled with the p.d.f. value at the boundary of the observable range
53  // 'Mirror' means that the buffer is filled with a mirror image of the p.d.f. around the convolution observable boundary
54  return _bufStrat ;
55  }
56  void setBufferStrategy(BufStrat bs) ;
57  void setBufferFraction(Double_t frac) ;
58 
59  void printMetaArgs(std::ostream& os) const ;
60 
61  // Propagate maximum value estimate of pdf1 as convolution can only result in lower max values
62  virtual Int_t getMaxVal(const RooArgSet& vars) const { return _pdf1.arg().getMaxVal(vars) ; }
63  virtual Double_t maxVal(Int_t code) const { return _pdf1.arg().maxVal(code) ; }
64 
65 
66 protected:
67 
68  RooRealProxy _x ; // Convolution observable
69  RooRealProxy _xprime ; // Input function representing value of convolution observable
70  RooRealProxy _pdf1 ; // First input p.d.f
71  RooRealProxy _pdf2 ; // Second input p.d.f
72  RooSetProxy _params ; // Effective parameters of this p.d.f.
73 
74  void calcParams() ;
75  Bool_t redirectServersHook(const RooAbsCollection& newServerList, Bool_t mustReplaceAll, Bool_t nameChange, Bool_t isRecursive) ;
76 
77  Double_t* scanPdf(RooRealVar& obs, RooAbsPdf& pdf, const RooDataHist& hist, const RooArgSet& slicePos, Int_t& N, Int_t& N2, Int_t& zeroBin, Double_t shift) const ;
78 
79  class FFTCacheElem : public PdfCacheElem {
80  public:
81  FFTCacheElem(const RooFFTConvPdf& self, const RooArgSet* nset) ;
82  ~FFTCacheElem() ;
83 
84  virtual RooArgList containedArgs(Action) ;
85 
86  TVirtualFFT* fftr2c1 ;
87  TVirtualFFT* fftr2c2 ;
88  TVirtualFFT* fftc2r ;
89 
90  RooAbsPdf* pdf1Clone ;
91  RooAbsPdf* pdf2Clone ;
92 
93  RooAbsBinning* histBinning ;
94  RooAbsBinning* scanBinning ;
95 
96  };
97 
98  friend class FFTCacheElem ;
99 
100  virtual Double_t evaluate() const { RooArgSet dummy(_x.arg()) ; return getVal(&dummy) ; } ; // dummy
101  virtual const char* inputBaseName() const ;
102  virtual RooArgSet* actualObservables(const RooArgSet& nset) const ;
103  virtual RooArgSet* actualParameters(const RooArgSet& nset) const ;
104  virtual RooAbsArg& pdfObservable(RooAbsArg& histObservable) const ;
105  virtual void fillCacheObject(PdfCacheElem& cache) const ;
106  void fillCacheSlice(FFTCacheElem& cache, const RooArgSet& slicePosition) const ;
107 
108  virtual PdfCacheElem* createCache(const RooArgSet* nset) const ;
109  virtual TString histNameSuffix() const ;
110 
111  // mutable std::map<const RooHistPdf*,CacheAuxInfo*> _cacheAuxInfo ; //! Auxilary Cache information (do not persist)
112  Double_t _bufFrac ; // Sampling buffer size as fraction of domain size
113  BufStrat _bufStrat ; // Strategy to fill the buffer
114 
115  Double_t _shift1 ;
116  Double_t _shift2 ;
117 
118  virtual RooAbsGenContext* genContext(const RooArgSet &vars, const RooDataSet *prototype=0,
119  const RooArgSet* auxProto=0, Bool_t verbose= kFALSE) const ;
120 
121  friend class RooConvGenContext ;
122  RooSetProxy _cacheObs ; // Non-convolution observables that are also cached
123 
124 private:
125 
126  void prepareFFTBinning(RooRealVar& convVar) const;
127 
128  ClassDef(RooFFTConvPdf,1) // Convolution operator p.d.f based on numeric Fourier transforms
129 };
130 
131 #endif