FairShip
Loading...
Searching...
No Matches
eventDisplay.DrawTracks Class Reference
Inheritance diagram for eventDisplay.DrawTracks:
[legend]
Collaboration diagram for eventDisplay.DrawTracks:
[legend]

Public Member Functions

None InitTask (self)
None FinishEvent (self)
None ExecuteTask (self, str option="")
None DrawParticle (self, n)
None DrawMCTrack (self, int n)
None DrawMCTracks (self, str option="")
None DrawFittedTracks (self, str option="")

Public Attributes

 comp = ROOT.TEveCompound("Tracks")
dict trackColors
float z_end = 500.0
int z_start = T1Lid.GetTranslation()[2]
int z_mag = magNode.GetMatrix().GetTranslation()[2]
int niter = 100
tuple dz = (self.z_end - self.z_start) / float(self.niter)
 parallelToZ = ROOT.TVector3(0.0, 0.0, 1.0)
 evscene = sc.FindChild("Event scene")
int Targetz = targetNode.GetMatrix().GetTranslation()[2]

Detailed Description

Definition at line 289 of file eventDisplay.py.

Member Function Documentation

◆ DrawFittedTracks()

None eventDisplay.DrawTracks.DrawFittedTracks ( self,
str option = "" )

Definition at line 507 of file eventDisplay.py.

507 def DrawFittedTracks(self, option: str = "") -> None:
508 n, ntot = -1, 0
509 for fT in sTree.FitTracks:
510 n += 1
511 fst = fT.getFitStatus()
512 if not fst.isFitConverged():
513 continue
514 if fst.getNdf() < 20:
515 continue
516 DTrack = ROOT.TEveLine()
517 DTrack.SetPickable(ROOT.kTRUE)
518 DTrack.SetTitle(fT.__repr__())
519 fstate = fT.getFittedState(0)
520 fPos = fstate.getPos()
521 fMom = fstate.getMom()
522 pos = fPos
523 mom = fMom
524 pid = fstate.getPDG()
525 zs = self.z_start
526 for i in range(self.niter):
527 rc, newpos, _newmom = TrackExtrapolateTool.extrapolateToPlane(fT, zs)
528 if rc:
529 DTrack.SetNextPoint(newpos.X(), newpos.Y(), newpos.Z())
530 else:
531 print("error with extrapolation: z=", zs)
532 # use linear extrapolation
533 px, py, pz = mom.X(), mom.Y(), mom.Z()
534 lam = (zs - pos.Z()) / pz
535 DTrack.SetNextPoint(pos.X() + lam * px, pos.Y() + lam * py, zs)
536 zs += self.dz
537 DTrack.SetName("FitTrack_" + str(n))
538 c = ROOT.kWhite
539 if abs(pid) in self.trackColors:
540 c = self.trackColors[abs(pid)]
541 DTrack.SetMainColor(c)
542 DTrack.SetLineWidth(3)
543 self.comp.AddElement(DTrack)
544 ntot += 1
545 print("draw ", ntot, " fitted tracks")
546 n = -1
547 for aP in sTree.Particles:
548 n += 1
549 # check fitted tracks
550 tracksOK = True
551 if aP.GetMother(1) == 99: # DOCA is set
552 if aP.T() > 3 * u.cm:
553 continue
554 for k in range(aP.GetNDaughters()):
555 if k > 1:
556 break # we don't have more than 2tracks/vertex yet, no idea why ROOT sometimes comes up with 4!
557 fT = sTree.FitTracks[aP.GetDaughter(k)]
558 fst = fT.getFitStatus()
559 if not fst.isFitConverged():
560 tracksOK = False
561 if fst.getNdf() < 20:
562 tracksOK = False
563 if not tracksOK:
564 continue
565 DTrack = ROOT.TEveLine()
566 DTrack.SetPickable(ROOT.kTRUE)
567 DTrack.SetMainColor(ROOT.kCyan)
568 DTrack.SetLineWidth(4)
569 DTrack.SetName("Particle_" + str(n))
570 DTrack.SetTitle(aP.__repr__())
571 DTrack.SetNextPoint(aP.Vx(), aP.Vy(), aP.Vz())
572 lam = (self.Targetz - aP.Vz()) / aP.Pz()
573 DTrack.SetNextPoint(aP.Vx() + lam * aP.Px(), aP.Vy() + lam * aP.Py(), self.Targetz)
574 self.comp.AddElement(DTrack)
575
576
577#
tuple[bool, Any, Any] extrapolateToPlane(fT, z)

◆ DrawMCTrack()

None eventDisplay.DrawTracks.DrawMCTrack ( self,
int n )

Definition at line 371 of file eventDisplay.py.

371 def DrawMCTrack(self, n: int) -> None:
372 self.comp.OpenCompound()
373 fT = sTree.MCTrack[n]
374 DTrack = ROOT.TEveLine()
375 DTrack.SetPickable(ROOT.kTRUE)
376 DTrack.SetTitle(fT.__repr__())
377 p = pdg.GetParticle(fT.GetPdgCode())
378 if p:
379 pName = p.GetName()
380 else:
381 pName = str(fT.GetPdgCode())
382 DTrack.SetName("MCTrck_" + str(n) + "_" + pName)
383 fPos = ROOT.TVector3()
384 fMom = ROOT.TVector3()
385 fT.GetStartVertex(fPos)
386 fT.GetMomentum(fMom)
387 # check for end vertex
388 evVx = False
389 for da in sTree.MCTrack:
390 if da.GetMotherId() == n:
391 evVx = True
392 break
393 DTrack.SetNextPoint(fPos.X(), fPos.Y(), fPos.Z())
394 if evVx and abs(da.GetStartZ() - fPos.Z()) > 1 * u.cm:
395 DTrack.SetNextPoint(da.GetStartX(), da.GetStartY(), da.GetStartZ())
396 else:
397 zEx = 10 * u.m
398 if evVx:
399 zEx = -10 * u.m
400 lam = (zEx + fPos.Z()) / fMom.Z()
401 DTrack.SetNextPoint(fPos.X() + lam * fMom.X(), fPos.Y() + lam * fMom.Y(), zEx + fPos.Z())
402 c = ROOT.kYellow
403 DTrack.SetMainColor(c)
404 DTrack.SetLineWidth(3)
405 self.comp.AddElement(DTrack)
406 self.comp.CloseCompound()
407 gEve.ElementChanged(self.evscene, True, True)
408

◆ DrawMCTracks()

None eventDisplay.DrawTracks.DrawMCTracks ( self,
str option = "" )

Definition at line 409 of file eventDisplay.py.

409 def DrawMCTracks(self, option: str = "") -> None:
410 n = -1
411 ntot = 0
412 fPos = ROOT.TVector3()
413 fMom = ROOT.TVector3()
414 # Map trackID -> hits once per event, preserving branch and in-branch
415 # order (the hitlist building below relies on it).
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 # look for HNL
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 # end vertex of HNL
447 if found:
448 da.GetStartVertex(fPos)
449 hitlist[fPos.Z()] = [fPos.X(), fPos.Y()]
450 # collect the hits belonging to this MC track (per-event map above)
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 # must be old data, don't expect hit at 0,0,0
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 # still would like to draw track stub
470 # check for end vertex
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 # sort in z
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

◆ DrawParticle()

None eventDisplay.DrawTracks.DrawParticle ( self,
n )

Definition at line 357 of file eventDisplay.py.

357 def DrawParticle(self, n) -> None:
358 self.comp.OpenCompound()
359 DTrack = ROOT.TEveLine()
360 DTrack.SetPickable(ROOT.kTRUE)
361 DTrack.SetMainColor(ROOT.kCyan)
362 DTrack.SetLineWidth(4)
363 aP = sTree.Particles[n]
364 DTrack.SetTitle(aP.__repr__())
365 DTrack.SetName("Prtcle_" + str(n))
366 DTrack.SetNextPoint(aP.Vx(), aP.Vy(), aP.Vz())
367 lam = (self.Targetz - aP.Vz()) / aP.Pz()
368 DTrack.SetNextPoint(aP.Vx() + lam * aP.Px(), aP.Vy() + lam * aP.Py(), self.Targetz)
369 self.comp.AddElement(DTrack)
370

◆ ExecuteTask()

None eventDisplay.DrawTracks.ExecuteTask ( self,
str option = "" )

Definition at line 344 of file eventDisplay.py.

344 def ExecuteTask(self, option: str = "") -> None:
345 self.comp.DestroyElements()
346 self.comp.OpenCompound()
347 if (sTree.FindBranch("FitTracks") or sTree.FindBranch("FitTracks_PR")) and len(sTree.FitTracks) > 0:
348 self.DrawFittedTracks()
349 if not sTree.FindBranch("GeoTracks") and len(sTree.MCTrack) > 0 and globals()["withMCTracks"]:
350 if top.GetNode("Tunnel_1"):
351 DrawSimpleMCTracks() # for sndlhc, until more details are simulated
352 else:
353 self.DrawMCTracks()
354 self.comp.CloseCompound()
355 gEve.ElementChanged(self.evscene, True, True)
356

◆ FinishEvent()

None eventDisplay.DrawTracks.FinishEvent ( self)

Definition at line 341 of file eventDisplay.py.

341 def FinishEvent(self) -> None:
342 pass
343

◆ InitTask()

None eventDisplay.DrawTracks.InitTask ( self)

Definition at line 292 of file eventDisplay.py.

292 def InitTask(self) -> None:
293 # prepare container for fitted tracks
294 self.comp = ROOT.TEveCompound("Tracks")
295 gEve.AddElement(self.comp)
296 self.trackColors = {
297 13: ROOT.kGreen,
298 211: ROOT.kRed,
299 11: ROOT.kOrange,
300 321: ROOT.kMagenta,
301 }
302 dv = top.GetNode("DecayVolume_1")
303 self.z_end = 500.0
304 if dv:
305 ns = dv.GetNodes()
306 try:
307 T1Lid = ns.FindObject("T1Lid_1").GetMatrix()
308 self.z_start = T1Lid.GetTranslation()[2]
309 except AttributeError:
310 self.z_start = 0
311 else:
312 self.z_start = 0
313 muonDet = top.GetNode("MuonDetector_1")
314 if muonDet:
315 self.z_end = muonDet.GetMatrix().GetTranslation()[2] + muonDet.GetVolume().GetShape().GetDZ()
316 elif hasattr(ShipGeo, "CaloScoringPlane"):
317 self.z_end = ShipGeo["CaloScoringPlane"].z
318 elif top.GetNode("VMuonBox_1"):
319 xx = top.GetNode("VMuonBox_1")
320 self.z_end = xx.GetMatrix().GetTranslation()[2] + xx.GetVolume().GetShape().GetDZ()
321 magNode = top.GetNode("MCoil_1")
322 if magNode:
323 self.z_mag = magNode.GetMatrix().GetTranslation()[2]
324 elif hasattr(ShipGeo, "Bfield"):
325 self.z_mag = ShipGeo["Bfield"].z
326 else:
327 self.z_mag = 0
328 self.niter = 100
329 self.dz = (self.z_end - self.z_start) / float(self.niter)
330 self.parallelToZ = ROOT.TVector3(0.0, 0.0, 1.0)
331 sc = gEve.GetScenes()
332 self.evscene = sc.FindChild("Event scene")
333 targetNode = top.GetNode("TargetArea_1")
334 if targetNode:
335 self.Targetz = targetNode.GetMatrix().GetTranslation()[2]
336 elif hasattr(ShipGeo, "target"):
337 self.Targetz = ShipGeo["target"].z0
338 else:
339 self.Targetz = 0
340

Member Data Documentation

◆ comp

eventDisplay.DrawTracks.comp = ROOT.TEveCompound("Tracks")

Definition at line 294 of file eventDisplay.py.

◆ dz

tuple eventDisplay.DrawTracks.dz = (self.z_end - self.z_start) / float(self.niter)

Definition at line 329 of file eventDisplay.py.

◆ evscene

eventDisplay.DrawTracks.evscene = sc.FindChild("Event scene")

Definition at line 332 of file eventDisplay.py.

◆ niter

eventDisplay.DrawTracks.niter = 100

Definition at line 328 of file eventDisplay.py.

◆ parallelToZ

eventDisplay.DrawTracks.parallelToZ = ROOT.TVector3(0.0, 0.0, 1.0)

Definition at line 330 of file eventDisplay.py.

◆ Targetz

eventDisplay.DrawTracks.Targetz = targetNode.GetMatrix().GetTranslation()[2]

Definition at line 335 of file eventDisplay.py.

◆ trackColors

dict eventDisplay.DrawTracks.trackColors
Initial value:
= {
13: ROOT.kGreen,
211: ROOT.kRed,
11: ROOT.kOrange,
321: ROOT.kMagenta,
}

Definition at line 296 of file eventDisplay.py.

◆ z_end

float eventDisplay.DrawTracks.z_end = 500.0

Definition at line 303 of file eventDisplay.py.

◆ z_mag

int eventDisplay.DrawTracks.z_mag = magNode.GetMatrix().GetTranslation()[2]

Definition at line 323 of file eventDisplay.py.

◆ z_start

int eventDisplay.DrawTracks.z_start = T1Lid.GetTranslation()[2]

Definition at line 308 of file eventDisplay.py.


The documentation for this class was generated from the following file: