10from rootUtils
import get_particle, is_known_particle
12ROOT.gROOT.ProcessLine(
'#include "FairEventHeader.h"')
15from argparse
import ArgumentParser
16from array
import array
21from ShipGeoConfig
import load_from_root_file
28 """Downstream reference for the rulers.
30 The scoring plane, or the former MuonStation3 position in geometry files
31 made before the SplitCal removal.
33 if hasattr(ShipGeo,
"CaloScoringPlane"):
34 return ShipGeo.CaloScoringPlane.z
35 return ShipGeo.MuonStation3.z
39 """Check whether a file exists (local or remote via XRootD)."""
40 if path.startswith(
"root://"):
41 from urllib.parse
import urlparse
43 from XRootD
import client
as xrd_client
45 parsed = urlparse(path)
46 fs = xrd_client.FileSystem(f
"{parsed.scheme}://{parsed.netloc}")
47 status, _ = fs.stat(parsed.path)
49 return os.path.exists(path)
53 """Prevent double delete due to a FairRoot bug."""
55 if ROOT.addressof(ROOT.gEve) == 0:
57 ROOT.SetOwnership(fMan,
False)
60atexit.register(evExit)
64pdg = ROOT.TDatabasePDG.Instance()
67gEnv.SetValue(
"Eve.Viewer.HideMenus",
"off")
75transparentMaterials = {
79 "STTmix9010_2bar": 95,
82 "LiquidScintillator": 80,
93parser = ArgumentParser()
95parser.add_argument(
"-f",
"--inputFile", dest=
"InputFile", help=
"Input file (MC simulation)", required=
True)
97 "-r",
"--recoFile", dest=
"recoFile", help=
"Reconstruction file (will be used as friend tree)", required=
False
99parser.add_argument(
"-g",
"--geoFile", dest=
"geoFile", help=
"ROOT geofile", required=
True)
104 help=
"FairRoot param file",
111 help=
"Switch on debugging",
125 dest=
"HiddenParticleID",
126 help=
"HiddenParticle ID",
132options = parser.parse_args()
133if options.InputFile.find(
"_D") > 0:
137if not options.recoFile:
139 if options.InputFile.find(
"_rec.root") > 0:
140 options.recoFile = options.InputFile
141 options.InputFile = options.InputFile.replace(
"_rec.root",
".root")
143 candidate = options.InputFile.replace(
".root",
"_rec.root")
145 options.recoFile = candidate
151 " %6i %7i %6.3F %6.3F %7.3F %7.3F %7.3F %7.3F %6i "
158 mcp.GetStartX() / u.m,
159 mcp.GetStartY() / u.m,
160 mcp.GetStartZ() / u.m,
166def dump(pcut: float = 0) ->
None:
167 print(
" # pid px py pz vx vy vz mid")
169 for mcp
in sTree.MCTrack:
171 if mcp.GetP() / u.GeV < pcut:
177 print(
" # converged Ndf chi2/Ndf P Pt MCid")
179 for ft
in sTree.FitTracks:
181 fitStatus = ft.getFitStatus()
182 fitState = ft.getFittedState()
183 mom = fitState.getMom()
185 "%3i %6i %4i %6.3F %6.3F %6.3F %6i "
188 fitStatus.isFitConverged(),
190 fitStatus.getChi2() / fitStatus.getNdf(),
193 sTree.fitTrack2MC[n],
199 print(
" # P Pt[GeV/c] DOCA[mm] Rsq Vz[m] d1 d2")
201 for aP
in sTree.Particles:
204 if aP.GetMother(1) == 99:
206 Rsq = (aP.Vx() / (2.45 * u.m)) ** 2 + (aP.Vy() / ((10.0 / 2.0 - 0.05) * u.m)) ** 2
208 "%3i %6.3F %6.3F %9.3F %6.3F %6.3F %4i %4i "
228 self.
comp = ROOT.TEveCompound(
"Veto Digis")
229 gEve.AddElement(self.
comp)
230 sc = gEve.GetScenes()
237 self.comp.DestroyElements()
238 self.comp.OpenCompound()
239 nav = ROOT.gGeoManager.GetCurrentNavigator()
240 for digi
in sTree.Digi_SBTHits:
241 if not digi.isValid():
243 node = digi.GetNode()
244 shape = node.GetVolume().GetShape()
245 bx = ROOT.TEveBox(node.GetName())
246 bx.SetPickable(ROOT.kTRUE)
247 bx.SetTitle(digi.__repr__())
248 bx.SetMainColor(ROOT.kMagenta + 3)
249 dx, dy, dz = shape.GetDX(), shape.GetDY(), shape.GetDZ()
250 o = shape.GetOrigin()
251 master = array(
"d", [0, 0, 0])
263 origin = array(
"d", [edge[0] + o[0], edge[1] + o[1], edge[2] + o[2]])
264 nav.LocalToMaster(origin, master)
265 bx.SetVertex(n, master[0], master[1], master[2])
267 self.comp.AddElement(bx)
268 self.comp.CloseCompound()
269 gEve.ElementChanged(self.evscene,
True,
True)
272 self.
comp.OpenCompound()
273 DTrack = ROOT.TEveLine()
274 DTrack.SetPickable(ROOT.kTRUE)
275 DTrack.SetMainColor(ROOT.kCyan)
276 DTrack.SetLineWidth(4)
277 aP = sTree.Particles[n]
278 DTrack.SetTitle(aP.__repr__())
279 DTrack.SetName(
"Prtcle_" + str(n))
280 DTrack.SetNextPoint(aP.Vx(), aP.Vy(), aP.Vz())
281 lam = (self.
Targetz - aP.Vz()) / aP.Pz()
282 DTrack.SetNextPoint(aP.Vx() + lam * aP.Px(), aP.Vy() + lam * aP.Py(), self.
Targetz)
283 self.
comp.AddElement(DTrack)
284 self.
comp.CloseCompound()
285 gEve.ElementChanged(self.
evscene,
True,
True)
294 self.
comp = ROOT.TEveCompound(
"Tracks")
295 gEve.AddElement(self.
comp)
302 dv = top.GetNode(
"DecayVolume_1")
307 T1Lid = ns.FindObject(
"T1Lid_1").GetMatrix()
309 except AttributeError:
313 muonDet = top.GetNode(
"MuonDetector_1")
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")
323 self.
z_mag = magNode.GetMatrix().GetTranslation()[2]
324 elif hasattr(ShipGeo,
"Bfield"):
325 self.
z_mag = ShipGeo[
"Bfield"].z
331 sc = gEve.GetScenes()
333 targetNode = top.GetNode(
"TargetArea_1")
335 self.
Targetz = targetNode.GetMatrix().GetTranslation()[2]
336 elif hasattr(ShipGeo,
"target"):
337 self.
Targetz = ShipGeo[
"target"].z0
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"):
354 self.comp.CloseCompound()
355 gEve.ElementChanged(self.evscene,
True,
True)
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)
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())
381 pName = str(fT.GetPdgCode())
382 DTrack.SetName(
"MCTrck_" + str(n) +
"_" + pName)
383 fPos = ROOT.TVector3()
384 fMom = ROOT.TVector3()
385 fT.GetStartVertex(fPos)
389 for da
in sTree.MCTrack:
390 if da.GetMotherId() == n:
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())
400 lam = (zEx + fPos.Z()) / fMom.Z()
401 DTrack.SetNextPoint(fPos.X() + lam * fMom.X(), fPos.Y() + lam * fMom.Y(), zEx + fPos.Z())
403 DTrack.SetMainColor(c)
404 DTrack.SetLineWidth(3)
405 self.
comp.AddElement(DTrack)
406 self.
comp.CloseCompound()
407 gEve.ElementChanged(self.
evscene,
True,
True)
412 fPos = ROOT.TVector3()
413 fMom = ROOT.TVector3()
416 hits_by_track: dict[int, list] = {}
423 "SiliconTargetPoint",
425 "CaloScoringPlanePoint",
427 if not sTree.GetBranch(P):
429 for p
in getattr(sTree, P):
430 hits_by_track.setdefault(p.GetTrackID(), []).append(p)
431 for fT
in sTree.MCTrack:
433 DTrack = ROOT.TEveLine()
434 DTrack.SetPickable(ROOT.kTRUE)
435 DTrack.SetTitle(fT.__repr__())
436 fT.GetStartVertex(fPos)
438 hitlist[fPos.Z()] = [fPos.X(), fPos.Y()]
440 if abs(fT.GetPdgCode()) == options.HiddenParticleID:
442 for da
in sTree.MCTrack:
443 if da.GetMotherId() == n:
448 da.GetStartVertex(fPos)
449 hitlist[fPos.Z()] = [fPos.X(), fPos.Y()]
451 for p
in hits_by_track.get(n, []):
452 if hasattr(p,
"LastPoint"):
454 if lp.x() == lp.y()
and lp.x() == lp.z()
and lp.x() == 0:
456 hitlist[p.GetZ()] = [p.GetX(), p.GetY()]
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(),
464 hitlist[p.GetZ()] = [p.GetX(), p.GetY()]
465 if len(hitlist) == 1:
466 if fT.GetMotherId() < 0:
468 if abs(sTree.MCTrack[fT.GetMotherId()].GetPdgCode()) == options.HiddenParticleID:
472 for da
in sTree.MCTrack:
473 if da.GetMotherId() == n:
477 hitlist[da.GetStartZ()] = [da.GetStartX(), da.GetStartY()]
481 lam = (zEx + fPos.Z()) / fMom.Z()
482 hitlist[zEx + fPos.Z()] = [
483 fPos.X() + lam * fMom.X(),
484 fPos.Y() + lam * fMom.Y(),
487 lz = list(hitlist.keys())
491 DTrack.SetNextPoint(hitlist[z][0], hitlist[z][1], z)
492 p = pdg.GetParticle(fT.GetPdgCode())
496 pName = str(fT.GetPdgCode())
497 DTrack.SetName(
"MCTrack_" + str(n) +
"_" + pName)
499 if abs(fT.GetPdgCode()) == options.HiddenParticleID:
501 DTrack.SetMainColor(c)
502 DTrack.SetLineWidth(3)
503 self.
comp.AddElement(DTrack)
505 print(
"draw ", ntot,
" MC tracks")
509 for fT
in sTree.FitTracks:
511 fst = fT.getFitStatus()
512 if not fst.isFitConverged():
514 if fst.getNdf() < 20:
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()
524 pid = fstate.getPDG()
526 for i
in range(self.
niter):
529 DTrack.SetNextPoint(newpos.X(), newpos.Y(), newpos.Z())
531 print(
"error with extrapolation: z=", zs)
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)
537 DTrack.SetName(
"FitTrack_" + str(n))
541 DTrack.SetMainColor(c)
542 DTrack.SetLineWidth(3)
543 self.
comp.AddElement(DTrack)
545 print(
"draw ", ntot,
" fitted tracks")
547 for aP
in sTree.Particles:
551 if aP.GetMother(1) == 99:
552 if aP.T() > 3 * u.cm:
554 for k
in range(aP.GetNDaughters()):
557 fT = sTree.FitTracks[aP.GetDaughter(k)]
558 fst = fT.getFitStatus()
559 if not fst.isFitConverged():
561 if fst.getNdf() < 20:
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)
584 self.
master.title(
"SHiP Event Display GUI")
585 self.
master.geometry(
"320x580+165+820")
587 b = tkinter.Button(self.
fram1, text=
"Next Event", command=self.
nextEvent)
588 b.pack(fill=tkinter.BOTH, expand=1)
589 label = tkinter.Label(self.
fram1, text=
"Event number:")
590 label[
"relief"] = tkinter.RAISED
591 entry = tkinter.Entry(self.
fram1)
592 entry[
"foreground"] =
"blue"
593 label.pack(side=tkinter.LEFT)
594 entry.pack(side=tkinter.RIGHT)
600 entry[
"textvariable"] = self.
contents
608 if globals()[
"withMCTracks"]:
612 self.
lbut[x] = tkinter.Checkbutton(self.
master, text=
"with MC Tracks", compound=tkinter.LEFT, variable=a)
615 self.
lbut[x].pack(side=tkinter.TOP)
616 self.
geoscene = ROOT.gEve.GetScenes().FindChild(
"Geometry scene")
617 for v
in top.GetNodes():
620 assembly =
"Assembly" in v.GetVolume().__str__()
621 if v.IsVisible()
or (assembly
and v.IsVisDaughters()):
625 self.
lbut[x] = tkinter.Checkbutton(self.
master, text=x.replace(
"_1",
""), compound=tkinter.LEFT, variable=a)
627 self.
lbut[x][
"command"] =
lambda x=x: self.
toggle(x)
628 self.
lbut[x].pack(side=tkinter.BOTTOM)
632 slot = ROOT.TEveWindow.CreateWindowInTab(gEve.GetBrowser().GetTabLeft())
633 slot.SetShowTitleBar(ROOT.kFALSE)
634 packs = slot.MakePack()
635 packs.SetShowTitleBar(ROOT.kFALSE)
636 packs.SetElementName(
"SHiP actions")
637 packs.SetHorizontal()
638 slot = packs.NewSlot()
639 frame = slot.MakeFrame()
640 frame.SetElementName(
"commands")
641 frame.SetShowTitleBar(ROOT.kFALSE)
642 cf = frame.GetGUICompositeFrame()
643 hf = ROOT.TGVerticalFrame(cf)
644 hf.SetCleanup(ROOT.kLocalCleanup)
647 guiFrame = ROOT.TGVerticalFrame(hf)
648 hf.AddFrame(guiFrame, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
649 guiFrame.SetCleanup(ROOT.kDeepCleanup)
650 b = ROOT.TGTextButton(guiFrame,
"Add particle follower")
652 b.SetToolTipText(
"start new window with top projection and energy loss")
653 b.SetCommand(
'TPython::ExecScript("' + os.environ[
"FAIRSHIP"] +
'/macro/evd_addParticleFollower.py")')
654 guiFrame.AddFrame(b, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
655 bn = ROOT.TGTextButton(guiFrame,
"fill histogram")
657 bn.SetToolTipText(
"Fill histogram with energy along flight path")
658 bn.SetCommand(
'TPython::ExecScript("' + os.environ[
"FAIRSHIP"] +
'/macro/evd_fillEnergy.py")')
659 guiFrame.AddFrame(bn, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
660 bt = ROOT.TGTextButton(guiFrame,
"switch transparent mode on/off")
662 bt.SetToolTipText(
"switch transparent mode on/off for better visibility of tracks")
663 bt.SetCommand(
'TPython::ExecScript("' + os.environ[
"FAIRSHIP"] +
'/macro/evd_transparentMode.py")')
664 guiFrame.AddFrame(bt, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
665 bnx = ROOT.TGTextButton(guiFrame,
"next event")
667 bnx.SetToolTipText(
"click for next event")
668 bnx.SetCommand(
'TPython::ExecScript("' + os.environ[
"FAIRSHIP"] +
'/macro/evd_nextEvent.py")')
669 guiFrame.AddFrame(bnx, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
682 SHiPDisplay.NextEvent(self.
n)
686 raise RuntimeError(
"toggleMCTracks called before fRun was initialised")
687 tl = fRun.GetMainTask().GetListOfTasks()
688 geoTask = tl.FindObject(
"GeoTracks")
689 if globals()[
"withMCTracks"]:
690 globals()[
"withMCTracks"] =
False
691 self.
lbut[
"withMC"].var.set(0)
695 globals()[
"withMCTracks"] =
True
696 self.
lbut[
"withMC"].var.set(1)
702 assembly =
"Assembly" in v.GetVolume().__str__()
703 if v.IsVisible() > 0
or (assembly
and v.IsVisDaughters() > 0):
704 print(
"switch off ", x)
707 self.
lbut[x].var.set(0)
709 print(
"switch on ", x)
714 self.
lbut[x].var.set(1)
715 gEve.ElementChanged(self.
geoscene,
True,
True)
716 for v
in top.GetNodes():
719 assembly =
"Assembly" in v.GetVolume().__str__()
720 if v.IsVisible() > 0
or (assembly
and v.IsVisDaughters() > 0):
721 self.
lbut[x].var.set(1)
723 self.
lbut[x].var.set(0)
733 if sGeo.GetVolume(
"volTarget"):
742 v1 = gEve.GetDefaultViewer()
743 v1.GetEveFrame().HideAllDecorations()
744 tr = gEve.GetBrowser().GetTabRight()
746 t0.SetText(ROOT.TGString(
"3D"))
750 raise RuntimeError(
"NextEvent called before fRun was initialised")
755 fRun.Run(self.
n, self.
n + 1)
757 if sTree.GetBranch(
"FitTracks_PR"):
758 sTree.FitTracks = sTree.FitTracks_PR
759 if sTree.GetBranch(
"fitTrack2MC_PR"):
760 sTree.fitTrack2MC = sTree.fitTrack2MC_PR
761 if sTree.GetBranch(
"Particles_PR"):
762 sTree.Particles = sTree.Particles_PR
763 if hasattr(self,
"tracks"):
765 if sTree.FindBranch(
"Digi_SBTHits"):
766 self.
veto.ExecuteTask()
767 if ROOT.gROOT.FindObject(
"Root Canvas EnergyLoss"):
769 print(
"Event %i ready" % (self.
n))
772 p = ROOT.gEve.GetCurrentEvent().FindChild(mcHits[x].GetName())
774 p.SetPickable(ROOT.kTRUE)
775 p.SetTitle(p.__repr__())
777 def rotateView(self, hor: float | int = 0, ver: float | int = 0) ->
None:
778 v = ROOT.gEve.GetDefaultGLViewer()
779 cam = v.CurrentCamera()
781 if hor != 0
or ver != 0:
782 cam.RotateRad(hor, ver)
804 for m
in transparentMaterials:
805 mat = ROOT.gGeoManager.GetMaterial(m)
808 if mode.lower() ==
"on" or mode == 1:
809 mat.SetTransparency(transparentMaterials[m])
812 mat.SetTransparency(
"\x00")
814 sc = gEve.GetScenes()
815 geoscene = sc.FindChild(
"Geometry scene")
817 gEve.ElementChanged(geoscene,
True,
True)
824 s = ROOT.gEve.SpawnNewScene(
"Projected Event")
825 ROOT.gEve.GetDefaultViewer().AddScene(s)
826 v = ROOT.gEve.GetDefaultGLViewer()
827 v.SetCurrentCamera(ROOT.TGLViewer.kCameraOrthoXOY)
828 cam = v.CurrentCamera()
829 cam.SetZoomMinMax(0.2, 20)
831 mng = ROOT.TEveProjectionManager(ROOT.TEveProjection.kPT_RPhi)
833 axes = ROOT.TEveProjectionAxes(mng)
834 axes.SetTitle(
"TEveProjections demo")
836 ROOT.gEve.AddToListTree(axes, ROOT.kTRUE)
837 ROOT.gEve.AddToListTree(mng, ROOT.kTRUE)
842 v = gEve.GetViewers()
843 vw = v.FindChild(
"Viewer 1")
846 sev = ROOT.gEve.SpawnNewViewer(
"Scaled 2D")
847 smng = ROOT.TEveProjectionManager(ROOT.TEveProjection.kPP_Plane)
848 sp = smng.GetProjection()
849 sp.SetUsePreScale(ROOT.kTRUE)
850 sp.AddPreScaleEntry(2, 100000000.0, 0.1)
851 ss = ROOT.gEve.SpawnNewScene(
"Scaled Geom")
854 N = sGeo.GetTopNode()
855 TNod = ROOT.TEveGeoTopNode(sGeo, N, 1, 3, 10)
857 eventscene = ROOT.gEve.SpawnNewScene(
"Scaled event")
858 eventscene.AddElement(ROOT.FairEventManager.Instance())
859 sev.AddScene(eventscene)
860 eventscene.AddElement(smng)
861 ROOT.gEve.GetBrowser().GetTabRight().SetTab(1)
862 ROOT.gEve.FullRedraw3D(ROOT.kTRUE)
866 f = ROOT.TFile.Open(fname,
"RECREATE")
867 cam = ROOT.gEve.GetDefaultGLViewer().CurrentCamera()
873 f = ROOT.TFile.Open(fname)
874 cam = ROOT.gEve.GetDefaultGLViewer().CurrentCamera()
875 f.GetKey(cam.ClassName()).Read(cam)
877 gEve.GetDefaultGLViewer().RequestDraw()
882 for x
in [
"wire",
"gas",
"rockD",
"rockS",
"rockSFe"]:
883 xvol = sGeo.GetVolume(x)
885 xvol.SetVisibility(0)
886 for k
in range(1, 7):
887 va = sGeo.GetVolume(
"T" + str(k))
890 for x
in va.GetNodes():
892 if not nm.find(
"Inner") < 0
and k < 3:
893 x.SetVisDaughters(
False)
894 x.SetVisibility(
False)
895 if not nm.find(
"LiSc") < 0:
896 x.SetVisDaughters(
False)
897 if not nm.find(
"RibPhi") < 0:
898 x.SetVisDaughters(
False)
904 xvol = sGeo.GetVolume(x)
907 xvol.SetVisDaughters(0)
908 xvol.SetVisibility(1)
909 sc = gEve.GetScenes()
910 geoscene = sc.FindChild(
"Geometry scene")
911 gEve.ElementChanged(geoscene,
True,
True)
915 sc = gEve.GetScenes()
916 geoscene = sc.FindChild(
"Geometry scene")
917 for v
in top.GetNodes():
919 if not vname.find(tag) < 0:
922 gEve.ElementChanged(geoscene,
True,
True)
926 sc = gEve.GetScenes()
927 geoscene = sc.FindChild(
"Geometry scene")
928 for v
in top.GetNodes():
930 if not vname.find(tag) < 0:
931 print(
"switch on ", vname)
934 gEve.ElementChanged(geoscene,
True,
True)
938 sc = gEve.GetScenes()
939 geoscene = sc.FindChild(
"Geometry scene")
940 v = sGeo.FindVolumeFast(
"vleft")
943 for v
in sGeo.GetListOfVolumes():
944 if v.GetName().find(
"wallVeto") > 0:
947 gEve.ElementChanged(geoscene,
True,
True)
952 sc = gEve.GetScenes()
953 geoscene = sc.FindChild(
"Geometry scene")
954 for x
in [
"rockD",
"rockS"]:
955 v = sGeo.FindVolumeFast(x)
957 gEve.ElementChanged(geoscene,
True,
True)
961 sc = gEve.GetScenes()
962 geoscene = sc.FindChild(
"Geometry scene")
963 for v
in top.GetNodes():
965 if not vname.find(
"cave") < 0:
969 if not tag.find(vname) < 0:
974 gEve.ElementChanged(geoscene,
True,
True)
978 sc = gEve.GetScenes()
979 geoscene = sc.FindChild(
"Geometry scene")
980 for v
in top.GetNodes():
982 if not vname.find(
"cave") < 0:
986 if not tag.find(vname) < 0:
991 gEve.ElementChanged(geoscene,
True,
True)
996 for v
in sGeo.GetListOfVolumes():
998 if not vname.find(pattern) < 0:
1005 if not x.find(tag) < 0:
1009def rename(name: str =
"ship.TGeant4.root") ->
None:
1010 f = ROOT.TFile(name,
"UPDATE")
1012 for x
in t.GetListOfBranches():
1013 nm = x.GetName().replace(
"_1",
"")
1023 self.
ruler = ROOT.TEveCompound(
"Rulers")
1024 gEve.AddElement(self.
ruler)
1026 def show(self, xy: int = 0, ticks: int = 5) ->
None:
1027 self.
ruler.DestroyElements()
1028 self.
ruler.OpenCompound()
1029 xpos, ypos = -500.0, -1500.0
1030 zstart = ShipGeo.target.z0
1032 a1 = ROOT.TEveLine()
1033 a1.SetNextPoint(xpos, ypos, zstart)
1034 a1.SetNextPoint(xpos, ypos, zstart + zlength)
1035 a1.SetMainColor(ROOT.kAzure - 9)
1039 for i
in range(int(zlength / 100 / ticks)):
1041 m.SetNextPoint(xpos, ypos, z)
1042 m.SetNextPoint(xpos - 1 * u.m, ypos, z)
1043 m.SetMainColor(ROOT.kRed)
1045 self.
ruler.AddElement(m)
1046 t1 = ROOT.TEveText(str(i * ticks) +
"m")
1047 t1.SetMainColor(ROOT.kGray + 3)
1049 t1.RefMainTrans().SetPos(xpos - 0.1 * u.m, ypos + 0.2 * u.m, z)
1050 self.
ruler.AddElement(t1)
1052 xpos, ypos = 0.0, 0.0
1058 a2 = ROOT.TEveLine()
1059 a2.SetNextPoint(xpos, -ylength, z)
1060 a2.SetNextPoint(xpos, ylength, z)
1061 a2.SetMainColor(ROOT.kAzure - 9)
1065 for i
in range(-int(ylength / 100), int(ylength / 100), 1):
1067 m.SetNextPoint(xpos, ypos, z)
1068 m.SetNextPoint(xpos + 0.05 * u.m, ypos, z)
1069 m.SetMainColor(ROOT.kRed)
1071 self.
ruler.AddElement(m)
1072 t1 = ROOT.TEveText(str(i) +
"m")
1073 t1.SetMainColor(ROOT.kGray + 3)
1075 t1.RefMainTrans().SetPos(xpos - 0.5 * u.m, ypos, z)
1076 self.
ruler.AddElement(t1)
1078 ty = ROOT.TEveText(
"y-axis")
1080 ty.RefMainTrans().SetPos(0.0, ypos + 1 * u.m, z)
1081 ty.SetMainColor(ROOT.kRed - 2)
1082 self.
ruler.AddElement(ty)
1083 xpos, ypos = 0.0, 0.0
1087 a3 = ROOT.TEveLine()
1088 a3.SetNextPoint(-xlength, 0, z)
1089 a3.SetNextPoint(xlength, 0, z)
1090 a3.SetMainColor(ROOT.kAzure - 9)
1094 for i
in range(-int(xlength / 100), int(xlength / 100), 1):
1096 m.SetNextPoint(xpos, ypos, z)
1097 m.SetNextPoint(xpos, ypos - 0.05 * u.m, z)
1098 m.SetMainColor(ROOT.kRed)
1100 self.
ruler.AddElement(m)
1101 t1 = ROOT.TEveText(str(i) +
"m")
1102 t1.SetMainColor(ROOT.kGray + 3)
1104 t1.RefMainTrans().SetPos(xpos, ypos - 0.1 * u.m, z)
1105 self.
ruler.AddElement(t1)
1107 tx = ROOT.TEveText(
"x-axis")
1109 tx.RefMainTrans().SetPos(xpos + 1 * u.m, 0.0, z)
1110 tx.SetMainColor(ROOT.kRed - 2)
1111 self.
ruler.AddElement(tx)
1112 t1 = ROOT.TEveText(
"SHiP")
1114 t1.RefMainTrans().SetPos(0.0, 600.0, ShipGeo.TrackStation1.z - 10 * u.m)
1115 t1.PtrMainTrans().RotateLF(1, 3, ROOT.TMath.PiOver2())
1116 t1.SetMainColor(ROOT.kOrange - 2)
1117 t1.SetFontMode(ROOT.TGLFont.kExtrude)
1118 t1.SetLighting(ROOT.kTRUE)
1119 self.
ruler.AddElement(t1)
1120 self.
ruler.CloseCompound()
1121 sc = ROOT.gEve.GetScenes()
1122 geoscene = sc.FindChild(
"Geometry scene")
1123 ROOT.gEve.ElementChanged(geoscene,
True,
True)
1126 self.
ruler.DestroyElements()
1130 t = g.FindObjectAny(
"cbmsim")
1131 nev = t.GetEntriesFast()
1134 for i
in range(min(5, nev)):
1136 for gTr
in t.GeoTracks:
1139 lorv = ROOT.TLorentzVector()
1151 for i
in range(min(5, nev)):
1153 for gMCTr
in t.MCTrack:
1155 print(gMCTr.GetPdgCode(), gMCTr.GetMass(), gMCTr.GetP())
1157 for i
in range(nev):
1160 t.MCEventHeader.GetEventID(),
1161 t.MCEventHeader.GetRunID(),
1162 t.MCEventHeader.GetZ(),
1165 sGeo = ROOT.gGeoManager
1166 cave = sGeo.GetTopVolume()
1171 sc = gEve.GetScenes()
1172 geoscene = sc.FindChild(
"Geometry scene")
1173 topnode = geoscene.FindChild(
"cave_1")
1174 topnode.SetVisLevel(4)
1175 gEve.ElementChanged(geoscene,
True,
True)
1179 sGeo = ROOT.gGeoManager
1180 vols = sGeo.GetListOfVolumes()
1181 sTree = g.FindObjectAny(
"cbmsim")
1183 for s
in sTree.strawtubesPoint:
1184 print(vols[s.GetDetectorID() - 1].GetName())
1188ROOT.gSystem.Load(
"libEGPythia6.so")
1189ROOT.gSystem.Load(
"libPythia6.so")
1190ROOT.gSystem.Load(
"libpythia8.so")
1192ROOT.gInterpreter.Declare(
'#include "VectorMCPointSource.h"')
1195fRun = ROOT.FairRunAna()
1197 fRun.SetGeomFile(options.geoFile)
1199inFile = ROOT.FairFileSource(options.InputFile)
1200fRun.SetSource(inFile)
1201ROOT.SetOwnership(inFile,
False)
1202if options.OutputFile
is None:
1205 options.OutputFile = tempfile.mktemp(suffix=
".root")
1206sink = ROOT.FairRootFileSink(options.OutputFile)
1208ROOT.SetOwnership(sink,
False)
1211 rtdb = fRun.GetRuntimeDb()
1212 parInput1 = ROOT.FairParRootFileIo()
1213 parInput1.open(options.ParFile)
1214 rtdb.setFirstInput(parInput1)
1216fMan = ROOT.FairEventManager()
1217fMan.SetMaxEnergy(400.0)
1218fMan.SetMinEnergy(0.1)
1219fMan.SetEvtMaxEnergy(400.0)
1220fMan.SetPriOnly(
False)
1225 Track = ROOT.FairMCTracksDraw(
"Monte-Carlo Tracks")
1226 GTrack = ROOT.FairGeoTracksDraw(
"GeoTracks")
1227 fMan.AddTask(GTrack)
1231ShipGeo = load_from_root_file(fRun.GetGeoFile(),
"ShipGeo")
1234_tmpFile = ROOT.TFile.Open(options.InputFile)
1235_tmpTree = _tmpFile.Get(
"cbmsim")
if _tmpFile
else None
1239 "VetoPoints": (
"vetoPoint", ROOT.kBlue, ROOT.kFullDiamond),
1240 "TimeDetPoints": (
"TimeDetPoint", ROOT.kBlue, ROOT.kFullDiamond),
1241 "CaloScoringPlanePoints": (
"CaloScoringPlanePoint", ROOT.kMagenta, ROOT.kFullCircle),
1242 "StrawPoints": (
"strawtubesPoint", ROOT.kGreen, ROOT.kFullCircle),
1243 "TargetPoints": (
"TargetPoint", ROOT.kRed, ROOT.kFullSquare),
1244 "MTCDetPoint": (
"MTCDetPoint", ROOT.kGreen, ROOT.kFullSquare),
1245 "SiliconTargetPoint": (
"SiliconTargetPoint", ROOT.kCyan, ROOT.kFullSquare),
1247for key, (branch, colour, marker)
in _candidates.items():
1248 if _tmpTree
and _tmpTree.GetBranch(branch):
1249 source = ROOT.VectorMCPointSource[branch](branch)
1250 mcHits[key] = ROOT.FairMCPointDraw(branch, source, colour, marker)
1256 fMan.AddTask(mcHits[x])
1265fRman = ROOT.FairRootManager.Instance()
1266sTree = fRman.GetInChain()
1268 sTree.AddFriend(
"ship_reco_sim", options.recoFile)
1269lsOfGlobals = ROOT.gROOT.GetListOfGlobals()
1270lsOfGlobals.Add(sTree)
1271sGeo = ROOT.gGeoManager
1272top = sGeo.GetTopVolume()
1277if hasattr(ShipGeo,
"Bfield"):
1278 if hasattr(ShipGeo.Bfield,
"fieldMap"):
1279 ROOT.gSystem.Load(
"libgeant4vmc.so")
1283 bfield = ROOT.genfit.FairShipFields()
1284 bfield.setField(fieldMaker.getGlobalField())
1286 bellField = ROOT.ShipBellField(
1287 "bellfield", ShipGeo.Bfield.max, ShipGeo.Bfield.z, 2, ShipGeo.Bfield.y / 2.0 * u.m
1289 compField = ROOT.ShipCompField(
"compfield", bellField)
1290 bfield = ROOT.genfit.FairShipFields()
1291 bfield.setField(compField)
1292 geoMat = ROOT.genfit.TGeoMaterialInterface()
1293 ROOT.genfit.MaterialEffects.getInstance().init(geoMat)
1294 fM = ROOT.genfit.FieldManager.getInstance()
1297import TrackExtrapolateTool
1299br = gEve.GetBrowser()
1301br.SetWindowName(
"SHiP Eve Window")
1304if sGeo.FindVolumeFast(
"T2LiSc"):
1310eveGlobal.SHiPDisplay = SHiPDisplay
1311SHiPDisplay.SetName(
"SHiP Displayer")
1312lsOfGlobals.Add(SHiPDisplay)
1313SHiPDisplay.InitTask()
1317print(
"Help on GL viewer can be found by pressing Help button followed by help on GL viewer")
1318print(
"With the camera button, you can switch to different views.")
1332 for aTrack
in sTree.MCTrack:
1336 if aTrack.GetMotherId() == 1:
1337 pdg_code = sTree.MCTrack[i].GetPdgCode()
1338 if is_known_particle(pdg_code)
and get_particle(pdg_code).Lifetime() > 1.0e-12:
1339 print(sTree.MCTrack[i])
1340 SHiPDisplay.tracks.DrawMCTrack(i)
1344 comp = SHiPDisplay.tracks.comp
1348 fPos = ROOT.TVector3()
1349 fMom = ROOT.TVector3()
1351 for fT
in sTree.MCTrack:
1353 DTrack = ROOT.TEveLine()
1354 DTrack.SetPickable(ROOT.kTRUE)
1355 DTrack.SetTitle(fT.__repr__())
1356 fT.GetStartVertex(fPos)
1357 fT.GetMomentum(fMom)
1359 hitlist[fPos.Z()] = [fPos.X(), fPos.Y()]
1361 slx, sly = fMom.X() / fMom.Z(), fMom.Y() / fMom.Z()
1362 hitlist[z] = [fPos.X() + slx * delZ, fPos.Y() + sly * delZ]
1364 DTrack.SetNextPoint(hitlist[z][0], hitlist[z][1], z)
1365 p = pdg.GetParticle(fT.GetPdgCode())
1369 pName = str(fT.GetPdgCode())
1370 DTrack.SetName(
"MCTrack_" + str(n) +
"_" + pName)
1372 DTrack.SetMainColor(c)
1373 DTrack.SetLineWidth(3)
1374 comp.AddElement(DTrack)
1376 comp.CloseCompound()
1377 gEve.ElementChanged(SHiPDisplay.tracks.evscene,
True,
True)
1389 mode=ROOT.TGLFont.kExtrude,
1392 tt = ROOT.TEveText(txt)
1393 tt.SetFontSize(size)
1394 tt.RefMainTrans().SetPos(x, y, z)
1395 tt.PtrMainTrans().RotateLF(1, 3, angle)
1396 tt.SetMainColor(color)
1397 tt.SetFontMode(mode)
1398 tt.SetLighting(light)
1405 "moreShieldingSide",
1406 "moreShieldingTopBot",
1411 vol = ROOT.gGeoManager.FindVolumeFast(x)
1412 vol.SetVisibility(0)
1413 ROOT.gGeoManager.GetMaterial(
"Concrete").SetTransparency(0)
1418 xpos, ypos = -500.0, -1500.0
1419 zstart = ShipGeo.target.z0
1422 for i
in range(int(zlength / 100 / ticks)):
1424 m.SetNextPoint(xpos, ypos, z)
1425 m.SetNextPoint(xpos - 1 * u.m, ypos, z)
1426 m.SetMainColor(ROOT.kRed)
1429 t1 = ROOT.TEveText(str(i * ticks) +
"m")
1430 t1.SetMainColor(ROOT.kGray + 3)
1432 t1.RefMainTrans().SetPos(xpos - 0.1 * u.m, ypos + 0.2 * u.m, z)
1435 xpos, ypos = 0.0, 0.0
1439 for i
in range(-int(ylength / 100), int(ylength / 100), 1):
1441 m.SetNextPoint(xpos, ypos, z)
1442 m.SetNextPoint(xpos + 0.05 * u.m, ypos, z)
1443 m.SetMainColor(ROOT.kRed)
1446 t1 = ROOT.TEveText(str(i) +
"m")
1447 t1.SetMainColor(ROOT.kGray + 3)
1449 t1.RefMainTrans().SetPos(xpos - 0.5 * u.m, ypos, z)
1452 ty = ROOT.TEveText(
"y-axis")
1454 ty.RefMainTrans().SetPos(0.0, ypos + 1 * u.m, z)
1455 ty.SetMainColor(ROOT.kRed - 2)
1457 xpos, ypos = 0.0, 0.0
1461 for i
in range(-int(xlength / 100), int(xlength / 100), 1):
1463 m.SetNextPoint(xpos, ypos, z)
1464 m.SetNextPoint(xpos, ypos - 0.05 * u.m, z)
1465 m.SetMainColor(ROOT.kRed)
1468 t1 = ROOT.TEveText(str(i) +
"m")
1469 t1.SetMainColor(ROOT.kGray + 3)
1471 t1.RefMainTrans().SetPos(xpos, ypos - 0.1 * u.m, z)
1474 tx = ROOT.TEveText(
"x-axis")
1476 tx.RefMainTrans().SetPos(xpos + 1 * u.m, 0.0, z)
1477 tx.SetMainColor(ROOT.kRed - 2)
1479 rotAngle = ROOT.TMath.Pi() + ROOT.TMath.PiOver2() * 5.0 / 2.0
1484 ShipGeo.TrackStation1.z - 20 * u.m,
1494 ShipGeo.TrackStation1.z - 40 * u.m,
1496 "Vacuum decay vessel",
1500 positionText(r, 0.0, 100.0, ShipGeo.target.z - 6 * u.m, rotAngle,
"Target", 200, ROOT.kBlue)
1505 ShipGeo.muShield.z - 10 * u.m,
1507 "Active muon shield",
1515 ShipGeo.tauMudet.zMudetC - 10 * u.m,
1517 "Tau neutrino detector",
1525 ShipGeo.Bfield.z - 5 * u.m,
1535 ShipGeo.TrackStation3.z - 2 * u.m,
1542 sc = gEve.GetScenes()
1543 geoscene = sc.FindChild(
"Geometry scene")
1544 gEve.ElementChanged(geoscene,
True,
True)
None ExecuteTask(self, str option="")
None DrawFittedTracks(self, str option="")
None DrawMCTrack(self, int n)
None DrawMCTracks(self, str option="")
None DrawParticle(self, n)
None ExecuteTask(self, str option="")
None DrawParticle(self, n)
None rotateView(self, float|int hor=0, float|int ver=0)
None transparentMode(self, str mode="on")
None NextEvent(self, int i=-1)
None toggleMCTracks(self)
None show(self, int xy=0, int ticks=5)
None rename(str name="ship.TGeant4.root")
None storeCameraSetting(str fname="camSetting.root")
None projection_prescale()
bool _file_accessible(str path)
None hidePlasticScintillator()
None readCameraSetting(str fname="camSetting.root")
None positionText(r, float x, float y, z, angle, str txt, int size=200, color=ROOT.kBlue, mode=ROOT.TGLFont.kExtrude, light=ROOT.kTRUE)
float z_end_of_detector(ShipGeo)
None printMCTrack(int n, MCTrack)
None DrawSimpleMCTracks()
addVMCFields(shipGeo, str controlFile="", bool verbose=False, bool withVirtualMC=True)
None configure(darkphoton=None)