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