14 This module is used
for the SVD validation.
15 It gets information about clusters
and truehits, saving
in a ttree
in a ROOT file.
17 <noexecute>SVD validation helper
class</noexecute>
27from ROOT import Belle2
28from ROOT import gROOT, addressof
31# Define a ROOT struct to hold output data in the TTree
32gROOT.ProcessLine('struct EventDataCluster {\
39 int cluster_truehits_number;\
44 float cluster_position;\
45 float cluster_positionSigma;\
46 float cluster_clsTime;\
47 float cluster_clsTimeSigma;\
48 float cluster_charge;\
49 float cluster_seedCharge;\
52 float cluster_interstripPosition;\
54 float cluster_residual;\
55 float truehit_position;\
56 float truehit_interstripPosition;\
57 float truehit_deposEnergy;\
58 float truehit_lossmomentum;\
67from ROOT
import EventDataCluster
71 '''class to produce the ttree for cluster reconstruction validation'''
74 """Initialize the module"""
79 self.
file = ROOT.TFile(
'../SVDValidationTTreeCluster.root',
'recreate')
81 self.
tree = ROOT.TTree(
'tree',
'Event data of SVD validation events')
83 self.
data = EventDataCluster()
86 for key
in EventDataCluster.__dict__:
89 if isinstance(self.
data.__getattribute__(key), int):
91 self.
tree.Branch(key, addressof(self.
data, key), key + formstring)
94 """ Find clusters with a truehit and save needed information """
99 self.
data.eventt0_all = -1
100 self.
data.eventt0_top = -1
101 self.
data.eventt0_cdc = -1
102 self.
data.eventt0_ecl = -1
103 self.
data.eventt0_svd = -1
108 if eventt0.hasEventT0():
109 self.
data.eventt0_all = eventt0.getEventT0()
110 if eventt0.hasTemporaryEventT0(svd):
111 tmp = eventt0.getTemporaryEventT0s(Belle2.Const.SVD)
112 self.
data.eventt0_svd = tmp.back().eventT0
113 if eventt0.hasTemporaryEventT0(cdc):
114 tmp = eventt0.getTemporaryEventT0s(Belle2.Const.CDC)
115 self.
data.eventt0_cdc = tmp.back().eventT0
116 if eventt0.hasTemporaryEventT0(top):
117 tmp = eventt0.getTemporaryEventT0s(Belle2.Const.TOP)
118 self.
data.eventt0_top = tmp.back().eventT0
119 if eventt0.hasTemporaryEventT0(ecl):
120 evtT0List_ECL = eventt0.getTemporaryEventT0s(Belle2.Const.ECL)
122 smallest_ECL_t0_minChi2 = evtT0List_ECL[0].quality
123 self.
data.eventt0_ecl = evtT0List_ECL[0].eventT0
124 for tmp
in evtT0List_ECL:
125 if tmp.quality < smallest_ECL_t0_minChi2:
126 smallest_ECL_t0_minChi2 = tmp.quality
127 self.
data.eventt0_ecl = tmp.eventT0
129 for cluster
in clusters:
131 cluster_truehits = cluster.getRelationsTo(
'SVDTrueHits')
135 sensorID = cluster.getSensorID()
136 self.
data.sensor_id = int(sensorID)
137 sensorNum = sensorID.getSensorNumber()
138 self.
data.sensor = sensorNum
139 layerNum = sensorID.getLayerNumber()
140 self.
data.layer = layerNum
148 self.
data.sensor_type = sensorType
149 ladderNum = sensorID.getLadderNumber()
150 self.
data.ladder = ladderNum
151 if cluster.isUCluster():
156 self.
data.matched = 1
160 if len(cluster_truehits) == 0:
161 self.
data.matched = 0
170 for i, trueHit
in enumerate(cluster_truehits):
171 if trueHit.getEnergyDep() > energy:
172 energy = trueHit.getEnergyDep()
174 bestTrueHit = cluster_truehits[bestTrueHitIndex]
177 self.
data.cluster_clsTime = cluster.getClsTime()
178 self.
data.cluster_clsTimeSigma = cluster.getClsTimeSigma()
179 self.
data.cluster_charge = cluster.getCharge()
180 self.
data.cluster_seedCharge = cluster.getSeedCharge()
181 self.
data.cluster_size = cluster.getSize()
182 self.
data.cluster_snr = cluster.getSNR()
183 cluster_position = cluster.getPosition()
184 if cluster.isUCluster():
185 cluster_position = cluster.getPosition(bestTrueHit.getV())
187 strip_pitch = sensorInfo.getUPitch(bestTrueHit.getV())
189 strip_pitch = sensorInfo.getVPitch(bestTrueHit.getU())
190 self.
data.strip_dir = strip_dir
191 self.
data.strip_pitch = strip_pitch
192 self.
data.cluster_interstripPosition = cluster_position % strip_pitch / strip_pitch
194 if cluster.isUCluster():
195 uPos = cluster_position
199 vPos = cluster_position
200 localPosition = Math.XYZVector(uPos, vPos, 0)
201 globalPosition = sensorInfo.pointToGlobal(localPosition,
True)
202 x = globalPosition.X()
203 y = globalPosition.Y()
204 z = globalPosition.Z()
207 rho = math.sqrt(x * x + y * y)
208 r = math.sqrt(x * x + y * y + z * z)
210 thetaRadians = math.acos(z / r)
211 theta = (thetaRadians * 180) / math.pi
213 phiRadians = math.acos(x / rho)
215 phi = 360 - (phiRadians * 180) / math.pi
217 phi = (phiRadians * 180) / math.pi
218 self.
data.cluster_theta = theta
219 self.
data.cluster_phi = phi
221 clusterPos = cluster_position
222 clusterPosSigma = cluster.getPositionSigma()
223 if cluster.isUCluster():
224 truehitPos = bestTrueHit.getU()
226 truehitPos = bestTrueHit.getV()
227 cluster_residual = clusterPos - truehitPos
228 cluster_pull = cluster_residual / clusterPosSigma
229 self.
data.cluster_position = clusterPos
230 self.
data.cluster_positionSigma = clusterPosSigma
231 self.
data.cluster_residual = cluster_residual
232 self.
data.cluster_pull = cluster_pull
234 self.
data.truehit_position = truehitPos
235 truehit_interstripPosition = truehitPos % strip_pitch / strip_pitch
236 self.
data.truehit_interstripPosition = truehit_interstripPosition
237 self.
data.truehit_deposEnergy = bestTrueHit.getEnergyDep()
238 self.
data.truehit_lossmomentum = bestTrueHit.getEntryMomentum().R() - bestTrueHit.getExitMomentum().R()
239 self.
data.truehit_time = bestTrueHit.getGlobalTime()
254 """Close the output file. """
The DetectorSet class for sets of detector IDs in the form of EDetector values.
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
static GeoCache & getInstance()
Return a reference to the singleton instance.
data
instance of EventData class
tree
TTree for output data.