15 ValidationFiguresOfMerit,
16 ValidationManyFiguresOfMerit
21 TrackingValidationModule
30from ROOT
import Belle2
32ROOT.gSystem.Load(
'libtracking')
36ROOT.genfit.TrackCand.__hash__ =
lambda x: id(x)
41 """Module to collect more matching information about the found particles and to generate validation
42 plots and figures of merit on the performance of track finding. This module gives information on the
43 number of hits etc.
"""
52 output_file_name=None,
53 track_filter_object=AlwaysPassFilter(),
55 plot_title_postfix=
'',
56 exclude_profile_mc_parameter=
'',
57 exclude_profile_pr_parameter=
'',
58 use_expert_folder=
True,
59 trackCandidatesColumnName=
'RecoTracks',
60 mcTrackCandidatesColumnName=
'MCRecoTracks',
61 cdcHitsColumnName=
'CDCHits',
65 TrackingValidationModule.__init__(
76 exclude_profile_mc_parameter,
77 exclude_profile_pr_parameter,
79 trackCandidatesColumnName,
80 mcTrackCandidatesColumnName)
88 """Receive signal at the start of event processing"""
89 TrackingValidationModule.initialize(self)
139 TrackingValidationModule.event(self)
143 """Classify all of the hits in the event according to the parent track(s)"""
155 for mcTrackCand
in mcTrackCands:
156 cdcHitIDs = [cdcHit.getArrayIndex()
for cdcHit
in getObjectList(mcTrackCand.getCDCHitList())]
158 if len(cdcHitIDs) == 0:
161 cdcHitIDs = set(cdcHitIDs)
162 totalHitListMC.extend(cdcHitIDs)
165 totalHitListMC = set(totalHitListMC)
169 totalHitListPRGood = []
170 totalHitListPRClone = []
171 totalHitListPRFake = []
172 for trackCand
in trackCands:
173 if trackCand.getNumberOfTotalHits() == 0:
174 basf2.B2WARNING(
"Encountered a pattern recognition track with no hits")
177 cdcHitIDs = [cdcHit.getArrayIndex()
for cdcHit
in getObjectList(trackCand.getCDCHitList())]
179 if len(cdcHitIDs) == 0:
182 cdcHitIDs = set(cdcHitIDs)
184 totalHitListPR.extend(cdcHitIDs)
186 totalHitListPRGood.extend(cdcHitIDs)
189 totalHitListPRClone.extend(cdcHitIDs)
193 totalHitListPRFake.extend(cdcHitIDs)
196 totalHitListPR = set(totalHitListPR)
197 totalHitListPRGood = set(totalHitListPRGood)
198 totalHitListPRClone = set(totalHitListPRClone)
199 totalHitListPRFake = set(totalHitListPRFake)
202 totalHitList = {cdcHit.getArrayIndex()
for cdcHit
in cdcHits}
204 number_of_mc_hits = len(totalHitListMC)
205 number_of_pr_hits = len(totalHitListPR)
206 number_of_all_hits = len(totalHitList)
209 is_hit_found = len(totalHitListMC & totalHitListPR)
211 for trackCand
in trackCands:
216 trackCandHits = [cdcHit.getArrayIndex()
for cdcHit
in getObjectList(trackCand.getCDCHitList())]
218 if len(trackCandHits) == 0:
219 trackCandHits = set()
221 trackCandHits = set(trackCandHits)
224 list_of_connected_mc_tracks = set()
225 list_of_numbers_of_hits_for_connected_tracks = collections.deque()
229 for mcTrackCand
in mcTrackCands:
230 mcTrackCandHits = [cdcHit.getArrayIndex()
for cdcHit
in getObjectList(mcTrackCand.getCDCHitList())]
232 if len(mcTrackCandHits) == 0:
233 mcTrackCandHits = set()
235 mcTrackCandHits = set(mcTrackCandHits)
237 length_of_intersection = len(mcTrackCandHits & trackCandHits)
238 if length_of_intersection > 0:
239 list_of_connected_mc_tracks.add(mcTrackCand)
240 list_of_numbers_of_hits_for_connected_tracks.append(length_of_intersection)
242 if len(list_of_numbers_of_hits_for_connected_tracks) == 0:
246 maximum_intersection = \
247 max(list_of_numbers_of_hits_for_connected_tracks)
250 maximum_intersection)
254 if is_matched
or is_clone:
257 mcTrackCandHits = [cdcHit.getArrayIndex()
for cdcHit
in getObjectList(mcTrackCand.getCDCHitList())]
259 if len(mcTrackCandHits) == 0:
260 mcTrackCandHits = set()
262 mcTrackCandHits = set(mcTrackCandHits)
264 is_hit_matched += len(trackCandHits & mcTrackCandHits)
268 for mcTrackCand
in mcTrackCands:
272 mcTrackCandHits = [cdcHit.getArrayIndex()
for cdcHit
in getObjectList(mcTrackCand.getCDCHitList())]
275 if len(mcTrackCandHits) == 0:
278 mcTrackCandHits = set(mcTrackCandHits)
280 ratio = 1.0 * len(mcTrackCandHits & totalHitListPR) / len(mcTrackCandHits)
287 1.0 * len(mcTrackCandHits & totalHitListPRGood) / len(mcTrackCandHits))
289 1.0 * len(mcTrackCandHits & totalHitListPRFake) / len(mcTrackCandHits))
294 mcParticle.hasStatus(Belle2.MCParticle.c_PrimaryParticle)
308 """Receive signal at the end of event processing"""
309 TrackingValidationModule.terminate(self)
313 validation_plots = []
319 quantity_name=
"ratio of hits in MCTracks found by the track finder",
322 profile_parameters={},
325 validation_plots.extend(all_tracks_plot)
329 quantity_name=
"ratio of hits in missing MCTracks found by the track finder",
332 profile_parameters={},
335 validation_plots.extend(missing_tracks_plot)
337 for validation_plot
in validation_plots:
338 validation_plot.write()
342 mc_figures_of_merit = \
345 mc_figures_of_merit[
'mc_pts'] = self.
mc_pts
346 mc_figures_of_merit[
'mc_d0s'] = self.
mc_d0s
347 mc_figures_of_merit[
'mc_matches'] = self.
mc_matches
350 mc_figures_of_merit[
'mc_phis'] = self.
mc_phi
352 mc_figures_of_merit[
'mc_missing'] = self.
mc_missing
355 mc_figures_of_merit[
'ratio_hits_in_mc_tracks_and_in_good_pr_tracks'] = \
357 mc_figures_of_merit[
'ratio_hits_in_mc_tracks_and_in_fake_pr_tracks'] = \
359 mc_figures_of_merit[
'ratio_hits_in_mc_tracks_and_not_in_pr_tracks'] = \
362 mc_figures_of_merit.write()
365 pr_figures_of_merit = \
368 pr_figures_of_merit[
'pr_clones_and_matches'] = \
370 pr_figures_of_merit[
'pr_matches'] = self.
pr_matches
371 pr_figures_of_merit[
'pr_fakes'] = self.
pr_fakes
373 pr_figures_of_merit[
'pr_number_of_matched_hits'] = \
376 pr_figures_of_merit[
'pr_seed_phi'] = self.
pr_seed_phi
378 pr_figures_of_merit[
'number_of_connected_tracks'] = \
382 pr_figures_of_merit.write()
385 hit_figures_of_merit = \
388 hit_figures_of_merit[
'number_of_total_hits'] = \
390 hit_figures_of_merit[
'number_of_mc_hits'] = \
392 hit_figures_of_merit[
'number_of_pr_hits'] = \
394 hit_figures_of_merit[
'is_hit_found'] = np.sum(self.
is_hit_found)
395 hit_figures_of_merit[
'is_hit_matched'] = np.sum(self.
is_hit_matched)
397 print(hit_figures_of_merit)
398 hit_figures_of_merit.write()
A (simplified) python wrapper for StoreArray.
static std::vector< std::string > list(DataStore::EDurability durability=DataStore::EDurability::c_Event)
Return list of available arrays for given durability.
ratio_hits_in_mc_tracks_and_in_pr_tracks
list of fraction of number of hits in MC track and in PR track
pr_number_of_hits
list of the number of pattern-reconstructed hits
mc_is_primary
list of flags indicating that the MC track is [not] a primary MCParticle
ratio_hits_in_missing_mc_tracks_and_in_pr_tracks
list of fraction of number of hits in missing MC track and in PR track
number_of_total_hits
number of all hits
ratio_hits_in_mc_tracks_and_in_good_pr_tracks
list of fraction of number of hits in MC track and in good PR track
def __init__(self, name, contact, fit=False, pulls=False, resolution=False, output_file_name=None, track_filter_object=AlwaysPassFilter(), plot_name_postfix='', plot_title_postfix='', exclude_profile_mc_parameter='', exclude_profile_pr_parameter='', use_expert_folder=True, trackCandidatesColumnName='RecoTracks', mcTrackCandidatesColumnName='MCRecoTracks', cdcHitsColumnName='CDCHits', write_tables=False)
mc_number_of_hits
list of the number of MCTrackCandHits on the MC track
number_of_connected_tracks
This is the number of mcTrackCands sharing a hit with the track cand.
ratio_hits_in_mc_tracks_and_not_in_pr_tracks
list of fraction of number of hits in MC track but not in PR track
write_tables
cached value of the flag to write the validation figures of merit
number_of_wrong_hits
This number gives information about the "badness" of the fake.
number_of_pr_hits
number of hits on pattern reconstructed tracks
is_hit_found
list of flags for [not-]found hits
def examine_hits_in_event(self)
cdcHitsColumnname
cached name of the CDCHits StoreArray
pr_number_of_matched_hits
list of the number of pattern-reconstructed hits matched to MC track
ratio_hits_in_mc_tracks_and_in_fake_pr_tracks
list of fraction of number of hits in MC track and in fake PR track
is_hit_matched
list of flags for [not-]matched hits
number_of_mc_hits
number of hits on MC track
mc_missing
list of flags where MCRecoTrack is [not] missing MCTrackCand
mc_d0s
list of MC-track d0 values
pr_seed_tan_lambdas
list of PR-track seed tan(lambda) values
pr_fakes
list of PR-track fakes
pr_matches
list of PR-track matches
trackCandidatesColumnName
cached name of the RecoTracks StoreArray
pr_seed_phi
list of PR-track seed phi values
output_file_name
cached value of the output ROOT TFile
trackMatchLookUp
Track-match object that examines relation information from MCMatcherTracksModule.
mc_pts
list of MC-track pt values
mc_multiplicities
list of MC-track multiplicities
mc_matches
list of MC-track matches
pr_clones_and_matches
Use dequeues in favour of lists to prevent repeated memory allocation of cost O(n)
mc_phi
direction of the track in phi
mcTrackCandidatesColumnName
cached name of the MCRecoTracks StoreArray
mc_tan_lambdas
list of MC-track tan(lambda) values
mc_hit_efficiencies
list of MC-track hit efficiencies
def profiles_by_parameters_base(self, xs, quantity_name, parameter_names, profile_parameters, unit, make_hist, weights=None, is_asymmetry=False)