-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrf304_uncorrprod.py
77 lines (59 loc) · 2.37 KB
/
rf304_uncorrprod.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
71
72
73
74
75
76
77
# /
#
# 'MULTIDIMENSIONAL MODELS' ROOT.RooFit tutorial macro #304
#
# Simple uncorrelated multi-dimensional p.d.f.s
#
# pdf = gauss(x,mx,sx) * gauss(y,my,sy)
#
#
# 07/2008 - Wouter Verkerke
#
# /
import ROOT
def rf304_uncorrprod():
# C r e a t e c o m p o n e n t p d f s i n x a n d y
# ----------------------------------------------------------------
# Create two p.d.f.s gaussx(x,meanx,sigmax) gaussy(y,meany,sigmay) and its
# variables
x = ROOT.RooRealVar("x", "x", -5, 5)
y = ROOT.RooRealVar("y", "y", -5, 5)
meanx = ROOT.RooRealVar("mean1", "mean of gaussian x", 2)
meany = ROOT.RooRealVar("mean2", "mean of gaussian y", -2)
sigmax = ROOT.RooRealVar("sigmax", "width of gaussian x", 1)
sigmay = ROOT.RooRealVar("sigmay", "width of gaussian y", 5)
gaussx = ROOT.RooGaussian("gaussx", "gaussian PDF", x, meanx, sigmax)
gaussy = ROOT.RooGaussian("gaussy", "gaussian PDF", y, meany, sigmay)
# C o n s t r u c t u n c o r r e l a t e d p r o d u c t p d f
# -------------------------------------------------------------------
# Multiply gaussx and gaussy into a two-dimensional p.d.f. gaussxy
gaussxy = ROOT.RooProdPdf(
"gaussxy", "gaussx*gaussy", ROOT.RooArgList(gaussx, gaussy))
# S a m p l e p d f , l o t p r o j e c t i o n o n x a n d y
# ---------------------------------------------------------------------------
# Generate 10000 events in x and y from gaussxy
data = gaussxy.generate(ROOT.RooArgSet(x, y), 10000)
# Plot x distribution of data and projection of gaussxy x = Int(dy)
# gaussxy(x,y)
xframe = x.frame(ROOT.RooFit.Title("X projection of gauss(x)*gauss(y)"))
data.plotOn(xframe)
gaussxy.plotOn(xframe)
# Plot x distribution of data and projection of gaussxy y = Int(dx)
# gaussxy(x,y)
yframe = y.frame(ROOT.RooFit.Title("Y projection of gauss(x)*gauss(y)"))
data.plotOn(yframe)
gaussxy.plotOn(yframe)
# Make canvas and draw ROOT.RooPlots
c = ROOT.TCanvas("rf304_uncorrprod", "rf304_uncorrprod", 800, 400)
c.Divide(2)
c.cd(1)
ROOT.gPad.SetLeftMargin(0.15)
xframe.GetYaxis().SetTitleOffset(1.4)
xframe.Draw()
c.cd(2)
ROOT.gPad.SetLeftMargin(0.15)
yframe.GetYaxis().SetTitleOffset(1.4)
yframe.Draw()
c.SaveAs("rf304_uncorrprod.png")
if __name__ == "__main__":
rf304_uncorrprod()