Belle II Software  release-08-01-10
caf_klm_time.py
1 
8 
9 """
10 Calibration of KLM time. It provides calibration constants for the KLMTimeCableDelay
11 and KLMTimeConstants database objects.
12 """
13 
14 import basf2
15 from prompt import CalibrationSettings, INPUT_DATA_FILTERS
16 
17 
24 
25 
26 settings = CalibrationSettings(name='KLM time',
27  expert_username='seemac',
28  description=__doc__,
29  input_data_formats=['cdst'],
30  input_data_names=['hlt_mumu'],
31  input_data_filters={
32  'hlt_mumu': [INPUT_DATA_FILTERS['Run Type']['physics'],
33  INPUT_DATA_FILTERS['Data Tag']['mumu_tight_or_highm_calib'],
34  INPUT_DATA_FILTERS['Data Quality Tag']['Good Or Recoverable']]
35  },
36  depends_on=[])
37 
38 
39 
40 
49 
50 
51 def get_calibrations(input_data, **kwargs):
52  """
53  Parameters:
54  input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
55  Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
56  assigning to calibration.files_to_iov
57 
58  **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
59  backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
60  release explicitly if you want to.
61 
62  Currently only kwargs["requested_iov"] is used. This is the output IoV range that your payloads should
63  correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
64 
65  Returns:
66  list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
67  """
68  # Set up config options
69 
70  # In this script we want to use one sources of input data.
71  # Get the input files from the input_data variable
72  file_to_iov_cdst = input_data['hlt_mumu']
73  input_files_cdst = sorted(list(file_to_iov_cdst.keys()))
74  basf2.B2INFO(f'Total number of \'hlt_mumu\' files actually used as input = {len(input_files_cdst)}')
75 
76  if not input_files_cdst:
77  raise Exception('No valid input files found!')
78 
79  # Get the overall IoV we our process should cover. Includes the end values that we may want to ignore since our output
80  # IoV should be open ended. We could also use this as part of the input data selection in some way.
81  requested_iov = kwargs['requested_iov']
82 
83  from caf.utils import IoV
84  # The actual value our output IoV payload should have. Notice that we've set it open ended.
85  output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
86 
87 
89 
90  from ROOT.Belle2 import KLMTimeAlgorithm
91 
92  alg = KLMTimeAlgorithm()
93 
94 
96 
97  from caf.framework import Calibration, Collection
98 
99  cal_klm = Calibration('KLMTime')
100 
101 
103 
104  from klm_calibration_utils import get_time_pre_collector_path
105 
106  if input_files_cdst:
107  muon_list_name = 'klmTime'
108  coll_cdst = get_collector(input_data_name='hlt_mumu',
109  muon_list_name=muon_list_name)
110  rec_path_cdst = get_time_pre_collector_path(muon_list_name=muon_list_name)
111 
112  collection_cdst = Collection(collector=coll_cdst,
113  input_files=input_files_cdst,
114  pre_collector_path=rec_path_cdst)
115 
116  cal_klm.add_collection(name='cdst', collection=collection_cdst)
117 
118 
120 
121  cal_klm.algorithms = [alg]
122 
123  from caf.strategies import SequentialRunByRun
124 
125  for algorithm in cal_klm.algorithms:
126  algorithm.strategy = SequentialRunByRun
127  algorithm.params = {'iov_coverage': output_iov}
128 
129  # You must return all calibrations you want to run in the prompt process, even if it's only one
130  return [cal_klm]
131 
132 
133 
134 
135 def get_collector(input_data_name, muon_list_name):
136  """
137  Return the correct KLMTimeCollector module setup for each data type.
138  Placed here so it can be different for prompt compared to standard.
139  """
140 
141  if input_data_name == 'hlt_mumu':
142  return basf2.register_module('KLMTimeCollector',
143  inputParticleList=f'mu+:{muon_list_name}')
144  raise Exception("Unknown input data name used when setting up collector")