-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackupRootFitter.py
More file actions
85 lines (69 loc) · 2.76 KB
/
BackupRootFitter.py
File metadata and controls
85 lines (69 loc) · 2.76 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
import ROOT
from ROOT import *
cutnum = 180
listGoodness = []
while cutnum <= 340:
bufferString = "Dalitz Delta Medium "+str(cutnum)
print("File being fit: "+str(bufferString))
rootdir = '/cms/data18/scherer/LumiFilteredScouting/2012D/Finished/'
fdata = TFile(rootdir+"Filtered2D.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)
#to define your own function
#expofitlin =TF1("expofitlin","expo(0) + pol1(2)")