Belle II Software  release-05-01-25
klm_calibration_utils.py
1 # -*- coding: utf-8 -*-
2 
3 """Implements some extra utilities for doing KLM calibration with the CAF."""
4 
5 import basf2
6 
7 from rawdata import add_unpackers
8 from reconstruction import add_cosmics_reconstruction, add_reconstruction, prepare_cdst_analysis
9 from softwaretrigger.constants import RAWDATA_OBJECTS
10 import modularAnalysis as ma
11 
12 
13 def get_channel_status_pre_collector_path(entry_sequence=""):
14  """
15  Parameters:
16  entry_sequence (str): A single entry sequence e.g. '0:100' to help limit processed events.
17 
18  Returns:
19  basf2.Path: A reconstruction path to run before the collector. Used for raw cosmic input files.
20  """
21  main = basf2.create_path()
22  if entry_sequence:
23  main.add_module('RootInput',
24  entrySequences=[entry_sequence])
25 
26  # KLM unpacker.
27  add_unpackers(main, components=['KLM'])
28 
29  return main
30 
31 
32 def get_alignment_pre_collector_path_cosmic(entry_sequence=""):
33  """
34  Parameters:
35  entry_sequence (str): A single entry sequence e.g. '0:100' to help limit processed events.
36 
37  Returns:
38  basf2.Path: A reconstruction path to run before the collector. Used for raw cosmic input files.
39  """
40  main = basf2.create_path()
41  root_input = basf2.register_module(
42  'RootInput',
43  branchNames=RAWDATA_OBJECTS + ['EventMetaData'])
44  if entry_sequence:
45  root_input.param('entrySequences', [entry_sequence])
46  main.add_module(root_input)
47 
48  # Unpackers and reconstruction.
49  add_unpackers(main)
50  add_cosmics_reconstruction(main, pruneTracks=False, add_muid_hits=True,
51  merge_tracks=False)
52  # Disable the time window in muid module by setting it to 1 second.
53  # This is necessary because the alignment needs to be performed before
54  # the time calibration; if the time window is not disabled, then all
55  # scintillator hits are rejected.
56  basf2.set_module_parameters(main, 'Muid', MaxDt=1e9)
57 
58  main.add_module('DAFRecoFitter',
59  pdgCodesToUseForFitting=[13],
60  resortHits=True)
61 
62  main.add_module('SetupGenfitExtrapolation',
63  noiseBetheBloch=False,
64  noiseCoulomb=False,
65  noiseBrems=False)
66 
67  return main
68 
69 
70 def get_alignment_pre_collector_path_physics(entry_sequence=""):
71  """
72  Parameters:
73  entry_sequence (str): A single entry sequence e.g. '0:100' to help limit processed events.
74 
75  Returns:
76  basf2.Path: A reconstruction path to run before the collector. Used for raw physics input files.
77  """
78  main = basf2.create_path()
79  root_input = basf2.register_module(
80  'RootInput',
81  branchNames=RAWDATA_OBJECTS + ['EventMetaData'])
82  if entry_sequence:
83  root_input.param('entrySequences', [entry_sequence])
84  main.add_module(root_input)
85 
86  # Unpackers and reconstruction.
87  add_unpackers(main)
88  add_reconstruction(main, pruneTracks=False, add_muid_hits=True)
89  # Disable the time window in muid module by setting it to 1 second.
90  # This is necessary because the alignment needs to be performed before
91  # the time calibration; if the time window is not disabled, then all
92  # scintillator hits are rejected.
93  basf2.set_module_parameters(main, 'Muid', MaxDt=1e9)
94 
95  main.add_module('DAFRecoFitter', resortHits=True)
96 
97  main.add_module('SetupGenfitExtrapolation',
98  noiseBetheBloch=False,
99  noiseCoulomb=False,
100  noiseBrems=False)
101 
102  return main
103 
104 
105 def get_strip_efficiency_pre_collector_path(entry_sequence="", raw_format=True):
106  """
107  Parameters:
108  entry_sequence (str): A single entry sequence e.g. '0:100' to help limit processed events.
109  raw_format (bool): True if cDST input files are in the raw+tracking format.
110 
111  Returns:
112  basf2.Path: A reconstruction path to run before the collector. Used for cDST input files.
113  """
114  main = basf2.create_path()
115  if entry_sequence:
116  main.add_module('RootInput',
117  entrySequences=[entry_sequence])
118  if raw_format:
119  prepare_cdst_analysis(main)
120  else:
121  main.add_module('Gearbox')
122  main.add_module('Geometry')
123 
124  # Fill muon particle list
125  ma.fillParticleList('mu+:klmStripEfficiency',
126  '[1 < p] and [p < 11] and [abs(d0) < 2] and [abs(z0) < 5]',
127  path=main)
128 
129  return main
softwaretrigger.constants
Definition: constants.py:1