40import EventInspectorPocketDAQ
43from optparse
import OptionParser
46parser = OptionParser()
47parser.add_option(
'-i',
'--inputfile',
48 dest=
'infilename', default=
'',
49 help=
'Input ROOT filename [no default]')
50parser.add_option(
'-e',
'--experiment',
51 dest=
'eNumber', default=
'',
52 help=
'Experiment number [no default]')
53parser.add_option(
'-r',
'--run',
54 dest=
'rNumber', default=
'',
55 help=
'Run number [no default]')
56parser.add_option(
'-n',
'--nEvents',
57 dest=
'nEvents', default=
'',
58 help=
'# of events to process [no default]')
59parser.add_option(
'-f',
'--filter',
60 dest=
'eventFilter', default=
'',
61 help=
'Event filter (0=evens, 1=odds) [no default]')
62(options, args) = parser.parse_args()
65if options.nEvents !=
'':
66 maxCount = int(options.nEvents)
68 print(
"Maximum number of events to analyze is", maxCount,
" - nothing to do.")
72if (options.eventFilter ==
'0')
or (options.eventFilter ==
'1'):
73 eventFilter = int(options.eventFilter)
78if options.infilename !=
'':
79 inputName = options.infilename
80 fileList = glob.glob(inputName)
81 if len(fileList) == 0:
82 print(f
"No file(s) match {inputName}")
84 inputName = fileList[0].replace(
"f00000",
"f*")
86 print(f
"Missing input filename (required parameter) for experiment <{options.eNumber}> run <{options.rNumber}>")
88if not options.eNumber.isdecimal():
89 print(f
"Experiment number ({options.eNumber}) is not valid")
91exp = f
'{int(options.eNumber):04d}'
92if not options.rNumber.isdecimal():
93 print(f
"Run number ({options.rNumber}) is not valid")
95run = f
'{int(options.rNumber):05d}'
97infile = TFile(fileList[0])
98histName = f
'bklmHists-e{exp}r{run}.root'
99pdfName = f
'bklmPlots-e{exp}r{run}.pdf'
102 print(
'bklm-pocketdaq: exp=' + exp +
' run=' + run +
' input=', options.infilename +
' - processing even-numbered events')
103elif eventFilter == 1:
104 print(
'bklm-pocketdaq: exp=' + exp +
' run=' + run +
' input=', options.infilename +
' - processing odd-numbered events')
106 print(
'bklm-pocketdaq: exp=' + exp +
' run=' + run +
' input=', options.infilename)
109inspector.initialize()
116for row
in infile.Get(
'KLM_raw_hits'):
118 if (maxCount > 0)
and (row.eventNr >= maxCount):
121 if (eventFilter >= 0)
and (row.eventNr % 2) != eventFilter:
123 items = (row.lane, row.channel, row.axis, row.ctime, row.tdc, row.charge)
124 newEventNumber = row.eventNr
125 if newEventNumber == eventNumber:
126 eventHits.append(items)
129 inspector.event(eventHits, tt_ctime, raw_time)
131 eventNumber = newEventNumber
133 print(f
'*** Event {eventNumber} is broken!')
135 eventHits.append(items)
136 tt_ctime = row.tt_ctime << 3
137 raw_time = (row.raw_time >> 16) << 3
139 inspector.event(eventHits, tt_ctime, raw_time)
142print(
'# of analyzed events = ', count)