20 from ROOT
import Belle2
30 """Draw BKLM event displays from BKLMHit2ds, ExtHits, and MuidHits."""
47 BKLM_MAXSTRIP_BIT = 15
49 BKLM_STRIP_MASK = 0x3f
51 BKLM_PLANE_MASK = (1 << BKLM_PLANE_BIT)
53 BKLM_LAYER_MASK = (15 << BKLM_LAYER_BIT)
55 BKLM_SECTOR_MASK = (7 << BKLM_SECTOR_BIT)
57 BKLM_SECTION_MASK = (1 << BKLM_SECTION_BIT)
59 BKLM_MAXSTRIP_MASK = (63 << BKLM_MAXSTRIP_BIT)
61 BKLM_MODULEID_MASK = (BKLM_SECTION_MASK | BKLM_SECTOR_MASK | BKLM_LAYER_MASK)
63 def __init__(self, exp, run, eventPdfName, maxDisplays, minRPCHits, minMuidHits):
67 exp (str): formatted experiment number
68 run (str): formatter run number
69 eventPdfName (str): path name of the output event-display PDF file
70 maxDisplays (int): max # of events displays to write
71 minRPCHits (int): min # of RPC BKLMHit2ds in any sector for event display
72 minMuidHits (int): min # of MuidHits in the event for event display
95 """Handle job initialization: fill the mapping database, create histograms, open the event-display file"""
97 expRun =
'e{0:02d}r{1}: '.format(int(self.
expexp), int(self.
runrun))
111 self.
cosinecosine = [0, 0, 0, 0, 0, 0, 0, 0]
113 self.
sinesine = [0, 0, 0, 0, 0, 0, 0, 0]
114 for sector
in range(0, 8):
115 phi = math.pi * sector / 4
116 self.
cosinecosine[sector] = math.cos(phi)
117 self.
sinesine[sector] = math.sin(phi)
119 self.
hist_XYhist_XY = ROOT.TH2F(
'XY',
' ;x;y', 10, -345.0, 345.0, 10, -345.0, 345.0)
120 self.
hist_XYhist_XY.SetStats(
False)
122 self.
hist_ZYhist_ZY = ROOT.TH2F(
'ZY',
' ;z;y', 10, -345.0, 345.0, 10, -345.0, 345.0)
123 self.
hist_ZYhist_ZY.SetStats(
False)
132 self.
hist_XYShist_XYS[0] = ROOT.TH2F(
'XYS0',
' ;x;y', 10, +u3, +u4, 10, -u5, +u5)
133 self.
hist_XYShist_XYS[0].SetStats(
False)
134 self.
hist_XYShist_XYS[1] = ROOT.TH2F(
'XYS1',
' ;x;y', 10, +u1, +u2, 10, +u1, +u2)
135 self.
hist_XYShist_XYS[1].SetStats(
False)
136 self.
hist_XYShist_XYS[2] = ROOT.TH2F(
'XYS2',
' ;x;y', 10, -u5, +u5, 10, +u3, +u4)
137 self.
hist_XYShist_XYS[2].SetStats(
False)
138 self.
hist_XYShist_XYS[3] = ROOT.TH2F(
'XYS3',
' ;x;y', 10, -u2, -u1, 10, +u1, +u2)
139 self.
hist_XYShist_XYS[3].SetStats(
False)
140 self.
hist_XYShist_XYS[4] = ROOT.TH2F(
'XYS4',
' ;x;y', 10, -u4, -u3, 10, -u5, +u5)
141 self.
hist_XYShist_XYS[4].SetStats(
False)
142 self.
hist_XYShist_XYS[5] = ROOT.TH2F(
'XYS5',
' ;x;y', 10, -u2, -u1, 10, -u2, -u1)
143 self.
hist_XYShist_XYS[5].SetStats(
False)
144 self.
hist_XYShist_XYS[6] = ROOT.TH2F(
'XYS6',
' ;x;y', 10, -u5, +u5, 10, -u4, -u3)
145 self.
hist_XYShist_XYS[6].SetStats(
False)
146 self.
hist_XYShist_XYS[7] = ROOT.TH2F(
'XYS7',
' ;x;y', 10, +u1, +u2, 10, -u2, -u1)
147 self.
hist_XYShist_XYS[7].SetStats(
False)
149 self.
hist_ZYShist_ZYS = ROOT.TH2F(
'ZYS',
' ;z;y', 10, -150.0, 150.0, 10, 125.0, 425.0)
150 self.
hist_ZYShist_ZYS.SetStats(
False)
151 ROOT.gStyle.SetOptStat(10)
154 r0 = 201.9 + 0.5 * 4.4
156 tan0 = math.tan(math.pi / 8.0)
158 g.SetPoint(0, -200.0, 0.0)
159 g.SetPoint(1, +200.0, 0.0)
163 self.
bklmXYbklmXY.append(g)
165 g.SetPoint(0, 0.0, -200.0)
166 g.SetPoint(1, 0.0, +200.0)
170 self.
bklmXYbklmXY.append(g)
172 g.SetPoint(0, -5.0, 0.0)
173 g.SetPoint(1, +5.0, 0.0)
174 g.SetPoint(2, 0.0, 0.0)
175 g.SetPoint(3, 0.0, +5.0)
176 g.SetPoint(4, 0.0, -5.0)
179 self.
bklmXYbklmXY.append(g)
180 for layer
in range(0, 15):
184 g.SetPoint(0, +r, -x)
185 g.SetPoint(1, +r, +x)
186 g.SetPoint(2, +x, +r)
187 g.SetPoint(3, -x, +r)
188 g.SetPoint(4, -r, +x)
189 g.SetPoint(5, -r, -x)
190 g.SetPoint(6, -x, -r)
191 g.SetPoint(7, +x, -r)
192 g.SetPoint(8, +r, -x)
200 self.
bklmXYbklmXY.append(g)
208 g.SetPoint(0, -zL + z0 - 140.0, 0.0)
209 g.SetPoint(1, +zL + z0 + 70.0, 0.0)
213 self.
bklmZYbklmZY.append(g)
215 g.SetPoint(0, 0.0, -315.0)
216 g.SetPoint(1, 0.0, +340.0)
220 self.
bklmZYbklmZY.append(g)
222 g.SetPoint(0, -5.0, 0.0)
223 g.SetPoint(1, +5.0, 0.0)
224 g.SetPoint(2, 0.0, 0.0)
225 g.SetPoint(3, 0.0, +5.0)
226 g.SetPoint(4, 0.0, -5.0)
229 self.
bklmZYbklmZY.append(g)
231 g.SetPoint(0, -zL + z0, +x0)
232 g.SetPoint(1, -zL + z0, +r0)
236 self.
bklmZYbklmZY.append(g)
238 g.SetPoint(0, -zL + z0, -x0)
239 g.SetPoint(1, -zL + z0, -r0)
243 self.
bklmZYbklmZY.append(g)
245 g.SetPoint(0, +zL + z0, +x0)
246 g.SetPoint(1, +zL + z0, +r0)
250 self.
bklmZYbklmZY.append(g)
252 g.SetPoint(0, +zL + z0, -x0)
253 g.SetPoint(1, +zL + z0, -r0)
257 self.
bklmZYbklmZY.append(g)
259 g.SetPoint(0, -zL + z0, r0)
260 g.SetPoint(1, +zL + z0, r0)
261 g.SetPoint(2, +zL + z0, rF)
262 g.SetPoint(3, -zL + z0, rF)
263 g.SetPoint(4, -zL + z0, r0)
266 self.
bklmZYbklmZY.append(g)
268 g.SetPoint(0, -zL + z0, -r0)
269 g.SetPoint(1, +zL + z0, -r0)
270 g.SetPoint(2, +zL + z0, -rF)
271 g.SetPoint(3, -zL + z0, -rF)
272 g.SetPoint(4, -zL + z0, -r0)
275 self.
bklmZYbklmZY.append(g)
277 g.SetPoint(0, -zL + z0, -x0)
278 g.SetPoint(1, +zL + z0, -x0)
279 g.SetPoint(2, +zL + z0, +x0)
280 g.SetPoint(3, -zL + z0, +x0)
281 g.SetPoint(4, -zL + z0, -x0)
284 self.
bklmZYbklmZY.append(g)
287 for layer
in range(0, 15):
292 g.SetPoint(0, -zL + z0, r)
293 g.SetPoint(1, +zL + z0, r)
300 self.
sectorFBToDCsectorFBToDC = [11, 15, 2, 6, 10, 14, 3, 7, 9, 13, 0, 4, 8, 12, 1, 5]
302 self.
dcToSectorFBdcToSectorFB = [10, 14, 2, 6, 11, 15, 3, 7, 12, 8, 4, 0, 13, 9, 5, 1]
312 self.
t0RPCt0RPC = [8, -14, -6, -14, -2, 10, 9, 13, 0, -10, -14, -20, 2, 6, 14, 11]
314 self.
ct0Scintct0Scint = [-1, -33, -46, -33, -2, 32, 51, 32, 0, -32, -45, -33, -4, 34, 45, 27]
317 """Handle job termination: close event-display file"""
319 pdfNameLast =
'{0}]'.format(self.
eventPdfNameeventPdfName)
324 """Handle begin of run: print diagnostic message"""
326 print(
'beginRun', EventMetaData.getRun())
329 """Handle end of run: print diagnostic message"""
331 print(
'endRun', EventMetaData.getRun())
334 """Process one event: (optionally) draw event display"""
343 event = EventMetaData.getEvent()
349 rawFb = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
350 rawSector = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
351 rawLayer = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
352 rawPlane = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
353 rawStrip = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
354 rawCtime = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
356 for copper
in range(0, len(rawklms)):
357 rawklm = rawklms[copper]
358 nodeID = rawklm.GetNodeID(0) - self.
BKLM_IDBKLM_ID
361 if (nodeID < 0)
or (nodeID > 4):
363 for finesse
in range(0, 4):
364 dc = (finesse << 2) + copper
365 n = rawklm.GetDetectorNwords(0, finesse)
366 bufSlot = rawklm.GetDetectorBuffer(0, finesse)
369 for j
in range(0, n):
370 word0 = bufSlot[j * 2]
371 word1 = bufSlot[j * 2 + 1]
372 ctime = word0 & 0xffff
373 channel = (word0 >> 16) & 0x7f
374 axis = (word0 >> 23) & 0x01
375 lane = (word0 >> 24) & 0x1f
376 flag = (word0 >> 30) & 0x03
382 electId = (channel << 12) | (axis << 11) | (lane << 6) | (finesse << 4) | nodeID
391 rawSector[dc].append(sector)
392 rawLayer[dc].append(layer)
393 rawPlane[dc].append(plane)
394 rawStrip[dc].append(strip)
395 rawCtime[dc].append(ctime)
399 tCal2d.append(hit2d.getTime())
412 for exthit
in exthits:
414 extPosition = exthit.getPosition()
421 if (dx * dx + dy * dy + dz * dz > 36)
and (sumn > 0):
422 eposition = [sumx / sumn, sumy / sumn, sumz / sumn, sold]
423 epositions.append(eposition)
439 eposition = [sumx / sumn, sumy / sumn, sumz / sumn, sold]
440 epositions.append(eposition)
441 extXYGraph = ROOT.TGraph()
442 extXYGraph.SetMarkerColor(30)
443 extXYGraph.SetMarkerSize(2.25)
444 extXYGraph.SetMarkerStyle(21)
445 extZYGraph = ROOT.TGraph()
446 extZYGraph.SetMarkerColor(30)
447 extZYGraph.SetMarkerSize(2.25)
448 extZYGraph.SetMarkerStyle(21)
449 extZYSGraph = [0, 0, 0, 0, 0, 0, 0, 0]
450 for sector
in range(0, 8):
451 extZYSGraph[sector] = ROOT.TGraph()
452 extZYSGraph[sector].SetMarkerColor(30)
453 extZYSGraph[sector].SetMarkerSize(2.25)
454 extZYSGraph[sector].SetMarkerStyle(21)
456 for eposition
in epositions:
461 extXYGraph.SetPoint(j, x, y)
462 extZYGraph.SetPoint(j, z, y)
463 sector = int(eposition[3])
464 nPoint = extZYSGraph[sector].GetN()
465 extZYSGraph[sector].SetPoint(nPoint, z, abs(x * self.
cosinecosine[sector] + y * self.
sinesine[sector]))
469 zMuids = [0, 0, 0, 0, 0, 0, 0, 0]
470 nMuids = [0, 0, 0, 0, 0, 0, 0, 0]
471 muidXYGraph = ROOT.TGraph()
472 muidXYGraph.SetMarkerColor(5)
473 muidXYGraph.SetMarkerSize(2.0)
474 muidXYGraph.SetMarkerStyle(20)
475 muidZYGraph = ROOT.TGraph()
476 muidZYGraph.SetMarkerColor(5)
477 muidZYGraph.SetMarkerSize(2.0)
478 muidZYGraph.SetMarkerStyle(20)
479 muidZYSGraph = [0, 0, 0, 0, 0, 0, 0, 0]
480 for sector
in range(0, 8):
481 muidZYSGraph[sector] = ROOT.TGraph()
482 muidZYSGraph[sector].SetMarkerColor(5)
483 muidZYSGraph[sector].SetMarkerSize(2.0)
484 muidZYSGraph[sector].SetMarkerStyle(20)
486 for muidhit
in muidhits:
488 muidPosition = muidhit.getExtPosition()
492 muidXYGraph.SetPoint(j, x, y)
493 muidZYGraph.SetPoint(j, z, y)
494 sector = muidhit.getSector()
495 nPoint = muidZYSGraph[sector].GetN()
496 muidZYSGraph[sector].SetPoint(nPoint, z, abs(x * self.
cosinecosine[sector] + y * self.
sinesine[sector]))
497 if nMuids[sector] == 0:
503 rpcHitCount = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
504 promptXYGraph = ROOT.TGraph()
505 promptXYGraph.SetMarkerColor(4)
506 promptXYGraph.SetMarkerSize(2.0)
507 promptXYGraph.SetMarkerStyle(29)
508 promptZYGraph = ROOT.TGraph()
509 promptZYGraph.SetMarkerColor(4)
510 promptZYGraph.SetMarkerSize(2.0)
511 promptZYGraph.SetMarkerStyle(29)
512 bkgdXYGraph = ROOT.TGraph()
513 bkgdXYGraph.SetMarkerColor(2)
514 bkgdXYGraph.SetMarkerSize(2.0)
515 bkgdXYGraph.SetMarkerStyle(29)
516 bkgdZYGraph = ROOT.TGraph()
517 bkgdZYGraph.SetMarkerColor(2)
518 bkgdZYGraph.SetMarkerSize(2.0)
519 bkgdZYGraph.SetMarkerStyle(29)
520 promptZYSGraph = [0, 0, 0, 0, 0, 0, 0, 0]
521 bkgdZYSGraph = [0, 0, 0, 0, 0, 0, 0, 0]
522 for sector
in range(0, 8):
523 promptZYSGraph[sector] = ROOT.TGraph()
524 promptZYSGraph[sector].SetMarkerColor(4)
525 promptZYSGraph[sector].SetMarkerSize(2.0)
526 promptZYSGraph[sector].SetMarkerStyle(29)
527 bkgdZYSGraph[sector] = ROOT.TGraph()
528 bkgdZYSGraph[sector].SetMarkerColor(2)
529 bkgdZYSGraph[sector].SetMarkerSize(2.0)
530 bkgdZYSGraph[sector].SetMarkerStyle(29)
534 key = hit2d.getModuleID()
538 phiStripMin = hit2d.getPhiStripMin() - 1
539 phiStripMax = hit2d.getPhiStripMax() - 1
540 zStripMin = hit2d.getZStripMin() - 1
541 zStripMax = hit2d.getZStripMax() - 1
542 sectorFB = sector
if fb == 0
else sector + 8
544 rpcHitCount[sectorFB] += 1
548 n = rawklms[copper].GetDetectorNwords(0, finesse) >> 1
549 trigCtime = (rawklms[copper].GetTTCtime(0) & 0x07ffffff) << 3
556 for j
in range(0, n):
557 if layer != rawLayer[dc][j]:
559 if sector != rawSector[dc][j]:
561 if fb != rawFb[dc][j]:
563 strip = rawStrip[dc][j]
564 plane = rawPlane[dc][j]
566 if strip < zStripMin:
568 if strip > zStripMax:
570 ctZ = rawCtime[dc][j] << 3
573 if strip < phiStripMin:
575 if strip > phiStripMax:
577 ctPhi = rawCtime[dc][j] << 3
579 if (jZ >= 0)
and (jPhi >= 0):
581 if abs(ctZ - ctPhi) > 40:
583 ct = int((ctZ + ctPhi) * 0.5 - trigCtime - self.
ct0Scintct0Scint[sectorFB]) & 0x3ff
584 if abs(ct - self.
ct0Calct0Cal) < ctDiffMax:
585 ctDiffMax = int(abs(ct - self.
ct0Calct0Cal))
590 tCal = ((int(hit2d.getTime()) - trigCtime) & 0x03ff) - self.
t0RPCt0RPC[sectorFB] - 0.75 * jPhi - 0.75 * jZ
592 x = hit2d.getGlobalPositionX()
593 y = hit2d.getGlobalPositionY()
594 z = hit2d.getGlobalPositionZ()
597 if abs(tCal - self.
ct0Cal2dct0Cal2d) < 20:
600 if abs(tCal - self.
t0Cal2dt0Cal2d) < 20:
604 promptXYGraph.SetPoint(jPrompt, x, y)
605 promptZYGraph.SetPoint(jPrompt, z, y)
606 nPoint = promptZYSGraph[sector].GetN()
607 promptZYSGraph[sector].SetPoint(nPoint, z, abs(x * self.
cosinecosine[sector] + y * self.
sinesine[sector]))
610 bkgdXYGraph.SetPoint(jBkgd, x, y)
611 bkgdZYGraph.SetPoint(jBkgd, z, y)
612 nPoint = bkgdZYSGraph[sector].GetN()
613 bkgdZYSGraph[sector].SetPoint(nPoint, z, abs(x * self.
cosinecosine[sector] + y * self.
sinesine[sector]))
615 hasEnoughRPCHits =
False
616 for count
in rpcHitCount:
618 hasEnoughRPCHits =
True
620 if hasEnoughRPCHits
and (len(muidhits) > self.
minMuidHitsminMuidHits):
622 title =
'e{0:02d}r{1}: event {2}'.format(int(self.
expexp), int(self.
runrun), event)
623 self.
hist_XYhist_XY.SetTitle(title)
624 self.
hist_ZYhist_ZY.SetTitle(title)
627 for g
in self.
bklmXYbklmXY:
629 if extXYGraph.GetN() > 0:
631 if muidXYGraph.GetN() > 0:
632 muidXYGraph.Draw(
"P")
633 if bkgdXYGraph.GetN() > 0:
634 bkgdXYGraph.Draw(
"P")
635 if promptXYGraph.GetN() > 0:
636 promptXYGraph.Draw(
"P")
639 for g
in self.
bklmZYbklmZY:
641 if extZYGraph.GetN() > 0:
643 if muidZYGraph.GetN() > 0:
644 muidZYGraph.Draw(
"P")
645 if bkgdZYGraph.GetN() > 0:
646 bkgdZYGraph.Draw(
"P")
647 if promptZYGraph.GetN() > 0:
648 promptZYGraph.Draw(
"P")
651 for sector
in range(0, 8):
652 if nMuids[sector] > 0:
653 title =
'e{0:02d}r{1}: event {2} sector {3}'.format(int(self.
expexp), int(self.
runrun), event, sector)
654 self.
hist_XYShist_XYS[sector].SetTitle(title)
656 self.
hist_XYShist_XYS[sector].Draw()
657 for g
in self.
bklmXYbklmXY:
659 if extXYGraph.GetN() > 0:
661 if muidXYGraph.GetN() > 0:
662 muidXYGraph.Draw(
"P")
663 if bkgdXYGraph.GetN() > 0:
664 bkgdXYGraph.Draw(
"P")
665 if promptXYGraph.GetN() > 0:
666 promptXYGraph.Draw(
"P")
669 self.
hist_ZYShist_ZYS.SetTitle(title)
670 self.
hist_ZYShist_ZYS.SetBins(10, z0 - 150.0, z0 + 150.0, 10, 125.0, 425.0)
672 for g
in self.
bklmZYbklmZY:
676 if extZYSGraph[sector].GetN() > 0:
677 extZYSGraph[sector].Draw(
"P")
678 if muidZYSGraph[sector].GetN() > 0:
679 muidZYSGraph[sector].Draw(
"P")
680 if bkgdZYSGraph[sector].GetN() > 0:
681 bkgdZYSGraph[sector].Draw(
"P")
682 if promptZYSGraph[sector].GetN() > 0:
683 promptZYSGraph[sector].Draw(
"P")
684 self.
lastTitlelastTitle =
"Title:E{0} sector {1}".format(event, 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 BKLMHit2ds
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 BKLMHit2ds 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 BKLMHit2ds.
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