3 """Calibration of KLM channel status."""
8 from caf.utils
import ExpRun, IoV
9 from prompt
import CalibrationSettings, input_data_filters
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'],
28 'raw_beam': [input_data_filters[
'Run Type'][
'beam'],
29 input_data_filters[
'Data Quality Tag'][
'Good Or Recoverable']],
30 'raw_cosmic': [input_data_filters[
'Run Type'][
'cosmic'],
31 input_data_filters[
'Data Quality Tag'][
'Good Or Recoverable']],
32 'raw_physics': [input_data_filters[
'Run Type'][
'physics'],
33 f
"NOT {input_data_filters['Data Tag']['random_calib']}",
34 input_data_filters[
'Data Tag'][
'bhabha_all_calib'],
35 input_data_filters[
'Data Tag'][
'gamma_gamma_calib'],
36 input_data_filters[
'Data Tag'][
'hadron_calib'],
37 input_data_filters[
'Data Tag'][
'mumutight_calib'],
38 input_data_filters[
'Data Tag'][
'radmumu_calib'],
39 input_data_filters[
'Data Quality Tag'][
'Good Or Recoverable']]
46 def select_input_files(file_to_iov):
49 files_to_iov (dict): Dictionary {run : IOV}.
50 reduced_file_to_iov (dict): Selected data.
52 run_to_files = collections.defaultdict(list)
53 for input_file, file_iov
in file_to_iov.items():
54 run = ExpRun(exp=file_iov.exp_low, run=file_iov.run_low)
56 if events_in_basf2_file(input_file) > 0:
57 run_to_files[run].append(input_file)
58 reduced_file_to_iov = collections.OrderedDict()
59 for run, files
in run_to_files.items():
60 for input_file
in files:
61 reduced_file_to_iov[input_file] = IoV(*run, *run)
62 return reduced_file_to_iov
75 def get_calibrations(input_data, **kwargs):
78 input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
79 Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
80 assigning to calibration.files_to_iov
82 **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
83 backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
84 release explicitly if you want to.
86 Currently only kwargs["requested_iov"] is used. This is the output IoV range that your payloads should
87 correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
90 list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
96 file_to_iov_raw_beam = input_data[
'raw_beam']
97 file_to_iov_raw_cosmic = input_data[
'raw_cosmic']
98 file_to_iov_raw_physics = input_data[
'raw_physics']
101 reduced_file_to_iov_raw_beam = select_input_files(file_to_iov_raw_beam)
102 reduced_file_to_iov_raw_cosmic = select_input_files(file_to_iov_raw_cosmic)
103 reduced_file_to_iov_raw_physics = select_input_files(file_to_iov_raw_physics)
106 input_files_raw = list(reduced_file_to_iov_raw_beam.keys())
107 input_files_raw.extend(list(reduced_file_to_iov_raw_cosmic.keys()))
108 input_files_raw.extend(list(reduced_file_to_iov_raw_physics.keys()))
109 input_files_raw.sort()
110 basf2.B2INFO(f
'Total number of raw-data files used as input = {len(input_files_raw)}')
112 if not input_files_raw:
113 raise Exception(
'No valid input files found!')
117 requested_iov = kwargs[
'requested_iov']
119 from caf.utils
import IoV
121 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
126 from ROOT.Belle2
import KLMChannelStatusAlgorithm
128 alg = KLMChannelStatusAlgorithm()
133 from caf.framework
import Calibration, Collection
140 from klm_calibration_utils
import get_channel_status_pre_collector_path
143 coll_raw = get_collector(
'raw')
144 rec_path_raw = get_channel_status_pre_collector_path()
146 collection_raw =
Collection(collector=coll_raw,
147 input_files=input_files_raw,
148 pre_collector_path=rec_path_raw)
150 cal_klm.add_collection(name=
'raw', collection=collection_raw)
155 cal_klm.algorithms = [alg]
157 from klm_channel_status
import KLMChannelStatus
159 for algorithm
in cal_klm.algorithms:
160 algorithm.strategy = KLMChannelStatus
161 algorithm.params = {
'iov_coverage': output_iov}
169 def get_collector(input_data_name):
171 Return the correct KLMChannelStatusCollector module setup for each data type.
172 Placed here so it can be different for prompt compared to standard.
175 if input_data_name ==
'raw':
176 return basf2.register_module(
'KLMChannelStatusCollector')
177 raise Exception(
"Unknown input data name used when setting up collector")