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