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