Belle II Software  release-08-01-10
caf_ecl_time_validate_bhabha_and_hadronic.py
1 # -*- coding: utf-8 -*-
2 
3 
10 
11 """ECL timing validations. Does both the bhabha self-consistency check and the hadronic event selection validation."""
12 
13 from prompt import CalibrationSettings
14 from reconstruction import prepare_user_cdst_analysis
15 
16 
17 
24 
25 
28 settings = CalibrationSettings(
29  name="ECL time validations - bhabha and hadronic selections",
30  expert_username="ehill",
31  description=__doc__,
32  input_data_formats=["cdst"],
33  input_data_names=["bhabha_all_calib", "hadron_calib"],
34  input_data_filters={
35  "bhabha_all_calib": [
36  "bhabha_all_calib",
37  "4S",
38  "Continuum",
39  "Scan",
40  "Good",
41  "physics",
42  "On"],
43  "hadron_calib": [
44  "hadron_calib",
45  "4S",
46  "Continuum",
47  "Scan",
48  "Good",
49  "physics",
50  "On"]},
51  depends_on=[])
52 
53 
54 
55 
64 
65 
66 def get_calibrations(input_data, **kwargs):
67  """
68  Parameters:
69  input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
70  Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
71  assigning to calibration.files_to_iov
72 
73  **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
74  backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
75  release explicitly if you want to.
76 
77  Currently only kwargs["output_iov"] is used. This is the output IoV range that your payloads should
78  correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
79 
80  Returns:
81  list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
82  """
83  import basf2
84  # Set up config options
85 
86  # In this script we want to use one sources of input data.
87  # Get the input files from the input_data variable
88  # The input data should be the bhabha and hadron skims
89  file_to_iov_bhabha = input_data["bhabha_all_calib"]
90  file_to_iov_hadron = input_data["hadron_calib"]
91 
92  max_events_per_run = 3000
93 
94  # We filter addition files if there are more than [max_events_per_run] files per run.
95  # The input data files are sorted alphabetically by b2caf-prompt-run
96  # already. This procedure respects that ordering
97  from prompt.utils import filter_by_max_events_per_run
98 
99  reduced_file_to_iov_bhabha = filter_by_max_events_per_run(file_to_iov_bhabha, max_events_per_run)
100  input_files_bhabha = list(reduced_file_to_iov_bhabha.keys())
101  basf2.B2INFO(f"Total number of bhabha files actually used as input = {len(input_files_bhabha)}")
102 
103  reduced_file_to_iov_hadron = filter_by_max_events_per_run(file_to_iov_hadron, max_events_per_run)
104  input_files_hadron = list(reduced_file_to_iov_hadron.keys())
105  basf2.B2INFO(f"Total number of hadron files actually used as input = {len(input_files_hadron)}")
106 
107 
108  from basf2 import register_module, create_path
109  from ROOT import Belle2
110  from caf.framework import Collection
111 
112 
114  root_input = register_module('RootInput')
115  rec_path_bhabha = create_path()
116  rec_path_bhabha.add_module(root_input)
117  if 'Gearbox' not in rec_path_bhabha:
118  rec_path_bhabha.add_module('Gearbox')
119  if 'Geometry' not in rec_path_bhabha:
120  rec_path_bhabha.add_module('Geometry', useDB=True)
121 
122  prepare_user_cdst_analysis(rec_path_bhabha) # for new 2020 cdst format
123 
124  col_bhabha = register_module('eclBhabhaTimeCalibrationValidationCollector')
125  col_bhabha.param('timeAbsMax', 70)
126  col_bhabha.param('saveTree', False)
127 
128  eclValTCol = Collection(collector=col_bhabha,
129  input_files=input_files_bhabha,
130  pre_collector_path=rec_path_bhabha)
131 
132 
134 
135  # Give the collector name to the algorithm since one algorithm
136  # is used to analyse the results from several possible collectors
137  eclValTAlgBhabha = Belle2.ECL.eclTValidationAlgorithm("eclBhabhaTimeCalibrationValidationCollector")
138 
139  # Define the CAF algorithm arguments
140  # eclValTAlgBhabha.cellIDLo= 3
141  # eclValTAlgBhabha.cellIDHi = 2
142  eclValTAlgBhabha.meanCleanRebinFactor = 3
143  eclValTAlgBhabha.meanCleanCutMinFactor = 0.4
144  eclValTAlgBhabha.debugFilenameBase = "eclBhabhaTValidationAlgorithm"
145 
146 
148 
149  from caf.framework import Calibration
150 
151  valid_cal_bhabha = Calibration("ECLcrystalTimeCalValidation_bhabhaPhysics")
152  valid_cal_bhabha.add_collection(name="bhabha", collection=eclValTCol)
153  valid_cal_bhabha.algorithms = [eclValTAlgBhabha]
154 
155  # Here we set the AlgorithmStrategy for our algorithm
156  from caf.strategies import SingleIOV
157 
158  # The default value is SingleIOV, you don't have to set this, it is done automatically.
159  # SingleIOV just takes all of the runs as one big IoV and executes the algorithm once on all of their data.
160  # You can use granularity='run' or granularity='all' for the collector when using this strategy.
161 
162  valid_cal_bhabha.strategies = SingleIOV
163 
164 
166  root_input = register_module('RootInput')
167  rec_path_hadron = create_path()
168  rec_path_hadron.add_module(root_input)
169  if 'Gearbox' not in rec_path_hadron:
170  rec_path_hadron.add_module('Gearbox')
171  if 'Geometry' not in rec_path_hadron:
172  rec_path_hadron.add_module('Geometry', useDB=True)
173 
174  prepare_user_cdst_analysis(rec_path_hadron) # for new 2020 cdst format
175 
176  col_hadron = register_module('eclHadronTimeCalibrationValidationCollector')
177  col_hadron.param('timeAbsMax', 70)
178  col_hadron.param('saveTree', False)
179 
180  eclValTCol = Collection(collector=col_hadron,
181  input_files=input_files_hadron,
182  pre_collector_path=rec_path_hadron)
183 
184 
186 
187  # Give the collector name to the algorithm since one algorithm
188  # is used to analyse the results from several possible collectors
189  eclValTAlgHadronic = Belle2.ECL.eclTValidationAlgorithm("eclHadronTimeCalibrationValidationCollector")
190 
191  # Define the CAF algorithm arguments
192  # eclValTAlgHadronic.cellIDLo= 3
193  # eclValTAlgHadronic.cellIDHi = 2
194  eclValTAlgHadronic.meanCleanRebinFactor = 3
195  eclValTAlgHadronic.meanCleanCutMinFactor = 0.4
196  eclValTAlgHadronic.debugFilenameBase = "eclHadronTValidationAlgorithm"
197 
198 
200 
201  from caf.framework import Calibration
202 
203  valid_cal_hadron = Calibration("ECLcrystalTimeCalValidation_hadronPhysics")
204  valid_cal_hadron.add_collection(name="hadron", collection=eclValTCol)
205  valid_cal_hadron.algorithms = [eclValTAlgHadronic]
206 
207  # Here we set the AlgorithmStrategy for our algorithm
208  from caf.strategies import SingleIOV
209 
210  # The default value is SingleIOV, you don't have to set this, it is done automatically.
211  # SingleIOV just takes all of the runs as one big IoV and executes the algorithm once on all of their data.
212  # You can use granularity='run' or granularity='all' for the collector when using this strategy.
213 
214  valid_cal_hadron.strategies = SingleIOV
215 
216 
218 
219  # You must return all calibrations you want to run in the prompt process, even if it's only one
220  return [valid_cal_bhabha, valid_cal_hadron]
Validate the ecl timing calibrations using a hadronic event selection.