29from ROOT
import Belle2
30from ROOT
import gROOT, AddressOf
33gROOT.ProcessLine(
'struct TreeStruct {\
45from ROOT
import TreeStruct
52 This module writes its output to a ROOT tree.
53 Adapted from pxd/validation/PXDValidationTTreeSimHit.py
57 """Initialize the module"""
62 self.
file = ROOT.TFile(
'PID_TTree.root',
'recreate')
64 self.
tree = ROOT.TTree(
'tree',
'')
67 """ Declare tree branches """
68 for key
in TreeStruct.__dict__.keys():
71 if isinstance(self.
data.__getattribute__(key), int):
73 self.
tree.Branch(key, AddressOf(self.
data, key), key + formstring)
76 """Store TOP and dE/dx info in tree"""
80 track = pid.getRelatedFrom(
'Tracks')
82 mcpart = track.getRelatedTo(
'MCParticles')
84 pdg = abs(mcpart.getPDG())
85 if pdg != 211
and pdg != 321:
87 momentumVec = mcpart.getMomentum()
88 momentum = momentumVec.Mag()
91 costheta = momentumVec.CosTheta()
92 phi = momentumVec.Phi()
93 fitresult = track.getTrackFitResultWithClosestMass(Belle2.Const.pion)
95 trackmomentum = fitresult.getMomentum().Mag()
100 selectedpart = Belle2.Const.kaon
103 logl_sel = pid.getLogL(selectedpart, pid_dedx)
104 logl_pi = pid.getLogL(Belle2.Const.pion, pid_dedx)
105 dedx_DLL = logl_pi - logl_sel
107 logl_sel = pid.getLogL(selectedpart, pid_top)
108 logl_pi = pid.getLogL(Belle2.Const.pion, pid_top)
109 top_DLL = logl_pi - logl_sel
111 self.
data.lld_dedx = dedx_DLL
112 self.
data.lld_top = top_DLL
113 self.
data.p = momentum
115 self.
data.costheta = costheta
116 self.
data.trackmomentum = trackmomentum
117 self.
data.iskaon = pdg == 321
122 except BaseException:
125 b2.B2WARNING(
'problems with track <-> mcparticle relations')
127 print(f
'event: {int(event)}, track: {int(track.getArrayIndex())}')
130 """ Close the output file."""
138main = b2.create_path()
141main.add_module(b2.register_module(
'RootInput'))
A class for sets of detector IDs whose content is limited to restricted set of valid detector IDs.
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
data
Instance of EventData class.
tree
TTree for output data.