10Calibration of KLM channel status. It provides calibration constants for the KLMChannelStatus
17from caf.utils
import ExpRun, IoV
18from prompt
import CalibrationSettings, INPUT_DATA_FILTERS
30settings = CalibrationSettings(
31 name=
'KLM channel status',
32 expert_username=
'sayan97',
34 input_data_formats=[
'raw'],
35 input_data_names=[
'raw_beam',
'raw_cosmic',
'raw_physics'],
37 'raw_beam': [INPUT_DATA_FILTERS[
'Run Type'][
'beam'],
38 INPUT_DATA_FILTERS[
'Data Quality Tag'][
'Good Or Recoverable']],
39 'raw_cosmic': [INPUT_DATA_FILTERS[
'Run Type'][
'cosmic'],
40 INPUT_DATA_FILTERS[
'Data Quality Tag'][
'Good Or Recoverable']],
41 'raw_physics': [INPUT_DATA_FILTERS[
'Run Type'][
'physics'],
42 f
"NOT {INPUT_DATA_FILTERS['Data Tag']['random_calib']}",
43 INPUT_DATA_FILTERS[
'Data Tag'][
'hlt_skim'],
44 INPUT_DATA_FILTERS[
'Data Quality Tag'][
'Good Or Recoverable']]
51def select_input_files(file_to_iov):
54 files_to_iov (dict): Dictionary {run : IOV}.
55 reduced_file_to_iov (dict): Selected data.
57 run_to_files = collections.defaultdict(list)
58 for input_file, file_iov
in file_to_iov.items():
59 run = ExpRun(exp=file_iov.exp_low, run=file_iov.run_low)
61 if events_in_basf2_file(input_file) > 0:
62 run_to_files[run].append(input_file)
63 reduced_file_to_iov = collections.OrderedDict()
64 for run, files
in run_to_files.items():
65 for input_file
in files:
66 reduced_file_to_iov[input_file] = IoV(*run, *run)
67 return reduced_file_to_iov
80def get_calibrations(input_data, **kwargs):
83 input_data (dict): Should contain every name from the
'input_data_names' variable
as a key.
84 Each value
is a dictionary
with {
"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful
for
85 assigning to calibration.files_to_iov
87 **kwargs: Configuration options to be sent
in. Since this may change we use kwargs
as a way to help prevent
88 backwards compatibility problems. But you could use the correct arguments
in b2caf-prompt-run
for this
89 release explicitly
if you want to.
91 Currently only kwargs[
"requested_iov"]
is used. This
is the output IoV range that your payloads should
92 correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
95 list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
101 file_to_iov_raw_beam = input_data[
'raw_beam']
102 file_to_iov_raw_cosmic = input_data[
'raw_cosmic']
103 file_to_iov_raw_physics = input_data[
'raw_physics']
106 reduced_file_to_iov_raw_beam = select_input_files(file_to_iov_raw_beam)
107 reduced_file_to_iov_raw_cosmic = select_input_files(file_to_iov_raw_cosmic)
108 reduced_file_to_iov_raw_physics = select_input_files(file_to_iov_raw_physics)
111 input_files_raw = list(reduced_file_to_iov_raw_beam.keys())
112 input_files_raw.extend(list(reduced_file_to_iov_raw_cosmic.keys()))
113 input_files_raw.extend(list(reduced_file_to_iov_raw_physics.keys()))
114 input_files_raw.sort()
115 basf2.B2INFO(f
'Total number of raw-data files used as input = {len(input_files_raw)}')
117 if not input_files_raw:
118 raise Exception(
'No valid input files found!')
122 requested_iov = kwargs[
'requested_iov']
124 from caf.utils
import IoV
126 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
130 from ROOT
import Belle2
131 from ROOT.Belle2
import KLMChannelStatusAlgorithm
133 alg = KLMChannelStatusAlgorithm()
138 from caf.framework
import Calibration, Collection
145 from klm_calibration_utils
import get_channel_status_pre_collector_path
148 coll_raw = get_collector(
'raw')
149 rec_path_raw = get_channel_status_pre_collector_path()
151 collection_raw =
Collection(collector=coll_raw,
152 input_files=input_files_raw,
153 pre_collector_path=rec_path_raw)
155 cal_klm.add_collection(name=
'raw', collection=collection_raw)
160 cal_klm.algorithms = [alg]
162 from klm_channel_status
import KLMChannelStatus
164 for algorithm
in cal_klm.algorithms:
165 algorithm.strategy = KLMChannelStatus
166 algorithm.params = {
'iov_coverage': output_iov}
174def get_collector(input_data_name):
176 Return the correct KLMChannelStatusCollector module setup for each data type.
177 Placed here so it can be different
for prompt compared to standard.
180 if input_data_name ==
'raw':
181 return basf2.register_module(
'KLMChannelStatusCollector')
182 raise Exception(
"Unknown input data name used when setting up collector")