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