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