409 def DrawMCTracks(self, option: str = "") -> None:
410 n = -1
411 ntot = 0
412 fPos = ROOT.TVector3()
413 fMom = ROOT.TVector3()
414
415
416 hits_by_track: dict[int, list] = {}
417 for P in [
418 "vetoPoint",
419 "strawtubesPoint",
420 "ShipRpcPoint",
421 "TargetPoint",
422 "MTCDetPoint",
423 "SiliconTargetPoint",
424 "TimeDetPoint",
425 "CaloScoringPlanePoint",
426 ]:
427 if not sTree.GetBranch(P):
428 continue
429 for p in getattr(sTree, P):
430 hits_by_track.setdefault(p.GetTrackID(), []).append(p)
431 for fT in sTree.MCTrack:
432 n += 1
433 DTrack = ROOT.TEveLine()
434 DTrack.SetPickable(ROOT.kTRUE)
435 DTrack.SetTitle(fT.__repr__())
436 fT.GetStartVertex(fPos)
437 hitlist = {}
438 hitlist[fPos.Z()] = [fPos.X(), fPos.Y()]
439
440 if abs(fT.GetPdgCode()) == options.HiddenParticleID:
441 found = False
442 for da in sTree.MCTrack:
443 if da.GetMotherId() == n:
444 found = True
445 break
446
447 if found:
448 da.GetStartVertex(fPos)
449 hitlist[fPos.Z()] = [fPos.X(), fPos.Y()]
450
451 for p in hits_by_track.get(n, []):
452 if hasattr(p, "LastPoint"):
453 lp = p.LastPoint()
454 if lp.x() == lp.y() and lp.x() == lp.z() and lp.x() == 0:
455
456 hitlist[p.GetZ()] = [p.GetX(), p.GetY()]
457 else:
458 hitlist[lp.z()] = [lp.x(), lp.y()]
459 hitlist[2.0 * p.GetZ() - lp.z()] = [
460 2.0 * p.GetX() - lp.x(),
461 2.0 * p.GetY() - lp.y(),
462 ]
463 else:
464 hitlist[p.GetZ()] = [p.GetX(), p.GetY()]
465 if len(hitlist) == 1:
466 if fT.GetMotherId() < 0:
467 continue
468 if abs(sTree.MCTrack[fT.GetMotherId()].GetPdgCode()) == options.HiddenParticleID:
469
470
471 evVx = False
472 for da in sTree.MCTrack:
473 if da.GetMotherId() == n:
474 evVx = True
475 break
476 if evVx:
477 hitlist[da.GetStartZ()] = [da.GetStartX(), da.GetStartY()]
478 else:
479 zEx = 10 * u.m
480 fT.GetMomentum(fMom)
481 lam = (zEx + fPos.Z()) / fMom.Z()
482 hitlist[zEx + fPos.Z()] = [
483 fPos.X() + lam * fMom.X(),
484 fPos.Y() + lam * fMom.Y(),
485 ]
486
487 lz = list(hitlist.keys())
488 if len(lz) > 1:
489 lz.sort()
490 for z in lz:
491 DTrack.SetNextPoint(hitlist[z][0], hitlist[z][1], z)
492 p = pdg.GetParticle(fT.GetPdgCode())
493 if p:
494 pName = p.GetName()
495 else:
496 pName = str(fT.GetPdgCode())
497 DTrack.SetName("MCTrack_" + str(n) + "_" + pName)
498 c = ROOT.kYellow
499 if abs(fT.GetPdgCode()) == options.HiddenParticleID:
500 c = ROOT.kMagenta
501 DTrack.SetMainColor(c)
502 DTrack.SetLineWidth(3)
503 self.comp.AddElement(DTrack)
504 ntot += 1
505 print("draw ", ntot, " MC tracks")
506