Logo ROOT   6.08/07
Reference Guide
rf208_convolution.cxx
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////
2 //
3 // 'ADDITION AND CONVOLUTION' RooFit tutorial macro #208
4 //
5 // One-dimensional numeric convolution
6 // (require ROOT to be compiled with --enable-fftw3)
7 //
8 // pdf = landau(t) (x) gauss(t)
9 //
10 //
11 // 07/2008 - Wouter Verkerke
12 //
13 /////////////////////////////////////////////////////////////////////////
14 
15 #ifndef __CINT__
16 #include "RooGlobalFunc.h"
17 #endif
18 #include "RooRealVar.h"
19 #include "RooDataSet.h"
20 #include "RooGaussian.h"
21 #include "RooLandau.h"
22 #include "RooFFTConvPdf.h"
23 #include "RooPlot.h"
24 #include "TCanvas.h"
25 #include "TH1.h"
26 #include "TPluginManager.h"
27 #include "TROOT.h"
28 
29 using namespace RooFit ;
30 
31 
32 
33 class TestBasic208 : public RooFitTestUnit
34 {
35 public:
36  TestBasic208(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("FFT Convolution operator p.d.f.",refFile,writeRef,verbose) {} ;
37 
38  Bool_t isTestAvailable() {
39 
41  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualFFT"))) {
42  if (h->LoadPlugin() == -1) {
43  return kFALSE;
44  } else {
45  return kTRUE ;
46  }
47  }
48  return kFALSE ;
49  }
50 
51  Double_t ctol() { return 5e-3 ; } // Account for difficult shape of Landau distribution
52 
53  Bool_t testCode() {
54 
55  // S e t u p c o m p o n e n t p d f s
56  // ---------------------------------------
57 
58  // Construct observable
59  RooRealVar t("t","t",-10,30) ;
60 
61  // Construct landau(t,ml,sl) ;
62  RooRealVar ml("ml","mean landau",5.,-20,20) ;
63  RooRealVar sl("sl","sigma landau",1,0.1,10) ;
64  RooLandau landau("lx","lx",t,ml,sl) ;
65 
66  // Construct gauss(t,mg,sg)
67  RooRealVar mg("mg","mg",0) ;
68  RooRealVar sg("sg","sg",2,0.1,10) ;
69  RooGaussian gauss("gauss","gauss",t,mg,sg) ;
70 
71 
72  // C o n s t r u c t c o n v o l u t i o n p d f
73  // ---------------------------------------
74 
75  // Set #bins to be used for FFT sampling to 10000
76  t.setBins(10000,"cache") ;
77 
78  // Construct landau (x) gauss
79  RooFFTConvPdf lxg("lxg","landau (X) gauss",t,landau,gauss) ;
80 
81 
82  // S a m p l e , f i t a n d p l o t c o n v o l u t e d p d f
83  // ----------------------------------------------------------------------
84 
85  // Sample 1000 events in x from gxlx
86  RooDataSet* data = lxg.generate(t,10000) ;
87 
88  // Fit gxlx to data
89  lxg.fitTo(*data) ;
90 
91  // Plot data, landau pdf, landau (X) gauss pdf
92  RooPlot* frame = t.frame(Title("landau (x) gauss convolution")) ;
93  data->plotOn(frame) ;
94  lxg.plotOn(frame) ;
95  landau.plotOn(frame,LineStyle(kDashed)) ;
96 
97  regPlot(frame,"rf208_plot1") ;
98 
99  delete data ;
100  return kTRUE ;
101 
102  }
103 } ;
104 
105 
106 
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Plot dataset on specified frame.
Definition: RooAbsData.cxx:552
TH1 * h
Definition: legend2.C:5
#define gROOT
Definition: TROOT.h:364
Int_t LoadPlugin()
Load the plugin library for this handler.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Landau Distribution p.d.f.
Definition: RooLandau.h:24
RooCmdArg Title(const char *name)
RooCmdArg LineStyle(Style_t style)
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
bool verbose
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
double Double_t
Definition: RtypesCore.h:55
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
const Bool_t kTRUE
Definition: Rtypes.h:91