11 from .pull
import PullAnalysis
13 ValidationFiguresOfMerit,
14 ValidationManyFiguresOfMerit
19 getHelixFromMCParticle,
20 TrackingValidationModule
27 ROOT.gSystem.Load(
'libtracking')
28 from ROOT
import Belle2
33 ROOT.genfit.TrackCand.__hash__ =
lambda x: id(x)
38 """Module to collect more matching information about the found particles and to generate validation
39 plots and figures of merit on the performance of track finding. This module gives information on the
40 number of hits etc. """
49 output_file_name=None,
50 track_filter_object=AlwaysPassFilter(),
52 plot_title_postfix=
'',
53 exclude_profile_mc_parameter=
'',
54 exclude_profile_pr_parameter=
'',
55 use_expert_folder=
True,
56 trackCandidatesColumnName=
'RecoTracks',
57 mcTrackCandidatesColumnName=
'MCRecoTracks',
58 cdcHitsColumnName=
'CDCHits',
62 TrackingValidationModule.__init__(
73 exclude_profile_mc_parameter,
74 exclude_profile_pr_parameter,
76 trackCandidatesColumnName,
77 mcTrackCandidatesColumnName)
85 """Receive signal at the start of event processing"""
86 TrackingValidationModule.initialize(self)
136 TrackingValidationModule.event(self)
140 """Classify all of the hits in the event according to the parent track(s)"""
152 for mcTrackCand
in mcTrackCands:
153 cdcHitIDs = [cdcHit.getArrayIndex()
for cdcHit
in mcTrackCand.getCDCHitList()]
155 if len(cdcHitIDs) == 0:
158 cdcHitIDs = set(cdcHitIDs)
159 totalHitListMC.extend(cdcHitIDs)
162 totalHitListMC = set(totalHitListMC)
166 totalHitListPRGood = []
167 totalHitListPRClone = []
168 totalHitListPRFake = []
169 for trackCand
in trackCands:
170 if trackCand.getNumberOfTotalHits() == 0:
171 basf2.B2WARNING(
"Encountered a pattern recognition track with no hits")
174 cdcHitIDs = [cdcHit.getArrayIndex()
for cdcHit
in trackCand.getCDCHitList()]
176 if len(cdcHitIDs) == 0:
179 cdcHitIDs = set(cdcHitIDs)
181 totalHitListPR.extend(cdcHitIDs)
183 totalHitListPRGood.extend(cdcHitIDs)
186 totalHitListPRClone.extend(cdcHitIDs)
190 totalHitListPRFake.extend(cdcHitIDs)
193 totalHitListPR = set(totalHitListPR)
194 totalHitListPRGood = set(totalHitListPRGood)
195 totalHitListPRClone = set(totalHitListPRClone)
196 totalHitListPRFake = set(totalHitListPRFake)
199 totalHitList = set([cdcHit.getArrayIndex()
for cdcHit
in cdcHits])
201 number_of_mc_hits = len(totalHitListMC)
202 number_of_pr_hits = len(totalHitListPR)
203 number_of_all_hits = len(totalHitList)
206 is_hit_found = len(totalHitListMC & totalHitListPR)
208 for trackCand
in trackCands:
213 trackCandHits = [cdcHit.getArrayIndex()
for cdcHit
in trackCand.getCDCHitList()]
215 if len(trackCandHits) == 0:
216 trackCandHits = set()
218 trackCandHits = set(trackCandHits)
221 list_of_connected_mc_tracks = set()
222 list_of_numbers_of_hits_for_connected_tracks = collections.deque()
223 number_of_connected_tracks = 0
224 number_of_wrong_hits = 0
226 for mcTrackCand
in mcTrackCands:
227 mcTrackCandHits = [cdcHit.getArrayIndex()
for cdcHit
in mcTrackCand.getCDCHitList()]
229 if len(mcTrackCandHits) == 0:
230 mcTrackCandHits = set()
232 mcTrackCandHits = set(mcTrackCandHits)
234 length_of_intersection = len(mcTrackCandHits & trackCandHits)
235 if length_of_intersection > 0:
236 list_of_connected_mc_tracks.add(mcTrackCand)
237 list_of_numbers_of_hits_for_connected_tracks.append(length_of_intersection)
239 if len(list_of_numbers_of_hits_for_connected_tracks) == 0:
243 maximum_intersection = \
244 max(list_of_numbers_of_hits_for_connected_tracks)
247 maximum_intersection)
251 if is_matched
or is_clone:
254 mcTrackCandHits = [cdcHit.getArrayIndex()
for cdcHit
in mcTrackCand.getCDCHitList()]
256 if len(mcTrackCandHits) == 0:
257 mcTrackCandHits = set()
259 mcTrackCandHits = set(mcTrackCandHits)
261 is_hit_matched += len(trackCandHits & mcTrackCandHits)
265 for mcTrackCand
in mcTrackCands:
269 mcTrackCandHits = [cdcHit.getArrayIndex()
for cdcHit
in mcTrackCand.getCDCHitList()]
272 if len(mcTrackCandHits) == 0:
275 mcTrackCandHits = set(mcTrackCandHits)
277 ratio = 1.0 * len(mcTrackCandHits & totalHitListPR) / len(mcTrackCandHits)
284 1.0 * len(mcTrackCandHits & totalHitListPRGood) / len(mcTrackCandHits))
286 1.0 * len(mcTrackCandHits & totalHitListPRFake) / len(mcTrackCandHits))
291 mcParticle.hasStatus(Belle2.MCParticle.c_PrimaryParticle)
305 """Receive signal at the end of event processing"""
306 TrackingValidationModule.terminate(self)
310 validation_plots = []
316 quantity_name=
"ratio of hits in MCTracks found by the track finder",
319 profile_parameters={},
322 validation_plots.extend(all_tracks_plot)
326 quantity_name=
"ratio of hits in missing MCTracks found by the track finder",
329 profile_parameters={},
332 validation_plots.extend(missing_tracks_plot)
334 for validation_plot
in validation_plots:
335 validation_plot.write()
339 mc_figures_of_merit = \
342 mc_figures_of_merit[
'mc_pts'] = self.
mc_pts
343 mc_figures_of_merit[
'mc_d0s'] = self.
mc_d0s
344 mc_figures_of_merit[
'mc_matches'] = self.
mc_matches
347 mc_figures_of_merit[
'mc_phis'] = self.
mc_phi
349 mc_figures_of_merit[
'mc_thetas'] = self.
mc_theta
350 mc_figures_of_merit[
'mc_missing'] = self.
mc_missing
353 mc_figures_of_merit[
'ratio_hits_in_mc_tracks_and_in_good_pr_tracks'] = \
355 mc_figures_of_merit[
'ratio_hits_in_mc_tracks_and_in_fake_pr_tracks'] = \
357 mc_figures_of_merit[
'ratio_hits_in_mc_tracks_and_not_in_pr_tracks'] = \
360 mc_figures_of_merit.write()
363 pr_figures_of_merit = \
366 pr_figures_of_merit[
'pr_clones_and_matches'] = \
368 pr_figures_of_merit[
'pr_matches'] = self.
pr_matches
369 pr_figures_of_merit[
'pr_fakes'] = self.
pr_fakes
371 pr_figures_of_merit[
'pr_number_of_matched_hits'] = \
374 pr_figures_of_merit[
'pr_seed_phi'] = self.
pr_seed_phi
377 pr_figures_of_merit[
'number_of_connected_tracks'] = \
381 pr_figures_of_merit.write()
384 hit_figures_of_merit = \
387 hit_figures_of_merit[
'number_of_total_hits'] = \
389 hit_figures_of_merit[
'number_of_mc_hits'] = \
391 hit_figures_of_merit[
'number_of_pr_hits'] = \
393 hit_figures_of_merit[
'is_hit_found'] = np.sum(self.
is_hit_found)
394 hit_figures_of_merit[
'is_hit_matched'] = np.sum(self.
is_hit_matched)
396 print(hit_figures_of_merit)
397 hit_figures_of_merit.write()