19from ROOT
import Belle2
29 """Draw BKLM event displays from KLMHit2ds, ExtHits, and MuidHits."""
46 BKLM_MAXSTRIP_BIT = 15
48 BKLM_STRIP_MASK = 0x3f
50 BKLM_PLANE_MASK = (1 << BKLM_PLANE_BIT)
52 BKLM_LAYER_MASK = (15 << BKLM_LAYER_BIT)
54 BKLM_SECTOR_MASK = (7 << BKLM_SECTOR_BIT)
56 BKLM_SECTION_MASK = (1 << BKLM_SECTION_BIT)
58 BKLM_MAXSTRIP_MASK = (63 << BKLM_MAXSTRIP_BIT)
60 BKLM_MODULEID_MASK = (BKLM_SECTION_MASK | BKLM_SECTOR_MASK | BKLM_LAYER_MASK)
62 def __init__(self, exp, run, eventPdfName, maxDisplays, minRPCHits, minMuidHits):
66 exp (str): formatted experiment number
67 run (str): formatter run number
68 eventPdfName (str): path name of the output event-display PDF file
69 maxDisplays (int): max
71 minMuidHits (int): min
94 """Handle job initialization: fill the mapping database, create histograms, open the event-display file"""
100 title = f
'{self.eventPdfName}['
110 self.
sine = [0, 0, 0, 0, 0, 0, 0, 0]
111 for sector
in range(0, 8):
112 phi = math.pi * sector / 4
113 self.
cosine[sector] = math.cos(phi)
114 self.
sine[sector] = math.sin(phi)
116 self.
hist_XY = ROOT.TH2F(
'XY',
' ;x;y', 10, -345.0, 345.0, 10, -345.0, 345.0)
119 self.
hist_ZY = ROOT.TH2F(
'ZY',
' ;z;y', 10, -345.0, 345.0, 10, -345.0, 345.0)
129 self.
hist_XYS[0] = ROOT.TH2F(
'XYS0',
' ;x;y', 10, +u3, +u4, 10, -u5, +u5)
131 self.
hist_XYS[1] = ROOT.TH2F(
'XYS1',
' ;x;y', 10, +u1, +u2, 10, +u1, +u2)
133 self.
hist_XYS[2] = ROOT.TH2F(
'XYS2',
' ;x;y', 10, -u5, +u5, 10, +u3, +u4)
135 self.
hist_XYS[3] = ROOT.TH2F(
'XYS3',
' ;x;y', 10, -u2, -u1, 10, +u1, +u2)
137 self.
hist_XYS[4] = ROOT.TH2F(
'XYS4',
' ;x;y', 10, -u4, -u3, 10, -u5, +u5)
139 self.
hist_XYS[5] = ROOT.TH2F(
'XYS5',
' ;x;y', 10, -u2, -u1, 10, -u2, -u1)
141 self.
hist_XYS[6] = ROOT.TH2F(
'XYS6',
' ;x;y', 10, -u5, +u5, 10, -u4, -u3)
143 self.
hist_XYS[7] = ROOT.TH2F(
'XYS7',
' ;x;y', 10, +u1, +u2, 10, -u2, -u1)
146 self.
hist_ZYS = ROOT.TH2F(
'ZYS',
' ;z;y', 10, -150.0, 150.0, 10, 125.0, 425.0)
148 ROOT.gStyle.SetOptStat(10)
151 r0 = 201.9 + 0.5 * 4.4
153 tan0 = math.tan(math.pi / 8.0)
155 g.SetPoint(0, -200.0, 0.0)
156 g.SetPoint(1, +200.0, 0.0)
162 g.SetPoint(0, 0.0, -200.0)
163 g.SetPoint(1, 0.0, +200.0)
169 g.SetPoint(0, -5.0, 0.0)
170 g.SetPoint(1, +5.0, 0.0)
171 g.SetPoint(2, 0.0, 0.0)
172 g.SetPoint(3, 0.0, +5.0)
173 g.SetPoint(4, 0.0, -5.0)
177 for layer
in range(0, 15):
181 g.SetPoint(0, +r, -x)
182 g.SetPoint(1, +r, +x)
183 g.SetPoint(2, +x, +r)
184 g.SetPoint(3, -x, +r)
185 g.SetPoint(4, -r, +x)
186 g.SetPoint(5, -r, -x)
187 g.SetPoint(6, -x, -r)
188 g.SetPoint(7, +x, -r)
189 g.SetPoint(8, +r, -x)
205 g.SetPoint(0, -zL + z0 - 140.0, 0.0)
206 g.SetPoint(1, +zL + z0 + 70.0, 0.0)
212 g.SetPoint(0, 0.0, -315.0)
213 g.SetPoint(1, 0.0, +340.0)
219 g.SetPoint(0, -5.0, 0.0)
220 g.SetPoint(1, +5.0, 0.0)
221 g.SetPoint(2, 0.0, 0.0)
222 g.SetPoint(3, 0.0, +5.0)
223 g.SetPoint(4, 0.0, -5.0)
228 g.SetPoint(0, -zL + z0, +x0)
229 g.SetPoint(1, -zL + z0, +r0)
235 g.SetPoint(0, -zL + z0, -x0)
236 g.SetPoint(1, -zL + z0, -r0)
242 g.SetPoint(0, +zL + z0, +x0)
243 g.SetPoint(1, +zL + z0, +r0)
249 g.SetPoint(0, +zL + z0, -x0)
250 g.SetPoint(1, +zL + z0, -r0)
256 g.SetPoint(0, -zL + z0, r0)
257 g.SetPoint(1, +zL + z0, r0)
258 g.SetPoint(2, +zL + z0, rF)
259 g.SetPoint(3, -zL + z0, rF)
260 g.SetPoint(4, -zL + z0, r0)
265 g.SetPoint(0, -zL + z0, -r0)
266 g.SetPoint(1, +zL + z0, -r0)
267 g.SetPoint(2, +zL + z0, -rF)
268 g.SetPoint(3, -zL + z0, -rF)
269 g.SetPoint(4, -zL + z0, -r0)
274 g.SetPoint(0, -zL + z0, -x0)
275 g.SetPoint(1, +zL + z0, -x0)
276 g.SetPoint(2, +zL + z0, +x0)
277 g.SetPoint(3, -zL + z0, +x0)
278 g.SetPoint(4, -zL + z0, -x0)
284 for layer
in range(0, 15):
289 g.SetPoint(0, -zL + z0, r)
290 g.SetPoint(1, +zL + z0, r)
297 self.
sectorFBToDC = [11, 15, 2, 6, 10, 14, 3, 7, 9, 13, 0, 4, 8, 12, 1, 5]
299 self.
dcToSectorFB = [10, 14, 2, 6, 11, 15, 3, 7, 12, 8, 4, 0, 13, 9, 5, 1]
309 self.
t0RPC = [8, -14, -6, -14, -2, 10, 9, 13, 0, -10, -14, -20, 2, 6, 14, 11]
311 self.
ct0Scint = [-1, -33, -46, -33, -2, 32, 51, 32, 0, -32, -45, -33, -4, 34, 45, 27]
314 """Handle job termination: close event-display file"""
316 pdfNameLast = f
'{self.eventPdfName}]'
321 """Handle begin of run: print diagnostic message"""
323 print(
'beginRun', EventMetaData.getRun())
326 """Handle end of run: print diagnostic message"""
328 print(
'endRun', EventMetaData.getRun())
331 """Process one event: (optionally) draw event display"""
340 event = EventMetaData.getEvent()
346 rawFb = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
347 rawSector = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
348 rawLayer = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
349 rawPlane = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
350 rawStrip = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
351 rawCtime = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
353 for copper
in range(0, len(rawklms)):
354 rawklm = rawklms[copper]
355 nodeID = rawklm.GetNodeID(0) - self.
BKLM_ID
358 if (nodeID < 0)
or (nodeID > 4):
360 for finesse
in range(0, 4):
361 dc = (finesse << 2) + copper
362 n = rawklm.GetDetectorNwords(0, finesse)
363 bufSlot = rawklm.GetDetectorBuffer(0, finesse)
366 for j
in range(0, n):
367 word0 = bufSlot[j * 2]
368 word1 = bufSlot[j * 2 + 1]
369 ctime = word0 & 0xffff
370 channel = (word0 >> 16) & 0x7f
371 axis = (word0 >> 23) & 0x01
372 lane = (word0 >> 24) & 0x1f
373 flag = (word0 >> 30) & 0x03
379 electId = (channel << 12) | (axis << 11) | (lane << 6) | (finesse << 4) | nodeID
388 rawSector[dc].append(sector)
389 rawLayer[dc].append(layer)
390 rawPlane[dc].append(plane)
391 rawStrip[dc].append(strip)
392 rawCtime[dc].append(ctime)
396 tCal2d.append(hit2d.getTime())
409 for exthit
in exthits:
411 extPosition = exthit.getPosition()
418 if (dx * dx + dy * dy + dz * dz > 36)
and (sumn > 0):
419 eposition = [sumx / sumn, sumy / sumn, sumz / sumn, sold]
420 epositions.append(eposition)
436 eposition = [sumx / sumn, sumy / sumn, sumz / sumn, sold]
437 epositions.append(eposition)
438 extXYGraph = ROOT.TGraph()
439 extXYGraph.SetMarkerColor(30)
440 extXYGraph.SetMarkerSize(2.25)
441 extXYGraph.SetMarkerStyle(21)
442 extZYGraph = ROOT.TGraph()
443 extZYGraph.SetMarkerColor(30)
444 extZYGraph.SetMarkerSize(2.25)
445 extZYGraph.SetMarkerStyle(21)
446 extZYSGraph = [0, 0, 0, 0, 0, 0, 0, 0]
447 for sector
in range(0, 8):
448 extZYSGraph[sector] = ROOT.TGraph()
449 extZYSGraph[sector].SetMarkerColor(30)
450 extZYSGraph[sector].SetMarkerSize(2.25)
451 extZYSGraph[sector].SetMarkerStyle(21)
453 for eposition
in epositions:
458 extXYGraph.SetPoint(j, x, y)
459 extZYGraph.SetPoint(j, z, y)
460 sector = int(eposition[3])
461 nPoint = extZYSGraph[sector].GetN()
462 extZYSGraph[sector].SetPoint(nPoint, z, abs(x * self.
cosine[sector] + y * self.
sine[sector]))
466 zMuids = [0, 0, 0, 0, 0, 0, 0, 0]
467 nMuids = [0, 0, 0, 0, 0, 0, 0, 0]
468 muidXYGraph = ROOT.TGraph()
469 muidXYGraph.SetMarkerColor(5)
470 muidXYGraph.SetMarkerSize(2.0)
471 muidXYGraph.SetMarkerStyle(20)
472 muidZYGraph = ROOT.TGraph()
473 muidZYGraph.SetMarkerColor(5)
474 muidZYGraph.SetMarkerSize(2.0)
475 muidZYGraph.SetMarkerStyle(20)
476 muidZYSGraph = [0, 0, 0, 0, 0, 0, 0, 0]
477 for sector
in range(0, 8):
478 muidZYSGraph[sector] = ROOT.TGraph()
479 muidZYSGraph[sector].SetMarkerColor(5)
480 muidZYSGraph[sector].SetMarkerSize(2.0)
481 muidZYSGraph[sector].SetMarkerStyle(20)
483 for muidhit
in muidhits:
485 muidPosition = muidhit.getExtPosition()
489 muidXYGraph.SetPoint(j, x, y)
490 muidZYGraph.SetPoint(j, z, y)
491 sector = muidhit.getSector()
492 nPoint = muidZYSGraph[sector].GetN()
493 muidZYSGraph[sector].SetPoint(nPoint, z, abs(x * self.
cosine[sector] + y * self.
sine[sector]))
494 if nMuids[sector] == 0:
500 rpcHitCount = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
501 promptXYGraph = ROOT.TGraph()
502 promptXYGraph.SetMarkerColor(4)
503 promptXYGraph.SetMarkerSize(2.0)
504 promptXYGraph.SetMarkerStyle(29)
505 promptZYGraph = ROOT.TGraph()
506 promptZYGraph.SetMarkerColor(4)
507 promptZYGraph.SetMarkerSize(2.0)
508 promptZYGraph.SetMarkerStyle(29)
509 bkgdXYGraph = ROOT.TGraph()
510 bkgdXYGraph.SetMarkerColor(2)
511 bkgdXYGraph.SetMarkerSize(2.0)
512 bkgdXYGraph.SetMarkerStyle(29)
513 bkgdZYGraph = ROOT.TGraph()
514 bkgdZYGraph.SetMarkerColor(2)
515 bkgdZYGraph.SetMarkerSize(2.0)
516 bkgdZYGraph.SetMarkerStyle(29)
517 promptZYSGraph = [0, 0, 0, 0, 0, 0, 0, 0]
518 bkgdZYSGraph = [0, 0, 0, 0, 0, 0, 0, 0]
519 for sector
in range(0, 8):
520 promptZYSGraph[sector] = ROOT.TGraph()
521 promptZYSGraph[sector].SetMarkerColor(4)
522 promptZYSGraph[sector].SetMarkerSize(2.0)
523 promptZYSGraph[sector].SetMarkerStyle(29)
524 bkgdZYSGraph[sector] = ROOT.TGraph()
525 bkgdZYSGraph[sector].SetMarkerColor(2)
526 bkgdZYSGraph[sector].SetMarkerSize(2.0)
527 bkgdZYSGraph[sector].SetMarkerStyle(29)
531 key = hit2d.getModuleID()
535 phiStripMin = hit2d.getPhiStripMin() - 1
536 phiStripMax = hit2d.getPhiStripMax() - 1
537 zStripMin = hit2d.getZStripMin() - 1
538 zStripMax = hit2d.getZStripMax() - 1
539 sectorFB = sector
if fb == 0
else sector + 8
541 rpcHitCount[sectorFB] += 1
545 n = rawklms[copper].GetDetectorNwords(0, finesse) >> 1
546 trigCtime = (rawklms[copper].GetTTCtime(0) & 0x07ffffff) << 3
553 for j
in range(0, n):
554 if layer != rawLayer[dc][j]:
556 if sector != rawSector[dc][j]:
558 if fb != rawFb[dc][j]:
560 strip = rawStrip[dc][j]
561 plane = rawPlane[dc][j]
563 if strip < zStripMin:
565 if strip > zStripMax:
567 ctZ = rawCtime[dc][j] << 3
570 if strip < phiStripMin:
572 if strip > phiStripMax:
574 ctPhi = rawCtime[dc][j] << 3
576 if (jZ >= 0)
and (jPhi >= 0):
578 if abs(ctZ - ctPhi) > 40:
580 ct = int((ctZ + ctPhi) * 0.5 - trigCtime - self.
ct0Scint[sectorFB]) & 0x3ff
581 if abs(ct - self.
ct0Cal) < ctDiffMax:
582 ctDiffMax = int(abs(ct - self.
ct0Cal))
587 tCal = ((int(hit2d.getTime()) - trigCtime) & 0x03ff) - self.
t0RPC[sectorFB] - 0.75 * jPhi - 0.75 * jZ
589 x = hit2d.getGlobalPositionX()
590 y = hit2d.getGlobalPositionY()
591 z = hit2d.getGlobalPositionZ()
597 if abs(tCal - self.
t0Cal2d) < 20:
601 promptXYGraph.SetPoint(jPrompt, x, y)
602 promptZYGraph.SetPoint(jPrompt, z, y)
603 nPoint = promptZYSGraph[sector].GetN()
604 promptZYSGraph[sector].SetPoint(nPoint, z, abs(x * self.
cosine[sector] + y * self.
sine[sector]))
607 bkgdXYGraph.SetPoint(jBkgd, x, y)
608 bkgdZYGraph.SetPoint(jBkgd, z, y)
609 nPoint = bkgdZYSGraph[sector].GetN()
610 bkgdZYSGraph[sector].SetPoint(nPoint, z, abs(x * self.
cosine[sector] + y * self.
sine[sector]))
612 hasEnoughRPCHits =
False
613 for count
in rpcHitCount:
615 hasEnoughRPCHits =
True
617 if hasEnoughRPCHits
and (len(muidhits) > self.
minMuidHits):
619 title = f
'e{int(self.exp):02d}r{int(self.run)}: event {event}'
626 if extXYGraph.GetN() > 0:
628 if muidXYGraph.GetN() > 0:
629 muidXYGraph.Draw(
"P")
630 if bkgdXYGraph.GetN() > 0:
631 bkgdXYGraph.Draw(
"P")
632 if promptXYGraph.GetN() > 0:
633 promptXYGraph.Draw(
"P")
638 if extZYGraph.GetN() > 0:
640 if muidZYGraph.GetN() > 0:
641 muidZYGraph.Draw(
"P")
642 if bkgdZYGraph.GetN() > 0:
643 bkgdZYGraph.Draw(
"P")
644 if promptZYGraph.GetN() > 0:
645 promptZYGraph.Draw(
"P")
646 self.
lastTitle = f
"Title:E{event} (#{self.eventCounter})"
648 for sector
in range(0, 8):
649 if nMuids[sector] > 0:
650 title = f
'e{int(self.exp):02d}r{int(self.run)}: event {event} sector {sector}'
651 self.
hist_XYS[sector].SetTitle(title)
656 if extXYGraph.GetN() > 0:
658 if muidXYGraph.GetN() > 0:
659 muidXYGraph.Draw(
"P")
660 if bkgdXYGraph.GetN() > 0:
661 bkgdXYGraph.Draw(
"P")
662 if promptXYGraph.GetN() > 0:
663 promptXYGraph.Draw(
"P")
667 self.
hist_ZYS.SetBins(10, z0 - 150.0, z0 + 150.0, 10, 125.0, 425.0)
673 if extZYSGraph[sector].GetN() > 0:
674 extZYSGraph[sector].Draw(
"P")
675 if muidZYSGraph[sector].GetN() > 0:
676 muidZYSGraph[sector].Draw(
"P")
677 if bkgdZYSGraph[sector].GetN() > 0:
678 bkgdZYSGraph[sector].Draw(
"P")
679 if promptZYSGraph[sector].GetN() > 0:
680 promptZYSGraph[sector].Draw(
"P")
681 self.
lastTitle = f
"Title:E{event} sector {sector}"
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
int EKLM_ID
COPPER base identifier for EKLM readout.
run
internal copy of run number
hist_ZYS
blank scatterplot to define the per-sector bounds of the rotated BKLM side view
sine
table of sines for the BKLM-sector normals
hist_XY
blank scatterplot to define the bounds of the BKLM end view
int BKLM_SECTOR_BIT
bit position for sector-1 [0..7]; 0 is on the +x axis and 2 is on the +y axis
ct0Scint
per-sector variations in scint-ctime calibration adjustment (ns) for rawKLMs
ct0Cal
scint-ctime calibration adjustment (ns) for rawKLMs
tuple BKLM_SECTOR_MASK
bit mask for sector-1 [0..7]; 0 is on the +x axis and 2 is on the +y axis
ct0Cal2d
scint-ctime calibration adjustment (ns) for KLMHit2ds
tuple BKLM_SECTION_MASK
bit mask for section [0..1]; forward is 0
eventCanvas
TCanvas on which event displays will be drawn.
def __init__(self, exp, run, eventPdfName, maxDisplays, minRPCHits, minMuidHits)
eventPdfName
internal copy of the pathname of the output event-display PDF file
maxDisplays
internal copy of the maximum number of event displays to write
t0RPC
per-sector variations in RPC-time calibration adjustment (ns) for rawKLMs
int BKLM_PLANE_BIT
bit position for plane-1 [0..1]; 0 is inner-plane
eventCounter
event counter (needed for PDF table of contents' ordinal event#)
bklmZYL
list of line-segment (z,y) points for the BKLM sector's zoomed and rotated side view
t0Cal
RPC-time calibration adjustment (ns) for rawKLMs.
minMuidHits
internal copy of the minimum number of MuidHits in the event for event display
dcToSectorFB
map for data concentrator -> sectorFB
int BKLM_STRIP_BIT
bit position for strip-1 [0..47]
hist_XYS
list of blank scatterplots to define the per-sector bounds of the BKLM end view
int BKLM_ID
COPPER base identifier for BKLM readout.
hist_ZY
blank scatterplot to define the bounds of the BKLM side view
minRPCHits
internal copy of the minimum number of RPC KLMHit2ds in any sector for event display
exp
internal copy of experiment number
tuple BKLM_LAYER_MASK
bit mask for layer-1 [0..15]; 0 is innermost and 14 is outermost
bklmZY
list of line-segment (z,y) points for the BKLM side view
cosine
table of cosines for the BKLM-sector normals
eventDisplays
event-display counter
lastTitle
title of the last-drawn event display (needed for PDF table of contents' last event)
tuple BKLM_PLANE_MASK
bit mask for plane-1 [0..1]; 0 is inner-plane
int BKLM_SECTION_BIT
bit position for section [0..1]; forward is 0
int BKLM_LAYER_BIT
bit position for layer-1 [0..14]; 0 is innermost
bklmXY
list of line-segment (x,y) points for the BKLM end view
t0Cal2d
RPC-time calibration adjustment (ns) for KLMHit2ds.
electIdToModuleId
readout <-> detector map (from the information retrieved from the conditions database)
int BKLM_STRIP_MASK
bit mask for strip-1 [0..47]
sectorFBToDC
map for sectorFB -> data concentrator