ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/mkTMDfits.py
(Generate patch)

Comparing UserCode/RateMonShiftTool_dev/mkTMDfits.py (file contents):
Revision 1.1 by grchrist, Tue Apr 3 12:38:40 2012 UTC vs.
Revision 1.6 by grchrist, Tue May 29 09:35:54 2012 UTC

# Line 4 | Line 4 | import pickle
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 "--NColBunches=<# colliding bunches>"
14 +    print "--NoVersion   Exclude version number"
15 +    print "--Lumi luminosity of estimations"
16  
17   def main():
18      print "making TMD pkl fit files"
19      
20 < ############# fIT FILE NAME ###########
21 <    
22 <    fit_file="fits_TMD.pkl"
20 >
21 >
22 > #######################################
23 >
24 >    ncolbunch=28
25 >    ntotbunch=1331
26 >    bunfrac=float(ncolbunch)/float(ntotbunch)
27  
28   #######################################
21    
29      try:
30 <        opt, args = getopt.getopt(sys.argv[1:],"",["TriggerList="])
30 >        opt, args = getopt.getopt(sys.argv[1:],"",["NColBunches=","NoVersion","Lumi=","TriggerList="])
31              
32      except getopt.GetoptError, err:
33          print str(err)
# Line 29 | Line 36 | def main():
36  
37      trig_list=[]
38      fit_list={}
39 +    NoVersion=False
40 +    lumi=5000
41 +    
42 +    for o,a in opt:
43 +        if o == "--NColBunches":
44 +            ncolbunch=int(a)
45 +            ntotbunch=1331
46 +            bunfrac=float(ncolbunch)/float(ntotbunch)
47 +        elif o == "--NoVersion":
48 +            NoVersion=True
49 +        elif o == "--Lumi":
50 +            lumi=float(a)
51 +            
52      for o,a in opt:
53          if o == "--TriggerList":
54              try:
# Line 40 | Line 60 | def main():
60                      if len(line)<3 or line=='\n':
61                          continue
62                      line = ((line.rstrip('\n')).rstrip(' '))
63 <                    if line.find(':')==-1: # exclude list, no rate estimates
63 >                    if line.find(':')==-1:
64                          list.append( line )
65 +                    
66                      else:
67                          split = line.split(':')
68                          ##trig_list.append([split[0],split[1],split[2],split[3]])
69 <                        trig_list.append(split[0])
70 <                        fit_list[split[0]]=[float(split[1]),float(split[2]),float(split[3])]
71 <                        
69 >                        if not NoVersion:
70 >                            trig_list.append(split[0])
71 >                            fit_list[split[0]]=[0.,float(split[1])/lumi,float(split[2])]
72 >                            
73 >                        else:
74 >                            trig_list.append(StripVersion(split[0]))
75 >                            fit_list[StripVersion(split[0])]=[0.,float(split[1])/lumi,float(split[2])]
76 >                            
77 >                            
78  
79                      
80                      ## if entry.find(':')!=-1:
# Line 58 | Line 85 | def main():
85              except:
86                  print "\nInvalid Trigger List\n"
87                  sys.exit(0)
88 +        elif o == "--NColBunches":
89 +            ncolbunch=int(a)
90 +            ntotbunch=1331
91 +            bunfrac=float(ncolbunch)/float(ntotbunch)
92 +        elif o == "--NoVersion":
93 +            NoVersion=True
94 +        elif o == "--Lumi":
95 +            lumi=float(a)
96          else:
97              print "\nInvalid Option %s\n" % (str(o),)
98              usage()
# Line 67 | Line 102 | def main():
102  
103      OutputFit={}
104      for keys in fit_list.iterkeys():
70        
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 <        fit_list_fortrig.append(0.0)#cubic term
109 <        fit_list_fortrig.append(10.0)#chisq/ndf
110 <        fit_list_fortrig.append(0.0)#meanrawrate
111 <        fit_list_fortrig.append(0.0)#0.err
108 >        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          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 <        ##print "trig=",keys, "fit pars=",fit_list_fortrig
118 >        print "trig=",keys, "fit pars=",fit_list_fortrig
119 >
120 >    ############# fIT FILE NAME ###########
121 >    lumiint=int(lumi)
122 >    if not NoVersion:
123 >        fit_file="fits_TMD_ncolbunch%s_lumi%s.pkl"
124 >    else:
125 >        fit_file="fits_TMD_ncolbunch%s_noV_lumi%s.pkl"
126 >    fit_file = fit_file % (ncolbunch,lumiint)
127      
128      if os.path.exists(fit_file):
129              os.remove(fit_file)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines