-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwoDGaussToy.py
136 lines (104 loc) · 4.07 KB
/
TwoDGaussToy.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from ROOT import *
from array import array
from tdrStyle import *
setTDRStyle()
import numpy as np
import matplotlib.pyplot as plt
savePath = '/home/mhl/public_html/2016/20161013_investigateGENZrecoz/'
## failed to find an easy way to generate multivari-gaussian using roofit
#w = RooWorkspace('w')
#w.factory('x1[10, 100]')
#w.factory('x2[10, 100]')
#cov = TMatrixDSym(2)
#cov[0][0] = 156.25
#cov[0][1] = -96.4
#cov[1][0] = -96.4
#cov[1][1] = 156.25
#getattr(w,'import')(cov, 'cov')
#w.factory('MultiVarGaussian::mvg({x1,x2},{45.5,45.5},cov)')
## numpy way is much easier
mean = [45.6,45.6]
#cov = [[156.25,-96.4],[-96.4,156.25]]
cov = [[6,-3.75],[-3.75,6]]
x1, x2 = np.random.multivariate_normal(mean, cov, 5000000).T
mZ = x1 + x2
mZ_cutOneLeg = [mZ[i] for i in range(len(x1)) if (x1[i] > 42 and x1[i] < 48)]
mZ_cutTwoLeg = [mZ[i] for i in range(len(x1)) if (x1[i] > 42 and x1[i] < 48 and x2[i] > 10 and x2[i] < 40)]
print len(mZ),len(mZ_cutOneLeg),len(mZ_cutTwoLeg)
hist_mZ = TH1F('hist_mZ', '', 100, 80, 100)
hist_mZ_cutOneLeg = TH1F('hist_mZ_cutOneLeg', '', 100, 80, 100)
hist_mZ_cutTwoLeg = TH1F('hist_mZ_cutTwoLeg', '', 100, 80, 100)
for i in range(len(mZ)):
hist_mZ.Fill(mZ[i])
for i in range(len(mZ_cutOneLeg)):
hist_mZ_cutOneLeg.Fill(mZ_cutOneLeg[i])
for i in range(len(mZ_cutTwoLeg)):
hist_mZ_cutTwoLeg.Fill(mZ_cutTwoLeg[i])
roovar_mZ = RooRealVar('roovar_mZ','',80,100)
dataHist_mZ = RooDataHist('dataHist_mZ', '', RooArgList(roovar_mZ), hist_mZ, 1)
dataHist_mZ_cutOneLeg = RooDataHist('dataHist_mZ_cutOneLeg', '', RooArgList(roovar_mZ), hist_mZ_cutOneLeg, 1)
dataHist_mZ_cutTwoLeg = RooDataHist('dataHist_mZ_cutTwoLeg', '', RooArgList(roovar_mZ), hist_mZ_cutTwoLeg, 1)
mean = RooRealVar('mean','', 90, 80, 100)
sigma = RooRealVar('sigma', '', 10, 0, 30)
gauss = RooGaussian('gauss', '', roovar_mZ,mean,sigma)
### no cut on lep
c1 = TCanvas("c1", "c1", 800, 800)
dummy = TH1D("dummy","dummy",1,80,100)
dummy.SetMinimum(0)
dummy.SetMaximum(hist_mZ.GetMaximum()*1.5)
dummy.SetLineColor(0)
dummy.SetMarkerColor(0)
dummy.SetLineWidth(0)
dummy.SetMarkerSize(0)
dummy.GetYaxis().SetTitle('Events/0.02GeV')
dummy.GetYaxis().SetTitleOffset(1.3)
dummy.GetXaxis().SetTitle('massZ')
dummy.Draw()
mZFrame = roovar_mZ.frame()
dataHist_mZ.plotOn(mZFrame, RooFit.MarkerStyle(20), RooFit.MarkerColor(1))
fit1 = gauss.fitTo(dataHist_mZ)
gauss.plotOn(mZFrame, RooFit.LineColor(4), RooFit.LineWidth(2) )
gauss.paramOn(mZFrame, RooFit.Layout(0.17, 0.4, 0.9), RooFit.Format("NE", RooFit.FixedPrecision(4)))
mZFrame.Draw('same')
c1.SaveAs(savePath+'toy.png')
c1.SaveAs(savePath+'toy.pdf')
### cut on one leg
dummy = TH1D("dummy","dummy",1,80,100)
dummy.SetMinimum(0)
dummy.SetMaximum(hist_mZ_cutOneLeg.GetMaximum()*1.5)
dummy.SetLineColor(0)
dummy.SetMarkerColor(0)
dummy.SetLineWidth(0)
dummy.SetMarkerSize(0)
dummy.GetYaxis().SetTitle('Events/0.02GeV')
dummy.GetYaxis().SetTitleOffset(1.3)
dummy.GetXaxis().SetTitle('massZ')
dummy.Draw()
mZFrame = roovar_mZ.frame()
dataHist_mZ_cutOneLeg.plotOn(mZFrame, RooFit.MarkerStyle(20), RooFit.MarkerColor(1))
fit1 = gauss.fitTo(dataHist_mZ_cutOneLeg)
gauss.plotOn(mZFrame, RooFit.LineColor(4), RooFit.LineWidth(2) )
gauss.paramOn(mZFrame, RooFit.Layout(0.17, 0.4, 0.9), RooFit.Format("NE", RooFit.FixedPrecision(4)))
mZFrame.Draw('same')
c1.SaveAs(savePath+'toy_cutOneLeg.png')
c1.SaveAs(savePath+'toy_cutOneLeg.pdf')
### cut on two leg
dummy = TH1D("dummy","dummy",1,80,100)
dummy.SetMinimum(0)
dummy.SetMaximum(hist_mZ_cutTwoLeg.GetMaximum()*1.5)
dummy.SetLineColor(0)
dummy.SetMarkerColor(0)
dummy.SetLineWidth(0)
dummy.SetMarkerSize(0)
dummy.GetYaxis().SetTitle('Events/0.02GeV')
dummy.GetYaxis().SetTitleOffset(1.3)
dummy.GetXaxis().SetTitle('massZ')
dummy.Draw()
mZFrame = roovar_mZ.frame()
dataHist_mZ_cutTwoLeg.plotOn(mZFrame, RooFit.MarkerStyle(20), RooFit.MarkerColor(1))
fit1 = gauss.fitTo(dataHist_mZ_cutTwoLeg)
gauss.plotOn(mZFrame, RooFit.LineColor(4), RooFit.LineWidth(2) )
gauss.paramOn(mZFrame, RooFit.Layout(0.17, 0.4, 0.9), RooFit.Format("NE", RooFit.FixedPrecision(4)))
mZFrame.Draw('same')
c1.SaveAs(savePath+'toy_cutTwoLeg.png')
c1.SaveAs(savePath+'toy_cutTwoLeg.pdf')