Skip to content

Commit

Permalink
Merge pull request #422 from axelrannou/carm_contrib
Browse files Browse the repository at this point in the history
C-arm contrib
  • Loading branch information
tbaudier committed Aug 21, 2024
2 parents da47ed0 + 4bf906c commit 9e56ef3
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ jobs:
fi
pip install SimpleITK
pip install gaga_phsp==0.7.2
pip install spekpy
pip install dist/opengate_core-*-${PYTHONFOLDER}-${OSNAME}*_${PLATFORM}64.whl
pip install dist/opengate-*.whl
export GIT_SSL_NO_VERIFY=1
Expand Down
2 changes: 1 addition & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (Geant4_multithreaded_FOUND)
ENDIF ()
find_package(Threads REQUIRED)

#GDML
# GDML
IF (Geant4_gdml_FOUND)
message(STATUS "OPENGATE - Geant4 is compiled with GDML")
add_definitions(-DUSE_GDML=1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ GateAcceptanceAngleTesterManager::GateAcceptanceAngleTesterManager() {
}

void GateAcceptanceAngleTesterManager::Initialize(py::dict puser_info,
bool is_iso) {
bool is_valid_type) {
fAcceptanceAngleVolumeNames = DictGetVecStr(puser_info, "volumes");
fEnabledFlag = !fAcceptanceAngleVolumeNames.empty();
if (!fEnabledFlag)
Expand All @@ -39,10 +39,11 @@ void GateAcceptanceAngleTesterManager::Initialize(py::dict puser_info,
Fatal(oss.str());
}

// Cannot use SkipEvent with non iso source
if (!is_iso && fPolicy == AASkipEvent) {
// Cannot use SkipEvent with not a valid type of source
if (!is_valid_type && fPolicy == AASkipEvent) {
std::ostringstream oss;
oss << "Cannot use 'SkipEvent' mode without 'iso' direction type";
oss << "Cannot use 'SkipEvent' mode without 'iso' or 'histogram' direction "
"type";
Fatal(oss.str());
}
}
Expand Down
21 changes: 14 additions & 7 deletions core/opengate_core/opengate_lib/GateGenericSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ GateGenericSource::GateGenericSource() : GateVSource() {
fEffectiveEventTime = -1;
fEffectiveEventTime = -1;
fDirectionRelativeToAttachedVolume = false;
fUserParticleLifeTime = -1;
fBackToBackMode = false;
}

GateGenericSource::~GateGenericSource() {
Expand Down Expand Up @@ -90,7 +92,6 @@ void GateGenericSource::InitializeUserInfo(py::dict &user_info) {
fCurrentSkippedEvents = 0;
fTotalSkippedEvents = 0;
fEffectiveEventTime = -1;

fDirectionRelativeToAttachedVolume =
DictGetBool(user_info, "direction_relative_to_attached_volume");
}
Expand Down Expand Up @@ -162,14 +163,13 @@ double GateGenericSource::PrepareNextTime(double current_simulation_time) {
}

void GateGenericSource::PrepareNextRun() {
// The following compute the global transformation from
// The following function computes the global transformation from
// the local volume (mother) to the world
GateVSource::PrepareNextRun();

// This global transformation is given to the SPS that will
// generate particles in the correct coordinate system
auto &l = fThreadLocalData.Get();
// auto user_info_pos = py::dict(puser_info["position"]);
// auto pos_init = DictGetG4ThreeVector(user_info_pos, "translation");
auto *pos = fSPS->GetPosDist();
pos->SetCentreCoords(l.fGlobalTranslation);

Expand All @@ -180,17 +180,23 @@ void GateGenericSource::PrepareNextRun() {
pos->SetPosRot1(r1);
pos->SetPosRot2(r2);

// For the direction, the orientation may or may not be
// relative to the volume according to user option
auto *ang = fSPS->GetAngDist();

ang->fDirectionRelativeToAttachedVolume = fDirectionRelativeToAttachedVolume;
ang->fGlobalRotation = l.fGlobalRotation;
ang->fGlobalTranslation = l.fGlobalTranslation;
if (fangType == "momentum" && fDirectionRelativeToAttachedVolume) {
auto new_d = rotation * fInitializeMomentum;
ang->SetParticleMomentumDirection(new_d);
ang->fDirectionRelativeToAttachedVolume = false;
}
if (fangType == "focused" && fDirectionRelativeToAttachedVolume) {
auto vec_f = fInitiliazeFocusPoint - fInitTranslation;
auto rot_f = rotation * vec_f;
auto new_f = rot_f + l.fGlobalTranslation;
ang->SetFocusPoint(new_f);
ang->fDirectionRelativeToAttachedVolume = false;
}
}

Expand Down Expand Up @@ -443,10 +449,11 @@ void GateGenericSource::InitializeDirection(py::dict puser_info) {
// set the angle acceptance volume if needed
auto d = py::dict(puser_info["direction"]);
auto dd = py::dict(d["acceptance_angle"]);
auto is_iso = ang->GetDistType() == "iso";
auto is_valid_type =
ang->GetDistType() == "iso" || ang->GetDistType() == "user";
auto &l = fThreadLocalDataAA.Get();
l.fAAManager = new GateAcceptanceAngleTesterManager;
l.fAAManager->Initialize(dd, is_iso);
l.fAAManager->Initialize(dd, is_valid_type);
fSPS->SetAAManager(l.fAAManager);
}

Expand Down
19 changes: 19 additions & 0 deletions core/opengate_core/opengate_lib/GateSPSAngDistribution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* --------------------------------------------------
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 "GateSPSAngDistribution.h"
#include "GateHelpers.h"

G4ThreeVector GateSPSAngDistribution::VGenerateOne() {
// return GenerateOne();
auto direction = GenerateOne();
if (fDirectionRelativeToAttachedVolume) {
direction = direction / direction.mag();
direction = fGlobalRotation * direction;
}
return direction;
}
30 changes: 30 additions & 0 deletions core/opengate_core/opengate_lib/GateSPSAngDistribution.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* --------------------------------------------------
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 GateSPSAngDistribution_h
#define GateSPSAngDistribution_h

#include "G4ParticleDefinition.hh"
#include "G4SPSAngDistribution.hh"

class GateSPSAngDistribution : public G4SPSAngDistribution {

public:
virtual ~GateSPSAngDistribution() = default;

// Cannot inherit from GenerateOne, so we consider VGenerateOne instead
virtual G4ThreeVector VGenerateOne();

// Store the global orientation that may be applied to the direction
// in the GenerateOne function.
// (Must be updated each run)
bool fDirectionRelativeToAttachedVolume;
G4ThreeVector fGlobalTranslation;
G4RotationMatrix fGlobalRotation;
};

#endif // GateSPSAngDistribution_h
6 changes: 3 additions & 3 deletions core/opengate_core/opengate_lib/GateSingleParticleSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
#include "G4PrimaryVertex.hh"
#include "G4RunManager.hh"
#include "GateHelpers.h"

#include "GateRandomMultiGauss.h"

GateSingleParticleSource::GateSingleParticleSource(
std::string /*mother_volume*/) {
fPositionGenerator = new GateSPSPosDistribution();
fDirectionGenerator = new G4SPSAngDistribution();
fDirectionGenerator = new GateSPSAngDistribution();
fEnergyGenerator = new GateSPSEneDistribution();

// needed
Expand Down Expand Up @@ -64,7 +63,8 @@ GateSingleParticleSource::GenerateDirectionWithAA(const G4ThreeVector &position,
fAAManager->StartAcceptLoop();
while (!accept_angle) {
// direction
direction = fDirectionGenerator->GenerateOne();
direction = fDirectionGenerator->VGenerateOne();

// accept ?
accept_angle = fAAManager->TestIfAccept(position, direction);
if (!accept_angle && fAAManager->GetPolicy() ==
Expand Down
9 changes: 4 additions & 5 deletions core/opengate_core/opengate_lib/GateSingleParticleSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@

#include "G4AffineTransform.hh"
#include "G4ParticleDefinition.hh"
#include "G4SPSAngDistribution.hh"
#include "G4VPrimaryGenerator.hh"
#include "GateAcceptanceAngleTester.h"
#include "GateAcceptanceAngleTesterManager.h"
#include "GateHelpers.h"
#include "GateRandomMultiGauss.h"
#include "GateSPSAngDistribution.h"
#include "GateSPSEneDistribution.h"
#include "GateSPSPosDistribution.h"

#include "GateRandomMultiGauss.h"

/*
Single Particle Source generator.
We need to re-implement the one from G4 in order to
Expand All @@ -37,7 +36,7 @@ class GateSingleParticleSource : public G4VPrimaryGenerator {

GateSPSPosDistribution *GetPosDist() { return fPositionGenerator; }

G4SPSAngDistribution *GetAngDist() { return fDirectionGenerator; }
GateSPSAngDistribution *GetAngDist() { return fDirectionGenerator; }

GateSPSEneDistribution *GetEneDist() { return fEnergyGenerator; }

Expand All @@ -62,7 +61,7 @@ class GateSingleParticleSource : public G4VPrimaryGenerator {
double fCharge;
double fMass;
GateSPSPosDistribution *fPositionGenerator;
G4SPSAngDistribution *fDirectionGenerator;
GateSPSAngDistribution *fDirectionGenerator;
GateSPSEneDistribution *fEnergyGenerator;
G4SPSRandomGenerator *fBiasRndm;
bool fAccolinearityFlag;
Expand Down
Binary file added opengate/contrib/carm/anodeheeleffect.npz
Binary file not shown.
Loading

0 comments on commit 9e56ef3

Please sign in to comment.