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