12 from ROOT
import Belle2, TH1F, TH2F, TCanvas, THistPainter, TPad, TFile
16 """Fill BKLM histograms of values from RawKLMs, KLMDigits, BKLMHit1ds, and BKLMHit2ds;
17 (optionally) draw event displays from these data-objects."""
34 BKLM_MAXSTRIP_BIT = 15
36 BKLM_STRIP_MASK = 0x3f
38 BKLM_PLANE_MASK = (1 << BKLM_PLANE_BIT)
40 BKLM_LAYER_MASK = (15 << BKLM_LAYER_BIT)
42 BKLM_SECTOR_MASK = (7 << BKLM_SECTOR_BIT)
44 BKLM_SECTION_MASK = (1 << BKLM_SECTION_BIT)
46 BKLM_MAXSTRIP_MASK = (63 << BKLM_MAXSTRIP_BIT)
48 BKLM_MODULEID_MASK = (BKLM_SECTION_MASK | BKLM_SECTOR_MASK | BKLM_LAYER_MASK)
50 def __init__(self, exp, run, histName, pdfName):
54 exp (str): formatted experiment number
55 run (str): formatter run number
56 histName (str): path name of the output histogram ROOT file
57 pdfName (str): path name of the output histogram PDF file
58 eventPdfName (str): path name of the output event-display PDF file
59 maxDisplays (int): max # of events displays to write
60 minRPCHits (int): min # of RPC BKLMHit2ds in any sector for event display
73 """Create and return a ROOT TGraph
76 x[] (real): x coordinates
77 y[] (real): y coordinates
80 for i
in range(0, len(x)):
81 graph.SetPoint(i, x[i], y[i])
87 """Create and return a ROOT TLatex with the following properties:
88 size = 0.04, color = red, alignment = middle centre, angle = 90 degrees
91 x (real): x coordinate
92 y (real): y coordinate
93 s (str): character string
95 text = ROOT.TLatex(x, y, s)
96 text.SetTextSize(0.04)
103 """Handle job initialization: create histograms"""
105 expRun =
'e{0:02d}r{1}: '.format(int(self.
exp), int(self.
run))
114 expRun +
'tt_ctime relative to triggertime;' +
115 'tt_ctime - triggertime (ns)',
119 expRun +
'RawKLM lane;Lane (scint: 1..7, RPC: 8..20)',
123 expRun +
'RawKLM word count (N/channel)',
127 expRun +
'RawKLM word count (1/channel)',
131 'PerChannelMultiplicity',
132 expRun +
'Per-channel multiplicity (N/channel > 1);' +
133 'Per-channel multiplicity;' +
134 '(Lane #) * 2 + (Axis #)',
135 30, -0.5, 29.5, 42, -0.5, 41.5)
138 'RPCLaneAxisOccupancy',
139 expRun +
'Lane/axis occupancy of RPC channels (1/channel);' +
140 'Sector # (always 0);' +
141 '(Lane #) * 2 + (Axis #)',
142 3, -1.5, 1.5, 42, -0.5, 41.5)
145 'ScintLaneAxisOccupancy',
146 expRun +
'Lane/axis occupancy of scint channels (1/channel);' +
147 'Sector # (always 0);' +
148 '(Lane #) * 2 + (Axis #)',
149 3, -1.5, 1.5, 42, -0.5, 41.5)
153 expRun +
'Channel occupancy for axis 0;lane;channel',
154 42, -0.25, 20.75, 128, -0.25, 63.75)
156 expRun +
'Channel occupancy for axis 1;lane;channel',
157 42, -0.25, 20.75, 128, -0.25, 63.75)
160 [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
161 [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
162 [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]
163 for lane
in range(0, 21):
164 nChannels = 64
if (lane > 2)
else 128
165 label =
'ChannelOccupancy_A0L{0}'.format(lane)
166 title =
'{0}Channel occupancy for axis 0 lane {1};channel'.format(expRun, lane)
168 label =
'ChannelOccupancy_A1L{0}'.format(lane)
169 title =
'{0}Channel occupancy for axis 1 lane {1};channel'.format(expRun, lane)
173 expRun +
'RPC TDC lowest-order bits;' +
174 'Sector # (always 0);' +
175 'TDC % 4 (ns) [should be 0]',
176 3, -1.5, 1.5, 8, -0.25, 3.75)
179 expRun +
'RPC tdc relative to event trigtime;tdc - triggerTime (ns)',
183 expRun +
'RPC tdc relative to event ctime;tdc - trigCtime (ns)',
186 self.
hist_RPCTimePerLayerA0 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
187 for lane
in range(0, 21):
188 label =
'RPCTimeA0L{0:02d}'.format(lane)
189 title =
'{0}RPC axis 0 lane {1} time relative to trigtime;t - triggerTime (ns)'.format(expRun, lane)
192 self.
hist_RPCTimePerLayerA1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
193 for lane
in range(0, 21):
194 label =
'RPCTimeA1L{0:02d}'.format(lane)
195 title =
'{0}RPC axis 1 lane {1} time relative to trigtime;t - triggerTime (ns)'.format(expRun, lane)
198 self.
hist_RPCTime2PerLayerA0 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
199 for lane
in range(0, 21):
200 label =
'RPCTime2A0L{0:02d}'.format(lane)
201 title =
'{0}RPC axis 0 lane {1} time relative to trigCtime;t - trigCtime (ns)'.format(expRun, lane)
204 self.
hist_RPCTime2PerLayerA1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
205 for lane
in range(0, 21):
206 label =
'RPCTime2A1L{0:02d}'.format(lane)
207 title =
'{0}RPC axis 1 lane {1} time relative to trigCtime;t - trigCtime (ns)'.format(expRun, lane)
210 self.
hist_RPCTdcRange = ROOT.TH1F(
'RPCTdcRange', expRun +
'RPC TDC-range in event;TDCMax - TDCMin (ns)', 512, -0.5, 2047.5)
213 expRun +
'RPC revotime-range in event;revotimeMax - revotimeMin (ns)',
217 expRun +
'RPC TDC vs revotime;tdc (ns);revotime - minRevotime',
218 64, 767.5, 1023.5, 10, -0.5, 159.5)
222 expRun +
'RPC TDC vs revotime;' +
223 'tdc - dt(index) (ns);' +
224 'revotime - minRevotime',
225 64, 767.5, 1023.5, 10, -0.5, 159.5)
228 expRun +
'RPC TDC vs hit index;tdc (ns);Hit index',
229 64, 767.5, 1023.5, 60, -0.5, 59.5)
232 expRun +
'RPC TDC vs hit index;tdc - dt(index) (ns);Hit index',
233 64, 767.5, 1023.5, 60, -0.5, 59.5)
236 'ScintTimeLowBitsBySector',
237 expRun +
'Scint TDC lowest-order bits;' +
238 'Sector # (always 0);' +
240 3, -1.5, 1.5, 8, -0.25, 3.75)
243 expRun +
'Scint tdc distribution;tdc - triggerTime (ns)',
247 expRun +
'Scint ctime distribution;ctime - triggerCtime (ns)',
251 expRun +
'Scint ctime distribution;ctime - triggerTime (ns)',
255 'ScintCtimeRange', expRun +
'Scint ctime-range in event;ctimeMax - ctimeMin (ns)', 128, -0.5, 8191.5)
258 """Handle job termination: draw histograms, close output files"""
260 canvas = ROOT.TCanvas(
"canvas", self.
pdfName, 1600, 1600)
261 title =
'{0}['.format(self.
pdfName)
264 canvas.GetPad(0).SetGrid(1, 1)
265 canvas.GetPad(0).Update()
276 canvas.GetPad(0).SetGrid(1, 1)
277 canvas.GetPad(1).SetGrid(1, 1)
278 canvas.GetPad(2).SetGrid(1, 1)
279 for sectorFB
in range(0, 1):
285 for lane
in range(0, 21):
302 for lane
in range(0, 21):
306 for lane
in range(0, 21):
332 pdfNameLast =
'{0}]'.format(self.
pdfName)
339 """Handle begin of run: print diagnostic message"""
340 print(
'beginRun', self.
run)
343 """Handle end of run: print diagnostic message"""
344 print(
'endRun', self.
run)
346 def event(self, eventHits, tt_ctime, raw_time):
347 """Process one event: fill histograms"""
351 countAllMultihit = 2 * n + 1
if (n > 0)
else 0
353 channelMultiplicity = {}
359 minScintCtime = 99999
362 for j
in range(0, n):
368 flag = 1
if (lane > 2)
else 2
370 isScint = (flag == 2)
371 laneAxisChannel = (((lane << 1) + axis) << 7) + channel
372 if laneAxisChannel
not in channelMultiplicity:
373 countAll = countAll + 2
374 channelMultiplicity[laneAxisChannel] = 0
375 channelMultiplicity[laneAxisChannel] = channelMultiplicity[laneAxisChannel] + 1
379 for j
in range(0, n):
387 flag = 1
if (lane > 2)
else 2
389 isScint = (flag == 2)
390 laneAxisChannel = (((lane << 1) + axis) << 7) + channel
391 laneAxis = axis
if ((lane < 1)
or (lane > 20))
else ((lane << 1) + axis)
392 if laneAxisChannel
in channelMultiplicity:
393 if channelMultiplicity[laneAxisChannel] > 1:
396 t = (tdc - raw_time) & 0x03ff
397 t2 = (tdc - tt_ctime) & 0x03ff
398 ct = ((ctime << 3) - tt_ctime) & 0x3ff
404 if ctime < minRPCCtime:
406 if ctime > maxRPCCtime:
425 if ctime < minScintCtime:
426 minScintCtime = ctime
427 if ctime > maxScintCtime:
428 maxScintCtime = ctime
441 if maxScintCtime > 0: