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