5 from __future__
import print_function
8 beamspotnt is a command line utility for beam spot ntuples.
10 __author__ =
'Juerg Beringer'
11 __version__ =
'beamspotnt.py atlas/athena'
12 __usage__ =
'''%prog [options] command [args ...]
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
31 beamspotnt -t BeamSpotCOOL -f IndetBeampos-ES1-UPD2 --ru 165815 --rl 165815 dump
35 periodDef =
'/afs/cern.ch/user/a/atlidbs/nt/DataPeriods'
37 import sys, os, time, glob, re, copy, math
42 if re.search(
'\s|\*|\?',s):
44 qargv.append(
'"%s"' % re.sub(
'"',
"'",s))
46 qargv.append(
"'%s'" % re.sub(
"'",
'"',s))
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')
152 (options,args) = parser.parse_args()
154 parser.error(
'wrong number of command line arguments')
157 if options.fillcooldata
and options.pseudoLbFile:
158 sys.exit(
'Options fillColl and pseudoLbFile are mutually exclusive')
162 os.unsetenv(
'DISPLAY')
166 import InDetBeamSpotExample
169 from InDetBeamSpotExample
import BeamSpotData
171 BeamSpotData.varDefs = getattr(BeamSpotData,
'varDefs'+options.defaults)
175 from InDetBeamSpotExample.Utils
import getUserName, getHostName
176 from InDetBeamSpotExample
import ROOTUtils
181 if options.interactive:
182 os.environ[
'PYTHONINSPECT'] =
'1'
185 os.environ[
'TZ'] = options.timezone
187 timeLabel =
'Time (%s)' % options.timezone
189 timeLabel =
'Local time'
191 timeLabel = options.talabel
193 if not options.datefmt:
195 options.datefmt =
'%b %Y'
197 options.datefmt =
'%a %b %d'
200 if options.atlasx==
None:
201 if options.published:
202 options.atlasx = 0.83
if 'wide' in options.canvas
else 0.8
204 options.atlasx = 0.72
if 'wide' in options.canvas
else 0.645
205 if options.atlasy==
None:
207 options.atlasy = 0.86
208 if options.atlasdx==
None:
209 options.atlasdx = 0.08
if 'wide' in options.canvas
else 0.115
211 ntClass = locals()[options.type]
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'))
246 nt.statusList = [
int(x)
for x
in options.status.split(
',')]
248 for p
in options.period.split(
','):
249 project,period = p.split(
'.')
250 location = os.path.normpath(options.periodDef +
'/' + project)
252 fileName = glob.glob(
'%s/%s.runs.list' % (location,period))[0]
255 sys.exit(
'ERROR: Definition file for period %s not found in directory %s' % (options.period, location))
258 sys.exit(
'ERROR: no runs found for requested periods')
268 if options.fullCorrelations:
269 nt =
ntClass(options.ntname,fullCorrelations=
True)
272 except Exception
as e:
273 sys.exit(
'ERROR: '+
str(e))
277 print (nt.cutSummary())
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
290 while i < len( allBSResultsInNt ):
291 b = allBSResultsInNt[i]
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" )
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))
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))
316 if lastGoodEntry == b
and nextGoodEntry == b :
317 print (
"Failed to do average - no good entries were found")
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")
328 varList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY']
330 varList.append(
'sigmaXY')
331 calc = BeamSpotAverage(varList ,weightedAverage=
True)
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) ):
336 if lastGoodEntry != b
and abs(b.lbStart - lastGoodEntry.lbEnd) <= abs(lbSize) :
337 calc.add(lastGoodEntry)
339 if nextGoodEntry != b
and abs(nextGoodEntry.lbStart - b.lbEnd) <= abs(lbSize) :
340 calc.add(nextGoodEntry)
346 bcopy = copy.deepcopy(b)
349 setattr(bcopy, var, ave[calc.varList.index(var)])
350 setattr(bcopy, var+
"Err", err[calc.varList.index(var)])
354 allBSResultsInNt.insert(i, bcopy)
364 while i < len( allBSResultsInNt ):
365 if allBSResultsInNt[i].status != 59:
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))
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))
381 varList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY']
383 varList.append(
'sigmaXY')
384 calc = BeamSpotAverage(varList ,weightedAverage=
True)
385 calc.add(allBSResultsInNt[nextValidEntry])
386 calc.add(allBSResultsInNt[lastValidEntry])
392 bcopy = copy.deepcopy(b)
395 setattr(bcopy, var, ave[calc.varList.index(var)])
396 setattr(bcopy, var+
"Err", err[calc.varList.index(var)])
405 bcopy.lbStart = allBSResultsInNt[lastValidEntry].lbEnd + 1
406 bcopy.lbEnd = allBSResultsInNt[nextValidEntry].lbStart-1
407 allBSResultsInNt.insert(lastValidEntry+1, bcopy)
411 lastValidEntry = nextValidEntry
421 self.
whatList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY',
'k',
'nValid']
424 showRuns=True, showFills=True, showTime=True, otherTitle=None, otherComment=None,
430 title = options.title
or varDef(var,
'title',var)
434 comments.append(otherComment)
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)
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)
446 comments.append(
'Fills %i - %i' % (self.
nt.selFillMin,self.
nt.selFillMax))
447 if showTime
and not options.omittime:
449 t1 = time.strftime(options.datefmt,time.localtime(self.
nt.selTimeMin))
450 t2 = time.strftime(options.datefmt,time.localtime(self.
nt.selTimeMax))
452 t1 = time.strftime(options.datefmt,time.localtime(self.
nt.selTimeMin))
453 t2 = time.strftime(options.datefmt,time.localtime(self.
nt.selTimeMax))
457 comments.append(
'%s - %s' % (t1,t2))
461 logoSize = options.lsize
if options.lsize
else 0.5
463 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,
True,offset=options.atlasdx,energy=options.energy,size=logoSize)
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)
472 legendMinY =
max(0.91-0.07*len(legendList),0.2)
476 """Histogram of variable what.
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
483 (what,shift) = what.split(
':')
487 ROOT.gStyle.SetOptStat(options.optstat)
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) )
495 h.GetYaxis().SetTitle(
'Number of fit results')
496 arescale =
varDef(what,
'arescale',1.0)
499 h.Fill(arescale*(getattr(b,what)-shift))
500 except Exception
as e:
501 print (
'ERROR filling histogram:',
str(e))
504 ROOT.gStyle.SetOptFit(1111)
505 h.Fit(options.fit,options.optfit)
507 ROOT.gPad.SetLogy(options.logy)
508 ndivs =
varDef(what,
'ndivs',override=options.ndivs)
510 h.GetXaxis().SetNdivisions(ndivs,0)
512 self.
writeText(what,[],
False,
False,
False)
514 self.
writeText(what,[],
not options.public,options.public)
517 """Profile histogram of variable what vs pileup.
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
524 (what,shift) = what.split(
':')
528 ROOT.gStyle.SetOptStat(options.optstat)
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) )
536 h.GetYaxis().SetRangeUser(xmin,xmax)
537 arescale =
varDef(what,
'arescale',1.0)
540 h.Fill(getattr(b,
'pileup'),arescale*(getattr(b,what)-shift))
541 except Exception
as e:
542 print (
'ERROR filling histogram:',
str(e))
545 ROOT.gStyle.SetOptFit(1111)
546 h.Fit(options.fit,options.optfit)
548 ROOT.gPad.SetLogy(options.logy)
549 ndivs =
varDef(what,
'ndivs',override=options.ndivs)
551 h.GetYaxis().SetNdivisions(ndivs,0)
553 self.
writeText(what,[],
False,
False,
False)
555 self.
writeText(what,[],
not options.public,options.public)
558 """Pull histogram of variable what.
560 what must be of the form name:value, where value is the
561 correct value of variable name."""
563 (what,value) = what.split(
':')
566 print((
'ERROR: Illegal input %s for pull variable - must be of the form NAME:VALUE' % what))
568 ROOT.gStyle.SetOptStat(options.optstat)
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) )
576 h.GetYaxis().SetTitle(
'Number of fit results')
580 h.Fill((getattr(b,what)-value)/getattr(b,whatErr))
581 except Exception
as e:
582 print (
'ERROR filling histogram:',
str(e))
585 ROOT.gStyle.SetOptFit(1111)
586 h.Fit(options.fit,options.optfit)
588 ROOT.gPad.SetLogy(options.logy)
590 h.GetXaxis().SetNdivisions(options.ndivs,0)
592 self.
writeText(what,[],
False,
False,
False)
594 self.
writeText(what,[],
not options.public,options.public)
597 """History of variable what vs LB or time."""
598 ROOT.gStyle.SetOptStat(0)
600 calc = BeamSpotAverage([what],weightedAverage=
not options.simpleaverage)
603 arescale =
varDef(what,
'arescale',1.0)
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)
611 grDict[b.bcid].
add(b,what,arescale)
615 print (
'Plotting data from %i BCID ...\n' % len(grDict))
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)
635 xmax += .05*h
if len(grDict)==1
else 0.3*h
637 h = (ymax-ymin)/2*options.yscale
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)
645 ymin =
varDef(what,
'min',-100)
646 ymax =
varDef(what,
'max',+100)
647 if options.ymin!=
None:
649 if options.ymax!=
None:
654 atit =
';%s;%s' % (timeLabel,
varDef(what,
'atit',what))
655 elif options.separation:
656 atit =
';%s;%s' % (
'Nominal Separation [mm]',
varDef(what,
'atit',what))
658 atit =
';%s;%s' % (
'Luminosity block number',
varDef(what,
'atit',what))
661 ROOT.gPad.SetLogy(options.logy)
663 xAxis = frame.GetXaxis()
664 yAxis = frame.GetYaxis()
665 xAxis.SetTimeDisplay(1)
670 xAxis.SetTimeOffset(0)
672 if (xmax-xmin)/86400 < 1:
673 xAxis.SetTimeFormat(
'%H:%M')
680 xAxis.SetTimeFormat(
'%b %d')
682 xAxis.SetTimeFormat(
'#splitline{%b %d}{%H:%M}')
683 xAxis.SetLabelOffset(0.02)
684 xAxis.SetTitleOffset(1.6)
686 xAxis.SetLabelSize(options.lsize)
687 xAxis.SetTitleSize(options.lsize)
688 yAxis.SetLabelSize(options.lsize)
689 yAxis.SetTitleSize(options.lsize)
691 xAxis.SetLabelSize(0.044)
693 xAxis.SetTimeFormat(options.adatefmt)
695 xAxis.SetNdivisions(options.ndivs,0)
696 frame.LabelsOption(
'd',
'X')
698 if options.xtitoffset:
699 xAxis.SetTitleOffset(options.xtitoffset)
700 if options.ytitoffset:
701 yAxis.SetTitleOffset(options.ytitoffset)
715 legendList.append([b,options.alegend,
'FL'])
716 legendList.append([
None,
'%s %s #pm %s %s' % (
fmtVal(what,mean,
True),
varDef(what,
'units'),
721 for bcid
in sorted(grDict.keys()):
725 name = what
if bcid==0
else '%s-bcid%04i' % (what,bcid)
726 tgraph = self.
protect( gr.getTGraph(name) )
729 if options.tgraphfile:
730 print (
'Saving TGraphErrors',tgraph.GetName(),
'to file',options.tgraphfile)
731 tgraphfile = ROOT.TFile(options.tgraphfile,
'UPDATE')
737 tgraph.SetMarkerSize(options.msize
if options.msize
else 0.8)
739 legendList.append([tgraph,options.plegend,
'PLE'])
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'])
750 if options.fit
and len(grDict)==1:
751 ROOT.gStyle.SetOptFit(1111)
753 tgraph.Fit(options.fit,
'',
'SAME', gr.xmin,gr.xmax)
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)
760 """Variable what vs BCID."""
761 ROOT.gStyle.SetOptStat(0)
763 calc = BeamSpotAverage([what],weightedAverage=
not options.simpleaverage)
764 gr = BeamSpotGraph(bcidAxis=
True)
769 atit =
';%s;%s' % (
'BCID',
varDef(what,
'atit',what))
772 xmin =
max(-100,gr.xmin-100)
773 xmax =
min(3600,gr.xmax+100)
783 h = (ymax-ymin)/2*options.yscale
787 ymin =
varDef(what,
'min',-100)
788 ymax =
varDef(what,
'max',+100)
789 if options.ymin!=
None:
791 if options.ymax!=
None:
795 ROOT.gPad.SetLogy(options.logy)
809 legendList.append([b,options.alegend,
'FL'])
810 legendList.append([
None,
'%s %s #pm %s %s' % (
fmtVal(what,mean,
True),
varDef(what,
'units'),
814 name =
'%s-perBCID' % what
815 tgraph = self.
protect( gr.getTGraph(name) )
818 if options.tgraphfile:
819 print (
'Saving TGraphErrors',tgraph.GetName(),
'to file',options.tgraphfile)
820 tgraphfile = ROOT.TFile(options.tgraphfile,
'UPDATE')
823 tgraph.SetMarkerSize(options.msize
if options.msize
else 0.8)
825 legendList.append([tgraph,options.plegend,
'PLE'])
829 self.
writeText(what,legendList,
not options.public)
832 """Variable what vs bunch position in train."""
833 ROOT.gStyle.SetOptStat(0)
842 if b.bcid - lastb > trainGap:
846 bunchnumber = b.bcid - startb
848 if bunchnumber
in calcmap:
849 calcmap[bunchnumber].
add(b)
851 calcmap[bunchnumber] = BeamSpotAverage([what], weightedAverage =
not options.simpleaverage)
852 bunchnrs.append(bunchnumber)
854 gr = self.
protect( ROOT.TGraphErrors(len(bunchnrs)))
861 for bunchnr
in bunchnrs:
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])
876 h = (ymax - ymin)/2*options.yscale
880 if options.xmin !=
None:
882 if options.xmax !=
None:
884 if options.ymin !=
None:
886 if options.ymax !=
None:
889 gr.SetMarkerSize(options.msize
if options.msize
else 0.8)
891 atit =
';%s;%s' % (
'Bunch position in train',
varDef(what,
'atit',what))
898 legendList.append([gr,options.plegend,
'PLE'])
900 self.
writeText(what,legendList,
not options.public)
903 """History of variable what vs LB, time or separation. Additionally overlap the results of more than one scan
906 ROOT.gStyle.SetOptStat(0)
908 calc = BeamSpotAverage([what],weightedAverage=
not options.simpleaverage)
911 scans = [(
int(s.split(
'-')[0]),
int(s.split(
'-')[1]))
for s
in options.scans.split(
',')]
915 if options.separation
and options.overlayScans:
917 scanGroup = [s
for s
in scans
if s[0] <= b.lbStart <= s[1]][0]
924 if not scanGroup
in grDict:
925 grDict[scanGroup] = BeamSpotGraph(timeAxis=options.timeaxis, separationAxis=options.separation)
926 grDict[scanGroup].
add(b,what)
930 print (
'Plotting data from %i scans ...\n' % len(grDict))
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)
950 xmax += .05*h
if len(grDict)==1
else 0.3*h
952 h = (ymax-ymin)/2*options.yscale
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)
960 ymin =
varDef(what,
'min',-100)
961 ymax =
varDef(what,
'max',+100)
962 if options.ymin!=
None:
964 if options.ymax!=
None:
969 atit =
';%s;%s' % (timeLabel,
varDef(what,
'atit',what))
970 elif options.separation:
971 atit =
';%s;%s' % (
'Nominal Separation [mm]',
varDef(what,
'atit',what))
973 atit =
';%s;%s' % (
'Luminosity block number',
varDef(what,
'atit',what))
976 ROOT.gPad.SetLogy(options.logy)
978 xAxis = frame.GetXaxis()
979 xAxis.SetTimeDisplay(1)
980 if (xmax-xmin)/86400 < 1:
981 xAxis.SetTimeFormat(
'%H:%M')
987 xAxis.SetTimeFormat(
'#splitline{%b %d}{%H:%M}')
988 xAxis.SetLabelOffset(0.025)
989 xAxis.SetTitleOffset(1.6)
991 xAxis.SetTimeFormat(options.adatefmt)
993 xAxis.SetNdivisions(options.ndivs,0)
994 frame.LabelsOption(
'd',
'X')
1008 legendList.append([b,options.alegend,
'FL'])
1009 legendList.append([
None,
'%s %s #pm %s %s' % (
fmtVal(what,mean,
True),
varDef(what,
'units'),
1014 for scan
in sorted(grDict.keys()):
1018 name = what
if scan==0
else '%s-scanoverlay' % (what)
1019 tgraph = self.
protect( gr.getTGraph(name) )
1022 if options.tgraphfile:
1023 print (
'Saving TGraphErrors',tgraph.GetName(),
'to file',options.tgraphfile)
1024 tgraphfile = ROOT.TFile(options.tgraphfile,
'UPDATE')
1030 tgraph.SetMarkerSize(options.msize
if options.msize
else 0.8)
1032 legendList.append([tgraph,options.plegend,
'PLE'])
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'])
1043 if len(grDict)>options.maxlegends:
1044 legendList.append([
None,
'...',
''])
1047 if options.fit
and len(grDict)==1:
1048 ROOT.gStyle.SetOptFit(1111)
1050 tgraph.Fit(options.fit,
'',
'SAME',gr.xmin,gr.xmax)
1053 legendX = 0.6
if len(grDict)==1
else 0.8
1054 self.
writeText(what,legendList,
not options.public,legendX=legendX)
1061 if cmd==
'dump' and len(args)==1:
1065 b.dump(options.verbose)
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}
1105 if cmd==
'maketable' and len(args)==1:
1106 if options.varlist
is None:
1108 varList = [
'status',
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'k']
1110 varList = options.varlist.split(
',')
1117 cols.append(
'%s $\pm$ %s' % (
fmtVal(v,getattr(b,v),
True,useAlternate=
True),
1118 fmtVal(v,getattr(b,v+
'Err'),
True,useAlternate=
True)))
1120 cols.append(
'%10s' % (
fmtVal(v,getattr(b,v),
True,useAlternate=
True)))
1121 rows.append(
'%s \\\\' %
' & '.
join(cols))
1123 print (tableTemplate % (len(varList)*
'c',
1124 ' & '.
join([
'%s' %
varDef(n,
'latexheader',useAlternate=
True)
for n
in varList]),
1133 if cmd==
'inspect' and len(args)==1:
1139 if not b.run
in runInfo:
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 '',
1160 print (
'%i runs found\n' % len(runInfo.keys()))
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)
1174 srcNt =
srcNtClass(args[1],fullCorrelations=options.fullCorrelations)
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())
1185 allBSResultsInNt = []
1187 allBSResultsInNt.append( b )
1190 totalVtxs += b.nValid
1191 lbSize += b.lbEnd - b.lbStart
1193 if totalEntries == 0:
1195 averagenVtx = totalVtxs/totalEntries
1196 print (
'Average Entries: '+
str(averagenVtx))
1199 lbSize = lbSize/totalEntries + 1
1200 print (
'Average number of lb used for fit: '+
str( lbSize ))
1204 allBSResultsInNt.sort()
1207 allBSResultsInNt.sort()
1210 for b
in allBSResultsInNt:
1211 if options.fillcooldata:
1212 b.fillDataFromCOOL()
1213 if options.addScanVars:
1215 if options.pseudoLbFile:
1216 b.fillDataFromPseudoLb(options.pseudoLbFile,
float(options.pseudoLbTimeUnit))
1217 if options.filldqdata:
1219 if not options.quiet:
1220 b.dump(options.verbose)
1229 if cmd==
'ave' and len(args)==1:
1231 if options.varlist
is None:
1233 varList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY']
1235 varList.append(
'sigmaXY')
1237 varList = options.varlist.split(
',')
1241 plots.whatList = varList
1242 plots.saveAsList = options.output.split(
',')
1243 plots.allCanvasSize =
'landscape'
1244 plots.allCanvasDivs = (3,3)
1246 plots.genPlot(
'all',
'hist')
1248 plots.genPlot(
'all',
'plot')
1252 calc = BeamSpotAverage(varList,weightedAverage=
not options.simpleaverage)
1253 if options.lumicalcnt
is not None:
1254 calc.readLumiData(options.lumicalcnt)
1258 if options.verbose
or options.debug:
1259 b.dump(options.debug)
1261 minrun =
min(b.run,minrun)
1262 maxrun =
max(b.run,maxrun)
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))
1272 if options.splittable:
1273 varRanges = [
range(options.splittable),
1274 range(options.splittable,len(calc.varList)) ]
1276 varRanges = [
range(len(calc.varList)) ]
1283 latexheader =
'Period '
1284 latexrow =
'%s' % options.period.replace(
'_',
'\_')
1285 print (
'\nAverage beam spot parameters (part %i):\n' % iTable)
1287 parName = calc.varList[i]
1288 print (
'%7s: %s +- %s %-3s (RMS = %s)' % (parName,
1293 latexheader +=
'& %s ' %
varDef(parName,
'latexheader',parName,useAlternate=
True)
1295 latexrow +=
' & %s $\pm$ %s' % (
fmtVal(parName,ave[i],useAlternate=
True),
fmtVal(parName,rms[i],useAlternate=
True))
1297 latexrow +=
' & %s $\pm$ %s' % (
fmtVal(parName,ave[i],useAlternate=
True),
fmtVal(parName,err[i],useAlternate=
True))
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')
1304 print (latexrow,
' \\\\')
1306 print (
'\hline \hline')
1307 print (
'\\end{tabular}\n\\end{center}\n\\caption{\\label{tab:}}\n\\end{table}')
1309 if options.cooltag
and minrun<1e10:
1311 sqliteFile= options.cooltag+
'.db'
1314 if not options.newave:
1315 print (
'\nWriting average to COOL SQLite file %s (folder tag = %s) ...' % (sqliteFile,options.cooltag))
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')])
1338 print (
'\nWriting average and LB info to COOL SQLite file %s (folder tag = %s) ...' % (sqliteFile,
"nominal"))
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')])
1361 print (
'Copying beam spot data from',options.ntname)
1363 if options.lbMin
and options.lbMin>b.lbStart:
1365 if options.lbMax
and options.lbMax<b.lbEnd+1:
1368 runEndInt = b.runEnd
1369 except AttributeError:
1372 if b.status
in nt.statusList:
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) ) )
1393 if (cmd==
'hist' or cmd==
'histvspileup' or cmd==
'pull')
and len(args)==2:
1397 plots.saveAsList = options.output.split(
',')
1399 plots.singleCanvasSize = options.canvas
1400 plots.allCanvasSize = options.canvas
1401 plots.allCanvasDivs = (options.xdivs,options.ydivs)
1403 plots.whatList = var.split(
',')
1404 plots.genPlot(
'all',cmd)
1406 plots.genPlot(var,cmd)
1413 if cmd==
'plot' and len(args)==2:
1417 plots.saveAsList = options.output.split(
',')
1419 plots.singleCanvasSize = options.canvas
1420 plots.allCanvasSize = options.canvas
1421 plots.allCanvasDivs = (options.xdivs,options.ydivs)
1423 plotType =
'perbcid'
1424 elif options.vsbunchpos:
1425 plotType =
'vsBunchPos'
1429 plots.whatList = var.split(
',')
1430 plots.genPlot(
'all',plotType)
1432 plots.genPlot(var,plotType)
1439 if cmd==
'summary' and len(args)==1:
1441 if not options.msize:
1444 plots.saveAsList = options.output.split(
',')
1445 plots.allCanvasSize =
'landscape'
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"))]
1455 plots.allCanvasDivs = (3,3)
1456 plots.whatList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY']
1461 plots.genPlot(
'all',
'perbcid',labels=labels)
1462 elif options.vsbunchpos:
1463 plots.whatList.remove(
'nValid')
1464 plots.genPlot(
'all',
'vsBunchPos',labels=labels)
1466 plots.genPlot(
'all',
'plot',labels=labels)
1474 if cmd==
'ascii' and len(args)==2:
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)
1483 ascii.write(
'%s ' %
str(b.fill))
1484 ascii.write(
'%s ' %
str(b.timeStart - time0 +
int((b.timeEnd-b.timeStart)/2)))
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 ')
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')
1503 if cmd==
'scan' and len(args)==1:
1505 if not options.msize:
1508 if options.timeaxis:
1510 elif options.separation:
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),]
1525 if options.separation
and options.overlayScans:
1526 plots.genPlot(
'all',
'plotscan')
1528 plots.genPlot(
'all',
'plot')
1530 plots.whatList.append(
'k')
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')
1540 graphs = plots.genPlot(var,
'plot')
1545 scans = [(
int(s.split(
'-')[0]),
int(s.split(
'-')[1]))
for s
in options.scans.split(
',')]
1549 options.overlayScans =
False
1550 for (lbMin, lbMax)
in scans:
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')
1565 plots.whatList.append(
'k')
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')
1578 print (
'ERROR: Illegal command or number of arguments')