Belle II Software development
SegmentFitValidationModule Class Reference
Inheritance diagram for SegmentFitValidationModule:

Public Member Functions

def __init__ (self, output_file_name)
 
def initialize (self)
 
def prepare (self)
 
def pick (self, segment)
 
def peel (self, segment)
 

Public Attributes

 mc_segment_lookup
 by default, there is no method to find matching MC track segments
 
 mc_hit_lookup
 Method to find matching MC hits.
 

Static Public Attributes

refiners save_histograms = refiners.save_histograms(outlier_z_score=5.0, allow_discrete=True)
 Save histograms in a sub folder.
 
refiners save_tree = refiners.save_tree()
 Save a tree of all collected variables in a sub folder.
 
refiners save_curvature_pull
 Save curvature-pull information in a sub folder.
 
refiners save_curvature_pull_rl_pure
 Save right-left curvature-pull information in a sub folder.
 
refiners save_absolute_curvature_pull
 Save absolute curvature-pull information in a sub folder.
 
refiners save_fit_quality_histograms
 Save fit-quality histograms in a sub folder.
 

Detailed Description

Module to collect information about the generated segments and
compose validation plots on terminate.

Definition at line 224 of file record.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  output_file_name 
)
Constructor

Definition at line 229 of file record.py.

229 def __init__(self, output_file_name):
230 """Constructor"""
231 super().__init__(foreach='CDCSegment2DVector',
232 output_file_name=output_file_name)
233
234
235 self.mc_segment_lookup = None
236

Member Function Documentation

◆ initialize()

def initialize (   self)
Receive signal at the start of event processing

Definition at line 237 of file record.py.

237 def initialize(self):
238 """Receive signal at the start of event processing"""
239 super().initialize()
240
241
243
245
static const CDCMCHitLookUp & getInstance()
Getter for the singletone instance.
static const CDCMCSegment2DLookUp & getInstance()
Getter for the singletone instance.

◆ peel()

def peel (   self,
  segment 
)
Aggregate the track and MC information for track-segment analysis

Definition at line 258 of file record.py.

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
264 segment_crops = cdc_peelers.peel_segment2d(segment)
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: # <- The root interface mistakes the signed enum value for an unsigned value
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}")
Definition: cdc_peelers.py:14

◆ pick()

def pick (   self,
  segment 
)
Select segments with 4 or more hits and a matching primary MC particle

Definition at line 250 of file record.py.

250 def pick(self, segment):
251 """Select segments with 4 or more hits and a matching primary MC particle"""
252 mc_segment_lookup = self.mc_segment_lookup
253 mc_particle = mc_segment_lookup.getMCParticle(segment)
254
255 # Check that mc_particle is not a nullptr
256 return mc_particle and is_primary(mc_particle) and segment.size() > 3
257

◆ prepare()

def prepare (   self)
Initialize the MC-hit lookup method

Definition at line 246 of file record.py.

246 def prepare(self):
247 """Initialize the MC-hit lookup method"""
249

Member Data Documentation

◆ mc_hit_lookup

mc_hit_lookup

Method to find matching MC hits.

Definition at line 244 of file record.py.

◆ mc_segment_lookup

mc_segment_lookup

by default, there is no method to find matching MC track segments

Method to find matching MC track segments.

Definition at line 235 of file record.py.

◆ save_absolute_curvature_pull

refiners save_absolute_curvature_pull
static
Initial value:
= refiners.save_pull_analysis(
part_name="curvature",
unit="1/cm",
absolute=True,
aux_names=["tan_lambda_truth", "abs_curvature_truth"],
groupby=[
"stereo_kind",
"superlayer_id"
],
outlier_z_score=4.0,
title_postfix="")

Save absolute curvature-pull information in a sub folder.

Definition at line 380 of file record.py.

◆ save_curvature_pull

refiners save_curvature_pull
static
Initial value:
= refiners.save_pull_analysis(
part_name="curvature",
unit="1/cm",
absolute=False,
aux_names=["tan_lambda_truth", "abs_curvature_truth"],
groupby=[
"stereo_kind",
"superlayer_id"
],
outlier_z_score=4.0,
title_postfix="")

Save curvature-pull information in a sub folder.

Definition at line 350 of file record.py.

◆ save_curvature_pull_rl_pure

refiners save_curvature_pull_rl_pure
static
Initial value:
= refiners.save_pull_analysis(
part_name="curvature",
unit="1/cm",
absolute=True,
filter_on="rl_purity",
filter=lambda rl_purity: rl_purity > 0.5,
aux_names=["tan_lambda_truth", "abs_curvature_truth"],
groupby=[
"stereo_kind",
"superlayer_id"
],
outlier_z_score=4.0,
title_postfix="",
folder_name="rl_pure/{groupby_addition}"
)

Save right-left curvature-pull information in a sub folder.

Definition at line 363 of file record.py.

◆ save_fit_quality_histograms

refiners save_fit_quality_histograms
static
Initial value:
= refiners.save_histograms(
outlier_z_score=5.0,
select={
"ndf": "ndf",
"chi2": "#chi2",
"p_value": "p-value",
"tan_lambda_truth": "true tan #lambda",
},
groupby=[None, "stereo_kind", "superlayer_id"],
title="Histogram of {part_name}{stacked_by_indication}{stackby}",
description="Distribution of {part_name} in the segment fits",
)

Save fit-quality histograms in a sub folder.

Definition at line 393 of file record.py.

◆ save_histograms

refiners save_histograms = refiners.save_histograms(outlier_z_score=5.0, allow_discrete=True)
static

Save histograms in a sub folder.

Definition at line 345 of file record.py.

◆ save_tree

refiners save_tree = refiners.save_tree()
static

Save a tree of all collected variables in a sub folder.

Definition at line 347 of file record.py.


The documentation for this class was generated from the following file: