forked from cms-tsg-fog/RateMon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkTMDfits.py
executable file
·138 lines (110 loc) · 4.42 KB
/
mkTMDfits.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
136
137
138
#!/usr/bin/env python
import pickle
import getopt
import sys
import os
from DatabaseParser import StripVersion
def usage():
print sys.argv[0]+" [options]"
print "This script makes a pkl file from TMD rate predictions\nto be used in the RatePredictor script for new menu deployment"
print "--TriggerList=<path>"
print "--NColBunches=<# colliding bunches>"
print "--NoVersion Exclude version number"
print "--Lumi luminosity of estimations"
def main():
print "making TMD pkl fit files"
#######################################
ncolbunch=28
ntotbunch=1331
bunfrac=float(ncolbunch)/float(ntotbunch)
#######################################
try:
opt, args = getopt.getopt(sys.argv[1:],"",["NColBunches=","NoVersion","Lumi=","TriggerList="])
except getopt.GetoptError, err:
print str(err)
usage()
sys.exit(2)
trig_list=[]
fit_list={}
NoVersion=False
lumi=5000
for o,a in opt:
if o == "--NColBunches":
ncolbunch=int(a)
ntotbunch=1331
bunfrac=float(ncolbunch)/float(ntotbunch)
elif o == "--NoVersion":
NoVersion=True
elif o == "--Lumi":
lumi=float(a)
for o,a in opt:
if o == "--TriggerList":
try:
f = open(a)
for line in f:
if line.startswith('#'):
continue
if len(line)<3 or line=='\n':
continue
line = ((line.rstrip('\n')).rstrip(' '))
if line.find(':')==-1:
list.append( line )
else:
split = line.split(':')
##trig_list.append([split[0],split[1],split[2],split[3]])
if not NoVersion:
trig_list.append(split[0])
fit_list[split[0]]=[0.,float(split[1])/lumi,float(split[2])]
else:
trig_list.append(StripVersion(split[0]))
fit_list[StripVersion(split[0])]=[0.,float(split[1])/lumi,float(split[2])]
## if entry.find(':')!=-1:
## entry = entry[:entry.find(':')] ## We can point this to the existing monitor list, just remove everything after ':'!
## if entry.find('#')!=-1:
## entry = entry[:entry.find('#')] ## We can point this to the existing monitor list, just remove everything after ':'!
## trig_list.append( entry.rstrip('\n'))
except:
print "\nInvalid Trigger List\n"
sys.exit(0)
elif o == "--NColBunches":
ncolbunch=int(a)
ntotbunch=1331
bunfrac=float(ncolbunch)/float(ntotbunch)
elif o == "--NoVersion":
NoVersion=True
elif o == "--Lumi":
lumi=float(a)
else:
print "\nInvalid Option %s\n" % (str(o),)
usage()
sys.exit(2)
OutputFit={}
for keys in fit_list.iterkeys():
##change format to that produced in rate predictor
fit_list_fortrig=fit_list[keys]
fit_list_fortrig.insert(0,"poly")#fit name
fit_list_fortrig.insert(3,0.0)
fit_list_fortrig.insert(4,0.0)#cubic term
fit_list_fortrig.insert(5,10.0)#chisq/ndf
fit_list_fortrig.insert(6,0.0)#meanrawrate
#fit_list_fortrig.append(0.0)#0.err
fit_list_fortrig.append(0.0)#1.err
fit_list_fortrig.append(0.0)#2.err
fit_list_fortrig.append(0.0)#3.err
OutputFit[keys]=fit_list_fortrig
print "trig=",keys, "fit pars=",fit_list_fortrig
############# fIT FILE NAME ###########
lumiint=int(lumi)
if not NoVersion:
fit_file="fits_TMD_ncolbunch%s_lumi%s.pkl"
else:
fit_file="fits_TMD_ncolbunch%s_noV_lumi%s.pkl"
fit_file = fit_file % (ncolbunch,lumiint)
if os.path.exists(fit_file):
os.remove(fit_file)
FitOutputFile = open(fit_file, 'wb')
pickle.dump(OutputFit, FitOutputFile, 2)
FitOutputFile.close()
print "Output fit file is "+str(fit_file)
if __name__=='__main__':
main()