ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/DatabaseRatePredictor.py
Revision: 1.41
Committed: Tue May 29 09:35:54 2012 UTC (12 years, 11 months ago) by grchrist
Content type: text/x-python
Branch: MAIN
Changes since 1.40: +39 -40 lines
Log Message:
latest predictions and new forbidden columns

File Contents

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