30 from ROOT
import Belle2
31 from ROOT
import gROOT, AddressOf
34 gROOT.ProcessLine(
'struct TreeStruct {\
46 from ROOT
import TreeStruct
53 This module writes its output to a ROOT tree.
54 Adapted from pxd/validation/PXDValidationTTreeSimHit.py
58 """Initialize the module"""
60 super(TreeWriterModule, self).
__init__()
63 self.
filefile = ROOT.TFile(
'PID_TTree.root',
'recreate')
65 self.
treetree = ROOT.TTree(
'tree',
'')
67 self.
datadata = TreeStruct()
68 """ Declare tree branches """
69 for key
in TreeStruct.__dict__.keys():
72 if isinstance(self.
datadata.__getattribute__(key), int):
74 self.
treetree.Branch(key, AddressOf(self.
datadata, key), key + formstring)
77 """Store TOP and dE/dx info in tree"""
81 track = pid.getRelatedFrom(
'Tracks')
83 mcpart = track.getRelatedTo(
'MCParticles')
85 pdg = abs(mcpart.getPDG())
86 if pdg != 211
and pdg != 321:
88 momentumVec = mcpart.getMomentum()
89 momentum = momentumVec.Mag()
92 costheta = momentumVec.CosTheta()
93 phi = momentumVec.Phi()
94 fitresult = track.getTrackFitResultWithClosestMass(Belle2.Const.pion)
96 trackmomentum = fitresult.getMomentum().Mag()
101 selectedpart = Belle2.Const.kaon
104 logl_sel = pid.getLogL(selectedpart, pid_dedx)
105 logl_pi = pid.getLogL(Belle2.Const.pion, pid_dedx)
106 dedx_DLL = logl_pi - logl_sel
108 logl_sel = pid.getLogL(selectedpart, pid_top)
109 logl_pi = pid.getLogL(Belle2.Const.pion, pid_top)
110 top_DLL = logl_pi - logl_sel
112 self.
datadata.lld_dedx = dedx_DLL
113 self.
datadata.lld_top = top_DLL
114 self.
datadata.p = momentum
115 self.
datadata.phi = phi
116 self.
datadata.costheta = costheta
117 self.
datadata.trackmomentum = trackmomentum
118 self.
datadata.iskaon = pdg == 321
123 except BaseException:
126 b2.B2WARNING(
'problems with track <-> mcparticle relations')
128 print(
'event: %d, track: %d' % (event, track.getArrayIndex()))
131 """ Close the output file."""
134 self.
filefile.Write()
135 self.
filefile.Close()
139 main = b2.create_path()
142 main.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.