Belle II Software  release-08-01-10
path_utils.py
1 
2 
9 
10 from pybasf2 import B2WARNING
11 
12 from basf2 import register_module
13 from ckf.path_functions import add_pxd_ckf, add_ckf_based_merger, add_svd_ckf, add_cosmics_svd_ckf, add_cosmics_pxd_ckf
14 from pxd import add_pxd_reconstruction
15 from svd import add_svd_reconstruction
16 from tracking.adjustments import adjust_module
17 
18 
19 def use_local_sectormap(path, pathToLocalSM):
20  """ Helper function that sets up the SectorMapBootstrapModule in that way that a local sectormap will be
21  loaded instead the one from the DB. Has to be applied on the path after the SectorMapBootstrap was
22  put into the path (usually in add_reconstructin)
23 
24  :param path: The path the SectorMapBootstrapModule is in.
25  :param pathToLocalSM: the local storage position of the sectormap (including the name)
26 
27  """
28  B2WARNING("Warning will load local SectorMap from: " + pathToLocalSM)
29  adjust_module(path, 'SectorMapBootstrap', **{"ReadSecMapFromDB": False,
30  "ReadSectorMap": True, "SectorMapsInputFile": pathToLocalSM})
31 
32 
33 def add_geometry_modules(path, components=None):
34  """
35  Helper function to add the geometry related modules needed for tracking
36  to the path.
37 
38  :param path: The path to add the tracking reconstruction modules to
39  :param components: the list of geometry components in use or None for all components.
40  """
41  # check for detector geometry, necessary for track extrapolation in genfit
42  if 'Geometry' not in path:
43  path.add_module('Geometry', useDB=True)
44  if components is not None:
45  B2WARNING("Custom detector components specified: Will still build full geometry")
46 
47  # Material effects for all track extrapolations
48  if 'SetupGenfitExtrapolation' not in path:
49  path.add_module('SetupGenfitExtrapolation',
50  energyLossBrems=False, noiseBrems=False)
51 
52 
53 def add_hit_preparation_modules(path, components=None, pxd_filtering_offline=False):
54  """
55  Helper fucntion to prepare the hit information to be used by tracking.
56 
57  :param path: The path to add the tracking reconstruction modules to
58  :param components: the list of geometry components in use or None for all components.
59  :param pxd_filtering_offline: PXD data reduction is performed after CDC and SVD tracking,
60  so PXD reconstruction has to wait until the ROIs are calculated.
61  """
62 
63  # Preparation of the SVD clusters
64  if is_svd_used(components):
65  add_svd_reconstruction(path)
66 
67  # Preparation of the PXD clusters
68  if is_pxd_used(components) and not pxd_filtering_offline:
69  add_pxd_reconstruction(path)
70 
71 
72 def add_track_fit_and_track_creator(path, components=None, pruneTracks=False, trackFitHypotheses=None,
73  reco_tracks="RecoTracks", add_mva_quality_indicator=False, v0_finding=True):
74  """
75  Helper function to add the modules performing the
76  track fit, the V0 fit and the Belle2 track creation to the path.
77 
78  :param path: The path to add the tracking reconstruction modules to
79  :param components: the list of geometry components in use or None for all components.
80  :param pruneTracks: Delete all hits expect the first and the last from the found tracks.
81  :param reco_tracks: Name of the StoreArray where the reco tracks should be stored
82  :param v0_finding: if false, the V0Finder module is not executed
83  :param add_mva_quality_indicator: If true, add the MVA track quality estimation
84  to the path that sets the quality indicator property of the found tracks.
85  """
86 
87  add_prefilter_track_fit_and_track_creator(path,
88  trackFitHypotheses=trackFitHypotheses,
89  reco_tracks=reco_tracks,
90  add_mva_quality_indicator=add_mva_quality_indicator)
91 
92  # V0 finding
93  if v0_finding:
94  path.add_module('V0Finder', RecoTracks=reco_tracks, v0FitterMode=1)
95 
96  if pruneTracks:
97  add_prune_tracks(path, components=components, reco_tracks=reco_tracks)
98 
99 
100 def add_prefilter_track_fit_and_track_creator(path, trackFitHypotheses=None,
101  reco_tracks="RecoTracks", add_mva_quality_indicator=False):
102  """
103  Helper function to add only the modules required to calculate HLT filter decision:
104  performing the track fit and the Belle2 track creation to the path.
105 
106  :param path: The path to add the tracking reconstruction modules to
107  :param reco_tracks: Name of the StoreArray where the reco tracks should be stored
108  :param add_mva_quality_indicator: If true, add the MVA track quality estimation
109  to the path that sets the quality indicator property of the found tracks.
110  """
111 
112  # Correct time seed
113  path.add_module("IPTrackTimeEstimator",
114  recoTracksStoreArrayName=reco_tracks, useFittedInformation=False)
115  # track fitting
116  path.add_module("DAFRecoFitter", recoTracksStoreArrayName=reco_tracks).set_name(
117  "Combined_DAFRecoFitter")
118  # Add MVA classifier that uses information not included in the calculation of the fit p-value
119  # to add a track quality indicator for classification of fake vs. MC-matched tracks
120 
121  if add_mva_quality_indicator:
122  path.add_module("TrackQualityEstimatorMVA", collectEventFeatures=True)
123  # create Belle2 Tracks from the genfit Tracks
124  # The following particle hypothesis will be fitted: Pion, Kaon and Proton
125  # Muon fit is working but gives very similar as the Pion due to the closeness of masses
126  # -> therefore not in the default fit list
127  # Electron fit has as systematic bias and therefore not done here. Therefore, pion fits
128  # will be used for electrons which gives a better result as GenFit's current electron
129  # implementation.
130  path.add_module('TrackCreator', recoTrackColName=reco_tracks,
131  pdgCodes=[211, 321, 2212] if not trackFitHypotheses else trackFitHypotheses)
132 
133 
134 def add_cr_track_fit_and_track_creator(path, components=None,
135  prune_tracks=False, event_timing_extraction=True,
136  reco_tracks="RecoTracks", tracks=""):
137  """
138  Helper function to add the modules performing the cdc cr track fit
139  and track creation to the path.
140 
141  :param path: The path to which to add the tracking reconstruction modules
142  :param components: the list of geometry components in use or None for all components.
143  :param reco_tracks: The name of the reco tracks to use
144  :param tracks: the name of the output Belle tracks
145  :param prune_tracks: Delete all hits expect the first and the last from the found tracks.
146  :param event_timing_extraction: extract the event time
147  """
148 
149  # Time seed
150  path.add_module("PlaneTriggerTrackTimeEstimator",
151  recoTracksStoreArrayName=reco_tracks,
152  pdgCodeToUseForEstimation=13,
153  triggerPlanePosition=[0., 0., 0.],
154  triggerPlaneDirection=[0., 1., 0.],
155  useFittedInformation=False)
156 
157  # Initial track fitting
158  path.add_module("DAFRecoFitter",
159  recoTracksStoreArrayName=reco_tracks,
160  probCut=0.00001,
161  pdgCodesToUseForFitting=13)
162 
163  # Correct time seed
164  path.add_module("PlaneTriggerTrackTimeEstimator",
165  recoTracksStoreArrayName=reco_tracks,
166  pdgCodeToUseForEstimation=13,
167  triggerPlanePosition=[0., 0., 0.],
168  triggerPlaneDirection=[0., 1., 0.],
169  useFittedInformation=True)
170 
171  # Final Track fitting
172  path.add_module("DAFRecoFitter",
173  recoTracksStoreArrayName=reco_tracks,
174  pdgCodesToUseForFitting=13
175  )
176 
177  if event_timing_extraction:
178  # Extract the time
179  path.add_module("FullGridChi2TrackTimeExtractor",
180  RecoTracksStoreArrayName=reco_tracks,
181  GridMaximalT0Value=40,
182  GridMinimalT0Value=-40,
183  GridGridSteps=6
184  )
185 
186  # Track fitting
187  path.add_module("DAFRecoFitter",
188  # probCut=0.00001,
189  recoTracksStoreArrayName=reco_tracks,
190  pdgCodesToUseForFitting=13
191  )
192 
193  # Create Belle2 Tracks from the genfit Tracks
194  path.add_module('TrackCreator',
195  pdgCodes=[13],
196  recoTrackColName=reco_tracks,
197  trackColName=tracks,
198  useClosestHitToIP=True,
199  useBFieldAtHit=True
200  )
201 
202  # Prune genfit tracks
203  if prune_tracks:
204  add_prune_tracks(path=path, components=components,
205  reco_tracks=reco_tracks)
206 
207 
208 def add_mc_matcher(path, components=None, mc_reco_tracks="MCRecoTracks",
209  reco_tracks="RecoTracks", use_second_cdc_hits=False,
210  split_after_delta_t=-1.0, matching_method="hit",
211  chi2_cutoffs=[128024, 95, 173, 424, 90, 424],
212  chi2_linalg=False):
213  """
214  Match the tracks to the MC truth. The matching works based on
215  the output of the TrackFinderMCTruthRecoTracks.
216  Alternativly one can use the Chi2MCTrackMatcher based on chi2 values
217  calculated from the helixparameters of Tracks and MCParticles.
218 
219  :param path: The path to add the tracking reconstruction modules to
220  :param components: the list of geometry components in use or None for all components.
221  :param mc_reco_tracks: Name of the StoreArray where the mc reco tracks will be stored
222  :param reco_tracks: Name of the StoreArray where the reco tracks should be stored
223  :param use_second_cdc_hits: If true, the second hit information will be used in the CDC track finding.
224  :param split_after_delta_t: If positive, split MCRecoTrack into multiple MCRecoTracks if the time
225  distance between two adjecent SimHits is more than the given value
226  :param matching_method: hit: uses the hit-matching
227  chi2: uses the chi2-matching
228  :param chi2_cutoffs: If chi2 matching method is used, this list defines the individual cut-off values
229  for the chi2 values. Thereby each charged stable particle gets its cut-off
230  value. The order of the pdgs is [11,13,211,2212,321,1000010020]. The default
231  values are determined from a small study investigating chi2 value distribution of
232  trivial matching pairs.
233  :param chi2_linalg: If chi2 matching is used, this defines package used to invert the covariance5
234  matrix. ROOT has been shown to be faster than eigen. If False ROOT is used. If True
235  eigen is used.
236  """
237  if (matching_method == "hit"):
238  path.add_module('TrackFinderMCTruthRecoTracks',
239  RecoTracksStoreArrayName=mc_reco_tracks,
240  WhichParticles=[],
241  UseSecondCDCHits=use_second_cdc_hits,
242  UsePXDHits=is_pxd_used(components),
243  UseSVDHits=is_svd_used(components),
244  UseCDCHits=is_cdc_used(components),
245  SplitAfterDeltaT=split_after_delta_t)
246 
247  path.add_module('MCRecoTracksMatcher',
248  mcRecoTracksStoreArrayName=mc_reco_tracks,
249  prRecoTracksStoreArrayName=reco_tracks,
250  UsePXDHits=is_pxd_used(components),
251  UseSVDHits=is_svd_used(components),
252  UseCDCHits=is_cdc_used(components))
253 
254  path.add_module('TrackToMCParticleRelator')
255 
256  elif (matching_method == "chi2"):
257  print("Warning: The Chi2MCTrackMatcherModule is currently not fully developed and tested!")
258  path.add_module('Chi2MCTrackMatcherModule',
259  CutOffs=chi2_cutoffs,
260  linalg=chi2_linalg)
261 
262 
263 def add_prune_tracks(path, components=None, reco_tracks="RecoTracks"):
264  """
265  Adds removal of the intermediate states at each measurement from the fitted tracks.
266 
267  :param path: The path to add the tracking reconstruction modules to
268  :param components: the list of geometry components in use or None for all components.
269  :param reco_tracks: Name of the StoreArray where the reco tracks should be stored
270  """
271 
272  # do not add any pruning, if no tracking detectors are in the components
273  if components and not ('SVD' in components or 'CDC' in components):
274  return
275 
276  path.add_module('PruneRecoTracks', storeArrayName=reco_tracks)
277  path.add_module("PruneGenfitTracks")
278 
279 
280 def add_flipping_of_recoTracks(path, fit_tracks=True, reco_tracks="RecoTracks", trackFitHypotheses=None):
281  """
282  This function adds the mva based selections and the flipping of the recoTracks
283 
284  :param path: The path to add the tracking reconstruction modules to
285  :param fit_tracks: fit the flipped recotracks or not
286  :param reco_tracks: Name of the StoreArray where the reco tracks should be flipped
287  :param trackFitHypotheses: Which pdg hypothesis to fit. Defaults to [211, 321, 2212].
288  """
289 
290  path.add_module("FlipQuality", recoTracksStoreArrayName=reco_tracks,
291  identifier='TRKTrackFlipAndRefit_MVA1_weightfile',
292  indexOfFlippingMVA=1).set_name("FlipQuality_1stMVA")
293 
294  reco_tracks_flipped = "RecoTracks_flipped"
295  path.add_module("RecoTracksReverter", inputStoreArrayName=reco_tracks,
296  outputStoreArrayName=reco_tracks_flipped)
297  if fit_tracks:
298  path.add_module("DAFRecoFitter", recoTracksStoreArrayName=reco_tracks_flipped).set_name("Combined_DAFRecoFitter_flipped")
299  path.add_module("IPTrackTimeEstimator",
300  recoTracksStoreArrayName=reco_tracks_flipped, useFittedInformation=False)
301  path.add_module("TrackCreator", trackColName="Tracks_flipped",
302  trackFitResultColName="TrackFitResults_flipped",
303  recoTrackColName=reco_tracks_flipped,
304  pdgCodes=[
305  211,
306  321,
307  2212] if not trackFitHypotheses else trackFitHypotheses).set_name("TrackCreator_flipped")
308  path.add_module("FlipQuality", recoTracksStoreArrayName=reco_tracks,
309  identifier='TRKTrackFlipAndRefit_MVA2_weightfile',
310  indexOfFlippingMVA=2).set_name("FlipQuality_2ndMVA")
311  path.add_module("FlippedRecoTracksMerger",
312  inputStoreArrayName=reco_tracks,
313  inputStoreArrayNameFlipped=reco_tracks_flipped)
314 
315 
316 def add_pxd_track_finding(path, components, input_reco_tracks, output_reco_tracks, use_mc_truth=False,
317  add_both_directions=False, temporary_reco_tracks="PXDRecoTracks", **kwargs):
318  """Add the pxd track finding to the path"""
319  if not is_pxd_used(components):
320  return
321 
322  if use_mc_truth:
323  # MC CKF needs MC matching information
324  path.add_module("MCRecoTracksMatcher", UsePXDHits=False,
325  UseSVDHits=is_svd_used(components), UseCDCHits=is_cdc_used(components),
326  mcRecoTracksStoreArrayName="MCRecoTracks",
327  prRecoTracksStoreArrayName=input_reco_tracks)
328 
329  add_pxd_ckf(path, svd_cdc_reco_tracks=input_reco_tracks, pxd_reco_tracks=temporary_reco_tracks,
330  direction="backward", use_mc_truth=use_mc_truth, **kwargs)
331 
332  if add_both_directions:
333  add_pxd_ckf(path, svd_cdc_reco_tracks=input_reco_tracks, pxd_reco_tracks=temporary_reco_tracks,
334  direction="forward", use_mc_truth=use_mc_truth, **kwargs)
335 
336  path.add_module("RelatedTracksCombiner", CDCRecoTracksStoreArrayName=input_reco_tracks,
337  VXDRecoTracksStoreArrayName=temporary_reco_tracks, recoTracksStoreArrayName=output_reco_tracks)
338 
339 
340 def add_pxd_cr_track_finding(path, components, input_reco_tracks, output_reco_tracks, use_mc_truth=False,
341  add_both_directions=False, temporary_reco_tracks="PXDRecoTracks", **kwargs):
342  """Add the pxd track finding to the path"""
343  if not is_pxd_used(components):
344  return
345 
346  if use_mc_truth:
347  # MC CKF needs MC matching information
348  path.add_module("MCRecoTracksMatcher", UsePXDHits=False,
349  UseSVDHits=is_svd_used(components), UseCDCHits=is_cdc_used(components),
350  mcRecoTracksStoreArrayName="MCRecoTracks",
351  prRecoTracksStoreArrayName=input_reco_tracks)
352 
353  add_cosmics_pxd_ckf(path, svd_cdc_reco_tracks=input_reco_tracks, pxd_reco_tracks=temporary_reco_tracks,
354  direction="backward", use_mc_truth=use_mc_truth, **kwargs)
355 
356  if add_both_directions:
357  add_cosmics_pxd_ckf(path, svd_cdc_reco_tracks=input_reco_tracks, pxd_reco_tracks=temporary_reco_tracks,
358  direction="forward", use_mc_truth=use_mc_truth, **kwargs)
359 
360  path.add_module("RelatedTracksCombiner", CDCRecoTracksStoreArrayName=input_reco_tracks,
361  VXDRecoTracksStoreArrayName=temporary_reco_tracks, recoTracksStoreArrayName=output_reco_tracks)
362 
363 
364 def add_svd_track_finding(
365  path,
366  components,
367  input_reco_tracks,
368  output_reco_tracks,
369  svd_ckf_mode="SVD_after",
370  use_mc_truth=False,
371  add_both_directions=True,
372  temporary_reco_tracks="SVDRecoTracks",
373  temporary_svd_cdc_reco_tracks="SVDPlusCDCStandaloneRecoTracks",
374  use_svd_to_cdc_ckf=True,
375  prune_temporary_tracks=True,
376  add_mva_quality_indicator=False,
377  svd_standalone_mode="VXDTF2",
378  **kwargs,
379 ):
380  """
381  Add SVD track finding to the path.
382 
383  :param path: The path to add the tracking reconstruction modules to
384  :param components: The list of geometry components in use or None for all components.
385  :param input_reco_tracks: Name of the StoreArray with the input reco tracks (usually from CDC) that are used in the
386  CKF track finding and are merged with the newly found SVD tracks into the ``output_reco_tracks``.
387  :param output_reco_tracks: Name of the StoreArray where the reco tracks outputted by the SVD track finding should be
388  stored.
389  :param svd_ckf_mode: String designating the mode of the CDC-to-SVD CKF, that is how it is combined with the SVD
390  standalone track finding. One of "SVD_after", "SVD_before", "SVD_before_with_second_ckf",
391  "only_ckf", "SVD_alone", "cosmics".
392  :param use_mc_truth: Add mc matching and use the MC information in the CKF (but not in the VXDTF2)
393  :param add_both_directions: Whether to add the CKF with both forward and backward extrapolation directions instead
394  of just one.
395  :param temporary_reco_tracks: Intermediate store array where the SVD tracks from the SVD standalone track finding
396  are stored, before they are merged with CDC tracks and extended via the CKF tracking.
397  :param temporary_svd_cdc_reco_tracks: Intermediate store array where the combination of ``temporary_reco_tracks``
398  (from SVD) and ``input_reco_tracks`` (from CDC standalone) is stored, before the CKF is applied.
399  It is only used if ``use_svd_to_cdc_ckf`` is true. Otherwise, the combination is stored directly in
400  ``output_reco_tracks``.
401  :param use_svd_to_cdc_ckf: Whether to enable the CKF extrapolation from the SVD into the CDC.
402  That CKF application is not affected by ``svd_ckf_mode``.
403  :param prune_temporary_tracks: Delete all hits expect the first and last from intermediate track objects.
404  :param add_mva_quality_indicator: Add the VXDQualityEstimatorMVA module to set the quality indicator
405  property for tracks from VXDTF2 standalone tracking
406  (ATTENTION: Standard triplet QI of VXDTF2 is replaced in this case
407  -> setting this option to 'True' will have some influence on the final track collection)
408  :param svd_standalone_mode: Which SVD standalone tracking is used.
409  Options are "VXDTF2", "SVDHough", "VXDTF2_and_SVDHough", and "SVDHough_and_VXDTF2".
410  Defaults to "VXDTF2"
411  """
412 
413  if not is_svd_used(components):
414  return
415 
416  if not input_reco_tracks:
417  # We do not have an input track store array. So lets just add vxdtf track finding
418  add_svd_standalone_tracking(path, components=["SVD"],
419  svd_standalone_mode=svd_standalone_mode,
420  reco_tracks=output_reco_tracks,
421  add_mva_quality_indicator=add_mva_quality_indicator)
422  return
423 
424  if use_mc_truth:
425  # MC CKF needs MC matching information
426  path.add_module("MCRecoTracksMatcher", UsePXDHits=False, UseSVDHits=False,
427  UseCDCHits=is_cdc_used(components),
428  mcRecoTracksStoreArrayName="MCRecoTracks",
429  prRecoTracksStoreArrayName=input_reco_tracks)
430 
431  if svd_ckf_mode == "SVD_before":
432  add_svd_standalone_tracking(path, components=["SVD"],
433  svd_standalone_mode=svd_standalone_mode,
434  reco_tracks=temporary_reco_tracks,
435  add_mva_quality_indicator=add_mva_quality_indicator)
436  add_ckf_based_merger(path, cdc_reco_tracks=input_reco_tracks, svd_reco_tracks=temporary_reco_tracks,
437  use_mc_truth=use_mc_truth, direction="backward", **kwargs)
438  if add_both_directions:
439  add_ckf_based_merger(path, cdc_reco_tracks=input_reco_tracks, svd_reco_tracks=temporary_reco_tracks,
440  use_mc_truth=use_mc_truth, direction="forward", **kwargs)
441 
442  elif svd_ckf_mode == "SVD_before_with_second_ckf":
443  add_svd_standalone_tracking(path, components=["SVD"],
444  svd_standalone_mode=svd_standalone_mode,
445  reco_tracks=temporary_reco_tracks,
446  add_mva_quality_indicator=add_mva_quality_indicator)
447  add_ckf_based_merger(path, cdc_reco_tracks=input_reco_tracks, svd_reco_tracks=temporary_reco_tracks,
448  use_mc_truth=use_mc_truth, direction="backward", **kwargs)
449  if add_both_directions:
450  add_ckf_based_merger(path, cdc_reco_tracks=input_reco_tracks, svd_reco_tracks=temporary_reco_tracks,
451  use_mc_truth=use_mc_truth, direction="forward", **kwargs)
452  add_svd_ckf(path, cdc_reco_tracks=input_reco_tracks, svd_reco_tracks=temporary_reco_tracks,
453  use_mc_truth=use_mc_truth, direction="backward", **kwargs)
454  if add_both_directions:
455  add_svd_ckf(path, cdc_reco_tracks=input_reco_tracks, svd_reco_tracks=temporary_reco_tracks,
456  use_mc_truth=use_mc_truth, direction="forward", **kwargs)
457 
458  elif svd_ckf_mode == "only_ckf":
459  add_svd_ckf(path, cdc_reco_tracks=input_reco_tracks, svd_reco_tracks=temporary_reco_tracks,
460  use_mc_truth=use_mc_truth, direction="backward", **kwargs)
461  if add_both_directions:
462  add_svd_ckf(path, cdc_reco_tracks=input_reco_tracks, svd_reco_tracks=temporary_reco_tracks,
463  use_mc_truth=use_mc_truth, direction="forward", **kwargs)
464 
465  elif svd_ckf_mode == "SVD_after":
466  add_svd_ckf(path, cdc_reco_tracks=input_reco_tracks, svd_reco_tracks=temporary_reco_tracks,
467  use_mc_truth=use_mc_truth, direction="backward", **kwargs)
468  if add_both_directions:
469  add_svd_ckf(path, cdc_reco_tracks=input_reco_tracks, svd_reco_tracks=temporary_reco_tracks,
470  use_mc_truth=use_mc_truth, direction="forward", **kwargs)
471 
472  add_svd_standalone_tracking(path, components=["SVD"],
473  svd_standalone_mode=svd_standalone_mode,
474  reco_tracks=temporary_reco_tracks,
475  add_mva_quality_indicator=add_mva_quality_indicator)
476  add_ckf_based_merger(path, cdc_reco_tracks=input_reco_tracks, svd_reco_tracks=temporary_reco_tracks,
477  use_mc_truth=use_mc_truth, direction="backward", **kwargs)
478  if add_both_directions:
479  add_ckf_based_merger(path, cdc_reco_tracks=input_reco_tracks, svd_reco_tracks=temporary_reco_tracks,
480  use_mc_truth=use_mc_truth, direction="forward", **kwargs)
481 
482  elif svd_ckf_mode == "SVD_alone":
483  add_svd_standalone_tracking(path, components=["SVD"],
484  svd_standalone_mode=svd_standalone_mode,
485  reco_tracks=temporary_reco_tracks,
486  add_mva_quality_indicator=add_mva_quality_indicator)
487  path.add_module('VXDCDCTrackMerger',
488  CDCRecoTrackColName=input_reco_tracks,
489  VXDRecoTrackColName=temporary_reco_tracks)
490 
491  elif svd_ckf_mode == "cosmics":
492  add_cosmics_svd_ckf(path, cdc_reco_tracks=input_reco_tracks, svd_reco_tracks=temporary_reco_tracks,
493  use_mc_truth=use_mc_truth, direction="backward", **kwargs)
494  if add_both_directions:
495  add_cosmics_svd_ckf(path, cdc_reco_tracks=input_reco_tracks, svd_reco_tracks=temporary_reco_tracks,
496  use_mc_truth=use_mc_truth, direction="forward", **kwargs)
497 
498  else:
499  raise ValueError(f"Do not understand the svd_ckf_mode {svd_ckf_mode}")
500 
501  if use_svd_to_cdc_ckf:
502  combined_svd_cdc_standalone_tracks = temporary_svd_cdc_reco_tracks
503  else:
504  combined_svd_cdc_standalone_tracks = output_reco_tracks
505 
506  # Write out the combinations of tracks
507  path.add_module("RelatedTracksCombiner", VXDRecoTracksStoreArrayName=temporary_reco_tracks,
508  CDCRecoTracksStoreArrayName=input_reco_tracks,
509  recoTracksStoreArrayName=combined_svd_cdc_standalone_tracks)
510 
511  if use_svd_to_cdc_ckf:
512  path.add_module("ToCDCCKF",
513  inputWireHits="CDCWireHitVector",
514  inputRecoTrackStoreArrayName=combined_svd_cdc_standalone_tracks,
515  relatedRecoTrackStoreArrayName="CKFCDCRecoTracks",
516  relationCheckForDirection="backward",
517  ignoreTracksWithCDChits=True,
518  outputRecoTrackStoreArrayName="CKFCDCRecoTracks",
519  outputRelationRecoTrackStoreArrayName=combined_svd_cdc_standalone_tracks,
520  writeOutDirection="backward",
521  stateBasicFilterParameters={"maximalHitDistance": 0.15},
522  pathFilter="arc_length",
523  maximalLayerJump=4)
524 
525  path.add_module("CDCCKFTracksCombiner",
526  CDCRecoTracksStoreArrayName="CKFCDCRecoTracks",
527  VXDRecoTracksStoreArrayName=combined_svd_cdc_standalone_tracks,
528  recoTracksStoreArrayName=output_reco_tracks)
529 
530  if prune_temporary_tracks:
531  for temp_reco_track in [combined_svd_cdc_standalone_tracks, "CKFCDCRecoTracks"]:
532  path.add_module('PruneRecoTracks', storeArrayName=temp_reco_track)
533 
534 
535 def add_svd_standalone_tracking(path,
536  components=["SVD"],
537  svd_clusters="",
538  svd_standalone_mode="VXDTF2",
539  reco_tracks="SVDRecoTracks",
540  add_mva_quality_indicator=False,
541  suffix=""):
542  """
543  Convenience function to add the SVD standalone tracking
544 
545  :param path: basf2 path
546  :param components: components to use, defaults to SVD
547  :param svd_clusters: Name of the SVDClusters StoreArray used for tracking
548  :param svd_standalone_mode: Which SVD standalone tracking is used.
549  Options are "VXDTF2", "SVDHough", "VXDTF2_and_SVDHough", and "SVDHough_and_VXDTF2".
550  Defaults to "VXDTF2"
551  :param reco_tracks: In case the only SVD standalone tracking is performed, these are the final RecoTracks,
552  otherwise it's an intermediate StoreaArray where the SVD tracks from the SVD standalone track finding
553  are stored, before they are merged with CDC tracks and extended via the CKF tracking.
554  :param add_mva_quality_indicator: Add the VXDQualityEstimatorMVA module to set the quality indicator
555  property for tracks from VXDTF2 standalone tracking
556  (ATTENTION: Standard triplet QI of VXDTF2 is replaced in this case
557  -> setting this option to 'True' will have some influence on the final track collection)
558  :param suffix: all names of intermediate Storearrays will have the suffix appended. Useful in cases someone needs to
559  put several instances of track finding in one path.
560  """
561  if svd_standalone_mode == "VXDTF2":
562  add_vxd_track_finding_vxdtf2(path, components=components, svd_clusters=svd_clusters, reco_tracks=reco_tracks,
563  add_mva_quality_indicator=add_mva_quality_indicator, suffix=suffix)
564 
565  elif svd_standalone_mode == "SVDHough":
566  add_svd_hough_tracking(path, reco_tracks=reco_tracks, suffix=suffix)
567 
568  elif svd_standalone_mode == "VXDTF2_and_SVDHough":
569  add_vxd_track_finding_vxdtf2(path,
570  components=components,
571  svd_clusters=svd_clusters,
572  nameSPTCs="SPTrackCands"+"VXDTF2",
573  reco_tracks=reco_tracks+"VXDTF2",
574  add_mva_quality_indicator=add_mva_quality_indicator,
575  suffix=suffix)
576  add_svd_hough_tracking(path,
577  reco_tracks=reco_tracks+"Hough",
578  svd_space_point_track_candidates="SPTrackCands"+"Hough",
579  suffix=suffix)
580 
581  path.add_module('RecoTrackStoreArrayCombiner',
582  Temp1RecoTracksStoreArrayName=reco_tracks+"VXDTF2",
583  Temp2RecoTracksStoreArrayName=reco_tracks+"Hough",
584  recoTracksStoreArrayName=reco_tracks)
585  path.add_module('PruneRecoTracks', storeArrayName=reco_tracks+"VXDTF2")
586  path.add_module('PruneRecoTracks', storeArrayName=reco_tracks+"Hough")
587 
588  elif svd_standalone_mode == "SVDHough_and_VXDTF2":
589  add_svd_hough_tracking(path,
590  reco_tracks=reco_tracks+"Hough",
591  svd_space_point_track_candidates="SPTrackCands"+"Hough",
592  suffix=suffix)
593  add_vxd_track_finding_vxdtf2(path,
594  components=components,
595  svd_clusters=svd_clusters,
596  nameSPTCs="SPTrackCands"+"VXDTF2",
597  reco_tracks=reco_tracks+"VXDTF2",
598  add_mva_quality_indicator=add_mva_quality_indicator,
599  suffix=suffix)
600 
601  path.add_module('RecoTrackStoreArrayCombiner',
602  Temp1RecoTracksStoreArrayName=reco_tracks+"Hough",
603  Temp2RecoTracksStoreArrayName=reco_tracks+"VXDTF2",
604  recoTracksStoreArrayName=reco_tracks)
605  path.add_module('PruneRecoTracks', storeArrayName=reco_tracks+"Hough")
606  path.add_module('PruneRecoTracks', storeArrayName=reco_tracks+"VXDTF2")
607 
608  else:
609  raise ValueError(f"Do not understand the svd_standalone_mode {svd_standalone_mode}")
610 
611 
612 def add_cdc_track_finding(path, output_reco_tracks="RecoTracks", with_ca=False,
613  use_second_hits=False, add_mva_quality_indicator=True,
614  reattach_hits=False):
615  """
616  Convenience function for adding all cdc track finder modules
617  to the path.
618 
619  The result is a StoreArray with name @param reco_tracks full of RecoTracks (not TrackCands any more!).
620  Use the GenfitTrackCandidatesCreator Module to convert back.
621 
622  :param path: basf2 path
623  :param output_reco_tracks: Name of the output RecoTracks. Defaults to RecoTracks.
624  :param use_second_hits: If true, the second hit information will be used in the CDC track finding.
625  :param add_mva_quality_indicator: Add the TFCDC_TrackQualityEstimator module to set the CDC quality
626  indicator property of the CDC ``output_reco_tracks``
627  :param cdc_quality_estimator_weightfile: Weightfile identifier for the TFCDC_TrackQualityEstimator
628  :param reattach_hits: if true, use the ReattachCDCWireHitsToRecoTracks module at the end of the CDC track finding
629  to readd hits with bad ADC or TOT rejected by the TFCDC_WireHitPreparer module.
630  """
631  # add EventLevelTrackinginfo for logging errors
632  if 'RegisterEventLevelTrackingInfo' not in path:
633  path.add_module('RegisterEventLevelTrackingInfo')
634 
635  # Init the geometry for cdc tracking and the hits and cut low ADC hits
636  path.add_module("TFCDC_WireHitPreparer",
637  wirePosition="aligned",
638  useSecondHits=use_second_hits,
639  flightTimeEstimation="outwards",
640  filter="cuts_from_DB")
641 
642  # Constructs clusters
643  path.add_module("TFCDC_ClusterPreparer",
644  ClusterFilter="all",
645  ClusterFilterParameters={})
646 
647  # Find segments within the clusters
648  path.add_module("TFCDC_SegmentFinderFacetAutomaton",
649  SegmentRelationFilterParameters={'DBPayloadName': 'trackfindingcdc_RealisticSegmentRelationFilterParameters'})
650 
651  # Find axial tracks
652  path.add_module("TFCDC_AxialTrackFinderLegendre")
653 
654  # Improve the quality of the axial tracks
655  path.add_module("TFCDC_TrackQualityAsserter",
656  corrections=["B2B"])
657 
658  # Find the stereo hits to those axial tracks
659  path.add_module('TFCDC_StereoHitFinder')
660 
661  # Combine segments with axial tracks
662  path.add_module('TFCDC_SegmentTrackCombiner',
663  segmentTrackFilter="mva",
664  segmentTrackFilterParameters={'DBPayloadName': 'trackfindingcdc_SegmentTrackFilterParameters'},
665  trackFilter="mva",
666  trackFilterParameters={'DBPayloadName': 'trackfindingcdc_TrackFilterParameters'})
667 
668  output_tracks = "CDCTrackVector"
669 
670  if with_ca:
671  output_tracks = "CombinedCDCTrackVector"
672  path.add_module("TFCDC_TrackFinderSegmentPairAutomaton",
673  tracks="CDCTrackVector2")
674 
675  # Overwrites the origin CDCTrackVector
676  path.add_module("TFCDC_TrackCombiner",
677  inputTracks="CDCTrackVector",
678  secondaryInputTracks="CDCTrackVector2",
679  tracks=output_tracks)
680 
681  # Improve the quality of all tracks and output
682  path.add_module("TFCDC_TrackQualityAsserter",
683  inputTracks=output_tracks,
684  corrections=[
685  "LayerBreak",
686  "OneSuperlayer",
687  "Small",
688  ])
689 
690  if with_ca:
691  # Add curlers in the axial inner most superlayer
692  path.add_module("TFCDC_TrackCreatorSingleSegments",
693  inputTracks=output_tracks,
694  MinimalHitsBySuperLayerId={0: 15})
695 
696  if add_mva_quality_indicator:
697  # Add CDC-specific mva method to set the quality indicator for the CDC tracks
698  path.add_module(
699  "TFCDC_TrackQualityEstimator",
700  inputTracks=output_tracks,
701  filter='mva',
702  filterParameters={'DBPayloadName': 'trackfindingcdc_TrackQualityEstimatorParameters'},
703  deleteTracks=True,
704  resetTakenFlag=True
705  )
706 
707  # Export CDCTracks to RecoTracks representation
708  path.add_module("TFCDC_TrackExporter",
709  inputTracks=output_tracks,
710  RecoTracksStoreArrayName="CDCRecoTracksBeforeReattaching" if reattach_hits else output_reco_tracks)
711 
712  if reattach_hits:
713  # The ReattachCDCWireHitsToRecoTracks module (below) requires the SetupGenfitExtrapolation module
714  if 'SetupGenfitExtrapolation' not in path:
715  # Prepare Genfit extrapolation
716  path.add_module('SetupGenfitExtrapolation')
717 
718  # Loop over low-ADC/TOT CDCWireHits and RecoTracks and reattach the hits to the tracks if they are close enough
719  path.add_module("ReattachCDCWireHitsToRecoTracks",
720  inputRecoTracksStoreArrayName="CDCRecoTracksBeforeReattaching",
721  outputRecoTracksStoreArrayName=output_reco_tracks)
722 
723  # Correct time seed (only necessary for the CDC tracks)
724  path.add_module("IPTrackTimeEstimator",
725  useFittedInformation=False,
726  recoTracksStoreArrayName=output_reco_tracks)
727 
728  # run fast t0 estimation from CDC hits only
729  path.add_module("CDCHitBasedT0Extraction")
730 
731  # prepare mdst event level info
732  path.add_module("CDCTrackingEventLevelMdstInfoFiller")
733 
734 
735 def add_eclcdc_track_finding(path, components, output_reco_tracks="RecoTracks", prune_temporary_tracks=True):
736  """
737  Convenience function for adding all track finder modules to the path that are based on ecl seeds.
738 
739  The result is a StoreArray with name @param reco_tracks full of RecoTracks.
740  Use the GenfitTrackCandidatesCreator Module to convert back.
741 
742  :param path: basf2 path
743  :param components: the list of geometry components in use or None for all components.
744  :param output_reco_tracks: Name of the output RecoTracks. Defaults to RecoTracks.
745  :param pruneTracks: Delete all hits expect the first and the last from the found tracks.
746  """
747  if not is_cdc_used(components) or not is_ecl_used(components):
748  return
749 
750  ecl_cdc_reco_tracks = "ECLCDCRecoTracks"
751 
752  if not is_svd_used(components):
753  ecl_cdc_reco_tracks = output_reco_tracks
754 
755  # collections that will be pruned
756  temporary_reco_track_list = []
757 
758  path.add_module("ToCDCFromEclCKF",
759  inputWireHits="CDCWireHitVector",
760  minimalEnRequirementCluster=0.3,
761  eclSeedRecoTrackStoreArrayName='EclSeedRecoTracks',
762  hitFindingDirection="backward",
763  outputRecoTrackStoreArrayName="CDCRecoTracksFromEcl",
764  outputRelationRecoTrackStoreArrayName="EclSeedRecoTracks",
765  writeOutDirection="forward",
766  stateBasicFilterParameters={"maximalHitDistance": 7.5, "maximalHitDistanceEclSeed": 75.0},
767  stateExtrapolationFilterParameters={"direction": "backward"},
768  pathFilter="arc_length_fromEcl",
769  inputECLshowersStoreArrayName="ECLShowers",
770  trackFindingDirection="backward",
771  setTakenFlag=False,
772  seedComponent="ECL"
773  )
774 
775  path.add_module("ToCDCCKF",
776  inputWireHits="CDCWireHitVector",
777  inputRecoTrackStoreArrayName="CDCRecoTracksFromEcl",
778  relatedRecoTrackStoreArrayName=ecl_cdc_reco_tracks,
779  relationCheckForDirection="backward",
780  outputRecoTrackStoreArrayName=ecl_cdc_reco_tracks,
781  outputRelationRecoTrackStoreArrayName="CDCRecoTracksFromEcl",
782  writeOutDirection="backward",
783  stateBasicFilterParameters={"maximalHitDistance": 0.75},
784  stateExtrapolationFilterParameters={"direction": "forward"},
785  pathFilter="arc_length",
786  seedComponent="ECL"
787  )
788  # "EclSeedRecoTracks" don't have to be added to the list as these do not contain any hits
789  temporary_reco_track_list.append('CDCRecoTracksFromEcl')
790 
791  # Do the following modules have to be added as these are executed already after
792  # the CDC standalone?
793  # If so: they also have to be included in the new SVD->CDC CKF (see add_svd_track_finding(..) above)
794 
795  # Correct time seed (only necessary for the CDC tracks)
796  # path.add_module("IPTrackTimeEstimator",
797  # useFittedInformation=False,
798  # recoTracksStoreArrayName=ecl_cdc_reco_tracks)
799 
800  # run fast t0 estimation from CDC hits only
801  # path.add_module("CDCHitBasedT0Extraction")
802 
803  # prepare mdst event level info
804  # path.add_module("CDCTrackingEventLevelMdstInfoFiller")
805 
806  if is_svd_used(components):
807  add_svd_track_finding(path, components=components, input_reco_tracks=ecl_cdc_reco_tracks,
808  output_reco_tracks=output_reco_tracks, use_mc_truth=False,
809  svd_ckf_mode="only_ckf", add_both_directions=False,
810  temporary_reco_tracks="ECLSVDRecoTracks", use_svd_to_cdc_ckf=False,
811  prune_temporary_tracks=prune_temporary_tracks)
812  temporary_reco_track_list.append(ecl_cdc_reco_tracks)
813  temporary_reco_track_list.append('ECLSVDRecoTracks')
814 
815  if prune_temporary_tracks:
816  for temporary_reco_track_name in temporary_reco_track_list:
817  if temporary_reco_track_name != output_reco_tracks:
818  path.add_module('PruneRecoTracks', storeArrayName=temporary_reco_track_name)
819 
820 
821 def add_cdc_cr_track_finding(path, output_reco_tracks="RecoTracks", trigger_point=(0, 0, 0), merge_tracks=True,
822  use_second_cdc_hits=False):
823  """
824  Convenience function for adding all cdc track finder modules currently dedicated for the CDC-TOP testbeam
825  to the path.
826 
827  The result is a StoreArray with name @param reco_tracks full of RecoTracks (not TrackCands any more!).
828 
829  Arguments
830  ---------
831  path: basf2.Path
832  The path to be filled
833  output_reco_tracks: str
834  Name of the output RecoTracks. Defaults to RecoTracks.
835  merge_tracks: bool
836  The upper and lower half of the tracks should be merged together in one track
837  use_second_hits: bool
838  If true, the second hit information will be used in the CDC track finding.
839  """
840 
841  # Init the geometry for cdc tracking and the hits
842  path.add_module("TFCDC_WireHitPreparer",
843  useSecondHits=use_second_cdc_hits,
844  flightTimeEstimation="downwards",
845  filter="cuts_from_DB",
846  triggerPoint=trigger_point)
847 
848  # Constructs clusters and reduce background hits
849  path.add_module("TFCDC_ClusterPreparer",
850  ClusterFilter="mva_bkg",
851  ClusterFilterParameters={'DBPayloadName': 'trackfindingcdc_ClusterFilterParameters'})
852 
853  # Find segments within the clusters
854  path.add_module("TFCDC_SegmentFinderFacetAutomaton",
855  SegmentOrientation="downwards")
856 
857  # Find axial tracks
858  path.add_module("TFCDC_AxialTrackFinderLegendre")
859 
860  # Improve the quality of the axial tracks
861  path.add_module("TFCDC_TrackQualityAsserter",
862  corrections=["B2B"])
863 
864  # Find the stereo hits to those axial tracks
865  path.add_module('TFCDC_StereoHitFinder')
866 
867  # Combine segments with axial tracks
868  path.add_module('TFCDC_SegmentTrackCombiner',
869  segmentTrackFilter="mva",
870  segmentTrackFilterParameters={'DBPayloadName': 'trackfindingcdc_SegmentTrackFilterParameters'},
871  trackFilter="mva",
872  trackFilterParameters={'DBPayloadName': 'trackfindingcdc_TrackFilterParameters'})
873 
874  # Improve the quality of all tracks and output
875  path.add_module("TFCDC_TrackQualityAsserter",
876  corrections=["LayerBreak", "OneSuperlayer", "Small"],
877  )
878 
879  # Flip track orientation to always point downwards
880  path.add_module("TFCDC_TrackOrienter",
881  inputTracks="CDCTrackVector",
882  tracks="OrientedCDCTrackVector",
883  TrackOrientation="downwards",
884  )
885 
886  output_tracks = "OrientedCDCTrackVector"
887 
888  if merge_tracks:
889  # Merge tracks together if needed
890  path.add_module("TFCDC_TrackLinker",
891  inputTracks="OrientedCDCTrackVector",
892  tracks="MergedCDCTrackVector",
893  filter="phi",
894  )
895  output_tracks = "MergedCDCTrackVector"
896 
897  # However, we also want to export the non merged tracks
898  # Correct time seed - assumes velocity near light speed
899  path.add_module("TFCDC_TrackFlightTimeAdjuster",
900  inputTracks="OrientedCDCTrackVector",
901  )
902 
903  # Export CDCTracks to RecoTracks representation
904  path.add_module("TFCDC_TrackExporter",
905  inputTracks="OrientedCDCTrackVector",
906  RecoTracksStoreArrayName="NonMergedRecoTracks")
907 
908  # Correct time seed - assumes velocity near light speed
909  path.add_module("TFCDC_TrackFlightTimeAdjuster",
910  inputTracks=output_tracks,
911  )
912 
913  # Export CDCTracks to RecoTracks representation
914  path.add_module("TFCDC_TrackExporter",
915  inputTracks=output_tracks,
916  RecoTracksStoreArrayName=output_reco_tracks)
917 
918  # run fast t0 estimation from CDC hits only
919  path.add_module("CDCHitBasedT0Extraction")
920 
921 
922 def add_vxd_track_finding_vxdtf2(
923  path,
924  svd_clusters="",
925  reco_tracks="RecoTracks",
926  nameSPTCs='SPTrackCands',
927  components=None,
928  suffix="",
929  useTwoStepSelection=True,
930  PXDminSVDSPs=3,
931  sectormap_file=None,
932  custom_setup_name=None,
933  min_SPTC_quality=0.,
934  filter_overlapping=True,
935  add_mva_quality_indicator=False,
936 ):
937  """
938  Convenience function for adding all vxd track finder Version 2 modules
939  to the path.
940 
941  The result is a StoreArray with name @param reco_tracks full of RecoTracks (not TrackCands any more!).
942  Use the GenfitTrackCandidatesCreator Module to convert back.
943 
944  :param path: basf2 path
945  :param svd_clusters: SVDCluster collection name
946  :param reco_tracks: Name of the output RecoTracks, Defaults to RecoTracks.
947  :param nameSPTCs: Name of the SpacePointTrackCands StoreArray
948  :param components: List of the detector components to be used in the reconstruction. Defaults to None which means
949  all components.
950  :param suffix: all names of intermediate Storearrays will have the suffix appended. Useful in cases someone needs to
951  put several instances of track finding in one path.
952  :param useTwoStepSelection: if True Families will be defined during path creation and will be used to create only
953  the best candidate per family.
954  :param PXDminSVDSPs: When using PXD require at least this number of SVD SPs for the SPTCs
955  :param sectormap_file: if set to a finite value, a file will be used instead of the sectormap in the database.
956  :param custom_setup_name: Set a custom setup name for the tree in the sector map.
957  :param min_SPTC_quality: minimal qualityIndicator value to keeps SPTCs after the QualityEstimation.
958  0 means no cut. Default: 0
959  :param filter_overlapping: Whether to use SVDOverlapResolver, Default: True
960  :param add_mva_quality_indicator: Whether to use the MVA Quality Estimator module for VXDTF2 tracks to set the
961  quality_indicator property of the found ``reco_tracks``. Default: False.
962  """
963 
966 
967  # setting different for pxd and svd:
968  if is_pxd_used(components):
969  setup_name = "SVDPXDDefault"
970  db_sec_map_file = "VXDSectorMap_v000.root"
971  use_pxd = True
972  else:
973  setup_name = "SVDOnlyDefault"
974  db_sec_map_file = "SVDSectorMap_v000.root"
975  use_pxd = False
976 
977 
981 
982  # setup the event level tracking info to log errors and stuff
983  nameTrackingInfoModule = "RegisterEventLevelTrackingInfo" + suffix
984  nameEventTrackingInfo = "EventLevelTrackingInfo" + suffix
985  if nameTrackingInfoModule not in path:
986  # Use modified name of module and created StoreObj as module might be added twice (PXDDataReduction)
987  registerEventlevelTrackingInfo = register_module('RegisterEventLevelTrackingInfo')
988  registerEventlevelTrackingInfo.set_name(nameTrackingInfoModule)
989  registerEventlevelTrackingInfo.param('EventLevelTrackingInfoName', nameEventTrackingInfo)
990  path.add_module(registerEventlevelTrackingInfo)
991 
992  nameSPs = 'SpacePoints' + suffix
993 
994  pxdSPCreatorName = 'PXDSpacePointCreator' + suffix
995  if pxdSPCreatorName not in [e.name() for e in path.modules()]:
996  if use_pxd:
997  spCreatorPXD = register_module('PXDSpacePointCreator')
998  spCreatorPXD.set_name(pxdSPCreatorName)
999  spCreatorPXD.param('NameOfInstance', 'PXDSpacePoints')
1000  spCreatorPXD.param('SpacePoints', "PXD" + nameSPs)
1001  path.add_module(spCreatorPXD)
1002 
1003  # SecMap Bootstrap
1004  secMapBootStrap = register_module('SectorMapBootstrap')
1005  secMapBootStrap.param('ReadSectorMap', sectormap_file is not None) # read from file
1006  secMapBootStrap.param('ReadSecMapFromDB', sectormap_file is None) # this will override ReadSectorMap
1007  secMapBootStrap.param('SectorMapsInputFile', sectormap_file or db_sec_map_file)
1008  secMapBootStrap.param('SetupToRead', custom_setup_name or setup_name)
1009  secMapBootStrap.param('WriteSectorMap', False)
1010  path.add_module(secMapBootStrap)
1011 
1012 
1016 
1017  spacePointArrayNames = ["SVD" + nameSPs]
1018  if use_pxd:
1019  spacePointArrayNames += ["PXD" + nameSPs]
1020 
1021  nameSegNet = 'SegmentNetwork' + suffix
1022 
1023  segNetProducer = register_module('SegmentNetworkProducer')
1024  segNetProducer.param('NetworkOutputName', nameSegNet)
1025  segNetProducer.param('SpacePointsArrayNames', spacePointArrayNames)
1026  segNetProducer.param('sectorMapName', custom_setup_name or setup_name)
1027  segNetProducer.param('EventLevelTrackingInfoName', nameEventTrackingInfo)
1028  path.add_module(segNetProducer)
1029 
1030 
1034 
1035  # append a suffix to the storearray name
1036  nameSPTCs += suffix
1037 
1038  trackFinder = register_module('TrackFinderVXDCellOMat')
1039  trackFinder.param('NetworkName', nameSegNet)
1040  trackFinder.param('SpacePointTrackCandArrayName', nameSPTCs)
1041  trackFinder.param('printNetworks', False)
1042  trackFinder.param('setFamilies', useTwoStepSelection)
1043  trackFinder.param('selectBestPerFamily', useTwoStepSelection)
1044  trackFinder.param('xBestPerFamily', 30)
1045  trackFinder.param('EventLevelTrackingInfoName', nameEventTrackingInfo)
1046  path.add_module(trackFinder)
1047 
1048  if useTwoStepSelection:
1049  subSetModule = register_module('AddVXDTrackCandidateSubSets')
1050  subSetModule.param('NameSpacePointTrackCands', nameSPTCs)
1051  path.add_module(subSetModule)
1052 
1053 
1057 
1058  # When using PXD require at least PXDminSVDSPs SVD SPs for the SPTCs
1059  if use_pxd:
1060  pxdSVDCut = register_module('PXDSVDCut')
1061  pxdSVDCut.param('minSVDSPs', PXDminSVDSPs)
1062  pxdSVDCut.param('SpacePointTrackCandsStoreArrayName', nameSPTCs)
1063  path.add_module(pxdSVDCut)
1064 
1065  if add_mva_quality_indicator:
1066  path.add_module(
1067  "VXDQualityEstimatorMVA",
1068  SpacePointTrackCandsStoreArrayName=nameSPTCs,
1069  )
1070  else:
1071  path.add_module(
1072  'QualityEstimatorVXD',
1073  EstimationMethod='tripletFit',
1074  SpacePointTrackCandsStoreArrayName=nameSPTCs,
1075  )
1076 
1077  if min_SPTC_quality > 0.:
1078  qualityIndicatorCutter = register_module('VXDTrackCandidatesQualityIndicatorCutter')
1079  qualityIndicatorCutter.param('minRequiredQuality', min_SPTC_quality)
1080  qualityIndicatorCutter.param('NameSpacePointTrackCands', nameSPTCs)
1081  path.add_module(qualityIndicatorCutter)
1082 
1083  # will discard track candidates (with low quality estimators) if the number of TC is above threshold
1084  maxCandidateSelection = register_module('BestVXDTrackCandidatesSelector')
1085  maxCandidateSelection.param('NameSpacePointTrackCands', nameSPTCs)
1086  maxCandidateSelection.param('NewNameSpacePointTrackCands', nameSPTCs)
1087  maxCandidateSelection.param('SubsetCreation', False)
1088  path.add_module(maxCandidateSelection)
1089 
1090  # Properties
1091  vIPRemover = register_module('SPTCvirtualIPRemover')
1092  vIPRemover.param('tcArrayName', nameSPTCs)
1093  # want to remove virtualIP for any track length
1094  vIPRemover.param('maxTCLengthForVIPKeeping', 0)
1095  path.add_module(vIPRemover)
1096 
1097 
1101 
1102  if filter_overlapping:
1103  overlapResolver = register_module('SVDOverlapResolver')
1104  overlapResolver.param('NameSpacePointTrackCands', nameSPTCs)
1105  overlapResolver.param('ResolveMethod', 'greedy') # other option is 'hopfield'
1106  overlapResolver.param('NameSVDClusters', svd_clusters)
1107  path.add_module(overlapResolver)
1108 
1109 
1113 
1114  momSeedRetriever = register_module('SPTCmomentumSeedRetriever')
1115  momSeedRetriever.param('tcArrayName', nameSPTCs)
1116  path.add_module(momSeedRetriever)
1117 
1118  converter = register_module('SPTC2RTConverter')
1119  converter.param('recoTracksStoreArrayName', reco_tracks)
1120  converter.param('spacePointsTCsStoreArrayName', nameSPTCs)
1121  converter.param('svdClustersName', svd_clusters)
1122  converter.param('svdHitsStoreArrayName', svd_clusters)
1123  path.add_module(converter)
1124 
1125 
1126 def add_svd_hough_tracking(path,
1127  svd_space_points='SVDSpacePoints',
1128  svd_clusters='SVDClusters',
1129  reco_tracks='RecoTracks',
1130  svd_space_point_track_candidates='SPTrackCands',
1131  suffix=''):
1132  """
1133  Convenience function to add the SVDHoughTracking to the path.
1134  :param path: The path to add the SVDHoughTracking module to.
1135  :param svd_space_points: Name of the StoreArray containing the SVDSpacePoints
1136  :param svd_clusters: Name of the StoreArray containing the SVDClusters
1137  :param reco_tracks: Name of the StoreArray containing the RecoTracks
1138  :param svd_space_point_track_candidates: Name of the StoreArray containing the SpacePointTrackCandidates
1139  :param suffix: all names of intermediate StoreArrays will have the suffix appended. Useful in cases someone needs to
1140  put several instances of track finding in one path.
1141  """
1142 
1143  path.add_module('SVDHoughTracking',
1144  SVDSpacePointStoreArrayName=svd_space_points + suffix,
1145  SVDClustersStoreArrayName=svd_clusters + suffix,
1146  finalOverlapResolverNameSVDClusters=svd_clusters + suffix,
1147  refinerOverlapResolverNameSVDClusters=svd_clusters + suffix,
1148  RecoTracksStoreArrayName=reco_tracks + suffix,
1149  SVDSpacePointTrackCandsStoreArrayName=svd_space_point_track_candidates + suffix,
1150  relationFilter='angleAndTime',
1151  twoHitUseNBestHits=4,
1152  threeHitUseNBestHits=3,
1153  fourHitUseNBestHits=3,
1154  fiveHitUseNBestHits=2,
1155  )
1156 
1157 
1158 def is_svd_used(components):
1159  """Return true, if the SVD is present in the components list"""
1160  return components is None or 'SVD' in components
1161 
1162 
1163 def is_pxd_used(components):
1164  """Return true, if the PXD is present in the components list"""
1165  return components is None or 'PXD' in components
1166 
1167 
1168 def is_cdc_used(components):
1169  """Return true, if the CDC is present in the components list"""
1170  return components is None or 'CDC' in components
1171 
1172 
1173 def is_ecl_used(components):
1174  """Return true, if the ECL is present in the components list"""
1175  return components is None or 'ECL' in components