14 This module is used
for the SVD validation.
15 It gets information about clusters related to SVDRecoTracks, saving
16 in a ttree
in a ROOT file.
18 <noexecute>SVD validation helper
class</noexecute>
22from collections import OrderedDict
28from ROOT import Belle2
29from ROOT import gROOT, addressof
31# Define a ROOT struct to hold output data in the TTree
32gROOT.ProcessLine('struct EventDataRecoTrack {\
39 int cluster_truehits_number;\
40 float cluster_UVTimeDiff;\
41 float cluster_UUTimeDiff;\
42 float cluster_VVTimeDiff;\
45from ROOT
import EventDataRecoTrack
49 '''class to create the reco track ttree'''
52 """Initialize the module"""
56 self.
file = ROOT.TFile(
'../SVDValidationTTreeRecoTrack.root',
'recreate')
58 self.
tree = ROOT.TTree(
'tree',
'Event data of SVD validation events')
60 self.
data = EventDataRecoTrack()
63 for key
in EventDataRecoTrack.__dict__:
66 if isinstance(self.
data.__getattribute__(key), int):
68 self.
tree.Branch(key, addressof(self.
data, key), key + formstring)
71 """Take clusters from SVDRecoTracks with at least one truehit and save needed information"""
74 clusters = track.getRelationsWith(
'SVDClusters')
75 clusters_number = len(clusters)
76 dict_cluster = OrderedDict({
'L3': [],
'L4': [],
'L5': [],
'L6': []})
78 for i
in range(0, len(clusters), 2):
79 c_U, c_V = clusters[i], clusters[i + 1]
80 cluster_U_truehits = c_U.getRelationsTo(
'SVDTrueHits')
81 U_id = c_U.getSensorID()
82 sensorNum_U = U_id.getSensorNumber()
83 layer_U = U_id.getLayerNumber()
87 if (sensorNum_U == 1):
91 cluster_U = {
'sensor_id': int(U_id),
92 'layer': U_id.getLayerNumber(),
93 'ladder': U_id.getLadderNumber(),
94 'sensor_type': sensor_type_U,
96 'matched': 1
if len(cluster_U_truehits) > 0
else 0,
97 'cluster_truehits_number': len(cluster_U_truehits),
98 'cluster_clsTime': c_U.getClsTime()
if len(cluster_U_truehits) > 0
else nan,
99 'cluster_UVTimeDiff': nan,
100 'cluster_UUTimeDiff': nan,
101 'cluster_VVTimeDiff': nan,
102 'clusters_number': clusters_number}
103 cluster_V_truehits = c_V.getRelationsTo(
'SVDTrueHits')
104 V_id = c_V.getSensorID()
105 sensorNum_V = V_id.getSensorNumber()
106 layer_V = V_id.getLayerNumber()
110 if (sensorNum_V == 1):
114 cluster_V = {
'sensor_id': int(V_id),
115 'layer': V_id.getLayerNumber(),
116 'ladder': V_id.getLadderNumber(),
117 'sensor_type': sensor_type_V,
119 'matched': 1
if len(cluster_V_truehits) > 0
else 0,
120 'cluster_truehits_number': len(cluster_V_truehits),
121 'cluster_clsTime': c_V.getClsTime()
if len(cluster_V_truehits) > 0
else nan,
122 'cluster_UVTimeDiff': c_U.getClsTime() - c_V.getClsTime()
123 if (len(cluster_U_truehits) > 0)
and (len(cluster_V_truehits) > 0)
else nan,
124 'cluster_UUTimeDiff': nan,
125 'cluster_VVTimeDiff': nan,
126 'clusters_number': clusters_number}
128 if U_id.getLayerNumber() == 3:
129 dict_cluster[
'L3'].append(cluster_U)
130 dict_cluster[
'L3'].append(cluster_V)
131 elif U_id.getLayerNumber() == 4:
132 dict_cluster[
'L4'].append(cluster_U)
133 dict_cluster[
'L4'].append(cluster_V)
134 elif U_id.getLayerNumber() == 5:
135 dict_cluster[
'L5'].append(cluster_U)
136 dict_cluster[
'L5'].append(cluster_V)
137 elif U_id.getLayerNumber() == 6:
138 dict_cluster[
'L6'].append(cluster_U)
139 dict_cluster[
'L6'].append(cluster_V)
141 raise Exception(
'Incorrect number of layer')
143 for (i, layer)
in enumerate(dict_cluster.items()):
144 if i < len(dict_cluster) - 1:
145 next_layer = list(dict_cluster.items())[i + 1]
147 if (layer[0] ==
"L3" and next_layer[0] ==
"L4" and len(layer[1]) != 0
and len(next_layer[1]) != 0)
or \
148 (layer[0] ==
"L4" and next_layer[0] ==
"L5" and len(layer[1]) != 0
and len(next_layer[1]) != 0)
or \
149 (layer[0] ==
"L5" and next_layer[0] ==
"L6" and len(layer[1]) != 0
and len(next_layer[1]) != 0):
150 cluster_UUTimeDiff = \
151 layer[1][0][
'cluster_clsTime'] - next_layer[1][0][
'cluster_clsTime']
152 cluster_VVTimeDiff = \
153 layer[1][1][
'cluster_clsTime'] - next_layer[1][1][
'cluster_clsTime']
154 layer[1][0].update({
'cluster_UUTimeDiff': cluster_UUTimeDiff})
155 layer[1][0].update({
'cluster_VVTimeDiff': nan})
156 layer[1][1].update({
'cluster_UUTimeDiff': nan})
157 layer[1][1].update({
'cluster_VVTimeDiff': cluster_VVTimeDiff})
162 for layer
in dict_cluster.items():
165 self.
data.sensor_id = c[
'sensor_id']
166 self.
data.layer = c[
'layer']
167 self.
data.ladder = c[
'ladder']
168 self.
data.sensor_type = c[
'sensor_type']
169 self.
data.strip_dir = c[
'strip_dir']
170 self.
data.matched = c[
'matched']
171 self.
data.cluster_truehits_number = c[
'cluster_truehits_number']
172 self.
data.cluster_UVTimeDiff = c[
'cluster_UVTimeDiff']
173 self.
data.cluster_UUTimeDiff = c[
'cluster_UUTimeDiff']
174 self.
data.cluster_VVTimeDiff = c[
'cluster_VVTimeDiff']
175 self.
data.clusters_number = c[
'clusters_number']
177 print(layer[0],
": empty list")
183 """Close the output file. """
A (simplified) python wrapper for StoreArray.
data
instance of EventData class