|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | # -*- coding: utf-8 -*- |
3 | 3 |
|
| 4 | +import os |
| 5 | +import subprocess |
| 6 | + |
4 | 7 | from opengate.utility import g4_units |
5 | 8 | import opengate.tests.utility as utility |
6 | 9 | from opengate.actors.coincidences import * |
7 | 10 | import opengate.contrib.compton_camera.macaco as macaco |
8 | 11 | import opengate.contrib.compton_camera.coresi_helpers as ch |
9 | 12 |
|
10 | | -if __name__ == "__main__": |
11 | 13 |
|
| 14 | +def main(dependency="test097a_ccmod_simulation.py"): |
12 | 15 | # get tests paths |
13 | 16 | paths = utility.get_default_test_paths( |
14 | 17 | __file__, gate_folder="", output_folder="test097_coresi_ccmod" |
15 | 18 | ) |
16 | 19 | output_folder = paths.output |
17 | | - data_folder = paths.data |
18 | 20 |
|
19 | 21 | # units |
20 | | - mm = g4_units.mm |
21 | | - cm = g4_units.cm |
22 | 22 | ns = g4_units.ns |
23 | 23 |
|
24 | | - # compute the coincidences |
25 | 24 | scatt_file = output_folder / "ThrScatt.root" |
26 | 25 | abs_file = output_folder / "ThrAbs.root" |
| 26 | + |
| 27 | + # The test needs the output of the simulation step. |
| 28 | + # When this script is launched via the opengate_tests suite, the |
| 29 | + # dependency="test097a_ccmod_simulation.py" signature on main() is used by |
| 30 | + # the runner to schedule test097a before test097b. The fallback below is |
| 31 | + # only for standalone execution of this script. |
| 32 | + if not scatt_file.exists() or not abs_file.exists(): |
| 33 | + subdir = os.path.dirname(__file__) |
| 34 | + print(f"Missing input singles files, running {dependency} first.") |
| 35 | + subprocess.call(["python", paths.current / subdir / dependency]) |
| 36 | + |
| 37 | + if not scatt_file.exists() or not abs_file.exists(): |
| 38 | + utility.test_ok( |
| 39 | + False, |
| 40 | + exceptions=[ |
| 41 | + f"Required input files were not created: {scatt_file.name}, {abs_file.name}" |
| 42 | + ], |
| 43 | + ) |
| 44 | + |
| 45 | + # compute the coincidences |
27 | 46 | print(f"Computing coincidences from {scatt_file.name} and {abs_file.name}") |
28 | 47 | merge_file = output_folder / "singles.root" |
29 | 48 | coinc_file = output_folder / "coincidences.root" |
|
65 | 84 | data_filename = output_folder / "coincidences.dat" |
66 | 85 | ch.coresi_convert_root_data(cones_filename, "cones", data_filename) |
67 | 86 | print(f"Data file: {data_filename.name}") |
| 87 | + |
| 88 | + is_ok = ( |
| 89 | + merge_file.exists() |
| 90 | + and coinc_file.exists() |
| 91 | + and cones_filename.exists() |
| 92 | + and data_filename.exists() |
| 93 | + and len(coincidences) > 0 |
| 94 | + and len(data_cones) > 0 |
| 95 | + ) |
| 96 | + utility.test_ok(is_ok) |
| 97 | + |
| 98 | + |
| 99 | +if __name__ == "__main__": |
| 100 | + main() |
0 commit comments