ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/mkTMDfits.py
Revision: 1.1
Committed: Tue Apr 3 12:38:40 2012 UTC (13 years ago) by grchrist
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-00-26
Log Message:
mkTMD_predictions takes tmd predictions and makes pickle files

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    
13     def main():
14     print "making TMD pkl fit files"
15    
16     ############# fIT FILE NAME ###########
17    
18     fit_file="fits_TMD.pkl"
19    
20     #######################################
21    
22     try:
23     opt, args = getopt.getopt(sys.argv[1:],"",["TriggerList="])
24    
25     except getopt.GetoptError, err:
26     print str(err)
27     usage()
28     sys.exit(2)
29    
30     trig_list=[]
31     fit_list={}
32     for o,a in opt:
33     if o == "--TriggerList":
34     try:
35     f = open(a)
36     for line in f:
37     if line.startswith('#'):
38     continue
39    
40     if len(line)<3 or line=='\n':
41     continue
42     line = ((line.rstrip('\n')).rstrip(' '))
43     if line.find(':')==-1: # exclude list, no rate estimates
44     list.append( line )
45     else:
46     split = line.split(':')
47     ##trig_list.append([split[0],split[1],split[2],split[3]])
48     trig_list.append(split[0])
49     fit_list[split[0]]=[float(split[1]),float(split[2]),float(split[3])]
50    
51    
52    
53     ## if entry.find(':')!=-1:
54     ## entry = entry[:entry.find(':')] ## We can point this to the existing monitor list, just remove everything after ':'!
55     ## if entry.find('#')!=-1:
56     ## entry = entry[:entry.find('#')] ## We can point this to the existing monitor list, just remove everything after ':'!
57     ## trig_list.append( entry.rstrip('\n'))
58     except:
59     print "\nInvalid Trigger List\n"
60     sys.exit(0)
61     else:
62     print "\nInvalid Option %s\n" % (str(o),)
63     usage()
64     sys.exit(2)
65    
66    
67    
68     OutputFit={}
69     for keys in fit_list.iterkeys():
70    
71     ##change format to that produced in rate predictor
72     fit_list_fortrig=fit_list[keys]
73     fit_list_fortrig.insert(0,"poly")#fit name
74     fit_list_fortrig.append(0.0)#cubic term
75     fit_list_fortrig.append(10.0)#chisq/ndf
76     fit_list_fortrig.append(0.0)#meanrawrate
77     fit_list_fortrig.append(0.0)#0.err
78     fit_list_fortrig.append(0.0)#1.err
79     fit_list_fortrig.append(0.0)#2.err
80     fit_list_fortrig.append(0.0)#3.err
81    
82     OutputFit[keys]=fit_list_fortrig
83     ##print "trig=",keys, "fit pars=",fit_list_fortrig
84    
85     if os.path.exists(fit_file):
86     os.remove(fit_file)
87     FitOutputFile = open(fit_file, 'wb')
88     pickle.dump(OutputFit, FitOutputFile, 2)
89     FitOutputFile.close()
90     print "Output fit file is "+str(fit_file)
91    
92    
93    
94     if __name__=='__main__':
95     main()