6 beamspotnt is a command line utility for beam spot ntuples.
8 __author__ =
'Juerg Beringer'
9 __version__ =
'beamspotnt.py atlas/athena'
10 __usage__ =
'''%prog [options] command [args ...]
14 dump Dump contents of a beam spot ntuple
15 maketable Make LaTeX table of selected entries
16 inspect Inspect ntuple and provide summary of contents
17 merge SRCNT Merge source beam spot ntuple into master ntuple
18 (use --srcnt to specify type if not BeamSpotFinderNt)
19 ave Calculate average of beam spot parameters
20 hist var Histogram of var
21 histvspileup var Profile histogram of var vs pileup
22 pull var:value Pull of var with respect to true value
23 plot var History of var
24 summary Summary history plots
25 ascii filename Write ASCII file with data in Massi\'s format
29 beamspotnt -t BeamSpotCOOL -f IndetBeampos-ES1-UPD2 --ru 165815 --rl 165815 dump
33 periodDef =
'/afs/cern.ch/user/a/atlidbs/nt/DataPeriods'
35 import sys, os, time, glob, re, copy, math
40 if re.search(
r'\s|\*|\?',s):
42 qargv.append(
'"%s"' % re.sub(
'"',
"'",s))
44 qargv.append(
"'%s'" % re.sub(
"'",
'"',s))
47 qcmd =
' '.
join(qargv)
49 from optparse
import OptionParser
50 parser = OptionParser(usage=__usage__, version=__version__)
51 parser.add_option(
'-f',
'--nt', dest=
'ntname', default=
'beamspotnt.root', help=
'master ntuple file name or COOL tag (default: beamspotnt.root)')
52 parser.add_option(
'-t',
'--type', dest=
'type', default=
'BeamSpotNt', help=
'master ntuple type (default: BeamSpotNt)')
53 parser.add_option(
'-s',
'--srctype', dest=
'srctype', default=
'BeamSpotNt', help=
'source ntuple type for merging (default: BeamSpotNt)')
54 parser.add_option(
'-v',
'--verbose', dest=
'verbose', action=
'store_true', default=
False, help=
'verbose output')
55 parser.add_option(
'-d',
'--debug', dest=
'debug', action=
'store_true', default=
False, help=
'debug output')
56 parser.add_option(
'-q',
'--quiet', dest=
'quiet', action=
'store_true', default=
False, help=
'reduce output')
57 parser.add_option(
'-r',
'--run', dest=
'run', type=
'int', default=
None, help=
'run number (single run)')
58 parser.add_option(
'',
'--rl', dest=
'runMin', type=
'int', default=
None, help=
'minimum run number (inclusive)')
59 parser.add_option(
'',
'--ru', dest=
'runMax', type=
'int', default=
None, help=
'maximum run number (inclusive)')
60 parser.add_option(
'',
'--re', dest=
'runExclude', default=
None, help=
'comma seperated list of runs to exclude')
61 parser.add_option(
'',
'--fill', dest=
'fill', type=
'int', default=
None, help=
'fill number (single fill)')
62 parser.add_option(
'',
'--fl', dest=
'fillMin', type=
'int', default=
None, help=
'minimum fill number (inclusive)')
63 parser.add_option(
'',
'--fu', dest=
'fillMax', type=
'int', default=
None, help=
'maximum fill number (inclusive)')
64 parser.add_option(
'',
'--bcid', dest=
'bcid', type=
'int', default=
None, help=
'BCID number (single BCID)')
65 parser.add_option(
'',
'--bcl', dest=
'bcidMin', type=
'int', default=
None, help=
'minimum BCID number (inclusive)')
66 parser.add_option(
'',
'--bcu', dest=
'bcidMax', type=
'int', default=
None, help=
'maximum BCID number (inclusive)')
67 parser.add_option(
'',
'--lbl', dest=
'lbMin', type=
'int', default=
None, help=
'minimum LB number (inclusive)')
68 parser.add_option(
'',
'--lbu', dest=
'lbMax', type=
'int', default=
None, help=
'maximum LB number (inclusive)')
69 parser.add_option(
'',
'--tl', dest=
'timeMin', default=
None, help=
'minimum start time')
70 parser.add_option(
'',
'--tu', dest=
'timeMax', default=
None, help=
'maximum end time')
71 parser.add_option(
'',
'--status', dest=
'status', default=
'59', help=
'comma-separated list of accepted fit status values (default: 59)')
72 parser.add_option(
'',
'--energy', dest=
'energy', default=
'13', help=
'center-of-mass energy')
73 parser.add_option(
'-p',
'--period', dest=
'period', default=
None, help=
'comma-separated list of accepted run periods (e.g. data10_7TeV.G)')
74 parser.add_option(
'',
'--perioddef', dest=
'periodDef', default=periodDef, help=
'location of run period definition files (default: %s)' % periodDef)
75 parser.add_option(
'-g',
'--grl', dest=
'grl', default=
None, help=
'GRL to select runs/Lbs')
76 parser.add_option(
'',
'--mc', dest=
'mc', action=
'store_true', default=
False, help=
'flag to indicate beam spot results are from MC')
77 parser.add_option(
'',
'--fillCOOL', dest=
'fillcooldata', action=
'store_true', default=
False, help=
'fill data from COOL (time, fill#)')
78 parser.add_option(
'',
'--fillDQ', dest=
'filldqdata', action=
'store_true', default=
False, help=
'fill data from DataQualtiy')
79 parser.add_option(
'',
'--pLbFile', dest=
'pseudoLbFile', default=
None, help=
'File for pseudo LB info from scan')
80 parser.add_option(
'',
'--pLbTimeUnit', dest=
'pseudoLbTimeUnit', default=1., help=
'Time unit for pseudo LB relative to seconds, e.g. 1e-9 for ns')
81 parser.add_option(
'',
'--tz', dest=
'timezone', default=
'CET', help=
'time zone to use for time represenation (default: CERN local time)')
82 parser.add_option(
'',
'--simpleaverage', dest=
'simpleaverage', action=
'store_true', default=
False, help=
'use simple instead of weighted average (for checks only)')
83 parser.add_option(
'',
'--lumicalcnt', dest=
'lumicalcnt', default=
None, help=
'ave: use luminosity ntuple (from iLumiCalc.exe) for weighted average')
84 parser.add_option(
'',
'--latex', dest=
'latex', action=
'store_true', default=
False, help=
'output results in LaTeX')
85 parser.add_option(
'',
'--splittable', dest=
'splittable', type=
'int', default=
None, help=
'latex: split table, put first n cols into first table')
86 parser.add_option(
'',
'--hist', dest=
'hist', action=
'store_true', default=
False, help=
'ave: produce validation histograms')
87 parser.add_option(
'',
'--summary', dest=
'summary', action=
'store_true', default=
False, help=
'ave: produce validation summary plots')
88 parser.add_option(
'',
'--rms', dest=
'rms', action=
'store_true', default=
False, help=
'Use RMS instead of error on mean')
89 parser.add_option(
'',
'--varlist', dest=
'varlist', default=
None, help=
'list of beam spot variables used by ave')
90 parser.add_option(
'-n',
'--nbins', dest=
'nbins', type=
'int', default=
None, help=
'number of bins')
91 parser.add_option(
'',
'--xmin', dest=
'xmin', default=
None, help=
'x axis minimum')
92 parser.add_option(
'',
'--xmax', dest=
'xmax', default=
None, help=
'x axis maximum')
93 parser.add_option(
'',
'--timeaxis', dest=
'timeaxis', action=
'store_true', default=
False, help=
'use time on x axis instead of run or LB numbers')
94 parser.add_option(
'',
'--talabel', dest=
'talabel', default=
None, help=
'time axis label (default: Time (timezone))')
95 parser.add_option(
'',
'--perbcid', dest=
'perbcid', action=
'store_true', default=
False, help=
'plot per BCID instead of vs time/LB')
96 parser.add_option(
'',
'--separation', dest=
'separation', action=
'store_true', default=
False, help=
'plot versus beam separation for scans')
97 parser.add_option(
'',
'--vsbunchpos', dest=
'vsbunchpos', action=
'store_true', default=
False, help=
'plot versus bunch position in train')
98 parser.add_option(
'',
'--ndivs', dest=
'ndivs', type=
'int', default=
None, help=
'Number of x axis divisions (ROOT format)')
99 parser.add_option(
'',
'--ymin', dest=
'ymin', type=
'float', default=
None, help=
'y axis minimum')
100 parser.add_option(
'',
'--ymax', dest=
'ymax', type=
'float', default=
None, help=
'y axis maximum')
101 parser.add_option(
'-y',
'--yscale', dest=
'yscale', type=
'float', default=1.0, help=
'y axis scale factor')
102 parser.add_option(
'-m',
'--msize', dest=
'msize', type=
'float', default=
None, help=
'set marker size')
103 parser.add_option(
'',
'--lsize', dest=
'lsize', type=
'float', default=
None, help=
'set axis label size')
104 parser.add_option(
'',
'--ydef', dest=
'ydef', action=
'store_true', default=
False, help=
'use default y range for given quantity')
105 parser.add_option(
'',
'--defaults', dest=
'defaults', default=
'Gen', help=
'choose varDef defauls (default: Gen')
106 parser.add_option(
'',
'--logy', dest=
'logy', action=
'store_true', default=
False, help=
'log scale')
107 parser.add_option(
'',
'--fit', dest=
'fit', default=
'', help=
'fit function (e.g. pol1)')
108 parser.add_option(
'',
'--optfit', dest=
'optfit', default=
'', help=
"fit options (default: '')")
109 parser.add_option(
'-c',
'--canvas', dest=
'canvas', default=
'', help=
'canvas size: default, page, wide, extrawide or square')
110 parser.add_option(
'',
'--xdivs', dest=
'xdivs', type=
'int', default=1, help=
'number of pads on canvas in x (needs -c, default: 1)')
111 parser.add_option(
'',
'--ydivs', dest=
'ydivs', type=
'int', default=1, help=
'number of pads on canvas in y (needs -c, default: 1)')
112 parser.add_option(
'',
'--optstat', dest=
'optstat', default=
'emruo', help=
'default OptStat value (Default: emruo)')
113 parser.add_option(
'',
'--ave', dest=
'ave', action=
'store_true', default=
False, help=
'show average on plot')
114 parser.add_option(
'',
'--newave', dest=
'newave', action=
'store_true', default=
False, help=
'replicate the functionality of the old aveBeamSpot.py script.')
115 parser.add_option(
'',
'--title', dest=
'title', default=
'', help=
'title text on plots')
116 parser.add_option(
'',
'--comment', dest=
'comment', default=
'', help=
'additional text (use semicolon to indicate line breaks)')
117 parser.add_option(
'',
'--datefmt', dest=
'datefmt', default=
'', help=
'date format')
118 parser.add_option(
'',
'--adatefmt', dest=
'adatefmt', default=
'', help=
'axis date format')
119 parser.add_option(
'',
'--plegend', dest=
'plegend', default=
'fit to groups of LBs', help=
'legend text for points')
120 parser.add_option(
'',
'--alegend', dest=
'alegend', default=
'average of data shown:', help=
'legend text for average')
121 parser.add_option(
'',
'--maxlegends', dest=
'maxlegends', type=
'int', default=10, help=
'maximum number of legend entries')
122 parser.add_option(
'',
'--omitfill', dest=
'omitfill', action=
'store_true', default=
False, help=
'remove any fill info from legend')
123 parser.add_option(
'',
'--omitrun', dest=
'omitrun', action=
'store_true', default=
False, help=
'remove any run info from legend')
124 parser.add_option(
'',
'--omittime', dest=
'omittime', action=
'store_true', default=
False, help=
'remove any time info from legend')
125 parser.add_option(
'',
'--public', dest=
'public', action=
'store_true', default=
False, help=
'use labelling for public plots')
126 parser.add_option(
'',
'--prelim', dest=
'prelim', action=
'store_true', default=
False, help=
'add ATLAS Preliminary to figure')
127 parser.add_option(
'',
'--approval', dest=
'approval', action=
'store_true', default=
False, help=
'Label figure ATLAS for approval')
128 parser.add_option(
'',
'--published', dest=
'published', action=
'store_true', default=
False, help=
'add ATLAS to figure')
129 parser.add_option(
'',
'--customlabel', dest=
'customlabel', default=
'', help=
'add custom label after ATLAS to figure')
130 parser.add_option(
'',
'--xtitoffset', dest=
'xtitoffset', type=
'float', default=
None, help=
'x axis title offset')
131 parser.add_option(
'',
'--ytitoffset', dest=
'ytitoffset', type=
'float', default=
None, help=
'y axis title offset')
132 parser.add_option(
'',
'--atlasx', dest=
'atlasx', type=
'float', default=
None, help=
'x position for drawing ATLAS (Preliminary) label')
133 parser.add_option(
'',
'--atlasy', dest=
'atlasy', type=
'float', default=
None, help=
'y position for drawing ATLAS (Preliminary) label')
134 parser.add_option(
'',
'--atlasdx', dest=
'atlasdx', type=
'float', default=
None, help=
'x position offset for drawing Preliminary label')
135 parser.add_option(
'-o',
'--output', dest=
'output', default=
'.gif', help=
'comma-separated list of output files or formats (default: .gif)')
136 parser.add_option(
'',
'--name', dest=
'name', default=
'BeamSpotNtPlots', help=
'base name for plots (default: BeamSpotNtPlots)')
137 parser.add_option(
'',
'--tgraphfile', dest=
'tgraphfile', default=
'', help=
'optional root file to save TGraph into')
138 parser.add_option(
'',
'--tag', dest=
'cooltag', default=
'', help=
'COOL tag for writing average into beam spot SQLite file (also determines file name)')
139 parser.add_option(
'-i',
'--interactive', dest=
'interactive', action=
'store_true', default=
False, help=
'interactive')
140 parser.add_option(
'-b',
'--batch', dest=
'batch', action=
'store_true', default=
False, help=
'run in batch mode')
141 parser.add_option(
'',
'--fullCorrelations', dest=
'fullCorrelations', action=
'store_true', default=
False, help=
'Get all correlations')
142 parser.add_option(
'',
'--scans', dest=
'scans', default=
'', help=
'comma-separated list of hypenated lb ranges for lumi scans')
143 parser.add_option(
'',
'--acqFlag', dest=
'acqFlag', default =
False, action=
'store_true', help=
'Cut on AcquistionFlag=1.0 for stationary points of VdM scan')
144 parser.add_option(
'',
'--overlayScans', dest=
'overlayScans', default =
False, action=
'store_true', help=
'overlay VdM scans on same plot')
145 parser.add_option(
'',
'--useAve', dest=
'useAve', action=
'store_true', default=
False, help=
'Average over poor fits in the beamspot -- performed during merging step')
146 (options,args) = parser.parse_args()
148 parser.error(
'wrong number of command line arguments')
151 if options.fillcooldata
and options.pseudoLbFile:
152 sys.exit(
'Options fillColl and pseudoLbFile are mutually exclusive')
156 os.unsetenv(
'DISPLAY')
160 import InDetBeamSpotExample
163 from InDetBeamSpotExample
import BeamSpotData
165 BeamSpotData.varDefs = getattr(BeamSpotData,
'varDefs'+options.defaults)
169 from InDetBeamSpotExample.Utils
import getUserName, getHostName
170 from InDetBeamSpotExample
import ROOTUtils
175 if options.interactive:
176 os.environ[
'PYTHONINSPECT'] =
'1'
179 os.environ[
'TZ'] = options.timezone
181 timeLabel =
'Time (%s)' % options.timezone
183 timeLabel =
'Local time'
185 timeLabel = options.talabel
187 if not options.datefmt:
189 options.datefmt =
'%b %Y'
191 options.datefmt =
'%a %b %d'
194 if options.atlasx==
None:
195 if options.published:
196 options.atlasx = 0.83
if 'wide' in options.canvas
else 0.8
198 options.atlasx = 0.72
if 'wide' in options.canvas
else 0.645
199 if options.atlasy==
None:
201 options.atlasy = 0.86
202 if options.atlasdx==
None:
203 options.atlasdx = 0.08
if 'wide' in options.canvas
else 0.115
205 ntClass = locals()[options.type]
208 if options.run!=
None:
209 nt.runMin = options.run
210 nt.runMax = options.run
211 if options.runMin!=
None:
212 nt.runMin = options.runMin
213 if options.runMax!=
None:
214 nt.runMax = options.runMax
215 if options.runExclude!=
None:
216 nt.runListExclude = [
int(r)
for r
in options.runExclude.split(
',')]
217 if options.fill!=
None:
218 nt.fillMin = options.fill
219 nt.fillMax = options.fill
220 if options.fillMin!=
None:
221 nt.fillMin = options.fillMin
222 if options.fillMax!=
None:
223 nt.fillMax = options.fillMax
224 if options.bcid!=
None:
225 nt.bcidMin = options.bcid
226 nt.bcidMax = options.bcid
227 if options.bcidMin!=
None:
228 nt.bcidMin = options.bcidMin
229 if options.bcidMax!=
None:
230 nt.bcidMax = options.bcidMax
231 if options.lbMin!=
None:
232 nt.lbMin = options.lbMin
233 if options.lbMax!=
None:
234 nt.lbMax = options.lbMax
235 if options.timeMin!=
None:
236 nt.timeMin = time.mktime(time.strptime(options.timeMin,
'%b %d %H:%M:%S %Y'))
237 if options.timeMax!=
None:
238 nt.timeMax = time.mktime(time.strptime(options.timeMax,
'%b %d %H:%M:%S %Y'))
240 nt.statusList = [
int(x)
for x
in options.status.split(
',')]
242 for p
in options.period.split(
','):
243 project,period = p.split(
'.')
244 location = os.path.normpath(options.periodDef +
'/' + project)
246 fileName = glob.glob(
'%s/%s.runs.list' % (location,period))[0]
249 sys.exit(
'ERROR: Definition file for period %s not found in directory %s' % (options.period, location))
252 sys.exit(
'ERROR: no runs found for requested periods')
262 if options.fullCorrelations:
263 nt =
ntClass(options.ntname,fullCorrelations=
True)
266 except Exception
as e:
267 sys.exit(
'ERROR: '+
str(e))
271 print (nt.cutSummary())
276 while i < len( allBSResultsInNt ):
277 b = allBSResultsInNt[i]
278 if b.status < 70
and b.sigmaZErr == 0:
279 print (
"Will change Z error for lb's " +
str(b.lbStart) +
" to " +
str(b.lbEnd) +
" which has " +
str(b.nValid) +
" verticies")
280 b.sigmaZErr = b.sigmaZ * 0.5
284 while i < len( allBSResultsInNt ):
285 b = allBSResultsInNt[i]
287 if b.status < 70
and b.nValid < 2000
and b.nValid < averagenVtx:
288 print (
"Will take an average for lb's " +
str(b.lbStart) +
" to " +
str(b.lbEnd) +
" which has " +
str(b.nValid) +
" verticies" )
294 if allBSResultsInNt[iNeg].status == 59
and allBSResultsInNt[iNeg].nValid > 2000 :
295 lastGoodEntry = allBSResultsInNt[iNeg]
296 print (
" --- Starting with lb : " +
str(lastGoodEntry.lbStart) +
" to " +
str(lastGoodEntry.lbEnd))
302 while iPos < len(allBSResultsInNt):
303 if allBSResultsInNt[iPos].status == 59
and allBSResultsInNt[iPos].nValid > 2000:
304 nextGoodEntry = allBSResultsInNt[iPos]
305 print (
" --- Ending with lb : " +
str(nextGoodEntry.lbStart) +
" to " +
str(nextGoodEntry.lbEnd))
310 if lastGoodEntry == b
and nextGoodEntry == b :
311 print (
"Failed to do average - no good entries were found")
316 if( ( nextGoodEntry == b
or abs(nextGoodEntry.lbStart - b.lbEnd) > abs(lbSize) )
and (lastGoodEntry == b
or abs(b.lbStart - lastGoodEntry.lbEnd) > abs(lbSize) ) ):
317 print (
"Failed to do average - entries were too far away")
322 varList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY',
'sigmaXY']
323 calc = BeamSpotAverage(varList ,weightedAverage=
True)
325 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) ):
328 if lastGoodEntry != b
and abs(b.lbStart - lastGoodEntry.lbEnd) <= abs(lbSize) :
329 calc.add(lastGoodEntry)
331 if nextGoodEntry != b
and abs(nextGoodEntry.lbStart - b.lbEnd) <= abs(lbSize) :
332 calc.add(nextGoodEntry)
338 bcopy = copy.deepcopy(b)
342 setattr(bcopy, var, ave[calc.varList.index(var)])
343 setattr(bcopy, var+
"Err", err[calc.varList.index(var)])
347 allBSResultsInNt.insert(i, bcopy)
357 while i < len( allBSResultsInNt ):
358 if allBSResultsInNt[i].status != 59:
364 if(lastValidEntry >= 0):
365 if allBSResultsInNt[nextValidEntry].lbStart != allBSResultsInNt[lastValidEntry].lbEnd + 1:
366 print (
"Missing Lumi block from {:>5d} to {:>5d}".
format( allBSResultsInNt[lastValidEntry].lbEnd + 1 , allBSResultsInNt[nextValidEntry].lbStart))
369 if allBSResultsInNt[nextValidEntry].lbStart - allBSResultsInNt[lastValidEntry].lbEnd + 1 > lbSize:
370 print (
"--Lumi block gap too large wont fill in the gap" )
371 elif (allBSResultsInNt[nextValidEntry].lbStart-1) - (allBSResultsInNt[lastValidEntry].lbEnd+1) < 0 :
372 print (
"Missing Lumi block is invalid from {:>5d} to {:>5d}".
format( allBSResultsInNt[lastValidEntry].lbEnd+1, allBSResultsInNt[nextValidEntry].lbStart -1))
374 varList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY',
'sigmaXY']
375 calc = BeamSpotAverage(varList ,weightedAverage=
True)
376 calc.add(allBSResultsInNt[nextValidEntry])
377 calc.add(allBSResultsInNt[lastValidEntry])
383 bcopy = copy.deepcopy(b)
387 setattr(bcopy, var, ave[calc.varList.index(var)])
388 setattr(bcopy, var+
"Err", err[calc.varList.index(var)])
397 bcopy.lbStart = allBSResultsInNt[lastValidEntry].lbEnd + 1
398 bcopy.lbEnd = allBSResultsInNt[nextValidEntry].lbStart-1
399 allBSResultsInNt.insert(lastValidEntry+1, bcopy)
403 lastValidEntry = nextValidEntry
413 self.
whatList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY',
'k']
416 showRuns=True, showFills=True, showTime=True, otherTitle=None, otherComment=None,
422 title = options.title
or varDef(var,
'title',var)
426 comments.append(otherComment)
428 comments.append(options.comment)
429 if showRuns
and not options.omitrun:
430 if self.
nt.selRunMin==self.
nt.selRunMax:
431 comments.append(
'Run %i' % self.
nt.selRunMin)
433 comments.append(
'Runs %i - %i' % (self.
nt.selRunMin,self.
nt.selRunMax))
434 if showFills
and not options.omitfill:
435 if self.
nt.selFillMin==self.
nt.selFillMax:
436 comments.append(
'Fill %i' % self.
nt.selFillMin)
438 comments.append(
'Fills %i - %i' % (self.
nt.selFillMin,self.
nt.selFillMax))
439 if showTime
and not options.omittime:
441 t1 = time.strftime(options.datefmt,time.localtime(self.
nt.selTimeMin))
442 t2 = time.strftime(options.datefmt,time.localtime(self.
nt.selTimeMax))
444 t1 = time.strftime(options.datefmt,time.localtime(self.
nt.selTimeMin))
445 t2 = time.strftime(options.datefmt,time.localtime(self.
nt.selTimeMax))
449 comments.append(
'%s - %s' % (t1,t2))
453 logoSize = options.lsize
if options.lsize
else 0.5
455 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,
True,offset=options.atlasdx,energy=options.energy,size=logoSize)
457 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,
False,offset=options.atlasdx,isForApproval=
True,energy=options.energy,size=logoSize)
458 if options.published:
459 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,
False,offset=options.atlasdx,energy=options.energy,size=logoSize)
460 if options.customlabel!=
"":
461 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,
False,offset=options.atlasdx,isForApproval=
False,customstring=options.customlabel,energy=options.energy,size=logoSize)
464 legendMinY =
max(0.91-0.07*len(legendList),0.2)
468 """Histogram of variable what.
470 If what is of the form NAME:VALUE, VALUE will be subtracted
471 from each entry in order to produce plots of measured minus
475 (what,shift) = what.split(
':')
479 ROOT.gStyle.SetOptStat(options.optstat)
480 title =
varDef(what,
'title',what)+
';'+
varDef(what,
'atit',what)
481 nBins = options.nbins
if options.nbins
else varDef(what,
'nBins',100)
482 xmin =
float(options.xmin)
if options.xmin!=
None else varDef(what,
'min',-100)
483 xmax =
float(options.xmax)
if options.xmax!=
None else varDef(what,
'max',+100)
484 h = self.
protect( ROOT.TH1F(what,title,nBins,xmin,xmax) )
487 h.GetYaxis().SetTitle(
'Number of fit results')
488 arescale =
varDef(what,
'arescale',1.0)
491 h.Fill(arescale*(getattr(b,what)-shift))
492 except Exception
as e:
493 print (
'ERROR filling histogram:',
str(e))
496 ROOT.gStyle.SetOptFit(1111)
497 h.Fit(options.fit,options.optfit)
499 ROOT.gPad.SetLogy(options.logy)
500 ndivs =
varDef(what,
'ndivs',override=options.ndivs)
502 h.GetXaxis().SetNdivisions(ndivs,0)
504 self.
writeText(what,[],
False,
False,
False)
506 self.
writeText(what,[],
not options.public,options.public)
509 """Profile histogram of variable what vs pileup.
511 If what is of the form NAME:VALUE, VALUE will be subtracted
512 from each entry in order to produce plots of measured minus
516 (what,shift) = what.split(
':')
520 ROOT.gStyle.SetOptStat(options.optstat)
521 title =
varDef(what,
'title',what)+
';Number of pileup vertices;'+
varDef(what,
'atit',what)
522 nBins = options.nbins
if options.nbins
else varDef(what,
'nBins',100)
523 xmin =
float(options.xmin)
if options.xmin!=
None else varDef(what,
'min',-100)
524 xmax =
float(options.xmax)
if options.xmax!=
None else varDef(what,
'max',+100)
525 h = self.
protect( ROOT.TProfile(what,title,nBins,0,nBins) )
528 h.GetYaxis().SetRangeUser(xmin,xmax)
529 arescale =
varDef(what,
'arescale',1.0)
532 h.Fill(getattr(b,
'pileup'),arescale*(getattr(b,what)-shift))
533 except Exception
as e:
534 print (
'ERROR filling histogram:',
str(e))
537 ROOT.gStyle.SetOptFit(1111)
538 h.Fit(options.fit,options.optfit)
540 ROOT.gPad.SetLogy(options.logy)
541 ndivs =
varDef(what,
'ndivs',override=options.ndivs)
543 h.GetYaxis().SetNdivisions(ndivs,0)
545 self.
writeText(what,[],
False,
False,
False)
547 self.
writeText(what,[],
not options.public,options.public)
550 """Pull histogram of variable what.
552 what must be of the form name:value, where value is the
553 correct value of variable name."""
555 (what,value) = what.split(
':')
558 print((
'ERROR: Illegal input %s for pull variable - must be of the form NAME:VALUE' % what))
560 ROOT.gStyle.SetOptStat(options.optstat)
562 nBins = options.nbins
if options.nbins
else varDef(what,
'nBins',100)
563 xmin =
float(options.xmin)
if options.xmin!=
None else -4.
564 xmax =
float(options.xmax)
if options.xmax!=
None else +4.
565 h = self.
protect( ROOT.TH1F(what,title,nBins,xmin,xmax) )
568 h.GetYaxis().SetTitle(
'Number of fit results')
572 h.Fill((getattr(b,what)-value)/getattr(b,whatErr))
573 except Exception
as e:
574 print (
'ERROR filling histogram:',
str(e))
577 ROOT.gStyle.SetOptFit(1111)
578 h.Fit(options.fit,options.optfit)
580 ROOT.gPad.SetLogy(options.logy)
582 h.GetXaxis().SetNdivisions(options.ndivs,0)
584 self.
writeText(what,[],
False,
False,
False)
586 self.
writeText(what,[],
not options.public,options.public)
589 """History of variable what vs LB or time."""
590 ROOT.gStyle.SetOptStat(0)
592 calc = BeamSpotAverage([what],weightedAverage=
not options.simpleaverage)
595 arescale =
varDef(what,
'arescale',1.0)
597 if b.sigmaX < 0.01
or b.sigmaY < 0.01:
598 print (
"OUTLIER ", b.run, b.lbStart, b.lbEnd, b.sigmaX, b.sigmaY)
599 if not b.bcid
in grDict:
600 grDict[b.bcid] = BeamSpotGraph(timeAxis=options.timeaxis, separationAxis=options.separation)
603 grDict[b.bcid].
add(b,what,arescale)
607 print (
'Plotting data from %i BCID ...\n' % len(grDict))
614 for gr
in [grDict.get(bcid)
for bcid
in grDict]:
615 xmin =
min(xmin,gr.xmin)
616 xmax =
max(xmax,gr.xmax)
617 ymin =
min(ymin,gr.ymin)
618 ymax =
max(ymax,gr.ymax)
627 xmax += .05*h
if len(grDict)==1
else 0.3*h
629 h = (ymax-ymin)/2*options.yscale
632 if options.xmin!=
None:
633 xmin = time.mktime(time.strptime(options.xmin,
'%b %d %H:%M:%S %Y'))
if options.timeaxis
else float(options.xmin)
634 if options.xmax!=
None:
635 xmax = time.mktime(time.strptime(options.xmax,
'%b %d %H:%M:%S %Y'))
if options.timeaxis
else float(options.xmax)
637 ymin =
varDef(what,
'min',-100)
638 ymax =
varDef(what,
'max',+100)
639 if options.ymin!=
None:
641 if options.ymax!=
None:
646 atit =
';%s;%s' % (timeLabel,
varDef(what,
'atit',what))
647 elif options.separation:
648 atit =
';%s;%s' % (
'Nominal Separation [mm]',
varDef(what,
'atit',what))
650 atit =
';%s;%s' % (
'Luminosity block number',
varDef(what,
'atit',what))
653 ROOT.gPad.SetLogy(options.logy)
655 xAxis = frame.GetXaxis()
656 yAxis = frame.GetYaxis()
657 xAxis.SetTimeDisplay(1)
662 xAxis.SetTimeOffset(0)
664 if (xmax-xmin)/86400 < 1:
665 xAxis.SetTimeFormat(
'%H:%M')
672 xAxis.SetTimeFormat(
'%b %d')
674 xAxis.SetTimeFormat(
'#splitline{%b %d}{%H:%M}')
675 xAxis.SetLabelOffset(0.02)
676 xAxis.SetTitleOffset(1.6)
678 xAxis.SetLabelSize(options.lsize)
679 xAxis.SetTitleSize(options.lsize)
680 yAxis.SetLabelSize(options.lsize)
681 yAxis.SetTitleSize(options.lsize)
683 xAxis.SetLabelSize(0.044)
685 xAxis.SetTimeFormat(options.adatefmt)
687 xAxis.SetNdivisions(options.ndivs,0)
688 frame.LabelsOption(
'd',
'X')
690 if options.xtitoffset:
691 xAxis.SetTitleOffset(options.xtitoffset)
692 if options.ytitoffset:
693 yAxis.SetTitleOffset(options.ytitoffset)
707 legendList.append([b,options.alegend,
'FL'])
708 legendList.append([
None,
'%s %s #pm %s %s' % (
fmtVal(what,mean,
True),
varDef(what,
'units'),
713 for bcid
in sorted(grDict.keys()):
717 name = what
if bcid==0
else '%s-bcid%04i' % (what,bcid)
718 tgraph = self.
protect( gr.getTGraph(name) )
721 if options.tgraphfile:
722 print (
'Saving TGraphErrors',tgraph.GetName(),
'to file',options.tgraphfile)
723 tgraphfile = ROOT.TFile(options.tgraphfile,
'UPDATE')
729 tgraph.SetMarkerSize(options.msize
if options.msize
else 0.8)
731 legendList.append([tgraph,options.plegend,
'PLE'])
733 tgraph.SetMarkerColor(styleFactory.nextColorStyle())
734 tgraph.SetMarkerStyle(styleFactory.nextMarkerStyle())
735 tgraph.SetMarkerSize(options.msize
if options.msize
else 1.2)
736 if len(legendList)<options.maxlegends:
737 text =
'All' if bcid==0
else 'BCID %i' % bcid
738 legendList.append([tgraph,text,
'PLE'])
742 if len(grDict)>options.maxlegends:
743 legendList.append([
None,
'...',
''])
746 if options.fit
and len(grDict)==1:
747 ROOT.gStyle.SetOptFit(1111)
749 tgraph.Fit(options.fit,
'',
'SAME', gr.xmin,gr.xmax)
752 legendX = 0.6
if len(grDict)==1
else 0.8
753 self.
writeText(what,legendList
if not options.public
else [],
not options.public,legendX=legendX)
756 """Variable what vs BCID."""
757 ROOT.gStyle.SetOptStat(0)
759 calc = BeamSpotAverage([what],weightedAverage=
not options.simpleaverage)
760 gr = BeamSpotGraph(bcidAxis=
True)
765 atit =
';%s;%s' % (
'BCID',
varDef(what,
'atit',what))
768 xmin =
max(-100,gr.xmin-100)
769 xmax =
min(3600,gr.xmax+100)
779 h = (ymax-ymin)/2*options.yscale
783 ymin =
varDef(what,
'min',-100)
784 ymax =
varDef(what,
'max',+100)
785 if options.ymin!=
None:
787 if options.ymax!=
None:
791 ROOT.gPad.SetLogy(options.logy)
805 legendList.append([b,options.alegend,
'FL'])
806 legendList.append([
None,
'%s %s #pm %s %s' % (
fmtVal(what,mean,
True),
varDef(what,
'units'),
810 name =
'%s-perBCID' % what
811 tgraph = self.
protect( gr.getTGraph(name) )
814 if options.tgraphfile:
815 print (
'Saving TGraphErrors',tgraph.GetName(),
'to file',options.tgraphfile)
816 tgraphfile = ROOT.TFile(options.tgraphfile,
'UPDATE')
819 tgraph.SetMarkerSize(options.msize
if options.msize
else 0.8)
821 legendList.append([tgraph,options.plegend,
'PLE'])
825 self.
writeText(what,legendList,
not options.public)
828 """Variable what vs bunch position in train."""
829 ROOT.gStyle.SetOptStat(0)
838 if b.bcid - lastb > trainGap:
842 bunchnumber = b.bcid - startb
844 if bunchnumber
in calcmap:
845 calcmap[bunchnumber].
add(b)
847 calcmap[bunchnumber] = BeamSpotAverage([what], weightedAverage =
not options.simpleaverage)
848 bunchnrs.append(bunchnumber)
850 gr = self.
protect( ROOT.TGraphErrors(len(bunchnrs)))
857 for bunchnr
in bunchnrs:
859 gr.SetPoint(counter, bunchnr, calcmap[bunchnr].ave[0])
860 gr.SetPointError(counter, 0.5, calcmap[bunchnr].err[0])
861 xmax =
max(xmax, bunchnr)
862 ymin =
min(ymin, calcmap[bunchnr].ave[0])
863 ymax =
max(ymax, calcmap[bunchnr].ave[0])
872 h = (ymax - ymin)/2*options.yscale
876 if options.xmin !=
None:
878 if options.xmax !=
None:
880 if options.ymin !=
None:
882 if options.ymax !=
None:
885 gr.SetMarkerSize(options.msize
if options.msize
else 0.8)
887 atit =
';%s;%s' % (
'Bunch position in train',
varDef(what,
'atit',what))
894 legendList.append([gr,options.plegend,
'PLE'])
896 self.
writeText(what,legendList,
not options.public)
899 """History of variable what vs LB, time or separation. Additionally overlap the results of more than one scan
902 ROOT.gStyle.SetOptStat(0)
904 calc = BeamSpotAverage([what],weightedAverage=
not options.simpleaverage)
907 scans = [(
int(s.split(
'-')[0]),
int(s.split(
'-')[1]))
for s
in options.scans.split(
',')]
911 if options.separation
and options.overlayScans:
913 scanGroup = [s
for s
in scans
if s[0] <= b.lbStart <= s[1]][0]
920 if not scanGroup
in grDict:
921 grDict[scanGroup] = BeamSpotGraph(timeAxis=options.timeaxis, separationAxis=options.separation)
922 grDict[scanGroup].
add(b,what)
926 print (
'Plotting data from %i scans ...\n' % len(grDict))
933 for gr
in [grDict.get(scan)
for scan
in grDict]:
934 xmin =
min(xmin,gr.xmin)
935 xmax =
max(xmax,gr.xmax)
936 ymin =
min(ymin,gr.ymin)
937 ymax =
max(ymax,gr.ymax)
946 xmax += .05*h
if len(grDict)==1
else 0.3*h
948 h = (ymax-ymin)/2*options.yscale
951 if options.xmin!=
None:
952 xmin = time.mktime(time.strptime(options.xmin,
'%b %d %H:%M:%S %Y'))
if options.timeaxis
else float(options.xmin)
953 if options.xmax!=
None:
954 xmax = time.mktime(time.strptime(options.xmax,
'%b %d %H:%M:%S %Y'))
if options.timeaxis
else float(options.xmax)
956 ymin =
varDef(what,
'min',-100)
957 ymax =
varDef(what,
'max',+100)
958 if options.ymin!=
None:
960 if options.ymax!=
None:
965 atit =
';%s;%s' % (timeLabel,
varDef(what,
'atit',what))
966 elif options.separation:
967 atit =
';%s;%s' % (
'Nominal Separation [mm]',
varDef(what,
'atit',what))
969 atit =
';%s;%s' % (
'Luminosity block number',
varDef(what,
'atit',what))
972 ROOT.gPad.SetLogy(options.logy)
974 xAxis = frame.GetXaxis()
975 xAxis.SetTimeDisplay(1)
976 if (xmax-xmin)/86400 < 1:
977 xAxis.SetTimeFormat(
'%H:%M')
983 xAxis.SetTimeFormat(
'#splitline{%b %d}{%H:%M}')
984 xAxis.SetLabelOffset(0.025)
985 xAxis.SetTitleOffset(1.6)
987 xAxis.SetTimeFormat(options.adatefmt)
989 xAxis.SetNdivisions(options.ndivs,0)
990 frame.LabelsOption(
'd',
'X')
1004 legendList.append([b,options.alegend,
'FL'])
1005 legendList.append([
None,
'%s %s #pm %s %s' % (
fmtVal(what,mean,
True),
varDef(what,
'units'),
1010 for scan
in sorted(grDict.keys()):
1014 name = what
if scan==0
else '%s-scanoverlay' % (what)
1015 tgraph = self.
protect( gr.getTGraph(name) )
1018 if options.tgraphfile:
1019 print (
'Saving TGraphErrors',tgraph.GetName(),
'to file',options.tgraphfile)
1020 tgraphfile = ROOT.TFile(options.tgraphfile,
'UPDATE')
1026 tgraph.SetMarkerSize(options.msize
if options.msize
else 0.8)
1028 legendList.append([tgraph,options.plegend,
'PLE'])
1030 tgraph.SetMarkerColor(styleFactory.nextColorStyle())
1031 tgraph.SetMarkerStyle(styleFactory.nextMarkerStyle())
1032 tgraph.SetMarkerSize(options.msize
if options.msize
else 1.2)
1033 if len(legendList)<options.maxlegends:
1034 text =
'All' if scan==0
else 'scan %i - %i' % scan
1035 legendList.append([tgraph,text,
'PLE'])
1039 if len(grDict)>options.maxlegends:
1040 legendList.append([
None,
'...',
''])
1043 if options.fit
and len(grDict)==1:
1044 ROOT.gStyle.SetOptFit(1111)
1046 tgraph.Fit(options.fit,
'',
'SAME',gr.xmin,gr.xmax)
1049 legendX = 0.6
if len(grDict)==1
else 0.8
1050 self.
writeText(what,legendList,
not options.public,legendX=legendX)
1057 if cmd==
'dump' and len(args)==1:
1061 b.dump(options.verbose)
1069 tableTemplate =
r"""
1070 \documentclass[12pt,twoside]{article}
1071 \usepackage[landscape]{geometry}
1072 \RequirePackage{xspace}
1073 \def\lumposx {\ensuremath{\overline{x}_{\mathcal{L}}}\xspace}
1074 \def\lumposy {\ensuremath{\overline{y}_{\mathcal{L}}}\xspace}
1075 \def\lumposz {\ensuremath{\overline{z}_{\mathcal{L}}}\xspace}
1076 \def\lumsigx {\ensuremath{\sigma_{x{\mathcal L}}}\xspace}
1077 \def\lumsigy {\ensuremath{\sigma_{y{\mathcal L}}}\xspace}
1078 \def\lumsigz {\ensuremath{\sigma_{z{\mathcal L}}}\xspace}
1079 \def\lumtiltx {\ensuremath{\overline{x}_{\mathcal{L}}'}\xspace}
1080 \def\lumtilty {\ensuremath{\overline{y}_{\mathcal{L}}'}\xspace}
1081 \def\lumrhoxy {\ensuremath{\rho_{xy}}\xspace}
1101 if cmd==
'maketable' and len(args)==1:
1102 if options.varlist
is None:
1104 varList = [
'status',
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'k']
1106 varList = options.varlist.split(
',')
1113 cols.append(
r'%s $\pm$ %s' % (
fmtVal(v,getattr(b,v),
True,useAlternate=
True),
1114 fmtVal(v,getattr(b,v+
'Err'),
True,useAlternate=
True)))
1116 cols.append(
'%10s' % (
fmtVal(v,getattr(b,v),
True,useAlternate=
True)))
1117 rows.append(
'%s \\\\' %
' & '.
join(cols))
1119 print (tableTemplate % (len(varList)*
'c',
1120 ' & '.
join([
'%s' %
varDef(n,
'latexheader',useAlternate=
True)
for n
in varList]),
1129 if cmd==
'inspect' and len(args)==1:
1135 if not b.run
in runInfo:
1143 if runInfo[r][
'lbStart']
is None or b.lbStart<runInfo[r][
'lbStart']: runInfo[r][
'lbStart'] = b.lbStart
1144 if runInfo[r][
'lbEnd']
is None or b.lbEnd>runInfo[r][
'lbEnd']: runInfo[r][
'lbEnd'] = b.lbEnd
1145 runInfo[r][
'status'].
add(b.status)
1146 if b.timeStart
and b.timeEnd
and b.fill: runInfo[r][
'hasCOOL'] =
True
1147 if b.posXErr: runInfo[r][
'hasErrors'] =
True
1148 for r
in sorted(runInfo.keys()):
1149 print (
'%6s [ %10i, %10i ] %7s %9s fit status = %s' % (r,
1150 runInfo[r][
'lbStart'],
1151 runInfo[r][
'lbEnd'],
1152 'hasCOOL' if runInfo[r][
'hasCOOL']
else '',
1153 'hasErrors' if runInfo[r][
'hasErrors']
else '',
1156 print (
'%i runs found\n' % len(runInfo.keys()))
1164 if cmd==
'merge' and len(args)==2:
1165 srcNtClass = locals()[options.srctype]
1166 srcNt =
srcNtClass(args[1],fullCorrelations=options.fullCorrelations)
1168 print (
'\nImporting from '+srcNt.summary())
1169 print (srcNt.cutSummary())
1170 dstNt =
ntClass(options.ntname,
True,fullCorrelations=options.fullCorrelations)
1171 print (
'\nMerging into '+dstNt.summary())
1176 allBSResultsInNt = []
1178 allBSResultsInNt.append( b )
1181 totalVtxs += b.nValid
1182 lbSize += b.lbEnd - b.lbStart
1184 if totalEntries == 0:
1186 averagenVtx = totalVtxs/totalEntries
1187 print (
'Average Entries: '+
str(averagenVtx))
1190 lbSize = lbSize/totalEntries + 1
1191 print (
'Average number of lb used for fit: '+
str( lbSize ))
1195 allBSResultsInNt.sort()
1198 allBSResultsInNt.sort()
1201 for b
in allBSResultsInNt:
1202 if options.fillcooldata:
1203 b.fillDataFromCOOL()
1204 if options.pseudoLbFile:
1205 b.fillDataFromPseudoLb(options.pseudoLbFile,
float(options.pseudoLbTimeUnit))
1206 if options.filldqdata:
1208 if not options.quiet:
1209 b.dump(options.verbose)
1218 if cmd==
'ave' and len(args)==1:
1220 if options.varlist
is None:
1222 varList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY']
1224 varList.append(
'sigmaXY')
1226 varList = options.varlist.split(
',')
1230 plots.whatList = varList
1231 plots.saveAsList = options.output.split(
',')
1232 plots.allCanvasSize =
'landscape'
1233 plots.allCanvasDivs = (3,3)
1235 plots.genPlot(
'all',
'hist')
1237 plots.genPlot(
'all',
'plot')
1241 calc = BeamSpotAverage(varList,weightedAverage=
not options.simpleaverage)
1242 if options.lumicalcnt
is not None:
1243 calc.readLumiData(options.lumicalcnt)
1247 if options.verbose
or options.debug:
1248 b.dump(options.debug)
1250 minrun =
min(b.run,minrun)
1251 maxrun =
max(b.run,maxrun)
1257 print (
'... %i warnings detected' % calc.nWarnings)
1258 if options.lumicalcnt
is not None:
1259 print (
'... integrated luminosity of selected runs = %6.1f / pb' % (calc.sumw[0]/1.E6))
1261 if options.splittable:
1262 varRanges = [
range(options.splittable),
1263 range(options.splittable,len(calc.varList)) ]
1265 varRanges = [
range(len(calc.varList)) ]
1272 latexheader =
'Period '
1273 latexrow =
'%s' % options.period.replace(
'_',
r'\_')
1274 print (
'\nAverage beam spot parameters (part %i):\n' % iTable)
1276 parName = calc.varList[i]
1277 print (
'%7s: %s +- %s %-3s (RMS = %s)' % (parName,
1282 latexheader +=
'& %s ' %
varDef(parName,
'latexheader',parName,useAlternate=
True)
1284 latexrow +=
r' & %s $\pm$ %s' % (
fmtVal(parName,ave[i],useAlternate=
True),
fmtVal(parName,rms[i],useAlternate=
True))
1286 latexrow +=
r' & %s $\pm$ %s' % (
fmtVal(parName,ave[i],useAlternate=
True),
fmtVal(parName,err[i],useAlternate=
True))
1288 print (
'\nLaTeX code for table %i:\n' % iTable)
1289 print (
'\\begin{table}[htbp]\n\\begin{center}\n\\begin{tabular}{l%s}' % (len(r)*
'c'))
1290 print (
r'\hline \hline')
1291 print (latexheader,
r'\\\\ \hline')
1293 print (latexrow,
' \\\\')
1295 print (
r'\hline \hline')
1296 print (
'\\end{tabular}\n\\end{center}\n\\caption{\\label{tab:}}\n\\end{table}')
1298 if options.cooltag
and minrun<1e10:
1300 sqliteFile= options.cooltag+
'.db'
1303 if not options.newave:
1304 print (
'\nWriting average to COOL SQLite file %s (folder tag = %s) ...' % (sqliteFile,options.cooltag))
1307 posX=ave[calc.varList.index(
'posX')],
1308 posY=ave[calc.varList.index(
'posY')],
1309 posZ=ave[calc.varList.index(
'posZ')],
1310 sigmaX=ave[calc.varList.index(
'sigmaX')],
1311 sigmaY=ave[calc.varList.index(
'sigmaY')],
1312 sigmaZ=ave[calc.varList.index(
'sigmaZ')],
1313 tiltX=ave[calc.varList.index(
'tiltX')],
1314 tiltY=ave[calc.varList.index(
'tiltY')],
1315 sigmaXY=ave[calc.varList.index(
'sigmaXY')],
1316 posXErr=err[calc.varList.index(
'posX')],
1317 posYErr=err[calc.varList.index(
'posY')],
1318 posZErr=err[calc.varList.index(
'posZ')],
1319 sigmaXErr=err[calc.varList.index(
'sigmaX')],
1320 sigmaYErr=err[calc.varList.index(
'sigmaY')],
1321 sigmaZErr=err[calc.varList.index(
'sigmaZ')],
1322 tiltXErr=err[calc.varList.index(
'tiltX')],
1323 tiltYErr=err[calc.varList.index(
'tiltY')],
1324 sigmaXYErr=err[calc.varList.index(
'sigmaXY')])
1327 print (
'\nWriting average and LB info to COOL SQLite file %s (folder tag = %s) ...' % (sqliteFile,
"nominal"))
1329 runMin=
int(minrun),runMax=
int(maxrun),
1331 posX=ave[calc.varList.index(
'posX')],
1332 posY=ave[calc.varList.index(
'posY')],
1333 posZ=ave[calc.varList.index(
'posZ')],
1334 sigmaX=ave[calc.varList.index(
'sigmaX')],
1335 sigmaY=ave[calc.varList.index(
'sigmaY')],
1336 sigmaZ=ave[calc.varList.index(
'sigmaZ')],
1337 tiltX=ave[calc.varList.index(
'tiltX')],
1338 tiltY=ave[calc.varList.index(
'tiltY')],
1339 sigmaXY=ave[calc.varList.index(
'sigmaXY')],
1340 posXErr=err[calc.varList.index(
'posX')],
1341 posYErr=err[calc.varList.index(
'posY')],
1342 posZErr=err[calc.varList.index(
'posZ')],
1343 sigmaXErr=err[calc.varList.index(
'sigmaX')],
1344 sigmaYErr=err[calc.varList.index(
'sigmaY')],
1345 sigmaZErr=err[calc.varList.index(
'sigmaZ')],
1346 tiltXErr=err[calc.varList.index(
'tiltX')],
1347 tiltYErr=err[calc.varList.index(
'tiltY')],
1348 sigmaXYErr=err[calc.varList.index(
'sigmaXY')])
1350 print (
'Copying beam spot data from',options.ntname)
1352 if options.lbMin
and options.lbMin>b.lbStart:
1354 if options.lbMax
and options.lbMax<b.lbEnd+1:
1357 runEndInt = b.runEnd
1358 except AttributeError:
1361 if b.status
in nt.statusList:
1368 posX=b.posX, posY=b.posY, posZ=b.posZ,
1369 sigmaX=b.sigmaX, sigmaY=b.sigmaY, sigmaZ=b.sigmaZ,
1370 tiltX=b.tiltX, tiltY=b.tiltY,
1371 sigmaXY=b.rhoXY*b.sigmaX*b.sigmaY,
1372 posXErr=b.posXErr, posYErr=b.posYErr, posZErr=b.posZErr,
1373 sigmaXErr=b.sigmaXErr, sigmaYErr=b.sigmaYErr, sigmaZErr=b.sigmaZErr,
1374 tiltXErr=b.tiltXErr, tiltYErr=b.tiltYErr,
1375 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) ) )
1382 if (cmd==
'hist' or cmd==
'histvspileup' or cmd==
'pull')
and len(args)==2:
1386 plots.saveAsList = options.output.split(
',')
1388 plots.singleCanvasSize = options.canvas
1389 plots.allCanvasSize = options.canvas
1390 plots.allCanvasDivs = (options.xdivs,options.ydivs)
1392 plots.whatList = var.split(
',')
1393 plots.genPlot(
'all',cmd)
1395 plots.genPlot(var,cmd)
1402 if cmd==
'plot' and len(args)==2:
1406 plots.saveAsList = options.output.split(
',')
1408 plots.singleCanvasSize = options.canvas
1409 plots.allCanvasSize = options.canvas
1410 plots.allCanvasDivs = (options.xdivs,options.ydivs)
1412 plotType =
'perbcid'
1413 elif options.vsbunchpos:
1414 plotType =
'vsBunchPos'
1418 plots.whatList = var.split(
',')
1419 plots.genPlot(
'all',plotType)
1421 plots.genPlot(var,plotType)
1428 if cmd==
'summary' and len(args)==1:
1430 if not options.msize:
1433 plots.saveAsList = options.output.split(
',')
1434 plots.allCanvasSize =
'landscape'
1437 if "COOL-Current" not in options.ntname:
1438 plots.allCanvasDivs = (4,3)
1439 plots.whatList = [
'posX',
'posY',
'posZ',
'k',
'sigmaX',
'sigmaY',
'sigmaZ',
'nValid',
'tiltX',
'tiltY',
'rhoXY']
1440 datasetinfo=options.ntname.replace(
"-DB_BEAMSPOT",
"").
split(
'.')
1441 labels=[
"%s.%s.%s.%s" % (datasetinfo[0],datasetinfo[1],datasetinfo[2],datasetinfo[3])]
1442 labels+=[
"Generated on %s, at %s (%s)" % (time.strftime(
"%x"), time.strftime(
"%X"), time.strftime(
"%Z"))]
1444 plots.allCanvasDivs = (3,3)
1445 plots.whatList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY']
1450 plots.genPlot(
'all',
'perbcid',labels=labels)
1451 elif options.vsbunchpos:
1452 plots.whatList.remove(
'nValid')
1453 plots.genPlot(
'all',
'vsBunchPos',labels=labels)
1455 plots.genPlot(
'all',
'plot',labels=labels)
1463 if cmd==
'ascii' and len(args)==2:
1465 ascii =
open(args[1],
'w')
1466 ascii.write(
'# Beam spot data file\n')
1467 ascii.write(
'# Generated %s by %s on host %s using command:\n' % (time.asctime(),
getUserName(),
getHostName()))
1468 ascii.write(
'# %s\n' % qcmd)
1472 ascii.write(
'%s ' %
str(b.fill))
1473 ascii.write(
'%s ' %
str(b.timeStart - time0 +
int((b.timeEnd-b.timeStart)/2)))
1474 ascii.write(
'%s ' %
str(b.posX))
1475 ascii.write(
'%s ' %
str(b.posXErr))
1476 ascii.write(
'%s ' %
str(b.posY))
1477 ascii.write(
'%s ' %
str(b.posYErr))
1478 ascii.write(
'%s ' %
str(b.posZ))
1479 ascii.write(
'%s ' %
str(b.posZErr))
1480 ascii.write(
'0 0 0 0 0 0 ')
1481 ascii.write(
'%s ' %
str(b.sigmaX))
1482 ascii.write(
'%s ' %
str(b.sigmaXErr))
1483 ascii.write(
'%s ' %
str(b.sigmaY))
1484 ascii.write(
'%s ' %
str(b.sigmaYErr))
1485 ascii.write(
'%s ' %
str(b.sigmaZ))
1486 ascii.write(
'%s ' %
str(b.sigmaZErr))
1487 ascii.write(
'0 0 0\n')
1492 if cmd==
'scan' and len(args)==1:
1494 if not options.msize:
1497 if options.timeaxis:
1499 elif options.separation:
1508 plots.allCanvasSize =
'landscape'
1509 plots.allCanvasDivs = (3,3)
1510 plots.whatList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY']
1511 plots.saveAsList = [
'%s-scanfull-%s-all.gif' %(options.name,xtype),
1512 '%s-scanfull-%s-all.eps' %(options.name,xtype),]
1514 if options.separation
and options.overlayScans:
1515 plots.genPlot(
'all',
'plotscan')
1517 plots.genPlot(
'all',
'plot')
1519 plots.whatList.append(
'k')
1522 plots.singleCanvasSize =
'wide'
1523 for var
in plots.whatList:
1524 plots.saveAsList = [
'%s-scanfull-%s-%s.gif' %(options.name,xtype,var),
1525 '%s-scanfull-%s-%s.eps' %(options.name,xtype,var) ]
1526 if options.separation
and options.overlayScans:
1527 graphs = plots.genPlot(var,
'plotscan')
1529 graphs = plots.genPlot(var,
'plot')
1534 scans = [(
int(s.split(
'-')[0]),
int(s.split(
'-')[1]))
for s
in options.scans.split(
',')]
1538 options.overlayScans =
False
1539 for (lbMin, lbMax)
in scans:
1547 plots.allCanvasSize =
'landscape'
1548 plots.allCanvasDivs = (3,3)
1549 plots.whatList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY']
1550 plots.saveAsList = [
'%s-scan%s-%s-%s-all.gif' %(options.name,lbMin,lbMax,xtype),
1551 '%s-scan%s-%s-%s-all.eps' %(options.name,lbMin,lbMax,xtype) ]
1552 plots.genPlot(
'all',
'plot')
1554 plots.whatList.append(
'k')
1557 plots.singleCanvasSize =
'default'
1558 for var
in plots.whatList:
1559 plots.saveAsList = [
'%s-scan%s-%s-%s-%s.gif' %(options.name,lbMin,lbMax,xtype,var),
1560 '%s-scan%s-%s-%s-%s.eps' %(options.name,lbMin,lbMax,xtype,var) ]
1561 graphs = plots.genPlot(var,
'plot')
1567 print (
'ERROR: Illegal command or number of arguments')