Belle II Software development
caf_klm_strip_efficiency.py
1
8
9"""
10Calibration of KLM strip efficiency. It provides calibration constants for the KLMSripEfficiency
11database object.
12"""
13
14import basf2
15from prompt import CalibrationSettings, INPUT_DATA_FILTERS
16
17
24
25
26settings = CalibrationSettings(
27 name='KLM strip efficiency',
28 expert_username='nbrenny',
29 subsystem='klm',
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']['mumu_tight_or_highm_calib'],
36 INPUT_DATA_FILTERS['Data Quality Tag']['Good Or Recoverable']]
37 },
38 depends_on=[],
39 produced_payloads=["KLMStripEfficiency"])
40
41
42
51
52
53def 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
76 # We might have requested an enormous amount of data across a run range.
77 # There's a LOT more files than runs!
78 # Lets set some limits because this calibration doesn't need that much to run.
79 # max_files_per_run = 2
80
81 # If you are using Raw data there's a chance that input files could have zero events.
82 # This causes a B2FATAL in basf2 RootInput so the collector job will fail.
83 # Currently we don't have a good way of filtering this on the automated side, so we can check here.
84 # min_events_per_file = 1
85
86 # We filter out any more than 2 files per run. The input data files are sorted alphabetically by b2caf-prompt-run
87 # already. This procedure respects that ordering
88
89 # For testing
90 # reduced_file_to_iov_cdst = filter_by_max_files_per_run(file_to_iov_cdst, max_files_per_run, min_events_per_file)
91 # input_files_cdst = sorted(list(reduced_file_to_iov_cdst.keys()))
92 input_files_cdst = sorted(list(file_to_iov_cdst.keys()))
93 basf2.B2INFO(f'Total number of \'hlt_mumu\' files actually used as input = {len(input_files_cdst)}')
94
95 if not input_files_cdst:
96 raise Exception('No valid input files found!')
97
98 # Get the overall IoV we our process should cover. Includes the end values that we may want to ignore since our output
99 # IoV should be open ended. We could also use this as part of the input data selection in some way.
100 requested_iov = kwargs['requested_iov']
101
102 from caf.utils import IoV
103 # The actual value our output IoV payload should have. Notice that we've set it open ended.
104 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
105
106
108 from ROOT import Belle2 # noqa: make the Belle2 namespace available
109 from ROOT.Belle2 import KLMStripEfficiencyAlgorithm
110
111 alg = KLMStripEfficiencyAlgorithm()
112
113
115
116 from caf.framework import Calibration, Collection
117
118 cal_klm = Calibration('KLMStripEfficiency')
119
120
122
123 from klm_calibration_utils import get_strip_efficiency_pre_collector_path
124
125 if input_files_cdst:
126 muon_list_name = 'klmStripEfficiency'
127 coll_cdst = get_collector(input_data_name='hlt_mumu',
128 muon_list_name=muon_list_name)
129 rec_path_cdst = get_strip_efficiency_pre_collector_path(muon_list_name=muon_list_name)
130
131 collection_cdst = Collection(collector=coll_cdst,
132 input_files=input_files_cdst,
133 pre_collector_path=rec_path_cdst)
134
135 cal_klm.add_collection(name='cdst', collection=collection_cdst)
136
137
139
140 cal_klm.algorithms = [alg]
141
142 from klm_strip_efficiency import KLMStripEfficiency
143
144 for algorithm in cal_klm.algorithms:
145 algorithm.strategy = KLMStripEfficiency
146 algorithm.params = {'iov_coverage': output_iov}
147
148 # You must return all calibrations you want to run in the prompt process, even if it's only one
149 return [cal_klm]
150
151
152
153
154def get_collector(input_data_name, muon_list_name):
155 """
156 Return the correct KLMStripEfficiencyCollector module setup for each data type.
157 Placed here so it can be different for prompt compared to standard.
158 """
159
160 if input_data_name == 'hlt_mumu':
161 return basf2.register_module('KLMStripEfficiencyCollector',
162 MuonListName=f'mu+:{muon_list_name}',
163 MinimalMatchingDigits=14,
164 MinimalMatchingDigitsOuterLayers=4,
165 MinimalMomentumNoOuterLayers=4.0)
166 raise Exception("Unknown input data name used when setting up collector")