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