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