Belle II Software release-09-00-00
reconstruction.py
1#!/usr/bin/env python3
2
3
10
11# Limit the number of threads spawned by external libraries (e.g. XGBoost)
12import os
13os.environ['OMP_THREAD_LIMIT'] = "1" # noqa
14
15import basf2
16
17from geometry import check_components
18
19from svd import add_svd_reconstruction
20from pxd import add_pxd_reconstruction
21
22from rawdata import add_unpackers
23
24from softwaretrigger.constants import ALWAYS_SAVE_OBJECTS, RAWDATA_OBJECTS, DEFAULT_HLT_COMPONENTS
25
26from tracking import (
27 add_mc_tracking_reconstruction,
28 add_prefilter_tracking_reconstruction,
29 add_postfilter_tracking_reconstruction,
30 add_cr_tracking_reconstruction,
31 add_prune_tracks,
32)
33
35 add_filter_software_trigger,
36 add_skim_software_trigger
37)
38
39
40CDST_TRACKING_OBJECTS = (
41 'EventLevelTrackingInfo',
42 'RecoTracks',
43 'Tracks',
44 'V0s',
45 'TrackFitResults',
46 'EventT0',
47 'CDCDedxHits',
48 'CDCDedxTracks',
49 'SVDShaperDigitsFromTracks',
50 'PXDClustersFromTracks',
51 'VXDDedxTracks',
52 'CDCDedxLikelihoods',
53 'VXDDedxLikelihoods'
54)
55
56
57DIGITS_OBJECTS = (
58 'ARICHDigits',
59 'CDCHits',
60 'ECLDigits',
61 'ECLDsps',
62 'KLMDigits',
63 'PXDDigits',
64 'SVDEventInfoSim',
65 'SVDShaperDigits',
66 'TOPDigits'
67)
68
69
70def default_event_abort(module, condition, error_flag):
71 """Default event abort outside of HLT: Ignore the error flag and just stop
72 processing by giving an empty path"""
73 p = basf2.Path()
74 module.if_value(condition, p, basf2.AfterConditionPath.END)
75
76
77def add_reconstruction(path, components=None, pruneTracks=True, add_trigger_calculation=True, skipGeometryAdding=False,
78 trackFitHypotheses=None, addClusterExpertModules=True,
79 use_second_cdc_hits=False, add_muid_hits=False, reconstruct_cdst=None,
80 event_abort=default_event_abort, use_random_numbers_for_hlt_prescale=True,
81 pxd_filtering_offline=False,
82 create_intercepts_for_pxd_ckf=False,
83 append_full_grid_cdc_eventt0=True,
84 legacy_ecl_charged_pid=False, emulate_HLT=False,
85 skip_full_grid_cdc_eventt0_if_svd_time_present=True):
86 """
87 This function adds the standard reconstruction modules to a path.
88 Consists of clustering, tracking and the PID modules essentially in this structure:
89
90 | :func:`add_reconstruction()`
91 | ├── :func:`add_prefilter_reconstruction()`
92 | │ ├── :func:`add_prefilter_pretracking_reconstruction()` : Clustering
93 | │ ├── ``add_prefilter_tracking_reconstruction()`` : Tracking essential for HLT filter calculation
94 | │ └── :func:`add_prefilter_posttracking_reconstruction()` : PID and clustering essential for HLT
95 | └── :func:`add_postfilter_reconstruction()`
96 | ├── ``add_postfilter_tracking_reconstruction()`` : Rest of the tracking
97 | └── :func:`add_postfilter_posttracking_reconstruction()` : Rest of PID and clustering
98
99 plus the modules to calculate the software trigger cuts.
100
101 :param path: Add the modules to this path.
102 :param components: list of geometry components to include reconstruction for, or None for all components.
103 :param pruneTracks: Delete all hits except the first and last of the tracks after the V0Finder modules.
104 :param skipGeometryAdding: Advances flag: The tracking modules need the geometry module and will add it,
105 if it is not already present in the path. In a setup with multiple (conditional) paths however, it can not
106 determine, if the geometry is already loaded. This flag can be used to just turn off the geometry adding at
107 all (but you will have to add it on your own then).
108 :param trackFitHypotheses: Change the additional fitted track fit hypotheses. If no argument is given,
109 the fitted hypotheses are pion, muon and proton, i.e. [211, 321, 2212].
110 :param addClusterExpertModules: Add the cluster expert modules in the KLM and ECL. Turn this off to reduce
111 execution time.
112 :param use_second_cdc_hits: If true, the second hit information will be used in the CDC track finding.
113 :param add_muid_hits: Add the found KLM hits to the RecoTrack. Make sure to refit the track afterwards.
114 :param add_trigger_calculation: add the software trigger modules for monitoring (do not make any cut)
115 :param reconstruct_cdst: None for mdst, 'rawFormat' to reconstruct cdsts in rawFormat, 'fullFormat' for the
116 full (old) format. This parameter is needed when reconstructing cdsts, otherwise the
117 required PXD objects won't be added. :param event_abort: A function to abort event processing at the given point. Should take three arguments: a module,
118 the condition and the error_flag to be set if these events are kept. If run on HLT this will not abort the event
119 but just remove all data except for the event information.
120 :param use_random_numbers_for_hlt_prescale: If True, the HLT filter prescales are applied using randomly
121 generated numbers, otherwise are applied using an internal counter.
122 :param pxd_filtering_offline: If True, PXD data reduction (ROI filtering) is applied during the track reconstruction.
123 The reconstructed SVD/CDC tracks are used to define the ROIs and reject all PXD clusters outside of these.
124 :param create_intercepts_for_pxd_ckf: If True, the PXDROIFinder is added to the path to create PXDIntercepts to be used
125 for hit filtering when creating the CKF relations. This independent of the offline PXD digit filtering which is
126 steered by 'pxd_filtering_offline'. This can be applied for both data and MC.
127 :param append_full_grid_cdc_eventt0: If True, the module FullGridChi2TrackTimeExtractor is added to the path
128 and provides the CDC temporary EventT0.
129 :param legacy_ecl_charged_pid: Bool denoting whether to use the legacy EoP based charged particleID in the ECL (true) or
130 MVA based charged particle ID (false).
131 :param emulate_HLT: if True, it runs the reconstruction as it is run on HLT (e.g. without PXD).
132 If you want to use this flag on raw data, you should also exclude the following branches from RootInput: ROIs, ROIpayload
133 :param skip_full_grid_cdc_eventt0_if_svd_time_present: if true, and if also append_full_grid_cdc_eventt0 is true, the
134 FullGridChi2TrackTimeExtractor is only executed in the events where no SVD-based EventT0 is found. If false, but
135 append_full_grid_cdc_eventt0 is true, FullGridChi2TrackTimeExtractor will be executed in each event regardless of
136 SVD EventT0 being present. Has no effect if append_full_grid_cdc_eventt0 is false. Default: true
137 """
138
139 # Set the run for beam data
140 basf2.declare_beam()
141
142 # By default, the FullGrid module is not used in the reconstruction chain.
143 # It is needed for detectors that perform post-tracking calibration with respect to CDC EventT0 using cDST
144 if reconstruct_cdst == 'rawFormat':
145 append_full_grid_cdc_eventt0 = True
146
147 if emulate_HLT:
148 components = DEFAULT_HLT_COMPONENTS
149
150 # pre-filter reconstruction
151 add_prefilter_reconstruction(path,
152 components=components,
153 add_modules_for_trigger_calculation=add_trigger_calculation,
154 skipGeometryAdding=skipGeometryAdding,
155 trackFitHypotheses=trackFitHypotheses,
156 use_second_cdc_hits=use_second_cdc_hits,
157 add_muid_hits=add_muid_hits,
158 reconstruct_cdst=reconstruct_cdst,
159 event_abort=event_abort,
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
165 # Add the modules calculating the software trigger cuts (but not performing them)
166 if add_trigger_calculation and (not components or ("CDC" in components and "ECL" in components and "KLM" in components)):
167 add_filter_software_trigger(path,
168 use_random_numbers_for_prescale=use_random_numbers_for_hlt_prescale)
169
170 # post-filter reconstruction
171 add_postfilter_reconstruction(path,
172 components=components,
173 pruneTracks=pruneTracks,
174 addClusterExpertModules=addClusterExpertModules,
175 reconstruct_cdst=reconstruct_cdst,
176 legacy_ecl_charged_pid=legacy_ecl_charged_pid)
177
178 # Add the modules calculating the software trigger skims
179 if add_trigger_calculation and (not components or ("CDC" in components and "ECL" in components and "KLM" in components)):
180 add_skim_software_trigger(path)
181
182
183def add_prefilter_reconstruction(path,
184 components=None,
185 add_modules_for_trigger_calculation=True,
186 skipGeometryAdding=False,
187 trackFitHypotheses=None,
188 use_second_cdc_hits=False,
189 add_muid_hits=False,
190 reconstruct_cdst=None,
191 event_abort=default_event_abort,
192 pxd_filtering_offline=False,
193 create_intercepts_for_pxd_ckf=False,
194 append_full_grid_cdc_eventt0=True,
195 skip_full_grid_cdc_eventt0_if_svd_time_present=True):
196 """
197 This function adds only the reconstruction modules required to calculate HLT filter decision to a path.
198 Consists of essential tracking and the functionality provided by :func:`add_prefilter_posttracking_reconstruction()`.
199
200 :param path: Add the modules to this path.
201 :param components: list of geometry components to include reconstruction for, or None for all components.
202 :param add_modules_for_trigger_calculation: add the modules necessary for computing the software trigger decision
203 during later stages (do not make any cut), relevant only when reconstruct_cdst is not None.
204 :param skipGeometryAdding: Advances flag: The tracking modules need the geometry module and will add it,
205 if it is not already present in the path. In a setup with multiple (conditional) paths however, it can not
206 determine, if the geometry is already loaded. This flag can be used to just turn off the geometry adding at
207 all (but you will have to add it on your own then).
208 :param trackFitHypotheses: Change the additional fitted track fit hypotheses. If no argument is given,
209 the fitted hypotheses are pion, muon and proton, i.e. [211, 321, 2212].
210 :param use_second_cdc_hits: If true, the second hit information will be used in the CDC track finding.
211 :param add_muid_hits: Add the found KLM hits to the RecoTrack. Make sure to refit the track afterwards.
212 :param reconstruct_cdst: None for mdst, 'rawFormat' to reconstruct cdsts in rawFormat, 'fullFormat' for the
213 full (old) format. This parameter is needed when reconstructing cdsts, otherwise the
214 required PXD objects won't be added.
215 :param event_abort: A function to abort event processing at the given point. Should take three arguments: a module,
216 the condition and the error_flag to be set if these events are kept. If run on HLT this will not abort the event
217 but just remove all data except for the event information.
218 :param pxd_filtering_offline: If True, PXD data reduction (ROI filtering) is applied during the track reconstruction.
219 The reconstructed SVD/CDC tracks are used to define the ROIs and reject all PXD clusters outside of these.
220 :param create_intercepts_for_pxd_ckf: If True, the PXDROIFinder is added to the path to create PXDIntercepts to be used
221 for hit filtering when creating the CKF relations. This independent of the offline PXD digit filtering which is
222 steered by 'pxd_filtering_offline'. This can be applied for both data and MC.
223 :param append_full_grid_cdc_eventt0: If True, the module FullGridChi2TrackTimeExtractor is added to the path
224 and provides the CDC temporary EventT0.
225 :param skip_full_grid_cdc_eventt0_if_svd_time_present: if true, and if also append_full_grid_cdc_eventt0 is true, the
226 FullGridChi2TrackTimeExtractor is only executed in the events where no SVD-based EventT0 is found. If false, but
227 append_full_grid_cdc_eventt0 is true, FullGridChi2TrackTimeExtractor will be executed in each event regardless of
228 SVD EventT0 being present. Has no effect if append_full_grid_cdc_eventt0 is false. Default: true
229 """
230
231 # Always avoid the top-level 'import ROOT'.
232 from ROOT import Belle2 # noqa
233
234 # Check components.
235 check_components(components)
236
237 # Do not even attempt at reconstructing events w/ abnormally large occupancy.
238 doom = path.add_module("EventsOfDoomBuster")
239 event_abort(doom, ">=1", Belle2.EventMetaData.c_ReconstructionAbort)
240 path.add_module('StatisticsSummary').set_name('Sum_EventsofDoomBuster')
241
242 # Add modules that have to be run BEFORE track reconstruction
243 add_prefilter_pretracking_reconstruction(path, components=components)
244
245 # Add prefilter tracking reconstruction modules
246 add_prefilter_tracking_reconstruction(
247 path,
248 components=components,
249 mcTrackFinding=False,
250 skipGeometryAdding=skipGeometryAdding,
251 trackFitHypotheses=trackFitHypotheses,
252 use_second_cdc_hits=use_second_cdc_hits,
253 pxd_filtering_offline=pxd_filtering_offline,
254 create_intercepts_for_pxd_ckf=create_intercepts_for_pxd_ckf,
255 append_full_grid_cdc_eventt0=append_full_grid_cdc_eventt0,
256 skip_full_grid_cdc_eventt0_if_svd_time_present=skip_full_grid_cdc_eventt0_if_svd_time_present)
257
258 # Statistics summary
259 path.add_module('StatisticsSummary').set_name('Sum_Prefilter_Tracking')
260
261 # In case of cdst reconstruction ...
262 if reconstruct_cdst:
263 add_special_vxd_modules(path, components=components)
264 if reconstruct_cdst == 'rawFormat' and not add_modules_for_trigger_calculation:
265 return
266
267 # Add prefilter posttracking modules
268 add_prefilter_posttracking_reconstruction(path,
269 components=components,
270 add_muid_hits=add_muid_hits)
271
272 # Statistics summary
273 path.add_module('StatisticsSummary').set_name('Sum_Prefilter_PostTracking')
274
275
276def add_postfilter_reconstruction(path,
277 components=None,
278 pruneTracks=False,
279 addClusterExpertModules=True,
280 reconstruct_cdst=None,
281 legacy_ecl_charged_pid=False):
282 """
283 This function adds the reconstruction modules not required to calculate HLT filter decision to a path.
284
285 :param path: Add the modules to this path.
286 :param components: list of geometry components to include reconstruction for, or None for all components.
287 :param pruneTracks: Delete all hits expect the first and the last from the found tracks.
288 :param addClusterExpertModules: Add the cluster expert modules in the KLM and ECL. Turn this off to
289 reduce execution time.
290 :param reconstruct_cdst: None for mdst, 'rawFormat' to reconstruct cdsts in rawFormat, 'fullFormat' for the
291 full (old) format. This parameter is needed when reconstructing cdsts, otherwise the
292 required PXD objects won't be added.
293 :param legacy_ecl_charged_pid: Bool denoting whether to use the legacy EoP based charged particleID in the ECL (true) or
294 MVA based charged particle ID (false).
295 """
296
297 # Add postfilter tracking reconstruction modules
298 add_postfilter_tracking_reconstruction(path, components=components, pruneTracks=False)
299
300 path.add_module('StatisticsSummary').set_name('Sum_Postfilter_Tracking')
301
302 # Skip postfilter posttracking modules except dedx for raw format cdst reconstruction
303 if reconstruct_cdst == 'rawFormat':
304 add_dedx_modules(path, components=components, enableDebugOutput=True)
305 if pruneTracks:
306 add_prune_tracks(path, components)
307 return
308
309 # Add postfilter posttracking modules
310 add_postfilter_posttracking_reconstruction(path,
311 components=components,
312 addClusterExpertModules=addClusterExpertModules,
313 legacy_ecl_charged_pid=legacy_ecl_charged_pid)
314 # Prune tracks
315 if pruneTracks:
316 add_prune_tracks(path, components)
317
318 # Statistics summary
319 path.add_module('StatisticsSummary').set_name('Sum_Postfilter_PostTracking')
320
321
322def add_cosmics_reconstruction(
323 path,
324 components=None,
325 pruneTracks=True,
326 skipGeometryAdding=False,
327 eventTimingExtraction=True,
328 addClusterExpertModules=True,
329 merge_tracks=True,
330 use_second_cdc_hits=False,
331 add_muid_hits=False,
332 reconstruct_cdst=False,
333 posttracking=True,
334 legacy_ecl_charged_pid=False,
335 ):
336 """
337 This function adds the standard reconstruction modules for cosmic data to a path.
338 Consists of tracking and the functionality provided by :func:`add_posttracking_reconstruction()`,
339 plus the modules to calculate the software trigger cuts.
340
341 :param path: Add the modules to this path.
342 :param components: list of geometry components to include reconstruction for, or None for all components.
343 :param pruneTracks: Delete all hits except the first and last of the tracks after the dEdX modules.
344 :param skipGeometryAdding: Advances flag: The tracking modules need the geometry module and will add it,
345 if it is not already present in the path. In a setup with multiple (conditional) paths however, it can not
346 determine, if the geometry is already loaded. This flag can be used to just turn off the geometry adding at
347 all (but you will have to add it on your own then).
348
349 :param eventTimingExtraction: extract the event time
350 :param addClusterExpertModules: Add the cluster expert modules in the KLM and ECL. Turn this off to reduce
351 execution time.
352
353 :param merge_tracks: The upper and lower half of the tracks should be merged together in one track
354 :param use_second_cdc_hits: If true, the second hit information will be used in the CDC track finding.
355
356 :param add_muid_hits: Add the found KLM hits to the RecoTrack. Make sure to refit the track afterwards.
357
358 :param reconstruct_cdst: run only the minimal reconstruction needed to produce the cdsts (raw+tracking+dE/dx)
359 :param posttracking: run reconstruction for outer detectors.
360 :param legacy_ecl_charged_pid: Bool denoting whether to use the legacy EoP based charged particleID in the ECL (true) or
361 MVA based charged particle ID (false).
362 """
363
364 # Set the run for cosmics data
365 basf2.declare_cosmics()
366
367 # Check components.
368 check_components(components)
369
370 # Add modules that have to be run before track reconstruction
371 add_prefilter_pretracking_reconstruction(path,
372 components=components)
373
374 # Add cdc tracking reconstruction modules
375 add_cr_tracking_reconstruction(path,
376 components=components,
377 prune_tracks=False,
378 skip_geometry_adding=skipGeometryAdding,
379 event_time_extraction=eventTimingExtraction,
380 merge_tracks=merge_tracks,
381 use_second_cdc_hits=use_second_cdc_hits)
382
383 # Statistics summary
384 path.add_module('StatisticsSummary').set_name('Sum_Tracking')
385
386 if posttracking:
387 if reconstruct_cdst:
388 add_special_vxd_modules(path, components=components)
389 add_dedx_modules(path, components=components, enableDebugOutput=True)
390 add_prune_tracks(path, components=components)
391
392 else:
393 # Add further reconstruction modules
394 add_posttracking_reconstruction(path,
395 components=components,
396 pruneTracks=pruneTracks,
397 addClusterExpertModules=addClusterExpertModules,
398 add_muid_hits=add_muid_hits,
399 cosmics=True,
400 legacy_ecl_charged_pid=legacy_ecl_charged_pid)
401
402
403def add_mc_reconstruction(path, components=None, pruneTracks=True, addClusterExpertModules=True,
404 use_second_cdc_hits=False, add_muid_hits=False, legacy_ecl_charged_pid=False):
405 """
406 This function adds the standard reconstruction modules with MC tracking
407 to a path.
408
409 @param components list of geometry components to include reconstruction for, or None for all components.
410 @param use_second_cdc_hits: If true, the second hit information will be used in the CDC track finding.
411 :param add_muid_hits: Add the found KLM hits to the RecoTrack. Make sure to refit the track afterwards.
412 :param legacy_ecl_charged_pid: Bool denoting whether to use the legacy EoP based charged particleID in the ECL (true) or
413 MVA based charged particle ID (false).
414 """
415
416 # Set the run for beam data
417 basf2.declare_beam()
418
419 # Add modules that have to be run before track reconstruction
420 add_prefilter_pretracking_reconstruction(path,
421 components=components)
422
423 # tracking
424 add_mc_tracking_reconstruction(path,
425 components=components,
426 pruneTracks=False,
427 use_second_cdc_hits=use_second_cdc_hits)
428
429 # Statistics summary
430 path.add_module('StatisticsSummary').set_name('Sum_MC_Tracking')
431
432 # add further reconstruction modules
433 add_posttracking_reconstruction(path,
434 components=components,
435 pruneTracks=pruneTracks,
436 add_muid_hits=add_muid_hits,
437 addClusterExpertModules=addClusterExpertModules,
438 legacy_ecl_charged_pid=legacy_ecl_charged_pid)
439
440
441def add_prefilter_pretracking_reconstruction(path, components=None):
442 """
443 This function adds the standard reconstruction modules BEFORE tracking
444 to a path.
445
446 :param path: The path to add the modules to.
447 :param components: list of geometry components to include reconstruction for, or None for all components.
448 """
449
450 add_ecl_modules(path, components)
451
452 # Statistics summary
453 path.add_module('StatisticsSummary').set_name('Sum_Clustering')
454
455
456def add_prefilter_posttracking_reconstruction(path,
457 components=None,
458 add_muid_hits=False,
459 for_cdst_analysis=False,
460 add_eventt0_combiner_for_cdst=False):
461 """
462 This function adds to the path the standard reconstruction modules after prefilter tracking
463 whoose outputs are also needed in the filter.
464
465 :param path: The path to add the modules to.
466 :param components: list of geometry components to include reconstruction for, or None for all components.
467 :param add_muid_hits: Add the found KLM hits to the RecoTrack. Make sure to refit the track afterwards.
468 :param for_cdst_analysis: if True, EventT0Combiner is not added to path.
469 This is only needed by prepare_cdst_analysis().
470 :param add_eventt0_combiner_for_cdst: if True, the EventT0Combiner module is added to the path even if
471 for_cdst_analysis is False. This is useful for validation purposes for avoiding to run the full
472 add_reconstruction(). Note that, with the default settings (for_cdst_analysis=False and
473 add_eventt0_combiner_for_cdst=False), the EventT0Combiner module is added to the path.
474 """
475
476 add_ext_module(path, components)
477
478 # Add EventT0Combiner, if this function is not called from prepare_cdst_analysis() or if requested also there.
479 if not for_cdst_analysis or add_eventt0_combiner_for_cdst:
480 path.add_module("EventT0Combiner")
481 add_ecl_finalizer_module(path, components)
482 add_ecl_mc_matcher_module(path, components)
483 add_klm_modules(path, components)
484 add_klm_mc_matcher_module(path, components)
485 add_muid_module(path, add_hits_to_reco_track=add_muid_hits, components=components)
486 add_ecl_track_cluster_modules(path, components)
487 add_ecl_cluster_properties_modules(path, components)
488
489
490def add_postfilter_posttracking_reconstruction(path,
491 components=None,
492 addClusterExpertModules=True,
493 cosmics=False,
494 for_cdst_analysis=False,
495 legacy_ecl_charged_pid=False):
496 """
497 This function adds to the path the standard reconstruction modules whoose outputs are not needed in the filter.
498
499 :param path: The path to add the modules to.
500 :param components: list of geometry components to include reconstruction for, or None for all components.
501 :param addClusterExpertModules: Add the cluster expert modules in the KLM and ECL. Turn this off to reduce
502 execution time.
503 :param cosmics: if True, steer TOP for cosmic reconstruction.
504 :param for_cdst_analysis: if True, the OnlineEventT0Creator module is not added to the path.
505 This is only needed by prepare_cdst_analysis().
506 :param legacy_ecl_charged_pid: Bool denoting whether to use the legacy EoP based charged particleID in the ECL (true) or
507 MVA based charged particle ID (false).
508 """
509
510 add_dedx_modules(path, components, for_cdst_analysis=for_cdst_analysis)
511 add_top_modules(path, components, cosmics=cosmics)
512 add_arich_modules(path, components)
513
514 # only add the OnlineEventT0Creator if not preparing cDST
515 if not for_cdst_analysis:
516 path.add_module("OnlineEventT0Creator")
517
518 add_ecl_chargedpid_module(path, components, legacy_ecl_charged_pid)
519 add_pid_module(path, components)
520
521 if addClusterExpertModules:
522 # FIXME: Disabled for HLT until execution time bug is fixed
523 add_cluster_expert_modules(path, components)
524
525 add_ecl_track_brem_finder(path, components)
526
527
528def add_posttracking_reconstruction(path,
529 components=None,
530 pruneTracks=True,
531 addClusterExpertModules=True,
532 add_muid_hits=False,
533 cosmics=False,
534 for_cdst_analysis=False,
535 add_eventt0_combiner_for_cdst=False,
536 legacy_ecl_charged_pid=False):
537 """
538 This function adds the standard reconstruction modules after tracking
539 to a path.
540
541 :param path: The path to add the modules to.
542 :param components: list of geometry components to include reconstruction for, or None for all components.
543 :param pruneTracks: Delete all hits except the first and last after the post-tracking modules.
544 :param addClusterExpertModules: Add the cluster expert modules in the KLM and ECL. Turn this off to reduce
545 execution time.
546 :param add_muid_hits: Add the found KLM hits to the RecoTrack. Make sure to refit the track afterwards.
547 :param cosmics: if True, steer TOP for cosmic reconstruction.
548 :param for_cdst_analysis: if True, the dEdx and PruneTracks modules are not added to the path, as well
549 as all EventT0 related modules.
550 This is only needed by prepare_cdst_analysis().
551 :param add_eventt0_combiner_for_cdst: if True, the EventT0Combiner module is added to the path even if
552 for_cdst_analysis is True. This is useful for validation purposes for avoiding to run the full
553 add_reconstruction(). Note that, with the default settings (for_cdst_analysis=False and
554 add_eventt0_combiner_for_cdst=False), the EventT0Combiner module is added to the path.
555 :param legacy_ecl_charged_pid: Bool denoting whether to use the legacy EoP based charged particleID in the ECL (true) or
556 MVA based charged particle ID (false).
557 """
558
559 add_prefilter_posttracking_reconstruction(path,
560 components=components,
561 add_muid_hits=add_muid_hits,
562 for_cdst_analysis=for_cdst_analysis,
563 add_eventt0_combiner_for_cdst=add_eventt0_combiner_for_cdst)
564
565 add_postfilter_posttracking_reconstruction(path,
566 components=components,
567 addClusterExpertModules=addClusterExpertModules,
568 cosmics=cosmics,
569 for_cdst_analysis=for_cdst_analysis,
570 legacy_ecl_charged_pid=legacy_ecl_charged_pid)
571
572 # Prune tracks as soon as the post-tracking steps are complete
573 # Not add prune tracks modules in prepare_cdst_analysis()
574 if not for_cdst_analysis:
575 if pruneTracks:
576 add_prune_tracks(path, components)
577
578 path.add_module('StatisticsSummary').set_name('Sum_Posttracking_Reconstruction')
579
580
581def add_cdst_output(path,
582 mc=True,
583 filename='cdst.root',
584 additionalBranches=None,
585 dataDescription=None,
586 ignoreInputModulesCheck=False):
587 """
588 This function adds the `RootOutput` module to a path with the settings needed to produce a cDST output.
589 The actual cDST output content depends on the value of the parameter `mc`:
590 * if `mc` is `False` (default setting), the cDST content is raw + tracking dataobjects;
591 * if `mc` is `True`, the cDST content is digits + MCParticles + tracking dataobjects.
592
593 @param path Path to add modules to.
594 @param mc Define the type of cDST output content: `False` for raw + tracking dataobjects, `True` for digits +
595 MCParticles + tracking dataobjects.
596 @param filename Output file name.
597 @param additionalBranches Additional objects/arrays of event durability to save
598 @param dataDescription Additional key->value pairs to be added as data description
599 fields to the output FileMetaData.
600 @param ignoreInputModulesCheck If True, do not enforce check on missing PXD modules in the input path.
601 Needed when a conditional path is passed as input.
602 """
603
604 branches = list(CDST_TRACKING_OBJECTS)
605 persistentBranches = ['FileMetaData']
606
607 if not mc:
608 branches += ALWAYS_SAVE_OBJECTS + RAWDATA_OBJECTS
609 else:
610 branches += list(DIGITS_OBJECTS) + [
611 'MCParticles',
612 'EventLevelTriggerTimeInfo',
613 'SoftwareTriggerResult',
614 'TRGSummary']
615 persistentBranches += ['BackgroundInfo']
616
617 if not ignoreInputModulesCheck and "PXDClustersFromTracks" not in [module.name() for module in path.modules()]:
618 basf2.B2ERROR("PXDClustersFromTracks is required in CDST output but its module is not found in the input path!")
619
620 if dataDescription is None:
621 dataDescription = {}
622 dataDescription.setdefault("dataLevel", "cdst")
623
624 if additionalBranches is not None:
625 branches += additionalBranches
626
627 return path.add_module("RootOutput", outputFileName=filename, branchNames=branches,
628 branchNamesPersistent=persistentBranches, additionalDataDescription=dataDescription)
629
630
631def add_arich_modules(path, components=None):
632 """
633 Add the ARICH reconstruction to the path.
634
635 :param path: The path to add the modules to.
636 :param components: The components to use or None to use all standard components.
637 """
638 if components is None or 'ARICH' in components:
639 path.add_module('ARICHFillHits')
640 path.add_module('ARICHReconstructor',
641 storePhotons=1) # enabled for ARICH DQM plots
642
643
644def add_top_modules(path, components=None, cosmics=False):
645 """
646 Add the TOP reconstruction to the path.
647
648 :param path: The path to add the modules to.
649 :param components: The components to use or None to use all standard components.
650 :param cosmics: if True, steer TOP for cosmic reconstruction
651 """
652 if components is None or 'TOP' in components:
653 path.add_module('TOPChannelMasker')
654 if cosmics:
655 path.add_module('TOPCosmicT0Finder')
656 else:
657 path.add_module('TOPBunchFinder')
658 path.add_module('TOPReconstructor')
659
660
661def add_cluster_expert_modules(path, components=None):
662 """
663 Add the KLMExpert and ClusterMatcher modules to the path.
664
665 :param path: The path to add the modules to.
666 :param components: The components to use or None to use all standard components.
667 """
668 if components is None or ('KLM' in components and 'ECL' in components):
669 path.add_module('KLMExpert')
670 path.add_module('ClusterMatcher')
671
672
673def add_pid_module(path, components=None):
674 """
675 Add the PID modules to the path.
676
677 :param path: The path to add the modules to.
678 :param components: The components to use or None to use all standard components.
679 """
680 if components is None or 'SVD' in components or 'CDC' in components:
681 path.add_module('MdstPID')
682 if components is None:
683 path.add_module('KLMMuonIDDNNExpert')
684
685
686def add_klm_modules(path, components=None):
687 """
688 Add the KLM reconstruction modules to the path.
689
690 :param path: The path to add the modules to.
691 :param components: The components to use or None to use all standard components.
692 """
693 if components is None or 'KLM' in components:
694 path.add_module('KLMReconstructor')
695 path.add_module('KLMClustersReconstructor')
696
697
698def add_klm_mc_matcher_module(path, components=None):
699 """
700 Add the KLM mc matcher module to the path.
701
702 :param path: The path to add the modules to.
703 :param components: The components to use or None to use all standard components.
704 """
705 if components is None or 'KLM' in components:
706 path.add_module('MCMatcherKLMClusters')
707
708
709def add_muid_module(path, add_hits_to_reco_track=False, components=None):
710 """
711 Add the MuID module to the path.
712
713 :param path: The path to add the modules to.
714 :param add_hits_to_reco_track: Add the found KLM hits also to the RecoTrack. Make sure to refit the track afterwards.
715 :param components: The components to use or None to use all standard components.
716 """
717 # Muid is needed for muonID computation AND ECLCluster-Track matching.
718 if components is None or ('CDC' in components and 'ECL' in components and 'KLM' in components):
719 path.add_module('Muid',
720 addHitsToRecoTrack=add_hits_to_reco_track)
721 if components is not None and 'CDC' in components:
722 if ('ECL' not in components and 'KLM' in components):
723 basf2.B2WARNING('You added KLM to the components list but not ECL: the module Muid, that is necessary '
724 'for correct muonID computation, will not be added to your reconstruction path. '
725 'Make sure that this is fine for your purposes, otherwise please include also ECL.')
726 if ('ECL' in components and 'KLM' not in components):
727 basf2.B2WARNING('You added ECL to the components list but not KLM: the module Muid, that is necessary '
728 'for correct ECLCluster-Track matching, will not be added to your reconstruction path. '
729 ' Make sure that this is fine for your purposes, otherwise please include also KLM.')
730
731
732def add_ecl_modules(path, components=None):
733 """
734 Add the ECL reconstruction modules to the path.
735
736 :param path: The path to add the modules to.
737 :param components: The components to use or None to use all standard components.
738 """
739 if components is None or 'ECL' in components:
740 path.add_module('ECLWaveformFit')
741 path.add_module('ECLDigitCalibrator')
742 path.add_module('ECLEventT0')
743 path.add_module('ECLCRFinder') # connected region finder
744 path.add_module('ECLLocalMaximumFinder')
745 path.add_module('ECLSplitterN1')
746 path.add_module('ECLSplitterN2')
747 path.add_module('ECLShowerCorrector')
748 path.add_module('ECLShowerCalibrator')
749 path.add_module('ECLShowerShape')
750 path.add_module('ECLClusterPSD')
751 path.add_module('ECLCovarianceMatrix')
752 # The module ECLFinalizer must run after EventT0Combiner
753
754
755def add_ecl_finalizer_module(path, components=None):
756 """
757 Add the ECL finalizer module to the path.
758
759 :param path: The path to add the modules to.
760 :param components: The components to use or None to use all standard components.
761 """
762
763 if components is None or 'ECL' in components:
764 path.add_module('ECLFinalizer')
765
766
767def add_ecl_track_cluster_modules(path, components=None):
768 """
769 Add the ECL track cluster matching module to the path.
770
771 :param path: The path to add the modules to.
772 :param components: The components to use or None to use all standard components.
773 """
774 if components is None or ('ECL' in components and ('PXD' in components or 'SVD' in components or 'CDC' in components)):
775 path.add_module('ECLTrackClusterMatching')
776
777
778def add_ecl_cluster_properties_modules(path, components=None):
779 """
780 Add the ECL cluster properties module to the path.
781
782 :param path: The path to add the modules to.
783 :param components: The components to use or None to use all standard components.
784 """
785 if components is None or ('ECL' in components and ('PXD' in components or 'SVD' in components or 'CDC' in components)):
786 path.add_module('ECLClusterProperties')
787
788
789def add_ecl_track_brem_finder(path, components=None):
790 """
791 Add the bremsstrahlung finding module to the path.
792
793 :param path: The path to add the modules to.
794 :param components: The components to use or None to use all standard components.
795 """
796 if components is None or ('ECL' in components and ('PXD' in components or 'SVD' in components)):
797 path.add_module('ECLTrackBremFinder')
798
799
800def add_ecl_chargedpid_module(path, components=None, legacyMode=False):
801 """
802 Add the ECL charged PID module to the path.
803
804 :param path: The path to add the modules to.
805 :param components: The components to use or None to use all standard components.
806 :param legacyMode: Uses the simple E/p based charged PID instead of the MVA based charged PID.
807 """
808 if components is None or 'ECL' in components:
809 # charged PID
810 if legacyMode:
811 path.add_module('ECLChargedPID')
812 else:
813 path.add_module('ECLFillCellIdMapping')
814 path.add_module('ECLChargedPIDMVA')
815
816
817def add_ecl_mc_matcher_module(path, components=None):
818 """
819 Add the ECL MC matcher module to the path.
820
821 :param path: The path to add the modules to.
822 :param components: The components to use or None to use all standard components.
823 """
824 if components is None or 'ECL' in components:
825 path.add_module('MCMatcherECLClusters')
826
827
828def add_ext_module(path, components=None):
829 """
830 Add the extrapolation module to the path.
831
832 :param path: The path to add the modules to.
833 :param components: The components to use or None to use all standard components.
834 """
835 if components is None or 'CDC' in components:
836 path.add_module('Ext')
837
838
839def add_dedx_modules(path, components=None, for_cdst_analysis=False, enableDebugOutput=False):
840 """
841 Add the dE/dX reconstruction modules to the path.
842
843 :param path: The path to add the modules to.
844 :param components: The components to use or None to use all standard components.
845 :param for_cdst_analysis: if True, add only DedxPIDCreator module, otherwise add both
846 :param enableDebugOutput: enable/disable writing out debugging information to CDCDedxTracks
847 """
848 # CDC dE/dx PID
849 if components is None or 'CDC' in components:
850 if for_cdst_analysis:
851 path.add_module('CDCDedxPIDCreator', enableDebugOutput=True)
852 else:
853 path.add_module('CDCDedxHitSaver')
854 path.add_module('CDCDedxPIDCreator', enableDebugOutput=enableDebugOutput)
855 # VXD dE/dx PID
856 # only run this if the SVD is enabled - PXD is disabled by default
857 if components is None or 'SVD' in components:
858 if for_cdst_analysis:
859 path.add_module('VXDDedxPIDRemaker')
860 else:
861 path.add_module('VXDDedxPID')
862
863
864def add_special_vxd_modules(path, components=None):
865 """
866 Add two modules that are not part of the standard reconstruction.
867
868 :param path: The path to add the modules to.
869 :param components: The components to use or None to use all standard components.
870 """
871
872 if not components or ('PXD' in components):
873 path.add_module("PXDClustersFromTracks")
874 if not components or ('SVD' in components):
875 path.add_module("SVDShaperDigitsFromTracks")
876
877
878def prepare_cdst_analysis(path, components=None, mc=False, add_eventt0_combiner=False, legacy_ecl_charged_pid=False):
879 """
880 Adds to a (analysis) path all the modules needed to analyse a cDST file in the raw+tracking format
881 for collisions/cosmics data or in the digits+tracking format for MC data.
882
883 :param path: The path to add the modules to.
884 :param components: The components to use or None to use all standard components.
885 :param mc: Are we running over MC data or not? If so, do not run the unpackers.
886 :param add_eventt0_combiner: If True, it adds the EventT0Combiner module when the post-tracking
887 reconstruction is run. This must NOT be used during the calibration, but it may be necessary
888 for validation purposes or for the user analyses.
889 :param legacy_ecl_charged_pid: Bool denoting whether to use the legacy EoP based charged particleID in the ECL (true) or
890 MVA based charged particle ID (false).
891 """
892 # Add the unpackers only if not running on MC, otherwise check the components and simply add
893 # the Gearbox and the Geometry modules
894 if not mc:
895 add_unpackers(path,
896 components=components)
897 else:
898 check_components(components)
899 path.add_module('Gearbox')
900 path.add_module('Geometry')
901
902 # This currently just calls add_ecl_modules
903 add_prefilter_pretracking_reconstruction(path,
904 components=components)
905
906 # Needed to retrieve the PXD and SVD clusters out of the raw data
907 if components is None or 'SVD' in components:
908 add_svd_reconstruction(path)
909 if components is None or 'PXD' in components:
910 add_pxd_reconstruction(path)
911
912 # check, this one may not be needed...
913 path.add_module('SetupGenfitExtrapolation',
914 energyLossBrems=False,
915 noiseBrems=False)
916
917 # Add the posttracking modules needed for the cDST analysis
918 add_posttracking_reconstruction(path,
919 components=components,
920 for_cdst_analysis=True,
921 add_eventt0_combiner_for_cdst=add_eventt0_combiner,
922 legacy_ecl_charged_pid=legacy_ecl_charged_pid)
923
924
925def prepare_user_cdst_analysis(path, components=None, mc=False):
926 """
927 Adds to a (analysis) path all the modules needed to analyse a cDST file in the raw+tracking format
928 for collisions/cosmics data or in the digits+tracking format for MC data.
929 Differently from prepare_cdst_analysis(), this function add the EventT0Combiner module to the path,
930 which makes this function suitable for all the users and not only for the calibration expertes.
931 Note that the EventT0Combiner module is necessary for applying the proper EventT0 correction to
932 our data.
933
934 :param path: The path to add the modules to.
935 :param components: The components to use or None to use all standard components.
936 :param mc: Are we running over MC data or not? If so, do not run the unpackers.
937 """
938 prepare_cdst_analysis(path=path, components=components, mc=mc, add_eventt0_combiner=True)
939