Belle II Software development
fullTrackingTableValidationCreateData.py
1#!/usr/bin/env python3
2
3
10
11"""
12<header>
13 <contact>software-tracking@belle2.org</contact>
14 <output>matching_validation.root</output>
15 <input>EvtGenSim.root</input>
16 <description>This module generates events for the validation using the full tracking with a tabular output.</description>
17</header>
18"""
19import basf2
20from ROOT import Belle2
21
22import tracking
23from tracking.harvest.peelers import peel_mc_particle, peel_reco_track_hit_content
24
25from tracking.harvest.harvesting import HarvestingModule
26from tracking.harvest import refiners
27
28ACTIVE = True
29
30
31class VxdCdcPartFinderHarvester(HarvestingModule):
32 """
33 Harvester module to extract the information, if a MCTrack was found by the CDC
34 and/or the VXD tracking reconstruction.
35 """
36
37 def __init__(self, output_file_name):
38 """
39 Init harvester
40 """
41 HarvestingModule.__init__(self, foreach="MCRecoTracks", output_file_name=output_file_name)
42
43
44 self.mc_track_matcher_cdc = Belle2.TrackMatchLookUp("MCRecoTracks", "CDCRecoTracks")
45
46 self.mc_track_matcher_vxd = Belle2.TrackMatchLookUp("MCRecoTracks", "SVDRecoTracks")
47
48 self.mc_track_matcher = Belle2.TrackMatchLookUp("MCRecoTracks", "RecoTracks")
49
50 self.fitted_mc_track_matcher = Belle2.TrackMatchLookUp("MCRecoTracks", "FittedRecoTracks")
51
52 def peel(self, mc_track):
53 """
54 Extract the information.
55 """
56 this_best_track_cdc = self.mc_track_matcher_cdc.getAnyChargeMatchedPRRecoTrack(mc_track)
57 this_best_track_vxd = self.mc_track_matcher_vxd.getAnyChargeMatchedPRRecoTrack(mc_track)
58 # reco_track = self.mc_track_matcher.getAnyChargeMatchedPRRecoTrack(mc_track)
59
60 mc_particle = mc_track.getRelated("MCParticles")
61
62 return_dict = {
63 "vxd_was_found": bool(this_best_track_vxd),
64 "cdc_was_found": bool(this_best_track_cdc),
65 "cdc_has_related": False,
66 "vxd_has_related": False,
67 "both_related": False,
68 }
69
70 if this_best_track_vxd and this_best_track_cdc:
71 return_dict["both_related"] = this_best_track_cdc.getRelated("VXDRecoTracks") == this_best_track_vxd
72
73 if this_best_track_vxd:
74 return_dict["vxd_has_related"] = bool(this_best_track_vxd.getRelated("CDCRecoTracks"))
75 if this_best_track_cdc:
76 return_dict["cdc_has_related"] = bool(this_best_track_cdc.getRelated("VXDRecoTracks"))
77
78 return_dict.update(peel_reco_track_hit_content(mc_track))
79 return_dict.update(peel_mc_particle(mc_particle))
80
81 return_dict.update(dict(
82 is_matched=self.mc_track_matcher.isAnyChargeMatchedMCRecoTrack(mc_track),
83 is_merged=self.mc_track_matcher.isAnyChargeMergedMCRecoTrack(mc_track),
84 is_missing=self.mc_track_matcher.isMissingMCRecoTrack(mc_track),
85 hit_efficiency=self.mc_track_matcher.getRelatedEfficiency(mc_track),
86 ))
87
88 return_dict.update(dict(
89 fitted_is_matched=self.fitted_mc_track_matcher.isAnyChargeMatchedMCRecoTrack(mc_track),
90 fitted_is_merged=self.fitted_mc_track_matcher.isAnyChargeMergedMCRecoTrack(mc_track),
91 fitted_is_missing=self.fitted_mc_track_matcher.isMissingMCRecoTrack(mc_track),
92 fitted_hit_efficiency=self.fitted_mc_track_matcher.getRelatedEfficiency(mc_track),
93 ))
94
95 return return_dict
96
97
99 save_tree = refiners.SaveTreeRefiner()
100
101
102def run():
103 path = basf2.create_path()
104
105 # Read in the pre generated events
106 path.add_module('RootInput', inputFileName='../EvtGenSim.root')
107 path.add_module("Gearbox")
108
109 # Add the tracking reconstruction and store the fitted RecoTracks elsewhere
110 tracking.add_tracking_reconstruction(path, prune_temporary_tracks=False, components=["SVD", "CDC"])
111 path.add_module("FittedTracksStorer", inputRecoTracksStoreArrayName="RecoTracks",
112 outputRecoTracksStoreArrayName="FittedRecoTracks")
113
114 # Also do a matching for all RecoTracks in sub detectors
115 path.add_module(
116 "MCRecoTracksMatcher",
117 UsePXDHits=False,
118 UseSVDHits=False,
119 UseCDCHits=True,
120 mcRecoTracksStoreArrayName="MCRecoTracks",
121 prRecoTracksStoreArrayName="CDCRecoTracks")
122 path.add_module(
123 "MCRecoTracksMatcher",
124 UsePXDHits=True,
125 UseSVDHits=True,
126 UseCDCHits=False,
127 mcRecoTracksStoreArrayName="MCRecoTracks",
128 prRecoTracksStoreArrayName="SVDRecoTracks")
129
130 path.add_module(
131 "MCRecoTracksMatcher",
132 UsePXDHits=True,
133 UseSVDHits=True,
134 UseCDCHits=True,
135 mcRecoTracksStoreArrayName="MCRecoTracks",
136 prRecoTracksStoreArrayName="FittedRecoTracks")
137
138 # Gather the results into ROOT files
139 path.add_module(VxdCdcPartFinderHarvester("../matching_validation.root"))
140
141 path.add_module("Progress")
142 basf2.process(path)
143 print(basf2.statistics)
144
145
146if __name__ == "__main__":
147 if ACTIVE:
148 run()
149 else:
150 print("This validation deactivated and thus basf2 is not executed.\n"
151 "If you want to run this validation, please set the 'ACTIVE' flag above to 'True'.\n"
152 "Exiting.")
Class to provide convenient methods to look up matching information between pattern recognition and M...