rf208_convolution.cxx

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'ADDITION AND CONVOLUTION' RooFit tutorial macro #208
00004 // 
00005 // One-dimensional numeric convolution
00006 // (require ROOT to be compiled with --enable-fftw3)
00007 // 
00008 // pdf = landau(t) (x) gauss(t)
00009 // 
00010 //
00011 // 07/2008 - Wouter Verkerke 
00012 //
00013 /////////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef __CINT__
00016 #include "RooGlobalFunc.h"
00017 #endif
00018 #include "RooRealVar.h"
00019 #include "RooDataSet.h"
00020 #include "RooGaussian.h"
00021 #include "RooLandau.h"
00022 #include "RooFFTConvPdf.h"
00023 #include "RooPlot.h"
00024 #include "TCanvas.h"
00025 #include "TH1.h"
00026 #include "TPluginManager.h"
00027 #include "TROOT.h"
00028 
00029 using namespace RooFit ;
00030 
00031 
00032 
00033 class TestBasic208 : public RooFitTestUnit
00034 {
00035 public: 
00036   TestBasic208(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("FFT Convolution operator p.d.f.",refFile,writeRef,verbose) {} ;
00037 
00038   Bool_t isTestAvailable() { 
00039 
00040     TPluginHandler *h;
00041     if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualFFT"))) {
00042       if (h->LoadPlugin() == -1) {
00043         return kFALSE;
00044       } else {
00045         return kTRUE ;
00046       }
00047     }
00048     return kFALSE ;
00049   }
00050 
00051   Double_t ctol() { return 5e-3 ; } // Account for difficult shape of Landau distribution
00052 
00053   Bool_t testCode() {
00054 
00055     // S e t u p   c o m p o n e n t   p d f s 
00056     // ---------------------------------------
00057     
00058     // Construct observable
00059     RooRealVar t("t","t",-10,30) ;
00060     
00061     // Construct landau(t,ml,sl) ;
00062     RooRealVar ml("ml","mean landau",5.,-20,20) ;
00063     RooRealVar sl("sl","sigma landau",1,0.1,10) ;
00064     RooLandau landau("lx","lx",t,ml,sl) ;
00065     
00066     // Construct gauss(t,mg,sg)
00067     RooRealVar mg("mg","mg",0) ;
00068     RooRealVar sg("sg","sg",2,0.1,10) ;
00069     RooGaussian gauss("gauss","gauss",t,mg,sg) ;
00070     
00071     
00072     // C o n s t r u c t   c o n v o l u t i o n   p d f 
00073     // ---------------------------------------
00074     
00075     // Set #bins to be used for FFT sampling to 10000
00076     t.setBins(10000,"cache") ; 
00077     
00078     // Construct landau (x) gauss
00079     RooFFTConvPdf lxg("lxg","landau (X) gauss",t,landau,gauss) ;
00080     
00081         
00082     // 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 
00083     // ----------------------------------------------------------------------
00084     
00085     // Sample 1000 events in x from gxlx
00086     RooDataSet* data = lxg.generate(t,10000) ;
00087     
00088     // Fit gxlx to data
00089     lxg.fitTo(*data) ;
00090     
00091     // Plot data, landau pdf, landau (X) gauss pdf
00092     RooPlot* frame = t.frame(Title("landau (x) gauss convolution")) ;
00093     data->plotOn(frame) ;
00094     lxg.plotOn(frame) ;
00095     landau.plotOn(frame,LineStyle(kDashed)) ;
00096     
00097     regPlot(frame,"rf208_plot1") ;
00098 
00099     delete data ;
00100     return kTRUE ;
00101 
00102   }
00103 } ;
00104 
00105 
00106 

Generated on Tue Jul 5 15:07:46 2011 for ROOT_528-00b_version by  doxygen 1.5.1