Belle II Software  release-08-01-10
__init__.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import basf2 as b2
13 
14 # Many scripts import these functions from `tracking`, so leave these imports here
15 from tracking.path_utils import ( # noqa
16  add_cdc_cr_track_finding,
17  add_cdc_track_finding,
18  add_cr_track_fit_and_track_creator,
19  add_eclcdc_track_finding,
20  add_geometry_modules,
21  add_hit_preparation_modules,
22  add_mc_matcher,
23  add_prune_tracks,
24  add_flipping_of_recoTracks,
25  add_pxd_cr_track_finding,
26  add_pxd_track_finding,
27  add_svd_track_finding,
28  add_track_fit_and_track_creator,
29  add_prefilter_track_fit_and_track_creator,
30  add_vxd_track_finding_vxdtf2,
31  add_svd_standalone_tracking,
32  is_cdc_used,
33  is_ecl_used,
34  is_pxd_used,
35  is_svd_used,
36  use_local_sectormap,
37 )
38 
39 from pxd import add_pxd_reconstruction
40 
41 
42 def add_tracking_reconstruction(path, components=None, pruneTracks=False, skipGeometryAdding=False,
43  mcTrackFinding=False, trackFitHypotheses=None,
44  reco_tracks="RecoTracks", prune_temporary_tracks=True, fit_tracks=True,
45  use_second_cdc_hits=False, skipHitPreparerAdding=False,
46  svd_standalone_mode="VXDTF2",
47  use_svd_to_cdc_ckf=True, use_ecl_to_cdc_ckf=False,
48  add_cdcTrack_QI=True, add_vxdTrack_QI=False, add_recoTrack_QI=False,
49  pxd_filtering_offline=False, append_full_grid_cdc_eventt0=False,
50  v0_finding=True, flip_recoTrack=True):
51  """
52  This function adds the **standard tracking reconstruction** modules
53  to a path:
54 
55  #. first we find tracks using the CDC hits only, see :ref:`CDC Track Finding<tracking_trackFindingCDC>`
56 
57  #. CDC tracks are extrapolated to SVD and SVD hits are attached, see :ref:`CDC to SVD CKF<tracking_cdc2svd_ckf>`
58 
59  #. remaining SVD hits are used to find SVD tracks, see :ref:`SVD Track Finding<tracking_trackFindingSVD>`
60 
61  #. SVD tracks are extrapolated to CDC to attach CDC hits, see :ref:`SVD to CDC CKF<tracking_svd2cdc_ckf>`
62 
63  #. SVD and CDC tracks are merged and fitted, see :ref:`Track Fitting<tracking_trackFitting>`
64 
65  #. merged SVD+CDC tracks are extrapolated to PXD to attach PXD hits, see :ref:`SVD to PXD CKF<tracking_svd2pxd_ckf>`
66 
67  .. note::
68 
69  PXD hits are not available on HLT. At the end of the tracking chain on HLT we have the\
70  :ref:`PXD Region Of Interest Finding<tracking_pxdDataReduction>`, that consists of extrapolating\
71  the tracks on the PXD sensors and defining regions in which we expect to find the hit.\
72  Only fired pixels inside these regions reach Event Builder 2.
73 
74  #. after all the tracks from the IP are found, we look for special classes of tracks,\
75  in particular we search for displaced vertices to reconstruct K-short, Lambda and\
76  photon-conversions, see :ref:`V0 Finding<tracking_v0Finding>`.
77 
78  #. If the reconstruction uses PXD, we finally look for tracks with a wrong charge,\
79  flip and refit them to fix the charge, see :ref:`Flip&Refit<trk_flipNrefit>`.
80 
81 
82 
83  :param path: the path to add the tracking reconstruction modules to
84  :param components: the list of geometry components in use or None for all components.
85  :param pruneTracks: if true, delete all hits except the first and the last in the found tracks.
86  :param skipGeometryAdding: (advanced flag) the tracking modules need the geometry module and will add it,
87  if it is not already present in the path. In a setup with multiple (conditional) paths however, it can not
88  determine, if the geometry is already loaded. This flag can be used o just turn off the geometry adding at
89  all (but you will have to add it on your own then).
90  :param skipHitPreparerAdding: (advanced flag) if true, do not add the hit preparation (esp. VXD cluster creation
91  modules. This is useful if they have been added before already.
92  :param mcTrackFinding: if true, use the MC track finders instead of the realistic ones.
93  :param reco_tracks: name of the StoreArray where the reco tracks should be stored
94  :param prune_temporary_tracks: if false, store all information of the single CDC and VXD tracks before merging.
95  If true, prune them.
96  :param fit_tracks: if false, the final track find and the TrackCreator module will no be executed
97  :param use_second_cdc_hits: if true, the second hit information will be used in the CDC track finding.
98  :param trackFitHypotheses: which pdg hypothesis to fit. Defaults to [211, 321, 2212].
99  :param svd_standalone_mode: Which SVD standalone tracking is used.
100  Options are "VXDTF2", "SVDHough", "VXDTF2_and_SVDHough", and "SVDHough_and_VXDTF2".
101  Defaults to "VXDTF2"
102  :param use_svd_to_cdc_ckf: if true, add SVD to CDC CKF module.
103  :param use_ecl_to_cdc_ckf: if true, add ECL to CDC CKF module.
104  :param add_cdcTrack_QI: if true, add the MVA track quality estimation
105  to the path that sets the quality indicator property of the found CDC standalone tracks
106  :param add_vxdTrack_QI: if true, add the MVA track quality estimation
107  to the path that sets the quality indicator property of the found VXDTF2 tracks
108  (ATTENTION: Standard triplet QI of VXDTF2 is replaced in this case
109  -> setting this option to 'True' will have some influence on the final track collection)
110  :param add_recoTrack_QI: if true, add the MVA track quality estimation
111  to the path that sets the quality indicator property of all found reco tracks
112  (Both other QIs needed as input.)
113  :param pxd_filtering_offline: If True, PXD data reduction (ROI filtering) is applied during the track reconstruction.
114  The reconstructed SVD/CDC tracks are used to define the ROIs and reject all PXD clusters outside of these.
115  :param append_full_grid_cdc_eventt0: If True, the module FullGridChi2TrackTimeExtractor is added to the path
116  and provides the CDC temporary EventT0.
117  :param v0_finding: if false, the V0Finder module is not executed
118  :param flip_recoTrack: if true, add the recoTracks flipping function in the postfilter (only if PXD is present)
119  """
120 
121  add_prefilter_tracking_reconstruction(
122  path,
123  components=components,
124  skipGeometryAdding=skipGeometryAdding,
125  mcTrackFinding=mcTrackFinding,
126  trackFitHypotheses=trackFitHypotheses,
127  reco_tracks=reco_tracks,
128  prune_temporary_tracks=prune_temporary_tracks,
129  fit_tracks=fit_tracks,
130  use_second_cdc_hits=use_second_cdc_hits,
131  skipHitPreparerAdding=skipHitPreparerAdding,
132  svd_standalone_mode=svd_standalone_mode,
133  use_svd_to_cdc_ckf=use_svd_to_cdc_ckf,
134  use_ecl_to_cdc_ckf=use_ecl_to_cdc_ckf,
135  add_cdcTrack_QI=add_cdcTrack_QI,
136  add_vxdTrack_QI=add_vxdTrack_QI,
137  add_recoTrack_QI=add_recoTrack_QI,
138  pxd_filtering_offline=pxd_filtering_offline,
139  append_full_grid_cdc_eventt0=append_full_grid_cdc_eventt0)
140 
141  add_postfilter_tracking_reconstruction(path,
142  components=components,
143  pruneTracks=pruneTracks,
144  reco_tracks=reco_tracks,
145  use_second_cdc_hits=use_second_cdc_hits,
146  prune_temporary_tracks=prune_temporary_tracks,
147  v0_finding=v0_finding,
148  flip_recoTrack=flip_recoTrack,
149  mcTrackFinding=mcTrackFinding)
150 
151 
152 def add_prefilter_tracking_reconstruction(path, components=None, skipGeometryAdding=False,
153  mcTrackFinding=False, trackFitHypotheses=None, reco_tracks="RecoTracks",
154  prune_temporary_tracks=True, fit_tracks=True,
155  use_second_cdc_hits=False, skipHitPreparerAdding=False,
156  svd_standalone_mode="VXDTF2",
157  use_svd_to_cdc_ckf=True, use_ecl_to_cdc_ckf=False,
158  add_cdcTrack_QI=True, add_vxdTrack_QI=False, add_recoTrack_QI=False,
159  pxd_filtering_offline=False, append_full_grid_cdc_eventt0=False):
160  """
161  This function adds the tracking reconstruction modules required to calculate HLT filter decision
162  to a path.
163 
164  :param path: The path to add the tracking reconstruction modules to
165  :param components: the list of geometry components in use or None for all components.
166  :param skipGeometryAdding: Advances flag: The tracking modules need the geometry module and will add it,
167  if it is not already present in the path. In a setup with multiple (conditional) paths however, it can not
168  determine, if the geometry is already loaded. This flag can be used o just turn off the geometry adding at
169  all (but you will have to add it on your own then).
170  :param skipHitPreparerAdding: Advanced flag: do not add the hit preparation (esp. VXD cluster creation
171  modules. This is useful if they have been added before already.
172  :param mcTrackFinding: Use the MC track finders instead of the realistic ones.
173  :param reco_tracks: Name of the StoreArray where the reco tracks should be stored
174  :param prune_temporary_tracks: If false, store all information of the single CDC and VXD tracks before merging.
175  If true, prune them.
176  :param fit_tracks: If false, the final track find and the TrackCreator module will no be executed
177  :param use_second_cdc_hits: If true, the second hit information will be used in the CDC track finding.
178  :param trackFitHypotheses: Which pdg hypothesis to fit. Defaults to [211, 321, 2212].
179  :param svd_standalone_mode: Which SVD standalone tracking is used.
180  Options are "VXDTF2", "SVDHough", "VXDTF2_and_SVDHough", and "SVDHough_and_VXDTF2".
181  Defaults to "VXDTF2"
182  :param use_svd_to_cdc_ckf: if true, add SVD to CDC CKF module.
183  :param use_ecl_to_cdc_ckf: if true, add ECL to CDC CKF module.
184  :param add_cdcTrack_QI: If true, add the MVA track quality estimation
185  to the path that sets the quality indicator property of the found CDC standalone tracks
186  :param add_vxdTrack_QI: If true, add the MVA track quality estimation
187  to the path that sets the quality indicator property of the found VXDTF2 tracks
188  (ATTENTION: Standard triplet QI of VXDTF2 is replaced in this case
189  -> setting this option to 'True' will have some influence on the final track collection)
190  :param add_recoTrack_QI: If true, add the MVA track quality estimation
191  to the path that sets the quality indicator property of all found reco tracks
192  (Both other QIs needed as input.)
193  :param pxd_filtering_offline: If True, PXD data reduction (ROI filtering) is applied during the track reconstruction.
194  The reconstructed SVD/CDC tracks are used to define the ROIs and reject all PXD clusters outside of these.
195  :param append_full_grid_cdc_eventt0: If True, the module FullGridChi2TrackTimeExtractor is added to the path
196  and provides the CDC temporary EventT0.
197  """
198 
199  if not is_svd_used(components) and not is_cdc_used(components):
200  return
201 
202  if (add_cdcTrack_QI or add_vxdTrack_QI or add_recoTrack_QI) and not fit_tracks:
203  b2.B2ERROR("MVA track qualiy indicator requires `fit_tracks` to be enabled. Turning all off.")
204  add_cdcTrack_QI = False
205  add_vxdTrack_QI = False
206  add_recoTrack_QI = False
207 
208  if add_recoTrack_QI and (not add_cdcTrack_QI or not add_vxdTrack_QI):
209  b2.B2ERROR("RecoTrack qualiy indicator requires CDC and VXD QI as input. Turning it all of.")
210  add_cdcTrack_QI = False
211  add_vxdTrack_QI = False
212  add_recoTrack_QI = False
213 
214  if not skipGeometryAdding:
215  add_geometry_modules(path, components=components)
216 
217  if not skipHitPreparerAdding:
218  add_hit_preparation_modules(path, components=components, pxd_filtering_offline=pxd_filtering_offline)
219 
220  # Material effects for all track extrapolations
221  if 'SetupGenfitExtrapolation' not in path:
222  path.add_module('SetupGenfitExtrapolation',
223  energyLossBrems=False, noiseBrems=False)
224 
225  if mcTrackFinding:
226  add_mc_track_finding(path, components=components, reco_tracks=reco_tracks,
227  use_second_cdc_hits=use_second_cdc_hits)
228  else:
229  add_track_finding(path, components=components, reco_tracks=reco_tracks,
230  prune_temporary_tracks=prune_temporary_tracks,
231  use_second_cdc_hits=use_second_cdc_hits,
232  svd_standalone_mode=svd_standalone_mode,
233  use_svd_to_cdc_ckf=use_svd_to_cdc_ckf,
234  use_ecl_to_cdc_ckf=use_ecl_to_cdc_ckf,
235  add_cdcTrack_QI=add_cdcTrack_QI,
236  add_vxdTrack_QI=add_vxdTrack_QI,
237  pxd_filtering_offline=pxd_filtering_offline)
238 
239  # Only run the track time extraction on the full reconstruction chain for now. Later, we may
240  # consider to do the CDC-hit based method already during the fast reconstruction stage
241  add_time_extraction(path, append_full_grid_cdc_eventt0, components=components)
242 
243  if fit_tracks:
244  add_prefilter_track_fit_and_track_creator(path,
245  trackFitHypotheses=trackFitHypotheses,
246  reco_tracks=reco_tracks,
247  add_mva_quality_indicator=add_recoTrack_QI)
248 
249 
250 def add_postfilter_tracking_reconstruction(path, components=None, pruneTracks=False, reco_tracks="RecoTracks",
251  use_second_cdc_hits=False, prune_temporary_tracks=True, v0_finding=True,
252  flip_recoTrack=True, mcTrackFinding=False):
253  """
254  This function adds the tracking reconstruction modules not required to calculate HLT filter
255  decision to a path.
256 
257  :param path: The path to add the tracking reconstruction modules to
258  :param components: the list of geometry components in use or None for all components.
259  :param pruneTracks: Delete all hits except the first and the last in the found tracks.
260  :param reco_tracks: Name of the StoreArray where the reco tracks should be stored
261  :param use_second_cdc_hits: If true, the second hit information will be used in the CDC track finding.
262  :param prune_temporary_tracks: If false, store all information of the single CDC and VXD tracks before merging.
263  If true, prune them.
264  :param v0_finding: If false, the V0 module will not be executed
265  :param flip_recoTrack: if true, add the recoTracks flipping function in the postfilter (only if PXD is present)
266  :param mcTrackFinding: Use the MC track finders instead of the realistic ones.
267  """
268 
269  # do not add any new modules if no tracking detectors are in the components
270  if components and not ('SVD' in components or 'CDC' in components):
271  return
272 
273  # flip & refit to fix the charge of some tracks
274  if flip_recoTrack and not mcTrackFinding and is_pxd_used(components):
275  add_flipping_of_recoTracks(path, reco_tracks="RecoTracks")
276 
277  # V0 finding
278  if v0_finding:
279  path.add_module('V0Finder', RecoTracks=reco_tracks, v0FitterMode=1)
280 
281  # estimate the track time
282  path.add_module('TrackTimeEstimator')
283 
284  add_mc_matcher(path, components=components, reco_tracks=reco_tracks,
285  use_second_cdc_hits=use_second_cdc_hits)
286 
287  # prune
288  if pruneTracks:
289  add_prune_tracks(path, components=components, reco_tracks=reco_tracks)
290 
291  if prune_temporary_tracks or pruneTracks:
292  path.add_module("PruneRecoHits")
293 
294 
295 def add_time_extraction(path, append_full_grid_cdc_eventt0=False, components=None):
296  """
297  Add time extraction components via tracking
298 
299  :param path: The path to add the tracking reconstruction modules to
300  :param append_full_grid_cdc_eventt0: If True, the module FullGridChi2TrackTimeExtractor is added to the path
301  and provides the CDC temporary EventT0.
302  :param components: the list of geometry components in use or None for all components.
303  """
304  if is_svd_used(components):
305  path.add_module("SVDEventT0Estimator")
306 
307  if is_cdc_used(components) and append_full_grid_cdc_eventt0:
308  path.add_module("FullGridChi2TrackTimeExtractor")
309 
310 
311 def add_cr_tracking_reconstruction(path, components=None, prune_tracks=False,
312  skip_geometry_adding=False, event_time_extraction=True,
313  merge_tracks=True, use_second_cdc_hits=False):
314  """
315  This function adds the reconstruction modules for cr tracking to a path.
316 
317  :param path: The path to which to add the tracking reconstruction modules
318 
319  :param components: the list of geometry components in use or None for all components.
320  :param prune_tracks: Delete all hits except the first and the last in the found tracks.
321 
322  :param skip_geometry_adding: Advanced flag: The tracking modules need the geometry module and will add it,
323  if it is not already present in the path. In a setup with multiple (conditional) paths however, it cannot
324  determine if the geometry is already loaded. This flag can be used to just turn off the geometry adding
325  (but you will have to add it on your own).
326  :param event_time_extraction: extract the event time
327  :param merge_tracks: The upper and lower half of the tracks should be merged together in one track
328  :param use_second_cdc_hits: If true, the second hit information will be used in the CDC track finding.
329 
330  """
331 
332  # make sure CDC is used
333  if not is_cdc_used(components):
334  return
335 
336  if not skip_geometry_adding:
337  add_geometry_modules(path, components)
338 
339  add_hit_preparation_modules(path, components=components)
340 
341  # Material effects for all track extrapolations
342  if 'SetupGenfitExtrapolation' not in path:
343  path.add_module('SetupGenfitExtrapolation',
344  energyLossBrems=False, noiseBrems=False)
345 
346  # track finding
347  add_cr_track_finding(path, reco_tracks="RecoTracks", components=components,
348  merge_tracks=merge_tracks, use_second_cdc_hits=use_second_cdc_hits)
349 
350  # track fitting
351  # if tracks were merged, use the unmerged collection for time extraction
352  add_cr_track_fit_and_track_creator(path, components=components, prune_tracks=prune_tracks,
353  event_timing_extraction=event_time_extraction)
354 
355  if merge_tracks:
356  # Do also fit the not merged tracks
357  add_cr_track_fit_and_track_creator(path, components=components, prune_tracks=prune_tracks,
358  event_timing_extraction=False,
359  reco_tracks="NonMergedRecoTracks", tracks="NonMergedTracks")
360 
361 
362 def add_mc_tracking_reconstruction(path, components=None, pruneTracks=False, use_second_cdc_hits=False):
363  """
364  This function adds the standard reconstruction modules for MC tracking
365  to a path.
366 
367  :param path: The path to add the tracking reconstruction modules to
368  :param components: the list of geometry components in use or None for all components.
369  :param pruneTracks: Delete all hits expect the first and the last from the found tracks.
370  :param use_second_cdc_hits: If true, the second hit information will be used in the CDC track finding.
371  """
372  add_tracking_reconstruction(path,
373  components=components,
374  pruneTracks=pruneTracks,
375  mcTrackFinding=True,
376  use_second_cdc_hits=use_second_cdc_hits)
377 
378 
379 def add_track_finding(path, components=None, reco_tracks="RecoTracks",
380  prune_temporary_tracks=True, use_second_cdc_hits=False,
381  use_mc_truth=False, svd_ckf_mode="SVD_after", add_both_directions=True,
382  svd_standalone_mode="VXDTF2",
383  use_svd_to_cdc_ckf=True, use_ecl_to_cdc_ckf=False,
384  add_cdcTrack_QI=True, add_vxdTrack_QI=False,
385  pxd_filtering_offline=False, use_HLT_ROIs=False):
386  """
387  Add the CKF to the path with all the track finding related to and needed for it.
388  :param path: The path to add the tracking reconstruction modules to
389  :param reco_tracks: The store array name where to output all tracks
390  :param use_mc_truth: Use the truth information in the CKF modules
391  :param svd_ckf_mode: how to apply the CKF (with or without SVD standalone tracking). Defaults to "SVD_after".
392  :param add_both_directions: Curlers may be found in the wrong orientation by the CDC track finder, so try to
393  extrapolate also in the other direction.
394  :param svd_standalone_mode: Which SVD standalone tracking is used.
395  Options are "VXDTF2", "SVDHough", "VXDTF2_and_SVDHough", and "SVDHough_and_VXDTF2".
396  Defaults to "VXDTF2"
397  :param use_second_cdc_hits: whether to use the secondary CDC hit during CDC track finding or not
398  :param components: the list of geometry components in use or None for all components.
399  :param prune_temporary_tracks: If false, store all information of the single CDC and VXD tracks before merging.
400  If true, prune them.
401  :param use_svd_to_cdc_ckf: if true, add SVD to CDC CKF module.
402  :param use_ecl_to_cdc_ckf: if true, add ECL to CDC CKF module.
403  :param add_cdcTrack_QI: If true, add the MVA track quality estimation
404  to the path that sets the quality indicator property of the found CDC standalone tracks
405  :param add_vxdTrack_QI: If true, add the MVA track quality estimation
406  to the path that sets the quality indicator property of the found VXDTF2 tracks
407  (ATTENTION: Standard triplet QI of VXDTF2 is replaced in this case
408  -> setting this option to 'True' will have some influence on the final track collection)
409  :param pxd_filtering_offline: If True, PXD data reduction (ROI filtering) is applied during the track reconstruction.
410  The reconstructed SVD/CDC tracks are used to define the ROIs and reject all PXD clusters outside of these.
411  :param use_HLT_ROIs: Don't calculate the ROIs here but use the ones from the HLT (does obviously not work for simulation)
412  """
413  if not is_svd_used(components) and not is_cdc_used(components):
414  return
415 
416  if use_ecl_to_cdc_ckf and not is_cdc_used(components):
417  b2.B2WARNING("ECL CKF cannot be used without CDC. Turning it off.")
418  use_ecl_to_cdc_ckf = False
419 
420  if use_ecl_to_cdc_ckf and not is_ecl_used(components):
421  b2.B2ERROR("ECL CKF cannot be used without ECL. Turning it off.")
422  use_ecl_to_cdc_ckf = False
423 
424  # register EventTrackingInfo
425  if 'RegisterEventLevelTrackingInfo' not in path:
426  path.add_module('RegisterEventLevelTrackingInfo')
427 
428  # output tracks
429  cdc_reco_tracks = "CDCRecoTracks"
430  svd_cdc_reco_tracks = "SVDCDCRecoTracks"
431  ecl_reco_tracks = "ECLRecoTracks"
432  combined_ecl_reco_tracks = "combinedECLRecoTracks"
433 
434  # temporary collections
435  svd_reco_tracks = "SVDRecoTracks"
436  pxd_reco_tracks = "PXDRecoTracks"
437 
438  # collections that will be pruned
439  temporary_reco_track_list = []
440 
441  # the name of the most recent track collection
442  latest_reco_tracks = None
443 
444  if not is_pxd_used(components):
445  if use_ecl_to_cdc_ckf and is_cdc_used(components):
446  combined_ecl_reco_tracks = reco_tracks
447  elif (not use_ecl_to_cdc_ckf) and is_svd_used(components):
448  svd_cdc_reco_tracks = reco_tracks
449  elif (not use_ecl_to_cdc_ckf) and (not is_svd_used(components)) and is_cdc_used(components):
450  cdc_reco_tracks = reco_tracks
451 
452  if is_cdc_used(components):
453  add_cdc_track_finding(path, use_second_hits=use_second_cdc_hits, output_reco_tracks=cdc_reco_tracks,
454  add_mva_quality_indicator=add_cdcTrack_QI)
455  temporary_reco_track_list.append(cdc_reco_tracks)
456  latest_reco_tracks = cdc_reco_tracks
457 
458  if is_svd_used(components):
459  add_svd_track_finding(path, components=components, input_reco_tracks=latest_reco_tracks,
460  output_reco_tracks=svd_cdc_reco_tracks, use_mc_truth=use_mc_truth,
461  temporary_reco_tracks=svd_reco_tracks,
462  svd_ckf_mode=svd_ckf_mode, add_both_directions=add_both_directions,
463  use_svd_to_cdc_ckf=use_svd_to_cdc_ckf, prune_temporary_tracks=prune_temporary_tracks,
464  add_mva_quality_indicator=add_vxdTrack_QI,
465  svd_standalone_mode=svd_standalone_mode)
466  temporary_reco_track_list.append(svd_reco_tracks)
467  temporary_reco_track_list.append(svd_cdc_reco_tracks)
468  latest_reco_tracks = svd_cdc_reco_tracks
469 
470  if use_ecl_to_cdc_ckf and is_cdc_used(components):
471  add_eclcdc_track_finding(path, components=components, output_reco_tracks=ecl_reco_tracks,
472  prune_temporary_tracks=prune_temporary_tracks)
473 
474  # TODO: add another merging step? (SVD track found by vxdtf2, and CDC track found by ECL CKF)?
475 
476  path.add_module("RecoTrackStoreArrayCombiner",
477  Temp1RecoTracksStoreArrayName=latest_reco_tracks,
478  Temp2RecoTracksStoreArrayName=ecl_reco_tracks,
479  recoTracksStoreArrayName=combined_ecl_reco_tracks)
480  temporary_reco_track_list.append(ecl_reco_tracks)
481  temporary_reco_track_list.append(combined_ecl_reco_tracks)
482  latest_reco_tracks = combined_ecl_reco_tracks
483 
484  if is_pxd_used(components):
485  if pxd_filtering_offline:
486  roiName = "ROIs"
487  if not use_HLT_ROIs:
488  path.add_module("DAFRecoFitter", recoTracksStoreArrayName=latest_reco_tracks)
489 
490  roiName = "ROIs_offline"
491  add_roiFinder(path, reco_tracks=latest_reco_tracks, roiName=roiName)
492 
493  pxd_digifilter = b2.register_module('PXDdigiFilter')
494  pxd_digifilter.param('ROIidsName', roiName)
495  pxd_digifilter.param('PXDDigitsName', 'PXDDigits')
496  pxd_digifilter.param('PXDDigitsInsideROIName', 'PXDDigits')
497  pxd_digifilter.param('overrideDB', True)
498  pxd_digifilter.param('usePXDDataReduction', True)
499  path.add_module(pxd_digifilter)
500 
501  add_pxd_reconstruction(path)
502 
503  add_pxd_track_finding(path, components=components, input_reco_tracks=latest_reco_tracks,
504  use_mc_truth=use_mc_truth, output_reco_tracks=reco_tracks,
505  temporary_reco_tracks=pxd_reco_tracks,
506  add_both_directions=add_both_directions)
507  temporary_reco_track_list.append(pxd_reco_tracks)
508 
509  if prune_temporary_tracks:
510  for temporary_reco_track_name in temporary_reco_track_list:
511  if temporary_reco_track_name != reco_tracks:
512  path.add_module('PruneRecoTracks', storeArrayName=temporary_reco_track_name)
513 
514 
515 def add_cr_track_finding(path, reco_tracks="RecoTracks", components=None,
516  merge_tracks=True, use_second_cdc_hits=False):
517 
518  # register EventTrackingInfo
519  if 'RegisterEventLevelTrackingInfo' not in path:
520  path.add_module('RegisterEventLevelTrackingInfo')
521 
522  if not is_cdc_used(components):
523  b2.B2FATAL("CDC must be in components")
524 
525  reco_tracks_from_track_finding = reco_tracks
526  if merge_tracks:
527  reco_tracks_from_track_finding = "NonMergedRecoTracks"
528 
529  cdc_reco_tracks = "CDCRecoTracks"
530  if not is_pxd_used(components) and not is_svd_used(components):
531  cdc_reco_tracks = reco_tracks_from_track_finding
532 
533  svd_cdc_reco_tracks = "SVDCDCRecoTracks"
534  if not is_pxd_used(components):
535  svd_cdc_reco_tracks = reco_tracks_from_track_finding
536 
537  full_reco_tracks = reco_tracks_from_track_finding
538 
539  # CDC track finding with default settings
540  add_cdc_cr_track_finding(path, merge_tracks=False, use_second_cdc_hits=use_second_cdc_hits,
541  output_reco_tracks=cdc_reco_tracks)
542 
543  latest_reco_tracks = cdc_reco_tracks
544 
545  if is_svd_used(components):
546  add_svd_track_finding(path, components=components, input_reco_tracks=latest_reco_tracks,
547  output_reco_tracks=svd_cdc_reco_tracks,
548  svd_ckf_mode="cosmics", add_both_directions=True, svd_standalone_mode="VXDTF2")
549  latest_reco_tracks = svd_cdc_reco_tracks
550 
551  if is_pxd_used(components):
552  add_pxd_cr_track_finding(path, components=components, input_reco_tracks=latest_reco_tracks,
553  output_reco_tracks=full_reco_tracks, add_both_directions=True)
554 
555  if merge_tracks:
556  # merge the tracks together
557  path.add_module("CosmicsTrackMerger", inputRecoTracks=reco_tracks_from_track_finding,
558  outputRecoTracks=reco_tracks)
559 
560 
561 def add_mc_track_finding(path, components=None, reco_tracks="RecoTracks", use_second_cdc_hits=False):
562  """
563  Add the MC based TrackFinder to the path.
564 
565  :param path: The path to add the tracking reconstruction modules to
566  :param components: the list of geometry components in use or None for all components.
567  :param reco_tracks: Name of the StoreArray where the reco tracks should be stored
568  :param use_second_cdc_hits: If true, the second hit information will be used in the CDC track finding.
569  """
570  if is_cdc_used(components) or is_pxd_used(components) or is_svd_used(components):
571  # find MCTracks in CDC, SVD and PXD (or a subset of it)
572  path.add_module('TrackFinderMCTruthRecoTracks',
573  RecoTracksStoreArrayName=reco_tracks,
574  UseSecondCDCHits=use_second_cdc_hits,
575  UsePXDHits=is_pxd_used(components),
576  UseSVDHits=is_svd_used(components),
577  UseCDCHits=is_cdc_used(components))
578 
579 
580 def add_tracking_for_PXDDataReduction_simulation(path, components, svd_cluster='__ROIsvdClusters'):
581  """
582  This function adds the standard reconstruction modules for tracking to be used for the simulation of PXD data
583  reduction to a path.
584 
585  :param path: The path to add the tracking reconstruction modules to
586  :param components: the list of geometry components in use or None for all components, always exclude the PXD.
587  """
588 
589  if not is_svd_used(components):
590  return
591 
592  # Material effects
593  if 'SetupGenfitExtrapolation' not in path:
594  material_effects = b2.register_module('SetupGenfitExtrapolation')
595  material_effects.set_name(
596  'SetupGenfitExtrapolationForPXDDataReduction')
597  path.add_module(material_effects)
598 
599  # SET StoreArray names
600  svd_reco_tracks = "__ROIsvdRecoTracks"
601 
602  # SVD ONLY TRACK FINDING
603  add_svd_standalone_tracking(path, components=['SVD'], reco_tracks=svd_reco_tracks, suffix="__ROI",
604  svd_clusters=svd_cluster)
605 
606  # TRACK FITTING
607  dafRecoFitter = b2.register_module("DAFRecoFitter")
608  dafRecoFitter.set_name("SVD-only DAFRecoFitter")
609  dafRecoFitter.param('recoTracksStoreArrayName', svd_reco_tracks)
610  dafRecoFitter.param('svdHitsStoreArrayName', svd_cluster)
611  path.add_module(dafRecoFitter)
612 
613 
614 def add_roiFinder(path, reco_tracks="RecoTracks", roiName="ROIs"):
615  """
616  Add the ROI finding to the path creating ROIs out of reco tracks by extrapolating them to the PXD volume.
617  :param path: Where to add the module to.
618  :param reco_tracks: Which tracks to use in the extrapolation step.
619  :param roiName: Name of the produced/stored ROIs.
620  """
621 
622  pxdDataRed = b2.register_module('PXDROIFinder')
623  param_pxdDataRed = {
624  'recoTrackListName': reco_tracks,
625  'PXDInterceptListName': 'PXDIntercepts',
626  'ROIListName': roiName,
627  }
628  pxdDataRed.param(param_pxdDataRed)
629  path.add_module(pxdDataRed)
630 
631 
632 def add_vxd_standalone_cosmics_finder(
633  path,
634  reco_tracks="RecoTracks",
635  pxd_spacepoints_name="PXDSpacePoints",
636  svd_spacepoints_name="SVDSpacePoints",
637  quality_cut=0.0001,
638  min_sps=3,
639  max_rejected_sps=5):
640  """
641  Convenience function for adding VXD standalone cosmics track finding for B = 0 Tesla
642  to the path.
643 
644  The result is a StoreArray with name @param reco_tracks containing one or zero reco tracks per event.
645  This track candidates have an arbitrary but large momentum seed in the direction of the fitted line.
646  The position and momentum seed is obtained using a principal component analysis method.
647 
648  :param path: basf2 path
649  :param reco_tracks: Name of the output RecoTracks; defaults to RecoTracks.
650  :param spacepoints_name: name of store array containing the spacepoints; defaults to SpacePoints
651  :param quality_cut: Cut on the chi squared value of the line fit; candidates with values above the cut will be
652  rejected; defaults to 0.0001
653  :param min_sps: Minimal number of SpacePoints required to build a track candidate; defaults to 3;
654  :param max_rejected_sps: Maximal number of retries to refit a track after the worst spacepoint was removed;
655  defaults to 5;
656  """
657 
658  # register EventTrackingInfo
659  if 'RegisterEventLevelTrackingInfo' not in path:
660  path.add_module('RegisterEventLevelTrackingInfo')
661 
662  if "PXDSpacePointCreator" not in [m.name() for m in path.modules()]:
663  path.add_module('PXDSpacePointCreator', SpacePoints=pxd_spacepoints_name)
664 
665  # SVDSpacePointCreator is applied in funtion add_svd_reconstruction
666 
667  track_finder = b2.register_module('TrackFinderVXDCosmicsStandalone')
668  track_finder.param('SpacePointTrackCandArrayName', "")
669  track_finder.param('SpacePoints', [pxd_spacepoints_name, svd_spacepoints_name])
670  track_finder.param('QualityCut', quality_cut)
671  track_finder.param('MinSPs', min_sps)
672  track_finder.param('MaxRejectedSPs', max_rejected_sps)
673  path.add_module(track_finder)
674 
675  converter = b2.register_module('SPTC2RTConverter')
676  converter.param('recoTracksStoreArrayName', reco_tracks)
677  path.add_module(converter)