255 def peel(self, segment):
256 """Aggregate the track and MC information for track-segment analysis"""
257
258 mc_segment_lookup = self.mc_segment_lookup
259 mc_hit_lookup = self.mc_hit_lookup
260
262
263 mc_particle = mc_segment_lookup.getMCParticle(segment)
264 mc_particle_crops = peelers.peel_mc_particle(mc_particle)
265
266 fit3d_truth = mc_segment_lookup.getTrajectory3D(segment)
267 curvature_truth = fit3d_truth.getCurvatureXY()
268
269 reconstructed_backward = mc_segment_lookup.isForwardOrBackwardToMCTrack(segment)
270 is_fake = mc_segment_lookup.getMCTrackId(segment) < 0
271
272 if reconstructed_backward != 1:
273 curvature_truth = -curvature_truth
274
275 truth_crops = dict(
276 tan_lambda_truth=fit3d_truth.getTanLambda(),
277 curvature_truth=curvature_truth,
278 abs_curvature_truth=abs(curvature_truth),
279 curvature_residual=segment_crops["curvature_estimate"] - curvature_truth,
280 curvature_pull=(segment_crops["curvature_estimate"] - curvature_truth) / segment_crops["curvature_variance"],
281 reconstructed_backward=reconstructed_backward,
282 is_fake=is_fake
283 )
284
285 rl_sum = 0
286 n_correct = 0
287 n_total = segment.size()
288 first_i_incorrect = float("nan")
289 last_i_incorrect = float("nan")
290 first_l_incorrect = 0
291 last_l_incorrect = 0
292
293 n_rl_switch = 0
294 last_rl_info = 0
295 for i, reco_hit2d in enumerate(segment):
296 rl_info = reco_hit2d.getRLInfo()
297 hit = reco_hit2d.getWireHit().getHit()
298 true_rl_info = mc_hit_lookup.getRLInfo(hit)
299
300 if rl_info != last_rl_info:
301 n_rl_switch += 1
302 last_rl_info = rl_info
303
304 if true_rl_info == rl_info:
305 n_correct += 1
306 else:
307 if first_i_incorrect != first_i_incorrect:
308 first_i_incorrect = i
309 first_l_incorrect = reco_hit2d.getRefDriftLength()
310 last_i_incorrect = i
311 last_l_incorrect = reco_hit2d.getRefDriftLength()
312 if rl_info == 1:
313 rl_sum += 1
314 elif rl_info == -1 or rl_info == 65535:
315 rl_sum -= 1
316
317 alias_score = segment.getAliasScore()
318
319 rl_crops = dict(
320 n_total=n_total,
321 n_correct=n_correct,
322 n_incorrect=n_total - n_correct,
323 rl_purity=n_correct / n_total,
324 first_incorrect_location=first_i_incorrect / (n_total - 1),
325 first_l_incorrect=first_l_incorrect,
326 last_incorrect_location=last_i_incorrect / (n_total - 1),
327 last_l_incorrect=last_l_incorrect,
328 n_rl_switch=n_rl_switch,
329 n_rl_asymmetry=rl_sum / n_total,
330 n_abs_rl_asymmetry=abs(rl_sum) / n_total,
331 may_alias=alias_score == 0,
332 alias_score=alias_score
333 )
334
335 segment_crops.update(truth_crops)
336 segment_crops.update(mc_particle_crops)
337 segment_crops.update(rl_crops)
338 return segment_crops
339
def peel_segment2d(segment, key="{part_name}")