-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrf208_convolution.py
70 lines (52 loc) · 1.86 KB
/
rf208_convolution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# /
#
# 'ADDITION AND CONVOLUTION' ROOT.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
#
# /
import ROOT
def rf208_convolution():
# S e t u p c o m p o n e n t p d f s
# ---------------------------------------
# Construct observable
t = ROOT.RooRealVar("t", "t", -10, 30)
# Construct landau(t,ml,sl)
ml = ROOT.RooRealVar("ml", "mean landau", 5., -20, 20)
sl = ROOT.RooRealVar("sl", "sigma landau", 1, 0.1, 10)
landau = ROOT.RooLandau("lx", "lx", t, ml, sl)
# Construct gauss(t,mg,sg)
mg = ROOT.RooRealVar("mg", "mg", 0)
sg = ROOT.RooRealVar("sg", "sg", 2, 0.1, 10)
gauss = ROOT.RooGaussian("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
lxg = ROOT.RooFFTConvPdf("lxg", "landau (X) gauss", t, landau, gauss)
# S a m p l e , 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
data = lxg.generate(ROOT.RooArgSet(t), 10000)
# Fit gxlx to data
lxg.fitTo(data)
# Plot data, pdf, landau (X) gauss pdf
frame = t.frame(ROOT.RooFit.Title("landau (x) gauss convolution"))
data.plotOn(frame)
lxg.plotOn(frame)
landau.plotOn(frame, ROOT.RooFit.LineStyle(ROOT.kDashed))
# Draw frame on canvas
c = ROOT.TCanvas("rf208_convolution", "rf208_convolution", 600, 600)
ROOT.gPad.SetLeftMargin(0.15)
frame.GetYaxis().SetTitleOffset(1.4)
frame.Draw()
c.SaveAs("rf208_convolution.png")
if __name__ == "__main__":
rf208_convolution()