ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/DatabaseRatePredictor.py
Revision: 1.51
Committed: Thu Aug 16 07:55:40 2012 UTC (12 years, 8 months ago) by awoodard
Content type: text/x-python
Branch: MAIN
Changes since 1.50: +4 -2 lines
Log Message:
Changing deadtime correction to be consistent for rate and 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.47 plot_properties = [["ls", "rate", False, True, False,fitFile]]
329 grchrist 1.22
330 grchrist 1.34 masked_triggers = ["AlCa_", "DST_", "HLT_L1", "HLT_Zero"]
331 grchrist 1.22 save_fits = False
332 grchrist 1.25 if max_dt==-1.0:
333     max_dt=2.0 ## no deadtime cut=2.0
334 grchrist 1.22 force_new=True
335     print_info=True
336 grchrist 1.25 if subsys==-1.0:
337     SubSystemOff={'All':True,'Mu':False,'HCal':False,'ECal':False,'Tracker':False,'EndCap':False,'Beam':True}
338 grchrist 1.13
339 grchrist 1.26 for k in SubSystemOff.iterkeys():
340     print k,"=",SubSystemOff[k]," ",
341     print " "
342 grchrist 1.33
343 grchrist 1.22 ######## END PARAMETERS - CALL FUNCTIONS ##########
344 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)
345     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)
346 awoodard 1.47
347 grchrist 1.22 except KeyboardInterrupt:
348     print "Wait... come back..."
349 abrinke1 1.1
350 awoodard 1.47
351    
352    
353 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):
354 abrinke1 1.1
355     Rates = {}
356 grchrist 1.10 LumiPageInfo={}
357 abrinke1 1.5 ## Save in RefRuns with name dependent on trig_name, num_ls, JSON, and physics_active_psi
358     if JSON:
359 amott 1.18 #print "Using JSON file"
360 abrinke1 1.5 if physics_active_psi:
361 grchrist 1.29 RefRunNameTemplate = "RefRuns/%s/Rates_%s_%sLS_JPAP.pkl"
362 abrinke1 1.5 else:
363 grchrist 1.29 RefRunNameTemplate = "RefRuns/%s/Rates_%s_%sLS_JSON.pkl"
364 abrinke1 1.5 else:
365 grchrist 1.14 print "Using Physics and Active ==1"
366 abrinke1 1.5 if physics_active_psi:
367 grchrist 1.29 RefRunNameTemplate = "RefRuns/%s/Rates_%s_%sLS_PAP.pkl"
368 abrinke1 1.5 else:
369 grchrist 1.29 RefRunNameTemplate = "RefRuns/%s/Rates_%s_%sLS.pkl"
370 grchrist 1.10
371    
372 grchrist 1.29 RefRunFile = RefRunNameTemplate % (thisyear,trig_name,num_ls)
373     RefRunFileHLT = RefRunNameTemplate % (thisyear,"HLT",num_ls)
374 grchrist 1.10
375     print "RefRun=",RefRunFile
376     print "RefRunFileHLT",RefRunFileHLT
377 grchrist 1.11 if not force_new:
378     try: ##Open an existing RefRun file with the same parameters and trigger name
379     pkl_file = open(RefRunFile, 'rb')
380     Rates = pickle.load(pkl_file)
381     pkl_file.close()
382     os.remove(RefRunFile)
383     print "using",RefRunFile
384    
385    
386 abrinke1 1.5 except:
387 grchrist 1.11 try: ##Open an existing RefRun file with the same parameters and HLT for trigger name
388     pkl_file = open(RefRunFileHLT)
389     HLTRates = pickle.load(pkl_file)
390     for key in HLTRates:
391     if trig_name in str(key):
392     Rates[key] = HLTRates[key]
393     #print str(RefRunFile)+" does not exist. Creating ..."
394     except:
395     print str(RefRunFile)+" does not exist. Creating ..."
396 grchrist 1.10
397     ## try the lumis file
398 grchrist 1.29 RefLumiNameTemplate = "RefRuns/%s/Lumis_%s_%sLS.pkl"
399     RefLumiFile= RefLumiNameTemplate % (thisyear,"HLT",num_ls)
400 grchrist 1.11 if not force_new:
401     try:
402     pkl_lumi_file = open(RefLumiFile, 'rb')
403     LumiPageInfo = pickle.load(pkl_lumi_file)
404     pkl_lumi_file.close()
405     os.remove(RefLumiFile)
406     print "using",RefLumiFile
407     except:
408     print str(RefLumiFile)+" doesn't exist. Make it..."
409 grchrist 1.34
410    
411     trig_list_noV=[]
412     for trigs in trig_list:
413     trig_list_noV.append(StripVersion(trigs))
414 grchrist 1.40
415 grchrist 1.34 if NoVersion:
416     trig_list=trig_list_noV
417    
418 abrinke1 1.5 for RefRunNum in run_list:
419     if JSON:
420     if not RefRunNum in JSON:
421     continue
422 awoodard 1.47 try:
423 abrinke1 1.1 ExistsAlready = False
424     for key in Rates:
425     if RefRunNum in Rates[key]["run"]:
426     ExistsAlready = True
427     break
428 grchrist 1.10
429    
430     LumiExistsLAready=False
431     for v in LumiPageInfo.itervalues():
432     if RefRunNum == v["Run"]:
433     LumiExistsAlready=True
434     break
435     if ExistsAlready and LumiExistsAlready:
436 abrinke1 1.1 continue
437 grchrist 1.10
438    
439 abrinke1 1.1 except:
440     print "Getting info for run "+str(RefRunNum)
441    
442     if RefRunNum < 1:
443     continue
444 grchrist 1.30 ColRunNum,isCol,isGood = GetLatestRunNumber(RefRunNum)
445     if not isGood:
446     print "Run ",RefRunNum, " is not Collisions"
447    
448     continue
449 awoodard 1.50
450 grchrist 1.26 if not isCol:
451     print "Run ",RefRunNum, " is not Collisions"
452    
453     continue
454    
455 grchrist 1.17 print "calculating rates and green lumis for run ",RefRunNum
456 grchrist 1.10
457 abrinke1 1.5 if True: ##Placeholder
458 abrinke1 1.1 if True: #May replace with "try" - for now it's good to know when problems happen
459     RefParser = DatabaseParser()
460     RefParser.RunNumber = RefRunNum
461     RefParser.ParseRunSetup()
462 abrinke1 1.5 RefLumiRangePhysicsActive = RefParser.GetLSRange(1,9999) ##Gets array of all LS with physics and active on
463     RefLumiArray = RefParser.GetLumiInfo() ##Gets array of all existing LS and their lumi info
464 abrinke1 1.2 RefLumiRange = []
465 grchrist 1.17 RefMoreLumiArray = RefParser.GetMoreLumiInfo()#dict with keys as bits from lumisections WBM page and values are dicts with key=LS:value=bit
466 amott 1.18
467 abrinke1 1.5 for iterator in RefLumiArray[0]: ##Makes array of LS with proper PAP and JSON properties
468 grchrist 1.11 ##cheap way of getting PSCol None-->0
469 amott 1.18 if RefLumiArray[0][iterator] not in range(1,9):
470 grchrist 1.11 RefLumiArray[0][iterator]=0
471 grchrist 1.15
472 grchrist 1.11
473 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):
474 abrinke1 1.5 if not JSON or RefRunNum in JSON:
475     if not JSON or iterator in JSON[RefRunNum]:
476     RefLumiRange.append(iterator)
477 grchrist 1.15 #print iterator, RefLumiArray[0][iterator], "active=",RefLumiArray[5][iterator],"physics=",RefLumiArray[6][iterator]
478 grchrist 1.9 #print "hbhea=",RefMoreLumiArray['hbhea'][iterator]
479    
480 abrinke1 1.5 try:
481     nls = RefLumiRange[0]
482     LSRange = {}
483     except:
484     print "Run "+str(RefRunNum)+" has no good LS"
485     continue
486     if num_ls > len(RefLumiRange):
487 abrinke1 1.1 print "Run "+str(RefRunNum)+" is too short: from "+str(nls)+" to "+str(RefLumiRange[-1])+", while num_ls = "+str(num_ls)
488     continue
489     while nls < RefLumiRange[-1]-num_ls:
490 abrinke1 1.5 LSRange[nls] = []
491     counter = 0
492     for iterator in RefLumiRange:
493     if iterator >= nls and counter < num_ls:
494     LSRange[nls].append(iterator)
495     counter += 1
496 abrinke1 1.1 nls = LSRange[nls][-1]+1
497 abrinke1 1.5
498 grchrist 1.17 #print "Run "+str(RefRunNum)+" contains LS from "+str(min(LSRange))+" to "+str(max(LSRange))
499 grchrist 1.8 for nls in sorted(LSRange.iterkeys()):
500 abrinke1 1.1 TriggerRates = RefParser.GetHLTRates(LSRange[nls])
501 awoodard 1.47
502     ## Clumsy way to append Stream A. Should choose correct method for calculating stream a based on ps column used in data taking.
503     if 'HLT_Stream_A' in trig_list:
504     config = RateMonConfig(os.path.abspath(os.path.dirname(sys.argv[0])))
505     config.ReadCFG()
506     stream_mon = StreamMonitor()
507     core_a_rates = stream_mon.getStreamACoreRatesByLS(RefParser,LSRange[nls],config).values()
508     avg_core_a_rate = sum(core_a_rates)/len(LSRange[nls])
509     TriggerRates['HLT_Stream_A'] = [1,1,avg_core_a_rate,avg_core_a_rate]
510 abrinke1 1.5
511     [inst, live, delivered, dead, pscols] = RefParser.GetAvLumiInfo(LSRange[nls])
512 grchrist 1.17 deadtimebeamactive=RefParser.GetDeadTimeBeamActive(LSRange[nls])
513 awoodard 1.47
514 abrinke1 1.2 physics = 1
515     active = 1
516 abrinke1 1.5 psi = 99
517     for iterator in LSRange[nls]: ##Gets lowest value of physics, active, and psi in the set of lumisections
518 abrinke1 1.2 if RefLumiArray[5][iterator] == 0:
519     physics = 0
520     if RefLumiArray[6][iterator] == 0:
521     active = 0
522 abrinke1 1.5 if RefLumiArray[0][iterator] < psi:
523     psi = RefLumiArray[0][iterator]
524 abrinke1 1.2
525 grchrist 1.17 MoreLumiMulti=LumiRangeGreens(RefMoreLumiArray,LSRange,nls,RefRunNum,deadtimebeamactive)
526 grchrist 1.10
527 abrinke1 1.5 if inst < 0 or live < 0 or delivered < 0:
528     print "Run "+str(RefRunNum)+" LS "+str(nls)+" inst lumi = "+str(inst)+" live lumi = "+str(live)+", delivered = "+str(delivered)+", physics = "+str(physics)+", active = "+str(active)
529 abrinke1 1.2
530 grchrist 1.10
531    
532     LumiPageInfo[nls]=MoreLumiMulti
533    
534 abrinke1 1.1 for key in TriggerRates:
535 grchrist 1.34 if NoVersion:
536     name = StripVersion(key)
537     else:
538     name=key
539 grchrist 1.26 if not name in trig_list:
540 awoodard 1.50 if all_triggers:
541     trig_list.append(name)
542     else:
543     continue
544 awoodard 1.47
545 abrinke1 1.1 if not Rates.has_key(name):
546     Rates[name] = {}
547     Rates[name]["run"] = []
548     Rates[name]["ls"] = []
549     Rates[name]["ps"] = []
550     Rates[name]["inst_lumi"] = []
551     Rates[name]["live_lumi"] = []
552     Rates[name]["delivered_lumi"] = []
553     Rates[name]["deadtime"] = []
554     Rates[name]["rawrate"] = []
555     Rates[name]["rate"] = []
556     Rates[name]["rawxsec"] = []
557     Rates[name]["xsec"] = []
558 abrinke1 1.2 Rates[name]["physics"] = []
559     Rates[name]["active"] = []
560 abrinke1 1.5 Rates[name]["psi"] = []
561 grchrist 1.9
562    
563 abrinke1 1.1 [avps, ps, rate, psrate] = TriggerRates[key]
564     Rates[name]["run"].append(RefRunNum)
565     Rates[name]["ls"].append(nls)
566     Rates[name]["ps"].append(ps)
567     Rates[name]["inst_lumi"].append(inst)
568     Rates[name]["live_lumi"].append(live)
569     Rates[name]["delivered_lumi"].append(delivered)
570 grchrist 1.17 Rates[name]["deadtime"].append(deadtimebeamactive)
571 abrinke1 1.1 Rates[name]["rawrate"].append(rate)
572 abrinke1 1.2 if live == 0:
573 abrinke1 1.5 Rates[name]["rate"].append(0)
574 abrinke1 1.2 Rates[name]["rawxsec"].append(0.0)
575     Rates[name]["xsec"].append(0.0)
576     else:
577 awoodard 1.51 Rates[name]["rate"].append(psrate)
578     #AW Rates[name]["rate"].append(psrate/(1.0-deadtimebeamactive))
579 abrinke1 1.2 Rates[name]["rawxsec"].append(rate/live)
580     Rates[name]["xsec"].append(psrate/live)
581     Rates[name]["physics"].append(physics)
582     Rates[name]["active"].append(active)
583 abrinke1 1.5 Rates[name]["psi"].append(psi)
584 awoodard 1.47
585 grchrist 1.9
586 grchrist 1.10 #for keys, values in MoreLumiMulti.iteritems():
587     # Rates[name][keys].append(values)
588 grchrist 1.9 #print nls, name, keys, values
589 awoodard 1.47
590 grchrist 1.10 RateOutput = open(RefRunFile, 'wb') ##Save new Rates[] to RefRuns
591     pickle.dump(Rates, RateOutput, 2)
592     RateOutput.close()
593     LumiOutput = open(RefLumiFile,'wb')
594     pickle.dump(LumiPageInfo,LumiOutput, 2)
595     LumiOutput.close()
596    
597    
598     return [Rates,LumiPageInfo]
599 abrinke1 1.1
600 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):
601 abrinke1 1.1 min_run = min(run_list)
602     max_run = max(run_list)
603 muell149 1.46
604     priot.has_been_called=False
605 grchrist 1.11
606 abrinke1 1.5 InputFit = {}
607     OutputFit = {}
608 grchrist 1.14 first_trigger=True
609 abrinke1 1.1
610 grchrist 1.37
611     [[varX, varY, do_fit, save_root, save_png, fit_file]] = plot_properties
612    
613     RootNameTemplate = "%s_%sLS_%s_vs_%s_Run%s-%s.root"
614     RootFile = RootNameTemplate % (trig_name, num_ls, varX, varY, min_run, max_run)
615 abrinke1 1.1
616 amott 1.20 if not do_fit:
617     try:
618 abrinke1 1.1 pkl_file = open(fit_file, 'rb')
619 abrinke1 1.5 InputFit = pickle.load(pkl_file)
620 grchrist 1.40
621 amott 1.20 except:
622     print "ERROR: could not open fit file: %s" % (fit_file,)
623     if save_root:
624     try:
625     os.remove(RootFile)
626     except:
627     pass
628    
629 grchrist 1.38 trig_list_noV=[]
630     for trigs in trig_list:
631     trig_list_noV.append(StripVersion(trigs))
632     if NoVersion:
633     trig_list=trig_list_noV
634 grchrist 1.40
635 amott 1.20 ## check that all the triggers we ask to plot are in the input fit
636     if not save_fits:
637     goodtrig_list = []
638 grchrist 1.40 FitInputNoV={}
639 amott 1.20 for trig in trig_list:
640 grchrist 1.40
641     if NoVersion:
642     for trigger in InputFit.iterkeys():
643     FitInputNoV[StripVersion(trigger)]=InputFit[trigger]
644     InputFit=FitInputNoV
645    
646    
647    
648 amott 1.20 else:
649 grchrist 1.40 if not InputFit.has_key(trig):
650     print "WARNING: No Fit Prediction for Trigger %s, SKIPPING" % (trig,)
651     else:
652     goodtrig_list.append(trig)
653     trig_list = goodtrig_list
654 amott 1.18
655 grchrist 1.38
656 grchrist 1.34
657 grchrist 1.26 for print_trigger in sorted(Rates):
658 abrinke1 1.7 ##Limits Rates[] to runs in run_list
659     NewTrigger = {}
660 grchrist 1.34
661 grchrist 1.8 if not print_trigger in trig_list:
662 awoodard 1.50 if all_triggers:
663     trig_list.append(print_trigger)
664     else:
665     print "not in trig_list:",print_trigger, trig_list
666     continue
667 grchrist 1.34
668 abrinke1 1.7 for key in Rates[print_trigger]:
669     NewTrigger[key] = []
670     for iterator in range (len(Rates[print_trigger]["run"])):
671     if Rates[print_trigger]["run"][iterator] in run_list:
672     for key in Rates[print_trigger]:
673     NewTrigger[key].append(Rates[print_trigger][key][iterator])
674     Rates[print_trigger] = NewTrigger
675    
676 grchrist 1.34
677 abrinke1 1.1 meanrawrate = sum(Rates[print_trigger]["rawrate"])/len(Rates[print_trigger]["rawrate"])
678 grchrist 1.40
679 abrinke1 1.1 if not trig_name in print_trigger:
680 grchrist 1.40 print "failed",trig_name, print_trigger
681 abrinke1 1.1 continue
682 grchrist 1.40
683 abrinke1 1.1 if meanrawrate < min_rate:
684     continue
685     masked_trig = False
686     for mask in masked_triggers:
687     if str(mask) in print_trigger:
688     masked_trig = True
689     if masked_trig:
690     continue
691 grchrist 1.34
692 abrinke1 1.5 OutputFit[print_trigger] = {}
693 abrinke1 1.1
694     lowlumi = 0
695 abrinke1 1.7 meanlumi_init = median(Rates[print_trigger]["live_lumi"])
696 abrinke1 1.1 meanlumi = 0
697     highlumi = 0
698     lowxsec = 0
699     meanxsec = 0
700     highxsec = 0
701     nlow = 0
702     nhigh = 0
703 grchrist 1.15
704 abrinke1 1.1 for iterator in range(len(Rates[print_trigger]["rate"])):
705     if Rates[print_trigger]["live_lumi"][iterator] <= meanlumi_init:
706 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):
707 abrinke1 1.1 meanxsec+=Rates[print_trigger]["xsec"][iterator]
708     lowxsec+=Rates[print_trigger]["xsec"][iterator]
709     meanlumi+=Rates[print_trigger]["live_lumi"][iterator]
710     lowlumi+=Rates[print_trigger]["live_lumi"][iterator]
711     nlow+=1
712     if Rates[print_trigger]["live_lumi"][iterator] > meanlumi_init:
713 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):
714 abrinke1 1.1 meanxsec+=Rates[print_trigger]["xsec"][iterator]
715     highxsec+=Rates[print_trigger]["xsec"][iterator]
716     meanlumi+=Rates[print_trigger]["live_lumi"][iterator]
717     highlumi+=Rates[print_trigger]["live_lumi"][iterator]
718     nhigh+=1
719 abrinke1 1.7 try:
720     meanxsec = meanxsec/(nlow+nhigh)
721     meanlumi = meanlumi/(nlow+nhigh)
722     slopexsec = ( (highxsec/nhigh) - (lowxsec/nlow) ) / ( (highlumi/nhigh) - (lowlumi/nlow) )
723     except:
724 grchrist 1.40 #print str(print_trigger)+" has no good datapoints - setting initial xsec slope estimate to 0"
725 abrinke1 1.7 meanxsec = median(Rates[print_trigger]["xsec"])
726     meanlumi = median(Rates[print_trigger]["live_lumi"])
727     slopexsec = 0
728 abrinke1 1.1
729 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()
730    
731 amott 1.20 if not do_fit:
732 grchrist 1.40
733 abrinke1 1.5 FitType = InputFit[print_trigger][0]
734     X0 = InputFit[print_trigger][1]
735     X1 = InputFit[print_trigger][2]
736     X2 = InputFit[print_trigger][3]
737     X3 = InputFit[print_trigger][4]
738 awoodard 1.48 sigma = InputFit[print_trigger][5]*3#Display 3 sigma band to show outliers more clearly
739 grchrist 1.38 X0err= InputFit[print_trigger][7]
740 grchrist 1.40 ##print print_trigger," X0err=",X0err
741 grchrist 1.14 #print str(print_trigger)+" "+str(FitType)+" "+str(X0)+" "+str(X1)+" "+str(X2)+" "+str(X3)
742 amott 1.20 #if (first_trigger):
743     # print '%20s % 10s % 6s % 5s % 5s % 3s % 4s' % ('trigger', 'fit type ', 'cubic', 'quad', ' linear', ' c ', 'Chi2')
744     # first_trigger=False
745     #print '%20s % 10s % 2.2g % 2.2g % 2.2g % 2.2g % 2.2g' % (print_trigger, FitType, X3, X2, X1, X0, Chi2)
746 grchrist 1.14 #print '{}, {}, {:02.2g}, {:02.2g}, {:02.2g}, {:02.2g} '.format(print_trigger, FitType, X0, X1, X2, X3)
747 grchrist 1.8 ## we are 2 lumis off when we start! -gets worse when we skip lumis
748 grchrist 1.17 it_offset=0
749 abrinke1 1.1 for iterator in range(len(Rates[print_trigger]["rate"])):
750     if not Rates[print_trigger]["run"][iterator] in run_list:
751     continue
752     prediction = meanxsec + slopexsec * (Rates[print_trigger]["live_lumi"][iterator] - meanlumi)
753     realvalue = Rates[print_trigger]["xsec"][iterator]
754 grchrist 1.8
755 grchrist 1.11
756     if pass_cuts(data_clean, realvalue, prediction, meanxsec, Rates, print_trigger, iterator, num_ls,LumiPageInfo,SubSystemOff,max_dt,print_info, trig_list):
757 grchrist 1.40
758 abrinke1 1.1 run_t.append(Rates[print_trigger]["run"][iterator])
759     ls_t.append(Rates[print_trigger]["ls"][iterator])
760     ps_t.append(Rates[print_trigger]["ps"][iterator])
761     inst_t.append(Rates[print_trigger]["inst_lumi"][iterator])
762 grchrist 1.17 live_t.append(Rates[print_trigger]["live_lumi"][iterator])
763     delivered_t.append(Rates[print_trigger]["delivered_lumi"][iterator])
764     deadtime_t.append(Rates[print_trigger]["deadtime"][iterator])
765 abrinke1 1.1 rawrate_t.append(Rates[print_trigger]["rawrate"][iterator])
766     rate_t.append(Rates[print_trigger]["rate"][iterator])
767     rawxsec_t.append(Rates[print_trigger]["rawxsec"][iterator])
768     xsec_t.append(Rates[print_trigger]["xsec"][iterator])
769 abrinke1 1.5 psi_t.append(Rates[print_trigger]["psi"][iterator])
770 abrinke1 1.1
771     e_run_t.append(0.0)
772     e_ls_t.append(0.0)
773     e_ps_t.append(0.0)
774     e_inst_t.append(14.14)
775     e_live_t.append(14.14)
776     e_delivered_t.append(14.14)
777 abrinke1 1.2 e_deadtime_t.append(0.01)
778 abrinke1 1.1 e_rawrate_t.append(math.sqrt(Rates[print_trigger]["rawrate"][iterator]/(num_ls*23.3)))
779     e_rate_t.append(Rates[print_trigger]["ps"][iterator]*math.sqrt(Rates[print_trigger]["rawrate"][iterator]/(num_ls*23.3)))
780 abrinke1 1.5 e_psi_t.append(0.0)
781 abrinke1 1.2 if live_t[-1] == 0:
782     e_rawxsec_t.append(0)
783     e_xsec_t.append(0)
784     else:
785 grchrist 1.16 try:
786     e_rawxsec_t.append(math.sqrt(Rates[print_trigger]["rawrate"][iterator]/(num_ls*23.3))/Rates[print_trigger]["live_lumi"][iterator])
787     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])
788     except:
789     e_rawxsec_t.append(0.)
790     e_xsec_t.append(0.)
791 amott 1.20 if not do_fit:
792 grchrist 1.38 if not do_inst:
793     if FitType == "expo":
794 grchrist 1.43 rate_prediction = X0 + X1*math.exp(X2+X3*delivered_t[-1])
795 grchrist 1.38 else:
796     rate_prediction = X0 + X1*delivered_t[-1] + X2*delivered_t[-1]*delivered_t[-1] + X3*delivered_t[-1]*delivered_t[-1]*delivered_t[-1]
797 abrinke1 1.5 ## if rate_t[-1] < 0.7 * rate_prediction or rate_t[-1] > 1.4 * rate_prediction:
798     ## 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])
799 grchrist 1.38 else:
800     if FitType == "expo":
801 grchrist 1.43 rate_prediction = X0 + X1*math.exp(X2+X3*inst_t[-1])
802 grchrist 1.38 else:
803     rate_prediction = X0 + X1*inst_t[-1] + X2*inst_t[-1]*inst_t[-1] + X3*inst_t[-1]*inst_t[-1]*inst_t[-1]
804 abrinke1 1.5
805 abrinke1 1.2 if live_t[-1] == 0:
806 abrinke1 1.5 rawrate_fit_t.append(0)
807     rate_fit_t.append(0)
808 abrinke1 1.2 rawxsec_fit_t.append(0)
809     xsec_fit_t.append(0)
810 abrinke1 1.7 e_rawrate_fit_t.append(0)
811 awoodard 1.45 e_rate_fit_t.append(sigma)
812 abrinke1 1.7 e_rawxsec_fit_t.append(0)
813     e_xsec_fit_t.append(0)
814 grchrist 1.11 #print "live_t=0", ls_t[-1], rawrate_fit_t[-1]
815 abrinke1 1.2 else:
816 grchrist 1.11 if ps_t[-1]>0.0:
817     rawrate_fit_t.append(rate_prediction*(1.0-deadtime_t[-1])/(ps_t[-1]))
818     else:
819     rawrate_fit_t.append(0.0)
820    
821 awoodard 1.51 rate_fit_t.append(rate_prediction*(1.0-deadtime_t[-1]))
822     #AW 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()