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