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