ROOT logo
/////////////////////////////////////////////////////////////////////////
//
// 'ADDITION AND CONVOLUTION' RooFit tutorial macro #208
// 
// One-dimensional numeric convolution
// (require ROOT to be compiled with --enable-fftw3)
// 
// pdf = landau(t) (x) gauss(t)
// 
//
// 07/2008 - Wouter Verkerke 
//
/////////////////////////////////////////////////////////////////////////

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooLandau.h"
#include "RooFFTConvPdf.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH1.h"
using namespace RooFit ;



void rf208_convolution()
{
  // S e t u p   c o m p o n e n t   p d f s 
  // ---------------------------------------

  // Construct observable
  RooRealVar t("t","t",-10,30) ;

  // Construct landau(t,ml,sl) ;
  RooRealVar ml("ml","mean landau",5.,-20,20) ;
  RooRealVar sl("sl","sigma landau",1,0.1,10) ;
  RooLandau landau("lx","lx",t,ml,sl) ;
  
  // Construct gauss(t,mg,sg)
  RooRealVar mg("mg","mg",0) ;
  RooRealVar sg("sg","sg",2,0.1,10) ;
  RooGaussian gauss("gauss","gauss",t,mg,sg) ;


  // C o n s t r u c t   c o n v o l u t i o n   p d f 
  // ---------------------------------------

  // Set #bins to be used for FFT sampling to 10000
  t.setBins(10000,"cache") ; 

  // Construct landau (x) gauss
  RooFFTConvPdf lxg("lxg","landau (X) gauss",t,landau,gauss) ;



  // 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 
  // ----------------------------------------------------------------------

  // Sample 1000 events in x from gxlx
  RooDataSet* data = lxg.generate(t,10000) ;

  // Fit gxlx to data
  lxg.fitTo(*data) ;

  // Plot data, landau pdf, landau (X) gauss pdf
  RooPlot* frame = t.frame(Title("landau (x) gauss convolution")) ;
  data->plotOn(frame) ;
  lxg.plotOn(frame) ;
  landau.plotOn(frame,LineStyle(kDashed)) ;


  // Draw frame on canvas
  new TCanvas("rf208_convolution","rf208_convolution",600,600) ;
  gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ;

}



 rf208_convolution.C:1
 rf208_convolution.C:2
 rf208_convolution.C:3
 rf208_convolution.C:4
 rf208_convolution.C:5
 rf208_convolution.C:6
 rf208_convolution.C:7
 rf208_convolution.C:8
 rf208_convolution.C:9
 rf208_convolution.C:10
 rf208_convolution.C:11
 rf208_convolution.C:12
 rf208_convolution.C:13
 rf208_convolution.C:14
 rf208_convolution.C:15
 rf208_convolution.C:16
 rf208_convolution.C:17
 rf208_convolution.C:18
 rf208_convolution.C:19
 rf208_convolution.C:20
 rf208_convolution.C:21
 rf208_convolution.C:22
 rf208_convolution.C:23
 rf208_convolution.C:24
 rf208_convolution.C:25
 rf208_convolution.C:26
 rf208_convolution.C:27
 rf208_convolution.C:28
 rf208_convolution.C:29
 rf208_convolution.C:30
 rf208_convolution.C:31
 rf208_convolution.C:32
 rf208_convolution.C:33
 rf208_convolution.C:34
 rf208_convolution.C:35
 rf208_convolution.C:36
 rf208_convolution.C:37
 rf208_convolution.C:38
 rf208_convolution.C:39
 rf208_convolution.C:40
 rf208_convolution.C:41
 rf208_convolution.C:42
 rf208_convolution.C:43
 rf208_convolution.C:44
 rf208_convolution.C:45
 rf208_convolution.C:46
 rf208_convolution.C:47
 rf208_convolution.C:48
 rf208_convolution.C:49
 rf208_convolution.C:50
 rf208_convolution.C:51
 rf208_convolution.C:52
 rf208_convolution.C:53
 rf208_convolution.C:54
 rf208_convolution.C:55
 rf208_convolution.C:56
 rf208_convolution.C:57
 rf208_convolution.C:58
 rf208_convolution.C:59
 rf208_convolution.C:60
 rf208_convolution.C:61
 rf208_convolution.C:62
 rf208_convolution.C:63
 rf208_convolution.C:64
 rf208_convolution.C:65
 rf208_convolution.C:66
 rf208_convolution.C:67
 rf208_convolution.C:68
 rf208_convolution.C:69
 rf208_convolution.C:70
 rf208_convolution.C:71
 rf208_convolution.C:72
 rf208_convolution.C:73
 rf208_convolution.C:74
 rf208_convolution.C:75
 rf208_convolution.C:76
 rf208_convolution.C:77
 rf208_convolution.C:78
 rf208_convolution.C:79
 rf208_convolution.C:80
 rf208_convolution.C:81
 rf208_convolution.C:82
 rf208_convolution.C:83
 rf208_convolution.C:84
 rf208_convolution.C:85