Belle II Software  release-05-01-25
caf_ignoring_runs_singleiov.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 
16 b2.set_log_level(b2.LogLevel.INFO)
17 
18 
19 def main(argv):
20  if len(argv) == 1:
21  data_dir = argv[0]
22  else:
23  print("Usage: python3 caf_ignoring_runs.py <data directory>")
24  sys.exit(1)
25 
26 
29  input_files_test = [os.path.join(os.path.abspath(data_dir), '*.root')]
30 
31 
33 
34  # Make a bunch of test calibrations
35  col_test = b2.register_module('CaTest')
36  # Specific parameter to our test collector, proportional to the probability of algorithm requesting iteration.
37  col_test.param('spread', 15)
38 
39  alg_test = TestCalibrationAlgorithm()
40 
41  cal_test = Calibration(name='TestCalibration',
42  collector=col_test,
43  algorithms=alg_test,
44  input_files=input_files_test)
45 
46  # We don't want to run collector jobs on these runs (if possible) and we don't want the algorithm to use data from
47  # these runs. However, the algorithm strategy may also merge IoVs across the gaps left by the ignored runs.
48  # What the strategy does with missing runs depends on the AlgorithmStrategy and any configuration you have made.
49  cal_test.ignored_runs = [ExpRun(0, 2), ExpRun(0, 3), ExpRun(0, 5), ExpRun(0, 6)]
50 
51  # The framework.Algorithm class (not the CalibrationAlgorithm) has a params attribute.
52  # For the SingleIoV strategy (default), setting the "apply_iov" to an IoV object will cause the final payload
53  # to have this IoV.
54  # This happens REGARDLESS of whether data from this IoV was used in this calibration.
55  # Think of it as an optional override for the output IoV.
56  # This is ONLY true for the SingleIoV strategy.
57  #
58  # If you don't set this, then the output IoV will come from the IoV of all executed runs.
59  # In this case it would be IoV(0,1,0,1) as we are excluding all other runs manually either by the ignored_runs,
60  # or by the cal_fw.run(iov=)
61  cal_test.algorithms[0].params["apply_iov"] = IoV(0, 1, 0, 10)
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 
87 if __name__ == "__main__":
88  main(sys.argv[1:])
main
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:77
Calibration
Definition: Calibration.py:1