1 |
grchrist |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
|
3 |
|
|
import pickle
|
4 |
|
|
import getopt
|
5 |
|
|
import sys
|
6 |
|
|
import os
|
7 |
grchrist |
1.4 |
from DatabaseParser import StripVersion
|
8 |
grchrist |
1.1 |
|
9 |
|
|
def usage():
|
10 |
|
|
print sys.argv[0]+" [options]"
|
11 |
|
|
print "This script makes a pkl file from TMD rate predictions\nto be used in the RatePredictor script for new menu deployment"
|
12 |
|
|
print "--TriggerList=<path>"
|
13 |
grchrist |
1.4 |
print "--NColBunches=<# colliding bunches>"
|
14 |
|
|
print "--NoVersion Exclude version number"
|
15 |
grchrist |
1.1 |
|
16 |
|
|
def main():
|
17 |
|
|
print "making TMD pkl fit files"
|
18 |
|
|
|
19 |
grchrist |
1.4 |
|
20 |
grchrist |
1.1 |
|
21 |
|
|
#######################################
|
22 |
grchrist |
1.2 |
|
23 |
|
|
ncolbunch=28
|
24 |
|
|
ntotbunch=1331
|
25 |
|
|
bunfrac=float(ncolbunch)/float(ntotbunch)
|
26 |
|
|
|
27 |
|
|
#######################################
|
28 |
grchrist |
1.1 |
try:
|
29 |
grchrist |
1.4 |
opt, args = getopt.getopt(sys.argv[1:],"",["NColBunches=","NoVersion","TriggerList="])
|
30 |
grchrist |
1.1 |
|
31 |
|
|
except getopt.GetoptError, err:
|
32 |
|
|
print str(err)
|
33 |
|
|
usage()
|
34 |
|
|
sys.exit(2)
|
35 |
|
|
|
36 |
|
|
trig_list=[]
|
37 |
|
|
fit_list={}
|
38 |
grchrist |
1.4 |
NoVersion=False
|
39 |
|
|
|
40 |
grchrist |
1.1 |
for o,a in opt:
|
41 |
grchrist |
1.4 |
if o == "--NColBunches":
|
42 |
grchrist |
1.2 |
ncolbunch=int(a)
|
43 |
|
|
ntotbunch=1331
|
44 |
|
|
bunfrac=float(ncolbunch)/float(ntotbunch)
|
45 |
grchrist |
1.4 |
elif o == "--NoVersion":
|
46 |
|
|
NoVersion=True
|
47 |
|
|
for o,a in opt:
|
48 |
|
|
if o == "--TriggerList":
|
49 |
grchrist |
1.1 |
try:
|
50 |
|
|
f = open(a)
|
51 |
|
|
for line in f:
|
52 |
|
|
if line.startswith('#'):
|
53 |
|
|
continue
|
54 |
|
|
|
55 |
|
|
if len(line)<3 or line=='\n':
|
56 |
|
|
continue
|
57 |
|
|
line = ((line.rstrip('\n')).rstrip(' '))
|
58 |
grchrist |
1.2 |
if line.find(':')==-1:
|
59 |
grchrist |
1.1 |
list.append( line )
|
60 |
grchrist |
1.2 |
|
61 |
grchrist |
1.1 |
else:
|
62 |
|
|
split = line.split(':')
|
63 |
|
|
##trig_list.append([split[0],split[1],split[2],split[3]])
|
64 |
grchrist |
1.4 |
if not NoVersion:
|
65 |
|
|
trig_list.append(split[0])
|
66 |
|
|
fit_list[split[0]]=[0.,float(split[1])/5000.,float(split[2])]
|
67 |
|
|
|
68 |
|
|
else:
|
69 |
|
|
trig_list.append(StripVersion(split[0]))
|
70 |
|
|
fit_list[StripVersion(split[0])]=[0.,float(split[1])/5000.,float(split[2])]
|
71 |
|
|
|
72 |
|
|
|
73 |
grchrist |
1.1 |
|
74 |
|
|
|
75 |
|
|
## if entry.find(':')!=-1:
|
76 |
|
|
## entry = entry[:entry.find(':')] ## We can point this to the existing monitor list, just remove everything after ':'!
|
77 |
|
|
## if entry.find('#')!=-1:
|
78 |
|
|
## entry = entry[:entry.find('#')] ## We can point this to the existing monitor list, just remove everything after ':'!
|
79 |
|
|
## trig_list.append( entry.rstrip('\n'))
|
80 |
|
|
except:
|
81 |
|
|
print "\nInvalid Trigger List\n"
|
82 |
|
|
sys.exit(0)
|
83 |
grchrist |
1.4 |
elif o == "--NColBunches":
|
84 |
|
|
ncolbunch=int(a)
|
85 |
|
|
ntotbunch=1331
|
86 |
|
|
bunfrac=float(ncolbunch)/float(ntotbunch)
|
87 |
|
|
elif o == "--NoVersion":
|
88 |
|
|
NoVersion=True
|
89 |
grchrist |
1.1 |
else:
|
90 |
|
|
print "\nInvalid Option %s\n" % (str(o),)
|
91 |
|
|
usage()
|
92 |
|
|
sys.exit(2)
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
OutputFit={}
|
97 |
|
|
for keys in fit_list.iterkeys():
|
98 |
|
|
##change format to that produced in rate predictor
|
99 |
|
|
fit_list_fortrig=fit_list[keys]
|
100 |
|
|
fit_list_fortrig.insert(0,"poly")#fit name
|
101 |
grchrist |
1.4 |
fit_list_fortrig.insert(3,0.0)
|
102 |
|
|
fit_list_fortrig.insert(4,0.0)#cubic term
|
103 |
|
|
fit_list_fortrig.insert(5,10.0)#chisq/ndf
|
104 |
|
|
fit_list_fortrig.insert(6,0.0)#meanrawrate
|
105 |
|
|
#fit_list_fortrig.append(0.0)#0.err
|
106 |
grchrist |
1.1 |
fit_list_fortrig.append(0.0)#1.err
|
107 |
|
|
fit_list_fortrig.append(0.0)#2.err
|
108 |
|
|
fit_list_fortrig.append(0.0)#3.err
|
109 |
|
|
|
110 |
|
|
OutputFit[keys]=fit_list_fortrig
|
111 |
grchrist |
1.4 |
print "trig=",keys, "fit pars=",fit_list_fortrig
|
112 |
|
|
|
113 |
|
|
############# fIT FILE NAME ###########
|
114 |
grchrist |
1.3 |
|
115 |
grchrist |
1.4 |
if not NoVersion:
|
116 |
|
|
fit_file="fits_TMD_ncolbunch%s.pkl"
|
117 |
|
|
else:
|
118 |
|
|
fit_file="fits_TMD_ncolbunch%s_noV.pkl"
|
119 |
grchrist |
1.3 |
fit_file = fit_file % (ncolbunch)
|
120 |
grchrist |
1.1 |
|
121 |
|
|
if os.path.exists(fit_file):
|
122 |
|
|
os.remove(fit_file)
|
123 |
|
|
FitOutputFile = open(fit_file, 'wb')
|
124 |
|
|
pickle.dump(OutputFit, FitOutputFile, 2)
|
125 |
|
|
FitOutputFile.close()
|
126 |
|
|
print "Output fit file is "+str(fit_file)
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
if __name__=='__main__':
|
131 |
|
|
main()
|