ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/DatabaseRatePredictor.py
Revision: 1.56
Committed: Mon Aug 27 13:40:24 2012 UTC (12 years, 8 months ago) by awoodard
Content type: text/x-python
Branch: MAIN
Changes since 1.55: +6 -5 lines
Log Message:
Fixing divide by zero error on line 580.

File Contents

# User Rev Content
1 grchrist 1.3 #!/usr/bin/env python
2    
3 abrinke1 1.1 from DatabaseParser import *
4 abrinke1 1.5 from GetListOfRuns import *
5 abrinke1 1.1 import sys
6     import os
7     from numpy import *
8     import pickle
9 amott 1.18 import getopt
10 awoodard 1.47 from StreamMonitor import StreamMonitor
11 grchrist 1.29
12 abrinke1 1.1 from ROOT import gROOT, TCanvas, TF1, TGraph, TGraphErrors, TPaveStats, gPad, gStyle
13 amott 1.18 from ROOT import TFile, TPaveText, TBrowser
14 abrinke1 1.1 from ROOT import gBenchmark
15     import array
16     import math
17 grchrist 1.8 from ReadConfig import RateMonConfig
18 muell149 1.46 from TablePrint import *
19 abrinke1 1.5 from selectionParser import selectionParser
20    
21 amott 1.18 def usage():
22     print sys.argv[0]+" [options] <list of runs>"
23     print "This script is used to generate fits and do secondary shifter validation"
24     print "<list of runs> this is a list of the form: a b c-d e f-g, specifying individual runs and/or run ranges"
25     print " be careful with using ranges (c-d), it is highly recommended to use a JSON in this case"
26     print "options: "
27     print "--makeFits run in fit making mode"
28     print "--secondary run in secondary shifter mode"
29 grchrist 1.28 print "--TMD put in TMD predictions"
30 amott 1.18 print "--fitFile=<path> path to the fit file"
31     print "--json=<path> path to the JSON file"
32     print "--TriggerList=<path> path to the trigger list (without versions!)"
33 grchrist 1.26 print "--maxdt=<max deadtime> Mask LS above max deadtime threshold"
34     print "--All Mask LS with any red LS on WBM LS page (not inc castor zdc etc)"
35     print "--Mu Mask LS with Mu off"
36     print "--HCal Mask LS with HCal barrel off"
37     print "--Tracker Mask LS with Tracker barrel off"
38     print "--ECal Mask LS with ECal barrel off"
39     print "--EndCap Mask LS with EndCap sys off, used in combination with other subsys"
40     print "--Beam Mask LS with Beam off"
41 grchrist 1.34 print "--NoVersion Ignore version numbers"
42 grchrist 1.35 print "--linear Force Linear fits"
43 grchrist 1.38 print "--inst Fits using inst not delivered"
44     print "--TMDerr Use errors from TMD predictions"
45 muell149 1.46 print "--write Writes fit info into csv, for ranking nonlinear triggers"
46 awoodard 1.50 print "--AllTriggers Run for all triggers instead of specifying a trigger list"
47 muell149 1.46
48 amott 1.18 class Modes:
49 grchrist 1.29 none,fits,secondary = range(3)
50    
51     def pickYear():
52     global thisyear
53 grchrist 1.32 thisyear="2012"
54 grchrist 1.29 print "Year set to ",thisyear
55    
56 amott 1.18
57 abrinke1 1.1 def main():
58 amott 1.18 try:
59 grchrist 1.29
60 grchrist 1.32 ##set year to 2012
61 grchrist 1.29 pickYear()
62 awoodard 1.47
63 grchrist 1.22 try:
64 awoodard 1.50 opt, args = getopt.getopt(sys.argv[1:],"",["makeFits","secondary","fitFile=","json=","TriggerList=","maxdt=","All","Mu","HCal","Tracker","ECal","EndCap","Beam","NoVersion","linear","inst","TMDerr","write","AllTriggers"])
65 grchrist 1.22
66     except getopt.GetoptError, err:
67     print str(err)
68     usage()
69     sys.exit(2)
70    
71 grchrist 1.21 ## if len(args)<1:
72     ## print "\nPlease specify at least 1 run to look at\n"
73     ## usage()
74     ## sys.exit(0)
75 amott 1.18
76 grchrist 1.25
77     ##### RUN LIST ########
78 grchrist 1.22 run_list=[]
79 grchrist 1.23
80 grchrist 1.22 if len(args)<1:
81     inputrunlist=[]
82     print "No runs specified"
83     runinput=raw_input("Enter run range in form <run1> <run2> <run3> or <run1>-<run2>:")
84     inputrunlist.append(runinput)
85    
86    
87     if runinput.find(' ')!=-1:
88     args=runinput.split(' ')
89     else:
90     args.append(runinput)
91    
92 grchrist 1.23
93    
94 grchrist 1.22 for r in args:
95     if r.find('-')!=-1: # r is a run range
96     rrange = r.split('-')
97     if len(rrange)!=2:
98     print "Invalid run range %s" % (r,)
99     sys.exit(0)
100     try:
101     for rr in range(int(rrange[0]),int(rrange[1])+1):
102     run_list.append(rr)
103     except:
104     print "Invalid run range %s" % (r,)
105     sys.exit(0)
106     else: # r is not a run range
107     try:
108     run_list.append(int(r))
109     except:
110     print "Invalid run %s" % (r,)
111 grchrist 1.26
112 grchrist 1.21
113 grchrist 1.25 ##### READ CMD LINE ARGS #########
114 grchrist 1.22 mode = Modes.none
115     fitFile = ""
116     jsonfile = ""
117     trig_list = []
118 grchrist 1.25 max_dt=-1.0
119     subsys=-1.0
120 grchrist 1.34 NoVersion=False
121 grchrist 1.35 linear=False
122 grchrist 1.38 do_inst=False
123     TMDerr=False
124 muell149 1.46 wp_bool=False
125 awoodard 1.50 all_triggers=False
126 grchrist 1.25 SubSystemOff={'All':False,'Mu':False,'HCal':False,'ECal':False,'Tracker':False,'EndCap':False,'Beam':False}
127 grchrist 1.22 for o,a in opt:
128     if o == "--makeFits":
129     mode = Modes.fits
130     elif o == "--secondary":
131     mode = Modes.secondary
132     elif o == "--fitFile":
133     fitFile = str(a)
134     elif o == "--json":
135     jsonfile = a
136 grchrist 1.26 elif o=="--maxdt":
137     max_dt = float(a)
138 grchrist 1.25 elif o=="--All":
139     subsys=1
140     SubSystemOff["All"]=True
141     elif o=="--Mu":
142     subsys=1
143     SubSystemOff["Mu"]=True
144     elif o=="--HCal":
145     SubSystemOff["HCal"]=True
146     subsys=1
147     elif o=="--Tracker":
148     SubSystemOff["Tracker"]=True
149     subsys=1
150 grchrist 1.26 elif o=="--ECal":
151     SubSystemOff["ECal"]=True
152     subsys=1
153 grchrist 1.25 elif o=="--EndCap":
154     SubSystemOff["EndCap"]=True
155     subsys=1
156     elif o=="--Beam":
157     SubSystemOff["Beam"]=True
158     subsys=1
159 grchrist 1.34 elif o=="--NoVersion":
160     NoVersion=True
161 grchrist 1.35 elif o=="--linear":
162     linear=True
163 grchrist 1.38 elif o=="--inst":
164     do_inst=True
165     elif o=="--TMDerr":
166     TMDerr=True
167 muell149 1.46 elif o=="--write":
168     wp_bool=True
169 awoodard 1.50 elif o=="--AllTriggers":
170     all_triggers=True
171 grchrist 1.22 elif o == "--TriggerList":
172     try:
173     f = open(a)
174     for entry in f:
175     if entry.startswith('#'):
176     continue
177     if entry.find(':')!=-1:
178     entry = entry[:entry.find(':')] ## We can point this to the existing monitor list, just remove everything after ':'!
179     if entry.find('#')!=-1:
180     entry = entry[:entry.find('#')] ## We can point this to the existing monitor list, just remove everything after ':'!
181     trig_list.append( entry.rstrip('\n'))
182     except:
183     print "\nInvalid Trigger List\n"
184     sys.exit(0)
185     else:
186     print "\nInvalid Option %s\n" % (str(o),)
187     usage()
188     sys.exit(2)
189    
190     print "\n\n"
191 grchrist 1.25 ###### MODES #########
192    
193 grchrist 1.22 if mode == Modes.none: ## no mode specified
194     print "\nNo operation mode specified!\n"
195     modeinput=raw_input("Enter mode, --makeFits or --secondary:")
196     print "modeinput=",modeinput
197     if not (modeinput=="--makeFits" or modeinput=="--secondary"):
198     print "not either"
199     usage()
200 amott 1.18 sys.exit(0)
201 grchrist 1.22 elif modeinput == "--makeFits":
202     mode=Modes.fits
203     elif modeinput =="--secondary":
204     mode=Modes.secondary
205     else:
206     print "FATAL ERROR: No Mode specified"
207 amott 1.18 sys.exit(0)
208 grchrist 1.22
209     if mode == Modes.fits:
210     print "Running in Fit Making mode\n\n"
211     elif mode == Modes.secondary:
212     print "Running in Secondary Shifter mode\n\n"
213     else: ## should never get here, but exit if we do
214 grchrist 1.21 print "FATAL ERROR: No Mode specified"
215     sys.exit(0)
216 grchrist 1.22
217     if fitFile=="" and not mode==Modes.fits:
218     print "\nPlease specify fit file. These are available:\n"
219 grchrist 1.29 path="Fits/%s/" % (thisyear) # insert the path to the directory of interest
220 grchrist 1.22 dirList=os.listdir(path)
221     for fname in dirList:
222     print fname
223 grchrist 1.24 fitFile = path+raw_input("Enter fit file in format Fit_HLT_10LS_Run176023to180252.pkl: ")
224    
225 grchrist 1.21 ##usage()
226     ##sys.exit(0)
227 grchrist 1.22 elif fitFile=="":
228 grchrist 1.39 NoVstr=""
229     if NoVersion:
230     NoVstr="NoV_"
231 grchrist 1.38 if not do_inst:
232 grchrist 1.39 fitFile="Fits/%s/Fit_HLT_%s10LS_Run%sto%s.pkl" % (thisyear,NoVstr,min(run_list),max(run_list))
233 grchrist 1.38 else:
234 grchrist 1.39 fitFile="Fits/%s/Fit_inst_HLT_%s10LS_Run%sto%s.pkl" % (thisyear,NoVstr,min(run_list),max(run_list))
235 grchrist 1.26
236 grchrist 1.39 if "NoV" in fitFile:
237     NoVersion=True
238    
239 grchrist 1.25
240     ###### TRIGGER LIST #######
241 grchrist 1.24
242 awoodard 1.50 if trig_list == [] and not all_triggers:
243 grchrist 1.22
244     print "\nPlease specify list of triggers\n"
245     print "Available lists are:"
246     dirList=os.listdir(".")
247     for fname in dirList:
248     entry=fname
249     if entry.find('.')!=-1:
250     extension = entry[entry.find('.'):] ## We can point this to the existing monitor list, just remove everything after ':'!
251     if extension==".list":
252     print fname
253 grchrist 1.26 trig_input=raw_input("\nEnter triggers in format HLT_IsoMu30_eta2p1 or a .list file: ")
254 grchrist 1.21
255 grchrist 1.22 if trig_input.find('.')!=-1:
256     extension = trig_input[trig_input.find('.'):]
257 grchrist 1.21 if extension==".list":
258 grchrist 1.22 try:
259     fl=open(trig_input)
260     except:
261     print "Cannot open file"
262     usage()
263     sys.exit(0)
264 grchrist 1.21
265 grchrist 1.22 for line in fl:
266     if line.startswith('#'):
267     continue
268     if len(line)<1:
269     continue
270 grchrist 1.21
271 grchrist 1.22 if len(line)>=2:
272     arg=line.rstrip('\n').rstrip(' ').lstrip(' ')
273     trig_list.append(arg)
274     else:
275     arg=''
276     else:
277     trig_list.append(trig_input)
278 grchrist 1.21
279 abrinke1 1.5 ## Can use any combination of LowestRunNumber, HighestRunNumber, and NumberOfRuns -
280     ## just modify "ExistingRuns.sort" and for "run in ExistingRuns" accordingly
281    
282 grchrist 1.22 if jsonfile=="":
283     JSON=[]
284     else:
285     print "Using JSON: %s" % (jsonfile,)
286     JSON = GetJSON(jsonfile) ##Returns array JSON[runs][ls_list]
287 abrinke1 1.5
288 grchrist 1.21
289 abrinke1 1.5
290 grchrist 1.22 ###### TO CREATE FITS #########
291     if mode == Modes.fits:
292     trig_name = "HLT"
293 grchrist 1.34 num_ls = 10
294 grchrist 1.22 physics_active_psi = True ##Requires that physics and active be on, and that the prescale column is not 0
295     #JSON = [] ##To not use a JSON file, just leave the array empty
296     debug_print = False
297     no_versions=False
298 grchrist 1.34 min_rate = 0.0
299 grchrist 1.22 print_table = False
300     data_clean = True ##Gets rid of anomalous rate points, reqires physics_active_psi (PAP) and deadtime < 20%
301     ##plot_properties = [varX, varY, do_fit, save_root, save_png, fit_file]
302 grchrist 1.38 if not do_inst:
303     plot_properties = [["delivered", "rate", True, True, False, fitFile]]
304 awoodard 1.54 # plot_properties = [["delivered", "rawrate", True, True, False, fitFile]]
305 grchrist 1.38 else:
306     plot_properties = [["inst", "rate", True, True, False, fitFile]]
307 amott 1.18
308 grchrist 1.34 masked_triggers = ["AlCa_", "DST_", "HLT_L1", "HLT_Zero"]
309 grchrist 1.22 save_fits = True
310 grchrist 1.25 if max_dt==-1.0:
311     max_dt=0.08 ## no deadtime cutuse 2.0
312 grchrist 1.22 force_new=True
313     print_info=True
314 grchrist 1.25 if subsys==-1.0:
315     SubSystemOff={'All':False,'Mu':False,'HCal':False,'ECal':False,'Tracker':False,'EndCap':False,'Beam':True}
316 grchrist 1.22
317    
318     ###### TO SEE RATE VS PREDICTION ########
319     if mode == Modes.secondary:
320     trig_name = "HLT"
321     num_ls = 1
322     physics_active_psi = True
323     debug_print = False
324     no_versions=False
325 grchrist 1.34 min_rate = 0.0
326 grchrist 1.22 print_table = False
327     data_clean = True
328     ##plot_properties = [varX, varY, do_fit, save_root, save_png, fit_file]
329 awoodard 1.52 plot_properties = [["ls", "rawrate", False, True, False,fitFile]]
330     ## rate is calculated as: (measured rate, deadtime corrected) * prescale [prediction not dt corrected]
331     ## rawrate is calculated as: measured rate [prediction is dt corrected]
332 grchrist 1.22
333 grchrist 1.34 masked_triggers = ["AlCa_", "DST_", "HLT_L1", "HLT_Zero"]
334 grchrist 1.22 save_fits = False
335 grchrist 1.25 if max_dt==-1.0:
336     max_dt=2.0 ## no deadtime cut=2.0
337 grchrist 1.22 force_new=True
338     print_info=True
339 grchrist 1.25 if subsys==-1.0:
340     SubSystemOff={'All':True,'Mu':False,'HCal':False,'ECal':False,'Tracker':False,'EndCap':False,'Beam':True}
341 grchrist 1.13
342 grchrist 1.26 for k in SubSystemOff.iterkeys():
343     print k,"=",SubSystemOff[k]," ",
344     print " "
345 grchrist 1.33
346 grchrist 1.22 ######## END PARAMETERS - CALL FUNCTIONS ##########
347 awoodard 1.50 [Rates,LumiPageInfo]= GetDBRates(run_list, trig_name, trig_list, num_ls, max_dt, physics_active_psi, JSON, debug_print, force_new, SubSystemOff,NoVersion,all_triggers)
348     rootFileName = MakePlots(Rates, LumiPageInfo, run_list, trig_name, trig_list, num_ls, min_rate, max_dt, print_table, data_clean, plot_properties, masked_triggers, save_fits, debug_print,SubSystemOff, print_info,NoVersion, linear, do_inst, TMDerr,wp_bool,all_triggers)
349 awoodard 1.47
350 grchrist 1.22 except KeyboardInterrupt:
351     print "Wait... come back..."
352 abrinke1 1.1
353 awoodard 1.47
354    
355    
356 awoodard 1.50 def GetDBRates(run_list,trig_name,trig_list, num_ls, max_dt, physics_active_psi,JSON,debug_print, force_new, SubSystemOff,NoVersion,all_triggers):
357 abrinke1 1.1
358     Rates = {}
359 grchrist 1.10 LumiPageInfo={}
360 abrinke1 1.5 ## Save in RefRuns with name dependent on trig_name, num_ls, JSON, and physics_active_psi
361     if JSON:
362 amott 1.18 #print "Using JSON file"
363 abrinke1 1.5 if physics_active_psi:
364 grchrist 1.29 RefRunNameTemplate = "RefRuns/%s/Rates_%s_%sLS_JPAP.pkl"
365 abrinke1 1.5 else:
366 grchrist 1.29 RefRunNameTemplate = "RefRuns/%s/Rates_%s_%sLS_JSON.pkl"
367 abrinke1 1.5 else:
368 grchrist 1.14 print "Using Physics and Active ==1"
369 abrinke1 1.5 if physics_active_psi:
370 grchrist 1.29 RefRunNameTemplate = "RefRuns/%s/Rates_%s_%sLS_PAP.pkl"
371 abrinke1 1.5 else:
372 grchrist 1.29 RefRunNameTemplate = "RefRuns/%s/Rates_%s_%sLS.pkl"
373 grchrist 1.10
374    
375 grchrist 1.29 RefRunFile = RefRunNameTemplate % (thisyear,trig_name,num_ls)
376     RefRunFileHLT = RefRunNameTemplate % (thisyear,"HLT",num_ls)
377 grchrist 1.10
378     print "RefRun=",RefRunFile
379     print "RefRunFileHLT",RefRunFileHLT
380 grchrist 1.11 if not force_new:
381     try: ##Open an existing RefRun file with the same parameters and trigger name
382     pkl_file = open(RefRunFile, 'rb')
383     Rates = pickle.load(pkl_file)
384     pkl_file.close()
385     os.remove(RefRunFile)
386     print "using",RefRunFile
387    
388    
389 abrinke1 1.5 except:
390 grchrist 1.11 try: ##Open an existing RefRun file with the same parameters and HLT for trigger name
391     pkl_file = open(RefRunFileHLT)
392     HLTRates = pickle.load(pkl_file)
393     for key in HLTRates:
394     if trig_name in str(key):
395     Rates[key] = HLTRates[key]
396     #print str(RefRunFile)+" does not exist. Creating ..."
397     except:
398     print str(RefRunFile)+" does not exist. Creating ..."
399 grchrist 1.10
400     ## try the lumis file
401 grchrist 1.29 RefLumiNameTemplate = "RefRuns/%s/Lumis_%s_%sLS.pkl"
402     RefLumiFile= RefLumiNameTemplate % (thisyear,"HLT",num_ls)
403 grchrist 1.11 if not force_new:
404     try:
405     pkl_lumi_file = open(RefLumiFile, 'rb')
406     LumiPageInfo = pickle.load(pkl_lumi_file)
407     pkl_lumi_file.close()
408     os.remove(RefLumiFile)
409     print "using",RefLumiFile
410     except:
411     print str(RefLumiFile)+" doesn't exist. Make it..."
412 grchrist 1.34
413    
414     trig_list_noV=[]
415     for trigs in trig_list:
416     trig_list_noV.append(StripVersion(trigs))
417 grchrist 1.40
418 grchrist 1.34 if NoVersion:
419     trig_list=trig_list_noV
420    
421 abrinke1 1.5 for RefRunNum in run_list:
422     if JSON:
423     if not RefRunNum in JSON:
424     continue
425 awoodard 1.47 try:
426 abrinke1 1.1 ExistsAlready = False
427     for key in Rates:
428     if RefRunNum in Rates[key]["run"]:
429     ExistsAlready = True
430     break
431 grchrist 1.10
432    
433     LumiExistsLAready=False
434     for v in LumiPageInfo.itervalues():
435     if RefRunNum == v["Run"]:
436     LumiExistsAlready=True
437     break
438     if ExistsAlready and LumiExistsAlready:
439 abrinke1 1.1 continue
440 grchrist 1.10
441    
442 abrinke1 1.1 except:
443     print "Getting info for run "+str(RefRunNum)
444    
445     if RefRunNum < 1:
446     continue
447 grchrist 1.30 ColRunNum,isCol,isGood = GetLatestRunNumber(RefRunNum)
448     if not isGood:
449     print "Run ",RefRunNum, " is not Collisions"
450    
451     continue
452 awoodard 1.50
453 grchrist 1.26 if not isCol:
454     print "Run ",RefRunNum, " is not Collisions"
455    
456     continue
457    
458 grchrist 1.17 print "calculating rates and green lumis for run ",RefRunNum
459 grchrist 1.10
460 abrinke1 1.5 if True: ##Placeholder
461 abrinke1 1.1 if True: #May replace with "try" - for now it's good to know when problems happen
462     RefParser = DatabaseParser()
463     RefParser.RunNumber = RefRunNum
464     RefParser.ParseRunSetup()
465 abrinke1 1.5 RefLumiRangePhysicsActive = RefParser.GetLSRange(1,9999) ##Gets array of all LS with physics and active on
466     RefLumiArray = RefParser.GetLumiInfo() ##Gets array of all existing LS and their lumi info
467 abrinke1 1.2 RefLumiRange = []
468 grchrist 1.17 RefMoreLumiArray = RefParser.GetMoreLumiInfo()#dict with keys as bits from lumisections WBM page and values are dicts with key=LS:value=bit
469 amott 1.18
470 abrinke1 1.5 for iterator in RefLumiArray[0]: ##Makes array of LS with proper PAP and JSON properties
471 grchrist 1.11 ##cheap way of getting PSCol None-->0
472 amott 1.18 if RefLumiArray[0][iterator] not in range(1,9):
473 grchrist 1.11 RefLumiArray[0][iterator]=0
474 grchrist 1.15
475 grchrist 1.11
476 grchrist 1.17 if not physics_active_psi or (RefLumiArray[5][iterator] == 1 and RefLumiArray[6][iterator] == 1 and RefMoreLumiArray["b1pres"][iterator]==1 and RefMoreLumiArray["b2pres"][iterator]==1 and RefMoreLumiArray["b1stab"][iterator] and RefMoreLumiArray["b2stab"][iterator]==1):
477 abrinke1 1.5 if not JSON or RefRunNum in JSON:
478     if not JSON or iterator in JSON[RefRunNum]:
479     RefLumiRange.append(iterator)
480 grchrist 1.15 #print iterator, RefLumiArray[0][iterator], "active=",RefLumiArray[5][iterator],"physics=",RefLumiArray[6][iterator]
481 grchrist 1.9 #print "hbhea=",RefMoreLumiArray['hbhea'][iterator]
482    
483 abrinke1 1.5 try:
484     nls = RefLumiRange[0]
485     LSRange = {}
486     except:
487     print "Run "+str(RefRunNum)+" has no good LS"
488     continue
489     if num_ls > len(RefLumiRange):
490 abrinke1 1.1 print "Run "+str(RefRunNum)+" is too short: from "+str(nls)+" to "+str(RefLumiRange[-1])+", while num_ls = "+str(num_ls)
491     continue
492     while nls < RefLumiRange[-1]-num_ls:
493 abrinke1 1.5 LSRange[nls] = []
494     counter = 0
495     for iterator in RefLumiRange:
496     if iterator >= nls and counter < num_ls:
497     LSRange[nls].append(iterator)
498     counter += 1
499 abrinke1 1.1 nls = LSRange[nls][-1]+1
500 abrinke1 1.5
501 grchrist 1.17 #print "Run "+str(RefRunNum)+" contains LS from "+str(min(LSRange))+" to "+str(max(LSRange))
502 grchrist 1.8 for nls in sorted(LSRange.iterkeys()):
503 abrinke1 1.1 TriggerRates = RefParser.GetHLTRates(LSRange[nls])
504 awoodard 1.47
505     ## Clumsy way to append Stream A. Should choose correct method for calculating stream a based on ps column used in data taking.
506 awoodard 1.54 config = RateMonConfig(os.path.abspath(os.path.dirname(sys.argv[0])))
507     config.ReadCFG()
508     stream_mon = StreamMonitor()
509     core_a_rates = stream_mon.getStreamACoreRatesByLS(RefParser,LSRange[nls],config).values()
510     avg_core_a_rate = sum(core_a_rates)/len(LSRange[nls])
511     TriggerRates['HLT_Stream_A'] = [1,1,avg_core_a_rate,avg_core_a_rate]
512 abrinke1 1.5
513     [inst, live, delivered, dead, pscols] = RefParser.GetAvLumiInfo(LSRange[nls])
514 grchrist 1.17 deadtimebeamactive=RefParser.GetDeadTimeBeamActive(LSRange[nls])
515 awoodard 1.47
516 abrinke1 1.2 physics = 1
517     active = 1
518 abrinke1 1.5 psi = 99
519     for iterator in LSRange[nls]: ##Gets lowest value of physics, active, and psi in the set of lumisections
520 abrinke1 1.2 if RefLumiArray[5][iterator] == 0:
521     physics = 0
522     if RefLumiArray[6][iterator] == 0:
523     active = 0
524 abrinke1 1.5 if RefLumiArray[0][iterator] < psi:
525     psi = RefLumiArray[0][iterator]
526 abrinke1 1.2
527 grchrist 1.17 MoreLumiMulti=LumiRangeGreens(RefMoreLumiArray,LSRange,nls,RefRunNum,deadtimebeamactive)
528 grchrist 1.10
529 abrinke1 1.5 if inst < 0 or live < 0 or delivered < 0:
530     print "Run "+str(RefRunNum)+" LS "+str(nls)+" inst lumi = "+str(inst)+" live lumi = "+str(live)+", delivered = "+str(delivered)+", physics = "+str(physics)+", active = "+str(active)
531 abrinke1 1.2
532 grchrist 1.10
533    
534     LumiPageInfo[nls]=MoreLumiMulti
535    
536 abrinke1 1.1 for key in TriggerRates:
537 grchrist 1.34 if NoVersion:
538     name = StripVersion(key)
539     else:
540     name=key
541 grchrist 1.26 if not name in trig_list:
542 awoodard 1.50 if all_triggers:
543     trig_list.append(name)
544     else:
545     continue
546 awoodard 1.47
547 abrinke1 1.1 if not Rates.has_key(name):
548     Rates[name] = {}
549     Rates[name]["run"] = []
550     Rates[name]["ls"] = []
551     Rates[name]["ps"] = []
552     Rates[name]["inst_lumi"] = []
553     Rates[name]["live_lumi"] = []
554     Rates[name]["delivered_lumi"] = []
555     Rates[name]["deadtime"] = []
556     Rates[name]["rawrate"] = []
557     Rates[name]["rate"] = []
558     Rates[name]["rawxsec"] = []
559     Rates[name]["xsec"] = []
560 abrinke1 1.2 Rates[name]["physics"] = []
561     Rates[name]["active"] = []
562 abrinke1 1.5 Rates[name]["psi"] = []
563 grchrist 1.9
564    
565 abrinke1 1.1 [avps, ps, rate, psrate] = TriggerRates[key]
566     Rates[name]["run"].append(RefRunNum)
567     Rates[name]["ls"].append(nls)
568     Rates[name]["ps"].append(ps)
569     Rates[name]["inst_lumi"].append(inst)
570     Rates[name]["live_lumi"].append(live)
571     Rates[name]["delivered_lumi"].append(delivered)
572 grchrist 1.17 Rates[name]["deadtime"].append(deadtimebeamactive)
573 abrinke1 1.1 Rates[name]["rawrate"].append(rate)
574 abrinke1 1.2 if live == 0:
575 awoodard 1.56 Rates[name]["rate"].append(0.0)
576 abrinke1 1.2 Rates[name]["rawxsec"].append(0.0)
577     Rates[name]["xsec"].append(0.0)
578     else:
579 awoodard 1.56 try:
580     Rates[name]["rate"].append(psrate/(1.0-deadtimebeamactive))
581     except:
582     Rates[name]["rate"].append(0.0)
583 abrinke1 1.2 Rates[name]["rawxsec"].append(rate/live)
584     Rates[name]["xsec"].append(psrate/live)
585     Rates[name]["physics"].append(physics)
586     Rates[name]["active"].append(active)
587 abrinke1 1.5 Rates[name]["psi"].append(psi)
588 awoodard 1.47
589 grchrist 1.9
590 grchrist 1.10 #for keys, values in MoreLumiMulti.iteritems():
591     # Rates[name][keys].append(values)
592 grchrist 1.9 #print nls, name, keys, values
593 awoodard 1.47
594 grchrist 1.10 RateOutput = open(RefRunFile, 'wb') ##Save new Rates[] to RefRuns
595     pickle.dump(Rates, RateOutput, 2)
596     RateOutput.close()
597     LumiOutput = open(RefLumiFile,'wb')
598     pickle.dump(LumiPageInfo,LumiOutput, 2)
599     LumiOutput.close()
600    
601    
602     return [Rates,LumiPageInfo]
603 abrinke1 1.1
604 awoodard 1.50 def MakePlots(Rates, LumiPageInfo, run_list, trig_name, trig_list, num_ls, min_rate, max_dt, print_table, data_clean, plot_properties, masked_triggers, save_fits, debug_print, SubSystemOff, print_info,NoVersion, linear,do_inst, TMDerr,wp_bool,all_triggers):
605 abrinke1 1.1 min_run = min(run_list)
606     max_run = max(run_list)
607 muell149 1.46
608     priot.has_been_called=False
609 grchrist 1.11
610 abrinke1 1.5 InputFit = {}
611     OutputFit = {}
612 grchrist 1.14 first_trigger=True
613 abrinke1 1.1
614 grchrist 1.37
615     [[varX, varY, do_fit, save_root, save_png, fit_file]] = plot_properties
616    
617     RootNameTemplate = "%s_%sLS_%s_vs_%s_Run%s-%s.root"
618     RootFile = RootNameTemplate % (trig_name, num_ls, varX, varY, min_run, max_run)
619 abrinke1 1.1
620 amott 1.20 if not do_fit:
621     try:
622 abrinke1 1.1 pkl_file = open(fit_file, 'rb')
623 abrinke1 1.5 InputFit = pickle.load(pkl_file)
624 grchrist 1.40
625 amott 1.20 except:
626     print "ERROR: could not open fit file: %s" % (fit_file,)
627     if save_root:
628     try:
629     os.remove(RootFile)
630     except:
631     pass
632    
633 grchrist 1.38 trig_list_noV=[]
634     for trigs in trig_list:
635     trig_list_noV.append(StripVersion(trigs))
636     if NoVersion:
637     trig_list=trig_list_noV
638 grchrist 1.40
639 amott 1.20 ## check that all the triggers we ask to plot are in the input fit
640     if not save_fits:
641     goodtrig_list = []
642 grchrist 1.40 FitInputNoV={}
643 amott 1.20 for trig in trig_list:
644 grchrist 1.40
645     if NoVersion:
646     for trigger in InputFit.iterkeys():
647     FitInputNoV[StripVersion(trigger)]=InputFit[trigger]
648     InputFit=FitInputNoV
649 awoodard 1.56
650 amott 1.20 else:
651 grchrist 1.40 if not InputFit.has_key(trig):
652     print "WARNING: No Fit Prediction for Trigger %s, SKIPPING" % (trig,)
653     else:
654     goodtrig_list.append(trig)
655     trig_list = goodtrig_list
656 amott 1.18
657 grchrist 1.38
658 grchrist 1.34
659 grchrist 1.26 for print_trigger in sorted(Rates):
660 abrinke1 1.7 ##Limits Rates[] to runs in run_list
661     NewTrigger = {}
662 grchrist 1.34
663 grchrist 1.8 if not print_trigger in trig_list:
664 awoodard 1.50 if all_triggers:
665     trig_list.append(print_trigger)
666     else:
667     print "not in trig_list:",print_trigger, trig_list
668     continue
669 grchrist 1.34
670 abrinke1 1.7 for key in Rates[print_trigger]:
671     NewTrigger[key] = []
672     for iterator in range (len(Rates[print_trigger]["run"])):
673     if Rates[print_trigger]["run"][iterator] in run_list:
674     for key in Rates[print_trigger]:
675     NewTrigger[key].append(Rates[print_trigger][key][iterator])
676     Rates[print_trigger] = NewTrigger
677    
678 grchrist 1.34
679 abrinke1 1.1 meanrawrate = sum(Rates[print_trigger]["rawrate"])/len(Rates[print_trigger]["rawrate"])
680 grchrist 1.40
681 abrinke1 1.1 if not trig_name in print_trigger:
682 grchrist 1.40 print "failed",trig_name, print_trigger
683 abrinke1 1.1 continue
684 grchrist 1.40
685 abrinke1 1.1 if meanrawrate < min_rate:
686     continue
687     masked_trig = False
688     for mask in masked_triggers:
689     if str(mask) in print_trigger:
690     masked_trig = True
691     if masked_trig:
692     continue
693 grchrist 1.34
694 abrinke1 1.5 OutputFit[print_trigger] = {}
695 abrinke1 1.1
696     lowlumi = 0
697 abrinke1 1.7 meanlumi_init = median(Rates[print_trigger]["live_lumi"])
698 abrinke1 1.1 meanlumi = 0
699     highlumi = 0
700     lowxsec = 0
701     meanxsec = 0
702     highxsec = 0
703     nlow = 0
704     nhigh = 0
705 grchrist 1.15
706 abrinke1 1.1 for iterator in range(len(Rates[print_trigger]["rate"])):
707     if Rates[print_trigger]["live_lumi"][iterator] <= meanlumi_init:
708 grchrist 1.11 if ( Rates[print_trigger]["rawrate"][iterator] > 0.04 and Rates[print_trigger]["physics"][iterator] == 1 and Rates[print_trigger]["active"][iterator] == 1 and Rates[print_trigger]["deadtime"][iterator] < max_dt and Rates[print_trigger]["psi"][iterator] > 0 and Rates[print_trigger]["live_lumi"] > 500):
709 abrinke1 1.1 meanxsec+=Rates[print_trigger]["xsec"][iterator]
710     lowxsec+=Rates[print_trigger]["xsec"][iterator]
711     meanlumi+=Rates[print_trigger]["live_lumi"][iterator]
712     lowlumi+=Rates[print_trigger]["live_lumi"][iterator]
713     nlow+=1
714     if Rates[print_trigger]["live_lumi"][iterator] > meanlumi_init:
715 grchrist 1.11 if ( Rates[print_trigger]["rawrate"][iterator] > 0.04 and Rates[print_trigger]["physics"][iterator] == 1 and Rates[print_trigger]["active"][iterator] == 1 and Rates[print_trigger]["deadtime"][iterator] < max_dt and Rates[print_trigger]["psi"][iterator] > 0 and Rates[print_trigger]["live_lumi"] > 500):
716 abrinke1 1.1 meanxsec+=Rates[print_trigger]["xsec"][iterator]
717     highxsec+=Rates[print_trigger]["xsec"][iterator]
718     meanlumi+=Rates[print_trigger]["live_lumi"][iterator]
719     highlumi+=Rates[print_trigger]["live_lumi"][iterator]
720     nhigh+=1
721 abrinke1 1.7 try:
722     meanxsec = meanxsec/(nlow+nhigh)
723     meanlumi = meanlumi/(nlow+nhigh)
724     slopexsec = ( (highxsec/nhigh) - (lowxsec/nlow) ) / ( (highlumi/nhigh) - (lowlumi/nlow) )
725     except:
726 grchrist 1.40 #print str(print_trigger)+" has no good datapoints - setting initial xsec slope estimate to 0"
727 abrinke1 1.7 meanxsec = median(Rates[print_trigger]["xsec"])
728     meanlumi = median(Rates[print_trigger]["live_lumi"])
729     slopexsec = 0
730 abrinke1 1.1
731 abrinke1 1.5 [run_t,ls_t,ps_t,inst_t,live_t,delivered_t,deadtime_t,rawrate_t,rate_t,rawxsec_t,xsec_t,psi_t,e_run_t,e_ls_t,e_ps_t,e_inst_t,e_live_t,e_delivered_t,e_deadtime_t,e_rawrate_t,e_rate_t,e_rawxsec_t,e_xsec_t,e_psi_t,rawrate_fit_t,rate_fit_t,rawxsec_fit_t,xsec_fit_t,e_rawrate_fit_t,e_rate_fit_t,e_rawxsec_fit_t,e_xsec_fit_t] = MakePlotArrays()
732    
733 amott 1.20 if not do_fit:
734 grchrist 1.40
735 abrinke1 1.5 FitType = InputFit[print_trigger][0]
736     X0 = InputFit[print_trigger][1]
737     X1 = InputFit[print_trigger][2]
738     X2 = InputFit[print_trigger][3]
739     X3 = InputFit[print_trigger][4]
740 awoodard 1.48 sigma = InputFit[print_trigger][5]*3#Display 3 sigma band to show outliers more clearly
741 grchrist 1.38 X0err= InputFit[print_trigger][7]
742 grchrist 1.40 ##print print_trigger," X0err=",X0err
743 grchrist 1.14 #print str(print_trigger)+" "+str(FitType)+" "+str(X0)+" "+str(X1)+" "+str(X2)+" "+str(X3)
744 amott 1.20 #if (first_trigger):
745     # print '%20s % 10s % 6s % 5s % 5s % 3s % 4s' % ('trigger', 'fit type ', 'cubic', 'quad', ' linear', ' c ', 'Chi2')
746     # first_trigger=False
747     #print '%20s % 10s % 2.2g % 2.2g % 2.2g % 2.2g % 2.2g' % (print_trigger, FitType, X3, X2, X1, X0, Chi2)
748 grchrist 1.14 #print '{}, {}, {:02.2g}, {:02.2g}, {:02.2g}, {:02.2g} '.format(print_trigger, FitType, X0, X1, X2, X3)
749 grchrist 1.8 ## we are 2 lumis off when we start! -gets worse when we skip lumis
750 grchrist 1.17 it_offset=0
751 abrinke1 1.1 for iterator in range(len(Rates[print_trigger]["rate"])):
752     if not Rates[print_trigger]["run"][iterator] in run_list:
753     continue
754     prediction = meanxsec + slopexsec * (Rates[print_trigger]["live_lumi"][iterator] - meanlumi)
755     realvalue = Rates[print_trigger]["xsec"][iterator]
756 grchrist 1.8
757 grchrist 1.11
758     if pass_cuts(data_clean, realvalue, prediction, meanxsec, Rates, print_trigger, iterator, num_ls,LumiPageInfo,SubSystemOff,max_dt,print_info, trig_list):
759 grchrist 1.40
760 abrinke1 1.1 run_t.append(Rates[print_trigger]["run"][iterator])
761     ls_t.append(Rates[print_trigger]["ls"][iterator])
762     ps_t.append(Rates[print_trigger]["ps"][iterator])
763     inst_t.append(Rates[print_trigger]["inst_lumi"][iterator])
764 grchrist 1.17 live_t.append(Rates[print_trigger]["live_lumi"][iterator])
765     delivered_t.append(Rates[print_trigger]["delivered_lumi"][iterator])
766     deadtime_t.append(Rates[print_trigger]["deadtime"][iterator])
767 abrinke1 1.1 rawrate_t.append(Rates[print_trigger]["rawrate"][iterator])
768     rate_t.append(Rates[print_trigger]["rate"][iterator])
769     rawxsec_t.append(Rates[print_trigger]["rawxsec"][iterator])
770     xsec_t.append(Rates[print_trigger]["xsec"][iterator])
771 abrinke1 1.5 psi_t.append(Rates[print_trigger]["psi"][iterator])
772 abrinke1 1.1
773     e_run_t.append(0.0)
774     e_ls_t.append(0.0)
775     e_ps_t.append(0.0)
776     e_inst_t.append(14.14)
777     e_live_t.append(14.14)
778     e_delivered_t.append(14.14)
779 abrinke1 1.2 e_deadtime_t.append(0.01)
780 abrinke1 1.1 e_rawrate_t.append(math.sqrt(Rates[print_trigger]["rawrate"][iterator]/(num_ls*23.3)))
781     e_rate_t.append(Rates[print_trigger]["ps"][iterator]*math.sqrt(Rates[print_trigger]["rawrate"][iterator]/(num_ls*23.3)))
782 abrinke1 1.5 e_psi_t.append(0.0)
783 abrinke1 1.2 if live_t[-1] == 0:
784     e_rawxsec_t.append(0)
785     e_xsec_t.append(0)
786     else:
787 grchrist 1.16 try:
788     e_rawxsec_t.append(math.sqrt(Rates[print_trigger]["rawrate"][iterator]/(num_ls*23.3))/Rates[print_trigger]["live_lumi"][iterator])
789     e_xsec_t.append(Rates[print_trigger]["ps"][iterator]*math.sqrt(Rates[print_trigger]["rawrate"][iterator]/(num_ls*23.3))/Rates[print_trigger]["live_lumi"][iterator])
790     except:
791     e_rawxsec_t.append(0.)
792     e_xsec_t.append(0.)
793 amott 1.20 if not do_fit:
794 grchrist 1.38 if not do_inst:
795     if FitType == "expo":
796 grchrist 1.43 rate_prediction = X0 + X1*math.exp(X2+X3*delivered_t[-1])
797 grchrist 1.38 else:
798     rate_prediction = X0 + X1*delivered_t[-1] + X2*delivered_t[-1]*delivered_t[-1] + X3*delivered_t[-1]*delivered_t[-1]*delivered_t[-1]
799 abrinke1 1.5 ## if rate_t[-1] < 0.7 * rate_prediction or rate_t[-1] > 1.4 * rate_prediction:
800     ## print str(run_t[-1])+" "+str(ls_t[-1])+" "+str(print_trigger)+" "+str(ps_t[-1])+" "+str(deadtime_t[-1])+" "+str(rate_prediction)+" "+str(rate_t[-1])+" "+str(rawrate_t[-1])
801 grchrist 1.38 else:
802     if FitType == "expo":
803 grchrist 1.43 rate_prediction = X0 + X1*math.exp(X2+X3*inst_t[-1])
804 grchrist 1.38 else:
805     rate_prediction = X0 + X1*inst_t[-1] + X2*inst_t[-1]*inst_t[-1] + X3*inst_t[-1]*inst_t[-1]*inst_t[-1]
806 abrinke1 1.5
807 abrinke1 1.2 if live_t[-1] == 0:
808 abrinke1 1.5 rawrate_fit_t.append(0)
809     rate_fit_t.append(0)
810 abrinke1 1.2 rawxsec_fit_t.append(0)
811     xsec_fit_t.append(0)
812 abrinke1 1.7 e_rawrate_fit_t.append(0)
813 awoodard 1.45 e_rate_fit_t.append(sigma)
814 abrinke1 1.7 e_rawxsec_fit_t.append(0)
815     e_xsec_fit_t.append(0)
816 grchrist 1.11 #print "live_t=0", ls_t[-1], rawrate_fit_t[-1]
817 abrinke1 1.2 else:
818 grchrist 1.11 if ps_t[-1]>0.0:
819     rawrate_fit_t.append(rate_prediction*(1.0-deadtime_t[-1])/(ps_t[-1]))
820     else:
821     rawrate_fit_t.append(0.0)
822    
823 awoodard 1.52 rate_fit_t.append(rate_prediction)
824 awoodard 1.45 e_rate_fit_t.append(sigma)
825 abrinke1 1.5 rawxsec_fit_t.append(rawrate_fit_t[-1]/live_t[-1])
826     xsec_fit_t.append(rate_prediction*(1.0-deadtime_t[-1])/live_t[-1])
827 grchrist 1.38 try:
828    
829     if not TMDerr:
830 awoodard 1.45 e_rawrate_fit_t.append(sigma*rawrate_fit_t[-1]/rate_fit_t[-1])
831     e_rawxsec_fit_t.append(sigma*rawxsec_fit_t[-1]/rate_fit_t[-1])
832     e_xsec_fit_t.append(sigma*xsec_fit_t[-1]/rate_fit_t[-1])
833 grchrist 1.38 ###error from TMD predictions, calculated at 5e33
834     else:
835     e_rawrate_fit_t.append(X0err*inst_t[-1]/5000.)
836     e_rawxsec_fit_t.append(X0err/live_t[-1]*inst_t[-1]/5000.)
837     e_xsec_fit_t.append(X0err/live_t[-1]*inst_t[-1]/5000.)
838    
839     except:
840     print print_trigger, "has no fitted rate for LS", Rates[print_trigger]["ls"][iterator]
841 awoodard 1.45 e_rawrate_fit_t.append(sigma)
842     e_rawxsec_fit_t.append(sigma)
843     e_xsec_fit_t.append(sigma)
844 grchrist 1.11 #print "live_t>0", ls_t[-1], rawrate_fit_t[-1]
845 abrinke1 1.5
846 grchrist 1.17 ##print iterator, iterator, "ls=",ls_t[-1],"rate=",round(rawrate_t[-1],2), "deadtime=",round(deadtime_t[-1],2),"rawrate_fit=",round(rawrate_fit_t[-1],2),"max it=",len(Rates[print_trigger]["rate"])
847 grchrist 1.16
848 grchrist 1.27 if (print_info and num_ls==1 and (fabs(rawrate_fit_t[-1]-rawrate_t[-1])>2.5*sqrt(sum(Rates[print_trigger]["rawrate"])/len(Rates[print_trigger]["rawrate"])))):
849 grchrist 1.38 pass
850     ###print '%-60s has a bad prediction, run=%-10s LS=%-4s' % (print_trigger, Rates[print_trigger]["run"][iterator], Rates[print_trigger]["ls"][iterator])
851 grchrist 1.8
852 abrinke1 1.5 else: ##If the data point does not pass the data_clean filter
853 grchrist 1.11 #print "not passed", iterator, ls_t[-1], rawrate_fit_t[-1]
854 abrinke1 1.1 if debug_print:
855     print str(print_trigger)+" has xsec "+str(round(Rates[print_trigger]["xsec"][iterator],6))+" at lumi "+str(round(Rates[print_trigger]["live_lumi"][iterator],2))+" where the expected value is "+str(prediction)
856    
857 abrinke1 1.5 ## End "for iterator in range(len(Rates[print_trigger]["rate"])):" loop
858 abrinke1 1.1
859 abrinke1 1.5 AllPlotArrays = [run_t,ls_t,ps_t,inst_t,live_t,delivered_t,deadtime_t,rawrate_t,rate_t,rawxsec_t,xsec_t,psi_t,e_run_t,e_ls_t,e_ps_t,e_inst_t,e_live_t,e_delivered_t,e_deadtime_t,e_rawrate_t,e_rate_t,e_rawxsec_t,e_xsec_t,e_psi_t,rawrate_fit_t,rate_fit_t,rawxsec_fit_t,xsec_fit_t,e_rawrate_fit_t,e_rate_fit_t,e_rawxsec_fit_t,e_xsec_fit_t]
860 grchrist 1.40
861 abrinke1 1.5 [VX, VXE, VY, VYE, VF, VFE] = GetVXVY(plot_properties, fit_file, AllPlotArrays)
862 grchrist 1.40
863 abrinke1 1.5 if save_root or save_png:
864     c1 = TCanvas(str(varX),str(varY))
865     c1.SetName(str(print_trigger)+"_"+str(varY)+"_vs_"+str(varX))
866 grchrist 1.40
867     try:
868     gr1 = TGraphErrors(len(VX), VX, VY, VXE, VYE)
869     except:
870     print "No lumisections with events for", print_trigger, "probably due to v high deadtime"
871     continue
872 abrinke1 1.5 gr1.SetName("Graph_"+str(print_trigger)+"_"+str(varY)+"_vs_"+str(varX))
873     gr1.GetXaxis().SetTitle(varX)
874     gr1.GetYaxis().SetTitle(varY)
875     gr1.SetTitle(str(print_trigger))
876     gr1.SetMinimum(0)
877     gr1.SetMaximum(1.2*max(VY))
878     #gr1.GetXaxis().SetLimits(min(VX)-0.2*max(VX),1.2*max(VX))
879     gr1.GetXaxis().SetLimits(0,1.2*max(VX))
880     gr1.SetMarkerStyle(8)
881 grchrist 1.40
882    
883 abrinke1 1.5 if fit_file:
884     gr1.SetMarkerSize(0.8)
885     else:
886     gr1.SetMarkerSize(0.5)
887     gr1.SetMarkerColor(2)
888    
889 amott 1.20 if not do_fit:
890 abrinke1 1.5 gr3 = TGraphErrors(len(VX), VX, VF, VXE, VFE)
891     gr3.SetMarkerStyle(8)
892     gr3.SetMarkerSize(0.4)
893     gr3.SetMarkerColor(4)
894     gr3.SetFillColor(4)
895     gr3.SetFillStyle(3003)
896 abrinke1 1.1
897 abrinke1 1.5 if do_fit:
898 grchrist 1.35 if "rate" in varY and not linear:
899    
900 grchrist 1.41 f1a=0
901 abrinke1 1.5 f1a = TF1("f1a","pol2",0,8000)
902     f1a.SetLineColor(4)
903     f1a.SetLineWidth(2)
904 grchrist 1.41 #f1a.SetParLimits(0,0,0.2*(sum(VY)/len(VY))+0.8*min(VY))
905     #f1a.SetParLimits(1,0,2.0*max(VY)/(max(VX)*max(VX)))
906 awoodard 1.48 gr1.Fit("f1a","QN","rob=0.90")
907 muell149 1.46
908    
909     f1d=0
910     f1d = TF1("f1d","pol1",0,8000)#linear
911     f1d.SetLineColor(4)
912     f1d.SetLineWidth(2)
913     #f1a.SetParLimits(0,0,0.2*(sum(VY)/len(VY))+0.8*min(VY))
914     #f1a.SetParLimits(1,0,2.0*max(VY)/(max(VX)*max(VX)))
915 awoodard 1.48 gr1.Fit("f1d","QN","rob=0.90")
916 muell149 1.46
917 abrinke1 1.5 f1b = 0
918     f1c = 0
919 muell149 1.46 meanps = median(Rates[print_trigger]["ps"])
920     av_rte = mean(VY)
921    
922 grchrist 1.43 if True:
923     f1b = TF1("f1b","pol3",0,8000)
924     f1b.SetLineColor(2)
925     f1b.SetLineWidth(2)
926 grchrist 1.41 ## f1b.SetParLimits(0,0,0.2*(sum(VY)/len(VY))+0.8*min(VY))
927     ## f1b.SetParLimits(1,0,f1a.GetParameter(1)+0.0000001)
928     ## f1b.SetParLimits(2,0,f1a.GetParameter(2)+0.0000000001)
929     ## f1b.SetParLimits(3,0,2.0*max(VY)/(max(VX)*max(VX)*max(VX)))
930 awoodard 1.48 gr1.Fit("f1b","QN","rob=0.90")
931 grchrist 1.41 ## #if f1b.GetChisquare()/f1b.GetNDF() < f1a.GetChisquare()/f1a.GetNDF():
932     ## #print "X0 = "+str(f1a.GetParameter(0))+" X1 = "+str(f1a.GetParameter(1))+" X2 = "+str(f1a.GetParameter(2))
933     ## #print str(print_trigger)+" f1a Chi2 = "+str(10*f1a.GetChisquare()*math.sqrt(len(VY))/(math.sqrt(sum(VY))*num_ls*f1a.GetNDF()))+", f1b Chi2 = "+str(10*f1b.GetChisquare()*math.sqrt(len(VY))/(math.sqrt(sum(VY))*num_ls*f1b.GetNDF()))
934     ## #print "X0 = "+str(f1b.GetParameter(0))+" X1 = "+str(f1b.GetParameter(1))+" X2 = "+str(f1b.GetParameter(2))+" X3 = "+str(f1b.GetParameter(3))
935     ## if (first_trigger):
936     ## print '%-60s %4s x0 x1 x2 x3 chi2 ndf chi2/ndf' % ('trigger', 'type')
937 grchrist 1.15
938 grchrist 1.41 ## first_trigger=False
939 grchrist 1.15
940    
941 abrinke1 1.1
942 grchrist 1.43 f1c = TF1("f1c","[0]+[1]*expo(2)",0,8000)
943     f1c.SetLineColor(3)
944     f1c.SetLineWidth(2)
945     f1c.SetParLimits(0,0,0.2*(sum(VY)/len(VY))+0.8*min(VY))
946     f1c.SetParLimits(1,max(VY)/math.exp(10.0),max(VY)/math.exp(2.0))
947     f1c.SetParLimits(2,0.0,0.0000000001)
948     f1c.SetParLimits(3,2.0/max(VX),10.0/max(VX))
949 awoodard 1.48 gr1.Fit("f1c","QN","rob=0.90")
950 grchrist 1.41 ## #if f1c.GetChisquare()/f1c.GetNDF() < f1a.GetChisquare()/f1a.GetNDF():
951     ## #print str(print_trigger)+" f1a Chi2 = "+str(10*f1a.GetChisquare()*math.sqrt(len(VY))/(math.sqrt(sum(VY))*num_ls*f1a.GetNDF()))+", f1c Chi2 = "+str(10*f1c.GetChisquare()*math.sqrt(len(VY))/(math.sqrt(sum(VY))*num_ls*f1c.GetNDF()))
952     ## #print "X0 = "+str(f1c.GetParameter(0))+" X1 = "+str(f1c.GetParameter(1))+" X2 = "+str(f1c.GetParameter(2))+" X3 = "+str(f1c.GetParameter(3))
953 grchrist 1.15
954    
955 grchrist 1.34 ## if (f1c.GetChisquare()/f1c.GetNDF() < f1b.GetChisquare()/f1b.GetNDF() and f1c.GetChisquare()/f1c.GetNDF() < f1a.GetChisquare()/f1a.GetNDF()):
956     ## print '%-60s expo % .2f+/-%.2f % .2e+/-%.1e % .2e+/-%.1e % .2e+/-%.1e %7.2f %4.0f %5.3f ' % (print_trigger, f1c.GetParameter(0), f1c.GetParError(0), f1c.GetParameter(1), f1c.GetParError(1), 0 , 0 , 0 , 0 , f1c.GetChisquare(), f1c.GetNDF(), f1c.GetChisquare()/f1c.GetNDF())
957     ## elif (f1b.GetChisquare()/f1b.GetNDF() < f1a.GetChisquare()/f1a.GetNDF()):
958     ## print '%-60s cube % .2f+/-%.2f % .2e+/-%.1e % .2e+/-%.1e % .2e+/-%.1e %7.2f %4.0f %5.3f ' % (print_trigger, f1b.GetParameter(0), f1b.GetParError(0), f1b.GetParameter(1), f1b.GetParError(1), f1b.GetParameter(2), f1b.GetParError(2), f1b.GetParameter(3), f1b.GetParError(3), f1b.GetChisquare(), f1b.GetNDF(), f1b.GetChisquare()/f1b.GetNDF())
959     ## else:
960 grchrist 1.43
961 awoodard 1.48 # print f1a.GetChisquare()/f1a.GetNDF(), f1b.GetChisquare()/f1b.GetNDF(), f1c.GetChisquare()/f1c.GetNDF()
962 grchrist 1.15
963 abrinke1 1.5 else: ##If this is not a rate plot
964     f1a = TF1("f1a","pol1",0,8000)
965     f1a.SetLineColor(4)
966     f1a.SetLineWidth(2)
967     if "xsec" in varY:
968     f1a.SetParLimits(0,0,meanxsec*1.5)
969     if slopexsec > 0:
970     f1a.SetParLimits(1,0,max(VY)/max(VX))
971     else:
972     f1a.SetParLimits(1,2*slopexsec,-2*slopexsec)
973 abrinke1 1.1 else:
974 abrinke1 1.5 f1a.SetParLimits(0,-1000,1000)
975     gr1.Fit("f1a","Q","rob=0.80")
976 abrinke1 1.1
977 grchrist 1.35 if (first_trigger):
978     print '%-60s %4s x0 x1 x2 x3 chi2 ndf chi2/ndf' % ('trigger', 'type')
979     first_trigger=False
980 grchrist 1.40 try:
981     print '%-60s | line | % .2f | +/-%.2f | % .2e | +/-%.1e | % .2e | +/-%.1e | % .2e | +/-%.1e | %7.2f | %4.0f | %5.3f | ' % (print_trigger, f1a.GetParameter(0), f1a.GetParError(0), f1a.GetParameter(1), f1a.GetParError(1), 0 , 0 , 0 , 0 , f1a.GetChisquare(), f1a.GetNDF(), f1a.GetChisquare()/f1a.GetNDF())
982     except:
983     pass
984 awoodard 1.48
985     if print_table or save_fits:
986     if not do_fit:
987     print "Can't have save_fits = True and do_fit = False"
988     continue
989     try:
990     if (f1c.GetChisquare()/f1c.GetNDF() < (f1a.GetChisquare()/f1a.GetNDF()-1) and (f1b.GetChisquare()/f1b.GetNDF() < f1a.GetChisquare()/f1a.GetNDF()-1)):
991     print '%-60s | expo | % .2f | +/-%.2f | % .2e | +/-%.1e | % .2e | +/-%.1e | % .2e | +/-%.1e | %7.2f | %4.0f | %5.3f | ' % (print_trigger, f1c.GetParameter(0) , f1c.GetParError(0) , f1c.GetParameter(1) , f1c.GetParError(1) , f1c.GetParameter(2), f1c.GetParError(2) ,f1c.GetParameter(3), f1c.GetParError(3) ,f1c.GetChisquare() , f1c.GetNDF() , f1c.GetChisquare()/f1c.GetNDF())
992     f1c.SetLineColor(1)
993     priot(wp_bool,print_trigger,meanps,f1d,f1c,"expo",av_rte)
994     sigma = CalcSigma(VX, VY, f1c)*math.sqrt(num_ls)
995     OutputFit[print_trigger] = ["expo", f1c.GetParameter(0) , f1c.GetParameter(1) , f1c.GetParameter(2) , f1c.GetParameter(3) , sigma , meanrawrate, f1c.GetParError(0) , f1c.GetParError(1) , f1c.GetParError(2) , f1c.GetParError(3)]
996    
997     elif (f1b.GetChisquare()/f1b.GetNDF() < (f1a.GetChisquare()/f1a.GetNDF()-1)):
998     print '%-60s | cube | % .2f | +/-%.2f | % .2e | +/-%.1e | % .2e | +/-%.1e | % .2e | +/-%.1e | %7.2f | %4.0f | %5.3f | ' % (print_trigger, f1b.GetParameter(0) , f1b.GetParError(0) , f1b.GetParameter(1) , f1b.GetParError(1) , f1b.GetParameter(2), f1b.GetParError(2) ,f1b.GetParameter(3), f1b.GetParError(3), f1b.GetChisquare() , f1b.GetNDF() , f1b.GetChisquare()/f1b.GetNDF())
999     f1b.SetLineColor(1)
1000     priot(wp_bool,print_trigger,meanps,f1d,f1b,"cubic",av_rte)
1001     sigma = CalcSigma(VX, VY, f1b)*math.sqrt(num_ls)
1002     OutputFit[print_trigger] = ["poly", f1b.GetParameter(0) , f1b.GetParameter(1) , f1b.GetParameter(2) , f1b.GetParameter(3) , sigma , meanrawrate, f1b.GetParError(0) , f1b.GetParError(1) , f1b.GetParError(2) , f1b.GetParError(3)]
1003    
1004     else:
1005 awoodard 1.54
1006     print '%-60s | quad | % .2f | +/-%.2f | % .2e | +/-%.1e | % .2e | +/-%.1e | % .2e | +/-%.1e | %7.2f | %4.0f | %5.3f | ' % (print_trigger, f1a.GetParameter(0) , f1a.GetParError(0) , f1a.GetParameter(1) , f1a.GetParError(1) , f1a.GetParameter(2), f1a.GetParError(2), 0 , 0 , f1a.GetChisquare() , f1a.GetNDF() , f1a.GetChisquare()/f1a.GetNDF())
1007 awoodard 1.48 f1a.SetLineColor(1)
1008     priot(wp_bool,print_trigger,meanps,f1d,f1a,"quad",av_rte)
1009 awoodard 1.53 sigma = CalcSigma(VX, VY, f1a)*math.sqrt(num_ls)
1010 awoodard 1.48 OutputFit[print_trigger] = ["poly", f1a.GetParameter(0) , f1a.GetParameter(1) , f1a.GetParameter(2) , 0.0 , sigma , meanrawrate, f1a.GetParError(0) , f1a.GetParError(1) , f1a.GetParError(2) , 0.0]
1011 awoodard 1.55
1012 awoodard 1.48 except ZeroDivisionError:
1013     print "No NDF for",print_trigger,"skipping"
1014    
1015 abrinke1 1.5 if save_root or save_png:
1016     gr1.Draw("APZ")
1017 amott 1.20 if not do_fit:
1018 abrinke1 1.5 gr3.Draw("P3")
1019     if do_fit:
1020     f1a.Draw("same")
1021     try:
1022     f1b.Draw("same")
1023     f1c.Draw("same")
1024 muell149 1.46 f1d.Draw("same")
1025 abrinke1 1.5 except:
1026     True
1027     c1.Update()
1028     if save_root:
1029     myfile = TFile( RootFile, 'UPDATE' )
1030     c1.Write()
1031     myfile.Close()
1032     if save_png:
1033     c1.SaveAs(str(print_trigger)+"_"+str(varY)+"_vs_"+str(varX)+".png")
1034 abrinke1 1.1
1035 grchrist 1.35
1036 grchrist 1.28 ##print print_trigger, OutputFit[print_trigger]
1037 abrinke1 1.1 if save_root:
1038     print "Output root file is "+str(RootFile)
1039    
1040     if save_fits:
1041 grchrist 1.29 #FitNameTemplate = "Fits/%/Fit_%s_%sLS_Run%sto%s.pkl" % (thisyear)
1042 amott 1.20 #FitFile = FitNameTemplate % (trig_name, num_ls, min_run, max_run)
1043     if os.path.exists(fit_file):
1044     os.remove(fit_file)
1045     FitOutputFile = open(fit_file, 'wb')
1046 abrinke1 1.5 pickle.dump(OutputFit, FitOutputFile, 2)
1047     FitOutputFile.close()
1048 amott 1.20 print "Output fit file is "+str(fit_file)
1049 abrinke1 1.1
1050     if print_table:
1051 abrinke1 1.5 print "The expo fit is of the form p0+p1*e^(p2*x), poly is p0+(p1/10^3)*x+(p2/10^6)*x^2+(p3/10^9)*x^3, where x is Deliv. Lumi."
1052     print '%60s%10s%10s%10s%10s%10s%10s%10s' % ("Trig", "fit", "p0", "p1", "p2", "p3", "Chi2", "Av raw")
1053     for print_trigger in OutputFit:
1054     _trigger = (print_trigger[:56] + '...') if len(print_trigger) > 59 else print_trigger
1055 abrinke1 1.1 try:
1056 abrinke1 1.5 if OutputFit[print_trigger][0] == "poly":
1057     print '%60s%10s%10s%10s%10s%10s%10s' % (_trigger, OutputFit[print_trigger][0], round(OutputFit[print_trigger][1],3), round(OutputFit[print_trigger][2],6)*1000, round(OutputFit[print_trigger][3],9)*1000000, round(OutputFit[print_trigger][4],12)*1000000000, round(OutputFit[print_trigger][5],2), round(OutputFit[print_trigger][6],3))
1058     else:
1059     print '%60s%10s%10s%10s%10s%10s%10s' % (_trigger, OutputFit[print_trigger][0], OutputFit[print_trigger][1], OutputFit[print_trigger][2], OutputFit[print_trigger][3], OutputFit[print_trigger][4], round(OutputFit[print_trigger][5],2), round(OutputFit[print_trigger][6],3))
1060 abrinke1 1.1 except:
1061     print str(print_trigger)+" is somehow broken"
1062 amott 1.18 return RootFile
1063 abrinke1 1.5
1064     ############# SUPPORTING FUNCTIONS ################
1065    
1066    
1067 awoodard 1.47 def CalcSigma(var_x, var_y, func):
1068     residuals = []
1069     for x, y in zip(var_x,var_y):
1070 awoodard 1.53 residuals.append(y - func.Eval(x,0,0))
1071 awoodard 1.47
1072     res_squared = [i*i for i in residuals]
1073 awoodard 1.53 if len(res_squared) > 2:
1074     sigma = math.sqrt(sum(res_squared)/(len(res_squared)-2))
1075     else:
1076     sigma = 0
1077 awoodard 1.47 return sigma
1078    
1079 abrinke1 1.5 def GetJSON(json_file):
1080    
1081     input_file = open(json_file)
1082     file_content = input_file.read()
1083     inputRange = selectionParser(file_content)
1084     JSON = inputRange.runsandls()
1085     return JSON
1086     ##JSON is an array: JSON[run_number] = [1st ls, 2nd ls, 3rd ls ... nth ls]
1087    
1088     def MakePlotArrays():
1089     run_t = array.array('f')
1090     ls_t = array.array('f')
1091     ps_t = array.array('f')
1092     inst_t = array.array('f')
1093     live_t = array.array('f')
1094     delivered_t = array.array('f')
1095     deadtime_t = array.array('f')
1096     rawrate_t = array.array('f')
1097     rate_t = array.array('f')
1098     rawxsec_t = array.array('f')
1099     xsec_t = array.array('f')
1100     psi_t = array.array('f')
1101    
1102     e_run_t = array.array('f')
1103     e_ls_t = array.array('f')
1104     e_ps_t = array.array('f')
1105     e_inst_t = array.array('f')
1106     e_live_t = array.array('f')
1107     e_delivered_t = array.array('f')
1108     e_deadtime_t = array.array('f')
1109     e_rawrate_t = array.array('f')
1110     e_rate_t = array.array('f')
1111     e_rawxsec_t = array.array('f')
1112     e_xsec_t = array.array('f')
1113     e_psi_t = array.array('f')
1114    
1115     rawrate_fit_t = array.array('f')
1116     rate_fit_t = array.array('f')
1117     rawxsec_fit_t = array.array('f')
1118     xsec_fit_t = array.array('f')
1119     e_rawrate_fit_t = array.array('f')
1120     e_rate_fit_t = array.array('f')
1121     e_rawxsec_fit_t = array.array('f')
1122     e_xsec_fit_t = array.array('f')
1123    
1124     return [run_t,ls_t,ps_t,inst_t,live_t,delivered_t,deadtime_t,rawrate_t,rate_t,rawxsec_t,xsec_t,psi_t,e_run_t,e_ls_t,e_ps_t,e_inst_t,e_live_t,e_delivered_t,e_deadtime_t,e_rawrate_t,e_rate_t,e_rawxsec_t,e_xsec_t,e_psi_t,rawrate_fit_t,rate_fit_t,rawxsec_fit_t,xsec_fit_t,e_rawrate_fit_t,e_rate_fit_t,e_rawxsec_fit_t,e_xsec_fit_t]
1125    
1126    
1127     def GetVXVY(plot_properties, fit_file, AllPlotArrays):
1128    
1129     VF = "0"
1130     VFE = "0"
1131    
1132     [run_t,ls_t,ps_t,inst_t,live_t,delivered_t,deadtime_t,rawrate_t,rate_t,rawxsec_t,xsec_t,psi_t,e_run_t,e_ls_t,e_ps_t,e_inst_t,e_live_t,e_delivered_t,e_deadtime_t,e_rawrate_t,e_rate_t,e_rawxsec_t,e_xsec_t,e_psi_t,rawrate_fit_t,rate_fit_t,rawxsec_fit_t,xsec_fit_t,e_rawrate_fit_t,e_rate_fit_t,e_rawxsec_fit_t,e_xsec_fit_t] = AllPlotArrays
1133     for varX, varY, do_fit, save_root, save_png, fit_file in plot_properties:
1134     if varX == "run":
1135     VX = run_t
1136     VXE = run_t_e
1137     elif varX == "ls":
1138     VX = ls_t
1139     VXE = e_ls_t
1140     elif varX == "ps":
1141     VX = ps_t
1142     VXE = e_ps_t
1143     elif varX == "inst":
1144     VX = inst_t
1145     VXE = e_inst_t
1146     elif varX == "live":
1147     VX = live_t
1148     VXE = e_live_t
1149     elif varX == "delivered":
1150     VX = delivered_t
1151     VXE = e_delivered_t
1152     elif varX == "deadtime":
1153     VX = deadtime_t
1154     VXE = e_deadtime_t
1155     elif varX == "rawrate":
1156     VX = rawrate_t
1157     VXE = e_rawrate_t
1158     elif varX == "rate":
1159     VX = rate_t
1160     VXE = e_rate_t
1161     elif varX == "rawxsec":
1162     VX = rawxsec_t
1163     VXE = e_rawxsec_t
1164     elif varX == "xsec":
1165     VX = xsec_t
1166     VXE = e_xsec_t
1167     elif varX == "psi":
1168     VX = psi_t
1169     VXE = e_psi_t
1170     else:
1171     print "No valid variable entered for X"
1172     continue
1173     if varY == "run":
1174     VY = run_t
1175     VYE = run_t_e
1176     elif varY == "ls":
1177     VY = ls_t
1178     VYE = e_ls_t
1179     elif varY == "ps":
1180     VY = ps_t
1181     VYE = e_ps_t
1182     elif varY == "inst":
1183     VY = inst_t
1184     VYE = e_inst_t
1185     elif varY == "live":
1186     VY = live_t
1187     VYE = e_live_t
1188     elif varY == "delivered":
1189     VY = delivered_t
1190     VYE = e_delivered_t
1191     elif varY == "deadtime":
1192     VY = deadtime_t
1193     VYE = e_deadtime_t
1194     elif varY == "rawrate":
1195     VY = rawrate_t
1196     VYE = e_rawrate_t
1197     if fit_file:
1198     VF = rawrate_fit_t
1199     VFE = e_rawrate_fit_t
1200     elif varY == "rate":
1201     VY = rate_t
1202     VYE = e_rate_t
1203     if fit_file:
1204     VF = rate_fit_t
1205     VFE = e_rate_fit_t
1206     elif varY == "rawxsec":
1207     VY = rawxsec_t
1208     VYE = e_rawxsec_t
1209     if fit_file:
1210     VF = rawxsec_fit_t
1211     VFE = e_rawxsec_fit_t
1212     elif varY == "xsec":
1213     VY = xsec_t
1214     VYE = e_xsec_t
1215     if fit_file:
1216     VF = xsec_fit_t
1217     VFE = e_xsec_fit_t
1218     elif varY == "psi":
1219     VY = psi_t
1220     VYE = e_psi_t
1221     else:
1222     print "No valid variable entered for Y"
1223     continue
1224    
1225     return [VX, VXE, VY, VYE, VF, VFE]
1226    
1227 grchrist 1.11 def pass_cuts(data_clean, realvalue, prediction, meanxsec, Rates, print_trigger, iterator, num_ls,LumiPageInfo,SubSystemOff, max_dt, print_info, trig_list):
1228 grchrist 1.17 it_offset=0
1229 grchrist 1.15 Passed=True
1230     subsystemfailed=[]
1231 grchrist 1.11
1232 grchrist 1.8 if num_ls==1:
1233     ##fit is 2 ls ahead of real rate
1234 grchrist 1.17
1235 grchrist 1.8
1236 grchrist 1.10 LS=Rates[print_trigger]["ls"][iterator]
1237     #print "ls=",LS,
1238     LSRange=LumiPageInfo[LS]["LSRange"]
1239     #print LSRange,
1240     LS2=LSRange[-1]
1241     #LS2=LSRange.pop()
1242     #print "LS2=",LS2
1243    
1244     #print LumiPageInfo[LS]
1245     lumidict={}
1246     lumidict=LumiPageInfo[LS]
1247 grchrist 1.15
1248 grchrist 1.11
1249    
1250    
1251    
1252     if print_info:
1253     if (iterator==0 and print_trigger==trig_list[0]):
1254     print '%10s%10s%10s%10s%10s%10s%10s%15s%20s' % ("Status", "Run", "LS", "Physics", "Active", "Deadtime", " MaxDeadTime", " Passed all subsystems?", " List of Subsystems failed")
1255    
1256     ## if SubSystemOff["All"]:
1257     ## for keys in LumiPageInfo[LS]:
1258     ## #print LS, keys, LumiPageInfo[LS][keys]
1259     ## if not LumiPageInfo[LS][keys]:
1260     ## Passed=False
1261     ## subsystemfailed.append(keys)
1262     ## break
1263     ## else:
1264     if SubSystemOff["Mu"] or SubSystemOff["All"]:
1265 grchrist 1.38 if not (LumiPageInfo[LS]["rpc"] and LumiPageInfo[LS]["dt0"] and LumiPageInfo[LS]["dtp"] and LumiPageInfo[LS]["dtm"] and LumiPageInfo[LS]["cscp"] and LumiPageInfo[LS]["cscm"]):
1266 grchrist 1.11 Passed=False
1267     subsystemfailed.append("Mu")
1268     if SubSystemOff["HCal"] or SubSystemOff["All"]:
1269     if not (LumiPageInfo[LS]["hbhea"] and LumiPageInfo[LS]["hbheb"] and LumiPageInfo[LS]["hbhec"]):
1270     Passed=False
1271     subsystemfailed.append("HCal")
1272     if (SubSystemOff["EndCap"] or SubSystemOff["All"]) and not (LumiPageInfo[LS]["hf"]):
1273     Passed=False
1274     subsystemfailed.append("HCal-EndCap")
1275     if SubSystemOff["ECal"] or SubSystemOff["All"]:
1276     if not (LumiPageInfo[LS]["ebp"] and LumiPageInfo[LS]["ebm"]):
1277     Passed=False
1278     subsystemfailed.append("ECal")
1279     if (SubSystemOff["EndCap"] or SubSystemOff["All"]) and not (LumiPageInfo[LS]["eep"] and LumiPageInfo[LS]["eem"] and LumiPageInfo[LS]["esp"] or LumiPageInfo[LS]["esm"]):
1280     Passed=False
1281     subsystemfailed.append("ECal-EndCap")
1282     if SubSystemOff["Tracker"] or SubSystemOff["All"]:
1283     if not (LumiPageInfo[LS]["tob"] and LumiPageInfo[LS]["tibtid"] and LumiPageInfo[LS]["bpix"] and LumiPageInfo[LS]["fpix"]):
1284     Passed=False
1285     subsystemfailed.append("Tracker")
1286     if (SubSystemOff["EndCap"] or SubSystemOff["All"]) and not (LumiPageInfo[LS]["tecp"] and LumiPageInfo[LS]["tecm"]):
1287     Passed=False
1288     subsystemfailed.append("Tracker-EndCap")
1289     if SubSystemOff["Beam"] or SubSystemOff["All"]:
1290     if not(LumiPageInfo[LS]["b1pres"] and LumiPageInfo[LS]["b2pres"] and LumiPageInfo[LS]["b1stab"] and LumiPageInfo[LS]["b2stab"]):
1291     Passed=False
1292     subsystemfailed.append("Beam")
1293 grchrist 1.12 else:
1294 grchrist 1.17
1295 grchrist 1.12 Passed=True
1296 grchrist 1.10
1297 grchrist 1.38
1298 grchrist 1.10
1299 grchrist 1.8 if not data_clean or (
1300    
1301 grchrist 1.11 Rates[print_trigger]["physics"][iterator] == 1
1302 grchrist 1.8 and Rates[print_trigger]["active"][iterator] == 1
1303 grchrist 1.17 and Rates[print_trigger]["deadtime"][iterator] < max_dt
1304 grchrist 1.11 #and Rates[print_trigger]["psi"][iterator] > 0
1305 grchrist 1.10 and Passed
1306 grchrist 1.8 ):
1307 grchrist 1.11 #print LS, "True"
1308 grchrist 1.26 if (print_info and num_ls==1 and (realvalue <0.4*prediction or realvalue>2.5*prediction)):
1309     pass
1310     ##print '%-60s%10s%10s%10s%10s%10s%10s%10s%15s%20s' % (print_trigger,"Passed", Rates[print_trigger]["run"][iterator], LS, Rates[print_trigger]["physics"][iterator], Rates[print_trigger]["active"][iterator], round(Rates[print_trigger]["deadtime"][iterator],2), max_dt, Passed, subsystemfailed)
1311    
1312 grchrist 1.8 return True
1313     else:
1314 grchrist 1.11
1315 grchrist 1.13 if (print_info and print_trigger==trig_list[0] and num_ls==1):
1316 grchrist 1.17 print '%10s%10s%10s%10s%10s%10s%10s%15s%20s' % ("Failed", Rates[print_trigger]["run"][iterator], LS, Rates[print_trigger]["physics"][iterator], Rates[print_trigger]["active"][iterator], round(Rates[print_trigger]["deadtime"][iterator],2), max_dt, Passed, subsystemfailed)
1317 grchrist 1.26
1318 grchrist 1.8 return False
1319 abrinke1 1.5
1320 grchrist 1.10
1321     #### LumiRangeGreens ####
1322     ####inputs: RefMoreLumiArray --dict with lumi page info in LS by LS blocks,
1323     #### LRange --list range over lumis,
1324     #### nls --number of lumisections
1325     #### RefRunNum --run number
1326     ####
1327     ####outputs RangeMoreLumi --lumi page info in dict LSRange blocks with lumi, added items Run and LSRange
1328 grchrist 1.17 def LumiRangeGreens(RefMoreLumiArray,LSRange,nls,RefRunNum,deadtimebeamactive):
1329 grchrist 1.9
1330     RangeMoreLumi={}
1331     for keys,values in RefMoreLumiArray.iteritems():
1332     RangeMoreLumi[keys]=1
1333 grchrist 1.10
1334 grchrist 1.9 for iterator in LSRange[nls]:
1335     for keys, values in RefMoreLumiArray.iteritems():
1336     if RefMoreLumiArray[keys][iterator]==0:
1337     RangeMoreLumi[keys]=0
1338 grchrist 1.10 RangeMoreLumi['LSRange']=LSRange[nls]
1339     RangeMoreLumi['Run']=RefRunNum
1340 grchrist 1.17 RangeMoreLumi['DeadTimeBeamActive']=deadtimebeamactive
1341 grchrist 1.9 return RangeMoreLumi
1342    
1343 grchrist 1.10 #### CheckLumis ####
1344     ####inputs:
1345     #### PageLumiInfo --dict of LS with dict of some lumipage info
1346     #### Rates --dict of triggernames with dict of info
1347     def checkLS(Rates, PageLumiInfo,trig_list):
1348     rateslumis=Rates[trig_list[-1]]["ls"]
1349     keys=PageLumiInfo.keys()
1350     print "lumi run=",PageLumiInfo[keys[-1]]["Run"]
1351     ll=0
1352     for ls in keys:
1353     print ls,rateslumis[ll]
1354     ll=ll+1
1355     return False
1356    
1357    
1358 grchrist 1.9
1359 grchrist 1.29
1360 abrinke1 1.1 if __name__=='__main__':
1361 grchrist 1.29 global thisyear
1362 abrinke1 1.1 main()