ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/mkTMDfits.py
Revision: 1.2
Committed: Tue Apr 10 10:02:32 2012 UTC (13 years ago) by grchrist
Content type: text/x-python
Branch: MAIN
Changes since 1.1: +16 -5 lines
Log Message:
updates to TMD  for certificatinon

File Contents

# User Rev Content
1 grchrist 1.1 #!/usr/bin/env python
2    
3     import pickle
4     import getopt
5     import sys
6     import os
7    
8     def usage():
9     print sys.argv[0]+" [options]"
10     print "This script makes a pkl file from TMD rate predictions\nto be used in the RatePredictor script for new menu deployment"
11     print "--TriggerList=<path>"
12 grchrist 1.2 print "--NColBunch=<# colliding bunches>"
13 grchrist 1.1
14     def main():
15     print "making TMD pkl fit files"
16    
17     ############# fIT FILE NAME ###########
18    
19     fit_file="fits_TMD.pkl"
20    
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.2 opt, args = getopt.getopt(sys.argv[1:],"",["NColBunch=","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     for o,a in opt:
39 grchrist 1.2 if o == "--NColBunch":
40     ncolbunch=int(a)
41     ntotbunch=1331
42     bunfrac=float(ncolbunch)/float(ntotbunch)
43     elif o == "--TriggerList":
44 grchrist 1.1 try:
45     f = open(a)
46     for line in f:
47     if line.startswith('#'):
48     continue
49    
50     if len(line)<3 or line=='\n':
51     continue
52     line = ((line.rstrip('\n')).rstrip(' '))
53 grchrist 1.2 if line.find(':')==-1:
54 grchrist 1.1 list.append( line )
55 grchrist 1.2
56 grchrist 1.1 else:
57     split = line.split(':')
58     ##trig_list.append([split[0],split[1],split[2],split[3]])
59     trig_list.append(split[0])
60 grchrist 1.2 fit_list[split[0]]=[float(split[1])*bunfrac,float(split[2])*bunfrac,float(split[3])*bunfrac]
61 grchrist 1.1
62    
63    
64     ## if entry.find(':')!=-1:
65     ## entry = entry[:entry.find(':')] ## We can point this to the existing monitor list, just remove everything after ':'!
66     ## if entry.find('#')!=-1:
67     ## entry = entry[:entry.find('#')] ## We can point this to the existing monitor list, just remove everything after ':'!
68     ## trig_list.append( entry.rstrip('\n'))
69     except:
70     print "\nInvalid Trigger List\n"
71     sys.exit(0)
72     else:
73     print "\nInvalid Option %s\n" % (str(o),)
74     usage()
75     sys.exit(2)
76    
77    
78    
79     OutputFit={}
80     for keys in fit_list.iterkeys():
81    
82     ##change format to that produced in rate predictor
83     fit_list_fortrig=fit_list[keys]
84     fit_list_fortrig.insert(0,"poly")#fit name
85     fit_list_fortrig.append(0.0)#cubic term
86     fit_list_fortrig.append(10.0)#chisq/ndf
87     fit_list_fortrig.append(0.0)#meanrawrate
88     fit_list_fortrig.append(0.0)#0.err
89     fit_list_fortrig.append(0.0)#1.err
90     fit_list_fortrig.append(0.0)#2.err
91     fit_list_fortrig.append(0.0)#3.err
92    
93     OutputFit[keys]=fit_list_fortrig
94     ##print "trig=",keys, "fit pars=",fit_list_fortrig
95    
96     if os.path.exists(fit_file):
97     os.remove(fit_file)
98     FitOutputFile = open(fit_file, 'wb')
99     pickle.dump(OutputFit, FitOutputFile, 2)
100     FitOutputFile.close()
101     print "Output fit file is "+str(fit_file)
102    
103    
104    
105     if __name__=='__main__':
106     main()