Belle II Software  release-08-01-10
caf_top_pre.py
1 
8 
9 """
10 Airflow script for TOP pre-tracking calibration:
11  channel masks
12 """
13 import basf2
14 from prompt import CalibrationSettings, INPUT_DATA_FILTERS
15 from caf.utils import IoV
16 from caf.strategies import SequentialBoundaries
17 from top_calibration import channel_mask_calibration
18 from prompt.utils import filter_by_max_files_per_run
19 
20 
21 settings = CalibrationSettings(
22  name="TOP pre-tracking calibration",
23  expert_username="skohani",
24  description=__doc__,
25  input_data_formats=["raw"],
26  input_data_names=["hadron_calib"],
27  input_data_filters={
28  "hadron_calib": [
29  INPUT_DATA_FILTERS["Data Tag"]["hadron_calib"],
30  INPUT_DATA_FILTERS["Run Type"]["physics"],
31  INPUT_DATA_FILTERS["Data Quality Tag"]["Good Or Recoverable"]]},
32  depends_on=[],
33  expert_config={
34  "max_files_per_run": 20,
35  "payload_boundaries": None,
36  "request_memory": "8 GB"
37  })
38 
39 
40 # Required function
41 def get_calibrations(input_data, **kwargs):
42  '''
43  Returns a list of calibration objects.
44  :input_data (dict): Contains every file name from the 'input_data_names' as a key.
45  :**kwargs: Configuration options to be sent in.
46  '''
47  file_to_iov = input_data["hadron_calib"]
48  expert_config = kwargs.get("expert_config")
49  max_files_per_run = expert_config["max_files_per_run"]
50  min_events_per_file = 1
51  # Applying the min event per file to remove empty root files
52  reduced_file_to_iov = filter_by_max_files_per_run(file_to_iov, max_files_per_run, min_events_per_file, random_select=True)
53  inputFiles = list(reduced_file_to_iov.keys())
54  basf2.B2INFO(f"Total number of files actually used as input = {len(inputFiles)}")
55  requested_iov = kwargs.get("requested_iov", None)
56  output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
57 
58  cal = [channel_mask_calibration(inputFiles)] # this is run-dep
59 
60  for c in cal:
61  # If it's a SequentialBoundary calibration, check if there is any boundary in the config file
62  if c.strategies[0] == SequentialBoundaries:
63 
64  # Default boundaries. If there are no boundaries in the config file, this calibration will give a single IoV
65  payload_boundaries = [[output_iov.exp_low, output_iov.run_low]]
66 
67  # user-defined boundaries are set here.
68  if expert_config["payload_boundaries"] is not None:
69  payload_boundaries = expert_config["payload_boundaries"]
70 
71  # Set the actual boundaries.
72  for alg in c.algorithms:
73  alg.params = {"iov_coverage": output_iov, "payload_boundaries": payload_boundaries}
74 
75  # If it's not a SequentialBoundary calbration, just set the IoV coverage
76  else:
77  for alg in c.algorithms:
78  alg.params = {"iov_coverage": output_iov}
79 
80  return cal