Logo ROOT  
Reference Guide
rf208_convolution.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 ///
5 /// Addition and convolution: one-dimensional numeric convolution
6 ///
7 /// ```
8 /// pdf = landau(t) (x) gauss(t)
9 /// ```
10 ///
11 /// This tutorial requires FFT3 to be enabled.
12 ///
13 /// \macro_image
14 /// \macro_output
15 /// \macro_code
16 ///
17 /// \date 07/2008
18 /// \author Wouter Verkerke
19 
20 #include "RooRealVar.h"
21 #include "RooDataSet.h"
22 #include "RooGaussian.h"
23 #include "RooLandau.h"
24 #include "RooFFTConvPdf.h"
25 #include "RooPlot.h"
26 #include "TCanvas.h"
27 #include "TAxis.h"
28 #include "TH1.h"
29 using namespace RooFit;
30 
31 void rf208_convolution()
32 {
33  // S e t u p c o m p o n e n t p d f s
34  // ---------------------------------------
35 
36  // Construct observable
37  RooRealVar t("t", "t", -10, 30);
38 
39  // Construct landau(t,ml,sl) ;
40  RooRealVar ml("ml", "mean landau", 5., -20, 20);
41  RooRealVar sl("sl", "sigma landau", 1, 0.1, 10);
42  RooLandau landau("lx", "lx", t, ml, sl);
43 
44  // Construct gauss(t,mg,sg)
45  RooRealVar mg("mg", "mg", 0);
46  RooRealVar sg("sg", "sg", 2, 0.1, 10);
47  RooGaussian gauss("gauss", "gauss", t, mg, sg);
48 
49  // C o n s t r u c t c o n v o l u t i o n p d f
50  // ---------------------------------------
51 
52  // Set #bins to be used for FFT sampling to 10000
53  t.setBins(10000, "cache");
54 
55  // Construct landau (x) gauss
56  RooFFTConvPdf lxg("lxg", "landau (X) gauss", t, landau, gauss);
57 
58  // 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
59  // ----------------------------------------------------------------------
60 
61  // Sample 1000 events in x from gxlx
62  RooDataSet *data = lxg.generate(t, 10000);
63 
64  // Fit gxlx to data
65  lxg.fitTo(*data);
66 
67  // Plot data, landau pdf, landau (X) gauss pdf
68  RooPlot *frame = t.frame(Title("landau (x) gauss convolution"));
69  data->plotOn(frame);
70  lxg.plotOn(frame);
71  landau.plotOn(frame, LineStyle(kDashed));
72 
73  // Draw frame on canvas
74  new TCanvas("rf208_convolution", "rf208_convolution", 600, 600);
75  gPad->SetLeftMargin(0.15);
76  frame->GetYaxis()->SetTitleOffset(1.4);
77  frame->Draw();
78 }
TGeant4Unit::mg
static constexpr double mg
Definition: TGeant4SystemOfUnits.h:210
RooPlot::Draw
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:691
RooLandau
Definition: RooLandau.h:24
RooGaussian.h
RooGaussian
Definition: RooGaussian.h:25
TCanvas.h
RooDataSet.h
RooPlot::frame
static RooPlot * frame(const RooAbsRealLValue &var, Double_t xmin, Double_t xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition: RooPlot.cxx:249
TGeant4Unit::gauss
static constexpr double gauss
Definition: TGeant4SystemOfUnits.h:269
RooFit
Definition: RooCFunction1Binding.h:29
RooAbsData::plotOn
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
Definition: RooAbsData.cxx:547
RooPlot.h
RooPlot::GetYaxis
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1256
RooPlot
Definition: RooPlot.h:44
RooRealVar.h
RooFFTConvPdf
PDF for the numerical (FFT) convolution of two PDFs.
Definition: RooFFTConvPdf.h:25
TCanvas
Definition: TCanvas.h:23
TAxis.h
RooFFTConvPdf.h
kDashed
@ kDashed
Definition: TAttLine.h:48
gPad
#define gPad
Definition: TVirtualPad.h:287
RooDataSet
Definition: RooDataSet.h:33
RooFit::LineStyle
RooCmdArg LineStyle(Style_t style)
Definition: RooGlobalFunc.cxx:57
TAttAxis::SetTitleOffset
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:293
RooRealVar
Definition: RooRealVar.h:35
TH1.h
RooFit::Title
RooCmdArg Title(const char *name)
Definition: RooGlobalFunc.cxx:173
RooLandau.h