71 def event(self):
72 """Take clusters from SVDRecoTracks with at least one truehit and save needed information"""
74 for track in tracks:
75 clusters = track.getRelationsWith('SVDClusters')
76 clusters_number = len(clusters)
77 dict_cluster = OrderedDict({'L3': [], 'L4': [], 'L5': [], 'L6': []})
78
79 for i in range(0, len(clusters), 2):
80 c_U, c_V = clusters[i], clusters[i + 1]
81 cluster_U_truehits = c_U.getRelationsTo('SVDTrueHits')
82 U_id = c_U.getSensorID()
83 sensorNum_U = U_id.getSensorNumber()
84 layer_U = U_id.getLayerNumber()
85 if (layer_U == 3):
86 sensor_type_U = 1
87 else:
88 if (sensorNum_U == 1):
89 sensor_type_U = 0
90 else:
91 sensor_type_U = 1
92 cluster_U = {'sensor_id': int(U_id),
93 'layer': U_id.getLayerNumber(),
94 'ladder': U_id.getLadderNumber(),
95 'sensor_type': sensor_type_U,
96 'strip_dir': 0,
97 'matched': 1 if len(cluster_U_truehits) > 0 else 0,
98 'cluster_truehits_number': len(cluster_U_truehits),
99 'cluster_clsTime': c_U.getClsTime() if len(cluster_U_truehits) > 0 else nan,
100 'cluster_UVTimeDiff': nan,
101 'cluster_UUTimeDiff': nan,
102 'cluster_VVTimeDiff': nan,
103 'clusters_number': clusters_number}
104 cluster_V_truehits = c_V.getRelationsTo('SVDTrueHits')
105 V_id = c_V.getSensorID()
106 sensorNum_V = V_id.getSensorNumber()
107 layer_V = V_id.getLayerNumber()
108 if (layer_V == 3):
109 sensor_type_V = 1
110 else:
111 if (sensorNum_V == 1):
112 sensor_type_V = 0
113 else:
114 sensor_type_V = 1
115 cluster_V = {'sensor_id': int(V_id),
116 'layer': V_id.getLayerNumber(),
117 'ladder': V_id.getLadderNumber(),
118 'sensor_type': sensor_type_V,
119 'strip_dir': 1,
120 'matched': 1 if len(cluster_V_truehits) > 0 else 0,
121 'cluster_truehits_number': len(cluster_V_truehits),
122 'cluster_clsTime': c_V.getClsTime() if len(cluster_V_truehits) > 0 else nan,
123 'cluster_UVTimeDiff': c_U.getClsTime() - c_V.getClsTime()
124 if (len(cluster_U_truehits) > 0) and (len(cluster_V_truehits) > 0) else nan,
125 'cluster_UUTimeDiff': nan,
126 'cluster_VVTimeDiff': nan,
127 'clusters_number': clusters_number}
128
129 if U_id.getLayerNumber() == 3:
130 dict_cluster['L3'].append(cluster_U)
131 dict_cluster['L3'].append(cluster_V)
132 elif U_id.getLayerNumber() == 4:
133 dict_cluster['L4'].append(cluster_U)
134 dict_cluster['L4'].append(cluster_V)
135 elif U_id.getLayerNumber() == 5:
136 dict_cluster['L5'].append(cluster_U)
137 dict_cluster['L5'].append(cluster_V)
138 elif U_id.getLayerNumber() == 6:
139 dict_cluster['L6'].append(cluster_U)
140 dict_cluster['L6'].append(cluster_V)
141 else:
142 raise Exception('Incorrect number of layer')
143
144 for (i, layer) in enumerate(dict_cluster.items()):
145 if i < len(dict_cluster) - 1:
146 next_layer = list(dict_cluster.items())[i + 1]
147
148 if (layer[0] == "L3" and next_layer[0] == "L4" and len(layer[1]) != 0 and len(next_layer[1]) != 0) or \
149 (layer[0] == "L4" and next_layer[0] == "L5" and len(layer[1]) != 0 and len(next_layer[1]) != 0) or \
150 (layer[0] == "L5" and next_layer[0] == "L6" and len(layer[1]) != 0 and len(next_layer[1]) != 0):
151 cluster_UUTimeDiff = \
152 layer[1][0]['cluster_clsTime'] - next_layer[1][0]['cluster_clsTime']
153 cluster_VVTimeDiff = \
154 layer[1][1]['cluster_clsTime'] - next_layer[1][1]['cluster_clsTime']
155 layer[1][0].update({'cluster_UUTimeDiff': cluster_UUTimeDiff})
156 layer[1][0].update({'cluster_VVTimeDiff': nan})
157 layer[1][1].update({'cluster_UUTimeDiff': nan})
158 layer[1][1].update({'cluster_VVTimeDiff': cluster_VVTimeDiff})
159 else:
160
161 continue
162
163 for layer in dict_cluster.items():
164 for c in layer[1]:
165 if len(c) != 0:
166 self.data.sensor_id = c['sensor_id']
167 self.data.layer = c['layer']
168 self.data.ladder = c['ladder']
169 self.data.sensor_type = c['sensor_type']
170 self.data.strip_dir = c['strip_dir']
171 self.data.matched = c['matched']
172 self.data.cluster_truehits_number = c['cluster_truehits_number']
173 self.data.cluster_UVTimeDiff = c['cluster_UVTimeDiff']
174 self.data.cluster_UUTimeDiff = c['cluster_UUTimeDiff']
175 self.data.cluster_VVTimeDiff = c['cluster_VVTimeDiff']
176 self.data.clusters_number = c['clusters_number']
177 else:
178 print(layer[0], ": empty list")
179
180 self.file.cd()
181 self.tree.Fill()
182
A (simplified) python wrapper for StoreArray.