Belle II Software development
caf_arich.py
1
8
9"""A simple example calibration that takes one input data list from raw data and performs
10a single calibration."""
11
12from prompt import CalibrationSettings, INPUT_DATA_FILTERS
13
14
15settings = CalibrationSettings(
16 name="ARICH channel masks",
17 expert_username="luka",
18 description=__doc__,
19 input_data_formats=["raw"],
20 input_data_names=["bhabha_all_calib"],
21 input_data_filters={
22 "bhabha_all_calib": [
23 INPUT_DATA_FILTERS["Data Tag"]["bhabha_all_calib"],
24 INPUT_DATA_FILTERS["Run Type"]["physics"],
25 INPUT_DATA_FILTERS["Data Quality Tag"]["Good Or Recoverable"]]},
26 depends_on=[])
27
28
29
30
31def get_calibrations(input_data, **kwargs):
32 """
33 Parameters:
34 input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
35 Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
36 assigning to calibration.files_to_iov
37
38 **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
39 backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
40 release explicitly if you want to.
41
42 Currently only kwargs["output_iov"] is used. This is the output IoV range that your payloads should
43 correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
44
45 Returns:
46 list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
47 """
48 import basf2
49 # Set up config options
50
51 # In this script we want to use one sources of input data.
52 # Get the input files from the input_data variable
53 file_to_iov_physics = input_data["bhabha_all_calib"]
54
55 # We might have requested an enormous amount of data across a run range.
56 # There's a LOT more files than runs!
57 # Lets set some limits because this calibration doesn't need that much to run.
58 max_files_per_run = 100
59
60 # We filter out any more than 100 files per run. The input data files are sorted alphabetically by b2caf-prompt-run
61 # already. This procedure respects that ordering
62 from prompt.utils import filter_by_max_files_per_run
63
64 reduced_file_to_iov_physics = filter_by_max_files_per_run(file_to_iov_physics, max_files_per_run)
65 input_files_physics = list(reduced_file_to_iov_physics.keys())
66 basf2.B2INFO(f"Total number of files actually used as input = {len(input_files_physics)}")
67
68 # Get the overall IoV we our process should cover. Includes the end values that we may want to ignore since our output
69 # IoV should be open ended. We could also use this as part of the input data selection in some way.
70 requested_iov = kwargs.get("requested_iov", None)
71
72 from caf.utils import IoV
73 # The actual value our output IoV payload should have. Notice that we've set it open ended.
74 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
75
76
78
79 from basf2 import create_path
80 from ROOT.Belle2 import ARICHChannelMaskMaker
81
82 alg_arich = ARICHChannelMaskMaker()
83
84
86
87 from caf.framework import Calibration
88 from caf.strategies import SequentialRunByRun
89
90 # module to be run prior the collector
91 rec_path_1 = create_path()
92 rec_path_1.add_module('ARICHUnpacker')
93
94 cal_test = Calibration("ARICHChannelMasks",
95 collector="ARICHChannelMask",
96 algorithms=[alg_arich],
97 input_files=input_files_physics,
98 pre_collector_path=rec_path_1
99 )
100
101 cal_test.strategies = SequentialRunByRun
102
103 # Do this for the default AlgorithmStrategy to force the output payload IoV
104 # It may be different if you are using another strategy like SequentialRunByRun
105 for algorithm in cal_test.algorithms:
106 algorithm.params = {"iov_coverage": output_iov}
107
108 # Most other options like database chain and backend args will be overwritten by b2caf-prompt-run.
109 # So we don't bother setting them.
110
111 # You must return all calibrations you want to run in the prompt process, even if it's only one
112 return [cal_test]
113
114