ATLAS Offline Software
bin/beamspotnt.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
4 
5 from __future__ import print_function
6 
7 """
8 beamspotnt is a command line utility for beam spot ntuples.
9 """
10 __author__ = 'Juerg Beringer'
11 __version__ = 'beamspotnt.py atlas/athena'
12 __usage__ = '''%prog [options] command [args ...]
13 
14 Commands are:
15 
16 dump Dump contents of a beam spot ntuple
17 maketable Make LaTeX table of selected entries
18 inspect Inspect ntuple and provide summary of contents
19 merge SRCNT Merge source beam spot ntuple into master ntuple
20  (use --srcnt to specify type if not BeamSpotFinderNt)
21 ave Calculate average of beam spot parameters
22 hist var Histogram of var
23 histvspileup var Profile histogram of var vs pileup
24 pull var:value Pull of var with respect to true value
25 plot var History of var
26 summary Summary history plots
27 ascii filename Write ASCII file with data in Massi\'s format
28 
29 Examples:
30 
31 beamspotnt -t BeamSpotCOOL -f IndetBeampos-ES1-UPD2 --ru 165815 --rl 165815 dump
32 '''
33 
34 #periodDef = '/afs/cern.ch/atlas/www/GROUPS/DATAPREPARATION/DataPeriods'
35 periodDef = '/afs/cern.ch/user/a/atlidbs/nt/DataPeriods'
36 
37 import sys, os, time, glob, re, copy, math
38 
39 # Create a properly quoted string of the command line to save
40 qargv = [ ]
41 for s in sys.argv:
42  if re.search('\s|\*|\?',s): # any white space or special characters in word so we need quoting?
43  if "'" in s:
44  qargv.append('"%s"' % re.sub('"',"'",s))
45  else:
46  qargv.append("'%s'" % re.sub("'",'"',s))
47  else:
48  qargv.append(s)
49 qcmd = ' '.join(qargv)
50 
51 from optparse import OptionParser
52 parser = OptionParser(usage=__usage__, version=__version__)
53 parser.add_option('-f', '--nt', dest='ntname', default='beamspotnt.root', help='master ntuple file name or COOL tag (default: beamspotnt.root)')
54 parser.add_option('-t', '--type', dest='type', default='BeamSpotNt', help='master ntuple type (default: BeamSpotNt)')
55 parser.add_option('-s', '--srctype', dest='srctype', default='BeamSpotNt', help='source ntuple type for merging (default: BeamSpotNt)')
56 parser.add_option('-v', '--verbose', dest='verbose', action='store_true', default=False, help='verbose output')
57 parser.add_option('-d', '--debug', dest='debug', action='store_true', default=False, help='debug output')
58 parser.add_option('-q', '--quiet', dest='quiet', action='store_true', default=False, help='reduce output')
59 parser.add_option('-r', '--run', dest='run', type='int', default=None, help='run number (single run)')
60 parser.add_option('', '--rl', dest='runMin', type='int', default=None, help='minimum run number (inclusive)')
61 parser.add_option('', '--ru', dest='runMax', type='int', default=None, help='maximum run number (inclusive)')
62 parser.add_option('', '--re', dest='runExclude', default=None, help='comma seperated list of runs to exclude')
63 parser.add_option('', '--fill', dest='fill', type='int', default=None, help='fill number (single fill)')
64 parser.add_option('', '--fl', dest='fillMin', type='int', default=None, help='minimum fill number (inclusive)')
65 parser.add_option('', '--fu', dest='fillMax', type='int', default=None, help='maximum fill number (inclusive)')
66 parser.add_option('', '--bcid', dest='bcid', type='int', default=None, help='BCID number (single BCID)')
67 parser.add_option('', '--bcl', dest='bcidMin', type='int', default=None, help='minimum BCID number (inclusive)')
68 parser.add_option('', '--bcu', dest='bcidMax', type='int', default=None, help='maximum BCID number (inclusive)')
69 parser.add_option('', '--lbl', dest='lbMin', type='int', default=None, help='minimum LB number (inclusive)')
70 parser.add_option('', '--lbu', dest='lbMax', type='int', default=None, help='maximum LB number (inclusive)')
71 parser.add_option('', '--tl', dest='timeMin', default=None, help='minimum start time')
72 parser.add_option('', '--tu', dest='timeMax', default=None, help='maximum end time')
73 parser.add_option('', '--status', dest='status', default='59', help='comma-separated list of accepted fit status values (default: 59)')
74 parser.add_option('', '--energy', dest='energy', default='13', help='center-of-mass energy')
75 parser.add_option('-p', '--period', dest='period', default=None, help='comma-separated list of accepted run periods (e.g. data10_7TeV.G)')
76 parser.add_option('', '--perioddef', dest='periodDef', default=periodDef, help='location of run period definition files (default: %s)' % periodDef)
77 parser.add_option('-g', '--grl', dest='grl', default=None, help='GRL to select runs/Lbs')
78 parser.add_option('', '--mc', dest='mc', action='store_true', default=False, help='flag to indicate beam spot results are from MC')
79 parser.add_option('', '--fillCOOL', dest='fillcooldata', action='store_true', default=False, help='fill data from COOL (time, fill#)')
80 parser.add_option('', '--fillDQ', dest='filldqdata', action='store_true', default=False, help='fill data from DataQualtiy')
81 parser.add_option('', '--pLbFile', dest='pseudoLbFile', default=None, help='File for pseudo LB info from scan')
82 parser.add_option('', '--pLbTimeUnit', dest='pseudoLbTimeUnit', default=1., help='Time unit for pseudo LB relative to seconds, e.g. 1e-9 for ns')
83 parser.add_option('', '--tz', dest='timezone', default='CET', help='time zone to use for time represenation (default: CERN local time)')
84 parser.add_option('', '--simpleaverage', dest='simpleaverage', action='store_true', default=False, help='use simple instead of weighted average (for checks only)')
85 parser.add_option('', '--lumicalcnt', dest='lumicalcnt', default=None, help='ave: use luminosity ntuple (from iLumiCalc.exe) for weighted average')
86 parser.add_option('', '--latex', dest='latex', action='store_true', default=False, help='output results in LaTeX')
87 parser.add_option('', '--splittable', dest='splittable', type='int', default=None, help='latex: split table, put first n cols into first table')
88 parser.add_option('', '--hist', dest='hist', action='store_true', default=False, help='ave: produce validation histograms')
89 parser.add_option('', '--summary', dest='summary', action='store_true', default=False, help='ave: produce validation summary plots')
90 parser.add_option('', '--rms', dest='rms', action='store_true', default=False, help='Use RMS instead of error on mean')
91 parser.add_option('', '--varlist', dest='varlist', default=None, help='list of beam spot variables used by ave')
92 parser.add_option('-n', '--nbins', dest='nbins', type='int', default=None, help='number of bins')
93 parser.add_option('', '--xmin', dest='xmin', default=None, help='x axis minimum')
94 parser.add_option('', '--xmax', dest='xmax', default=None, help='x axis maximum')
95 parser.add_option('', '--timeaxis', dest='timeaxis', action='store_true', default=False, help='use time on x axis instead of run or LB numbers')
96 parser.add_option('', '--talabel', dest='talabel', default=None, help='time axis label (default: Time (timezone))')
97 parser.add_option('', '--perbcid', dest='perbcid', action='store_true', default=False, help='plot per BCID instead of vs time/LB')
98 parser.add_option('', '--separation', dest='separation', action='store_true', default=False, help='plot versus beam separation for scans')
99 parser.add_option('', '--vsbunchpos', dest='vsbunchpos', action='store_true', default=False, help='plot versus bunch position in train')
100 parser.add_option('', '--ndivs', dest='ndivs', type='int', default=None, help='Number of x axis divisions (ROOT format)')
101 parser.add_option('', '--ymin', dest='ymin', type='float', default=None, help='y axis minimum')
102 parser.add_option('', '--ymax', dest='ymax', type='float', default=None, help='y axis maximum')
103 parser.add_option('-y', '--yscale', dest='yscale', type='float', default=1.0, help='y axis scale factor')
104 parser.add_option('-m', '--msize', dest='msize', type='float', default=None, help='set marker size')
105 parser.add_option('', '--lsize', dest='lsize', type='float', default=None, help='set axis label size')
106 parser.add_option('', '--ydef', dest='ydef', action='store_true', default=False, help='use default y range for given quantity')
107 parser.add_option('', '--defaults', dest='defaults', default='Gen', help='choose varDef defauls (default: Gen')
108 parser.add_option('', '--logy', dest='logy', action='store_true', default=False, help='log scale')
109 parser.add_option('', '--fit', dest='fit', default='', help='fit function (e.g. pol1)')
110 parser.add_option('', '--optfit', dest='optfit', default='', help="fit options (default: '')")
111 parser.add_option('-c', '--canvas', dest='canvas', default='', help='canvas size: default, page, wide, extrawide or square')
112 parser.add_option('', '--xdivs', dest='xdivs', type='int', default=1, help='number of pads on canvas in x (needs -c, default: 1)')
113 parser.add_option('', '--ydivs', dest='ydivs', type='int', default=1, help='number of pads on canvas in y (needs -c, default: 1)')
114 parser.add_option('', '--optstat', dest='optstat', default='emruo', help='default OptStat value (Default: emruo)')
115 parser.add_option('', '--ave', dest='ave', action='store_true', default=False, help='show average on plot')
116 parser.add_option('', '--newave', dest='newave', action='store_true', default=False, help='replicate the functionality of the old aveBeamSpot.py script.')
117 parser.add_option('', '--title', dest='title', default='', help='title text on plots')
118 parser.add_option('', '--comment', dest='comment', default='', help='additional text (use semicolon to indicate line breaks)')
119 parser.add_option('', '--datefmt', dest='datefmt', default='', help='date format')
120 parser.add_option('', '--adatefmt', dest='adatefmt', default='', help='axis date format')
121 parser.add_option('', '--plegend', dest='plegend', default='fit to groups of LBs', help='legend text for points')
122 parser.add_option('', '--alegend', dest='alegend', default='average of data shown:', help='legend text for average')
123 parser.add_option('', '--maxlegends', dest='maxlegends', type='int', default=10, help='maximum number of legend entries')
124 parser.add_option('', '--omitfill', dest='omitfill', action='store_true', default=False, help='remove any fill info from legend')
125 parser.add_option('', '--omitrun', dest='omitrun', action='store_true', default=False, help='remove any run info from legend')
126 parser.add_option('', '--omittime', dest='omittime', action='store_true', default=False, help='remove any time info from legend')
127 parser.add_option('', '--public', dest='public', action='store_true', default=False, help='use labelling for public plots')
128 parser.add_option('', '--prelim', dest='prelim', action='store_true', default=False, help='add ATLAS Preliminary to figure')
129 parser.add_option('', '--approval', dest='approval', action='store_true', default=False, help='Label figure ATLAS for approval')
130 parser.add_option('', '--published', dest='published', action='store_true', default=False, help='add ATLAS to figure')
131 parser.add_option('', '--customlabel', dest='customlabel', default='', help='add custom label after ATLAS to figure')
132 parser.add_option('', '--xtitoffset', dest='xtitoffset', type='float', default=None, help='x axis title offset')
133 parser.add_option('', '--ytitoffset', dest='ytitoffset', type='float', default=None, help='y axis title offset')
134 parser.add_option('', '--atlasx', dest='atlasx', type='float', default=None, help='x position for drawing ATLAS (Preliminary) label')
135 parser.add_option('', '--atlasy', dest='atlasy', type='float', default=None, help='y position for drawing ATLAS (Preliminary) label')
136 parser.add_option('', '--atlasdx', dest='atlasdx', type='float', default=None, help='x position offset for drawing Preliminary label')
137 parser.add_option('-o', '--output', dest='output', default='.gif', help='comma-separated list of output files or formats (default: .gif)')
138 parser.add_option('', '--name', dest='name', default='BeamSpotNtPlots', help='base name for plots (default: BeamSpotNtPlots)')
139 parser.add_option('', '--tgraphfile', dest='tgraphfile', default='', help='optional root file to save TGraph into')
140 parser.add_option('', '--tag', dest='cooltag', default='', help='COOL tag for writing average into beam spot SQLite file (also determines file name)')
141 parser.add_option('-i', '--interactive', dest='interactive', action='store_true', default=False, help='interactive')
142 parser.add_option('-b', '--batch', dest='batch', action='store_true', default=False, help='run in batch mode')
143 parser.add_option('', '--fullCorrelations', dest='fullCorrelations', action='store_true', default=False, help='Get all correlations')
144 parser.add_option('', '--scans', dest='scans', default='', help='comma-separated list of hypenated lb ranges for lumi scans')
145 parser.add_option('', '--acqFlag', dest='acqFlag', default = False, action='store_true', help='Cut on AcquistionFlag=1.0 for stationary points of VdM scan')
146 parser.add_option('', '--overlayScans', dest='overlayScans', default = False, action='store_true', help='overlay VdM scans on same plot')
147 parser.add_option('', '--useAve', dest='useAve', action='store_true', default=False, help='Average over poor fits in the beamspot -- performed during merging step')
148 parser.add_option('', '--database', dest='database', default='COOLOFL_INDET/CONDBR2', help='DB to read beamspot info from when -s BeamSpotCOOL is enabled and running merge')
149 parser.add_option('', '--dbfolder', dest='dbfolder', default='/Indet/Beampos', help='Folder to read beamspot info from when -s BeamSpotCOOL is enabled and running merge')
150 parser.add_option('', '--addScanVars', dest='addScanVars', action='store_true', default=False, help='Add variables for VdM scan')
151 
152 (options,args) = parser.parse_args()
153 if len(args) < 1:
154  parser.error('wrong number of command line arguments')
155 cmd = args[0]
156 
157 if options.fillcooldata and options.pseudoLbFile:
158  sys.exit('Options fillColl and pseudoLbFile are mutually exclusive')
159 
160 # Reset DISPLAY if in batch
161 if options.batch:
162  os.unsetenv('DISPLAY')
163 
164 # Place after OptionParse to avoid conflict with ROOT option parsing
165 import ROOT
166 import InDetBeamSpotExample
167 
168 # Get BeamSpotData class and choose beam spot variable defaults
169 from InDetBeamSpotExample import BeamSpotData
170 if options.defaults:
171  BeamSpotData.varDefs = getattr(BeamSpotData,'varDefs'+options.defaults)
173 
174 #from InDetBeamSpotExample.COOLUtils import *
175 from InDetBeamSpotExample.Utils import getUserName, getHostName
176 from InDetBeamSpotExample import ROOTUtils
178 from math import *
179 
180 cmdOk = False
181 if options.interactive:
182  os.environ['PYTHONINSPECT'] = '1'
183 
184 if options.timezone:
185  os.environ['TZ'] = options.timezone
186  time.tzset()
187  timeLabel = 'Time (%s)' % options.timezone
188 else:
189  timeLabel = 'Local time'
190 if options.talabel:
191  timeLabel = options.talabel
192 
193 if not options.datefmt:
194  if options.public:
195  options.datefmt = '%b %Y'
196  else:
197  options.datefmt = '%a %b %d'
198 
199 # Graphics defaults
200 if options.atlasx==None:
201  if options.published:
202  options.atlasx = 0.83 if 'wide' in options.canvas else 0.8
203  else:
204  options.atlasx = 0.72 if 'wide' in options.canvas else 0.645
205 if options.atlasy==None:
206  if options.public:
207  options.atlasy = 0.86
208 if options.atlasdx==None:
209  options.atlasdx = 0.08 if 'wide' in options.canvas else 0.115
210 
211 ntClass = locals()[options.type]
212 
213 def setCuts(nt):
214  if options.run!=None:
215  nt.runMin = options.run
216  nt.runMax = options.run
217  if options.runMin!=None:
218  nt.runMin = options.runMin
219  if options.runMax!=None:
220  nt.runMax = options.runMax
221  if options.runExclude!=None:
222  nt.runListExclude = [int(r) for r in options.runExclude.split(',')]
223  if options.fill!=None:
224  nt.fillMin = options.fill
225  nt.fillMax = options.fill
226  if options.fillMin!=None:
227  nt.fillMin = options.fillMin
228  if options.fillMax!=None:
229  nt.fillMax = options.fillMax
230  if options.bcid!=None:
231  nt.bcidMin = options.bcid
232  nt.bcidMax = options.bcid
233  if options.bcidMin!=None:
234  nt.bcidMin = options.bcidMin
235  if options.bcidMax!=None:
236  nt.bcidMax = options.bcidMax
237  if options.lbMin!=None:
238  nt.lbMin = options.lbMin
239  if options.lbMax!=None:
240  nt.lbMax = options.lbMax
241  if options.timeMin!=None:
242  nt.timeMin = time.mktime(time.strptime(options.timeMin,'%b %d %H:%M:%S %Y'))
243  if options.timeMax!=None:
244  nt.timeMax = time.mktime(time.strptime(options.timeMax,'%b %d %H:%M:%S %Y'))
245  if options.status:
246  nt.statusList = [int(x) for x in options.status.split(',')]
247  if options.period:
248  for p in options.period.split(','):
249  project,period = p.split('.')
250  location = os.path.normpath(options.periodDef + '/' + project)
251  try:
252  fileName = glob.glob('%s/%s.runs.list' % (location,period))[0]
253  nt.runList.extend([int(r) for r in open(fileName).read().split()])
254  except:
255  sys.exit('ERROR: Definition file for period %s not found in directory %s' % (options.period, location))
256 
257  if not nt.runList:
258  sys.exit('ERROR: no runs found for requested periods')
259 
260  if options.grl:
261  nt.grl = options.grl
262 
263  if options.acqFlag:
264  nt.acqFlag = 1.0
265 
266 def getNt():
267  try:
268  if options.fullCorrelations:
269  nt = ntClass(options.ntname,fullCorrelations=True)
270  else:
271  nt = ntClass(options.ntname)
272  except Exception as e:
273  sys.exit('ERROR: '+str(e))
274 
275  setCuts(nt)
276  print (nt.summary())
277  print (nt.cutSummary())
278  return nt
279 
280 def cleanUpLowStat( allBSResultsInNt, averagenVtx, lbSize ):
281  i=0
282  while i < len( allBSResultsInNt ):
283  b = allBSResultsInNt[i]
284  if b.status < 70 and b.sigmaZErr == 0:
285  print ("Will change Z error for lb's " + str(b.lbStart) +" to " + str(b.lbEnd) + " which has " + str(b.nValid) + " verticies")
286  b.sigmaZErr = b.sigmaZ * 0.5
287  i += 1
288 
289  i=0
290  while i < len( allBSResultsInNt ):
291  b = allBSResultsInNt[i]
292 
293  if b.status < 70 and b.nValid < 2000 and b.nValid < averagenVtx:
294  print ("Will take an average for lb's " + str(b.lbStart) +" to " + str(b.lbEnd) + " which has " + str(b.nValid) + " verticies" )
295  lastGoodEntry = b
296  nextGoodEntry = b
297  iNeg = i-1;
298  # Find previous good entry
299  while iNeg >= 0:
300  if allBSResultsInNt[iNeg].status == 59 and allBSResultsInNt[iNeg].nValid > 2000 :
301  lastGoodEntry = allBSResultsInNt[iNeg]
302  print (" --- Starting with lb : " + str(lastGoodEntry.lbStart) +" to " + str(lastGoodEntry.lbEnd))
303  break
304  iNeg -= 1
305 
306  # Find the next good entry
307  iPos = i+1;
308  while iPos < len(allBSResultsInNt):
309  if allBSResultsInNt[iPos].status == 59 and allBSResultsInNt[iPos].nValid > 2000:
310  nextGoodEntry = allBSResultsInNt[iPos]
311  print (" --- Ending with lb : " + str(nextGoodEntry.lbStart) +" to " + str(nextGoodEntry.lbEnd))
312  break
313  iPos += 1
314 
315  #if all entries are useless then we are in trouble dont do anything
316  if lastGoodEntry == b and nextGoodEntry == b :
317  print ("Failed to do average - no good entries were found")
318  i+=1
319  continue
320 
321  #check the entries are reasonablly close to each other
322  if( ( nextGoodEntry == b or abs(nextGoodEntry.lbStart - b.lbEnd) > abs(lbSize) ) and (lastGoodEntry == b or abs(b.lbStart - lastGoodEntry.lbEnd) > abs(lbSize) ) ):
323  print ("Failed to do average - entries were too far away")
324  i+=1
325  continue
326 
327  #Calculate the average beamspot position for the following parameters
328  varList = ['posX','posY','posZ','sigmaX','sigmaY','sigmaZ','tiltX','tiltY','rhoXY']
329  if options.cooltag:
330  varList.append('sigmaXY')
331  calc = BeamSpotAverage(varList ,weightedAverage=True)
332  #Add current entry if it is reliable
333  if( b.status == 59 and b.posXErr != 0 and not math.isnan(b.posX) and not math.isnan(b.posZ) and not math.isnan(b.sigmaZ) ):
334  calc.add(b)
335  #Add previous entry if it is not too far away in time
336  if lastGoodEntry != b and abs(b.lbStart - lastGoodEntry.lbEnd) <= abs(lbSize) :
337  calc.add(lastGoodEntry)
338  #Add next entry if it is not too far away in time
339  if nextGoodEntry != b and abs(nextGoodEntry.lbStart - b.lbEnd) <= abs(lbSize) :
340  calc.add(nextGoodEntry)
341  calc.average()
342 
343  ave = calc.ave
344  err = calc.err
345  b.status = 666 #b.status << 4
346  bcopy = copy.deepcopy(b)
347 
348  for var in varList:
349  setattr(bcopy, var, ave[calc.varList.index(var)])
350  setattr(bcopy, var+"Err", err[calc.varList.index(var)])
351 
352  bcopy.status = 59
353  i += 1
354  allBSResultsInNt.insert(i, bcopy)
355  i += 1
356 
357 
358 
359 
360 def fillInMissingLbs(allBSResultsInNt, lbSize):
361  i=0
362  lastValidEntry = -1
363  nextValidEntry = -1
364  while i < len( allBSResultsInNt ):
365  if allBSResultsInNt[i].status != 59:
366  i += 1
367  continue
368 
369  nextValidEntry = i
370 
371  if(lastValidEntry >= 0):
372  if allBSResultsInNt[nextValidEntry].lbStart != allBSResultsInNt[lastValidEntry].lbEnd + 1:
373  print ("Missing Lumi block from {:>5d} to {:>5d}".format( allBSResultsInNt[lastValidEntry].lbEnd + 1 , allBSResultsInNt[nextValidEntry].lbStart))
374 
375 
376  if allBSResultsInNt[nextValidEntry].lbStart - allBSResultsInNt[lastValidEntry].lbEnd + 1 > lbSize:
377  print ("--Lumi block gap too large wont fill in the gap" )
378  elif (allBSResultsInNt[nextValidEntry].lbStart-1) - (allBSResultsInNt[lastValidEntry].lbEnd+1) < 0 :
379  print ("Missing Lumi block is invalid from {:>5d} to {:>5d}".format( allBSResultsInNt[lastValidEntry].lbEnd+1, allBSResultsInNt[nextValidEntry].lbStart -1))
380  else:
381  varList = ['posX','posY','posZ','sigmaX','sigmaY','sigmaZ','tiltX','tiltY','rhoXY']
382  if options.cooltag:
383  varList.append('sigmaXY')
384  calc = BeamSpotAverage(varList ,weightedAverage=True)
385  calc.add(allBSResultsInNt[nextValidEntry])
386  calc.add(allBSResultsInNt[lastValidEntry])
387  calc.average()
388 
389  ave = calc.ave
390  err = calc.err
391 
392  bcopy = copy.deepcopy(b)
393 
394  for var in varList:
395  setattr(bcopy, var, ave[calc.varList.index(var)])
396  setattr(bcopy, var+"Err", err[calc.varList.index(var)])
397 
398  bcopy.status = 59
399  bcopy.timeStart = 0
400  bcopy.timeEnd = 0
401  bcopy.nEvents = 1
402  bcopy.nValid = 1
403  bcopy.nVtxAll = 1
404  bcopy.nVtxPrim = 1
405  bcopy.lbStart = allBSResultsInNt[lastValidEntry].lbEnd + 1
406  bcopy.lbEnd = allBSResultsInNt[nextValidEntry].lbStart-1
407  allBSResultsInNt.insert(lastValidEntry+1, bcopy)
408  i += 1
409  nextValidEntry += 1
410 
411  lastValidEntry = nextValidEntry
412  i += 1
413 
414 
415 
417 
418  def __init__(self,nt):
419  ROOTUtils.PlotLibrary.__init__(self,options.name)
420  self.nt = nt
421  self.whatList = ['posX','posY','posZ','sigmaX','sigmaY','sigmaZ','tiltX','tiltY','rhoXY','k','nValid']
422 
423  def writeText(self, var, legendList=[],
424  showRuns=True, showFills=True, showTime=True, otherTitle=None, otherComment=None,
425  legendX=0.6):
426  # Title and comment lines with optional run, fill and time/date info
427  if otherTitle!=None:
428  self.protect( ROOTUtils.drawText(0.2,0.86,0.06,otherTitle) )
429  else:
430  title = options.title or varDef(var,'title',var)
431  self.protect( ROOTUtils.drawText(0.2,0.86,0.06,title) )
432  comments = []
433  if otherComment:
434  comments.append(otherComment)
435  if options.comment:
436  comments.append(options.comment)
437  if showRuns and not options.omitrun:
438  if self.nt.selRunMin==self.nt.selRunMax:
439  comments.append('Run %i' % self.nt.selRunMin)
440  else:
441  comments.append('Runs %i - %i' % (self.nt.selRunMin,self.nt.selRunMax))
442  if showFills and not options.omitfill:
443  if self.nt.selFillMin==self.nt.selFillMax:
444  comments.append('Fill %i' % self.nt.selFillMin)
445  else:
446  comments.append('Fills %i - %i' % (self.nt.selFillMin,self.nt.selFillMax))
447  if showTime and not options.omittime:
448  if options.public:
449  t1 = time.strftime(options.datefmt,time.localtime(self.nt.selTimeMin))
450  t2 = time.strftime(options.datefmt,time.localtime(self.nt.selTimeMax))
451  else:
452  t1 = time.strftime(options.datefmt,time.localtime(self.nt.selTimeMin))
453  t2 = time.strftime(options.datefmt,time.localtime(self.nt.selTimeMax))
454  if t1==t2:
455  comments.append(t1)
456  else:
457  comments.append('%s - %s' % (t1,t2))
458 
459  self.protect( ROOTUtils.drawText(0.2,0.79,0.06,';'.join(comments),font=42) )
460  # ATLAS (preliminary) label
461  logoSize = options.lsize if options.lsize else 0.5
462  if options.prelim:
463  ROOTUtils.atlasLabel(options.atlasx,options.atlasy,True,offset=options.atlasdx,energy=options.energy,size=logoSize)
464  if options.approval:
465  ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,isForApproval=True,energy=options.energy,size=logoSize)
466  if options.published:
467  ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,energy=options.energy,size=logoSize)
468  if options.customlabel!="":
469  ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,isForApproval=False,customstring=options.customlabel,energy=options.energy,size=logoSize)
470  # Legend
471  if legendList:
472  legendMinY = max(0.91-0.07*len(legendList),0.2)
473  self.protect( ROOTUtils.drawLegend(legendX,legendMinY,0.92,0.91,legendList) )
474 
475  def hist(self,what):
476  """Histogram of variable what.
477 
478  If what is of the form NAME:VALUE, VALUE will be subtracted
479  from each entry in order to produce plots of measured minus
480  true value."""
481  shift = 0.
482  try:
483  (what,shift) = what.split(':')
484  shift = float(shift)
485  except:
486  pass
487  ROOT.gStyle.SetOptStat(options.optstat) # emruo to add underflow, overflow
488  title = varDef(what,'title',what)+';'+varDef(what,'atit',what)
489  nBins = options.nbins if options.nbins else varDef(what,'nBins',100)
490  xmin = float(options.xmin) if options.xmin!=None else varDef(what,'min',-100)
491  xmax = float(options.xmax) if options.xmax!=None else varDef(what,'max',+100)
492  h = self.protect( ROOT.TH1F(what,title,nBins,xmin,xmax) )
493  if options.fit:
494  h.Sumw2()
495  h.GetYaxis().SetTitle('Number of fit results')
496  arescale = varDef(what,'arescale',1.0)
497  try:
498  for b in nt:
499  h.Fill(arescale*(getattr(b,what)-shift))
500  except Exception as e:
501  print ('ERROR filling histogram:',str(e))
502  h.Draw()
503  if options.fit:
504  ROOT.gStyle.SetOptFit(1111)
505  h.Fit(options.fit,options.optfit)
506  if options.logy:
507  ROOT.gPad.SetLogy(options.logy)
508  ndivs = varDef(what,'ndivs',override=options.ndivs)
509  if ndivs:
510  h.GetXaxis().SetNdivisions(ndivs,0)
511  if options.mc:
512  self.writeText(what,[],False,False,False)
513  else:
514  self.writeText(what,[],not options.public,options.public)
515 
516  def histvspileup(self,what):
517  """Profile histogram of variable what vs pileup.
518 
519  If what is of the form NAME:VALUE, VALUE will be subtracted
520  from each entry in order to produce plots of measured minus
521  true value."""
522  shift = 0.
523  try:
524  (what,shift) = what.split(':')
525  shift = float(shift)
526  except:
527  pass
528  ROOT.gStyle.SetOptStat(options.optstat) # emruo to add underflow, overflow
529  title = varDef(what,'title',what)+';Number of pileup vertices;'+varDef(what,'atit',what)
530  nBins = options.nbins if options.nbins else varDef(what,'nBins',100)
531  xmin = float(options.xmin) if options.xmin!=None else varDef(what,'min',-100)
532  xmax = float(options.xmax) if options.xmax!=None else varDef(what,'max',+100)
533  h = self.protect( ROOT.TProfile(what,title,nBins,0,nBins) )
534  if options.fit:
535  h.Sumw2()
536  h.GetYaxis().SetRangeUser(xmin,xmax)
537  arescale = varDef(what,'arescale',1.0)
538  try:
539  for b in nt:
540  h.Fill(getattr(b,'pileup'),arescale*(getattr(b,what)-shift))
541  except Exception as e:
542  print ('ERROR filling histogram:',str(e))
543  h.Draw()
544  if options.fit:
545  ROOT.gStyle.SetOptFit(1111)
546  h.Fit(options.fit,options.optfit)
547  if options.logy:
548  ROOT.gPad.SetLogy(options.logy)
549  ndivs = varDef(what,'ndivs',override=options.ndivs)
550  if ndivs:
551  h.GetYaxis().SetNdivisions(ndivs,0)
552  if options.mc:
553  self.writeText(what,[],False,False,False)
554  else:
555  self.writeText(what,[],not options.public,options.public)
556 
557  def pull(self,what):
558  """Pull histogram of variable what.
559 
560  what must be of the form name:value, where value is the
561  correct value of variable name."""
562  try:
563  (what,value) = what.split(':')
564  value = float(value)
565  except:
566  print(('ERROR: Illegal input %s for pull variable - must be of the form NAME:VALUE' % what))
567  return
568  ROOT.gStyle.SetOptStat(options.optstat)
569  title = ';Pull'
570  nBins = options.nbins if options.nbins else varDef(what,'nBins',100)
571  xmin = float(options.xmin) if options.xmin!=None else -4.
572  xmax = float(options.xmax) if options.xmax!=None else +4.
573  h = self.protect( ROOT.TH1F(what,title,nBins,xmin,xmax) )
574  if options.fit:
575  h.Sumw2()
576  h.GetYaxis().SetTitle('Number of fit results')
577  whatErr = what+'Err'
578  try:
579  for b in nt:
580  h.Fill((getattr(b,what)-value)/getattr(b,whatErr))
581  except Exception as e:
582  print ('ERROR filling histogram:',str(e))
583  h.Draw()
584  if options.fit:
585  ROOT.gStyle.SetOptFit(1111)
586  h.Fit(options.fit,options.optfit)
587  if options.logy:
588  ROOT.gPad.SetLogy(options.logy)
589  if options.ndivs:
590  h.GetXaxis().SetNdivisions(options.ndivs,0)
591  if options.mc:
592  self.writeText(what,[],False,False,False)
593  else:
594  self.writeText(what,[],not options.public,options.public)
595 
596  def plot(self,what):
597  """History of variable what vs LB or time."""
598  ROOT.gStyle.SetOptStat(0)
599  if options.ave:
600  calc = BeamSpotAverage([what],weightedAverage=not options.simpleaverage)
601  grDict = {}
602 
603  arescale = varDef(what,'arescale',1.0)
604  for b in nt:
605  if b.sigmaX < 0.005 or b.sigmaY < 0.005:
606  print ("OUTLIER ", b.run, b.lbStart, b.lbEnd, b.sigmaX, b.sigmaY)
607  if not b.bcid in grDict:
608  grDict[b.bcid] = BeamSpotGraph(timeAxis=options.timeaxis, separationAxis=options.separation)
609  # What was this for? Why ignore if no time info available?
610  #if b.timeStart>0 and b.timeEnd>0:
611  grDict[b.bcid].add(b,what,arescale)
612  if options.ave:
613  calc.add(b)
614 
615  print ('Plotting data from %i BCID ...\n' % len(grDict))
616 
617  # Determine axis range
618  xmin = 1E10
619  xmax = -1E10
620  ymin = 1E10
621  ymax = -1E10
622  for gr in [grDict.get(bcid) for bcid in grDict]:
623  xmin = min(xmin,gr.xmin)
624  xmax = max(xmax,gr.xmax)
625  ymin = min(ymin,gr.ymin)
626  ymax = max(ymax,gr.ymax)
627 
628  # Prevent xmin>xmax or ymin>ymax if no succesful fits (but still allow user to override)
629  if xmin>xmax:
630  xmin,xmax=0,1
631  if ymin>ymax:
632  ymin,ymax=0,1
633 
634  h = (xmax-xmin)
635  xmax += .05*h if len(grDict)==1 else 0.3*h
636  xmin -= .05*h
637  h = (ymax-ymin)/2*options.yscale
638  ymax += 1.3*h
639  ymin -= 0.5*h
640  if options.xmin!=None:
641  xmin = time.mktime(time.strptime(options.xmin,'%b %d %H:%M:%S %Y')) if options.timeaxis else float(options.xmin)
642  if options.xmax!=None:
643  xmax = time.mktime(time.strptime(options.xmax,'%b %d %H:%M:%S %Y')) if options.timeaxis else float(options.xmax)
644  if options.ydef:
645  ymin = varDef(what,'min',-100)
646  ymax = varDef(what,'max',+100)
647  if options.ymin!=None:
648  ymin = options.ymin
649  if options.ymax!=None:
650  ymax = options.ymax
651 
652  # Axis settings
653  if options.timeaxis:
654  atit = ';%s;%s' % (timeLabel,varDef(what,'atit',what))
655  elif options.separation:
656  atit = ';%s;%s' % ('Nominal Separation [mm]',varDef(what,'atit',what))
657  else:
658  atit = ';%s;%s' % ('Luminosity block number',varDef(what,'atit',what))
659  frame = ROOTUtils.drawAxisFrame(xmin,xmax,ymin,ymax,atit)
660  if options.logy:
661  ROOT.gPad.SetLogy(options.logy)
662  if options.timeaxis:
663  xAxis = frame.GetXaxis()
664  yAxis = frame.GetYaxis()
665  xAxis.SetTimeDisplay(1)
666 
667  # this may or may not be needed depending on the ROOT version... not sure whether to specify it or not.
668  # Setting this option in 5.34 seems to work, in 5.30 it offsets things by an hour, but then not setting it
669  # appears to result in bogus x-axis values.
670  xAxis.SetTimeOffset(0) # FIXME: this ignores options.timezone!
671 
672  if (xmax-xmin)/86400 < 1:
673  xAxis.SetTimeFormat('%H:%M')
674  else:
675  #d0 = ceil(xmin/86400) # day w/first tick mark
676  #d1 = floor(xmax/86400) # day w/last tick mark
677  #nTicks = d1-d0+1
678  #nDays = floor((xmax-xmin)/86400)
679  if options.public:
680  xAxis.SetTimeFormat('%b %d')
681  else:
682  xAxis.SetTimeFormat('#splitline{%b %d}{%H:%M}')
683  xAxis.SetLabelOffset(0.02)
684  xAxis.SetTitleOffset(1.6)
685  if options.lsize:
686  xAxis.SetLabelSize(options.lsize)
687  xAxis.SetTitleSize(options.lsize)
688  yAxis.SetLabelSize(options.lsize)
689  yAxis.SetTitleSize(options.lsize)
690  else:
691  xAxis.SetLabelSize(0.044)
692  if options.adatefmt:
693  xAxis.SetTimeFormat(options.adatefmt)
694  if options.ndivs:
695  xAxis.SetNdivisions(options.ndivs,0)
696  frame.LabelsOption('d','X') # Doesn't seem to work
697 
698  if options.xtitoffset:
699  xAxis.SetTitleOffset(options.xtitoffset)
700  if options.ytitoffset:
701  yAxis.SetTitleOffset(options.ytitoffset)
702 
703  legendList = []
704 
705  # Show average
706  if options.ave:
707  calc.average()
708  dx = (xmax-xmin)/30
709  mean = calc.ave[0]
710  if options.rms:
711  error = calc.rms[0]
712  else:
713  error = calc.err[0]
714  b = ROOTUtils.drawHorizontalBand(xmin+dx,xmax-dx,mean,error,centralLine=True)
715  legendList.append([b,options.alegend,'FL'])
716  legendList.append([None,'%s %s #pm %s %s' % (fmtVal(what,mean,True),varDef(what,'units'),
717  fmtVal(what,error,True),varDef(what,'units')),''])
718 
719  # Loop over graphs for all BCIDs
720  styleFactory = ROOTUtils.StyleFactory()
721  for bcid in sorted(grDict.keys()):
722  gr = grDict[bcid]
723 
724  # Get and save TGraphErrors, if desired
725  name = what if bcid==0 else '%s-bcid%04i' % (what,bcid)
726  tgraph = self.protect( gr.getTGraph(name) )
727  if not tgraph:
728  continue
729  if options.tgraphfile:
730  print ('Saving TGraphErrors',tgraph.GetName(),'to file',options.tgraphfile)
731  tgraphfile = ROOT.TFile(options.tgraphfile,'UPDATE')
732  tgraph.Write()
733  tgraphfile.Close()
734 
735  # Draw data points
736  if len(grDict)==1:
737  tgraph.SetMarkerSize(options.msize if options.msize else 0.8)
738  if options.plegend:
739  legendList.append([tgraph,options.plegend,'PLE'])
740  else:
741  tgraph.SetMarkerColor(styleFactory.nextColorStyle())
742  tgraph.SetMarkerStyle(styleFactory.nextMarkerStyle())
743  tgraph.SetMarkerSize(options.msize if options.msize else 1.2)
744  if len(legendList)<options.maxlegends:
745  text = 'All' if bcid==0 else 'BCID %i' % bcid
746  legendList.append([tgraph,text,'PLE'])
747  tgraph.Draw('P')
748 
749  # Fit data, if desired
750  if options.fit and len(grDict)==1:
751  ROOT.gStyle.SetOptFit(1111)
752  legendList = [] # No legend to avoid crowding plot
753  tgraph.Fit(options.fit,'','SAME', gr.xmin,gr.xmax) #-0.05, 0.05) #ZEBRA
754 
755  # Draw title and legend
756  legendX = 0.6 if len(grDict)==1 else 0.8
757  self.writeText(what,legendList if not options.public else [],not options.public,legendX=legendX)
758 
759  def perbcid(self,what):
760  """Variable what vs BCID."""
761  ROOT.gStyle.SetOptStat(0)
762  if options.ave:
763  calc = BeamSpotAverage([what],weightedAverage=not options.simpleaverage)
764  gr = BeamSpotGraph(bcidAxis=True)
765  for b in nt:
766  gr.add(b,what)
767  if options.ave:
768  calc.add(b)
769  atit = ';%s;%s' % ('BCID',varDef(what,'atit',what))
770 
771  # Axis range and labels
772  xmin = max(-100,gr.xmin-100)
773  xmax = min(3600,gr.xmax+100) # 3564 is the max number of BCIDS + a little space
774  ymin = gr.ymin
775  ymax = gr.ymax
776 
777  # Prevent xmin>xmax or ymin>ymax if no succesful fits (but still allow user to override)
778  if xmin>xmax:
779  xmin,xmax=0,1
780  if ymin>ymax:
781  ymin,ymax=0,1
782 
783  h = (ymax-ymin)/2*options.yscale
784  ymax += 1.3*h
785  ymin -= 0.5*h
786  if options.ydef:
787  ymin = varDef(what,'min',-100)
788  ymax = varDef(what,'max',+100)
789  if options.ymin!=None:
790  ymin = options.ymin
791  if options.ymax!=None:
792  ymax = options.ymax
793  frame = ROOTUtils.drawAxisFrame(xmin,xmax,ymin,ymax,atit)
794  if options.logy:
795  ROOT.gPad.SetLogy(options.logy)
796 
797  legendList = []
798 
799  # Show average
800  if options.ave:
801  calc.average()
802  dx = (xmax-xmin)/30
803  mean = calc.ave[0]
804  if options.rms:
805  error = calc.rms[0]
806  else:
807  error = calc.err[0]
808  b = ROOTUtils.drawHorizontalBand(xmin+dx,xmax-dx,mean,error,centralLine=True)
809  legendList.append([b,options.alegend,'FL'])
810  legendList.append([None,'%s %s #pm %s %s' % (fmtVal(what,mean,True),varDef(what,'units'),
811  fmtVal(what,error,True),varDef(what,'units')),''])
812 
813  # Save and draw graph
814  name = '%s-perBCID' % what
815  tgraph = self.protect( gr.getTGraph(name) )
816  if not tgraph:
817  return
818  if options.tgraphfile:
819  print ('Saving TGraphErrors',tgraph.GetName(),'to file',options.tgraphfile)
820  tgraphfile = ROOT.TFile(options.tgraphfile,'UPDATE')
821  tgraph.Write()
822  tgraphfile.Close()
823  tgraph.SetMarkerSize(options.msize if options.msize else 0.8)
824  if options.plegend:
825  legendList.append([tgraph,options.plegend,'PLE'])
826  tgraph.Draw('P')
827 
828  # Draw title and legend
829  self.writeText(what,legendList,not options.public)
830 
831  def vsBunchPos(self,what):
832  """Variable what vs bunch position in train."""
833  ROOT.gStyle.SetOptStat(0)
834 
835  lastb = -999
836  startb = -999
837  calcmap = {}
838  bunchnrs = []
839  trainGap = 36
840 
841  for b in nt:
842  if b.bcid - lastb > trainGap:
843  startb = b.bcid
844 
845  lastb = b.bcid
846  bunchnumber = b.bcid - startb
847 
848  if bunchnumber in calcmap:
849  calcmap[bunchnumber].add(b)
850  else:
851  calcmap[bunchnumber] = BeamSpotAverage([what], weightedAverage = not options.simpleaverage)
852  bunchnrs.append(bunchnumber)
853 
854  gr = self.protect( ROOT.TGraphErrors(len(bunchnrs)))
855  counter = 0
856  xmin = -10
857  xmax = 1
858  ymin = 1e9
859  ymax = -1e9
860 
861  for bunchnr in bunchnrs:
862  calcmap[bunchnr].average()
863  gr.SetPoint(counter, bunchnr, calcmap[bunchnr].ave[0])
864  gr.SetPointError(counter, 0.5, calcmap[bunchnr].err[0])
865  xmax = max(xmax, bunchnr)
866  ymin = min(ymin, calcmap[bunchnr].ave[0])
867  ymax = max(ymax, calcmap[bunchnr].ave[0])
868  counter += 1
869 
870  if xmin>xmax:
871  xmin,xmax=0,1
872  if ymin>ymax:
873  ymin,ymax=0,1
874 
875  xmax = xmax + 10
876  h = (ymax - ymin)/2*options.yscale
877  ymax += 2.0*h
878  ymin -= 1.0*h
879 
880  if options.xmin != None:
881  xmin = options.xmin
882  if options.xmax != None:
883  xmax = options.xmax
884  if options.ymin != None:
885  ymin = options.ymin
886  if options.ymax != None:
887  ymax = options.ymax
888 
889  gr.SetMarkerSize(options.msize if options.msize else 0.8)
890 
891  atit = ';%s;%s' % ('Bunch position in train',varDef(what,'atit',what))
892  frame = ROOTUtils.drawAxisFrame(xmin,xmax,ymin,ymax,atit)
893  if gr.GetN() == 0:
894  return
895 
896  legendList = []
897  if options.plegend:
898  legendList.append([gr,options.plegend,'PLE'])
899  gr.Draw('P')
900  self.writeText(what,legendList,not options.public)
901 
902  def plotscan(self,what):
903  """History of variable what vs LB, time or separation. Additionally overlap the results of more than one scan
904  """
905 
906  ROOT.gStyle.SetOptStat(0)
907  if options.ave:
908  calc = BeamSpotAverage([what],weightedAverage=not options.simpleaverage)
909  grDict = {}
910 
911  scans = [(int(s.split('-')[0]), int(s.split('-')[1])) for s in options.scans.split(',')]
912 
913  for b in nt:
914 
915  if options.separation and options.overlayScans:
916  try:
917  scanGroup = [s for s in scans if s[0] <= b.lbStart <= s[1]][0]
918  except IndexError:
919  # plB outside of scan ranges
920  continue
921  else:
922  scanGroup = 0
923 
924  if not scanGroup in grDict:
925  grDict[scanGroup] = BeamSpotGraph(timeAxis=options.timeaxis, separationAxis=options.separation)
926  grDict[scanGroup].add(b,what)
927  if options.ave:
928  calc.add(b)
929 
930  print ('Plotting data from %i scans ...\n' % len(grDict))
931 
932  # Determine axis range
933  xmin = 1E10
934  xmax = -1E10
935  ymin = 1E10
936  ymax = -1E10
937  for gr in [grDict.get(scan) for scan in grDict]:
938  xmin = min(xmin,gr.xmin)
939  xmax = max(xmax,gr.xmax)
940  ymin = min(ymin,gr.ymin)
941  ymax = max(ymax,gr.ymax)
942 
943  # Prevent xmin>xmax or ymin>ymax if no succesful fits (but still allow user to override)
944  if xmin>xmax:
945  xmin,xmax=0,1
946  if ymin>ymax:
947  ymin,ymax=0,1
948 
949  h = (xmax-xmin)
950  xmax += .05*h if len(grDict)==1 else 0.3*h
951  xmin -= .05*h
952  h = (ymax-ymin)/2*options.yscale
953  ymax += 1.3*h
954  ymin -= 0.5*h
955  if options.xmin!=None:
956  xmin = time.mktime(time.strptime(options.xmin,'%b %d %H:%M:%S %Y')) if options.timeaxis else float(options.xmin)
957  if options.xmax!=None:
958  xmax = time.mktime(time.strptime(options.xmax,'%b %d %H:%M:%S %Y')) if options.timeaxis else float(options.xmax)
959  if options.ydef:
960  ymin = varDef(what,'min',-100)
961  ymax = varDef(what,'max',+100)
962  if options.ymin!=None:
963  ymin = options.ymin
964  if options.ymax!=None:
965  ymax = options.ymax
966 
967  # Axis settings
968  if options.timeaxis:
969  atit = ';%s;%s' % (timeLabel,varDef(what,'atit',what))
970  elif options.separation:
971  atit = ';%s;%s' % ('Nominal Separation [mm]',varDef(what,'atit',what))
972  else:
973  atit = ';%s;%s' % ('Luminosity block number',varDef(what,'atit',what))
974  frame = ROOTUtils.drawAxisFrame(xmin,xmax,ymin,ymax,atit)
975  if options.logy:
976  ROOT.gPad.SetLogy(options.logy)
977  if options.timeaxis:
978  xAxis = frame.GetXaxis()
979  xAxis.SetTimeDisplay(1)
980  if (xmax-xmin)/86400 < 1:
981  xAxis.SetTimeFormat('%H:%M')
982  else:
983  #d0 = ceil(xmin/86400) # day w/first tick mark
984  #d1 = floor(xmax/86400) # day w/last tick mark
985  #nTicks = d1-d0+1
986  #nDays = floor((xmax-xmin)/86400)
987  xAxis.SetTimeFormat('#splitline{%b %d}{%H:%M}')
988  xAxis.SetLabelOffset(0.025)
989  xAxis.SetTitleOffset(1.6)
990  if options.adatefmt:
991  xAxis.SetTimeFormat(options.adatefmt)
992  if options.ndivs:
993  xAxis.SetNdivisions(options.ndivs,0)
994  frame.LabelsOption('d','X') # Doesn't seem to work
995 
996  legendList = []
997 
998  # Show average
999  if options.ave:
1000  calc.average()
1001  dx = (xmax-xmin)/30
1002  mean = calc.ave[0]
1003  if options.rms:
1004  error = calc.rms[0]
1005  else:
1006  error = calc.err[0]
1007  b = ROOTUtils.drawHorizontalBand(xmin+dx,xmax-dx,mean,error,centralLine=True)
1008  legendList.append([b,options.alegend,'FL'])
1009  legendList.append([None,'%s %s #pm %s %s' % (fmtVal(what,mean,True),varDef(what,'units'),
1010  fmtVal(what,error,True),varDef(what,'units')),''])
1011 
1012  # Loop over graphs for all scans
1013  styleFactory = ROOTUtils.StyleFactory()
1014  for scan in sorted(grDict.keys()):
1015  gr = grDict[scan]
1016 
1017  # Get and save TGraphErrors, if desired
1018  name = what if scan==0 else '%s-scanoverlay' % (what)
1019  tgraph = self.protect( gr.getTGraph(name) )
1020  if not tgraph:
1021  continue
1022  if options.tgraphfile:
1023  print ('Saving TGraphErrors',tgraph.GetName(),'to file',options.tgraphfile)
1024  tgraphfile = ROOT.TFile(options.tgraphfile,'UPDATE')
1025  tgraph.Write()
1026  tgraphfile.Close()
1027 
1028  # Draw data points
1029  if len(grDict)==1:
1030  tgraph.SetMarkerSize(options.msize if options.msize else 0.8)
1031  if options.plegend:
1032  legendList.append([tgraph,options.plegend,'PLE'])
1033  else:
1034  tgraph.SetMarkerColor(styleFactory.nextColorStyle())
1035  tgraph.SetMarkerStyle(styleFactory.nextMarkerStyle())
1036  tgraph.SetMarkerSize(options.msize if options.msize else 1.2)
1037  if len(legendList)<options.maxlegends:
1038  text = 'All' if scan==0 else 'scan %i - %i' % scan
1039  legendList.append([tgraph,text,'PLE'])
1040  tgraph.Draw('P')
1041 
1042  # Indicate if legend incomplete
1043  if len(grDict)>options.maxlegends:
1044  legendList.append([None,'...',''])
1045 
1046  # Fit data, if desired
1047  if options.fit and len(grDict)==1:
1048  ROOT.gStyle.SetOptFit(1111)
1049  legendList = [] # No legend to avoid crowding plot
1050  tgraph.Fit(options.fit,'','SAME',gr.xmin,gr.xmax)
1051 
1052  # Draw title and legend
1053  legendX = 0.6 if len(grDict)==1 else 0.8
1054  self.writeText(what,legendList,not options.public,legendX=legendX)
1055 
1056 
1057 
1058 #
1059 # Dump beam spot ntuple
1060 #
1061 if cmd=='dump' and len(args)==1:
1062  print()
1063  nt = getNt()
1064  for b in nt:
1065  b.dump(options.verbose)
1066  cmdOk = True
1067 
1068 
1069 #
1070 # Make LaTeX table of results
1071 #
1072 
1073 tableTemplate = r"""
1074 \documentclass[12pt,twoside]{article}
1075 \usepackage[landscape]{geometry}
1076 \RequirePackage{xspace}
1077 \def\lumposx {\ensuremath{\overline{x}_{\mathcal{L}}}\xspace}
1078 \def\lumposy {\ensuremath{\overline{y}_{\mathcal{L}}}\xspace}
1079 \def\lumposz {\ensuremath{\overline{z}_{\mathcal{L}}}\xspace}
1080 \def\lumsigx {\ensuremath{\sigma_{x{\mathcal L}}}\xspace}
1081 \def\lumsigy {\ensuremath{\sigma_{y{\mathcal L}}}\xspace}
1082 \def\lumsigz {\ensuremath{\sigma_{z{\mathcal L}}}\xspace}
1083 \def\lumtiltx {\ensuremath{\overline{x}_{\mathcal{L}}'}\xspace}
1084 \def\lumtilty {\ensuremath{\overline{y}_{\mathcal{L}}'}\xspace}
1085 \def\lumrhoxy {\ensuremath{\rho_{xy}}\xspace}
1086 \begin{document}
1087 
1088 \begin{table}[htbp]
1089 \begin{center}
1090 \begin{tabular}{%s}
1091 \hline \hline
1092 %s \\
1093 \hline \hline
1094 
1095 %s
1096 
1097 \hline \hline
1098 \end{tabular}
1099 \end{center}
1100 \end{table}
1101 
1102 \end{document}
1103 """
1104 
1105 if cmd=='maketable' and len(args)==1:
1106  if options.varlist is None:
1107  #varList = ['posX','posY','posZ','sigmaX','sigmaY','sigmaZ','tiltX','tiltY','rhoXY','k']
1108  varList = ['status','posX','posY','posZ','sigmaX','sigmaY','sigmaZ','k']
1109  else:
1110  varList = options.varlist.split(',')
1111  nt = getNt()
1112  rows = []
1113  for b in nt:
1114  cols = []
1115  for v in varList:
1116  try:
1117  cols.append('%s $\pm$ %s' % (fmtVal(v,getattr(b,v),True,useAlternate=True),
1118  fmtVal(v,getattr(b,v+'Err'),True,useAlternate=True)))
1119  except:
1120  cols.append('%10s' % (fmtVal(v,getattr(b,v),True,useAlternate=True)))
1121  rows.append('%s \\\\' % ' & '.join(cols))
1122  print()
1123  print (tableTemplate % (len(varList)*'c',
1124  ' & '.join(['%s' % varDef(n,'latexheader',useAlternate=True) for n in varList]),
1125  '\n'.join(rows)))
1126  print()
1127  cmdOk = True
1128 
1129 
1130 #
1131 # Dump beam spot ntuple
1132 #
1133 if cmd=='inspect' and len(args)==1:
1134  print()
1135  nt = getNt()
1136  runInfo = {}
1137  for b in nt:
1138  r = b.run
1139  if not b.run in runInfo:
1140  runInfo[r] = {
1141  'lbStart': None,
1142  'lbEnd': None,
1143  'status': set(),
1144  'hasErrors': False,
1145  'hasCOOL' : False
1146  }
1147  if runInfo[r]['lbStart'] is None or b.lbStart<runInfo[r]['lbStart']: runInfo[r]['lbStart'] = b.lbStart
1148  if runInfo[r]['lbEnd'] is None or b.lbEnd>runInfo[r]['lbEnd']: runInfo[r]['lbEnd'] = b.lbEnd
1149  runInfo[r]['status'].add(b.status)
1150  if b.timeStart and b.timeEnd and b.fill: runInfo[r]['hasCOOL'] = True
1151  if b.posXErr: runInfo[r]['hasErrors'] = True
1152  for r in sorted(runInfo.keys()):
1153  print ('%6s [ %10i, %10i ] %7s %9s fit status = %s' % (r,
1154  runInfo[r]['lbStart'],
1155  runInfo[r]['lbEnd'],
1156  'hasCOOL' if runInfo[r]['hasCOOL'] else '',
1157  'hasErrors' if runInfo[r]['hasErrors'] else '',
1158  sorted(list(runInfo[r]['status']))))
1159  print()
1160  print ('%i runs found\n' % len(runInfo.keys()))
1161  cmdOk = True
1162 
1163 
1164 
1165 #
1166 # Merge beam spot finder ntuple into master beam spot ntuple
1167 #
1168 if cmd=='merge' and len(args)==2:
1169  srcNtClass = locals()[options.srctype]
1170  if (options.srctype == 'BeamSpotCOOL'):
1171  print ('\n Reading in from database ')
1172  srcNt = srcNtClass(args[1],database=options.database,folder=options.dbfolder,fullCorrelations=options.fullCorrelations)
1173  else :
1174  srcNt = srcNtClass(args[1],fullCorrelations=options.fullCorrelations)
1175 
1176  setCuts(srcNt)
1177  print ('\nImporting from '+srcNt.summary())
1178  print (srcNt.cutSummary())
1179  dstNt = ntClass(options.ntname,True,fullCorrelations=options.fullCorrelations,addScanVars=options.addScanVars)
1180  print ('\nMerging into '+dstNt.summary())
1181 
1182  totalEntries = 0
1183  totalVtxs = 0
1184  lbSize = 0
1185  allBSResultsInNt = []
1186  for b in srcNt:
1187  allBSResultsInNt.append( b )
1188  if b.status == 59:
1189  totalEntries += 1
1190  totalVtxs += b.nValid
1191  lbSize += b.lbEnd - b.lbStart
1192 
1193  if totalEntries == 0:
1194  totalEntries = 1
1195  averagenVtx = totalVtxs/totalEntries
1196  print ('Average Entries: '+ str(averagenVtx))
1197  averagenVtx *= 0.33
1198 
1199  lbSize = lbSize/totalEntries + 1
1200  print ('Average number of lb used for fit: '+ str( lbSize ))
1201 
1202  #Sort entries in order of lb number
1203  #allBSResultsInNt.sort(key=lambda x: x.lbStart, reverse=False)
1204  allBSResultsInNt.sort()
1205  if options.useAve:
1206  cleanUpLowStat( allBSResultsInNt, averagenVtx, lbSize * 10)
1207  allBSResultsInNt.sort()
1208  fillInMissingLbs(allBSResultsInNt, lbSize * 10)
1209 
1210  for b in allBSResultsInNt:
1211  if options.fillcooldata:
1212  b.fillDataFromCOOL()
1213  if options.addScanVars:
1214  b.fillScanData()
1215  if options.pseudoLbFile:
1216  b.fillDataFromPseudoLb(options.pseudoLbFile, float(options.pseudoLbTimeUnit))
1217  if options.filldqdata:
1218  b.fillDataFromDQ()
1219  if not options.quiet:
1220  b.dump(options.verbose)
1221  dstNt.fill(b)
1222  cmdOk = True
1223 
1224 
1225 
1226 #
1227 # Calculate average of beam spot parameters
1228 #
1229 if cmd=='ave' and len(args)==1:
1230  nt = getNt()
1231  if options.varlist is None:
1232  #varList = 'posX,posY,posZ,sigmaX,sigmaY,sigmaZ,tiltX,tiltY,rhoXY,sigmaXY,k'
1233  varList = ['posX','posY','posZ','sigmaX','sigmaY','sigmaZ','tiltX','tiltY','rhoXY']
1234  if options.cooltag:
1235  varList.append('sigmaXY')
1236  else:
1237  varList = options.varlist.split(',')
1238 
1239  # Summary plot for checks
1240  plots = Plots(nt)
1241  plots.whatList = varList
1242  plots.saveAsList = options.output.split(',')
1243  plots.allCanvasSize = 'landscape'
1244  plots.allCanvasDivs = (3,3)
1245  if options.hist:
1246  plots.genPlot('all','hist')
1247  if options.summary:
1248  plots.genPlot('all','plot')
1249  print()
1250 
1251  # Averages
1252  calc = BeamSpotAverage(varList,weightedAverage=not options.simpleaverage)
1253  if options.lumicalcnt is not None:
1254  calc.readLumiData(options.lumicalcnt)
1255  minrun=1e10
1256  maxrun=0
1257  for b in nt:
1258  if options.verbose or options.debug:
1259  b.dump(options.debug)
1260  calc.add(b)
1261  minrun = min(b.run,minrun)
1262  maxrun = max(b.run,maxrun)
1263  calc.average()
1264  ave = calc.ave
1265  err = calc.err
1266  rms = calc.rms
1267  if calc.nWarnings:
1268  print ('... %i warnings detected' % calc.nWarnings)
1269  if options.lumicalcnt is not None:
1270  print ('... integrated luminosity of selected runs = %6.1f / pb' % (calc.sumw[0]/1.E6))
1271  print()
1272  if options.splittable:
1273  varRanges = [ range(options.splittable),
1274  range(options.splittable,len(calc.varList)) ]
1275  else:
1276  varRanges = [ range(len(calc.varList)) ]
1277  if options.latex:
1278  for r in varRanges:
1279  try:
1280  iTable += 1
1281  except:
1282  iTable = 1
1283  latexheader = 'Period '
1284  latexrow = '%s' % options.period.replace('_','\_')
1285  print ('\nAverage beam spot parameters (part %i):\n' % iTable)
1286  for i in r:
1287  parName = calc.varList[i]
1288  print ('%7s: %s +- %s %-3s (RMS = %s)' % (parName,
1289  fmtVal(parName,ave[i]),
1290  fmtVal(parName,err[i]),
1291  varDef(parName,'units'),
1292  fmtVal(parName,rms[i])))
1293  latexheader += '& %s ' % varDef(parName,'latexheader',parName,useAlternate=True)
1294  if options.rms:
1295  latexrow += ' & %s $\pm$ %s' % (fmtVal(parName,ave[i],useAlternate=True),fmtVal(parName,rms[i],useAlternate=True))
1296  else:
1297  latexrow += ' & %s $\pm$ %s' % (fmtVal(parName,ave[i],useAlternate=True),fmtVal(parName,err[i],useAlternate=True))
1298  print()
1299  print ('\nLaTeX code for table %i:\n' % iTable)
1300  print ('\\begin{table}[htbp]\n\\begin{center}\n\\begin{tabular}{l%s}' % (len(r)*'c'))
1301  print ('\hline \hline')
1302  print (latexheader,'\\\\ \hline')
1303  print()
1304  print (latexrow,' \\\\')
1305  print()
1306  print ('\hline \hline')
1307  print ('\\end{tabular}\n\\end{center}\n\\caption{\\label{tab:}}\n\\end{table}')
1308  print()
1309  if options.cooltag and minrun<1e10:
1310  from InDetBeamSpotExample.COOLUtils import *
1311  sqliteFile= options.cooltag+'.db'
1312  folderHandle = openBeamSpotDbFile(sqliteFile,True)
1313 
1314  if not options.newave:
1315  print ('\nWriting average to COOL SQLite file %s (folder tag = %s) ...' % (sqliteFile,options.cooltag))
1316  writeBeamSpotEntry(folderHandle,tag=options.cooltag,
1317  status=0,
1318  posX=ave[calc.varList.index('posX')],
1319  posY=ave[calc.varList.index('posY')],
1320  posZ=ave[calc.varList.index('posZ')],
1321  sigmaX=ave[calc.varList.index('sigmaX')],
1322  sigmaY=ave[calc.varList.index('sigmaY')],
1323  sigmaZ=ave[calc.varList.index('sigmaZ')],
1324  tiltX=ave[calc.varList.index('tiltX')],
1325  tiltY=ave[calc.varList.index('tiltY')],
1326  sigmaXY=ave[calc.varList.index('sigmaXY')],
1327  posXErr=err[calc.varList.index('posX')],
1328  posYErr=err[calc.varList.index('posY')],
1329  posZErr=err[calc.varList.index('posZ')],
1330  sigmaXErr=err[calc.varList.index('sigmaX')],
1331  sigmaYErr=err[calc.varList.index('sigmaY')],
1332  sigmaZErr=err[calc.varList.index('sigmaZ')],
1333  tiltXErr=err[calc.varList.index('tiltX')],
1334  tiltYErr=err[calc.varList.index('tiltY')],
1335  sigmaXYErr=err[calc.varList.index('sigmaXY')])
1336 
1337  else:
1338  print ('\nWriting average and LB info to COOL SQLite file %s (folder tag = %s) ...' % (sqliteFile,"nominal"))
1339  writeBeamSpotEntry(folderHandle,tag="nominal",
1340  runMin=int(minrun),runMax=int(maxrun),
1341  status=0,
1342  posX=ave[calc.varList.index('posX')],
1343  posY=ave[calc.varList.index('posY')],
1344  posZ=ave[calc.varList.index('posZ')],
1345  sigmaX=ave[calc.varList.index('sigmaX')],
1346  sigmaY=ave[calc.varList.index('sigmaY')],
1347  sigmaZ=ave[calc.varList.index('sigmaZ')],
1348  tiltX=ave[calc.varList.index('tiltX')],
1349  tiltY=ave[calc.varList.index('tiltY')],
1350  sigmaXY=ave[calc.varList.index('sigmaXY')],
1351  posXErr=err[calc.varList.index('posX')],
1352  posYErr=err[calc.varList.index('posY')],
1353  posZErr=err[calc.varList.index('posZ')],
1354  sigmaXErr=err[calc.varList.index('sigmaX')],
1355  sigmaYErr=err[calc.varList.index('sigmaY')],
1356  sigmaZErr=err[calc.varList.index('sigmaZ')],
1357  tiltXErr=err[calc.varList.index('tiltX')],
1358  tiltYErr=err[calc.varList.index('tiltY')],
1359  sigmaXYErr=err[calc.varList.index('sigmaXY')])
1360 
1361  print ('Copying beam spot data from',options.ntname)
1362  for b in nt:
1363  if options.lbMin and options.lbMin>b.lbStart:
1364  continue
1365  if options.lbMax and options.lbMax<b.lbEnd+1:
1366  continue
1367  try:
1368  runEndInt = b.runEnd
1369  except AttributeError:
1370  runEndInt = b.run
1371 
1372  if b.status in nt.statusList:
1373  writeBeamSpotEntry(folderHandle,tag='nominal',
1374  runMin=b.run,
1375  runMax=runEndInt,
1376  lbMin=b.lbStart,
1377  lbMax=b.lbEnd, # Beware - lbMax is inclusive
1378  status=b.status,
1379  posX=b.posX, posY=b.posY, posZ=b.posZ,
1380  sigmaX=b.sigmaX, sigmaY=b.sigmaY, sigmaZ=b.sigmaZ,
1381  tiltX=b.tiltX, tiltY=b.tiltY,
1382  sigmaXY=b.rhoXY*b.sigmaX*b.sigmaY,
1383  posXErr=b.posXErr, posYErr=b.posYErr, posZErr=b.posZErr,
1384  sigmaXErr=b.sigmaXErr, sigmaYErr=b.sigmaYErr, sigmaZErr=b.sigmaZErr,
1385  tiltXErr=b.tiltXErr, tiltYErr=b.tiltYErr,
1386  sigmaXYErr=sqrt( (b.sigmaX*b.sigmaX) * (b.sigmaY*b.sigmaY) * (b.rhoXYErr*b.rhoXYErr) +(b.sigmaX*b.sigmaX) * (b.sigmaYErr*b.sigmaYErr) * (b.rhoXY*b.rhoXY) + (b.sigmaXErr*b.sigmaXErr) * (b.sigmaY*b.sigmaY) * (b.rhoXY*b.rhoXY) ) )
1387 
1388  cmdOk = True
1389 
1390 #
1391 # Different histograms of beam spot variables
1392 #
1393 if (cmd=='hist' or cmd=='histvspileup' or cmd=='pull') and len(args)==2:
1394  var = args[1]
1395  nt = getNt()
1396  plots = Plots(nt)
1397  plots.saveAsList = options.output.split(',')
1398  if options.canvas:
1399  plots.singleCanvasSize = options.canvas
1400  plots.allCanvasSize = options.canvas
1401  plots.allCanvasDivs = (options.xdivs,options.ydivs)
1402  if ',' in var:
1403  plots.whatList = var.split(',')
1404  plots.genPlot('all',cmd)
1405  else:
1406  plots.genPlot(var,cmd)
1407  cmdOk = True
1408 
1409 
1410 #
1411 # Plot of beam spot variables vs LB or time
1412 #
1413 if cmd=='plot' and len(args)==2:
1414  var = args[1]
1415  nt = getNt()
1416  plots = Plots(nt)
1417  plots.saveAsList = options.output.split(',')
1418  if options.canvas:
1419  plots.singleCanvasSize = options.canvas
1420  plots.allCanvasSize = options.canvas
1421  plots.allCanvasDivs = (options.xdivs,options.ydivs)
1422  if options.perbcid:
1423  plotType = 'perbcid'
1424  elif options.vsbunchpos:
1425  plotType = 'vsBunchPos'
1426  else:
1427  plotType = 'plot'
1428  if ',' in var:
1429  plots.whatList = var.split(',')
1430  plots.genPlot('all',plotType)
1431  else:
1432  plots.genPlot(var,plotType)
1433  cmdOk = True
1434 
1435 
1436 #
1437 # Summary history of beam spot variables
1438 #
1439 if cmd=='summary' and len(args)==1:
1440  nt = getNt()
1441  if not options.msize:
1442  options.msize = 0.5
1443  plots = Plots(nt)
1444  plots.saveAsList = options.output.split(',')
1445  plots.allCanvasSize = 'landscape'
1446 
1447  labels=[]
1448  if "COOL-Current" not in options.ntname:
1449  plots.allCanvasDivs = (4,3)
1450  plots.whatList = ['posX','posY','posZ','k','sigmaX','sigmaY','sigmaZ','nValid','tiltX','tiltY','rhoXY']
1451  datasetinfo=options.ntname.replace("-DB_BEAMSPOT","").split('.')
1452  labels=["%s.%s.%s.%s" % (datasetinfo[0],datasetinfo[1],datasetinfo[2],datasetinfo[3])]
1453  labels+=["Generated on %s, at %s (%s)" % (time.strftime("%x"), time.strftime("%X"), time.strftime("%Z"))]
1454  else:
1455  plots.allCanvasDivs = (3,3)
1456  plots.whatList = ['posX','posY','posZ','sigmaX','sigmaY','sigmaZ','tiltX','tiltY','rhoXY']
1457 
1458  # add some labels to the empty pad
1459 
1460  if options.perbcid:
1461  plots.genPlot('all','perbcid',labels=labels)
1462  elif options.vsbunchpos:
1463  plots.whatList.remove('nValid')
1464  plots.genPlot('all','vsBunchPos',labels=labels)
1465  else:
1466  plots.genPlot('all','plot',labels=labels)
1467 
1468  cmdOk = True
1469 
1470 
1471 #
1472 # Plot of beam spot variables vs LB or time
1473 #
1474 if cmd=='ascii' and len(args)==2:
1475  time0 = 1262304000 # unix time for Jan 1, 2010, 00:00:00 CET
1476  ascii = open(args[1],'w')
1477  ascii.write('# Beam spot data file\n')
1478  ascii.write('# Generated %s by %s on host %s using command:\n' % (time.asctime(),getUserName(),getHostName()))
1479  ascii.write('# %s\n' % qcmd)
1480  nt = getNt()
1481  for b in nt:
1482  ascii.write('1 ') # IP number
1483  ascii.write('%s ' % str(b.fill))
1484  ascii.write('%s ' % str(b.timeStart - time0 + int((b.timeEnd-b.timeStart)/2))) # Time in sec since Jan 1, 2010
1485  ascii.write('%s ' % str(b.posX))
1486  ascii.write('%s ' % str(b.posXErr))
1487  ascii.write('%s ' % str(b.posY))
1488  ascii.write('%s ' % str(b.posYErr))
1489  ascii.write('%s ' % str(b.posZ))
1490  ascii.write('%s ' % str(b.posZErr))
1491  ascii.write('0 0 0 0 0 0 ') # No data from raw Gauss fit w/o subtracting vtx-resolution
1492  ascii.write('%s ' % str(b.sigmaX))
1493  ascii.write('%s ' % str(b.sigmaXErr))
1494  ascii.write('%s ' % str(b.sigmaY))
1495  ascii.write('%s ' % str(b.sigmaYErr))
1496  ascii.write('%s ' % str(b.sigmaZ))
1497  ascii.write('%s ' % str(b.sigmaZErr))
1498  ascii.write('0 0 0\n') # No RMS info
1499  ascii.close()
1500  cmdOk = True
1501 
1502 
1503 if cmd=='scan' and len(args)==1:
1504 
1505  if not options.msize:
1506  options.msize = 0.5
1507 
1508  if options.timeaxis:
1509  xtype = 'time'
1510  elif options.separation:
1511  xtype = 'sep'
1512  else:
1513  xtype = 'lb'
1514 
1515  # Plot summary plots for full scan
1516  nt = getNt()
1517 
1518  plots = Plots(nt)
1519  plots.allCanvasSize = 'landscape'
1520  plots.allCanvasDivs = (3,3)
1521  plots.whatList = ['posX','posY','posZ','sigmaX','sigmaY','sigmaZ','tiltX','tiltY','rhoXY']
1522  plots.saveAsList = ['%s-scanfull-%s-all.gif' %(options.name,xtype),
1523  '%s-scanfull-%s-all.eps' %(options.name,xtype),]
1524 
1525  if options.separation and options.overlayScans:
1526  plots.genPlot('all','plotscan')
1527  else:
1528  plots.genPlot('all','plot')
1529 
1530  plots.whatList.append('k')
1531 
1532  # Individual plot for full scan
1533  plots.singleCanvasSize = 'wide'
1534  for var in plots.whatList:
1535  plots.saveAsList = ['%s-scanfull-%s-%s.gif' %(options.name,xtype,var),
1536  '%s-scanfull-%s-%s.eps' %(options.name,xtype,var) ]
1537  if options.separation and options.overlayScans:
1538  graphs = plots.genPlot(var,'plotscan')
1539  else:
1540  graphs = plots.genPlot(var,'plot')
1541 
1542 
1543  # Plots for each scan range
1544  if options.scans:
1545  scans = [(int(s.split('-')[0]), int(s.split('-')[1])) for s in options.scans.split(',')]
1546  else:
1547  scans = []
1548 
1549  options.overlayScans = False
1550  for (lbMin, lbMax) in scans:
1551 
1552  nt = getNt()
1553  nt.lbMin = lbMin
1554  nt.lbMax = lbMax
1555 
1556  # Summary plot for each scan range
1557  plots = Plots(nt)
1558  plots.allCanvasSize = 'landscape'
1559  plots.allCanvasDivs = (3,3)
1560  plots.whatList = ['posX','posY','posZ','sigmaX','sigmaY','sigmaZ','tiltX','tiltY','rhoXY']
1561  plots.saveAsList = ['%s-scan%s-%s-%s-all.gif' %(options.name,lbMin,lbMax,xtype),
1562  '%s-scan%s-%s-%s-all.eps' %(options.name,lbMin,lbMax,xtype) ]
1563  plots.genPlot('all','plot')
1564 
1565  plots.whatList.append('k')
1566 
1567  # Individual plot for each scan range
1568  plots.singleCanvasSize = 'default'
1569  for var in plots.whatList:
1570  plots.saveAsList = ['%s-scan%s-%s-%s-%s.gif' %(options.name,lbMin,lbMax,xtype,var),
1571  '%s-scan%s-%s-%s-%s.eps' %(options.name,lbMin,lbMax,xtype,var) ]
1572  graphs = plots.genPlot(var,'plot')
1573 
1574  cmdOk = True
1575 
1576 
1577 if not cmdOk:
1578  print ('ERROR: Illegal command or number of arguments')
1579  sys.exit(1)
read
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
Definition: openCoraCool.cxx:569
python.Utils.getHostName
def getHostName()
Definition: InnerDetector/InDetExample/InDetBeamSpotExample/python/Utils.py:60
ROOTUtils.drawText
def drawText(x=0.74, y=0.87, dy=0.06, text='', font=62, color=1, align=11, linesep=';')
Definition: roofit/ROOTUtils.py:243
BeamSpotData
max
#define max(a, b)
Definition: cfImp.cxx:41
beamspotnt.ntClass
ntClass
Definition: bin/beamspotnt.py:211
vtune_athena.format
format
Definition: vtune_athena.py:14
drawFromPickle.average
def average(lst)
Definition: drawFromPickle.py:38
plotBeamSpotCompare.varDef
dictionary varDef
Definition: plotBeamSpotCompare.py:25
ROOTUtils.drawAxisFrame
def drawAxisFrame(xmin, xmax, ymin, ymax, title='', xTitleOffset=None, yTitleOffset=None, doPlot=True, protectFrame=True)
Definition: roofit/ROOTUtils.py:213
ROOTUtils.setStyle
def setStyle(style=None)
Definition: roofit/ROOTUtils.py:413
beamspotnt.Plots.writeText
def writeText(self, var, legendList=[], showRuns=True, showFills=True, showTime=True, otherTitle=None, otherComment=None, legendX=0.6)
Definition: bin/beamspotnt.py:423
beamspotnt.Plots.perbcid
def perbcid(self, what)
Definition: bin/beamspotnt.py:759
ROOTUtils.atlasLabel
def atlasLabel(x, y, isPreliminary=False, color=1, offset=0.115, isForApproval=False, energy=8, customstring="", size=0.05)
Definition: roofit/ROOTUtils.py:303
ROOTUtils.PlotLibrary.protect
def protect(self, obj)
Definition: roofit/ROOTUtils.py:101
beamspotnt.Plots.nt
nt
Definition: bin/beamspotnt.py:420
python.COOLUtils.writeBeamSpotEntry
def writeBeamSpotEntry(folderHandle, tag='nominal', runMin=0, runMax=(1<< 31) -1, lbMin=0, lbMax=(1<< 32) -2, status=0, posX=0., posY=0., posZ=0., sigmaX=30., sigmaY=30., sigmaZ=500., tiltX=0., tiltY=0., sigmaXY=0., posXErr=0., posYErr=0., posZErr=0., sigmaXErr=0., sigmaYErr=0., sigmaZErr=0., tiltXErr=0., tiltYErr=0., sigmaXYErr=0.)
Definition: COOLUtils.py:63
python.BeamSpotData.fmtVal
def fmtVal(var, value, strip=False, useAlternate=False)
Definition: BeamSpotData.py:248
beamspotnt.Plots.__init__
def __init__(self, nt)
Definition: bin/beamspotnt.py:418
ROOTUtils.drawHorizontalBand
def drawHorizontalBand(xmin, xmax, y, ywidth, color=33, protectBand=True, centralLine=False)
Definition: roofit/ROOTUtils.py:227
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
beamspotnt.fillInMissingLbs
def fillInMissingLbs(allBSResultsInNt, lbSize)
Definition: bin/beamspotnt.py:360
beamspotnt.Plots.whatList
whatList
Definition: bin/beamspotnt.py:421
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
beamspotnt.cleanUpLowStat
def cleanUpLowStat(allBSResultsInNt, averagenVtx, lbSize)
Definition: bin/beamspotnt.py:280
beamspotnt.Plots.vsBunchPos
def vsBunchPos(self, what)
Definition: bin/beamspotnt.py:831
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:224
min
#define min(a, b)
Definition: cfImp.cxx:40
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
beamspotnt.getNt
def getNt()
Definition: bin/beamspotnt.py:266
ROOTUtils.PlotLibrary.__init__
def __init__(self, name='MyPlots', otherMethods=[])
Definition: roofit/ROOTUtils.py:85
beamspotnt.srcNtClass
srcNtClass
Definition: bin/beamspotnt.py:1169
COOLUtils
ROOTUtils.PlotLibrary
Definition: roofit/ROOTUtils.py:77
beamspotnt.Plots.hist
def hist(self, what)
Definition: bin/beamspotnt.py:475
Trk::open
@ open
Definition: BinningType.h:40
beamspotnt.Plots.plotscan
def plotscan(self, what)
Definition: bin/beamspotnt.py:902
readCCLHist.int
int
Definition: readCCLHist.py:84
beamspotnt.Plots
Definition: bin/beamspotnt.py:416
beamspotnt.Plots.plot
def plot(self, what)
Definition: bin/beamspotnt.py:596
python.KeyStore.list
def list(self, key=None)
Definition: KeyStore.py:318
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:569
str
Definition: BTagTrackIpAccessor.cxx:11
python.COOLUtils.openBeamSpotDbFile
def openBeamSpotDbFile(fileName, forceNew=False, folderName='/Indet/Beampos', dbName='BEAMSPOT')
Definition: COOLUtils.py:22
beamspotnt.Plots.pull
def pull(self, what)
Definition: bin/beamspotnt.py:557
beamspotnt.setCuts
def setCuts(nt)
Definition: bin/beamspotnt.py:213
ROOTUtils.drawLegend
def drawLegend(x1, y1, x2, y2, legendList=[], fillColor=0, lineColor=0, textSize=None, protectLegend=True)
Definition: roofit/ROOTUtils.py:259
readCCLHist.float
float
Definition: readCCLHist.py:83
beamspotnt.Plots.histvspileup
def histvspileup(self, what)
Definition: bin/beamspotnt.py:516
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
ROOTUtils.StyleFactory
Definition: roofit/ROOTUtils.py:171
python.Utils.getUserName
def getUserName(default='UNKNOWN')
Definition: InnerDetector/InDetExample/InDetBeamSpotExample/python/Utils.py:48