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"
29using namespace RooFit;
30
31void 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}
@ kDashed
Definition: TAttLine.h:48
#define gPad
Definition: TVirtualPad.h:287
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
Calls RooPlot* plotOn(RooPlot* frame, const RooLinkedList& cmdList) const ;.
Definition: RooAbsData.cxx:546
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
PDF for the numerical (FFT) convolution of two PDFs.
Definition: RooFFTConvPdf.h:25
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
Landau distribution p.d.f.
Definition: RooLandau.h:24
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:44
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1277
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:277
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:712
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:294
The Canvas class.
Definition: TCanvas.h:27
RooCmdArg LineStyle(Style_t style)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
static constexpr double gauss
static constexpr double mg
const char * Title
Definition: TXMLSetup.cxx:67