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