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