ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/mkTMDfits.py
Revision: 1.6
Committed: Tue May 29 09:35:54 2012 UTC (12 years, 11 months ago) by grchrist
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-02-06, V00-02-05, V00-02-04, V00-02-03, V00-02-01, V00-01-10, V-00-01-10, V00-01-09, V00-01-08, V00-01-07, V00-01-06, V00-01-05, V00-01-04, V00-01-03, V00-01-02, V00-01-01, V00-00-34, V00-00-33, MenuAnalyzer_V00-00-02, MenuAnalyzer_V00-00-01, MenuAnalyzer_V1, HEAD
Changes since 1.5: +2 -2 lines
Log Message:
latest predictions and new forbidden columns

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