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