ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/DatabaseRatePredictor.py
Revision: 1.52
Committed: Thu Aug 16 15:10:07 2012 UTC (12 years, 8 months ago) by awoodard
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-01-08
Changes since 1.51: +5 -5 lines
Log Message:
changing certification plot default back to rawrate

File Contents

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