Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a628f00
tol for test007
dsarrut Jun 6, 2026
fbbe1ce
add a debug actor
dsarrut Jun 6, 2026
0e2400b
del unused include
dsarrut Jun 6, 2026
e4b9a8a
add DebugSource
dsarrut Jun 7, 2026
c58a932
replace super() with explicit base class initialization in all source…
dsarrut Jun 10, 2026
c368c6c
improve source cleanup, add pytomography integration tests, and provi…
dsarrut Jun 10, 2026
4593bbd
add dictionary serialization support to SourceManager and expand inte…
dsarrut Jun 10, 2026
d45fde1
add support for full simulation state serialization, including source…
dsarrut Jun 10, 2026
8406541
update debug source
dsarrut Jun 10, 2026
43960a8
prepare debug source
dsarrut Jun 11, 2026
a00a21d
no need mutex for value (in separate thread)
dsarrut Jun 11, 2026
61709cd
delegate source output recovery to objects and optimize G4 source ini…
dsarrut Jun 11, 2026
e29cf90
test sim json
dsarrut Jun 11, 2026
c7e448a
make it works on windows (no mt)
dsarrut Jun 11, 2026
5969a02
chmod
dsarrut Jun 11, 2026
17f0d78
debug print
dsarrut Jun 11, 2026
b7272b0
transition GenericSource to composition
dsarrut Jun 11, 2026
5f0615b
generic source refactor
dsarrut Jun 11, 2026
25fa5ca
refactor phid source
dsarrut Jun 11, 2026
3848d2d
refactor beamsource
dsarrut Jun 11, 2026
580b89e
refactor voxelsource
dsarrut Jun 11, 2026
16ff959
refactor lastvertexsource
dsarrut Jun 11, 2026
3188b0e
chmod a+x the tests
dsarrut Jun 11, 2026
d561303
refactor gan source
dsarrut Jun 11, 2026
95cfd62
fix total_skipped_events
dsarrut Jun 11, 2026
ae12fdf
refactor phspsource
dsarrut Jun 11, 2026
89be3fb
make it exec
dsarrut Jun 11, 2026
571edaa
Merge branch 'consolidate_june_2026' into refactor_source
dsarrut Jun 11, 2026
29719fd
fix cycle count
dsarrut Jun 11, 2026
da7be82
tweak ion particle
dsarrut Jun 11, 2026
ca9e8db
fix
dsarrut Jun 11, 2026
c02aba7
cache CDF in voxel sources
dsarrut Jun 11, 2026
66c4485
add print debug
dsarrut Jun 11, 2026
c5ec973
remove all thread local from sources
dsarrut Jun 12, 2026
f3f5933
fix comment
dsarrut Jun 12, 2026
9d3f981
rm debug print
dsarrut Jun 12, 2026
fcd20a3
Merge branch 'master' into refactor_source
dsarrut Jun 15, 2026
d0216cb
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] Jun 15, 2026
f331acd
Merge branch 'master' into refactor_source
dsarrut Jun 18, 2026
b68ffd0
Merge branch 'master' into refactor_source
dsarrut Jun 18, 2026
37ee3b6
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] Jun 18, 2026
610ffb1
rename to prevent run on windows (temporary)
dsarrut Jun 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ data/

# --- Tests
opengate/tests/output_dashboard/
opengate/tests/src/external/pytomography/output
opengate/tests/src/external/pytomography/data
opengate/tests/log
.clang-format
a.txt
Expand Down
6 changes: 6 additions & 0 deletions core/opengate_core/opengate_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ void init_GateAttributeComparisonFilter(py::module &);
// Gate actors
void init_GateDoseActor(py::module &m);

void init_GateDebugActor(py::module &m);

void init_GateVoxelizedPromptGammaTLEActor(py::module &m);

void init_GateVoxelizedPromptGammaAnalogActor(py::module &m);
Expand Down Expand Up @@ -530,6 +532,8 @@ void init_GateSourceManager(py::module &);

void init_GateGenericSource(py::module &);

void init_GateDebugSource(py::module &);

void init_GateTreatmentPlanPBSource(py::module &);

void init_GateTemplateSource(py::module &);
Expand Down Expand Up @@ -781,6 +785,7 @@ PYBIND11_MODULE(opengate_core, m) {
init_GateLastVertexSource(m);
init_GateSourceManager(m);
init_GateGenericSource(m);
init_GateDebugSource(m);
init_GateTreatmentPlanPBSource(m);
init_GateTemplateSource(m);
init_GatePencilBeamSource(m);
Expand All @@ -807,6 +812,7 @@ PYBIND11_MODULE(opengate_core, m) {
init_GateProcessDefinedStepInVolumeAttribute(m);

init_GateDoseActor(m);
init_GateDebugActor(m);
init_GateTLEDoseActor(m);
init_GateVoxelizedPromptGammaTLEActor(m);
init_GateVoxelizedPromptGammaAnalogActor(m);
Expand Down
64 changes: 64 additions & 0 deletions core/opengate_core/opengate_lib/GateDebugActor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* --------------------------------------------------
Copyright (C): OpenGATE Collaboration
This software is distributed under the terms
of the GNU Lesser General Public Licence (LGPL)
See LICENSE.md for further details
------------------------------------ -------------- */

#include "GateDebugActor.h"
#include "G4RunManager.hh"
#include "GateHelpers.h"

GateDebugActor::GateDebugActor(py::dict &user_info)
: GateVActor(user_info, true) {
DDD("(cpp) DebugActor constructor")
}

void GateDebugActor::InitializeUserInfo(py::dict &user_info) {
DDD("(cpp) DebugActor::InitializeUserInfo")
// IMPORTANT: call the base class method
GateVActor::InitializeUserInfo(user_info);
}

void GateDebugActor::InitializeCpp() {
DDD("(cpp) DebugActor::InitializeCpp")
GateVActor::InitializeCpp();
}

void GateDebugActor::BeginOfRunActionMasterThread(int run_id) {
DDD("(cpp) GateDebugActor::BeginOfRunActionMasterThread")
}

void GateDebugActor::BeginOfRunAction(const G4Run *run) {
DDD("(cpp) GateDebugActor::BeginOfRunAction", " ", run->GetRunID());
}

void GateDebugActor::BeginOfEventAction(const G4Event *event) {
DDD("(cpp) GateDebugActor::BeginOfEventAction", event->GetEventID());
}

void GateDebugActor::PreUserTrackingAction(const G4Track *track) {
DDD("(cpp) GateDebugActor::PreUserTrackingAction", " ", track->GetTrackID());
}

void GateDebugActor::PostUserTrackingAction(const G4Track *track) {
DDD("(cpp) GateDebugActor::PostUserTrackingAction", " ", track->GetTrackID());
}

void GateDebugActor::SteppingAction(G4Step *step) {
DDD("(cpp) GateDebugActor::SteppingAction", " ",
step->GetTrack()->GetCurrentStepNumber());
}

void GateDebugActor::EndOfEventAction(const G4Event *event) {
DDD("(cpp) GateDebugActor::EndOfEventAction", " ", event->GetEventID());
}

int GateDebugActor::EndOfRunActionMasterThread(int run_id) {
DDD("(cpp) GateDebugActor::EndOfRunActionMasterThread")
return 0;
}

void GateDebugActor::EndOfRunAction(const G4Run *run) {
DDD("(cpp) GateDebugActor::EndOfRunAction", " ", run->GetRunID());
}
43 changes: 43 additions & 0 deletions core/opengate_core/opengate_lib/GateDebugActor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* --------------------------------------------------
Copyright (C): OpenGATE Collaboration
This software is distributed under the terms
of the GNU Lesser General Public Licence (LGPL)
See LICENSE.md for further details
-------------------------------------------------- */

#ifndef GateDebugActor_h
#define GateDebugActor_h

#include "GateVActor.h"

namespace py = pybind11;

class GateDebugActor : public GateVActor {

public:
explicit GateDebugActor(py::dict &user_info);

void InitializeUserInfo(py::dict &user_info) override;

void InitializeCpp() override;

void BeginOfRunAction(const G4Run *run) override;

void BeginOfRunActionMasterThread(int run_id) override;

void BeginOfEventAction(const G4Event *event) override;

void PreUserTrackingAction(const G4Track *track) override;

void PostUserTrackingAction(const G4Track *track) override;

void SteppingAction(G4Step *) override;

void EndOfEventAction(const G4Event *event) override;

void EndOfRunAction(const G4Run *run) override;

int EndOfRunActionMasterThread(int run_id) override;
};

#endif // GateDebugActor_h
64 changes: 64 additions & 0 deletions core/opengate_core/opengate_lib/GateDebugSource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* --------------------------------------------------
Copyright (C): OpenGATE Collaboration
This software is distributed under the terms
of the GNU Lesser General Public Licence (LGPL)
See LICENSE.md for further details
-------------------------------------------------- */

#include "GateDebugSource.h"
#include "GateHelpers.h"
#include "GateHelpersDict.h"
#include "fmt/core.h"
#include <G4Threading.hh>
#include <G4UnitsTable.hh>
#include <pybind11/pytypes.h>

GateDebugSource::GateDebugSource() : GateVSource() {
DDD("GateDebugSource constructor");
fDebugValue = 0.0;
}

GateDebugSource::~GateDebugSource() { DDD("GateDebugSource destructor"); }

void GateDebugSource::CleanWorkerThread() {
DDD("GateDebugSource::CleanWorkerThread");
}

void GateDebugSource::InitializeUserInfo(py::dict &user_info) {
DDD("GateDebugSource::InitializeUserInfo");
GateVSource::InitializeUserInfo(user_info);
fDebugValue = DictGetDouble(user_info, "debug_value");
}

void GateDebugSource::UpdateActivity(const double time) {
DDD("GateDebugSource::UpdateActivity");
GateVSource::UpdateActivity(time);
}

double GateDebugSource::PrepareNextTime(const double current_simulation_time,
double NumberOfGeneratedEvents) {
DDD("GateDebugSource::PrepareNextTime", " ",
G4BestUnit(current_simulation_time, "Time"), " ",
NumberOfGeneratedEvents);
return GateVSource::PrepareNextTime(current_simulation_time,
NumberOfGeneratedEvents);
}

void GateDebugSource::PrepareNextRun() {
DDD("GateDebugSource::PrepareNextRun");
GateVSource::PrepareNextRun();
}

void GateDebugSource::GeneratePrimaries(G4Event *event,
const double current_simulation_time) {
DDD("GateDebugSource::GeneratePrimaries", " ", event->GetEventID(), " ",
fMaxN);
fNumberOfGeneratedEvents++;
fDebugValue += 1;
DDD("debug value = ", fDebugValue);
}

double GateDebugSource::GetDebugValue() {
DDD("GateDebugSource::GetDebugValue ", fDebugValue)
return fDebugValue;
}
42 changes: 42 additions & 0 deletions core/opengate_core/opengate_lib/GateDebugSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* --------------------------------------------------
Copyright (C): OpenGATE Collaboration
This software is distributed under the terms
of the GNU Lesser General Public Licence (LGPL)
See LICENSE.md for further details
-------------------------------------------------- */

#ifndef GateDebugSource_h
#define GateDebugSource_h

#include "GateVSource.h"
#include <G4Polymarker.hh>
#include <pybind11/stl.h>

namespace py = pybind11;

class GateDebugSource : public GateVSource {

public:
GateDebugSource();
~GateDebugSource() override;

void CleanWorkerThread() override;

void InitializeUserInfo(py::dict &user_info) override;

void UpdateActivity(const double time) override;

double PrepareNextTime(double current_simulation_time,
double NumberOfGeneratedEvents) override;

void PrepareNextRun() override;

void GeneratePrimaries(G4Event *event,
double current_simulation_time) override;

double GetDebugValue();

double fDebugValue = 0.0;
};

#endif // GateDebugSource_h
25 changes: 10 additions & 15 deletions core/opengate_core/opengate_lib/GateGANPairSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ GateGANPairSource::~GateGANPairSource() = default;

void GateGANPairSource::InitializeUserInfo(py::dict &user_info) {
GateGANSource::InitializeUserInfo(user_info);
auto &l = GetThreadLocalDataGenericSource();
if (l.fAAManager->IsEnabled()) {
if (fAAManager->IsEnabled()) {
std::ostringstream oss;
oss << "Error, cannot use AngularAcceptance with GAN pairs (yet), for the "
"source '"
Expand Down Expand Up @@ -71,8 +70,7 @@ void GateGANPairSource::GeneratePrimaries(G4Event *event,
fCurrentIndex++;

// update the number of generated event
auto &l = fThreadLocalData.Get();
l.fNumberOfGeneratedEvents++;
fNumberOfGeneratedEvents++;
}

void GateGANPairSource::GeneratePrimariesPair(G4Event *event,
Expand All @@ -89,12 +87,11 @@ void GateGANPairSource::GeneratePrimariesPair(G4Event *event,
fDirectionZ2[fCurrentIndex]);

// move position according to mother volume
auto &l = fThreadLocalData.Get();
position = l.fGlobalRotation * position + l.fGlobalTranslation;
position = fGlobalRotation * position + fGlobalTranslation;
// normalize (needed)
direction = direction / direction.mag();
// move according to mother volume
direction = l.fGlobalRotation * direction;
direction = fGlobalRotation * direction;

// energy of the second particle
double energy = fEnergy2[fCurrentIndex];
Expand All @@ -105,22 +102,20 @@ void GateGANPairSource::GeneratePrimariesPair(G4Event *event,
if (!accept_energy) {
energy = 0;
// at least one of the two vertices has been skipped with zeroE
auto &ll = GetThreadLocalDataGenericSource();
ll.fCurrentZeroEvents = 1;
fCurrentZeroEvents = 1;
}

auto &ll = fThreadLocalDataGenericSource.Get();
if (fTime_is_set_by_GAN && accept_energy) {
// time
double time = ll.fEffectiveEventTime;
double time = fEffectiveEventTime;
if (fRelativeTiming)
time += fTime2[fCurrentIndex];
else
time = fTime2[fCurrentIndex];
// consider the earliest one
ll.fEffectiveEventTime = std::min(time, ll.fEffectiveEventTime);
fEffectiveEventTime = std::min(time, fEffectiveEventTime);
} else {
ll.fEffectiveEventTime = current_simulation_time;
fEffectiveEventTime = current_simulation_time;
}

// weights
Expand All @@ -130,6 +125,6 @@ void GateGANPairSource::GeneratePrimariesPair(G4Event *event,
}

// Vertex
AddOnePrimaryVertex(event, position, direction, energy,
ll.fEffectiveEventTime, w);
AddOnePrimaryVertex(event, position, direction, energy, fEffectiveEventTime,
w);
}
Loading
Loading