12 from ROOT
import Belle2
19 """ Harvester module to check for the reconstructed positions """
21 def __init__(self, output_file_name, tracks_store_vector_name="CDCTrackVector"):
22 """ Initiialize with the output file name of the root file and the store obj with the
23 CDCTrack vector to use. MC track cands are needed. """
25 ReconstructionPositionHarvester,
27 foreach=tracks_store_vector_name,
28 output_file_name=output_file_name)
33 def peel(self, track_cand):
34 """ Extract the information """
38 sum_of_difference_norms_stereo = 0
40 sum_of_difference_norms_axial = 0
43 number_of_wrong_rl_infos = 0
45 for reco_hit3D
in list(track_cand.items()):
46 underlaying_cdc_hit = reco_hit3D.getWireHit().getHit()
47 hit_difference = mc_hit_lookup.getRecoPos3D(underlaying_cdc_hit) - reco_hit3D.getRecoPos3D()
48 sum_of_difference_norms_axial += hit_difference.xy().norm()
51 if reco_hit3D.getStereoType() != 0:
52 sum_of_difference_norms_stereo += abs(hit_difference.z())
55 correct_rl_info = mc_hit_lookup.getRLInfo(underlaying_cdc_hit)
57 if correct_rl_info != reco_hit3D.getRLInfo():
58 number_of_wrong_rl_infos += 1
60 return dict(sum_of_difference_norms_axial=sum_of_difference_norms_axial,
61 num_norms_axial=num_norms_axial,
62 mean_of_difference_norms_axial=np.true_divide(sum_of_difference_norms_axial, num_norms_axial),
63 sum_of_difference_norms_stereo=sum_of_difference_norms_stereo,
64 num_norms_stereo=num_norms_stereo,
65 mean_of_difference_norms_stereo=np.true_divide(sum_of_difference_norms_stereo, num_norms_stereo),
66 number_of_wrong_rl_infos=number_of_wrong_rl_infos,
67 mean_wrong_rl_infos=np.true_divide(number_of_wrong_rl_infos, num_norms_stereo))
71 save_tree = refiners.save_tree(
81 Harvester module to check for the correct reconstructed orientation.
84 def __init__(self, output_file_name, tracks_store_vector_name="TrackCands"):
86 Initialize with the root output file name and the store array name of the track cands to use.
88 HarvestingModule.__init__(self,
89 foreach=tracks_store_vector_name,
90 output_file_name=output_file_name)
95 def peel(self, track_cand):
96 """ Extract the information. """
102 number_of_wrong_rl_infos = 0
103 number_of_wrong_rl_infos_stereo_only = 0
108 for hitID
in range(track_cand.getNHits()):
109 hit = track_cand.getHit(hitID)
110 if not hit.__class__.__name__ ==
"genfit::WireTrackCandHit":
113 underlaying_cdc_hit = cdc_hits[hit.getHitId()]
115 correct_rl_info = mc_hit_lookup.getRLInfo(underlaying_cdc_hit)
119 if underlaying_cdc_hit.getISuperLayer() % 2 != 0:
120 number_of_stereo += 1
122 if correct_rl_info != hit.getLeftRightResolution():
123 if underlaying_cdc_hit.getISuperLayer() % 2 != 0:
124 number_of_wrong_rl_infos_stereo_only += 1
125 number_of_wrong_rl_infos += 1
127 return dict(number_of_wrong_rl_infos=number_of_wrong_rl_infos,
128 number_of_wrong_rl_infos_stereo_only=number_of_wrong_rl_infos_stereo_only,
129 number_of_hits=number_of_hits,
130 number_of_stereo=number_of_stereo,
131 mean_wrong_rl=np.true_divide(number_of_wrong_rl_infos, number_of_hits),
132 mean_wrong_rl_stereo=np.true_divide(number_of_wrong_rl_infos_stereo_only, number_of_stereo))
136 save_tree = refiners.save_tree(
146 Harvesting module to check for basic matching information of the found segments.
147 If you want to have matching information, please use the MC matcher module to make all possible
148 combinations between legendre, local and MC track candidates.
149 Also, the Segments must be transformed into GF track cands.
155 local_track_cands_store_array_name="LocalTrackCands",
156 mc_track_cands_store_array_name="MCTrackCands",
157 legendre_track_cand_store_array_name="LegendreTrackCands"):
159 Initialize the harvesting module with
162 output_file_name Name of the root file
163 local_track_cands_store_array_name Name of the StoreArray for local track cands
164 mc_track_cands_store_array_name Name of the StoreArray for MC track cands
165 legendre_track_cand_store_array_name Name of the StoreArray for legendre track cands
168 SegmentFakeRatesModule,
170 foreach=local_track_cands_store_array_name,
171 output_file_name=output_file_name)
183 legendre_track_cand_store_array_name)
186 """ Prepare the CDC lookup. """
189 return HarvestingModule.prepare(self)
191 def peel(self, local_track_cand):
192 """ Extract the information from the segments. """
198 is_background = mc_track_matcher_local.isBackgroundPRRecoTrack(local_track_cand)
199 is_ghost = mc_track_matcher_local.isGhostPRRecoTrack(local_track_cand)
200 is_matched = mc_track_matcher_local.isAnyChargeMatchedPRRecoTrack(local_track_cand)
201 is_clone = mc_track_matcher_local.isAnyChargeClonePRRecoTrack(local_track_cand)
202 is_clone_or_matched = is_matched
or is_clone
203 hit_purity = abs(mc_track_matcher_local.getRelatedPurity(local_track_cand))
206 first_cdc_hit_id = local_track_cand.getHitIDs(Belle2.Const.CDC)[0]
207 first_cdc_hit = cdc_hits[first_cdc_hit_id]
208 is_stereo = first_cdc_hit.getISuperLayer() % 2 == 1
209 superlayer_of_segment = first_cdc_hit.getISuperLayer()
212 hit_purity_of_partner = np.NaN
213 hit_efficiency_of_partner = np.NaN
215 mc_track_dist = np.NaN
216 number_of_new_hits = local_track_cand.getNHits()
217 number_of_hits = local_track_cand.getNHits()
218 number_of_hits_in_same_superlayer = np.NaN
219 partner_has_stereo_information = np.NaN
221 if is_clone_or_matched:
222 related_mc_track_cand = mc_track_matcher_local.getRelatedMCRecoTrack(local_track_cand)
223 has_partner = (mc_track_matcher_legendre.isAnyChargeMatchedMCRecoTrack(related_mc_track_cand)
or
224 mc_track_matcher_legendre.isAnyChargeMergedMCRecoTrack(related_mc_track_cand))
225 mc_track_pt = related_mc_track_cand.getMomSeed().Pt()
226 mc_track_dist = related_mc_track_cand.getPosSeed().Mag()
228 partner_legendre_track_cand = mc_track_matcher_legendre.getRelatedPRRecoTrack(related_mc_track_cand)
229 hit_purity_of_partner = abs(mc_track_matcher_legendre.getRelatedPurity(partner_legendre_track_cand))
230 hit_efficiency_of_partner = abs(mc_track_matcher_legendre.getRelatedEfficiency(related_mc_track_cand))
233 legendre_hits = set(list(partner_legendre_track_cand.getHitIDs()))
234 local_hits = set(list(local_track_cand.getHitIDs()))
236 local_hits_new = local_hits - legendre_hits
237 number_of_new_hits = len(local_hits_new)
240 partner_has_stereo_information = 0
241 number_of_hits_in_same_superlayer = 0
242 for cdc_hit_ID
in legendre_hits:
243 cdc_hit = cdc_hits[cdc_hit_ID]
244 if cdc_hit.getISuperLayer() == superlayer_of_segment:
245 number_of_hits_in_same_superlayer += 1
247 if cdc_hit.getISuperLayer() % 2 == 1:
248 partner_has_stereo_information = 1
250 return dict(superlayer_of_segment=superlayer_of_segment,
251 mc_track_dist=mc_track_dist,
252 is_background=is_background,
254 is_matched=is_matched,
256 is_clone_or_matched=is_clone_or_matched,
258 mc_track_pt=mc_track_pt,
259 hit_purity=hit_purity,
260 has_partner=has_partner,
261 hit_purity_of_partner=hit_purity_of_partner,
262 hit_efficiency_of_partner=hit_efficiency_of_partner,
263 number_of_new_hits=number_of_new_hits,
264 number_of_hits=number_of_hits,
265 number_of_hits_in_same_superlayer=number_of_hits_in_same_superlayer,
266 partner_has_stereo_information=partner_has_stereo_information)
270 save_tree = refiners.save_tree(
280 Harvester module to extract momentum and position information from the found segments and tracks.
281 You need the apply MC track matcher module.
284 def __init__(self, local_track_cands_store_array_name, mc_track_cands_store_array_name, output_file_name):
285 """ Init the harvester with the local track candidates StoreArray name and the one for MC track cands
286 and the output file name for the result root file.
289 SegmentFinderParameterExtractorModule,
291 foreach=local_track_cands_store_array_name,
292 output_file_name=output_file_name)
301 def peel(self, local_track_cand):
302 """ Extract the information from the local track candidate. """
305 is_matched = mc_track_matcher.isAnyChargeMatchedPRRecoTrack(local_track_cand)
306 is_background = mc_track_matcher.isBackgroundPRRecoTrack(local_track_cand)
307 is_ghost = mc_track_matcher.isGhostPRRecoTrack(local_track_cand)
309 related_mc_track_cand = mc_track_matcher.getRelatedMCRecoTrack(local_track_cand)
311 track_momentum = np.NaN
316 segment_momentum = np.NaN
322 track_momentum = related_mc_track_cand.getPosSeed()
324 track_pt = track_momentum.Pt()
325 track_phi = track_momentum.Phi()
331 segment_momentum = local_track_cand.getMomSeed()
333 segment_pt = segment_momentum.Pt()
334 segment_phi = segment_momentum.Phi()
340 return dict(is_matched=is_matched,
341 is_background=is_background,
343 segment_pt=segment_pt,
345 difference_pt=segment_pt - track_pt,
346 segment_phi=segment_phi,
348 difference_phi=segment_phi - track_phi)
352 save_tree = refiners.save_tree(
362 Extract the momentum seeds of the first and the last hit of the track candidates (when use_vxd_hits is true),
363 the helx and the mc momentum.
366 def __init__(self, output_file_name, track_cands, use_vxd_hits=True):
368 Init with the root output file name and the name of the store array of the track cands to use.
370 HarvestingModule.__init__(self, foreach=track_cands, output_file_name=output_file_name)
375 def peel(self, legendre_track_cand):
377 Extract the information.
379 if legendre_track_cand.getChargeSeed() > 0:
380 helix =
Belle2.Helix(legendre_track_cand.getPosSeed(), legendre_track_cand.getMomSeed(), 1, 1.5)
381 if legendre_track_cand.getChargeSeed() < 0:
382 helix =
Belle2.Helix(legendre_track_cand.getPosSeed(), legendre_track_cand.getMomSeed(), -1, 1.5)
385 mc_track_cand = matcher.getAnyChargeMatchedMCRecoTrack(legendre_track_cand)
391 mc_x = mc_track_cand.getPosSeed().X()
392 mc_y = mc_track_cand.getPosSeed().Y()
393 mc_z = mc_track_cand.getPosSeed().Z()
394 mc_mom_x = mc_track_cand.getMomSeed().X()
395 mc_mom_y = mc_track_cand.getMomSeed().Y()
396 mc_mom_z = mc_track_cand.getMomSeed().Z()
406 helix_z=helix.getZ0(),
407 helix_x=helix.getPerigeeX(),
408 helix_y=helix.getPerigeeY(),
409 helix_mom_z=helix.getMomentumZ(1.5),
410 helix_mom_x=helix.getMomentumX(1.5),
411 helix_mom_y=helix.getMomentumY(1.5),
420 first_hit = legendre_track_cand.getHit(0)
421 if first_hit.getDetId() == Belle2.Const.PXD:
422 first_cluster = pxd_clusters[first_hit.getHitId()]
423 first_true_hit = first_cluster.getRelated(
"PXDTrueHits")
424 elif first_hit.getDetId() == Belle2.Const.SVD:
425 first_cluster = svd_clusters[first_hit.getHitId()]
426 first_true_hit = first_cluster.getRelated(
"SVDTrueHits")
428 vxdID = first_cluster.getSensorID()
430 first_momentum = sensorInfoBase.vectorToGlobal(first_true_hit.getMomentum(),
True)
432 last_hit = legendre_track_cand.getHit(-1)
433 if last_hit.getDetId() == Belle2.Const.PXD:
434 last_cluster = pxd_clusters[last_hit.getHitId()]
435 last_true_hit = last_cluster.getRelated(
"PXDTrueHits")
436 elif last_hit.getDetId() == Belle2.Const.SVD:
437 last_cluster = svd_clusters[last_hit.getHitId()]
438 last_true_hit = last_cluster.getRelated(
"SVDTrueHits")
440 vxdID = first_cluster.getSensorID()
442 last_momentum = sensorInfoBase.vectorToGlobal(last_true_hit.getMomentum(),
True)
444 return_dict.update(dict(first_hit_mom_x=first_momentum.X(),
445 first_hit_mom_y=first_momentum.Y(),
446 first_hit_mom_z=first_momentum.Z(),
447 last_hit_mom_x=last_momentum.X(),
448 last_hit_mom_y=last_momentum.Y(),
449 last_hit_mom_z=last_momentum.Z()))
455 save_tree = refiners.SaveTreeRefiner()
A (simplified) python wrapper for StoreArray.
Interface class to the Monte Carlo information for individual hits.
Class to provide convenient methods to look up matching information between pattern recognition and M...
static GeoCache & getInstance()
Return a reference to the singleton instance.
def __init__(self, output_file_name, tracks_store_vector_name="CDCTrackVector")
mc_hit_lookup
function to look up CDC MC hits
def peel(self, track_cand)
use_vxd_hits
cached flag to use VXD hits
def peel(self, legendre_track_cand)
def __init__(self, output_file_name, track_cands, use_vxd_hits=True)
def __init__(self, output_file_name, local_track_cands_store_array_name="LocalTrackCands", mc_track_cands_store_array_name="MCTrackCands", legendre_track_cand_store_array_name="LegendreTrackCands")
mc_track_cands_store_array_name
cached name of the TrackCands StoreArray
mc_track_matcher_local
function to match local tracks to MC tracks
legendre_track_cand_store_array_name
cached name of the Legendre TrackCands StoreArray
cdcHits
cached CDCHits StoreArray
mc_track_matcher_legendre
function to match Legendre tracks to MC tracks
def peel(self, local_track_cand)
mc_hit_lookup
function to look up CDC MC hits
def peel(self, track_cand)
def __init__(self, output_file_name, tracks_store_vector_name="TrackCands")
foreach
Name of the StoreArray or iterable StoreObjPtr that contains the objects to be harvested.