Belle II Software  release-05-01-25
caf_top.py
1 # -*- coding: utf-8 -*-
2 
3 """
4 Airflow script for TOP post-tracking calibration:
5  BS13d carrier shifts, module T0 and common T0
6 
7 Author: Marko Staric, Umberto Tamponi
8 """
9 
10 from prompt import CalibrationSettings
11 from caf.utils import vector_from_runs, IoV, ExpRun
12 from caf.strategies import SingleIOV, SequentialBoundaries
13 from top_calibration import BS13d_calibration_cdst
14 from top_calibration import moduleT0_calibration_DeltaT, moduleT0_calibration_LL
15 from top_calibration import commonT0_calibration_BF
16 
17 
18 
19 settings = CalibrationSettings(name="TOP post-tracking calibration",
20  expert_username="skohani",
21  description=__doc__,
22  input_data_formats=["cdst"],
23  input_data_names=["hlt_bhabha"],
24  depends_on=[],
25  expert_config={"payload_boundaries": None})
26 
27 
28 # Required function
29 def get_calibrations(input_data, **kwargs):
30  '''
31  Returns a list of calibration objects.
32  :input_data (dict): Contains every file name from the 'input_data_names' as a key.
33  :**kwargs: Configuration options to be sent in.
34  '''
35 
36  file_to_iov = input_data["hlt_bhabha"]
37  sample = 'bhabha'
38  inputFiles = list(file_to_iov.keys())
39  requested_iov = kwargs.get("requested_iov", None)
40  expert_config = kwargs.get("expert_config")
41  output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
42 
43  cal = [BS13d_calibration_cdst(inputFiles), # this is run-dep
44  moduleT0_calibration_DeltaT(inputFiles), # this cal cannot span across experiments
45  moduleT0_calibration_LL(inputFiles, sample), # this cal cannot span across experiments
46  commonT0_calibration_BF(inputFiles)]
47 
48  for c in cal:
49  # If it's a SequentialBoundary calibration, check if there is any boundary in the config file
50  if c.strategies[0] == SequentialBoundaries:
51 
52  # Default boundaries. If there are no boundaries in the config file, this calibration will give a single IoV
53  payload_boundaries = [[output_iov.exp_low, output_iov.run_low]]
54 
55  # user-defined boundaries are set here.
56  if expert_config["payload_boundaries"] is not None:
57  payload_boundaries = expert_config["payload_boundaries"]
58 
59  # Set the actual boundaries.
60  for alg in c.algorithms:
61  alg.params = {"iov_coverage": output_iov, "payload_boundaries": payload_boundaries}
62 
63  # If it's not a SequentialBoundary calbration, just set the IoV coverage
64  else:
65  for alg in c.algorithms:
66  alg.params = {"iov_coverage": output_iov}
67 
68  # Don't save the rough moduleT0 result
69  cal[1].save_payloads = False
70 
71  cal[1].depends_on(cal[0])
72  cal[2].depends_on(cal[1])
73  cal[3].depends_on(cal[2])
74 
75  return cal