Belle II Software  release-08-01-10
caf_klm_strip_efficiency.py
1 
8 
9 """
10 Calibration of KLM strip efficiency. It provides calibration constants for the KLMSripEfficiency
11 database object.
12 """
13 
14 import basf2
15 from prompt import CalibrationSettings, INPUT_DATA_FILTERS
16 
17 
24 
25 
26 settings = CalibrationSettings(
27  name='KLM strip efficiency',
28  expert_username='nbrenny',
29  description=__doc__,
30  input_data_formats=['cdst'],
31  input_data_names=['hlt_mumu'],
32  input_data_filters={
33  'hlt_mumu': [INPUT_DATA_FILTERS['Run Type']['physics'],
34  INPUT_DATA_FILTERS['Data Tag']['mumu_tight_or_highm_calib'],
35  INPUT_DATA_FILTERS['Data Quality Tag']['Good Or Recoverable']]
36  },
37  depends_on=[])
38 
39 
40 
41 
50 
51 
52 def get_calibrations(input_data, **kwargs):
53  """
54  Parameters:
55  input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
56  Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
57  assigning to calibration.files_to_iov
58 
59  **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
60  backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
61  release explicitly if you want to.
62 
63  Currently only kwargs["requested_iov"] is used. This is the output IoV range that your payloads should
64  correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
65 
66  Returns:
67  list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
68  """
69  # Set up config options
70 
71  # In this script we want to use one sources of input data.
72  # Get the input files from the input_data variable
73  file_to_iov_cdst = input_data['hlt_mumu']
74 
75  # We might have requested an enormous amount of data across a run range.
76  # There's a LOT more files than runs!
77  # Lets set some limits because this calibration doesn't need that much to run.
78  # max_files_per_run = 2
79 
80  # If you are using Raw data there's a chance that input files could have zero events.
81  # This causes a B2FATAL in basf2 RootInput so the collector job will fail.
82  # Currently we don't have a good way of filtering this on the automated side, so we can check here.
83  # min_events_per_file = 1
84 
85  # We filter out any more than 2 files per run. The input data files are sorted alphabetically by b2caf-prompt-run
86  # already. This procedure respects that ordering
87 
88  # For testing
89  # reduced_file_to_iov_cdst = filter_by_max_files_per_run(file_to_iov_cdst, max_files_per_run, min_events_per_file)
90  # input_files_cdst = sorted(list(reduced_file_to_iov_cdst.keys()))
91  input_files_cdst = sorted(list(file_to_iov_cdst.keys()))
92  basf2.B2INFO(f'Total number of \'hlt_mumu\' files actually used as input = {len(input_files_cdst)}')
93 
94  if not input_files_cdst:
95  raise Exception('No valid input files found!')
96 
97  # Get the overall IoV we our process should cover. Includes the end values that we may want to ignore since our output
98  # IoV should be open ended. We could also use this as part of the input data selection in some way.
99  requested_iov = kwargs['requested_iov']
100 
101  from caf.utils import IoV
102  # The actual value our output IoV payload should have. Notice that we've set it open ended.
103  output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
104 
105 
107 
108  from ROOT.Belle2 import KLMStripEfficiencyAlgorithm
109 
110  alg = KLMStripEfficiencyAlgorithm()
111 
112 
114 
115  from caf.framework import Calibration, Collection
116 
117  cal_klm = Calibration('KLMStripEfficiency')
118 
119 
121 
122  from klm_calibration_utils import get_strip_efficiency_pre_collector_path
123 
124  if input_files_cdst:
125  muon_list_name = 'klmStripEfficiency'
126  coll_cdst = get_collector(input_data_name='hlt_mumu',
127  muon_list_name=muon_list_name)
128  rec_path_cdst = get_strip_efficiency_pre_collector_path(muon_list_name=muon_list_name)
129 
130  collection_cdst = Collection(collector=coll_cdst,
131  input_files=input_files_cdst,
132  pre_collector_path=rec_path_cdst)
133 
134  cal_klm.add_collection(name='cdst', collection=collection_cdst)
135 
136 
138 
139  cal_klm.algorithms = [alg]
140 
141  from klm_strip_efficiency import KLMStripEfficiency
142 
143  for algorithm in cal_klm.algorithms:
144  algorithm.strategy = KLMStripEfficiency
145  algorithm.params = {'iov_coverage': output_iov}
146 
147  # You must return all calibrations you want to run in the prompt process, even if it's only one
148  return [cal_klm]
149 
150 
151 
152 
153 def get_collector(input_data_name, muon_list_name):
154  """
155  Return the correct KLMStripEfficiencyCollector module setup for each data type.
156  Placed here so it can be different for prompt compared to standard.
157  """
158 
159  if input_data_name == 'hlt_mumu':
160  return basf2.register_module('KLMStripEfficiencyCollector',
161  MuonListName=f'mu+:{muon_list_name}',
162  MinimalMatchingDigits=14,
163  MinimalMatchingDigitsOuterLayers=4,
164  MinimalMomentumNoOuterLayers=4.0)
165  raise Exception("Unknown input data name used when setting up collector")