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

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
 
 trackColors
 
 z_end
 
 z_start
 
 z_mag
 
 niter
 
 dz
 
 parallelToZ
 
 evscene
 
 Targetz
 

Detailed Description

Definition at line 274 of file eventDisplay.py.

Member Function Documentation

◆ DrawFittedTracks()

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

Definition at line 485 of file eventDisplay.py.

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

◆ DrawMCTrack()

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

Definition at line 356 of file eventDisplay.py.

356 def DrawMCTrack(self, n: int) -> None:
357 self.comp.OpenCompound()
358 fT = sTree.MCTrack[n]
359 DTrack = ROOT.TEveLine()
360 DTrack.SetPickable(ROOT.kTRUE)
361 DTrack.SetTitle(fT.__repr__())
362 p = pdg.GetParticle(fT.GetPdgCode())
363 if p:
364 pName = p.GetName()
365 else:
366 pName = str(fT.GetPdgCode())
367 DTrack.SetName("MCTrck_" + str(n) + "_" + pName)
368 fPos = ROOT.TVector3()
369 fMom = ROOT.TVector3()
370 fT.GetStartVertex(fPos)
371 fT.GetMomentum(fMom)
372 # check for end vertex
373 evVx = False
374 for da in sTree.MCTrack:
375 if da.GetMotherId() == n:
376 evVx = True
377 break
378 DTrack.SetNextPoint(fPos.X(), fPos.Y(), fPos.Z())
379 if evVx and abs(da.GetStartZ() - fPos.Z()) > 1 * u.cm:
380 DTrack.SetNextPoint(da.GetStartX(), da.GetStartY(), da.GetStartZ())
381 else:
382 zEx = 10 * u.m
383 if evVx:
384 zEx = -10 * u.m
385 lam = (zEx + fPos.Z()) / fMom.Z()
386 DTrack.SetNextPoint(fPos.X() + lam * fMom.X(), fPos.Y() + lam * fMom.Y(), zEx + fPos.Z())
387 c = ROOT.kYellow
388 DTrack.SetMainColor(c)
389 DTrack.SetLineWidth(3)
390 self.comp.AddElement(DTrack)
391 self.comp.CloseCompound()
392 gEve.ElementChanged(self.evscene, True, True)
393

◆ DrawMCTracks()

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

Definition at line 394 of file eventDisplay.py.

394 def DrawMCTracks(self, option: str = "") -> None:
395 n = -1
396 ntot = 0
397 fPos = ROOT.TVector3()
398 fMom = ROOT.TVector3()
399 for fT in sTree.MCTrack:
400 n += 1
401 DTrack = ROOT.TEveLine()
402 DTrack.SetPickable(ROOT.kTRUE)
403 DTrack.SetTitle(fT.__repr__())
404 fT.GetStartVertex(fPos)
405 hitlist = {}
406 hitlist[fPos.Z()] = [fPos.X(), fPos.Y()]
407 # look for HNL
408 if abs(fT.GetPdgCode()) == options.HiddenParticleID:
409 for da in sTree.MCTrack:
410 if da.GetMotherId() == n:
411 break
412 # end vertex of HNL
413 da.GetStartVertex(fPos)
414 hitlist[fPos.Z()] = [fPos.X(), fPos.Y()]
415 # loop over all sensitive volumes to find hits
416 for P in [
417 "vetoPoint",
418 "strawtubesPoint",
419 "ShipRpcPoint",
420 "TargetPoint",
421 "MTCDetPoint",
422 "SiliconTargetPoint",
423 "TimeDetPoint",
424 ]:
425 if not sTree.GetBranch(P):
426 continue
427 c = eval("sTree." + P)
428 for p in c:
429 if p.GetTrackID() == n:
430 if hasattr(p, "LastPoint"):
431 lp = p.LastPoint()
432 if lp.x() == lp.y() and lp.x() == lp.z() and lp.x() == 0:
433 # must be old data, don't expect hit at 0,0,0
434 hitlist[p.GetZ()] = [p.GetX(), p.GetY()]
435 else:
436 hitlist[lp.z()] = [lp.x(), lp.y()]
437 hitlist[2.0 * p.GetZ() - lp.z()] = [
438 2.0 * p.GetX() - lp.x(),
439 2.0 * p.GetY() - lp.y(),
440 ]
441 else:
442 hitlist[p.GetZ()] = [p.GetX(), p.GetY()]
443 if len(hitlist) == 1:
444 if fT.GetMotherId() < 0:
445 continue
446 if abs(sTree.MCTrack[fT.GetMotherId()].GetPdgCode()) == options.HiddenParticleID:
447 # still would like to draw track stub
448 # check for end vertex
449 evVx = False
450 for da in sTree.MCTrack:
451 if da.GetMotherId() == n:
452 evVx = True
453 break
454 if evVx:
455 hitlist[da.GetStartZ()] = [da.GetStartX(), da.GetStartY()]
456 else:
457 zEx = 10 * u.m
458 fT.GetMomentum(fMom)
459 lam = (zEx + fPos.Z()) / fMom.Z()
460 hitlist[zEx + fPos.Z()] = [
461 fPos.X() + lam * fMom.X(),
462 fPos.Y() + lam * fMom.Y(),
463 ]
464 # sort in z
465 lz = list(hitlist.keys())
466 if len(lz) > 1:
467 lz.sort()
468 for z in lz:
469 DTrack.SetNextPoint(hitlist[z][0], hitlist[z][1], z)
470 p = pdg.GetParticle(fT.GetPdgCode())
471 if p:
472 pName = p.GetName()
473 else:
474 pName = str(fT.GetPdgCode())
475 DTrack.SetName("MCTrack_" + str(n) + "_" + pName)
476 c = ROOT.kYellow
477 if abs(fT.GetPdgCode()) == options.HiddenParticleID:
478 c = ROOT.kMagenta
479 DTrack.SetMainColor(c)
480 DTrack.SetLineWidth(3)
481 self.comp.AddElement(DTrack)
482 ntot += 1
483 print("draw ", ntot, " MC tracks")
484

◆ DrawParticle()

None eventDisplay.DrawTracks.DrawParticle (   self,
  n 
)

Definition at line 342 of file eventDisplay.py.

342 def DrawParticle(self, n) -> None:
343 self.comp.OpenCompound()
344 DTrack = ROOT.TEveLine()
345 DTrack.SetPickable(ROOT.kTRUE)
346 DTrack.SetMainColor(ROOT.kCyan)
347 DTrack.SetLineWidth(4)
348 aP = sTree.Particles[n]
349 DTrack.SetTitle(aP.__repr__())
350 DTrack.SetName("Prtcle_" + str(n))
351 DTrack.SetNextPoint(aP.Vx(), aP.Vy(), aP.Vz())
352 lam = (self.Targetz - aP.Vz()) / aP.Pz()
353 DTrack.SetNextPoint(aP.Vx() + lam * aP.Px(), aP.Vy() + lam * aP.Py(), self.Targetz)
354 self.comp.AddElement(DTrack)
355

◆ ExecuteTask()

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

Definition at line 329 of file eventDisplay.py.

329 def ExecuteTask(self, option: str = "") -> None:
330 self.comp.DestroyElements()
331 self.comp.OpenCompound()
332 if (sTree.FindBranch("FitTracks") or sTree.FindBranch("FitTracks_PR")) and len(sTree.FitTracks) > 0:
333 self.DrawFittedTracks()
334 if not sTree.FindBranch("GeoTracks") and len(sTree.MCTrack) > 0 and globals()["withMCTracks"]:
335 if top.GetNode("Tunnel_1"):
336 DrawSimpleMCTracks() # for sndlhc, until more details are simulated
337 else:
338 self.DrawMCTracks()
339 self.comp.CloseCompound()
340 gEve.ElementChanged(self.evscene, True, True)
341

◆ FinishEvent()

None eventDisplay.DrawTracks.FinishEvent (   self)

Definition at line 326 of file eventDisplay.py.

326 def FinishEvent(self) -> None:
327 pass
328

◆ InitTask()

None eventDisplay.DrawTracks.InitTask (   self)

Definition at line 277 of file eventDisplay.py.

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

Member Data Documentation

◆ comp

eventDisplay.DrawTracks.comp

Definition at line 279 of file eventDisplay.py.

◆ dz

eventDisplay.DrawTracks.dz

Definition at line 314 of file eventDisplay.py.

◆ evscene

eventDisplay.DrawTracks.evscene

Definition at line 317 of file eventDisplay.py.

◆ niter

eventDisplay.DrawTracks.niter

Definition at line 313 of file eventDisplay.py.

◆ parallelToZ

eventDisplay.DrawTracks.parallelToZ

Definition at line 315 of file eventDisplay.py.

◆ Targetz

eventDisplay.DrawTracks.Targetz

Definition at line 320 of file eventDisplay.py.

◆ trackColors

eventDisplay.DrawTracks.trackColors

Definition at line 281 of file eventDisplay.py.

◆ z_end

eventDisplay.DrawTracks.z_end

Definition at line 288 of file eventDisplay.py.

◆ z_mag

eventDisplay.DrawTracks.z_mag

Definition at line 308 of file eventDisplay.py.

◆ z_start

eventDisplay.DrawTracks.z_start

Definition at line 293 of file eventDisplay.py.


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