forked from froehlia/UHH_EXP18_LHC-Analysis
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFitter.py
52 lines (48 loc) · 2.13 KB
/
Fitter.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
import ROOT
class Fitter(object):
def __init__(self, analyzers):
self.top_hist_MC = 0
self.top_hist = 0
for x in analyzers:
if(x == 'Data'):
self.top_hist = analyzers[x].histograms['top_mass'].hists['top_mass']
elif(self.top_hist_MC == 0):
self.top_hist_MC = analyzers[x].histograms['top_mass'].hists['top_mass']
else:
self.top_hist_MC.Add(analyzers[x].histograms['top_mass'].hists['top_mass'])
self.mean = 0.0
self.unc = 0.0
def fit(self, fit_min, fit_max):
MyStyle = ROOT.TStyle("MyStyle1","My Root Style1")
MyStyle.SetOptStat(0)
MyStyle.SetOptFit(1)
MyStyle.SetOptLogy(False)
ROOT.gROOT.SetStyle("MyStyle1")
if(not self.top_hist == 0):
c = ROOT.TCanvas()
self.top_hist.Draw()
self.top_hist.Fit("gaus", "Q", "", fit_min, fit_max)
fit = self.top_hist.GetFunction("gaus")
self.mean = fit.GetParameter(1)
self.unc = fit.GetParError(1)
print('\n\n\n----------------------------------------------------------')
output = 'Fitted top quark mass in data: ' + str(self.mean) + ' +- ' + str(self.unc) + ' GeV\n\n'
print(output)
output = 'With ' + str(self.top_hist.GetEntries()) + ' top quark candidates'
print(output)
c.SaveAs("plots/ReconstructedTopMass.pdf")
del c
c = ROOT.TCanvas()
self.top_hist_MC.Draw()
self.top_hist_MC.Fit("gaus", "Q", "", fit_min, fit_max)
fit = self.top_hist_MC.GetFunction("gaus")
self.mean = fit.GetParameter(1)
self.unc = fit.GetParError(1)
print('\n\n\n----------------------------------------------------------')
output = 'Fitted top quark mass in Monte Carlo: ' + str(self.mean) + ' +- ' + str(self.unc) + ' GeV\n\n'
print(output)
output = 'With ' + str(self.top_hist_MC.GetEntries()) + ' top quark candidates\n'
print(output)
c.SaveAs("plots/ReconstructedTopMass_MC.pdf")
del c
return self.top_hist_MC