15 This module is used for the SVD validation.
16 It gets information about clusters related to SVDRecoTracks, saving
17 in a ttree in a ROOT file.
19 <noexecute>SVD validation helper class</noexecute>
23 from collections
import OrderedDict
29 from ROOT
import Belle2
30 from ROOT
import gROOT, addressof
33 gROOT.ProcessLine(
'struct EventDataRecoTrack {\
40 int cluster_truehits_number;\
41 float cluster_UVTimeDiff;\
42 float cluster_UUTimeDiff;\
43 float cluster_VVTimeDiff;\
47 from ROOT
import EventDataRecoTrack
51 '''class to create the reco track ttree'''
54 """Initialize the module"""
56 super(SVDValidationTTreeRecoTrack, self).
__init__()
58 self.
filefile = ROOT.TFile(
'../SVDValidationTTreeRecoTrack.root',
'recreate')
60 self.
treetree = ROOT.TTree(
'tree',
'Event data of SVD validation events')
62 self.
datadata = EventDataRecoTrack()
65 for key
in EventDataRecoTrack.__dict__:
68 if isinstance(self.
datadata.__getattribute__(key), int):
70 self.
treetree.Branch(key, addressof(self.
datadata, key), key + formstring)
73 """Take clusters from SVDRecoTracks with at least one truehit and save needed information"""
76 clusters = track.getRelationsWith(
'SVDClusters')
77 clusters_number = len(clusters)
78 dict_cluster = OrderedDict({
'L3': [],
'L4': [],
'L5': [],
'L6': []})
80 for i
in range(0, len(clusters), 2):
81 c_U, c_V = clusters[i], clusters[i + 1]
82 cluster_U_truehits = c_U.getRelationsTo(
'SVDTrueHits')
83 U_id = c_U.getSensorID()
84 sensorNum_U = U_id.getSensorNumber()
85 layer_U = U_id.getLayerNumber()
89 if (sensorNum_U == 1):
93 cluster_U = {
'sensor_id': int(U_id),
94 'layer': U_id.getLayerNumber(),
95 'ladder': U_id.getLadderNumber(),
96 'sensor_type': sensor_type_U,
98 'matched': 1
if len(cluster_U_truehits) > 0
else 0,
99 'cluster_truehits_number': len(cluster_U_truehits),
100 'cluster_clsTime': c_U.getClsTime()
if len(cluster_U_truehits) > 0
else nan,
101 'cluster_UVTimeDiff': nan,
102 'cluster_UUTimeDiff': nan,
103 'cluster_VVTimeDiff': nan,
104 'clusters_number': clusters_number}
105 cluster_V_truehits = c_V.getRelationsTo(
'SVDTrueHits')
106 V_id = c_V.getSensorID()
107 sensorNum_V = V_id.getSensorNumber()
108 layer_V = V_id.getLayerNumber()
112 if (sensorNum_V == 1):
116 cluster_V = {
'sensor_id': int(V_id),
117 'layer': V_id.getLayerNumber(),
118 'ladder': V_id.getLadderNumber(),
119 'sensor_type': sensor_type_V,
121 'matched': 1
if len(cluster_V_truehits) > 0
else 0,
122 'cluster_truehits_number': len(cluster_V_truehits),
123 'cluster_clsTime': c_V.getClsTime()
if len(cluster_V_truehits) > 0
else nan,
124 'cluster_UVTimeDiff': c_U.getClsTime() - c_V.getClsTime()
125 if (len(cluster_U_truehits) > 0)
and (len(cluster_V_truehits) > 0)
else nan,
126 'cluster_UUTimeDiff': nan,
127 'cluster_VVTimeDiff': nan,
128 'clusters_number': clusters_number}
130 if U_id.getLayerNumber() == 3:
131 dict_cluster[
'L3'].append(cluster_U)
132 dict_cluster[
'L3'].append(cluster_V)
133 elif U_id.getLayerNumber() == 4:
134 dict_cluster[
'L4'].append(cluster_U)
135 dict_cluster[
'L4'].append(cluster_V)
136 elif U_id.getLayerNumber() == 5:
137 dict_cluster[
'L5'].append(cluster_U)
138 dict_cluster[
'L5'].append(cluster_V)
139 elif U_id.getLayerNumber() == 6:
140 dict_cluster[
'L6'].append(cluster_U)
141 dict_cluster[
'L6'].append(cluster_V)
143 raise Exception(
'Incorrect number of layer')
145 for (i, layer)
in enumerate(dict_cluster.items()):
146 if i < len(dict_cluster) - 1:
147 next_layer = list(dict_cluster.items())[i + 1]
149 if (layer[0] ==
"L3" and next_layer[0] ==
"L4" and len(layer[1]) != 0
and len(next_layer[1]) != 0)
or \
150 (layer[0] ==
"L4" and next_layer[0] ==
"L5" and len(layer[1]) != 0
and len(next_layer[1]) != 0)
or \
151 (layer[0] ==
"L5" and next_layer[0] ==
"L6" and len(layer[1]) != 0
and len(next_layer[1]) != 0):
152 cluster_UUTimeDiff = \
153 layer[1][0][
'cluster_clsTime'] - next_layer[1][0][
'cluster_clsTime']
154 cluster_VVTimeDiff = \
155 layer[1][1][
'cluster_clsTime'] - next_layer[1][1][
'cluster_clsTime']
156 layer[1][0].update({
'cluster_UUTimeDiff': cluster_UUTimeDiff})
157 layer[1][0].update({
'cluster_VVTimeDiff': nan})
158 layer[1][1].update({
'cluster_UUTimeDiff': nan})
159 layer[1][1].update({
'cluster_VVTimeDiff': cluster_VVTimeDiff})
164 for layer
in dict_cluster.items():
167 self.
datadata.sensor_id = c[
'sensor_id']
168 self.
datadata.layer = c[
'layer']
169 self.
datadata.ladder = c[
'ladder']
170 self.
datadata.sensor_type = c[
'sensor_type']
171 self.
datadata.strip_dir = c[
'strip_dir']
172 self.
datadata.matched = c[
'matched']
173 self.
datadata.cluster_truehits_number = c[
'cluster_truehits_number']
174 self.
datadata.cluster_UVTimeDiff = c[
'cluster_UVTimeDiff']
175 self.
datadata.cluster_UUTimeDiff = c[
'cluster_UUTimeDiff']
176 self.
datadata.cluster_VVTimeDiff = c[
'cluster_VVTimeDiff']
177 self.
datadata.clusters_number = c[
'clusters_number']
179 print(layer[0],
": empty list")
185 """Close the output file. """
187 self.
filefile.Write()
188 self.
filefile.Close()
A (simplified) python wrapper for StoreArray.
data
instance of EventData class