FairShip
Loading...
Searching...
No Matches
decorators.py
Go to the documentation of this file.
1# SPDX-License-Identifier: LGPL-3.0-or-later
2# SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP Collaboration
3
4from ctypes import c_double
5
6import ROOT
7import shipunit as u
8
9
11 p = ROOT.TDatabasePDG.Instance().GetParticle(x.PdgCode())
12 n = ""
13 if p:
14 n = p.GetName()
15 txt = f'("{x.Class_Name()}") X:{x.GetX():6.3F}cm Y:{x.GetY():6.3F}cm Z:{x.GetZ():6.3F}cm dE/dx:{x.GetEnergyLoss() / u.MeV:6.2F}MeV {n}'
16 return txt
17
18
20 c = x.GetPdgCode()
21 p = ROOT.TDatabasePDG.Instance().GetParticle(c)
22 n = ""
23 if p:
24 n = p.GetName()
25 m = x.GetMotherId()
26 txt = '("ShipMCTrack") pdgCode: %7i(%10s) Z=%6.1F m P=%6.3F GeV/c mother=%i %s' % (
27 c,
28 n,
29 x.GetStartZ() / u.m,
30 x.GetP(),
31 m,
32 x.GetProcName(),
33 )
34 return txt
35
36
38 txt = '("vetoHit") detID:%7i ADC:%5.2F TDC:%5.2F' % (x.GetDetectorID(), x.GetADC(), x.GetTDC())
39 return txt
40
41
43 t = x.GetMeasurements()
44 txt = '("TimeDetHit") detID:%7i TDC1:%5.2F TDC2:%5.2F isValid:%r' % (x.GetDetectorID(), t[0], t[1], x.isValid())
45 return txt
46
47
49 st = x.getFitStatus()
50 if st.isFitConverged():
51 chi2DoF = st.getChi2() / st.getNdf()
52 sta = x.getFittedState()
53 P = sta.getMomMag()
54 txt = '("FitTrack") chi2/dof:%3.1F P:%5.2FGeV/c pdg:%i' % (chi2DoF, P, sta.getPDG())
55 else:
56 txt = '("FitTrack") fit not converged'
57 return txt
58
59
60def TParticlePrintOut(x) -> str:
61 txt = f'("TParticle") {x.GetName()} P:{x.P():5.2F}GeV/c VxZ:{x.Vz() / u.m:5.2F}m'
62 return txt
63
64
66 txt = f'("ShipParticle") {x.GetName()} M:{x.GetMass():5.2F}GeV/c2 P:{x.P():5.2F}GeV/c VxZ:{x.Vz() / u.m:5.2F}m'
67 return txt
68
69
70def Dump(x) -> None:
71 k = 0
72 for obj in x:
73 print(k, obj.__repr__())
74 k += 1
75
76
77def TVector3PrintOut(x) -> str:
78 txt = f"{x.X():9.5F},{x.Y():9.5F},{x.Z():9.5F}"
79 return txt
80
81
83 txt = f"{x.Px():9.5F},{x.Py():9.5F},{x.Pz():9.5F},{x.E():9.5F},{x.Mag():9.5F}"
84 return txt
85
86
88 x, y, z = c_double(), c_double(), c_double()
89 txt = ""
90 if P.GetN() == 0:
91 txt = "<ROOT.TEvePointSet object>"
92 for n in range(P.GetN()):
93 P.GetPoint(n, x, y, z)
94 txt += f"{n:6d} {x.value:7.1f}, {y.value:7.1f}, {z.value:9.1f} x, y, z cm\n"
95
96 return txt
97
98
99def apply_decorators() -> None:
100 """Apply custom __repr__ methods to ROOT classes.
101
102 Call this function after ROOT libraries are fully loaded to enable
103 enhanced string representations for ROOT objects.
104 """
105 ROOT.FairMCPoint.__repr__ = MCPointPrintOut
106 ROOT.ShipMCTrack.__repr__ = MCTrackPrintOut
107 ROOT.genfit.Track.__repr__ = FitTrackPrintOut
108 ROOT.TClonesArray.Dump = Dump
109 ROOT.TVector3.__repr__ = TVector3PrintOut
110 ROOT.TParticle.__repr__ = TParticlePrintOut
111 ROOT.ShipParticle.__repr__ = ShipParticlePrintOut
112 ROOT.TEvePointSet.__repr__ = TEvePointSetPrintOut
113 ROOT.vetoHit.__repr__ = vetoHitPrintOut
114 ROOT.TimeDetHit.__repr__ = TimeDetHitPrintOut
115 ROOT.TLorentzVector.__repr__ = TLorentzVectorPrintOut
def FitTrackPrintOut(x)
Definition: decorators.py:48
str TLorentzVectorPrintOut(x)
Definition: decorators.py:82
def MCTrackPrintOut(x)
Definition: decorators.py:19
str TParticlePrintOut(x)
Definition: decorators.py:60
str TEvePointSetPrintOut(P)
Definition: decorators.py:87
None apply_decorators()
Definition: decorators.py:99
def vetoHitPrintOut(x)
Definition: decorators.py:37
def MCPointPrintOut(x)
Definition: decorators.py:10
None Dump(x)
Definition: decorators.py:70
str TVector3PrintOut(x)
Definition: decorators.py:77
def ShipParticlePrintOut(x)
Definition: decorators.py:65
def TimeDetHitPrintOut(x)
Definition: decorators.py:42