Belle II Software  release-08-01-10
klm_calibration_utils.py
1 
8 
9 """Implements some extra utilities for doing KLM calibration with the CAF."""
10 
11 import basf2
12 
13 from rawdata import add_unpackers
14 from reconstruction import add_cosmics_reconstruction, add_reconstruction, prepare_cdst_analysis
15 from softwaretrigger.constants import RAWDATA_OBJECTS
16 import modularAnalysis as ma
17 
18 
19 def get_channel_status_pre_collector_path(entry_sequence=""):
20  """
21  Parameters:
22  entry_sequence (str): A single entry sequence e.g. '0:100' to help limit processed events.
23 
24  Returns:
25  basf2.Path: A reconstruction path to run before the collector. Used for raw cosmic input files.
26  """
27  main = basf2.create_path()
28  if entry_sequence:
29  main.add_module('RootInput',
30  entrySequences=[entry_sequence])
31 
32  # KLM unpacker.
33  add_unpackers(main, components=['KLM'])
34 
35  return main
36 
37 
38 def get_alignment_pre_collector_path_cosmic(entry_sequence=""):
39  """
40  Parameters:
41  entry_sequence (str): A single entry sequence e.g. '0:100' to help limit processed events.
42 
43  Returns:
44  basf2.Path: A reconstruction path to run before the collector. Used for raw cosmic input files.
45  """
46  main = basf2.create_path()
47  root_input = basf2.register_module(
48  'RootInput',
49  branchNames=RAWDATA_OBJECTS + ['EventMetaData'])
50  if entry_sequence:
51  root_input.param('entrySequences', [entry_sequence])
52  main.add_module(root_input)
53 
54  # Unpackers and reconstruction.
55  add_unpackers(main)
56  add_cosmics_reconstruction(main, pruneTracks=False, add_muid_hits=True,
57  merge_tracks=False)
58  # Disable the EventT0 correction.
59  basf2.set_module_parameters(main, 'KLMReconstructor', EventT0Correction=False)
60  # Disable the time window in muid module by setting it to 1 second.
61  # This is necessary because the alignment needs to be performed before
62  # the time calibration; if the time window is not disabled, then all
63  # scintillator hits are rejected.
64  basf2.set_module_parameters(main, 'Muid', MaxDt=1e9)
65 
66  main.add_module('DAFRecoFitter',
67  pdgCodesToUseForFitting=[13],
68  resortHits=True)
69 
70  main.add_module('SetupGenfitExtrapolation',
71  noiseBetheBloch=False,
72  noiseCoulomb=False,
73  noiseBrems=False)
74 
75  return main
76 
77 
78 def get_alignment_pre_collector_path_physics(entry_sequence=""):
79  """
80  Parameters:
81  entry_sequence (str): A single entry sequence e.g. '0:100' to help limit processed events.
82 
83  Returns:
84  basf2.Path: A reconstruction path to run before the collector. Used for raw physics input files.
85  """
86  main = basf2.create_path()
87  root_input = basf2.register_module(
88  'RootInput',
89  branchNames=RAWDATA_OBJECTS + ['EventMetaData'])
90  if entry_sequence:
91  root_input.param('entrySequences', [entry_sequence])
92  main.add_module(root_input)
93 
94  # Unpackers and reconstruction.
95  add_unpackers(main)
96  add_reconstruction(main, pruneTracks=False, add_muid_hits=True)
97  # Disable the EventT0 correction.
98  basf2.set_module_parameters(main, 'KLMReconstructor', EventT0Correction=False)
99  # Disable the time window in muid module by setting it to 1 second.
100  # This is necessary because the alignment needs to be performed before
101  # the time calibration; if the time window is not disabled, then all
102  # scintillator hits are rejected.
103  basf2.set_module_parameters(main, 'Muid', MaxDt=1e9)
104 
105  main.add_module('DAFRecoFitter', resortHits=True)
106 
107  main.add_module('SetupGenfitExtrapolation',
108  noiseBetheBloch=False,
109  noiseCoulomb=False,
110  noiseBrems=False)
111 
112  return main
113 
114 
115 def get_strip_efficiency_pre_collector_path(
116  muon_list_name, entry_sequence="", raw_format=True, mc=False):
117  """
118  Parameters:
119  muon_list_name (str): Name of the muon ParticleList to be filled.
120  entry_sequence (str): A single entry sequence e.g. '0:100' to help limit processed events.
121  raw_format (bool): True if cDST input files are in the raw+tracking format.
122 
123  Returns:
124  basf2.Path: A reconstruction path to run before the collector. Used for cDST input files.
125  """
126  main = basf2.create_path()
127  if entry_sequence:
128  main.add_module('RootInput',
129  entrySequences=[entry_sequence])
130  if raw_format:
131  prepare_cdst_analysis(main, mc=mc)
132  # Disable the EventT0 correction.
133  basf2.set_module_parameters(main, 'KLMReconstructor', EventT0Correction=False)
134  else:
135  main.add_module('Gearbox')
136  main.add_module('Geometry')
137 
138  # Fill muon particle list
139  ma.fillParticleList(f'mu+:{muon_list_name}',
140  '[1 < p] and [p < 11] and [abs(d0) < 2] and [abs(z0) < 5]',
141  path=main)
142 
143  return main
144 
145 
146 def get_time_pre_collector_path(muon_list_name, entry_sequence="",
147  raw_format=True, mc=False):
148  """
149  Parameters:
150  muon_list_name (str): Name of the muon ParticleList to be filled.
151  entry_sequence (str): A single entry sequence e.g. '0:100' to help limit processed events.
152  raw_format (bool): True if cDST input files are in the raw+tracking format.
153 
154  Returns:
155  basf2.Path: A reconstruction path to run before the collector. Used for cDST input files.
156  """
157  main = basf2.create_path()
158  if entry_sequence:
159  main.add_module('RootInput',
160  entrySequences=[entry_sequence])
161  if raw_format:
162  prepare_cdst_analysis(main, mc=mc)
163  # Disable the EventT0 correction.
164  basf2.set_module_parameters(main, 'KLMReconstructor', EventT0Correction=False)
165  # Disable the time window in muid module by setting it to 1 second.
166  # This is necessary because we are running now the time calibration.
167  basf2.set_module_parameters(main, 'Muid', MaxDt=1e9)
168  else:
169  main.add_module('Gearbox')
170  main.add_module('Geometry')
171 
172  # Fill muon particle list
173  ma.fillParticleList(f'mu+:{muon_list_name}',
174  '[1 < p] and [p < 11] and [abs(d0) < 2] and [abs(z0) < 5]',
175  path=main)
176 
177  return main