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