Belle II Software development
caf_ecl_time_crystal.py
1
8
9"""ECL timing calibration that performs the crystal calibrations, one for the whole set of runs."""
10
11from prompt import CalibrationSettings
12from reconstruction import prepare_cdst_analysis
13from caf.utils import IoV
14
15
16##############################
17# REQUIRED VARIABLE #
18##############################
19# Used to identify the keys in input_data that your get_calibrations function will need in order
20# to assign data correctly.
21# Will be used to construct the calibration in the automated system, as well as set up the submission web forms.
22# You can view the available input data formats from CalibrationSettings.allowed_data_formats
23
24## Tells the automated system some details of this script.
25# Default is to read in "bhabha_all_calib" since we want to
26# run over cdst bhabha_all_calib skim files.
27settings = CalibrationSettings(
28 name="ECL crystal time calibrations",
29 expert_username="ehill",
30 description=__doc__,
31 input_data_formats=["cdst"],
32 input_data_names=["bhabha_all_calib"],
33 input_data_filters={
34 "bhabha_all_calib": [
35 "bhabha_all_calib",
36 "4S",
37 "Continuum",
38 "Scan",
39 "Good",
40 "physics",
41 "On"]},
42 depends_on=[])
43
44
45
46
55
56
57def get_calibrations(input_data, **kwargs):
58 """
59 Parameters:
60 input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
61 Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
62 assigning to calibration.files_to_iov
63
64 **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
65 backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
66 release explicitly if you want to.
67
68 Currently only kwargs["output_iov"] is used. This is the output IoV range that your payloads should
69 correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
70
71 Returns:
72 list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
73 """
74 import basf2
75 # Set up config options
76
77 # In this script we want to use one sources of input data.
78 # Get the input files from the input_data variable
79 # The input data should be the bhabha skim
80 file_to_iov_physics = input_data["bhabha_all_calib"]
81
82 # Could remove this limit on the number of files per run but will just
83 # set to a large number in case we want to introduce it later.
84 # Also, keeping it allows the crystal calibrations code to look like the
85 # crates calibration code.
86 max_files_per_run = 2600
87
88 # We filter addition files if there are more than [max_files_per_run] files per run.
89 # The input data files are sorted alphabetically by b2caf-prompt-run
90 # already. This procedure respects that ordering
91 from prompt.utils import filter_by_max_files_per_run
92
93 reduced_file_to_iov_physics = filter_by_max_files_per_run(file_to_iov_physics, max_files_per_run)
94 input_files_physics = list(reduced_file_to_iov_physics.keys())
95 basf2.B2INFO(f"Total number of files actually used as input = {len(input_files_physics)}")
96
97
98 from basf2 import register_module, create_path
99 from ROOT import Belle2
100 from caf.framework import Collection
101
102
104 root_input = register_module('RootInput')
105 rec_path_bhabha = create_path()
106 rec_path_bhabha.add_module(root_input)
107 if 'Gearbox' not in rec_path_bhabha:
108 rec_path_bhabha.add_module('Gearbox')
109 if 'Geometry' not in rec_path_bhabha:
110 rec_path_bhabha.add_module('Geometry', useDB=True)
111
112 prepare_cdst_analysis(rec_path_bhabha) # for new 2020 cdst format
113
114 # ====================================================
115 t0BiasCorrection = -0.9 # Correct for the CDC t0 bias
116 # ====================================================
117
118 col_bhabha = register_module('ECLBhabhaTCollector')
119 col_bhabha.param('timeAbsMax', 250)
120 col_bhabha.param('minCrystal', 1)
121 col_bhabha.param('maxCrystal', 8736)
122 col_bhabha.param('saveTree', False)
123 col_bhabha.param('hadronEventT0_TO_bhabhaEventT0_correction', t0BiasCorrection)
124
125 eclTCol = Collection(collector=col_bhabha,
126 input_files=input_files_physics,
127 pre_collector_path=rec_path_bhabha)
128
129
131
132 eclTAlgCrystals = Belle2.ECL.eclBhabhaTAlgorithm()
133
134 # Define the CAF algorithm arguments
135 # Set the crateIDLo to be larger than crateIDHi so that no crate
136 # calibrations will be performed.
137 eclTAlgCrystals.crateIDLo = 3
138 eclTAlgCrystals.crateIDHi = 2
139 eclTAlgCrystals.debugOutput = True
140 eclTAlgCrystals.meanCleanRebinFactor = 3
141 eclTAlgCrystals.meanCleanCutMinFactor = 0.3
142 eclTAlgCrystals.debugFilenameBase = "eclBhabhaTAlgorithm"
143
144
146
147 from caf.framework import Calibration
148
149 cal_crystals = Calibration("ECLcrystalTimeCalibration_physics")
150 cal_crystals.add_collection(name="bhabha", collection=eclTCol)
151 cal_crystals.algorithms = [eclTAlgCrystals]
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 cal_crystals.strategies = SingleIOV
161
162
165
166 # We use a dummy collector that barely outputs any data and we set the input files to a single file so
167 # we spawn only one very fast job.
168 # It doesn't matter which input file we choose as the output is never used.
169
171 cal_ecl_merge = Calibration(name="ecl_t_merge", collector="DummyCollector", algorithms=[merging_alg],
172 input_files=input_files_physics[:1])
173
174 # The important part is that we depend on all the calibrations we previously ran
175 cal_ecl_merge.depends_on(cal_crystals)
176
177 # ..Uses cdst data so it requires prepare_cdst_analysis
178 ecl_merge_pre_path = basf2.create_path()
179 prepare_cdst_analysis(ecl_merge_pre_path, components=['ECL'])
180 ecl_merge_pre_path.pre_collector_path = ecl_merge_pre_path
181
182 # --------------------------------------------------------------
183 # ..Force the output iovs to be open
184 intermediate_iov = IoV(0, 0, -1, -1)
185 requested_iov = kwargs.get("requested_iov", None)
186 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
187 for algorithm in cal_crystals.algorithms:
188 algorithm.params = {"apply_iov": intermediate_iov}
189 for algorithm in cal_ecl_merge.algorithms:
190 algorithm.params = {"apply_iov": output_iov}
191
192
194 return [cal_crystals, cal_ecl_merge]
Calibrate ecl crystals using bhabha events.
Calibrate ecl crystals using previously created payloads.