Belle II Software development
recorded_data_module.py
1#!/usr/bin/env python3
2
3
10
11
12from ROOT import Belle2
13
14import numpy as np
15
16import tracking.harvest.harvesting as harvesting
17import tracking.harvest.refiners as refiners
18import tracking.harvest.peelers as peelers
19
20
21class EventInfoHarvester(harvesting.HarvestingModule):
22 """
23 Harvester retrieving event level information of reconstructed recorded data.
24 """
25
26 def __init__(self,
27 output_file_name,
28 pxd_clusters_name='PXDClusters',
29 pxd_spacepoints_name="PXDSpacePoints",
30 svd_clusters_name="SVDClusters",
31 svd_spacepoints_name="SVDSpacePoints",
32 cdc_hits_name="CDCHits",
33 reco_tracks_name="RecoTracks",
34 cdc_reco_tracks_name="CDCRecoTracks",
35 svd_cdc_reco_tracks_name="SVDCDCRecoTracks",
36 svd_reco_tracks_name="SVDRecoTracks",
37 pxd_reco_tracks_name="PXDRecoTracks"
38 ):
39 """Expecting a name for the output file"""
40 super().__init__(foreach='EventMetaData',
41 output_file_name=output_file_name,
42 )
43
44
45 self.pxd_clusters_name = pxd_clusters_name
46
47 self.pxd_spacepoints_name = pxd_spacepoints_name
48
49 self.svd_clusters_name = svd_clusters_name
50
51 self.svd_spacepoints_name = svd_spacepoints_name
52
53 self.cdc_hits_name = cdc_hits_name
54
55
56 self.reco_tracks_name = reco_tracks_name
57
58 self.cdc_reco_tracks_name = cdc_reco_tracks_name
59
60 self.svd_cdc_reco_tracks_name = svd_cdc_reco_tracks_name
61
62 self.svd_reco_tracks_name = svd_reco_tracks_name
63
64 self.pxd_reco_tracks_name = pxd_reco_tracks_name
65
66 def peel(self, event_meta_data):
67 """Extract and store counts of *RecoTracks' and hits, clusters, spacepoints"""
68
69 event_crops = peelers.peel_event_info(event_meta_data)
70
71 event_level_tracking_info = Belle2.PyStoreObj("EventLevelTrackingInfo")
72 event_level_tracking_info_crops = peelers.peel_event_level_tracking_info(event_level_tracking_info)
73
74 number_of_hits = dict(
75 **peelers.peel_store_array_size(self.pxd_clusters_name),
76 **peelers.peel_store_array_size(self.pxd_spacepoints_name),
77 **peelers.peel_store_array_size(self.svd_clusters_name),
78 **peelers.peel_store_array_size(self.svd_spacepoints_name),
79 **peelers.peel_store_array_size(self.cdc_hits_name),
80 )
81
82 number_of_tracks = dict(
83 **peelers.peel_store_array_size(self.reco_tracks_name),
84 **peelers.peel_store_array_size(self.cdc_reco_tracks_name),
85 **peelers.peel_store_array_size(self.svd_cdc_reco_tracks_name),
86 **peelers.peel_store_array_size(self.svd_reco_tracks_name),
87 **peelers.peel_store_array_size(self.pxd_reco_tracks_name),
88 )
89
90 module_list = ["SegmentNetworkProducer", "TrackFinderVXDCellOMat"]
91 module_stats = peelers.peel_module_statistics(module_list)
92
93 return dict(**event_crops,
94 **event_level_tracking_info_crops,
95 **number_of_hits,
96 **number_of_tracks,
97 **module_stats,
98 )
99
100
101 save_tree = refiners.SaveTreeRefiner()
102
103
104class TrackInfoHarvester(harvesting.HarvestingModule):
105 """
106 Harvester retrieving track level information of reconstructed recorded data.
107 """
108
109 def __init__(self, output_file_name,
110 reco_tracks_name="RecoTracks",
111 svd_cdc_reco_tracks_name="SVDCDCRecoTracks",
112 svd_reco_tracks_name="SVDRecoTracks",
113 sp_track_cands_name="SPTrackCands"
114 ):
115 """Expecting a name for the output file and the name of the RecoTracks StoreArray
116 to operate on. The latter defaults to 'RecoTracks'"""
117 super().__init__(foreach=reco_tracks_name,
118 output_file_name=output_file_name)
119
120
121 self.svd_cdc_reco_tracks_name = svd_cdc_reco_tracks_name
122
123 self.svd_reco_tracks_name = svd_reco_tracks_name
124
125 self.sp_track_cands_name = sp_track_cands_name
126
127 def peel(self, reco_track):
128 """Extract and store information about each RecoTrack"""
129
130 event_meta_data = Belle2.PyStoreObj("EventMetaData")
131 event_crops = peelers.peel_event_info(event_meta_data)
132
133 # Information on the store array
134 store_array_info = peelers.peel_store_array_info(reco_track)
135
136 # General information on the track
137 reco_track_hit_content = peelers.peel_reco_track_hit_content(reco_track)
138 reco_track_seed = peelers.peel_reco_track_seed(reco_track)
139 fit_status = peelers.peel_fit_status(reco_track)
140
141 # Information on the track fit result
142 related_belle2_track = reco_track.getRelated("Tracks")
143 if related_belle2_track:
144 track_fit_status = peelers.peel_track_fit_result(
145 related_belle2_track.getTrackFitResultWithClosestMass(Belle2.Const.pion))
146 else:
147 track_fit_status = peelers.peel_track_fit_result(None)
148
149 vxdtf2_was_involved = False
150 svd_cdc_reco_track = reco_track.getRelated(self.svd_cdc_reco_tracks_name)
151 if svd_cdc_reco_track:
152 svd_reco_track = svd_cdc_reco_track.getRelated(self.svd_reco_tracks_name)
153 if svd_reco_track:
154 svd_sptcs = svd_reco_track.getRelated(self.sp_track_cands_name)
155 if svd_sptcs:
156 vxdtf2_was_involved = True
157
158 return dict(**reco_track_hit_content,
159 **reco_track_seed,
160 **fit_status,
161 **track_fit_status,
162 **store_array_info,
163 vxdtf2_was_involved=vxdtf2_was_involved,
164 **event_crops,
165 )
166
167
168 save_tree = refiners.SaveTreeRefiner()
169
170
171class HitInfoHarvester(harvesting.HarvestingModule):
172 """
173 Harvester retrieving hit level information of reconstructed recorded data.
174 """
175
176 def __init__(self, output_file_name, reco_tracks_name="RecoTracks"):
177 """Expecting a name for the output file and the name of the RecoTracks StoreArray
178 to operate on. The latter defaults to 'RecoTracks'"""
179 super().__init__(foreach=reco_tracks_name,
180 output_file_name=output_file_name)
181
182 def peel(self, reco_track):
183 """Extract and store information about each RecoTrack's hits"""
184
185 # Event Info
186 event_meta_data = Belle2.PyStoreObj("EventMetaData")
187 event_crops = peelers.peel_event_info(event_meta_data)
188
189 # Information on the store array
190 store_array_info = peelers.peel_store_array_info(reco_track)
191
192 # Getting residuals for each hit of the RecoTrack
193 for hit_info in reco_track.getRelationsWith("RecoHitInformations"):
194 layer = float("nan")
195 if hit_info.getTrackingDetector() == Belle2.RecoHitInformation.c_SVD:
196 hit = hit_info.getRelated("SVDClusters")
197 layer = hit.getSensorID().getLayerNumber()
198 if hit_info.getTrackingDetector() == Belle2.RecoHitInformation.c_PXD:
199 hit = hit_info.getRelated("PXDClusters")
200 layer = hit.getSensorID().getLayerNumber()
201 if hit_info.getTrackingDetector() == Belle2.RecoHitInformation.c_CDC:
202 hit = hit_info.getRelated("CDCHits")
203 layer = hit.getISuperLayer()
204
205 if hit_info.useInFit() and reco_track.hasTrackFitStatus():
206 track_point = reco_track.getCreatedTrackPoint(hit_info)
207 fitted_state = track_point.getFitterInfo()
208 if fitted_state:
209 try:
210 res_info = fitted_state.getResidual()
211 res = np.sqrt(res_info.getState().Norm2Sqr())
212
213 yield dict(**store_array_info,
214 **event_crops,
215 residual=res,
216 tracking_detector=hit_info.getTrackingDetector(),
217 use_in_fit=hit_info.useInFit(),
218 layer_number=layer
219 )
220 except BaseException:
221 pass
222
223
224 save_tree = refiners.SaveTreeRefiner()
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
def __init__(self, output_file_name, pxd_clusters_name='PXDClusters', pxd_spacepoints_name="PXDSpacePoints", svd_clusters_name="SVDClusters", svd_spacepoints_name="SVDSpacePoints", cdc_hits_name="CDCHits", reco_tracks_name="RecoTracks", cdc_reco_tracks_name="CDCRecoTracks", svd_cdc_reco_tracks_name="SVDCDCRecoTracks", svd_reco_tracks_name="SVDRecoTracks", pxd_reco_tracks_name="PXDRecoTracks")
svd_cdc_reco_tracks_name
cached value of the SVDCDCRecoTracks StoreArray
def __init__(self, output_file_name, reco_tracks_name="RecoTracks")
def __init__(self, output_file_name, reco_tracks_name="RecoTracks", svd_cdc_reco_tracks_name="SVDCDCRecoTracks", svd_reco_tracks_name="SVDRecoTracks", sp_track_cands_name="SPTrackCands")
svd_cdc_reco_tracks_name
cached value of the SVDCDCRecoTracks StoreArray