4 |
|
import getopt |
5 |
|
import sys |
6 |
|
import os |
7 |
+ |
from DatabaseParser import StripVersion |
8 |
|
|
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 |
< |
print "--NColBunch=<# colliding bunches>" |
13 |
> |
print "--NColBunches=<# colliding bunches>" |
14 |
> |
print "--NoVersion Exclude version number" |
15 |
|
|
16 |
|
def main(): |
17 |
|
print "making TMD pkl fit files" |
18 |
|
|
19 |
< |
############# fIT FILE NAME ########### |
18 |
< |
|
19 |
< |
fit_file="fits_TMD_ncolbunch%s.pkl" |
19 |
> |
|
20 |
|
|
21 |
|
####################################### |
22 |
|
|
26 |
|
|
27 |
|
####################################### |
28 |
|
try: |
29 |
< |
opt, args = getopt.getopt(sys.argv[1:],"",["NColBunch=","TriggerList="]) |
29 |
> |
opt, args = getopt.getopt(sys.argv[1:],"",["NColBunches=","NoVersion","TriggerList="]) |
30 |
|
|
31 |
|
except getopt.GetoptError, err: |
32 |
|
print str(err) |
35 |
|
|
36 |
|
trig_list=[] |
37 |
|
fit_list={} |
38 |
+ |
NoVersion=False |
39 |
+ |
|
40 |
|
for o,a in opt: |
41 |
< |
if o == "--NColBunch": |
41 |
> |
if o == "--NColBunches": |
42 |
|
ncolbunch=int(a) |
43 |
|
ntotbunch=1331 |
44 |
|
bunfrac=float(ncolbunch)/float(ntotbunch) |
45 |
< |
elif o == "--TriggerList": |
45 |
> |
elif o == "--NoVersion": |
46 |
> |
NoVersion=True |
47 |
> |
for o,a in opt: |
48 |
> |
if o == "--TriggerList": |
49 |
|
try: |
50 |
|
f = open(a) |
51 |
|
for line in f: |
61 |
|
else: |
62 |
|
split = line.split(':') |
63 |
|
##trig_list.append([split[0],split[1],split[2],split[3]]) |
64 |
< |
trig_list.append(split[0]) |
65 |
< |
fit_list[split[0]]=[float(split[1])*bunfrac,float(split[2])*bunfrac,float(split[3])*bunfrac] |
66 |
< |
|
64 |
> |
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 |
|
|
74 |
|
|
75 |
|
## if entry.find(':')!=-1: |
80 |
|
except: |
81 |
|
print "\nInvalid Trigger List\n" |
82 |
|
sys.exit(0) |
83 |
+ |
elif o == "--NColBunches": |
84 |
+ |
ncolbunch=int(a) |
85 |
+ |
ntotbunch=1331 |
86 |
+ |
bunfrac=float(ncolbunch)/float(ntotbunch) |
87 |
+ |
elif o == "--NoVersion": |
88 |
+ |
NoVersion=True |
89 |
|
else: |
90 |
|
print "\nInvalid Option %s\n" % (str(o),) |
91 |
|
usage() |
95 |
|
|
96 |
|
OutputFit={} |
97 |
|
for keys in fit_list.iterkeys(): |
81 |
– |
|
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 |
< |
fit_list_fortrig.append(0.0)#cubic term |
102 |
< |
fit_list_fortrig.append(10.0)#chisq/ndf |
103 |
< |
fit_list_fortrig.append(0.0)#meanrawrate |
104 |
< |
fit_list_fortrig.append(0.0)#0.err |
101 |
> |
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 |
|
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 |
< |
##print "trig=",keys, "fit pars=",fit_list_fortrig |
111 |
> |
print "trig=",keys, "fit pars=",fit_list_fortrig |
112 |
> |
|
113 |
> |
############# fIT FILE NAME ########### |
114 |
|
|
115 |
+ |
if not NoVersion: |
116 |
+ |
fit_file="fits_TMD_ncolbunch%s.pkl" |
117 |
+ |
else: |
118 |
+ |
fit_file="fits_TMD_ncolbunch%s_noV.pkl" |
119 |
|
fit_file = fit_file % (ncolbunch) |
120 |
|
|
121 |
|
if os.path.exists(fit_file): |