14 from ROOT
import Belle2, TH1F, TH2F, TCanvas, THistPainter, TPad
24 """Draw BKLM event displays from BKLMHit2ds, ExtHits, and MuidHits."""
41 BKLM_MAXSTRIP_BIT = 15
43 BKLM_STRIP_MASK = 0x3f
45 BKLM_PLANE_MASK = (1 << BKLM_PLANE_BIT)
47 BKLM_LAYER_MASK = (15 << BKLM_LAYER_BIT)
49 BKLM_SECTOR_MASK = (7 << BKLM_SECTOR_BIT)
51 BKLM_SECTION_MASK = (1 << BKLM_SECTION_BIT)
53 BKLM_MAXSTRIP_MASK = (63 << BKLM_MAXSTRIP_BIT)
55 BKLM_MODULEID_MASK = (BKLM_SECTION_MASK | BKLM_SECTOR_MASK | BKLM_LAYER_MASK)
57 def __init__(self, exp, run, eventPdfName, maxDisplays, minRPCHits, minMuidHits):
61 exp (str): formatted experiment number
62 run (str): formatter run number
63 eventPdfName (str): path name of the output event-display PDF file
64 maxDisplays (int): max # of events displays to write
65 minRPCHits (int): min # of RPC BKLMHit2ds in any sector for event display
66 minMuidHits (int): min # of MuidHits in the event for event display
89 """Handle job initialization: fill the mapping database, create histograms, open the event-display file"""
91 expRun =
'e{0:02d}r{1}: '.format(int(self.
exp), int(self.
run))
107 self.
sine = [0, 0, 0, 0, 0, 0, 0, 0]
108 for sector
in range(0, 8):
109 phi = math.pi * sector / 4
110 self.
cosine[sector] = math.cos(phi)
111 self.
sine[sector] = math.sin(phi)
113 self.
hist_XY = ROOT.TH2F(
'XY',
' ;x;y', 10, -345.0, 345.0, 10, -345.0, 345.0)
116 self.
hist_ZY = ROOT.TH2F(
'ZY',
' ;z;y', 10, -345.0, 345.0, 10, -345.0, 345.0)
126 self.
hist_XYS[0] = ROOT.TH2F(
'XYS0',
' ;x;y', 10, +u3, +u4, 10, -u5, +u5)
128 self.
hist_XYS[1] = ROOT.TH2F(
'XYS1',
' ;x;y', 10, +u1, +u2, 10, +u1, +u2)
130 self.
hist_XYS[2] = ROOT.TH2F(
'XYS2',
' ;x;y', 10, -u5, +u5, 10, +u3, +u4)
132 self.
hist_XYS[3] = ROOT.TH2F(
'XYS3',
' ;x;y', 10, -u2, -u1, 10, +u1, +u2)
134 self.
hist_XYS[4] = ROOT.TH2F(
'XYS4',
' ;x;y', 10, -u4, -u3, 10, -u5, +u5)
136 self.
hist_XYS[5] = ROOT.TH2F(
'XYS5',
' ;x;y', 10, -u2, -u1, 10, -u2, -u1)
138 self.
hist_XYS[6] = ROOT.TH2F(
'XYS6',
' ;x;y', 10, -u5, +u5, 10, -u4, -u3)
140 self.
hist_XYS[7] = ROOT.TH2F(
'XYS7',
' ;x;y', 10, +u1, +u2, 10, -u2, -u1)
143 self.
hist_ZYS = ROOT.TH2F(
'ZYS',
' ;z;y', 10, -150.0, 150.0, 10, 125.0, 425.0)
145 ROOT.gStyle.SetOptStat(10)
148 r0 = 201.9 + 0.5 * 4.4
150 tan0 = math.tan(math.pi / 8.0)
152 g.SetPoint(0, -200.0, 0.0)
153 g.SetPoint(1, +200.0, 0.0)
159 g.SetPoint(0, 0.0, -200.0)
160 g.SetPoint(1, 0.0, +200.0)
166 g.SetPoint(0, -5.0, 0.0)
167 g.SetPoint(1, +5.0, 0.0)
168 g.SetPoint(2, 0.0, 0.0)
169 g.SetPoint(3, 0.0, +5.0)
170 g.SetPoint(4, 0.0, -5.0)
174 for layer
in range(0, 15):
178 g.SetPoint(0, +r, -x)
179 g.SetPoint(1, +r, +x)
180 g.SetPoint(2, +x, +r)
181 g.SetPoint(3, -x, +r)
182 g.SetPoint(4, -r, +x)
183 g.SetPoint(5, -r, -x)
184 g.SetPoint(6, -x, -r)
185 g.SetPoint(7, +x, -r)
186 g.SetPoint(8, +r, -x)
202 g.SetPoint(0, -zL + z0 - 140.0, 0.0)
203 g.SetPoint(1, +zL + z0 + 70.0, 0.0)
209 g.SetPoint(0, 0.0, -315.0)
210 g.SetPoint(1, 0.0, +340.0)
216 g.SetPoint(0, -5.0, 0.0)
217 g.SetPoint(1, +5.0, 0.0)
218 g.SetPoint(2, 0.0, 0.0)
219 g.SetPoint(3, 0.0, +5.0)
220 g.SetPoint(4, 0.0, -5.0)
225 g.SetPoint(0, -zL + z0, +x0)
226 g.SetPoint(1, -zL + z0, +r0)
232 g.SetPoint(0, -zL + z0, -x0)
233 g.SetPoint(1, -zL + z0, -r0)
239 g.SetPoint(0, +zL + z0, +x0)
240 g.SetPoint(1, +zL + z0, +r0)
246 g.SetPoint(0, +zL + z0, -x0)
247 g.SetPoint(1, +zL + z0, -r0)
253 g.SetPoint(0, -zL + z0, r0)
254 g.SetPoint(1, +zL + z0, r0)
255 g.SetPoint(2, +zL + z0, rF)
256 g.SetPoint(3, -zL + z0, rF)
257 g.SetPoint(4, -zL + z0, r0)
262 g.SetPoint(0, -zL + z0, -r0)
263 g.SetPoint(1, +zL + z0, -r0)
264 g.SetPoint(2, +zL + z0, -rF)
265 g.SetPoint(3, -zL + z0, -rF)
266 g.SetPoint(4, -zL + z0, -r0)
271 g.SetPoint(0, -zL + z0, -x0)
272 g.SetPoint(1, +zL + z0, -x0)
273 g.SetPoint(2, +zL + z0, +x0)
274 g.SetPoint(3, -zL + z0, +x0)
275 g.SetPoint(4, -zL + z0, -x0)
281 for layer
in range(0, 15):
286 g.SetPoint(0, -zL + z0, r)
287 g.SetPoint(1, +zL + z0, r)
294 self.
sectorFBToDC = [11, 15, 2, 6, 10, 14, 3, 7, 9, 13, 0, 4, 8, 12, 1, 5]
296 self.
dcToSectorFB = [10, 14, 2, 6, 11, 15, 3, 7, 12, 8, 4, 0, 13, 9, 5, 1]
306 self.
t0RPC = [8, -14, -6, -14, -2, 10, 9, 13, 0, -10, -14, -20, 2, 6, 14, 11]
308 self.
ct0Scint = [-1, -33, -46, -33, -2, 32, 51, 32, 0, -32, -45, -33, -4, 34, 45, 27]
311 """Handle job termination: close event-display file"""
318 """Handle begin of run: print diagnostic message"""
320 print(
'beginRun', EventMetaData.getRun())
323 """Handle end of run: print diagnostic message"""
325 print(
'endRun', EventMetaData.getRun())
328 """Process one event: (optionally) draw event display"""
337 event = EventMetaData.getEvent()
343 rawFb = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
344 rawSector = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
345 rawLayer = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
346 rawPlane = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
347 rawStrip = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
348 rawCtime = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
350 for copper
in range(0, len(rawklms)):
351 rawklm = rawklms[copper]
352 nodeID = rawklm.GetNodeID(0) - self.
BKLM_ID
355 if (nodeID < 0)
or (nodeID > 4):
357 for finesse
in range(0, 4):
358 dc = (finesse << 2) + copper
359 n = rawklm.GetDetectorNwords(0, finesse)
360 bufSlot = rawklm.GetDetectorBuffer(0, finesse)
363 for j
in range(0, n):
364 word0 = bufSlot[j * 2]
365 word1 = bufSlot[j * 2 + 1]
366 ctime = word0 & 0xffff
367 channel = (word0 >> 16) & 0x7f
368 axis = (word0 >> 23) & 0x01
369 lane = (word0 >> 24) & 0x1f
370 flag = (word0 >> 30) & 0x03
376 electId = (channel << 12) | (axis << 11) | (lane << 6) | (finesse << 4) | nodeID
385 rawSector[dc].append(sector)
386 rawLayer[dc].append(layer)
387 rawPlane[dc].append(plane)
388 rawStrip[dc].append(strip)
389 rawCtime[dc].append(ctime)
393 tCal2d.append(hit2d.getTime())
406 for exthit
in exthits:
408 extPosition = exthit.getPosition()
415 if (dx * dx + dy * dy + dz * dz > 36)
and (sumn > 0):
416 eposition = [sumx / sumn, sumy / sumn, sumz / sumn, sold]
417 epositions.append(eposition)
433 eposition = [sumx / sumn, sumy / sumn, sumz / sumn, sold]
434 epositions.append(eposition)
435 extXYGraph = ROOT.TGraph()
436 extXYGraph.SetMarkerColor(30)
437 extXYGraph.SetMarkerSize(2.25)
438 extXYGraph.SetMarkerStyle(21)
439 extZYGraph = ROOT.TGraph()
440 extZYGraph.SetMarkerColor(30)
441 extZYGraph.SetMarkerSize(2.25)
442 extZYGraph.SetMarkerStyle(21)
443 extZYSGraph = [0, 0, 0, 0, 0, 0, 0, 0]
444 for sector
in range(0, 8):
445 extZYSGraph[sector] = ROOT.TGraph()
446 extZYSGraph[sector].SetMarkerColor(30)
447 extZYSGraph[sector].SetMarkerSize(2.25)
448 extZYSGraph[sector].SetMarkerStyle(21)
450 for eposition
in epositions:
455 extXYGraph.SetPoint(j, x, y)
456 extZYGraph.SetPoint(j, z, y)
457 sector = int(eposition[3])
458 nPoint = extZYSGraph[sector].GetN()
459 extZYSGraph[sector].SetPoint(nPoint, z, abs(x * self.
cosine[sector] + y * self.
sine[sector]))
463 zMuids = [0, 0, 0, 0, 0, 0, 0, 0]
464 nMuids = [0, 0, 0, 0, 0, 0, 0, 0]
465 muidXYGraph = ROOT.TGraph()
466 muidXYGraph.SetMarkerColor(5)
467 muidXYGraph.SetMarkerSize(2.0)
468 muidXYGraph.SetMarkerStyle(20)
469 muidZYGraph = ROOT.TGraph()
470 muidZYGraph.SetMarkerColor(5)
471 muidZYGraph.SetMarkerSize(2.0)
472 muidZYGraph.SetMarkerStyle(20)
473 muidZYSGraph = [0, 0, 0, 0, 0, 0, 0, 0]
474 for sector
in range(0, 8):
475 muidZYSGraph[sector] = ROOT.TGraph()
476 muidZYSGraph[sector].SetMarkerColor(5)
477 muidZYSGraph[sector].SetMarkerSize(2.0)
478 muidZYSGraph[sector].SetMarkerStyle(20)
480 for muidhit
in muidhits:
482 muidPosition = muidhit.getExtPosition()
486 muidXYGraph.SetPoint(j, x, y)
487 muidZYGraph.SetPoint(j, z, y)
488 sector = muidhit.getSector()
489 nPoint = muidZYSGraph[sector].GetN()
490 muidZYSGraph[sector].SetPoint(nPoint, z, abs(x * self.
cosine[sector] + y * self.
sine[sector]))
491 if nMuids[sector] == 0:
497 rpcHitCount = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
498 promptXYGraph = ROOT.TGraph()
499 promptXYGraph.SetMarkerColor(4)
500 promptXYGraph.SetMarkerSize(2.0)
501 promptXYGraph.SetMarkerStyle(29)
502 promptZYGraph = ROOT.TGraph()
503 promptZYGraph.SetMarkerColor(4)
504 promptZYGraph.SetMarkerSize(2.0)
505 promptZYGraph.SetMarkerStyle(29)
506 bkgdXYGraph = ROOT.TGraph()
507 bkgdXYGraph.SetMarkerColor(2)
508 bkgdXYGraph.SetMarkerSize(2.0)
509 bkgdXYGraph.SetMarkerStyle(29)
510 bkgdZYGraph = ROOT.TGraph()
511 bkgdZYGraph.SetMarkerColor(2)
512 bkgdZYGraph.SetMarkerSize(2.0)
513 bkgdZYGraph.SetMarkerStyle(29)
514 promptZYSGraph = [0, 0, 0, 0, 0, 0, 0, 0]
515 bkgdZYSGraph = [0, 0, 0, 0, 0, 0, 0, 0]
516 for sector
in range(0, 8):
517 promptZYSGraph[sector] = ROOT.TGraph()
518 promptZYSGraph[sector].SetMarkerColor(4)
519 promptZYSGraph[sector].SetMarkerSize(2.0)
520 promptZYSGraph[sector].SetMarkerStyle(29)
521 bkgdZYSGraph[sector] = ROOT.TGraph()
522 bkgdZYSGraph[sector].SetMarkerColor(2)
523 bkgdZYSGraph[sector].SetMarkerSize(2.0)
524 bkgdZYSGraph[sector].SetMarkerStyle(29)
528 key = hit2d.getModuleID()
532 phiStripMin = hit2d.getPhiStripMin() - 1
533 phiStripMax = hit2d.getPhiStripMax() - 1
534 zStripMin = hit2d.getZStripMin() - 1
535 zStripMax = hit2d.getZStripMax() - 1
536 sectorFB = sector
if fb == 0
else sector + 8
538 rpcHitCount[sectorFB] += 1
542 n = rawklms[copper].GetDetectorNwords(0, finesse) >> 1
543 trigCtime = (rawklms[copper].GetTTCtime(0) & 0x07ffffff) << 3
550 for j
in range(0, n):
551 if layer != rawLayer[dc][j]:
553 if sector != rawSector[dc][j]:
555 if fb != rawFb[dc][j]:
557 strip = rawStrip[dc][j]
558 plane = rawPlane[dc][j]
560 if strip < zStripMin:
562 if strip > zStripMax:
564 ctZ = rawCtime[dc][j] << 3
567 if strip < phiStripMin:
569 if strip > phiStripMax:
571 ctPhi = rawCtime[dc][j] << 3
573 if (jZ >= 0)
and (jPhi >= 0):
575 if abs(ctZ - ctPhi) > 40:
577 ct = int((ctZ + ctPhi) * 0.5 - trigCtime - self.
ct0Scint[sectorFB]) & 0x3ff
578 if abs(ct - self.
ct0Cal) < ctDiffMax:
579 ctDiffMax = int(abs(ct - self.
ct0Cal))
584 tCal = ((int(hit2d.getTime()) - trigCtime) & 0x03ff) - self.
t0RPC[sectorFB] - 0.75 * jPhi - 0.75 * jZ
586 x = hit2d.getGlobalPositionX()
587 y = hit2d.getGlobalPositionY()
588 z = hit2d.getGlobalPositionZ()
594 if abs(tCal - self.
t0Cal2d) < 20:
598 promptXYGraph.SetPoint(jPrompt, x, y)
599 promptZYGraph.SetPoint(jPrompt, z, y)
600 nPoint = promptZYSGraph[sector].GetN()
601 promptZYSGraph[sector].SetPoint(nPoint, z, abs(x * self.
cosine[sector] + y * self.
sine[sector]))
604 bkgdXYGraph.SetPoint(jBkgd, x, y)
605 bkgdZYGraph.SetPoint(jBkgd, z, y)
606 nPoint = bkgdZYSGraph[sector].GetN()
607 bkgdZYSGraph[sector].SetPoint(nPoint, z, abs(x * self.
cosine[sector] + y * self.
sine[sector]))
609 hasEnoughRPCHits =
False
610 for count
in rpcHitCount:
612 hasEnoughRPCHits =
True
614 if hasEnoughRPCHits
and (len(muidhits) > self.
minMuidHits):
616 title =
'e{0:02d}r{1}: event {2}'.format(int(self.
exp), int(self.
run), event)
623 if extXYGraph.GetN() > 0:
625 if muidXYGraph.GetN() > 0:
626 muidXYGraph.Draw(
"P")
627 if bkgdXYGraph.GetN() > 0:
628 bkgdXYGraph.Draw(
"P")
629 if promptXYGraph.GetN() > 0:
630 promptXYGraph.Draw(
"P")
635 if extZYGraph.GetN() > 0:
637 if muidZYGraph.GetN() > 0:
638 muidZYGraph.Draw(
"P")
639 if bkgdZYGraph.GetN() > 0:
640 bkgdZYGraph.Draw(
"P")
641 if promptZYGraph.GetN() > 0:
642 promptZYGraph.Draw(
"P")
645 for sector
in range(0, 8):
646 if nMuids[sector] > 0:
647 title =
'e{0:02d}r{1}: event {2} sector {3}'.format(int(self.
exp), int(self.
run), event, sector)
648 self.
hist_XYS[sector].SetTitle(title)
653 if extXYGraph.GetN() > 0:
655 if muidXYGraph.GetN() > 0:
656 muidXYGraph.Draw(
"P")
657 if bkgdXYGraph.GetN() > 0:
658 bkgdXYGraph.Draw(
"P")
659 if promptXYGraph.GetN() > 0:
660 promptXYGraph.Draw(
"P")
664 self.
hist_ZYS.SetBins(10, z0 - 150.0, z0 + 150.0, 10, 125.0, 425.0)
670 if extZYSGraph[sector].GetN() > 0:
671 extZYSGraph[sector].Draw(
"P")
672 if muidZYSGraph[sector].GetN() > 0:
673 muidZYSGraph[sector].Draw(
"P")
674 if bkgdZYSGraph[sector].GetN() > 0:
675 bkgdZYSGraph[sector].Draw(
"P")
676 if promptZYSGraph[sector].GetN() > 0:
677 promptZYSGraph[sector].Draw(
"P")
678 self.
lastTitle =
"Title:E{0} sector {1}".format(event, sector)