Skip to content

Commit

Permalink
Merge branch 'master' into update_gaga_garf
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaudier committed Dec 20, 2023
2 parents 2e1b4a6 + 42460ce commit dfc3bf9
Show file tree
Hide file tree
Showing 28 changed files with 1,400 additions and 73 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-11, windows-latest]
python-version: [3.8, 3.9, '3.10', '3.11']
exclude:
- os: macos-latest
- os: macos-11
python-version: '3.11'

env:
Expand All @@ -36,7 +36,7 @@ jobs:
if [[ ${{ matrix.os }} == "ubuntu-latest" ]]; then
export GIT_SSL_NO_VERIFY=1
git submodule update --init --recursive
elif [[ ${{ matrix.os }} == "macos-latest" ]]; then
elif [[ ${{ matrix.os }} == "macos-11" ]]; then
export GIT_SSL_NO_VERIFY=1
git submodule update --init --recursive
else
Expand All @@ -56,7 +56,7 @@ jobs:
varOS=`cat /etc/os-release | grep "VERSION=" | grep -oP '(?<=\").*?(?=\")'`
varOS=($varOS)
echo "release=${varOS[0]}" >> $GITHUB_OUTPUT
elif [[ ${{ matrix.os }} == "macos-latest" ]]; then
elif [[ ${{ matrix.os }} == "macos-11" ]]; then
varOS=`sw_vers | grep "ProductVersion:"`
varOS="${varOS#*:}"
echo "release=${varOS:1}" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -106,21 +106,21 @@ jobs:
mv dist_opengate/* dist/
fi
- uses: conda-incubator/setup-miniconda@v2
if: (matrix.os == 'macos-latest') || (matrix.os == 'windows-latest')
if: (matrix.os == 'macos-11') || (matrix.os == 'windows-latest')
with:
auto-update-conda: true
activate-environment: opengate_core
python-version: ${{ matrix.python-version }}
- name: Set up Homebrew
if: matrix.os == 'macos-latest'
if: matrix.os == 'macos-11'
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Create opengate_core Wheel Mac
if: matrix.os == 'macos-latest'
if: matrix.os == 'macos-11'
shell: bash -l {0}
run: |
brew update
rm -rf /usr/local/bin/python3.11-config /usr/local/bin/2to3-3.11 /usr/local/bin/idle3.11 /usr/local/bin/pydoc3.11 /usr/local/bin/python3.11
rm -rf /usr/local/bin/python3.1*-config /usr/local/bin/2to3-3.1* /usr/local/bin/idle3.1* /usr/local/bin/pydoc3.1* /usr/local/bin/python3.1*
rm -rf /usr/local/bin/python3-config /usr/local/bin/2to3 /usr/local/bin/idle3 /usr/local/bin/pydoc3 /usr/local/bin/python3
brew install --force --verbose --overwrite \
ccache \
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.11.0
rev: 23.12.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.5
rev: v17.0.6
hooks:
- id: clang-format
ci:
Expand Down
15 changes: 14 additions & 1 deletion core/opengate_core/opengate_lib/GateGANSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,20 @@ void GateGANSource::PrepareNextRun() {
// (no need to update th fSPS pos in GateGenericSource)
// GateVSource::PrepareNextRun();
// FIXME remove this function ?
GateGenericSource::PrepareNextRun();
// GateGenericSource::PrepareNextRun();
GateVSource::PrepareNextRun();
// This global transformation is given to the SPS that will
// generate particles in the correct coordinate system
auto &l = fThreadLocalData.Get();
auto *pos = fSPS->GetPosDist();
pos->SetCentreCoords(l.fGlobalTranslation);

// orientation according to mother volume
auto rotation = l.fGlobalRotation;
G4ThreeVector r1(rotation(0, 0), rotation(1, 0), rotation(2, 0));
G4ThreeVector r2(rotation(0, 1), rotation(1, 1), rotation(2, 1));
pos->SetPosRot1(r1);
pos->SetPosRot2(r2);
}

void GateGANSource::SetGeneratorFunction(ParticleGeneratorType &f) {
Expand Down
49 changes: 36 additions & 13 deletions core/opengate_core/opengate_lib/GateGenericSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
#include <G4UnitsTable.hh>

GateGenericSource::GateGenericSource() : GateVSource() {
fNumberOfGeneratedEvents = 0;
/*fNumberOfGeneratedEvents = 0;
fMaxN = 0;
fActivity = 0;
fHalfLife = -1;
fLambda = -1;
*/
fInitGenericIon = false;
fA = 0;
fZ = 0;
fE = 0;
fInitConfine = false;
fWeight = -1;
fWeightSigma = -1;
fHalfLife = -1;
fDecayConstant = -1;
fTotalSkippedEvents = 0;
fCurrentSkippedEvents = 0;
fTotalZeroEvents = 0;
Expand All @@ -34,6 +35,7 @@ GateGenericSource::GateGenericSource() : GateVSource() {
fParticleDefinition = nullptr;
fEffectiveEventTime = -1;
fEffectiveEventTime = -1;
fforceRotation = false;
}

GateGenericSource::~GateGenericSource() {
Expand Down Expand Up @@ -75,18 +77,20 @@ void GateGenericSource::InitializeUserInfo(py::dict &user_info) {
CreateSPS();

// get user info about activity or nb of events
/*
fMaxN = DictGetInt(user_info, "n");
fActivity = DictGetDouble(user_info, "activity");
fInitialActivity = fActivity;
// half life ?
fHalfLife = DictGetDouble(user_info, "half_life");
fDecayConstant = log(2) / fHalfLife;
fUserParticleLifeTime = DictGetDouble(user_info, "user_particle_life_time");
fLambda = log(2) / fHalfLife;
*/

// weight
fWeight = DictGetDouble(user_info, "weight");
fWeightSigma = DictGetDouble(user_info, "weight_sigma");
fUserParticleLifeTime = DictGetDouble(user_info, "user_particle_life_time");

// get the user info for the particle
InitializeParticle(user_info);
Expand All @@ -103,14 +107,14 @@ void GateGenericSource::InitializeUserInfo(py::dict &user_info) {
fCurrentSkippedEvents = 0;
fTotalSkippedEvents = 0;
fEffectiveEventTime = -1;

fforceRotation = DictGetDouble(user_info, "force_rotation");
}

void GateGenericSource::UpdateActivity(double time) {
if (!fTAC_Times.empty())
return UpdateActivityWithTAC(time);
if (fHalfLife <= 0)
return;
fActivity = fInitialActivity * exp(-fDecayConstant * (time - fStartTime));
GateVSource::UpdateActivity(time);
}

void GateGenericSource::UpdateActivityWithTAC(double time) {
Expand Down Expand Up @@ -159,14 +163,15 @@ double GateGenericSource::PrepareNextTime(double current_simulation_time) {
return -1;

// get next time according to current fActivity
double next_time =
fEffectiveEventTime - log(G4UniformRand()) * (1.0 / fActivity);
double next_time = CalcNextTime(fEffectiveEventTime);
if (next_time >= fEndTime)
return -1;
return next_time;
}

// check according to t MaxN
// std::cout<<fNumberOfGeneratedEvents<<std::endl;

if (fNumberOfGeneratedEvents + cse >= fMaxN) {
return -1;
}
Expand All @@ -180,15 +185,30 @@ void GateGenericSource::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);

// orientation according to mother volume
auto rotation = l.fGlobalRotation;
G4ThreeVector r1(rotation(0, 0), rotation(0, 1), rotation(0, 2));
G4ThreeVector r2(rotation(1, 0), rotation(1, 1), rotation(1, 2));
G4ThreeVector r1(rotation(0, 0), rotation(1, 0), rotation(2, 0));
G4ThreeVector r2(rotation(0, 1), rotation(1, 1), rotation(2, 1));
pos->SetPosRot1(r1);
pos->SetPosRot2(r2);

auto *ang = fSPS->GetAngDist();

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

void GateGenericSource::UpdateEffectiveEventTime(
Expand Down Expand Up @@ -226,7 +246,6 @@ void GateGenericSource::GeneratePrimaries(G4Event *event,
// (acceptance angle is included)
fSPS->SetParticleTime(current_simulation_time);
fSPS->GeneratePrimaryVertex(event);

// update the time according to skipped events
fEffectiveEventTime = current_simulation_time;
auto &l = fThreadLocalDataAA.Get();
Expand Down Expand Up @@ -300,6 +319,7 @@ void GateGenericSource::InitializePosition(py::dict puser_info) {
std::vector<std::string> l = {"sphere", "point", "box", "disc", "cylinder"};
CheckIsIn(pos_type, l);
auto translation = DictGetG4ThreeVector(user_info, "translation");
fInitTranslation = translation;
if (pos_type == "point") {
pos->SetPosDisType("Point");
}
Expand Down Expand Up @@ -365,6 +385,7 @@ void GateGenericSource::InitializeDirection(py::dict puser_info) {
auto user_info = py::dict(puser_info["direction"]);
auto *ang = fSPS->GetAngDist();
auto ang_type = DictGetStr(user_info, "type");
fangType = ang_type;
std::vector<std::string> ll = {"iso", "momentum", "focused",
"beam2d"}; // FIXME check on py side ?
CheckIsIn(ang_type, ll);
Expand All @@ -382,11 +403,13 @@ void GateGenericSource::InitializeDirection(py::dict puser_info) {
if (ang_type == "momentum") {
ang->SetAngDistType("planar"); // FIXME really ??
auto d = DictGetG4ThreeVector(user_info, "momentum");
fInitializeMomentum = d;
ang->SetParticleMomentumDirection(d);
}
if (ang_type == "focused") {
ang->SetAngDistType("focused");
auto f = DictGetG4ThreeVector(user_info, "focus_point");
fInitiliazeFocusPoint = f;
ang->SetFocusPoint(f);
}
if (ang_type == "beam2d") {
Expand Down
24 changes: 17 additions & 7 deletions core/opengate_core/opengate_lib/GateGenericSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GateGenericSource : public GateVSource {

/// Current number of simulated events in this source
/// (do not include skipped events)
unsigned long fNumberOfGeneratedEvents;
// unsigned long fNumberOfGeneratedEvents;

/// Count the number of skipped events
/// (e.g. Acceptance Angle or in GANSource)
Expand All @@ -51,16 +51,22 @@ class GateGenericSource : public GateVSource {
const std::vector<double> &activities);

protected:
unsigned long fMaxN;
// We cannot not use a std::unique_ptr
// (or maybe by controlling the deletion during the CleanWorkerThread ?)
// unsigned long fMaxN;
// We cannot not use a std::unique_ptr
// (or maybe by controlling the deletion during the CleanWorkerThread ?)
GateSingleParticleSource *fSPS;

/*
double fActivity;
double fInitialActivity;
double fHalfLife;
double fDecayConstant;
double fLambda;
*/

G4ParticleDefinition *fParticleDefinition;
G4ThreeVector fInitializeMomentum;
G4ThreeVector fInitiliazeFocusPoint;
G4ThreeVector fInitTranslation;
G4String fangType;
double fEffectiveEventTime;
double fUserParticleLifeTime;

Expand All @@ -78,6 +84,10 @@ class GateGenericSource : public GateVSource {
double fWeight;
double fWeightSigma;

// Force the rotation of momentum and focal point to follow rotation of the
// source, eg: needed for motion actor
bool fforceRotation;

// angular acceptance management
struct threadLocalT {
GateAcceptanceAngleTesterManager *fAAManager;
Expand Down Expand Up @@ -106,7 +116,7 @@ class GateGenericSource : public GateVSource {

virtual void InitializeEnergy(py::dict user_info);

virtual void UpdateActivity(double time);
virtual void UpdateActivity(double time) override;

void UpdateEffectiveEventTime(double current_simulation_time,
unsigned long skipped_particle);
Expand Down
2 changes: 1 addition & 1 deletion core/opengate_core/opengate_lib/GateMotionVolumeActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void GateMotionVolumeActor::MoveGeometry(int run_id) {
rot->set(r.rep3x3());

// close the geometry manager
gm->CloseGeometry(false, false, pv);
gm->CloseGeometry(true, false, pv);
// G4RunManager::GetRunManager()->GeometryHasBeenModified(true);
}

Expand Down
Loading

0 comments on commit dfc3bf9

Please sign in to comment.