3 """Calibration of KLM channel status."""
8 from caf.utils
import ExpRun, IoV
9 from prompt
import CalibrationSettings
21 settings = CalibrationSettings(
22 name=
'KLM channel status',
23 expert_username=
'zhai',
25 input_data_formats=[
'raw'],
26 input_data_names=[
'raw_beam',
'raw_cosmic',
'raw_physics'],
32 def select_input_files(file_to_iov):
35 files_to_iov (dict): Dictionary {run : IOV}.
36 reduced_file_to_iov (dict): Selected data.
38 run_to_files = collections.defaultdict(list)
39 for input_file, file_iov
in file_to_iov.items():
40 run = ExpRun(exp=file_iov.exp_low, run=file_iov.run_low)
42 if events_in_basf2_file(input_file) > 0:
43 run_to_files[run].append(input_file)
44 reduced_file_to_iov = collections.OrderedDict()
45 for run, files
in run_to_files.items():
46 for input_file
in files:
47 reduced_file_to_iov[input_file] = IoV(*run, *run)
48 return reduced_file_to_iov
61 def get_calibrations(input_data, **kwargs):
64 input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
65 Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
66 assigning to calibration.files_to_iov
68 **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
69 backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
70 release explicitly if you want to.
72 Currently only kwargs["requested_iov"] is used. This is the output IoV range that your payloads should
73 correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
76 list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
82 file_to_iov_raw_beam = input_data[
'raw_beam']
83 file_to_iov_raw_cosmic = input_data[
'raw_cosmic']
84 file_to_iov_raw_physics = input_data[
'raw_physics']
87 reduced_file_to_iov_raw_beam = select_input_files(file_to_iov_raw_beam)
88 reduced_file_to_iov_raw_cosmic = select_input_files(file_to_iov_raw_cosmic)
89 reduced_file_to_iov_raw_physics = select_input_files(file_to_iov_raw_physics)
92 input_files_raw = list(reduced_file_to_iov_raw_beam.keys())
93 input_files_raw.extend(list(reduced_file_to_iov_raw_cosmic.keys()))
94 input_files_raw.extend(list(reduced_file_to_iov_raw_physics.keys()))
95 input_files_raw.sort()
96 basf2.B2INFO(f
'Total number of raw-data files used as input = {len(input_files_raw)}')
98 if not input_files_raw:
99 raise Exception(
'No valid input files found!')
103 requested_iov = kwargs[
'requested_iov']
105 from caf.utils
import IoV
107 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
112 from ROOT.Belle2
import KLMChannelStatusAlgorithm
114 alg = KLMChannelStatusAlgorithm()
119 from caf.framework
import Calibration, Collection
126 from klm_calibration_utils
import get_channel_status_pre_collector_path
129 coll_raw = get_collector(
'raw')
130 rec_path_raw = get_channel_status_pre_collector_path()
132 collection_raw =
Collection(collector=coll_raw,
133 input_files=input_files_raw,
134 pre_collector_path=rec_path_raw)
136 cal_klm.add_collection(name=
'raw', collection=collection_raw)
141 cal_klm.algorithms = [alg]
143 from klm_channel_status
import KLMChannelStatus
145 for algorithm
in cal_klm.algorithms:
146 algorithm.strategy = KLMChannelStatus
147 algorithm.params = {
'iov_coverage': output_iov}
155 def get_collector(input_data_name):
157 Return the correct KLMChannelStatusCollector module setup for each data type.
158 Placed here so it can be different for prompt compared to standard.
161 if input_data_name ==
'raw':
162 return basf2.register_module(
'KLMChannelStatusCollector')
163 raise Exception(
"Unknown input data name used when setting up collector")