Belle II Software  release-05-01-25
caf_ecl_time_crystalCrate.py
1 # -*- coding: utf-8 -*-
2 
3 """ECL timing calibration that performs the crystal and crate calibrations."""
4 
5 from prompt import CalibrationSettings
6 from reconstruction import *
7 
8 
9 
16 
17 
20 settings = CalibrationSettings(name="ECL crystal and crate time calibrations",
21  expert_username="ehill",
22  description=__doc__,
23  input_data_formats=["cdst"],
24  input_data_names=["hlt_bhabha"],
25  depends_on=[])
26 
27 
28 
29 
38 
39 
40 def get_calibrations(input_data, **kwargs):
41  """
42  Parameters:
43  input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
44  Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
45  assigning to calibration.files_to_iov
46 
47  **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
48  backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
49  release explicitly if you want to.
50 
51  Currently only kwargs["output_iov"] is used. This is the output IoV range that your payloads should
52  correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
53 
54  Returns:
55  list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
56  """
57  import basf2
58  # Set up config options
59 
60  # In this script we want to use one sources of input data.
61  # Get the input files from the input_data variable
62  # The input data should be the hlt bhabha skim
63  file_to_iov_physics = input_data["hlt_bhabha"]
64 
65  # Could remove this limit on the number of files per run but will just
66  # set to a large number in case we want to introduce it later.
67  # Also, keeping it allows the crystal calibrations code to look like the
68  # crates calibration code.
69  max_files_per_run = 1000
70 
71  # We filter addition files if there are more than [max_files_per_run] files per run.
72  # The input data files are sorted alphabetically by b2caf-prompt-run
73  # already. This procedure respects that ordering
74  from prompt.utils import filter_by_max_files_per_run
75 
76  reduced_file_to_iov_physics = filter_by_max_files_per_run(file_to_iov_physics, max_files_per_run)
77  input_files_physics = list(reduced_file_to_iov_physics.keys())
78  basf2.B2INFO(f"Total number of files actually used as input = {len(input_files_physics)}")
79 
80 
81  from basf2 import register_module, create_path
82  import ROOT
83  from ROOT import Belle2
84  from ROOT.Belle2 import TestCalibrationAlgorithm
85  from caf.framework import Collection
86 
87 
89 
90  root_input = register_module('RootInput')
91  rec_path_bhabha = create_path()
92  rec_path_bhabha.add_module(root_input)
93  if 'Gearbox' not in rec_path_bhabha:
94  rec_path_bhabha.add_module('Gearbox')
95  if 'Geometry' not in rec_path_bhabha:
96  rec_path_bhabha.add_module('Geometry', useDB=True)
97 
98  prepare_cdst_analysis(rec_path_bhabha) # for new 2020 cdst format
99 
100  col_bhabha = register_module('ECLBhabhaTCollector')
101  col_bhabha.param('timeAbsMax', 250)
102  col_bhabha.param('minCrystal', 1)
103  col_bhabha.param('maxCrystal', 8736)
104  col_bhabha.param('saveTree', False)
105 
106  eclTCol = Collection(collector=col_bhabha,
107  input_files=input_files_physics,
108  pre_collector_path=rec_path_bhabha,
109  )
110 
111 
113 
114  eclTAlgCrates = Belle2.ECL.eclBhabhaTAlgorithm()
115 
116  # Define the CAF algorithm arguments
117  # Set the cellIDLo to be larger than cellIDHi so that no crystal
118  # calibrations will be performed.
119  eclTAlgCrates.cellIDLo = 3
120  eclTAlgCrates.cellIDHi = 2
121  eclTAlgCrates.debugOutput = True
122  eclTAlgCrates.meanCleanRebinFactor = 3
123  eclTAlgCrates.meanCleanCutMinFactor = 0.3
124  eclTAlgCrates.debugFilenameBase = "eclBhabhaTAlgorithm"
125 
126 
128 
129  eclTAlgCrystals = Belle2.ECL.eclBhabhaTAlgorithm()
130 
131  # Define the CAF algorithm arguments
132  # Set the crateIDLo to be larger than crateIDHi so that no crate
133  # calibrations will be performed.
134  eclTAlgCrystals.crateIDLo = 3
135  eclTAlgCrystals.crateIDHi = 2
136  eclTAlgCrystals.debugOutput = True
137  eclTAlgCrystals.meanCleanRebinFactor = 3
138  eclTAlgCrystals.meanCleanCutMinFactor = 0.3
139  eclTAlgCrystals.debugFilenameBase = "eclBhabhaTAlgorithm"
140 
141 
143 
144  from caf.framework import Calibration
145 
146  cal_crates_1 = Calibration("ECLcrateTimeCalibration_physics_1")
147  cal_crates_1.add_collection(name="bhabha", collection=eclTCol)
148  cal_crates_1.algorithms = [eclTAlgCrates]
149 
150  # Here we set the AlgorithmStrategy for our algorithm
151  from caf.strategies import SimpleRunByRun
152 
153  # The SimpleRunByRun strategy executes your algorithm over runs
154  # individually to give you payloads for each one (if successful)
155  # It will not do any merging of runs which didn't contain enough data.
156  # So failure is expected if your algorithm requires a large amount of data compared to run length.
157  # You should only use granularity='run' for the collector when using this strategy.
158 
159  cal_crates_1.strategies = SimpleRunByRun
160 
161  # Most other options like database chain and backend args will be overwritten by b2caf-prompt-run.
162  # So we don't bother setting them.
163 
164 
166 
167  cal_crystals_1 = Calibration("ECLcrystalTimeCalibration_physics_1")
168  cal_crystals_1.add_collection(name="bhabha", collection=eclTCol)
169  cal_crystals_1.algorithms = [eclTAlgCrystals]
170 
171  # Here we set the AlgorithmStrategy for our algorithm
172  from caf.strategies import SingleIOV
173 
174  # The default value is SingleIOV, you don't have to set this, it is done automatically.
175  # SingleIOV just takes all of the runs as one big IoV and executes the algorithm once on all of their data.
176  # You can use granularity='run' or granularity='all' for the collector when using this strategy.
177 
178  cal_crystals_1.strategies = SingleIOV
179 
180 
182  cal_crates_2 = Calibration("ECLcrateTimeCalibration_physics_2")
183  cal_crates_2.add_collection(name="bhabha", collection=eclTCol)
184  cal_crates_2.algorithms = [eclTAlgCrates]
185  cal_crates_2.strategies = SimpleRunByRun
186 
187 
189  cal_crystals_2 = Calibration("ECLcrystalTimeCalibration_physics_2")
190  cal_crystals_2.add_collection(name="bhabha", collection=eclTCol)
191  cal_crystals_2.algorithms = [eclTAlgCrystals]
192  cal_crystals_2.strategies = SingleIOV
193 
194 
196  cal_crates_3 = Calibration("ECLcrateTimeCalibration_physics_3")
197  cal_crates_3.add_collection(name="bhabha", collection=eclTCol)
198  cal_crates_3.algorithms = [eclTAlgCrates]
199  cal_crates_3.strategies = SimpleRunByRun
200 
201 
203  cal_crystals_3 = Calibration("ECLcrystalTimeCalibration_physics_3")
204  cal_crystals_3.add_collection(name="bhabha", collection=eclTCol)
205  cal_crystals_3.algorithms = [eclTAlgCrystals]
206  cal_crystals_3.strategies = SingleIOV
207 
208 
210  cal_crates_4 = Calibration("ECLcrateTimeCalibration_physics_4")
211  cal_crates_4.add_collection(name="bhabha", collection=eclTCol)
212  cal_crates_4.algorithms = [eclTAlgCrates]
213  cal_crates_4.strategies = SimpleRunByRun
214 
215 
217  cal_crystals_4 = Calibration("ECLcrystalTimeCalibration_physics_4")
218  cal_crystals_4.add_collection(name="bhabha", collection=eclTCol)
219  cal_crystals_4.algorithms = [eclTAlgCrystals]
220  cal_crystals_4.strategies = SingleIOV
221 
222 
227 
228  # cal_crates_1 depends on the crystal payload values in the global tag
229  cal_crystals_1.depends_on(cal_crates_1)
230 
231  cal_crates_2.depends_on(cal_crystals_1)
232  cal_crystals_2.depends_on(cal_crates_2)
233 
234  cal_crates_3.depends_on(cal_crystals_2)
235  cal_crystals_3.depends_on(cal_crates_3)
236 
237  cal_crates_4.depends_on(cal_crystals_3)
238  cal_crystals_4.depends_on(cal_crates_4)
239 
240 
242 
243  # You must return all calibrations you want to run in the prompt process, even if it's only one
244  # Calibrations will be executed in this order as a result of the dependencies defined by the "dependes_on(...)".
245  return [cal_crates_1, cal_crystals_1, cal_crates_2, cal_crystals_2, cal_crates_3, cal_crystals_3, cal_crates_4, cal_crystals_4]
246 
247 
prompt.utils
Definition: utils.py:1
Collection
Definition: Collection.py:1
Belle2::ECL::eclBhabhaTAlgorithm
Calibrate ecl crystals using bhabha events.
Definition: eclBhabhaTAlgorithm.h:39
Calibration
Definition: Calibration.py:1