7beamspotnt is a command line utility for beam spot ntuples.
9__author__ =
'Juerg Beringer'
10__version__ =
'beamspotnt.py atlas/athena'
11__usage__ =
'''%prog [options] command [args ...]
15dump Dump contents of a beam spot ntuple
16maketable Make LaTeX table of selected entries
17inspect Inspect ntuple and provide summary of contents
18merge SRCNT Merge source beam spot ntuple into master ntuple
19 (use --srcnt to specify type if not BeamSpotFinderNt)
20ave Calculate average of beam spot parameters
21hist var Histogram of var
22histvspileup var Profile histogram of var vs pileup
23pull var:value Pull of var with respect to true value
24plot var History of var
25summary Summary history plots
26ascii filename Write ASCII file with data in Massi\'s format
30beamspotnt -t BeamSpotCOOL -f IndetBeampos-ES1-UPD2 --ru 165815 --rl 165815 dump
34periodDef =
'/afs/cern.ch/user/a/atlidbs/nt/DataPeriods'
36import sys, os, time, glob, re, copy, math
41 if re.search(
r'\s|\*|\?',s):
43 qargv.append(
'"%s"' % re.sub(
'"',
"'",s))
45 qargv.append(
"'%s'" % re.sub(
"'",
'"',s))
50from optparse
import OptionParser
51parser = OptionParser(usage=__usage__, version=__version__)
52parser.add_option(
'-f',
'--nt', dest=
'ntname', default=
'beamspotnt.root', help=
'master ntuple file name or COOL tag (default: beamspotnt.root)')
53parser.add_option(
'-t',
'--type', dest=
'type', default=
'BeamSpotNt', help=
'master ntuple type (default: BeamSpotNt)')
54parser.add_option(
'-s',
'--srctype', dest=
'srctype', default=
'BeamSpotNt', help=
'source ntuple type for merging (default: BeamSpotNt)')
55parser.add_option(
'-v',
'--verbose', dest=
'verbose', action=
'store_true', default=
False, help=
'verbose output')
56parser.add_option(
'-d',
'--debug', dest=
'debug', action=
'store_true', default=
False, help=
'debug output')
57parser.add_option(
'-q',
'--quiet', dest=
'quiet', action=
'store_true', default=
False, help=
'reduce output')
58parser.add_option(
'-r',
'--run', dest=
'run', type=
'int', default=
None, help=
'run number (single run)')
59parser.add_option(
'',
'--rl', dest=
'runMin', type=
'int', default=
None, help=
'minimum run number (inclusive)')
60parser.add_option(
'',
'--ru', dest=
'runMax', type=
'int', default=
None, help=
'maximum run number (inclusive)')
61parser.add_option(
'',
'--re', dest=
'runExclude', default=
None, help=
'comma seperated list of runs to exclude')
62parser.add_option(
'',
'--fill', dest=
'fill', type=
'int', default=
None, help=
'fill number (single fill)')
63parser.add_option(
'',
'--fl', dest=
'fillMin', type=
'int', default=
None, help=
'minimum fill number (inclusive)')
64parser.add_option(
'',
'--fu', dest=
'fillMax', type=
'int', default=
None, help=
'maximum fill number (inclusive)')
65parser.add_option(
'',
'--bcid', dest=
'bcid', type=
'int', default=
None, help=
'BCID number (single BCID)')
66parser.add_option(
'',
'--bcl', dest=
'bcidMin', type=
'int', default=
None, help=
'minimum BCID number (inclusive)')
67parser.add_option(
'',
'--bcu', dest=
'bcidMax', type=
'int', default=
None, help=
'maximum BCID number (inclusive)')
68parser.add_option(
'',
'--lbl', dest=
'lbMin', type=
'int', default=
None, help=
'minimum LB number (inclusive)')
69parser.add_option(
'',
'--lbu', dest=
'lbMax', type=
'int', default=
None, help=
'maximum LB number (inclusive)')
70parser.add_option(
'',
'--tl', dest=
'timeMin', default=
None, help=
'minimum start time')
71parser.add_option(
'',
'--tu', dest=
'timeMax', default=
None, help=
'maximum end time')
72parser.add_option(
'',
'--status', dest=
'status', default=
'59', help=
'comma-separated list of accepted fit status values (default: 59)')
73parser.add_option(
'',
'--energy', dest=
'energy', default=
'13', help=
'center-of-mass energy')
74parser.add_option(
'-p',
'--period', dest=
'period', default=
None, help=
'comma-separated list of accepted run periods (e.g. data10_7TeV.G)')
75parser.add_option(
'',
'--perioddef', dest=
'periodDef', default=periodDef, help=
'location of run period definition files (default: %s)' % periodDef)
76parser.add_option(
'-g',
'--grl', dest=
'grl', default=
None, help=
'GRL to select runs/Lbs')
77parser.add_option(
'',
'--mc', dest=
'mc', action=
'store_true', default=
False, help=
'flag to indicate beam spot results are from MC')
78parser.add_option(
'',
'--fillCOOL', dest=
'fillcooldata', action=
'store_true', default=
False, help=
'fill data from COOL (time, fill#)')
79parser.add_option(
'',
'--fillDQ', dest=
'filldqdata', action=
'store_true', default=
False, help=
'fill data from DataQualtiy')
80parser.add_option(
'',
'--pLbFile', dest=
'pseudoLbFile', default=
None, help=
'File for pseudo LB info from scan')
81parser.add_option(
'',
'--pLbTimeUnit', dest=
'pseudoLbTimeUnit', default=1., help=
'Time unit for pseudo LB relative to seconds, e.g. 1e-9 for ns')
82parser.add_option(
'',
'--tz', dest=
'timezone', default=
'CET', help=
'time zone to use for time represenation (default: CERN local time)')
83parser.add_option(
'',
'--simpleaverage', dest=
'simpleaverage', action=
'store_true', default=
False, help=
'use simple instead of weighted average (for checks only)')
84parser.add_option(
'',
'--lumicalcnt', dest=
'lumicalcnt', default=
None, help=
'ave: use luminosity ntuple (from iLumiCalc.exe) for weighted average')
85parser.add_option(
'',
'--latex', dest=
'latex', action=
'store_true', default=
False, help=
'output results in LaTeX')
86parser.add_option(
'',
'--splittable', dest=
'splittable', type=
'int', default=
None, help=
'latex: split table, put first n cols into first table')
87parser.add_option(
'',
'--hist', dest=
'hist', action=
'store_true', default=
False, help=
'ave: produce validation histograms')
88parser.add_option(
'',
'--summary', dest=
'summary', action=
'store_true', default=
False, help=
'ave: produce validation summary plots')
89parser.add_option(
'',
'--rms', dest=
'rms', action=
'store_true', default=
False, help=
'Use RMS instead of error on mean')
90parser.add_option(
'',
'--varlist', dest=
'varlist', default=
None, help=
'list of beam spot variables used by ave')
91parser.add_option(
'-n',
'--nbins', dest=
'nbins', type=
'int', default=
None, help=
'number of bins')
92parser.add_option(
'',
'--xmin', dest=
'xmin', default=
None, help=
'x axis minimum')
93parser.add_option(
'',
'--xmax', dest=
'xmax', default=
None, help=
'x axis maximum')
94parser.add_option(
'',
'--timeaxis', dest=
'timeaxis', action=
'store_true', default=
False, help=
'use time on x axis instead of run or LB numbers')
95parser.add_option(
'',
'--talabel', dest=
'talabel', default=
None, help=
'time axis label (default: Time (timezone))')
96parser.add_option(
'',
'--perbcid', dest=
'perbcid', action=
'store_true', default=
False, help=
'plot per BCID instead of vs time/LB')
97parser.add_option(
'',
'--separation', dest=
'separation', action=
'store_true', default=
False, help=
'plot versus beam separation for scans')
98parser.add_option(
'',
'--vsbunchpos', dest=
'vsbunchpos', action=
'store_true', default=
False, help=
'plot versus bunch position in train')
99parser.add_option(
'',
'--ndivs', dest=
'ndivs', type=
'int', default=
None, help=
'Number of x axis divisions (ROOT format)')
100parser.add_option(
'',
'--ymin', dest=
'ymin', type=
'float', default=
None, help=
'y axis minimum')
101parser.add_option(
'',
'--ymax', dest=
'ymax', type=
'float', default=
None, help=
'y axis maximum')
102parser.add_option(
'-y',
'--yscale', dest=
'yscale', type=
'float', default=1.0, help=
'y axis scale factor')
103parser.add_option(
'-m',
'--msize', dest=
'msize', type=
'float', default=
None, help=
'set marker size')
104parser.add_option(
'',
'--lsize', dest=
'lsize', type=
'float', default=
None, help=
'set axis label size')
105parser.add_option(
'',
'--ydef', dest=
'ydef', action=
'store_true', default=
False, help=
'use default y range for given quantity')
106parser.add_option(
'',
'--defaults', dest=
'defaults', default=
'Gen', help=
'choose varDef defauls (default: Gen')
107parser.add_option(
'',
'--logy', dest=
'logy', action=
'store_true', default=
False, help=
'log scale')
108parser.add_option(
'',
'--fit', dest=
'fit', default=
'', help=
'fit function (e.g. pol1)')
109parser.add_option(
'',
'--optfit', dest=
'optfit', default=
'', help=
"fit options (default: '')")
110parser.add_option(
'-c',
'--canvas', dest=
'canvas', default=
'', help=
'canvas size: default, page, wide, extrawide or square')
111parser.add_option(
'',
'--xdivs', dest=
'xdivs', type=
'int', default=1, help=
'number of pads on canvas in x (needs -c, default: 1)')
112parser.add_option(
'',
'--ydivs', dest=
'ydivs', type=
'int', default=1, help=
'number of pads on canvas in y (needs -c, default: 1)')
113parser.add_option(
'',
'--optstat', dest=
'optstat', default=
'emruo', help=
'default OptStat value (Default: emruo)')
114parser.add_option(
'',
'--ave', dest=
'ave', action=
'store_true', default=
False, help=
'show average on plot')
115parser.add_option(
'',
'--newave', dest=
'newave', action=
'store_true', default=
False, help=
'replicate the functionality of the old aveBeamSpot.py script.')
116parser.add_option(
'',
'--title', dest=
'title', default=
'', help=
'title text on plots')
117parser.add_option(
'',
'--comment', dest=
'comment', default=
'', help=
'additional text (use semicolon to indicate line breaks)')
118parser.add_option(
'',
'--datefmt', dest=
'datefmt', default=
'', help=
'date format')
119parser.add_option(
'',
'--adatefmt', dest=
'adatefmt', default=
'', help=
'axis date format')
120parser.add_option(
'',
'--plegend', dest=
'plegend', default=
'fit to groups of LBs', help=
'legend text for points')
121parser.add_option(
'',
'--alegend', dest=
'alegend', default=
'average of data shown:', help=
'legend text for average')
122parser.add_option(
'',
'--maxlegends', dest=
'maxlegends', type=
'int', default=10, help=
'maximum number of legend entries')
123parser.add_option(
'',
'--omitfill', dest=
'omitfill', action=
'store_true', default=
False, help=
'remove any fill info from legend')
124parser.add_option(
'',
'--omitrun', dest=
'omitrun', action=
'store_true', default=
False, help=
'remove any run info from legend')
125parser.add_option(
'',
'--omittime', dest=
'omittime', action=
'store_true', default=
False, help=
'remove any time info from legend')
126parser.add_option(
'',
'--public', dest=
'public', action=
'store_true', default=
False, help=
'use labelling for public plots')
127parser.add_option(
'',
'--prelim', dest=
'prelim', action=
'store_true', default=
False, help=
'add ATLAS Preliminary to figure')
128parser.add_option(
'',
'--approval', dest=
'approval', action=
'store_true', default=
False, help=
'Label figure ATLAS for approval')
129parser.add_option(
'',
'--published', dest=
'published', action=
'store_true', default=
False, help=
'add ATLAS to figure')
130parser.add_option(
'',
'--customlabel', dest=
'customlabel', default=
'', help=
'add custom label after ATLAS to figure')
131parser.add_option(
'',
'--xtitoffset', dest=
'xtitoffset', type=
'float', default=
None, help=
'x axis title offset')
132parser.add_option(
'',
'--ytitoffset', dest=
'ytitoffset', type=
'float', default=
None, help=
'y axis title offset')
133parser.add_option(
'',
'--atlasx', dest=
'atlasx', type=
'float', default=
None, help=
'x position for drawing ATLAS (Preliminary) label')
134parser.add_option(
'',
'--atlasy', dest=
'atlasy', type=
'float', default=
None, help=
'y position for drawing ATLAS (Preliminary) label')
135parser.add_option(
'',
'--atlasdx', dest=
'atlasdx', type=
'float', default=
None, help=
'x position offset for drawing Preliminary label')
136parser.add_option(
'-o',
'--output', dest=
'output', default=
'.gif', help=
'comma-separated list of output files or formats (default: .gif)')
137parser.add_option(
'',
'--name', dest=
'name', default=
'BeamSpotNtPlots', help=
'base name for plots (default: BeamSpotNtPlots)')
138parser.add_option(
'',
'--tgraphfile', dest=
'tgraphfile', default=
'', help=
'optional root file to save TGraph into')
139parser.add_option(
'',
'--tag', dest=
'cooltag', default=
'', help=
'COOL tag for writing average into beam spot SQLite file (also determines file name)')
140parser.add_option(
'-i',
'--interactive', dest=
'interactive', action=
'store_true', default=
False, help=
'interactive')
141parser.add_option(
'-b',
'--batch', dest=
'batch', action=
'store_true', default=
False, help=
'run in batch mode')
142parser.add_option(
'',
'--fullCorrelations', dest=
'fullCorrelations', action=
'store_true', default=
False, help=
'Get all correlations')
143parser.add_option(
'',
'--scans', dest=
'scans', default=
'', help=
'comma-separated list of hypenated lb ranges for lumi scans')
144parser.add_option(
'',
'--acqFlag', dest=
'acqFlag', default =
False, action=
'store_true', help=
'Cut on AcquistionFlag=1.0 for stationary points of VdM scan')
145parser.add_option(
'',
'--overlayScans', dest=
'overlayScans', default =
False, action=
'store_true', help=
'overlay VdM scans on same plot')
146parser.add_option(
'',
'--useAve', dest=
'useAve', action=
'store_true', default=
False, help=
'Average over poor fits in the beamspot -- performed during merging step')
147parser.add_option(
'',
'--database', dest=
'database', default=
'COOLOFL_INDET/CONDBR2', help=
'DB to read beamspot info from when -s BeamSpotCOOL is enabled and running merge')
148parser.add_option(
'',
'--dbfolder', dest=
'dbfolder', default=
'/Indet/Beampos', help=
'Folder to read beamspot info from when -s BeamSpotCOOL is enabled and running merge')
149parser.add_option(
'',
'--addScanVars', dest=
'addScanVars', action=
'store_true', default=
False, help=
'Add variables for VdM scan')
151(options,args) = parser.parse_args()
153 parser.error(
'wrong number of command line arguments')
156if options.fillcooldata
and options.pseudoLbFile:
157 sys.exit(
'Options fillColl and pseudoLbFile are mutually exclusive')
161 os.unsetenv(
'DISPLAY')
165import InDetBeamSpotExample
168from InDetBeamSpotExample
import BeamSpotData
170 BeamSpotData.varDefs = getattr(BeamSpotData,
'varDefs'+options.defaults)
174from InDetBeamSpotExample.Utils
import getUserName, getHostName
175from InDetBeamSpotExample
import ROOTUtils
180if options.interactive:
181 os.environ[
'PYTHONINSPECT'] =
'1'
184 os.environ[
'TZ'] = options.timezone
186 timeLabel =
'Time (%s)' % options.timezone
188 timeLabel =
'Local time'
190 timeLabel = options.talabel
192if not options.datefmt:
194 options.datefmt =
'%b %Y'
196 options.datefmt =
'%a %b %d'
199if options.atlasx==
None:
200 if options.published:
201 options.atlasx = 0.83
if 'wide' in options.canvas
else 0.8
203 options.atlasx = 0.72
if 'wide' in options.canvas
else 0.645
204if options.atlasy==
None:
206 options.atlasy = 0.86
207if options.atlasdx==
None:
208 options.atlasdx = 0.08
if 'wide' in options.canvas
else 0.115
210ntClass = locals()[options.type]
213 if options.run!=
None:
214 nt.runMin = options.run
215 nt.runMax = options.run
216 if options.runMin!=
None:
217 nt.runMin = options.runMin
218 if options.runMax!=
None:
219 nt.runMax = options.runMax
220 if options.runExclude!=
None:
221 nt.runListExclude = [int(r)
for r
in options.runExclude.split(
',')]
222 if options.fill!=
None:
223 nt.fillMin = options.fill
224 nt.fillMax = options.fill
225 if options.fillMin!=
None:
226 nt.fillMin = options.fillMin
227 if options.fillMax!=
None:
228 nt.fillMax = options.fillMax
229 if options.bcid!=
None:
230 nt.bcidMin = options.bcid
231 nt.bcidMax = options.bcid
232 if options.bcidMin!=
None:
233 nt.bcidMin = options.bcidMin
234 if options.bcidMax!=
None:
235 nt.bcidMax = options.bcidMax
236 if options.lbMin!=
None:
237 nt.lbMin = options.lbMin
238 if options.lbMax!=
None:
239 nt.lbMax = options.lbMax
240 if options.timeMin!=
None:
241 nt.timeMin = time.mktime(time.strptime(options.timeMin,
'%b %d %H:%M:%S %Y'))
242 if options.timeMax!=
None:
243 nt.timeMax = time.mktime(time.strptime(options.timeMax,
'%b %d %H:%M:%S %Y'))
245 nt.statusList = [int(x)
for x
in options.status.split(
',')]
247 for p
in options.period.split(
','):
248 project,period = p.split(
'.')
249 location = os.path.normpath(options.periodDef +
'/' + project)
251 fileName = glob.glob(
'%s/%s.runs.list' % (location,period))[0]
252 nt.runList.extend([int(r)
for r
in open(fileName).
read().
split()])
254 sys.exit(
'ERROR: Definition file for period %s not found in directory %s' % (options.period, location))
257 sys.exit(
'ERROR: no runs found for requested periods')
267 if options.fullCorrelations:
268 nt =
ntClass(options.ntname,fullCorrelations=
True)
271 except Exception
as e:
272 sys.exit(
'ERROR: '+str(e))
276 print (nt.cutSummary())
281 while i < len( allBSResultsInNt ):
282 b = allBSResultsInNt[i]
283 if b.status < 70
and b.sigmaZErr == 0:
284 print (
"Will change Z error for lb's " + str(b.lbStart) +
" to " + str(b.lbEnd) +
" which has " + str(b.nValid) +
" verticies")
285 b.sigmaZErr = b.sigmaZ * 0.5
289 while i < len( allBSResultsInNt ):
290 b = allBSResultsInNt[i]
292 if b.status < 70
and b.nValid < 2000
and b.nValid < averagenVtx:
293 print (
"Will take an average for lb's " + str(b.lbStart) +
" to " + str(b.lbEnd) +
" which has " + str(b.nValid) +
" verticies" )
299 if allBSResultsInNt[iNeg].status == 59
and allBSResultsInNt[iNeg].nValid > 2000 :
300 lastGoodEntry = allBSResultsInNt[iNeg]
301 print (
" --- Starting with lb : " + str(lastGoodEntry.lbStart) +
" to " + str(lastGoodEntry.lbEnd))
307 while iPos < len(allBSResultsInNt):
308 if allBSResultsInNt[iPos].status == 59
and allBSResultsInNt[iPos].nValid > 2000:
309 nextGoodEntry = allBSResultsInNt[iPos]
310 print (
" --- Ending with lb : " + str(nextGoodEntry.lbStart) +
" to " + str(nextGoodEntry.lbEnd))
315 if lastGoodEntry == b
and nextGoodEntry == b :
316 print (
"Failed to do average - no good entries were found")
321 if( ( nextGoodEntry == b
or abs(nextGoodEntry.lbStart - b.lbEnd) > abs(lbSize) )
and (lastGoodEntry == b
or abs(b.lbStart - lastGoodEntry.lbEnd) > abs(lbSize) ) ):
322 print (
"Failed to do average - entries were too far away")
327 varList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY']
329 varList.append(
'sigmaXY')
330 calc = BeamSpotAverage(varList ,weightedAverage=
True)
332 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) ):
335 if lastGoodEntry != b
and abs(b.lbStart - lastGoodEntry.lbEnd) <= abs(lbSize) :
336 calc.add(lastGoodEntry)
338 if nextGoodEntry != b
and abs(nextGoodEntry.lbStart - b.lbEnd) <= abs(lbSize) :
339 calc.add(nextGoodEntry)
345 bcopy = copy.deepcopy(b)
348 setattr(bcopy, var, ave[calc.varList.index(var)])
349 setattr(bcopy, var+
"Err", err[calc.varList.index(var)])
353 allBSResultsInNt.insert(i, bcopy)
363 while i < len( allBSResultsInNt ):
364 if allBSResultsInNt[i].status != 59:
370 if(lastValidEntry >= 0):
371 if allBSResultsInNt[nextValidEntry].lbStart != allBSResultsInNt[lastValidEntry].lbEnd + 1:
372 print (
"Missing Lumi block from {:>5d} to {:>5d}".format( allBSResultsInNt[lastValidEntry].lbEnd + 1 , allBSResultsInNt[nextValidEntry].lbStart))
375 if allBSResultsInNt[nextValidEntry].lbStart - allBSResultsInNt[lastValidEntry].lbEnd + 1 > lbSize:
376 print (
"--Lumi block gap too large wont fill in the gap" )
377 elif (allBSResultsInNt[nextValidEntry].lbStart-1) - (allBSResultsInNt[lastValidEntry].lbEnd+1) < 0 :
378 print (
"Missing Lumi block is invalid from {:>5d} to {:>5d}".format( allBSResultsInNt[lastValidEntry].lbEnd+1, allBSResultsInNt[nextValidEntry].lbStart -1))
380 varList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY']
382 varList.append(
'sigmaXY')
383 calc = BeamSpotAverage(varList ,weightedAverage=
True)
384 calc.add(allBSResultsInNt[nextValidEntry])
385 calc.add(allBSResultsInNt[lastValidEntry])
391 bcopy = copy.deepcopy(b)
394 setattr(bcopy, var, ave[calc.varList.index(var)])
395 setattr(bcopy, var+
"Err", err[calc.varList.index(var)])
404 bcopy.lbStart = allBSResultsInNt[lastValidEntry].lbEnd + 1
405 bcopy.lbEnd = allBSResultsInNt[nextValidEntry].lbStart-1
406 allBSResultsInNt.insert(lastValidEntry+1, bcopy)
410 lastValidEntry = nextValidEntry
420 self.
whatList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY',
'k',
'nValid']
423 showRuns=True, showFills=True, showTime=True, otherTitle=None, otherComment=None,
429 title = options.title
or varDef(var,
'title',var)
433 comments.append(otherComment)
435 comments.append(options.comment)
436 if showRuns
and not options.omitrun:
437 if self.
nt.selRunMin==self.
nt.selRunMax:
438 comments.append(
'Run %i' % self.
nt.selRunMin)
440 comments.append(
'Runs %i - %i' % (self.
nt.selRunMin,self.
nt.selRunMax))
441 if showFills
and not options.omitfill:
442 if self.
nt.selFillMin==self.
nt.selFillMax:
443 comments.append(
'Fill %i' % self.
nt.selFillMin)
445 comments.append(
'Fills %i - %i' % (self.
nt.selFillMin,self.
nt.selFillMax))
446 if showTime
and not options.omittime:
448 t1 = time.strftime(options.datefmt,time.localtime(self.
nt.selTimeMin))
449 t2 = time.strftime(options.datefmt,time.localtime(self.
nt.selTimeMax))
451 t1 = time.strftime(options.datefmt,time.localtime(self.
nt.selTimeMin))
452 t2 = time.strftime(options.datefmt,time.localtime(self.
nt.selTimeMax))
456 comments.append(
'%s - %s' % (t1,t2))
460 logoSize = options.lsize
if options.lsize
else 0.5
462 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,
True,offset=options.atlasdx,energy=options.energy,size=logoSize)
464 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,
False,offset=options.atlasdx,isForApproval=
True,energy=options.energy,size=logoSize)
465 if options.published:
466 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,
False,offset=options.atlasdx,energy=options.energy,size=logoSize)
467 if options.customlabel!=
"":
468 ROOTUtils.atlasLabel(options.atlasx,options.atlasy,
False,offset=options.atlasdx,isForApproval=
False,customstring=options.customlabel,energy=options.energy,size=logoSize)
471 legendMinY =
max(0.91-0.07*len(legendList),0.2)
475 """Histogram of variable what.
477 If what is of the form NAME:VALUE, VALUE will be subtracted
478 from each entry in order to produce plots of measured minus
482 (what,shift) = what.split(
':')
486 ROOT.gStyle.SetOptStat(options.optstat)
487 title = varDef(what,
'title',what)+
';'+varDef(what,
'atit',what)
488 nBins = options.nbins
if options.nbins
else varDef(what,
'nBins',100)
489 xmin = float(options.xmin)
if options.xmin!=
None else varDef(what,
'min',-100)
490 xmax = float(options.xmax)
if options.xmax!=
None else varDef(what,
'max',+100)
491 h = self.
protect( ROOT.TH1F(what,title,nBins,xmin,xmax) )
494 h.GetYaxis().SetTitle(
'Number of fit results')
495 arescale = varDef(what,
'arescale',1.0)
498 h.Fill(arescale*(getattr(b,what)-shift))
499 except Exception
as e:
500 print (
'ERROR filling histogram:',str(e))
503 ROOT.gStyle.SetOptFit(1111)
504 h.Fit(options.fit,options.optfit)
506 ROOT.gPad.SetLogy(options.logy)
507 ndivs = varDef(what,
'ndivs',override=options.ndivs)
509 h.GetXaxis().SetNdivisions(ndivs,0)
511 self.
writeText(what,[],
False,
False,
False)
513 self.
writeText(what,[],
not options.public,options.public)
516 """Profile histogram of variable what vs pileup.
518 If what is of the form NAME:VALUE, VALUE will be subtracted
519 from each entry in order to produce plots of measured minus
523 (what,shift) = what.split(
':')
527 ROOT.gStyle.SetOptStat(options.optstat)
528 title = varDef(what,
'title',what)+
';Number of pileup vertices;'+varDef(what,
'atit',what)
529 nBins = options.nbins
if options.nbins
else varDef(what,
'nBins',100)
530 xmin = float(options.xmin)
if options.xmin!=
None else varDef(what,
'min',-100)
531 xmax = float(options.xmax)
if options.xmax!=
None else varDef(what,
'max',+100)
532 h = self.
protect( ROOT.TProfile(what,title,nBins,0,nBins) )
535 h.GetYaxis().SetRangeUser(xmin,xmax)
536 arescale = varDef(what,
'arescale',1.0)
539 h.Fill(getattr(b,
'pileup'),arescale*(getattr(b,what)-shift))
540 except Exception
as e:
541 print (
'ERROR filling histogram:',str(e))
544 ROOT.gStyle.SetOptFit(1111)
545 h.Fit(options.fit,options.optfit)
547 ROOT.gPad.SetLogy(options.logy)
548 ndivs = varDef(what,
'ndivs',override=options.ndivs)
550 h.GetYaxis().SetNdivisions(ndivs,0)
552 self.
writeText(what,[],
False,
False,
False)
554 self.
writeText(what,[],
not options.public,options.public)
557 """Pull histogram of variable what.
559 what must be of the form name:value, where value is the
560 correct value of variable name."""
562 (what,value) = what.split(
':')
565 print((
'ERROR: Illegal input %s for pull variable - must be of the form NAME:VALUE' % what))
567 ROOT.gStyle.SetOptStat(options.optstat)
569 nBins = options.nbins
if options.nbins
else varDef(what,
'nBins',100)
570 xmin = float(options.xmin)
if options.xmin!=
None else -4.
571 xmax = float(options.xmax)
if options.xmax!=
None else +4.
572 h = self.
protect( ROOT.TH1F(what,title,nBins,xmin,xmax) )
575 h.GetYaxis().SetTitle(
'Number of fit results')
579 h.Fill((getattr(b,what)-value)/getattr(b,whatErr))
580 except Exception
as e:
581 print (
'ERROR filling histogram:',str(e))
584 ROOT.gStyle.SetOptFit(1111)
585 h.Fit(options.fit,options.optfit)
587 ROOT.gPad.SetLogy(options.logy)
589 h.GetXaxis().SetNdivisions(options.ndivs,0)
591 self.
writeText(what,[],
False,
False,
False)
593 self.
writeText(what,[],
not options.public,options.public)
596 """History of variable what vs LB or time."""
597 ROOT.gStyle.SetOptStat(0)
599 calc = BeamSpotAverage([what],weightedAverage=
not options.simpleaverage)
602 arescale = varDef(what,
'arescale',1.0)
604 if b.sigmaX < 0.005
or b.sigmaY < 0.005:
605 print (
"OUTLIER ", b.run, b.lbStart, b.lbEnd, b.sigmaX, b.sigmaY)
606 if not b.bcid
in grDict:
607 grDict[b.bcid] = BeamSpotGraph(timeAxis=options.timeaxis, separationAxis=options.separation)
610 grDict[b.bcid].
add(b,what,arescale)
614 print (
'Plotting data from %i BCID ...\n' % len(grDict))
621 for gr
in [grDict.get(bcid)
for bcid
in grDict]:
622 xmin =
min(xmin,gr.xmin)
623 xmax =
max(xmax,gr.xmax)
624 ymin =
min(ymin,gr.ymin)
625 ymax =
max(ymax,gr.ymax)
634 xmax += .05*h
if len(grDict)==1
else 0.3*h
636 h = (ymax-ymin)/2*options.yscale
639 if options.xmin!=
None:
640 xmin = time.mktime(time.strptime(options.xmin,
'%b %d %H:%M:%S %Y'))
if options.timeaxis
else float(options.xmin)
641 if options.xmax!=
None:
642 xmax = time.mktime(time.strptime(options.xmax,
'%b %d %H:%M:%S %Y'))
if options.timeaxis
else float(options.xmax)
644 ymin = varDef(what,
'min',-100)
645 ymax = varDef(what,
'max',+100)
646 if options.ymin!=
None:
648 if options.ymax!=
None:
653 atit =
';%s;%s' % (timeLabel,varDef(what,
'atit',what))
654 elif options.separation:
655 atit =
';%s;%s' % (
'Nominal Separation [mm]',varDef(what,
'atit',what))
657 atit =
';%s;%s' % (
'Luminosity block number',varDef(what,
'atit',what))
660 ROOT.gPad.SetLogy(options.logy)
662 xAxis = frame.GetXaxis()
663 yAxis = frame.GetYaxis()
664 xAxis.SetTimeDisplay(1)
669 xAxis.SetTimeOffset(0)
671 if (xmax-xmin)/86400 < 1:
672 xAxis.SetTimeFormat(
'%H:%M')
679 xAxis.SetTimeFormat(
'%b %d')
681 xAxis.SetTimeFormat(
'#splitline{%b %d}{%H:%M}')
682 xAxis.SetLabelOffset(0.02)
683 xAxis.SetTitleOffset(1.6)
685 xAxis.SetLabelSize(options.lsize)
686 xAxis.SetTitleSize(options.lsize)
687 yAxis.SetLabelSize(options.lsize)
688 yAxis.SetTitleSize(options.lsize)
690 xAxis.SetLabelSize(0.044)
692 xAxis.SetTimeFormat(options.adatefmt)
694 xAxis.SetNdivisions(options.ndivs,0)
695 frame.LabelsOption(
'd',
'X')
697 if options.xtitoffset:
698 xAxis.SetTitleOffset(options.xtitoffset)
699 if options.ytitoffset:
700 yAxis.SetTitleOffset(options.ytitoffset)
714 legendList.append([b,options.alegend,
'FL'])
715 legendList.append([
None,
'%s %s #pm %s %s' % (fmtVal(what,mean,
True),varDef(what,
'units'),
716 fmtVal(what,error,
True),varDef(what,
'units')),
''])
720 for bcid
in sorted(grDict.keys()):
724 name = what
if bcid==0
else '%s-bcid%04i' % (what,bcid)
725 tgraph = self.
protect( gr.getTGraph(name) )
728 if options.tgraphfile:
729 print (
'Saving TGraphErrors',tgraph.GetName(),
'to file',options.tgraphfile)
730 tgraphfile = ROOT.TFile(options.tgraphfile,
'UPDATE')
736 tgraph.SetMarkerSize(options.msize
if options.msize
else 0.8)
738 legendList.append([tgraph,options.plegend,
'PLE'])
740 tgraph.SetMarkerColor(styleFactory.nextColorStyle())
741 tgraph.SetMarkerStyle(styleFactory.nextMarkerStyle())
742 tgraph.SetMarkerSize(options.msize
if options.msize
else 1.2)
743 if len(legendList)<options.maxlegends:
744 text =
'All' if bcid==0
else 'BCID %i' % bcid
745 legendList.append([tgraph,text,
'PLE'])
749 if options.fit
and len(grDict)==1:
750 ROOT.gStyle.SetOptFit(1111)
752 tgraph.Fit(options.fit,
'',
'SAME', gr.xmin,gr.xmax)
755 legendX = 0.6
if len(grDict)==1
else 0.8
756 self.
writeText(what,legendList
if not options.public
else [],
not options.public,legendX=legendX)
759 """Variable what vs BCID."""
760 ROOT.gStyle.SetOptStat(0)
762 calc = BeamSpotAverage([what],weightedAverage=
not options.simpleaverage)
763 gr = BeamSpotGraph(bcidAxis=
True)
768 atit =
';%s;%s' % (
'BCID',varDef(what,
'atit',what))
771 xmin =
max(-100,gr.xmin-100)
772 xmax =
min(3600,gr.xmax+100)
782 h = (ymax-ymin)/2*options.yscale
786 ymin = varDef(what,
'min',-100)
787 ymax = varDef(what,
'max',+100)
788 if options.ymin!=
None:
790 if options.ymax!=
None:
794 ROOT.gPad.SetLogy(options.logy)
808 legendList.append([b,options.alegend,
'FL'])
809 legendList.append([
None,
'%s %s #pm %s %s' % (fmtVal(what,mean,
True),varDef(what,
'units'),
810 fmtVal(what,error,
True),varDef(what,
'units')),
''])
813 name =
'%s-perBCID' % what
814 tgraph = self.
protect( gr.getTGraph(name) )
817 if options.tgraphfile:
818 print (
'Saving TGraphErrors',tgraph.GetName(),
'to file',options.tgraphfile)
819 tgraphfile = ROOT.TFile(options.tgraphfile,
'UPDATE')
822 tgraph.SetMarkerSize(options.msize
if options.msize
else 0.8)
824 legendList.append([tgraph,options.plegend,
'PLE'])
828 self.
writeText(what,legendList,
not options.public)
831 """Variable what vs bunch position in train."""
832 ROOT.gStyle.SetOptStat(0)
841 if b.bcid - lastb > trainGap:
845 bunchnumber = b.bcid - startb
847 if bunchnumber
in calcmap:
848 calcmap[bunchnumber].
add(b)
850 calcmap[bunchnumber] = BeamSpotAverage([what], weightedAverage =
not options.simpleaverage)
851 bunchnrs.append(bunchnumber)
853 gr = self.
protect( ROOT.TGraphErrors(len(bunchnrs)))
860 for bunchnr
in bunchnrs:
861 calcmap[bunchnr].average()
862 gr.SetPoint(counter, bunchnr, calcmap[bunchnr].ave[0])
863 gr.SetPointError(counter, 0.5, calcmap[bunchnr].err[0])
864 xmax =
max(xmax, bunchnr)
865 ymin =
min(ymin, calcmap[bunchnr].ave[0])
866 ymax =
max(ymax, calcmap[bunchnr].ave[0])
875 h = (ymax - ymin)/2*options.yscale
879 if options.xmin !=
None:
881 if options.xmax !=
None:
883 if options.ymin !=
None:
885 if options.ymax !=
None:
888 gr.SetMarkerSize(options.msize
if options.msize
else 0.8)
890 atit =
';%s;%s' % (
'Bunch position in train',varDef(what,
'atit',what))
897 legendList.append([gr,options.plegend,
'PLE'])
899 self.
writeText(what,legendList,
not options.public)
902 """History of variable what vs LB, time or separation. Additionally overlap the results of more than one scan
905 ROOT.gStyle.SetOptStat(0)
907 calc = BeamSpotAverage([what],weightedAverage=
not options.simpleaverage)
910 scans = [(int(s.split(
'-')[0]), int(s.split(
'-')[1]))
for s
in options.scans.split(
',')]
914 if options.separation
and options.overlayScans:
916 scanGroup = [s
for s
in scans
if s[0] <= b.lbStart <= s[1]][0]
923 if not scanGroup
in grDict:
924 grDict[scanGroup] = BeamSpotGraph(timeAxis=options.timeaxis, separationAxis=options.separation)
925 grDict[scanGroup].
add(b,what)
929 print (
'Plotting data from %i scans ...\n' % len(grDict))
936 for gr
in [grDict.get(scan)
for scan
in grDict]:
937 xmin =
min(xmin,gr.xmin)
938 xmax =
max(xmax,gr.xmax)
939 ymin =
min(ymin,gr.ymin)
940 ymax =
max(ymax,gr.ymax)
949 xmax += .05*h
if len(grDict)==1
else 0.3*h
951 h = (ymax-ymin)/2*options.yscale
954 if options.xmin!=
None:
955 xmin = time.mktime(time.strptime(options.xmin,
'%b %d %H:%M:%S %Y'))
if options.timeaxis
else float(options.xmin)
956 if options.xmax!=
None:
957 xmax = time.mktime(time.strptime(options.xmax,
'%b %d %H:%M:%S %Y'))
if options.timeaxis
else float(options.xmax)
959 ymin = varDef(what,
'min',-100)
960 ymax = varDef(what,
'max',+100)
961 if options.ymin!=
None:
963 if options.ymax!=
None:
968 atit =
';%s;%s' % (timeLabel,varDef(what,
'atit',what))
969 elif options.separation:
970 atit =
';%s;%s' % (
'Nominal Separation [mm]',varDef(what,
'atit',what))
972 atit =
';%s;%s' % (
'Luminosity block number',varDef(what,
'atit',what))
975 ROOT.gPad.SetLogy(options.logy)
977 xAxis = frame.GetXaxis()
978 xAxis.SetTimeDisplay(1)
979 if (xmax-xmin)/86400 < 1:
980 xAxis.SetTimeFormat(
'%H:%M')
986 xAxis.SetTimeFormat(
'#splitline{%b %d}{%H:%M}')
987 xAxis.SetLabelOffset(0.025)
988 xAxis.SetTitleOffset(1.6)
990 xAxis.SetTimeFormat(options.adatefmt)
992 xAxis.SetNdivisions(options.ndivs,0)
993 frame.LabelsOption(
'd',
'X')
1007 legendList.append([b,options.alegend,
'FL'])
1008 legendList.append([
None,
'%s %s #pm %s %s' % (fmtVal(what,mean,
True),varDef(what,
'units'),
1009 fmtVal(what,error,
True),varDef(what,
'units')),
''])
1013 for scan
in sorted(grDict.keys()):
1017 name = what
if scan==0
else '%s-scanoverlay' % (what)
1018 tgraph = self.
protect( gr.getTGraph(name) )
1021 if options.tgraphfile:
1022 print (
'Saving TGraphErrors',tgraph.GetName(),
'to file',options.tgraphfile)
1023 tgraphfile = ROOT.TFile(options.tgraphfile,
'UPDATE')
1029 tgraph.SetMarkerSize(options.msize
if options.msize
else 0.8)
1031 legendList.append([tgraph,options.plegend,
'PLE'])
1033 tgraph.SetMarkerColor(styleFactory.nextColorStyle())
1034 tgraph.SetMarkerStyle(styleFactory.nextMarkerStyle())
1035 tgraph.SetMarkerSize(options.msize
if options.msize
else 1.2)
1036 if len(legendList)<options.maxlegends:
1037 text =
'All' if scan==0
else 'scan %i - %i' % scan
1038 legendList.append([tgraph,text,
'PLE'])
1042 if len(grDict)>options.maxlegends:
1043 legendList.append([
None,
'...',
''])
1046 if options.fit
and len(grDict)==1:
1047 ROOT.gStyle.SetOptFit(1111)
1049 tgraph.Fit(options.fit,
'',
'SAME',gr.xmin,gr.xmax)
1052 legendX = 0.6
if len(grDict)==1
else 0.8
1053 self.
writeText(what,legendList,
not options.public,legendX=legendX)
1060if cmd==
'dump' and len(args)==1:
1064 b.dump(options.verbose)
1073\documentclass[12pt,twoside]{article}
1074\usepackage[landscape]{geometry}
1075\RequirePackage{xspace}
1076\def\lumposx {\ensuremath{\overline{x}_{\mathcal{L}}}\xspace}
1077\def\lumposy {\ensuremath{\overline{y}_{\mathcal{L}}}\xspace}
1078\def\lumposz {\ensuremath{\overline{z}_{\mathcal{L}}}\xspace}
1079\def\lumsigx {\ensuremath{\sigma_{x{\mathcal L}}}\xspace}
1080\def\lumsigy {\ensuremath{\sigma_{y{\mathcal L}}}\xspace}
1081\def\lumsigz {\ensuremath{\sigma_{z{\mathcal L}}}\xspace}
1082\def\lumtiltx {\ensuremath{\overline{x}_{\mathcal{L}}'}\xspace}
1083\def\lumtilty {\ensuremath{\overline{y}_{\mathcal{L}}'}\xspace}
1084\def\lumrhoxy {\ensuremath{\rho_{xy}}\xspace}
1104if cmd==
'maketable' and len(args)==1:
1105 if options.varlist
is None:
1107 varList = [
'status',
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'k']
1109 varList = options.varlist.split(
',')
1116 cols.append(
r'%s $\pm$ %s' % (fmtVal(v,getattr(b,v),
True,useAlternate=
True),
1117 fmtVal(v,getattr(b,v+
'Err'),
True,useAlternate=
True)))
1119 cols.append(
'%10s' % (fmtVal(v,getattr(b,v),
True,useAlternate=
True)))
1120 rows.append(
'%s \\\\' %
' & '.join(cols))
1122 print (tableTemplate % (len(varList)*
'c',
1123 ' & '.join([
'%s' % varDef(n,
'latexheader',useAlternate=
True)
for n
in varList]),
1132if cmd==
'inspect' and len(args)==1:
1138 if not b.run
in runInfo:
1146 if runInfo[r][
'lbStart']
is None or b.lbStart<runInfo[r][
'lbStart']: runInfo[r][
'lbStart'] = b.lbStart
1147 if runInfo[r][
'lbEnd']
is None or b.lbEnd>runInfo[r][
'lbEnd']: runInfo[r][
'lbEnd'] = b.lbEnd
1148 runInfo[r][
'status'].
add(b.status)
1149 if b.timeStart
and b.timeEnd
and b.fill: runInfo[r][
'hasCOOL'] =
True
1150 if b.posXErr: runInfo[r][
'hasErrors'] =
True
1151 for r
in sorted(runInfo.keys()):
1152 print (
'%6s [ %10i, %10i ] %7s %9s fit status = %s' % (r,
1153 runInfo[r][
'lbStart'],
1154 runInfo[r][
'lbEnd'],
1155 'hasCOOL' if runInfo[r][
'hasCOOL']
else '',
1156 'hasErrors' if runInfo[r][
'hasErrors']
else '',
1157 sorted(list(runInfo[r][
'status']))))
1159 print (
'%i runs found\n' % len(runInfo.keys()))
1167if cmd==
'merge' and len(args)==2:
1168 srcNtClass = locals()[options.srctype]
1169 if (options.srctype ==
'BeamSpotCOOL'):
1170 print (
'\n Reading in from database ')
1171 srcNt =
srcNtClass(args[1],database=options.database,folder=options.dbfolder,fullCorrelations=options.fullCorrelations)
1173 srcNt =
srcNtClass(args[1],fullCorrelations=options.fullCorrelations)
1176 print (
'\nImporting from '+srcNt.summary())
1177 print (srcNt.cutSummary())
1178 dstNt =
ntClass(options.ntname,
True,fullCorrelations=options.fullCorrelations,addScanVars=options.addScanVars)
1179 print (
'\nMerging into '+dstNt.summary())
1184 allBSResultsInNt = []
1186 allBSResultsInNt.append( b )
1189 totalVtxs += b.nValid
1190 lbSize += b.lbEnd - b.lbStart
1192 if totalEntries == 0:
1194 averagenVtx = totalVtxs/totalEntries
1195 print (
'Average Entries: '+ str(averagenVtx))
1198 lbSize = lbSize/totalEntries + 1
1199 print (
'Average number of lb used for fit: '+ str( lbSize ))
1203 allBSResultsInNt.sort()
1206 allBSResultsInNt.sort()
1209 for b
in allBSResultsInNt:
1210 if options.fillcooldata:
1211 b.fillDataFromCOOL()
1212 if options.addScanVars:
1214 if options.pseudoLbFile:
1215 b.fillDataFromPseudoLb(options.pseudoLbFile, float(options.pseudoLbTimeUnit))
1216 if options.filldqdata:
1218 if not options.quiet:
1219 b.dump(options.verbose)
1228if cmd==
'ave' and len(args)==1:
1230 if options.varlist
is None:
1232 varList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY']
1234 varList.append(
'sigmaXY')
1236 varList = options.varlist.split(
',')
1240 plots.whatList = varList
1241 plots.saveAsList = options.output.split(
',')
1242 plots.allCanvasSize =
'landscape'
1243 plots.allCanvasDivs = (3,3)
1245 plots.genPlot(
'all',
'hist')
1247 plots.genPlot(
'all',
'plot')
1251 calc = BeamSpotAverage(varList,weightedAverage=
not options.simpleaverage)
1252 if options.lumicalcnt
is not None:
1253 calc.readLumiData(options.lumicalcnt)
1257 if options.verbose
or options.debug:
1258 b.dump(options.debug)
1260 minrun =
min(b.run,minrun)
1261 maxrun =
max(b.run,maxrun)
1267 print (
'... %i warnings detected' % calc.nWarnings)
1268 if options.lumicalcnt
is not None:
1269 print (
'... integrated luminosity of selected runs = %6.1f / pb' % (calc.sumw[0]/1.E6))
1271 if options.splittable:
1272 varRanges = [ range(options.splittable),
1273 range(options.splittable,len(calc.varList)) ]
1275 varRanges = [ range(len(calc.varList)) ]
1282 latexheader =
'Period '
1283 latexrow =
'%s' % options.period.replace(
'_',
r'\_')
1284 print (
'\nAverage beam spot parameters (part %i):\n' % iTable)
1286 parName = calc.varList[i]
1287 print (
'%7s: %s +- %s %-3s (RMS = %s)' % (parName,
1288 fmtVal(parName,ave[i]),
1289 fmtVal(parName,err[i]),
1290 varDef(parName,
'units'),
1291 fmtVal(parName,rms[i])))
1292 latexheader +=
'& %s ' % varDef(parName,
'latexheader',parName,useAlternate=
True)
1294 latexrow +=
r' & %s $\pm$ %s' % (fmtVal(parName,ave[i],useAlternate=
True),fmtVal(parName,rms[i],useAlternate=
True))
1296 latexrow +=
r' & %s $\pm$ %s' % (fmtVal(parName,ave[i],useAlternate=
True),fmtVal(parName,err[i],useAlternate=
True))
1298 print (
'\nLaTeX code for table %i:\n' % iTable)
1299 print (
'\\begin{table}[htbp]\n\\begin{center}\n\\begin{tabular}{l%s}' % (len(r)*
'c'))
1300 print (
r'\hline \hline')
1301 print (latexheader,
r'\\\\ \hline')
1303 print (latexrow,
' \\\\')
1305 print (
r'\hline \hline')
1306 print (
'\\end{tabular}\n\\end{center}\n\\caption{\\label{tab:}}\n\\end{table}')
1308 if options.cooltag
and minrun<1e10:
1310 sqliteFile= options.cooltag+
'.db'
1311 folderHandle = openBeamSpotDbFile(sqliteFile,
True)
1313 if not options.newave:
1314 print (
'\nWriting average to COOL SQLite file %s (folder tag = %s) ...' % (sqliteFile,options.cooltag))
1315 writeBeamSpotEntry(folderHandle,tag=options.cooltag,
1317 posX=ave[calc.varList.index(
'posX')],
1318 posY=ave[calc.varList.index(
'posY')],
1319 posZ=ave[calc.varList.index(
'posZ')],
1320 sigmaX=ave[calc.varList.index(
'sigmaX')],
1321 sigmaY=ave[calc.varList.index(
'sigmaY')],
1322 sigmaZ=ave[calc.varList.index(
'sigmaZ')],
1323 tiltX=ave[calc.varList.index(
'tiltX')],
1324 tiltY=ave[calc.varList.index(
'tiltY')],
1325 sigmaXY=ave[calc.varList.index(
'sigmaXY')],
1326 posXErr=err[calc.varList.index(
'posX')],
1327 posYErr=err[calc.varList.index(
'posY')],
1328 posZErr=err[calc.varList.index(
'posZ')],
1329 sigmaXErr=err[calc.varList.index(
'sigmaX')],
1330 sigmaYErr=err[calc.varList.index(
'sigmaY')],
1331 sigmaZErr=err[calc.varList.index(
'sigmaZ')],
1332 tiltXErr=err[calc.varList.index(
'tiltX')],
1333 tiltYErr=err[calc.varList.index(
'tiltY')],
1334 sigmaXYErr=err[calc.varList.index(
'sigmaXY')])
1337 print (
'\nWriting average and LB info to COOL SQLite file %s (folder tag = %s) ...' % (sqliteFile,
"nominal"))
1338 writeBeamSpotEntry(folderHandle,tag=
"nominal",
1339 runMin=int(minrun),runMax=int(maxrun),
1341 posX=ave[calc.varList.index(
'posX')],
1342 posY=ave[calc.varList.index(
'posY')],
1343 posZ=ave[calc.varList.index(
'posZ')],
1344 sigmaX=ave[calc.varList.index(
'sigmaX')],
1345 sigmaY=ave[calc.varList.index(
'sigmaY')],
1346 sigmaZ=ave[calc.varList.index(
'sigmaZ')],
1347 tiltX=ave[calc.varList.index(
'tiltX')],
1348 tiltY=ave[calc.varList.index(
'tiltY')],
1349 sigmaXY=ave[calc.varList.index(
'sigmaXY')],
1350 posXErr=err[calc.varList.index(
'posX')],
1351 posYErr=err[calc.varList.index(
'posY')],
1352 posZErr=err[calc.varList.index(
'posZ')],
1353 sigmaXErr=err[calc.varList.index(
'sigmaX')],
1354 sigmaYErr=err[calc.varList.index(
'sigmaY')],
1355 sigmaZErr=err[calc.varList.index(
'sigmaZ')],
1356 tiltXErr=err[calc.varList.index(
'tiltX')],
1357 tiltYErr=err[calc.varList.index(
'tiltY')],
1358 sigmaXYErr=err[calc.varList.index(
'sigmaXY')])
1360 print (
'Copying beam spot data from',options.ntname)
1362 if options.lbMin
and options.lbMin>b.lbStart:
1364 if options.lbMax
and options.lbMax<b.lbEnd+1:
1367 runEndInt = b.runEnd
1368 except AttributeError:
1371 if b.status
in nt.statusList:
1372 writeBeamSpotEntry(folderHandle,tag=
'nominal',
1378 posX=b.posX, posY=b.posY, posZ=b.posZ,
1379 sigmaX=b.sigmaX, sigmaY=b.sigmaY, sigmaZ=b.sigmaZ,
1380 tiltX=b.tiltX, tiltY=b.tiltY,
1381 sigmaXY=b.rhoXY*b.sigmaX*b.sigmaY,
1382 posXErr=b.posXErr, posYErr=b.posYErr, posZErr=b.posZErr,
1383 sigmaXErr=b.sigmaXErr, sigmaYErr=b.sigmaYErr, sigmaZErr=b.sigmaZErr,
1384 tiltXErr=b.tiltXErr, tiltYErr=b.tiltYErr,
1385 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) ) )
1392if (cmd==
'hist' or cmd==
'histvspileup' or cmd==
'pull')
and len(args)==2:
1396 plots.saveAsList = options.output.split(
',')
1398 plots.singleCanvasSize = options.canvas
1399 plots.allCanvasSize = options.canvas
1400 plots.allCanvasDivs = (options.xdivs,options.ydivs)
1402 plots.whatList = var.split(
',')
1403 plots.genPlot(
'all',cmd)
1405 plots.genPlot(var,cmd)
1412if cmd==
'plot' and len(args)==2:
1416 plots.saveAsList = options.output.split(
',')
1418 plots.singleCanvasSize = options.canvas
1419 plots.allCanvasSize = options.canvas
1420 plots.allCanvasDivs = (options.xdivs,options.ydivs)
1422 plotType =
'perbcid'
1423 elif options.vsbunchpos:
1424 plotType =
'vsBunchPos'
1428 plots.whatList = var.split(
',')
1429 plots.genPlot(
'all',plotType)
1431 plots.genPlot(var,plotType)
1438if cmd==
'summary' and len(args)==1:
1440 if not options.msize:
1443 plots.saveAsList = options.output.split(
',')
1444 plots.allCanvasSize =
'landscape'
1447 if "COOL-Current" not in options.ntname:
1448 plots.allCanvasDivs = (4,3)
1449 plots.whatList = [
'posX',
'posY',
'posZ',
'k',
'sigmaX',
'sigmaY',
'sigmaZ',
'nValid',
'tiltX',
'tiltY',
'rhoXY']
1450 datasetinfo=options.ntname.replace(
"-DB_BEAMSPOT",
"").
split(
'.')
1451 labels=[
"%s.%s.%s.%s" % (datasetinfo[0],datasetinfo[1],datasetinfo[2],datasetinfo[3])]
1452 labels+=[
"Generated on %s, at %s (%s)" % (time.strftime(
"%x"), time.strftime(
"%X"), time.strftime(
"%Z"))]
1454 plots.allCanvasDivs = (3,3)
1455 plots.whatList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY']
1460 plots.genPlot(
'all',
'perbcid',labels=labels)
1461 elif options.vsbunchpos:
1462 plots.whatList.remove(
'nValid')
1463 plots.genPlot(
'all',
'vsBunchPos',labels=labels)
1465 plots.genPlot(
'all',
'plot',labels=labels)
1473if cmd==
'ascii' and len(args)==2:
1475 ascii = open(args[1],
'w')
1476 ascii.write(
'# Beam spot data file\n')
1477 ascii.write(
'# Generated %s by %s on host %s using command:\n' % (time.asctime(),getUserName(),getHostName()))
1478 ascii.write(
'# %s\n' % qcmd)
1482 ascii.write(
'%s ' % str(b.fill))
1483 ascii.write(
'%s ' % str(b.timeStart - time0 + int((b.timeEnd-b.timeStart)/2)))
1484 ascii.write(
'%s ' % str(b.posX))
1485 ascii.write(
'%s ' % str(b.posXErr))
1486 ascii.write(
'%s ' % str(b.posY))
1487 ascii.write(
'%s ' % str(b.posYErr))
1488 ascii.write(
'%s ' % str(b.posZ))
1489 ascii.write(
'%s ' % str(b.posZErr))
1490 ascii.write(
'0 0 0 0 0 0 ')
1491 ascii.write(
'%s ' % str(b.sigmaX))
1492 ascii.write(
'%s ' % str(b.sigmaXErr))
1493 ascii.write(
'%s ' % str(b.sigmaY))
1494 ascii.write(
'%s ' % str(b.sigmaYErr))
1495 ascii.write(
'%s ' % str(b.sigmaZ))
1496 ascii.write(
'%s ' % str(b.sigmaZErr))
1497 ascii.write(
'0 0 0\n')
1502if cmd==
'scan' and len(args)==1:
1504 if not options.msize:
1507 if options.timeaxis:
1509 elif options.separation:
1518 plots.allCanvasSize =
'landscape'
1519 plots.allCanvasDivs = (3,3)
1520 plots.whatList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY']
1521 plots.saveAsList = [
'%s-scanfull-%s-all.gif' %(options.name,xtype),
1522 '%s-scanfull-%s-all.eps' %(options.name,xtype),]
1524 if options.separation
and options.overlayScans:
1525 plots.genPlot(
'all',
'plotscan')
1527 plots.genPlot(
'all',
'plot')
1529 plots.whatList.append(
'k')
1532 plots.singleCanvasSize =
'wide'
1533 for var
in plots.whatList:
1534 plots.saveAsList = [
'%s-scanfull-%s-%s.gif' %(options.name,xtype,var),
1535 '%s-scanfull-%s-%s.eps' %(options.name,xtype,var) ]
1536 if options.separation
and options.overlayScans:
1537 graphs = plots.genPlot(var,
'plotscan')
1539 graphs = plots.genPlot(var,
'plot')
1544 scans = [(int(s.split(
'-')[0]), int(s.split(
'-')[1]))
for s
in options.scans.split(
',')]
1548 options.overlayScans =
False
1549 for (lbMin, lbMax)
in scans:
1557 plots.allCanvasSize =
'landscape'
1558 plots.allCanvasDivs = (3,3)
1559 plots.whatList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY']
1560 plots.saveAsList = [
'%s-scan%s-%s-%s-all.gif' %(options.name,lbMin,lbMax,xtype),
1561 '%s-scan%s-%s-%s-all.eps' %(options.name,lbMin,lbMax,xtype) ]
1562 plots.genPlot(
'all',
'plot')
1564 plots.whatList.append(
'k')
1567 plots.singleCanvasSize =
'default'
1568 for var
in plots.whatList:
1569 plots.saveAsList = [
'%s-scan%s-%s-%s-%s.gif' %(options.name,lbMin,lbMax,xtype,var),
1570 '%s-scan%s-%s-%s-%s.eps' %(options.name,lbMin,lbMax,xtype,var) ]
1571 graphs = plots.genPlot(var,
'plot')
1577 print (
'ERROR: Illegal command or number of arguments')
void print(char *figname, TCanvas *c1)
__init__(self, name='MyPlots', otherMethods=[])
writeText(self, var, legendList=[], showRuns=True, showFills=True, showTime=True, otherTitle=None, otherComment=None, legendX=0.6)
bool add(const std::string &hname, TKey *tobj)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
atlasLabel(x, y, isPreliminary=False, color=1, offset=0.115, isForApproval=False, energy=8, customstring="", size=0.05)
drawText(x=0.74, y=0.87, dy=0.06, text='', font=62, color=1, align=11, linesep=';')
drawAxisFrame(xmin, xmax, ymin, ymax, title='', xTitleOffset=None, yTitleOffset=None, doPlot=True, protectFrame=True)
drawLegend(x1, y1, x2, y2, legendList=[], fillColor=0, lineColor=0, textSize=None, protectLegend=True)
drawHorizontalBand(xmin, xmax, y, ywidth, color=33, protectBand=True, centralLine=False)
cleanUpLowStat(allBSResultsInNt, averagenVtx, lbSize)
fillInMissingLbs(allBSResultsInNt, lbSize)
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)