-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericRootFitter.py
More file actions
173 lines (136 loc) · 5.99 KB
/
GenericRootFitter.py
File metadata and controls
173 lines (136 loc) · 5.99 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import ROOT
from ROOT import *
print("Begining Moderate Dalitz Cut")
cutnum = 180
listGoodness = []
while cutnum <= 340:
bufferString = "Dalitz Delta Medium "+str(cutnum)
print("File being fit: "+str(bufferString))
rootdir = '/cms/data18/scherer/LumiFilteredScouting/2012B/Finished/'
fdata = TFile(rootdir+"Filtered20B.root")
#fdata.cd("genHistos/Corrected/DalitzCuts/Moderate/")
bufferString = "genHistos/Corrected/DalitzCuts/Moderate/Dalitz_Delta_"+str(cutnum)
hist = fdata.Get(bufferString)
#Fancy Background
#background = TF1("background", '[0]*((1-x/8000)**([1])/((x/8000)**([2]+[3]*log(x/8000))))')
#background.SetParName(0,"P0")
#background.SetParName(1,"P1")
#background.SetParName(3,"P3")
#background.SetParName(2,"P2")
#background.SetParameter(0,1)
#background.SetParameter(1,5)
#background.SetParameter(2,10)
#background.SetParameter(3,1)
#Test Background
background = TF1("background", "[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",160,350)
background.SetParName(0,"P0")
background.SetParName(1,"P1")
background.SetParName(2,"P2")
background.SetParameter(0,1)
background.SetParameter(1,-50)
background.SetParameter(2,-10)
#background.SetParameteres(1.,1.,1.,1.)
hist.Fit("background", "R")
fitter = TVirtualFitter.GetFitter()
for i in range(0,4):
print(fitter.GetParameter(i))
#top = TF1("top", "a+b*x+c*x**2+d*x**3+e*x**4+expo(5)", 150, 250)
a = fitter.GetParameter(0)
b = fitter.GetParameter(1)
c = fitter.GetParameter(2)
d = fitter.GetParameter(3)
e = fitter.GetParameter(4)
top = TF1("top", "[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*exp(-(x-[6])**2/(2*[7]**2))", 160,350)
top.SetParName(5,"Amp")
top.SetParName(6,"Mean")
top.SetParName(7,"Sigma")
top.SetParameter(5,1000)
top.SetParameter(6,100)
top.SetParameter(7,10)
#Force the Amplitude of the Guassian to be non-negative
top.SetParLimits(5,0,1000000000000)
top.FixParameter(0,a)
top.FixParameter(1,b)
top.FixParameter(2,c)
top.FixParameter(3,d)
top.FixParameter(4,e)
hist.Fit("top", "R")
amp = top.GetParameter(5)
ampErr = top.GetParError(5)
goodness = (amp-ampErr)/ampErr
bufferString = str(goodness)
print("Goodness = "+bufferString)
listGoodness.append(goodness)
#Advance to next hist
cutnum = cutnum + 10
bestGood = max(listGoodness)
bufferString = str(bestGood)
print("Best goodness = " +bufferString)
bufferList = ["Very Soft", "Soft", "Hard"]
for cut in bufferList:
print("Begining " +cut+" Dalitz Cut")
cutnum = 180
listGoodness = []
while cutnum <= 340:
bufferString = "Dalitz Delta " +cut+str(cutnum)
print("File being fit: "+str(bufferString))
rootdir = '/cms/data18/scherer/LumiFilteredScouting/2012B/Finished/'
fdata = TFile(rootdir+"Filtered20B.root")
#fdata.cd("genHistos/Corrected/DalitzCuts/Moderate/")
bufferString = "genHistos/Corrected/DalitzCuts/"+cut+"/"+cut"_Dalitz_Delta_"+str(cutnum)
hist = fdata.Get(bufferString)
#Fancy Background
#background = TF1("background", '[0]*((1-x/8000)**([1])/((x/8000)**([2]+[3]*log(x/8000))))')
#background.SetParName(0,"P0")
#background.SetParName(1,"P1")
#background.SetParName(3,"P3")
#background.SetParName(2,"P2")
#background.SetParameter(0,1)
#background.SetParameter(1,5)
#background.SetParameter(2,10)
#background.SetParameter(3,1)
#Test Background
background = TF1("background", "[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",160,350)
background.SetParName(0,"P0")
background.SetParName(1,"P1")
background.SetParName(2,"P2")
background.SetParameter(0,1)
background.SetParameter(1,-50)
background.SetParameter(2,-10)
#background.SetParameteres(1.,1.,1.,1.)
hist.Fit("background", "R")
fitter = TVirtualFitter.GetFitter()
for i in range(0,4):
print(fitter.GetParameter(i))
#top = TF1("top", "a+b*x+c*x**2+d*x**3+e*x**4+expo(5)", 150, 250)
a = fitter.GetParameter(0)
b = fitter.GetParameter(1)
c = fitter.GetParameter(2)
d = fitter.GetParameter(3)
e = fitter.GetParameter(4)
top = TF1("top", "[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*exp(-(x-[6])**2/(2*[7]**2))", 160,350)
top.SetParName(5,"Amp")
top.SetParName(6,"Mean")
top.SetParName(7,"Sigma")
top.SetParameter(5,1000)
top.SetParameter(6,100)
top.SetParameter(7,10)
#Force the Amplitude of the Guassian to be non-negative
top.SetParLimits(5,0,1000000000000)
top.FixParameter(0,a)
top.FixParameter(1,b)
top.FixParameter(2,c)
top.FixParameter(3,d)
top.FixParameter(4,e)
hist.Fit("top", "R")
amp = top.GetParameter(5)
ampErr = top.GetParError(5)
goodness = (amp-ampErr)/ampErr
bufferString = str(goodness)
print("Goodness = "+bufferString)
listGoodness.append(goodness)
#Advance to next hist
cutnum = cutnum + 10
bestGood = max(listGoodness)
bufferString = str(bestGood)
print("Best goodness "+cut+" = " +bufferString)