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