ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/DatabaseRatePredictor.py
Revision: 1.39
Committed: Tue Apr 17 20:26:05 2012 UTC (13 years ago) by grchrist
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-00-31
Changes since 1.38: +8 -4 lines
Log Message:
No Version cleaned up

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