ROOT   Reference Guide
Searching...
No Matches
rf208_convolution.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook
4## 'ADDITION AND CONVOLUTION' RooFit tutorial macro #208
5## One-dimensional numeric convolution
6## (require ROOT to be compiled with --enable-fftw3)
7##
8## pdf = landau(t) (x) gauss(t)
9##
10## \macro_image
11## \macro_code
12## \macro_output
13##
14## \date February 2018
15## \authors Clemens Lange, Wouter Verkerke (C version)
16
17import ROOT
18
19# Set up component pdfs
20# ---------------------------------------
21
22# Construct observable
23t = ROOT.RooRealVar("t", "t", -10, 30)
24
25# Construct landau(t,ml,sl)
26ml = ROOT.RooRealVar("ml", "mean landau", 5.0, -20, 20)
27sl = ROOT.RooRealVar("sl", "sigma landau", 1, 0.1, 10)
28landau = ROOT.RooLandau("lx", "lx", t, ml, sl)
29
30# Construct gauss(t,mg,sg)
31mg = ROOT.RooRealVar("mg", "mg", 0)
32sg = ROOT.RooRealVar("sg", "sg", 2, 0.1, 10)
33gauss = ROOT.RooGaussian("gauss", "gauss", t, mg, sg)
34
35# Construct convolution pdf
36# ---------------------------------------
37
38# Set #bins to be used for FFT sampling to 10000
39t.setBins(10000, "cache")
40
41# Construct landau (x) gauss
42lxg = ROOT.RooFFTConvPdf("lxg", "landau (X) gauss", t, landau, gauss)
43
44# Sample, fit and plot convoluted pdf
45# ----------------------------------------------------------------------
46
47# Sample 1000 events in x from gxlx
48data = lxg.generate({t}, 10000)
49
50# Fit gxlx to data
51lxg.fitTo(data, PrintLevel=-1)
52
53# Plot data, pdf, landau (X) gauss pdf
54frame = t.frame(Title="landau (x) gauss convolution")
55data.plotOn(frame)
56lxg.plotOn(frame)
57landau.plotOn(frame, LineStyle="--")
58
59# Draw frame on canvas
60c = ROOT.TCanvas("rf208_convolution", "rf208_convolution", 600, 600)