8Calculate beamspot DQ defects automatically from result of beamspot fit and
9produce locally sqlite file that can later be merged into HEAD. Also dump
10results to txt file for linking to web page
13__author__ =
'Carl Gwilliam'
15__usage__ =
'%prog [options] nt.root [nt.root ...]'
22from optparse
import OptionParser
23parser = OptionParser(usage=__usage__, version=__version__)
24parser.add_option(
'-b',
'--batch', dest=
'batch', action=
'store_true', default=
False, help=
'run in batch mode')
25parser.add_option(
'-i',
'--interactive', dest=
'interactive', action=
'store_true', default=
False, help=
'interactive')
26parser.add_option(
'-e',
'--extend', dest=
'extend', action=
'store_true', default=
False, help=
'extend existing SQLite file (default: delete any existing file)')
27parser.add_option(
'',
'--noaverage', dest=
'noaverage', action=
'store_true', default=
False, help=
'do not write per-run average beam spot with large width')
28parser.add_option(
'',
'--statlist', dest=
'statlist', default=
'59', help=
'comma separated list of status word values to accept (must have known fitId)')
29parser.add_option(
'',
'--lbmin', dest=
'lbmin', type=
'int', default=
None, help=
'Minimum LB to consider')
30parser.add_option(
'',
'--lbmax', dest=
'lbmax', type=
'int', default=
None, help=
'Maximum LB to consider')
31parser.add_option(
'-o',
'--output', dest=
'output', default=
'dqflags.db', help=
'name of output COOL SQLite file for DQ (default: dqflags.db')
32parser.add_option(
'-t',
'--tag', dest=
'tag', default=
'nominal', help=
'COOL tag (default: nominal)')
33parser.add_option(
'-a',
'--absent', dest=
'absent', action=
'store_true', default=
False, help=
'Write absent (as well as present) defects to the DB (default: False)')
35(options,args) = parser.parse_args()
37 parser.error(
'wrong number of command line arguments')
42 os.unsetenv(
'DISPLAY')
44from InDetBeamSpotExample
import ROOTUtils
47from InDetBeamSpotExample.Utils
import getRunFromName
52for a
in options.statlist.split(
','):
53 statList.append(int(a))
55 fitIDInt = int( format( int(a),
'08b')[:4], 2)
56 fitIdList.append( fitIDInt )
58 print (
'ERROR: Status word value of %i has no known fitId entry' % int(a))
66runs = [int(getRunFromName(f))
for f
in args]
74print (
'\nDetermining if average beamspot parameters available')
76 print (
'\nExtracting from file ',filename,
':')
78 f = ROOT.TFile(filename)
79 if f.Get(
'BeamSpotNt'):
80 bsNt = BeamSpotNt(filename)
81 elif f.Get(
'Beamspot/Beamspots'):
82 bsNt = BeamSpotFinderNt(filename)
84 for bs
in bsNt.allData():
87 if options.lbmin
and options.lbmin>bs.lbStart:
89 if options.lbmax
and options.lbmax<bs.lbEnd+1:
91 if not bs.status
in statList:
94 fitStatusInt = int( format( bs.status,
'08b')[-2:], 2)
95 fitIDInt = int( format( bs.status,
'08b')[:4], 2)
97 print (
'[%i, %3i - %3i]: %5i vertices, fitStatus = %i, fitID = %i' % (bs.run,bs.lbStart,bs.lbEnd+1,bs.nEvents,fitStatusInt,fitIDInt))
99 minRun =
min(bs.run,minRun)
100 maxRun =
max(bs.run,maxRun)
104 print (
'*** Skipping unsuccessful fit ...\n')
106 if not fitIDInt
in fitIdList:
107 print (
'*** Skipping fit with ID =',fitIDInt,
'\n')
118from InDetBeamSpotExample.DQUtilities
import IDBSDefectWriter
119idbsDefects = IDBSDefectWriter(options.output,
not options.extend)
121if nEntries>0
and not options.noaverage:
122 print (
'\nInitially Setting DQ defect to ID_BS_RUNAVERAGE for runs %s ... %s with average beamspot available' %(minRun, maxRun))
123 idbsDefects.defectType(
'ID_BS_RUNAVERAGE')
125 print (
'\nInitially setting DQ defect to ID_BS_NOBEAMSPOT for runs %s ... %s without average beamspot available' % (minRun, maxRun))
126 idbsDefects.defectType(
'ID_BS_NOBEAMSPOT')
133 for i
in range(minRun,maxRun):
137 print (
'Copying beam spot data from',filename)
138 f = ROOT.TFile(filename)
139 if f.Get(
'BeamSpotNt'):
140 bsNt = BeamSpotNt(filename)
141 elif f.Get(
'Beamspot/Beamspots'):
142 bsNt = BeamSpotFinderNt(filename)
144 for bs
in bsNt.allData():
146 if options.lbmin
and options.lbmin>bs.lbStart:
148 if options.lbmax
and options.lbmax<bs.lbEnd+1:
151 if bs.status
in statList
and bs.lbStart
not in good_lbs[bs.run]:
153 idbsDefects.add(minRun, maxRun, bs.lbStart, bs.lbEnd+1)
154 good_lbs[bs.run][bs.lbStart]=1
157 print (
'WARNING: Skipping entry with status word %3s, lbStart=%4d, lbEnd=%4d' % (bs.status, bs.lbStart, bs.lbEnd))
162idbsDefects.complete(minRun, maxRun)
167 idbsDefects.writeDefects(nonpresent = options.absent)
168 idbsDefects.dump(options.output)
170if options.lbmin
or options.lbmax:
171 print (
'\n**** WARNING: ONLY CONSIDERED ENTRIES IN RANGE [%s,%s] ****\n' % (options.lbmin,options.lbmax))
174if options.interactive:
175 os.environ[
'PYTHONINSPECT'] =
'1'
void print(char *figname, TCanvas *c1)