From e424ef651e059a61748576716a60295ee287dd7d Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 12:21:19 -0600 Subject: [PATCH 01/28] add hep units --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 765c332..cbf0618 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ classifiers = [ dependencies = [ "awkward", "vector", + "hepunits", "fsspec", "pyarrow", "awkward-pandas", From 48907b35d76b5b35f21307becffc882276da936a Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 12:21:26 -0600 Subject: [PATCH 02/28] additional test --- tests/test_run.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_run.py b/tests/test_run.py index e58df82..630f510 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -4,6 +4,7 @@ import numpy as np import pytest import requests +from hepunits import MeV, keV from geant4_python_application import Application, basic_gdml @@ -34,3 +35,28 @@ def test_awkward_primaries(n_threads): event_primary_energy = ak.flatten(events.primaries.energy) assert np.allclose(event_primary_energy, primaries.energy) + + +@pytest.mark.parametrize("n_threads", [0]) +def test_reproduce(n_threads): + primaries = ak.Array( + [ + { + "particle": "neutron", + "energy": 100 * MeV / keV, + "direction": {"x": 0, "y": -1, "z": 0}, + "position": {"x": 0, "y": 10, "z": 0}, + } + for _ in range(500) + ] + ) + with Application(gdml=complex_gdml, n_threads=n_threads, seed=137) as app: + events = ak.Array([]) + batch_size = 100 + for i in range(0, len(primaries), batch_size): + events = ak.concatenate([events, app.run(primaries[i : i + batch_size])]) + + assert len(events) == len(primaries) + volume = app.detector.physical_volumes_from_logical("gasVolume") + events = events[events.energy_in_volume(volume) > 0] + assert len(events) == 7 From 9f876c2fc54531a00c37cf67e8af786fa4bc4e39 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 19:49:32 -0600 Subject: [PATCH 03/28] test length --- tests/test_analysis.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_analysis.py b/tests/test_analysis.py index 4e64f96..c2d43d9 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -61,12 +61,12 @@ def test_sensitive(): volume = list(volumes)[0] print("volume: ", volume) events = [] - total = 2 + total = 5 while (n := np.sum([len(_events) for _events in events])) < total: - run_events = app.run(20) + run_events = app.run(100) run_events = run_events[run_events.energy_in_volume(volume) > 0] events.append(run_events) events = ak.concatenate(events) - # ak.to_parquet(events.hits(volume), "hits.parquet") + assert len(events) == 6 hits = events.hits(volume) electrons = ak.concatenate([hit.electrons() for hit in hits]) From fc00d317ff317366a0381908a518b42305a63e69 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 20:00:07 -0600 Subject: [PATCH 04/28] expand test --- tests/test_analysis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_analysis.py b/tests/test_analysis.py index c2d43d9..844494d 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -42,8 +42,7 @@ def test_events(): def test_sensitive(): - with Application() as app: - app.seed = 1000 + with Application(seed=1000) as app: app.setup_detector(gdml=complexGdml).setup_action() sensitive_volume = "gasVolume" @@ -69,4 +68,5 @@ def test_sensitive(): events = ak.concatenate(events) assert len(events) == 6 hits = events.hits(volume) + np.isclose(hits.energy[0][0:5], [0.0401, 0.00271, 0.00391, 0.389, 0.204]) electrons = ak.concatenate([hit.electrons() for hit in hits]) From 8979b45130b5493add3a79d2f8e631a43c59d4d1 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 20:00:45 -0600 Subject: [PATCH 05/28] use unique pointer for builders --- .../include/geant4_application/DataModel.h | 2 +- src/geant4_application/src/DataModel.cpp | 103 +++++++++--------- src/geant4_application/src/RunAction.cpp | 6 +- 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/src/geant4_application/include/geant4_application/DataModel.h b/src/geant4_application/include/geant4_application/DataModel.h index f90755a..bb7ead0 100644 --- a/src/geant4_application/include/geant4_application/DataModel.h +++ b/src/geant4_application/include/geant4_application/DataModel.h @@ -178,7 +178,7 @@ void InsertEvent(const G4Event* event, Builders& builder); void InsertTrack(const G4Track* track, Builders& builder); void InsertStep(const G4Step* step, Builders& builder); -py::object SnapshotBuilder(Builders& builder); +py::object BuilderToObject(std::unique_ptr builders); namespace units { static constexpr auto energy = CLHEP::keV; diff --git a/src/geant4_application/src/DataModel.cpp b/src/geant4_application/src/DataModel.cpp index f1c2dd9..b966cb8 100644 --- a/src/geant4_application/src/DataModel.cpp +++ b/src/geant4_application/src/DataModel.cpp @@ -429,82 +429,83 @@ py::object snapshot_builder(const T& builder) { return from_buffers(builder.form(), builder.length(), container); } -py::object SnapshotBuilder(Builders& builder) { +py::object BuilderToObject(unique_ptr builder) { + // this will automatically clear the builders after the pointer goes out of scope py::dict snapshot; - if (builder.fields.contains("run")) { - snapshot["run"] = snapshot_builder(builder.run); + if (builder->fields.contains("run")) { + snapshot["run"] = snapshot_builder(builder->run); } - if (builder.fields.contains("id")) { - snapshot["id"] = snapshot_builder(builder.id); + if (builder->fields.contains("id")) { + snapshot["id"] = snapshot_builder(builder->id); } - if (builder.fields.contains("primaries")) { - snapshot["primaries"] = snapshot_builder(builder.primaries); + if (builder->fields.contains("primaries")) { + snapshot["primaries"] = snapshot_builder(builder->primaries); } - if (builder.fields.contains("track_id")) { - snapshot["track_id"] = snapshot_builder(builder.track_id); + if (builder->fields.contains("track_id")) { + snapshot["track_id"] = snapshot_builder(builder->track_id); } - if (builder.fields.contains("track_parent_id")) { - snapshot["track_parent_id"] = snapshot_builder(builder.track_parent_id); + if (builder->fields.contains("track_parent_id")) { + snapshot["track_parent_id"] = snapshot_builder(builder->track_parent_id); } - if (builder.fields.contains("track_initial_energy")) { - snapshot["track_initial_energy"] = snapshot_builder(builder.track_initial_energy); + if (builder->fields.contains("track_initial_energy")) { + snapshot["track_initial_energy"] = snapshot_builder(builder->track_initial_energy); } - if (builder.fields.contains("track_initial_time")) { - snapshot["track_initial_time"] = snapshot_builder(builder.track_initial_time); + if (builder->fields.contains("track_initial_time")) { + snapshot["track_initial_time"] = snapshot_builder(builder->track_initial_time); } - if (builder.fields.contains("track_weight")) { - snapshot["track_weight"] = snapshot_builder(builder.track_weight); + if (builder->fields.contains("track_weight")) { + snapshot["track_weight"] = snapshot_builder(builder->track_weight); } - if (builder.fields.contains("track_initial_position")) { - snapshot["track_initial_position"] = snapshot_builder(builder.track_initial_position); + if (builder->fields.contains("track_initial_position")) { + snapshot["track_initial_position"] = snapshot_builder(builder->track_initial_position); } - if (builder.fields.contains("track_initial_momentum")) { - snapshot["track_initial_momentum"] = snapshot_builder(builder.track_initial_momentum); + if (builder->fields.contains("track_initial_momentum")) { + snapshot["track_initial_momentum"] = snapshot_builder(builder->track_initial_momentum); } - if (builder.fields.contains("track_particle")) { - snapshot["track_particle"] = snapshot_builder(builder.track_particle); + if (builder->fields.contains("track_particle")) { + snapshot["track_particle"] = snapshot_builder(builder->track_particle); } - if (builder.fields.contains("track_particle_type")) { - snapshot["track_particle_type"] = snapshot_builder(builder.track_particle_type); + if (builder->fields.contains("track_particle_type")) { + snapshot["track_particle_type"] = snapshot_builder(builder->track_particle_type); } - if (builder.fields.contains("track_creator_process")) { - snapshot["track_creator_process"] = snapshot_builder(builder.track_creator_process); + if (builder->fields.contains("track_creator_process")) { + snapshot["track_creator_process"] = snapshot_builder(builder->track_creator_process); } - if (builder.fields.contains("track_creator_process_type")) { - snapshot["track_creator_process_type"] = snapshot_builder(builder.track_creator_process_type); + if (builder->fields.contains("track_creator_process_type")) { + snapshot["track_creator_process_type"] = snapshot_builder(builder->track_creator_process_type); } - if (builder.fields.contains("track_children_ids")) { - snapshot["track_children_ids"] = snapshot_builder(builder.track_children_ids); + if (builder->fields.contains("track_children_ids")) { + snapshot["track_children_ids"] = snapshot_builder(builder->track_children_ids); } - if (builder.fields.contains("step_energy")) { - snapshot["step_energy"] = snapshot_builder(builder.step_energy); + if (builder->fields.contains("step_energy")) { + snapshot["step_energy"] = snapshot_builder(builder->step_energy); } - if (builder.fields.contains("step_time")) { - snapshot["step_time"] = snapshot_builder(builder.step_time); + if (builder->fields.contains("step_time")) { + snapshot["step_time"] = snapshot_builder(builder->step_time); } - if (builder.fields.contains("step_track_kinetic_energy")) { - snapshot["step_track_kinetic_energy"] = snapshot_builder(builder.step_track_kinetic_energy); + if (builder->fields.contains("step_track_kinetic_energy")) { + snapshot["step_track_kinetic_energy"] = snapshot_builder(builder->step_track_kinetic_energy); } - if (builder.fields.contains("step_process")) { - snapshot["step_process"] = snapshot_builder(builder.step_process); + if (builder->fields.contains("step_process")) { + snapshot["step_process"] = snapshot_builder(builder->step_process); } - if (builder.fields.contains("step_process_type")) { - snapshot["step_process_type"] = snapshot_builder(builder.step_process_type); + if (builder->fields.contains("step_process_type")) { + snapshot["step_process_type"] = snapshot_builder(builder->step_process_type); } - if (builder.fields.contains("step_volume")) { - snapshot["step_volume"] = snapshot_builder(builder.step_volume); + if (builder->fields.contains("step_volume")) { + snapshot["step_volume"] = snapshot_builder(builder->step_volume); } - if (builder.fields.contains("step_volume_post")) { - snapshot["step_volume_post"] = snapshot_builder(builder.step_volume_post); + if (builder->fields.contains("step_volume_post")) { + snapshot["step_volume_post"] = snapshot_builder(builder->step_volume_post); } - if (builder.fields.contains("step_nucleus")) { - snapshot["step_nucleus"] = snapshot_builder(builder.step_nucleus); + if (builder->fields.contains("step_nucleus")) { + snapshot["step_nucleus"] = snapshot_builder(builder->step_nucleus); } - if (builder.fields.contains("step_position")) { - snapshot["step_position"] = snapshot_builder(builder.step_position); + if (builder->fields.contains("step_position")) { + snapshot["step_position"] = snapshot_builder(builder->step_position); } - if (builder.fields.contains("step_momentum")) { - snapshot["step_momentum"] = snapshot_builder(builder.step_momentum); + if (builder->fields.contains("step_momentum")) { + snapshot["step_momentum"] = snapshot_builder(builder->step_momentum); } return snapshot; } diff --git a/src/geant4_application/src/RunAction.cpp b/src/geant4_application/src/RunAction.cpp index b42cc57..04bb95a 100644 --- a/src/geant4_application/src/RunAction.cpp +++ b/src/geant4_application/src/RunAction.cpp @@ -30,10 +30,8 @@ void RunAction::EndOfRunAction(const G4Run*) { } if (isMaster) { - for (auto& builderToSnapshot: buildersToSnapshot) { - auto data = SnapshotBuilder(*builderToSnapshot); - container->append(data); - builderToSnapshot = nullptr; + for (auto& builders: buildersToSnapshot) { + container->append(BuilderToObject(std::move(builders))); } buildersToSnapshot.clear(); } From 686368faf9c820d352267f93adef644ee00aefb9 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 20:19:45 -0600 Subject: [PATCH 06/28] try different initialization --- tests/test_analysis.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/test_analysis.py b/tests/test_analysis.py index 844494d..199a02b 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -42,11 +42,8 @@ def test_events(): def test_sensitive(): - with Application(seed=1000) as app: - app.setup_detector(gdml=complexGdml).setup_action() - - sensitive_volume = "gasVolume" - app.detector.sensitive_volumes = {sensitive_volume} + with Application(gdml=complexGdml, seed=1000) as app: + volume_logical = "gasVolume" app.initialize() @@ -55,7 +52,7 @@ def test_sensitive(): app.command("/gun/direction 0 -1 0") app.command("/gun/position 0 10 0 m") - volumes = app.detector.physical_volumes_from_logical(sensitive_volume) + volumes = app.detector.physical_volumes_from_logical(volume_logical) assert len(volumes) == 1 volume = list(volumes)[0] print("volume: ", volume) @@ -66,6 +63,7 @@ def test_sensitive(): run_events = run_events[run_events.energy_in_volume(volume) > 0] events.append(run_events) events = ak.concatenate(events) + assert app.seed == 1000 assert len(events) == 6 hits = events.hits(volume) np.isclose(hits.energy[0][0:5], [0.0401, 0.00271, 0.00391, 0.389, 0.204]) From 202e6516383a93eba36aaac4a21c1958f85e5dbd Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 20:35:06 -0600 Subject: [PATCH 07/28] order of seed initialization --- src/geant4_application/src/Application.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/geant4_application/src/Application.cpp b/src/geant4_application/src/Application.cpp index beed4d8..c720a80 100644 --- a/src/geant4_application/src/Application.cpp +++ b/src/geant4_application/src/Application.cpp @@ -88,6 +88,10 @@ void Application::SetupManager(unsigned short nThreads) { delete G4VSteppingVerbose::GetInstance(); SteppingVerbose::SetInstance(new SteppingVerbose); + // https://geant4-forum.web.cern.ch/t/different-random-seeds-but-same-results/324/5 + // seed needs to be setup before the run manager is created + SetupRandomEngine(); + const auto runManagerType = nThreads > 0 ? G4RunManagerType::MTOnly : G4RunManagerType::SerialOnly; runManager = unique_ptr(G4RunManagerFactory::CreateRunManager(runManagerType)); if (nThreads > 0) { @@ -110,8 +114,6 @@ void Application::Initialize() { throw runtime_error("Application is already initialized"); } - SetupRandomEngine(); - runManager->Initialize(); isInitialized = true; } From b40604846f1f6c5a3e73c3b871c876710ac6bb74 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 20:45:07 -0600 Subject: [PATCH 08/28] debugging random seed --- tests/test_analysis.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_analysis.py b/tests/test_analysis.py index 199a02b..29c2d31 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -12,8 +12,7 @@ def test_events(): - with Application() as app: - app.seed = 1000 + with Application(seed=1000) as app: app.setup_detector(gdml=complexGdml) sensitive_volume = "gasVolume" @@ -59,7 +58,7 @@ def test_sensitive(): events = [] total = 5 while (n := np.sum([len(_events) for _events in events])) < total: - run_events = app.run(100) + run_events = app.run(500) run_events = run_events[run_events.energy_in_volume(volume) > 0] events.append(run_events) events = ak.concatenate(events) From 52301b37a7d362e8281465bf499fb7b6b24828a6 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 21:03:03 -0600 Subject: [PATCH 09/28] debugging random seed --- tests/test_analysis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_analysis.py b/tests/test_analysis.py index 29c2d31..df970c6 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -58,12 +58,12 @@ def test_sensitive(): events = [] total = 5 while (n := np.sum([len(_events) for _events in events])) < total: - run_events = app.run(500) + run_events = app.run(1000) run_events = run_events[run_events.energy_in_volume(volume) > 0] events.append(run_events) events = ak.concatenate(events) assert app.seed == 1000 - assert len(events) == 6 + assert len(events) == 7 hits = events.hits(volume) np.isclose(hits.energy[0][0:5], [0.0401, 0.00271, 0.00391, 0.389, 0.204]) electrons = ak.concatenate([hit.electrons() for hit in hits]) From d8197e13c79a093613de1dd3e2629e0f53b99f63 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 21:09:45 -0600 Subject: [PATCH 10/28] debugging random seed --- tests/test_analysis.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/test_analysis.py b/tests/test_analysis.py index df970c6..5ce8201 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -41,7 +41,7 @@ def test_events(): def test_sensitive(): - with Application(gdml=complexGdml, seed=1000) as app: + with Application(gdml=complexGdml, seed=1234) as app: volume_logical = "gasVolume" app.initialize() @@ -56,14 +56,12 @@ def test_sensitive(): volume = list(volumes)[0] print("volume: ", volume) events = [] - total = 5 - while (n := np.sum([len(_events) for _events in events])) < total: - run_events = app.run(1000) - run_events = run_events[run_events.energy_in_volume(volume) > 0] - events.append(run_events) + run_events = app.run(1000) + run_events = run_events[run_events.energy_in_volume(volume) > 0] + events.append(run_events) events = ak.concatenate(events) - assert app.seed == 1000 - assert len(events) == 7 + assert app.seed == 1234 + assert len(events) == 5 hits = events.hits(volume) np.isclose(hits.energy[0][0:5], [0.0401, 0.00271, 0.00391, 0.389, 0.204]) electrons = ak.concatenate([hit.electrons() for hit in hits]) From ca867f6f620efeff70375aae6664ba801f48eb1e Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 21:28:58 -0600 Subject: [PATCH 11/28] debug --- src/geant4_application/src/RunAction.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/geant4_application/src/RunAction.cpp b/src/geant4_application/src/RunAction.cpp index 04bb95a..dc6f3a4 100644 --- a/src/geant4_application/src/RunAction.cpp +++ b/src/geant4_application/src/RunAction.cpp @@ -20,6 +20,9 @@ void RunAction::BeginOfRunAction(const G4Run*) { if (IsMaster()) { container = make_unique(); } + + auto seed = G4Random::getTheSeed(); + cout << "RANDOM SEED: " << seed << endl; } void RunAction::EndOfRunAction(const G4Run*) { From a42b85a57f8b907c7dda8312c8f88da7d96840a9 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 21:43:32 -0600 Subject: [PATCH 12/28] debug --- tests/test_analysis.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_analysis.py b/tests/test_analysis.py index 5ce8201..83a9ce4 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -55,11 +55,12 @@ def test_sensitive(): assert len(volumes) == 1 volume = list(volumes)[0] print("volume: ", volume) - events = [] - run_events = app.run(1000) - run_events = run_events[run_events.energy_in_volume(volume) > 0] - events.append(run_events) - events = ak.concatenate(events) + events = app.run(1000) + energy_in_sensitive = events.energy_in_volume(volume) + for i, energy in enumerate(energy_in_sensitive): + print(f"event {i} energy: {energy}") + + events = events[energy_in_sensitive > 0] assert app.seed == 1234 assert len(events) == 5 hits = events.hits(volume) From 59342e1c560fff79900713f3ddb29fb3feefc55f Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 21:53:12 -0600 Subject: [PATCH 13/28] debug --- src/geant4_application/src/Application.cpp | 1 + tests/test_analysis.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/geant4_application/src/Application.cpp b/src/geant4_application/src/Application.cpp index c720a80..46c561d 100644 --- a/src/geant4_application/src/Application.cpp +++ b/src/geant4_application/src/Application.cpp @@ -36,6 +36,7 @@ void Application::SetupRandomEngine() { if (randomSeed == 0) { randomSeed = std::random_device()(); } + cout << "seed set to: " << randomSeed << endl; G4Random::setTheSeed(randomSeed); } diff --git a/tests/test_analysis.py b/tests/test_analysis.py index 83a9ce4..ea24c3d 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -61,6 +61,9 @@ def test_sensitive(): print(f"event {i} energy: {energy}") events = events[energy_in_sensitive > 0] + print("n: ", len(events)) + return + assert app.seed == 1234 assert len(events) == 5 hits = events.hits(volume) From 4132dd766641ae92a4b4630780a654300f0f9ec2 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 21:56:43 -0600 Subject: [PATCH 14/28] debug ci --- .github/workflows/build-test.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index f55701f..688846e 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -208,6 +208,10 @@ jobs: command: | python -c "import geant4_python_application as g4; g4.install_datasets()" + - name: Run tests debug + run: | + python -m pytest -s -vv tests/test_analysis.py + - name: Run tests run: | python -m pytest -vv --reruns 3 --reruns-delay 30 --only-rerun "(?i)http|timeout|connection|socket|resolve" From 3842ebd863c0dec44452caaca4e5a43081ed8ba0 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 22:13:16 -0600 Subject: [PATCH 15/28] debug datasets --- .github/workflows/build-test.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 688846e..1fdba40 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -15,10 +15,9 @@ on: pull_request: push: - branches: - [main] + branches: [main] - ## Paste this snippet into the workflow file to enable tmate debugging + ## Paste this snippet into the workflow file to enable tmate debugging # - name: Setup tmate session # uses: mxschmitt/action-tmate@v3 # if: @@ -186,8 +185,10 @@ jobs: if: matrix.python-version != '3.11' && matrix.os != 'windows-latest' run: | GEANT4_DATA_DIR=$(python -c "import geant4_python_application; print(geant4_python_application.data_directory())") + echo "GEANT4_DATA_DIR=$GEANT4_DATA_DIR" mkdir -p ${{ github.workspace }}/geant4-data $GEANT4_DATA_DIR mv ${{ github.workspace }}/geant4-data/* $GEANT4_DATA_DIR + ls -l $GEANT4_DATA_DIR # TODO: unify this with the above - name: Move Geant4 datasets (Windows) From f7547cbab6b9bc0ec81b55bb2d9b4728fb2a80f5 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 22:19:52 -0600 Subject: [PATCH 16/28] more debug --- .../include/geant4_application/RunAction.h | 1 + src/geant4_application/src/RunAction.cpp | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/geant4_application/include/geant4_application/RunAction.h b/src/geant4_application/include/geant4_application/RunAction.h index 9498740..18a49d9 100644 --- a/src/geant4_application/include/geant4_application/RunAction.h +++ b/src/geant4_application/include/geant4_application/RunAction.h @@ -1,6 +1,7 @@ #pragma once +#include #include #include diff --git a/src/geant4_application/src/RunAction.cpp b/src/geant4_application/src/RunAction.cpp index dc6f3a4..0db7b70 100644 --- a/src/geant4_application/src/RunAction.cpp +++ b/src/geant4_application/src/RunAction.cpp @@ -9,7 +9,7 @@ using namespace geant4_app; RunAction::RunAction() : G4UserRunAction() {} -void RunAction::BeginOfRunAction(const G4Run*) { +void RunAction::BeginOfRunAction(const G4Run* run) { lock_guard lock(mutex); builder = make_unique(Application::GetEventFields()); @@ -21,8 +21,7 @@ void RunAction::BeginOfRunAction(const G4Run*) { container = make_unique(); } - auto seed = G4Random::getTheSeed(); - cout << "RANDOM SEED: " << seed << endl; + cout << "RUN ID: " << run->GetRunID() << " RANDOM SEED: " << G4Random::getTheSeed() << endl; } void RunAction::EndOfRunAction(const G4Run*) { From 0d3f498651f3c64189b2c2dd7863e39c9ca44a54 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 22:25:06 -0600 Subject: [PATCH 17/28] more debug --- .../include/geant4_application/Application.h | 2 +- .../include/geant4_application/RunAction.h | 4 ++-- src/geant4_application/src/Application.cpp | 2 +- src/geant4_application/src/RunAction.cpp | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/geant4_application/include/geant4_application/Application.h b/src/geant4_application/include/geant4_application/Application.h index 17b8bb1..8fd3d46 100644 --- a/src/geant4_application/include/geant4_application/Application.h +++ b/src/geant4_application/include/geant4_application/Application.h @@ -49,7 +49,7 @@ class Application { void SetupAction(); void Initialize(); - py::list Run(const py::object& primaries); + std::vector Run(const py::object& primaries); bool IsSetup() const; bool IsInitialized() const; diff --git a/src/geant4_application/include/geant4_application/RunAction.h b/src/geant4_application/include/geant4_application/RunAction.h index 18a49d9..3e1633f 100644 --- a/src/geant4_application/include/geant4_application/RunAction.h +++ b/src/geant4_application/include/geant4_application/RunAction.h @@ -21,12 +21,12 @@ class RunAction : public G4UserRunAction { /// Only one instance of RunAction is created for each thread. static data::Builders& GetBuilder(); - static std::unique_ptr GetContainer(); + static std::unique_ptr> GetContainer(); private: std::unique_ptr builder = nullptr; std::mutex mutex; - static std::unique_ptr container; + static std::unique_ptr> container; static std::vector> buildersToSnapshot; }; diff --git a/src/geant4_application/src/Application.cpp b/src/geant4_application/src/Application.cpp index 46c561d..db465c1 100644 --- a/src/geant4_application/src/Application.cpp +++ b/src/geant4_application/src/Application.cpp @@ -119,7 +119,7 @@ void Application::Initialize() { isInitialized = true; } -py::list Application::Run(const py::object& primaries) { +vector Application::Run(const py::object& primaries) { if (!IsInitialized()) { Initialize(); } diff --git a/src/geant4_application/src/RunAction.cpp b/src/geant4_application/src/RunAction.cpp index 0db7b70..31737c4 100644 --- a/src/geant4_application/src/RunAction.cpp +++ b/src/geant4_application/src/RunAction.cpp @@ -18,7 +18,7 @@ void RunAction::BeginOfRunAction(const G4Run* run) { steppingVerbose->Initialize(); if (IsMaster()) { - container = make_unique(); + container = make_unique>(); } cout << "RUN ID: " << run->GetRunID() << " RANDOM SEED: " << G4Random::getTheSeed() << endl; @@ -33,7 +33,7 @@ void RunAction::EndOfRunAction(const G4Run*) { if (isMaster) { for (auto& builders: buildersToSnapshot) { - container->append(BuilderToObject(std::move(builders))); + container->push_back(BuilderToObject(std::move(builders))); } buildersToSnapshot.clear(); } @@ -44,9 +44,9 @@ data::Builders& RunAction::GetBuilder() { return *runAction->builder; } -unique_ptr RunAction::container = nullptr; +unique_ptr> RunAction::container = nullptr; -unique_ptr RunAction::GetContainer() { +unique_ptr> RunAction::GetContainer() { return std::move(RunAction::container); } From a0ed2cea1b47195ba56d796d6f7a7d3aec1b1dc3 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 22:28:42 -0600 Subject: [PATCH 18/28] more debug --- src/geant4_application/src/RunAction.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/geant4_application/src/RunAction.cpp b/src/geant4_application/src/RunAction.cpp index 31737c4..5eceac3 100644 --- a/src/geant4_application/src/RunAction.cpp +++ b/src/geant4_application/src/RunAction.cpp @@ -2,6 +2,8 @@ #include "geant4_application/RunAction.h" #include "geant4_application/SteppingVerbose.h" +#include + #include using namespace std; @@ -27,8 +29,10 @@ void RunAction::BeginOfRunAction(const G4Run* run) { void RunAction::EndOfRunAction(const G4Run*) { lock_guard lock(mutex); + cout << "END OF RUN. Thread: " << G4Threading::G4GetThreadId() << endl; if (!isMaster || !G4Threading::IsMultithreadedApplication()) { buildersToSnapshot.push_back(std::move(builder)); + cout << "LENGTH: " << buildersToSnapshot.back()->run.length() << endl; } if (isMaster) { @@ -37,6 +41,8 @@ void RunAction::EndOfRunAction(const G4Run*) { } buildersToSnapshot.clear(); } + + cout << "END OF END OF RUN. Thread: " << G4Threading::G4GetThreadId() << endl; } data::Builders& RunAction::GetBuilder() { From 837674a430a9781afdc490caab0f54e6e54709ad Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 22:38:43 -0600 Subject: [PATCH 19/28] space in directory name --- .github/workflows/build-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 1fdba40..efa7ba7 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -184,7 +184,7 @@ jobs: - name: Move Geant4 datasets (Ubuntu/MacOS) if: matrix.python-version != '3.11' && matrix.os != 'windows-latest' run: | - GEANT4_DATA_DIR=$(python -c "import geant4_python_application; print(geant4_python_application.data_directory())") + GEANT4_DATA_DIR="$(python -c "import geant4_python_application; print(geant4_python_application.data_directory())")" echo "GEANT4_DATA_DIR=$GEANT4_DATA_DIR" mkdir -p ${{ github.workspace }}/geant4-data $GEANT4_DATA_DIR mv ${{ github.workspace }}/geant4-data/* $GEANT4_DATA_DIR From c0da166650e167a56f10f16137585c1fe1a1145f Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 22:41:29 -0600 Subject: [PATCH 20/28] use other random engine --- src/geant4_application/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/geant4_application/src/Application.cpp b/src/geant4_application/src/Application.cpp index db465c1..e807553 100644 --- a/src/geant4_application/src/Application.cpp +++ b/src/geant4_application/src/Application.cpp @@ -32,7 +32,7 @@ Application::Application() { Application::~Application() = default; void Application::SetupRandomEngine() { - G4Random::setTheEngine(new CLHEP::RanecuEngine); + G4Random::setTheEngine(new CLHEP::MTwistEngine); if (randomSeed == 0) { randomSeed = std::random_device()(); } From 70b3058e976a4f3ee189f363d7914249a5a97cee Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 22:44:37 -0600 Subject: [PATCH 21/28] generate some random numbers --- src/geant4_application/src/RunAction.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/geant4_application/src/RunAction.cpp b/src/geant4_application/src/RunAction.cpp index 5eceac3..13f2dcb 100644 --- a/src/geant4_application/src/RunAction.cpp +++ b/src/geant4_application/src/RunAction.cpp @@ -24,6 +24,10 @@ void RunAction::BeginOfRunAction(const G4Run* run) { } cout << "RUN ID: " << run->GetRunID() << " RANDOM SEED: " << G4Random::getTheSeed() << endl; + + for (int i = 0; i < 10; ++i) { + cout << "RANDOM NUMBER: " << G4UniformRand() << endl; + } } void RunAction::EndOfRunAction(const G4Run*) { @@ -42,7 +46,7 @@ void RunAction::EndOfRunAction(const G4Run*) { buildersToSnapshot.clear(); } - cout << "END OF END OF RUN. Thread: " << G4Threading::G4GetThreadId() << endl; + cout << "- END OF RUN. Thread: " << G4Threading::G4GetThreadId() << endl; } data::Builders& RunAction::GetBuilder() { From 69964dde7f6cc1003e70b03508b3c94da6641110 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 22:53:47 -0600 Subject: [PATCH 22/28] quote path --- .github/workflows/build-test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index efa7ba7..2a3c004 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -184,11 +184,11 @@ jobs: - name: Move Geant4 datasets (Ubuntu/MacOS) if: matrix.python-version != '3.11' && matrix.os != 'windows-latest' run: | - GEANT4_DATA_DIR="$(python -c "import geant4_python_application; print(geant4_python_application.data_directory())")" + GEANT4_DATA_DIR=$(python -c "import geant4_python_application; print(geant4_python_application.data_directory())") echo "GEANT4_DATA_DIR=$GEANT4_DATA_DIR" - mkdir -p ${{ github.workspace }}/geant4-data $GEANT4_DATA_DIR - mv ${{ github.workspace }}/geant4-data/* $GEANT4_DATA_DIR - ls -l $GEANT4_DATA_DIR + mkdir -p ${{ github.workspace }}/geant4-data "$GEANT4_DATA_DIR" + mv ${{ github.workspace }}/geant4-data/* "$GEANT4_DATA_DIR" + ls -l "$GEANT4_DATA_DIR" # TODO: unify this with the above - name: Move Geant4 datasets (Windows) From 4f894b41472220166d73961b2a33cf56010c68d7 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 23:09:07 -0600 Subject: [PATCH 23/28] update test to new value --- tests/test_application.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/test_application.py b/tests/test_application.py index f43d1f0..377d0a9 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -47,15 +47,9 @@ def test_seed_single_thread(): # launch 100 events events = app.run(100) assert len(events) == 100 - reference_value = [ - 0.00000000e00, - 4.54930276e-01, - 2.25814551e-01, - 8.09506886e-03, - 1.22345221e00, - ] + reference_value = [0, 0.502, 0, 0.0952, 0.0199] energy = np.array(events.track.step.energy[0][0][0:5]) - assert np.allclose(energy, reference_value, atol=1e-5) + assert np.allclose(energy, reference_value, atol=1e-4) assert app.seed == 1100 From cc8663a3af6bd2340ff7495e656f64cf0c795af5 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 23:17:35 -0600 Subject: [PATCH 24/28] more debug --- tests/test_analysis.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_analysis.py b/tests/test_analysis.py index ea24c3d..47b6b4d 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -57,7 +57,9 @@ def test_sensitive(): print("volume: ", volume) events = app.run(1000) energy_in_sensitive = events.energy_in_volume(volume) - for i, energy in enumerate(energy_in_sensitive): + for i, energy in enumerate( + ak.flatten(ak.sum(events.track.step.energy, axis=-1)) + ): print(f"event {i} energy: {energy}") events = events[energy_in_sensitive > 0] From 56dbcbedf1506911dee124b7be03f4c0b584edfc Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 16 Dec 2023 23:47:41 -0600 Subject: [PATCH 25/28] more debug --- .../include/geant4_application/EventAction.h | 2 ++ src/geant4_application/src/EventAction.cpp | 5 +++++ src/geant4_application/src/SensitiveDetector.cpp | 6 +++++- tests/test_analysis.py | 9 +++++---- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/geant4_application/include/geant4_application/EventAction.h b/src/geant4_application/include/geant4_application/EventAction.h index 22f637f..b819f0e 100644 --- a/src/geant4_application/include/geant4_application/EventAction.h +++ b/src/geant4_application/include/geant4_application/EventAction.h @@ -13,6 +13,8 @@ class EventAction : public G4UserEventAction { void BeginOfEventAction(const G4Event*) override; void EndOfEventAction(const G4Event*) override; + + static double sensitiveEnergy; }; }// namespace geant4_app diff --git a/src/geant4_application/src/EventAction.cpp b/src/geant4_application/src/EventAction.cpp index c821043..a74f2d3 100644 --- a/src/geant4_application/src/EventAction.cpp +++ b/src/geant4_application/src/EventAction.cpp @@ -11,10 +11,15 @@ using namespace geant4_app; EventAction::EventAction() : G4UserEventAction() {} void EventAction::BeginOfEventAction(const G4Event* event) { + sensitiveEnergy = 0; data::InsertEventBegin(event, RunAction::GetBuilder()); data::InsertEvent(event, RunAction::GetBuilder()); } void EventAction::EndOfEventAction(const G4Event* event) { data::InsertEventEnd(event, RunAction::GetBuilder()); + + cout << "event id: " << event->GetEventID() << " Sensitive energy: " << sensitiveEnergy << endl; } + +double EventAction::sensitiveEnergy = 0.0; diff --git a/src/geant4_application/src/SensitiveDetector.cpp b/src/geant4_application/src/SensitiveDetector.cpp index 5774e39..c8a2582 100644 --- a/src/geant4_application/src/SensitiveDetector.cpp +++ b/src/geant4_application/src/SensitiveDetector.cpp @@ -1,11 +1,15 @@ #include "geant4_application/SensitiveDetector.h" +#include "geant4_application/EventAction.h" using namespace std; using namespace geant4_app; SensitiveDetector::SensitiveDetector(const string& name) : G4VSensitiveDetector(name) {} -G4bool SensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*) { return true; } +G4bool SensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*) { + EventAction::sensitiveEnergy += step->GetTotalEnergyDeposit() / CLHEP::keV; + return true; +} void SensitiveDetector::Initialize(G4HCofThisEvent*) {} diff --git a/tests/test_analysis.py b/tests/test_analysis.py index 47b6b4d..426d0e0 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -41,7 +41,10 @@ def test_events(): def test_sensitive(): - with Application(gdml=complexGdml, seed=1234) as app: + with Application(seed=1234) as app: + app.setup_detector(gdml=complexGdml) + + app.detector.sensitive_volumes = {"gasVolume"} volume_logical = "gasVolume" app.initialize() @@ -57,9 +60,7 @@ def test_sensitive(): print("volume: ", volume) events = app.run(1000) energy_in_sensitive = events.energy_in_volume(volume) - for i, energy in enumerate( - ak.flatten(ak.sum(events.track.step.energy, axis=-1)) - ): + for i, energy in enumerate(energy_in_sensitive): print(f"event {i} energy: {energy}") events = events[energy_in_sensitive > 0] From cb6011a3bd6fc98e98df7cddfb6211ceaf30191f Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sun, 17 Dec 2023 00:20:49 -0600 Subject: [PATCH 26/28] more debug --- .github/workflows/build-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index e238be3..be31e2c 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -209,7 +209,7 @@ jobs: - name: Run tests debug run: | - python -m pytest -s -vv tests/test_analysis.py + python -m pytest -s -vv tests/test_analysis.py::test_sensitive - name: Run tests run: | From 9bc82851e53a1836306848edb65868a808c3f4a4 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sun, 17 Dec 2023 00:29:25 -0600 Subject: [PATCH 27/28] more debug --- src/geant4_application/src/EventAction.cpp | 2 +- .../src/PrimaryGeneratorAction.cpp | 28 +------------------ tests/test_analysis.py | 2 +- 3 files changed, 3 insertions(+), 29 deletions(-) diff --git a/src/geant4_application/src/EventAction.cpp b/src/geant4_application/src/EventAction.cpp index a74f2d3..8090b22 100644 --- a/src/geant4_application/src/EventAction.cpp +++ b/src/geant4_application/src/EventAction.cpp @@ -19,7 +19,7 @@ void EventAction::BeginOfEventAction(const G4Event* event) { void EventAction::EndOfEventAction(const G4Event* event) { data::InsertEventEnd(event, RunAction::GetBuilder()); - cout << "event id: " << event->GetEventID() << " Sensitive energy: " << sensitiveEnergy << endl; + cout << "END OF EVENT: event id: " << event->GetEventID() << " Sensitive energy: " << sensitiveEnergy << endl; } double EventAction::sensitiveEnergy = 0.0; diff --git a/src/geant4_application/src/PrimaryGeneratorAction.cpp b/src/geant4_application/src/PrimaryGeneratorAction.cpp index b365606..d1be609 100644 --- a/src/geant4_application/src/PrimaryGeneratorAction.cpp +++ b/src/geant4_application/src/PrimaryGeneratorAction.cpp @@ -16,34 +16,8 @@ using namespace geant4_app; PrimaryGeneratorAction::PrimaryGeneratorAction() : G4VUserPrimaryGeneratorAction() {} void PrimaryGeneratorAction::GeneratePrimaries(G4Event* event) { - if (!awkwardPrimaryEnergies.empty()) { - const double energy = awkwardPrimaryEnergies[event->GetEventID()]; - gun.SetParticleEnergy(energy * keV); - } - if (!awkwardPrimaryPositions.empty()) { - const auto& position = awkwardPrimaryPositions[event->GetEventID()]; - gun.SetParticlePosition(G4ThreeVector(position[0] * cm, position[1] * cm, position[2] * cm)); - } - if (!awkwardPrimaryDirections.empty()) { - const auto& direction = awkwardPrimaryDirections[event->GetEventID()]; - gun.SetParticleMomentumDirection(G4ThreeVector(direction[0], direction[1], direction[2])); - } - if (!awkwardPrimaryParticles.empty()) { - const auto& particleAwkward = awkwardPrimaryParticles[event->GetEventID()]; - auto* particle = G4ParticleTable::GetParticleTable()->FindParticle(particleAwkward); - if (particle == nullptr) { - throw runtime_error("PrimaryGeneratorAction::GeneratePrimaries - particle '" + particleAwkward + "' not found"); - } - gun.SetParticleDefinition(particle); - } - if (generatorType == "gun") { - gun.GeneratePrimaryVertex(event); - } else if (generatorType == "gps") { - gps.GeneratePrimaryVertex(event); - } else { - throw runtime_error("PrimaryGeneratorAction::GeneratePrimaries - generatorType must be 'gun', 'gps'"); - } + gun.GeneratePrimaryVertex(event); } void PrimaryGeneratorAction::SetGeneratorType(const string& type) { diff --git a/tests/test_analysis.py b/tests/test_analysis.py index 426d0e0..bea17ea 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -58,7 +58,7 @@ def test_sensitive(): assert len(volumes) == 1 volume = list(volumes)[0] print("volume: ", volume) - events = app.run(1000) + events = app.run(2000) energy_in_sensitive = events.energy_in_volume(volume) for i, energy in enumerate(energy_in_sensitive): print(f"event {i} energy: {energy}") From ca092890324069a8dc6520f99e877e9086a8cb03 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sun, 17 Dec 2023 00:37:36 -0600 Subject: [PATCH 28/28] update parameters --- tests/test_analysis.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_analysis.py b/tests/test_analysis.py index bea17ea..535158f 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -49,16 +49,16 @@ def test_sensitive(): app.initialize() - app.command("/gun/particle neutron") - app.command("/gun/energy 100 MeV") - app.command("/gun/direction 0 -1 0") - app.command("/gun/position 0 10 0 m") + app.command("/gun/particle gamma") + app.command("/gun/energy 10 keV") + app.command("/gun/direction 0 0 -1") + app.command("/gun/position 0 0 20 cm") volumes = app.detector.physical_volumes_from_logical(volume_logical) assert len(volumes) == 1 volume = list(volumes)[0] print("volume: ", volume) - events = app.run(2000) + events = app.run(1000) energy_in_sensitive = events.energy_in_volume(volume) for i, energy in enumerate(energy_in_sensitive): print(f"event {i} energy: {energy}")