ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/DatabaseRatePredictor.py
Revision: 1.38
Committed: Fri Apr 13 09:47:36 2012 UTC (13 years ago) by grchrist
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-00-30, V00-00-29
Changes since 1.37: +69 -25 lines
Log Message:
bug fixes in predictor and monitor, mkTMDfits

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