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