Belle II Software development
caf_ignoring_runs_singleiov.py
1
12
13import basf2 as b2
14
15import os
16import sys
17
18from caf.framework import Calibration, CAF
19from caf.utils import ExpRun, IoV
20
21b2.set_log_level(b2.LogLevel.INFO)
22
23
24def main(argv):
25 if len(argv) == 1:
26 data_dir = argv[0]
27 else:
28 print("Usage: python3 caf_ignoring_runs.py <data directory>")
29 sys.exit(1)
30
31
34 input_files_test = [os.path.join(os.path.abspath(data_dir), '*.root')]
35
36
38
39 # Make a bunch of test calibrations
40 col_test = b2.register_module('CaTest')
41 # Specific parameter to our test collector, proportional to the probability of algorithm requesting iteration.
42 col_test.param('spread', 15)
43
44 from ROOT import Belle2 # noqa: make the Belle2 namespace available
45 from ROOT.Belle2 import TestCalibrationAlgorithm
46 alg_test = TestCalibrationAlgorithm()
47
48 cal_test = Calibration(name='TestCalibration',
49 collector=col_test,
50 algorithms=alg_test,
51 input_files=input_files_test)
52
53 # We don't want to run collector jobs on these runs (if possible) and we don't want the algorithm to use data from
54 # these runs. However, the algorithm strategy may also merge IoVs across the gaps left by the ignored runs.
55 # What the strategy does with missing runs depends on the AlgorithmStrategy and any configuration you have made.
56 cal_test.ignored_runs = [ExpRun(0, 2), ExpRun(0, 3), ExpRun(0, 5), ExpRun(0, 6)]
57
58 # The framework.Algorithm class (not the CalibrationAlgorithm) has a params attribute.
59 # For the SingleIoV strategy (default), setting the "apply_iov" to an IoV object will cause the final payload
60 # to have this IoV.
61 # This happens REGARDLESS of whether data from this IoV was used in this calibration.
62 # Think of it as an optional override for the output IoV.
63 # This is ONLY true for the SingleIoV strategy.
64 #
65 # If you don't set this, then the output IoV will come from the IoV of all executed runs.
66 # In this case it would be IoV(0,1,0,1) as we are excluding all other runs manually either by the ignored_runs,
67 # or by the cal_fw.run(iov=)
68 cal_test.algorithms[0].params["apply_iov"] = IoV(0, 1, 0, 10)
69
70
72 cal_fw = CAF()
73
74 # You could alternatively set the same ignored_runs for every Calibration by setting it here.
75 # Note that setting cal_test.ignored_runs will override the value set from here.
76
77 # cal_fw = CAF(calibration_defaults={'ignored_runs':[ExpRun(0,2), ExpRun(0, 3)])
78
79 cal_fw.add_calibration(cal_test)
80
81 # The iov value here allows you to set an IoV that all your input files/executed runs must overlap.
82 # Any input files not overlapping this IoV will be ignored.
83 # HOWEVER, if you have an input file containing multiple runs the file IoV may overlap this IoV. But it may still
84 # contain runs outside of it.
85 # In this case the CAF will still use the file in collector jobs, BUT any runs collected will not be used in the
86 # algorithm step if they exist outside of this IoV.
87 #
88 # To explicitly prevent certain runs from within this IoV being used, you should use the ignored_runs
89 # attribute of the Calibration. Or make sure that the input data files do not contain data from those runs at all.
90 cal_fw.run(iov=IoV(0, 3, 0, 9))
91 print("End of CAF processing.")
92
93
94if __name__ == "__main__":
95 main(sys.argv[1:])
Definition: main.py:1