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