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