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