From 70e41e7f2a7a53cd52f7566de06a2f0ae2f8dbfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Coussat?= Date: Mon, 9 Dec 2024 15:38:39 +0100 Subject: [PATCH 1/2] New utility function to change RunIDs in a ROOT file --- opengate/utility.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/opengate/utility.py b/opengate/utility.py index 9b0b17815..e73da312c 100644 --- a/opengate/utility.py +++ b/opengate/utility.py @@ -604,3 +604,19 @@ def standard_error_c4_correction(n): return ( np.sqrt(2 / (n - 1)) * sc.special.gamma(n / 2) / sc.special.gamma((n - 1) / 2) ) + +def update_runid(input_path, run_id, tree, output_path): + """ + Update a ROOT file by setting the RunID to some constant value. + + When a GATE simulation with multiple runs was parallelized by splitting it into several one-run simulations, all output ROOT files have RunIDs equal to one. + This can be a problem for post-processing ROOT files based on their RunID. + By using this piece of code, one can update the RunID from a ROOT output file to the actual RunID. + + This creates a new ROOT file, and does not operate in-place. The original ROOT file is preserved.""" + import uproot + input_tree = uproot.open(input_path)[tree] + input_array = input_tree.arrays(library='np') + input_array['RunID'] = np.full(input_array['RunID'].shape, run_id, dtype=input_array['RunID'].dtype) + with uproot.recreate(output_path) as output_file: + output_file[tree] = input_array From d81046194219e272a2c2f3c3e3d309c11cc86ce0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:46:40 +0000 Subject: [PATCH 2/2] [pre-commit.ci] Automatic python and c++ formatting --- opengate/utility.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/opengate/utility.py b/opengate/utility.py index e73da312c..7336b0543 100644 --- a/opengate/utility.py +++ b/opengate/utility.py @@ -605,6 +605,7 @@ def standard_error_c4_correction(n): np.sqrt(2 / (n - 1)) * sc.special.gamma(n / 2) / sc.special.gamma((n - 1) / 2) ) + def update_runid(input_path, run_id, tree, output_path): """ Update a ROOT file by setting the RunID to some constant value. @@ -613,10 +614,14 @@ def update_runid(input_path, run_id, tree, output_path): This can be a problem for post-processing ROOT files based on their RunID. By using this piece of code, one can update the RunID from a ROOT output file to the actual RunID. - This creates a new ROOT file, and does not operate in-place. The original ROOT file is preserved.""" + This creates a new ROOT file, and does not operate in-place. The original ROOT file is preserved. + """ import uproot + input_tree = uproot.open(input_path)[tree] - input_array = input_tree.arrays(library='np') - input_array['RunID'] = np.full(input_array['RunID'].shape, run_id, dtype=input_array['RunID'].dtype) + input_array = input_tree.arrays(library="np") + input_array["RunID"] = np.full( + input_array["RunID"].shape, run_id, dtype=input_array["RunID"].dtype + ) with uproot.recreate(output_path) as output_file: output_file[tree] = input_array