Skip to content

Commit

Permalink
[pre-commit.ci] Automatic python and c++ formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Jul 2, 2024
1 parent 5503679 commit 23d4720
Show file tree
Hide file tree
Showing 9 changed files with 485 additions and 448 deletions.
2 changes: 1 addition & 1 deletion core/opengate_core/opengate_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ void init_GatePhaseSpaceActor(py::module &);

void init_GateOptrComptSplittingActor(py::module &m);

void init_GateLastVertexInteractionSplittingActor(py::module &m);
void init_GateLastVertexInteractionSplittingActor(py::module &m);

void init_GateBOptrBremSplittingActor(py::module &m);

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@
#ifndef GateLastVertexInteractionSplittingActor_h
#define GateLastVertexInteractionSplittingActor_h 1

#include "GateVActor.h"
#include "G4ParticleChangeForGamma.hh"
#include "G4VEnergyLossProcess.hh"
#include "GateVActor.h"
#include <iostream>
#include <pybind11/stl.h>
namespace py = pybind11;



class GateLastVertexInteractionSplittingActor : public GateVActor {
public:
GateLastVertexInteractionSplittingActor(py::dict &user_info);
Expand All @@ -62,48 +60,50 @@ class GateLastVertexInteractionSplittingActor : public GateVActor {
G4double fSplitCounter = 0;
G4bool fNotSplitted = true;

G4Track* fTrackToSplit = nullptr;
G4Step* fStepToSplit = nullptr;
G4Track *fTrackToSplit = nullptr;
G4Step *fStepToSplit = nullptr;
G4String fProcessToSplit = "None";

std::vector<G4Track> fTracksToPostpone;
std::map<G4int,G4TrackVector> fRememberedTracks;
std::map<G4int,std::vector<G4Step*>> fRememberedSteps;
std::map<G4int,std::vector<G4String>> fRememberedProcesses;

std::map<G4int, G4TrackVector> fRememberedTracks;
std::map<G4int, std::vector<G4Step *>> fRememberedSteps;
std::map<G4int, std::vector<G4String>> fRememberedProcesses;

std::vector<std::string> fListOfVolumeAncestor;

std::vector<G4String> fListOfProcesses = {"compt","annihil","eBrem","conv","phot"};
std::vector<G4String> fListOfProcesses = {"compt", "annihil", "eBrem", "conv",
"phot"};

virtual void SteppingAction(G4Step *) override;
virtual void BeginOfEventAction(const G4Event *) override;
virtual void BeginOfRunAction(const G4Run *run) override;
virtual void PreUserTrackingAction(const G4Track* track) override;
virtual void PostUserTrackingAction(const G4Track* track) override;

//Pure splitting functions
G4double RussianRouletteForAngleSurvival(G4ThreeVector, G4ThreeVector, G4double, G4double);
G4Track* CreateComptonTrack(G4ParticleChangeForGamma*,G4Track, G4double);
void ComptonSplitting(G4Step* CurrentStep,G4Track* track,const G4Step* step,G4VProcess* process);
void SecondariesSplitting(G4Step* CurrentStep,G4Track* track,const G4Step* step,G4VProcess* process);


//Handling the remembered processes to replay
void RememberLastProcessInformation(G4Step*);
void CreateNewParticleAtTheLastVertex(G4Step*,G4Track*,const G4Step*,G4String);
void ResetProcessesForEnteringParticles(G4Step * step);
void ClearRememberedTracksAndSteps(std::map<G4int, G4TrackVector>, std::map<G4int, std::vector<G4Step *>>);


//Edge case to handle the bias in annihilation
//FIXME : The triple annihilation is not handled for the moment
void PostponeFirstAnnihilationTrackIfInteraction(G4Step *step,G4String processName);
virtual void PreUserTrackingAction(const G4Track *track) override;
virtual void PostUserTrackingAction(const G4Track *track) override;

// Pure splitting functions
G4double RussianRouletteForAngleSurvival(G4ThreeVector, G4ThreeVector,
G4double, G4double);
G4Track *CreateComptonTrack(G4ParticleChangeForGamma *, G4Track, G4double);
void ComptonSplitting(G4Step *CurrentStep, G4Track *track, const G4Step *step,
G4VProcess *process);
void SecondariesSplitting(G4Step *CurrentStep, G4Track *track,
const G4Step *step, G4VProcess *process);

// Handling the remembered processes to replay
void RememberLastProcessInformation(G4Step *);
void CreateNewParticleAtTheLastVertex(G4Step *, G4Track *, const G4Step *,
G4String);
void ResetProcessesForEnteringParticles(G4Step *step);
void ClearRememberedTracksAndSteps(std::map<G4int, G4TrackVector>,
std::map<G4int, std::vector<G4Step *>>);

// Edge case to handle the bias in annihilation
// FIXME : The triple annihilation is not handled for the moment
void PostponeFirstAnnihilationTrackIfInteraction(G4Step *step,
G4String processName);
void RegenerationOfPostponedAnnihilationTrack(G4Step *step);
void HandleTrackIDIfPostponedAnnihilation(G4Step* step);



void HandleTrackIDIfPostponedAnnihilation(G4Step *step);
};

#endif
106 changes: 49 additions & 57 deletions core/opengate_core/opengate_lib/GateLastVertexSplittingPostStepDoIt.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,78 +27,70 @@
#ifndef GateLastVertexSplittingPostStepDoIt_h
#define GateLastVertexSplittingPostStepDoIt_h


#include "G4VEnergyLossProcess.hh"
#include "G4VEmProcess.hh"
#include "G4VParticleChange.hh"
#include "G4eplusAnnihilation.hh"
#include "G4PhysicalConstants.hh"
#include "G4MaterialCutsCouple.hh"
#include "G4Gamma.hh"
#include "G4Electron.hh"
#include "G4Positron.hh"
#include "G4eeToTwoGammaModel.hh"
#include "G4EmBiasingManager.hh"
#include "G4EntanglementAuxInfo.hh"
#include "G4eplusAnnihilationEntanglementClipBoard.hh"
#include "G4EmParameters.hh"
#include "G4EntanglementAuxInfo.hh"
#include "G4Gamma.hh"
#include "G4MaterialCutsCouple.hh"
#include "G4PhysicalConstants.hh"
#include "G4PhysicsModelCatalog.hh"
#include "G4Positron.hh"
#include "G4VEmProcess.hh"
#include "G4VEnergyLossProcess.hh"
#include "G4VParticleChange.hh"
#include "G4eeToTwoGammaModel.hh"
#include "G4eplusAnnihilation.hh"
#include "G4eplusAnnihilationEntanglementClipBoard.hh"
#include <iostream>




class GateBremPostStepDoIt : public G4VEnergyLossProcess {
public :

GateBremPostStepDoIt();

~ GateBremPostStepDoIt();

virtual G4VParticleChange * PostStepDoIt (const G4Track & track, const G4Step & step) override
{
const G4MaterialCutsCouple* couple = step.GetPreStepPoint()->GetMaterialCutsCouple();
currentCouple = couple;
G4VParticleChange* particleChange = G4VEnergyLossProcess::PostStepDoIt(track,step);
return particleChange;
}


public:
GateBremPostStepDoIt();

~GateBremPostStepDoIt();

virtual G4VParticleChange *PostStepDoIt(const G4Track &track,
const G4Step &step) override {
const G4MaterialCutsCouple *couple =
step.GetPreStepPoint()->GetMaterialCutsCouple();
currentCouple = couple;
G4VParticleChange *particleChange =
G4VEnergyLossProcess::PostStepDoIt(track, step);
return particleChange;
}
};


class GateGammaEmPostStepDoIt : public G4VEmProcess {
public :

GateGammaEmPostStepDoIt();

~ GateGammaEmPostStepDoIt();

virtual G4VParticleChange * PostStepDoIt(const G4Track & track, const G4Step & step) override
{
const G4MaterialCutsCouple* couple = step.GetPreStepPoint()->GetMaterialCutsCouple();
currentCouple = couple;
G4VParticleChange* particleChange = G4VEmProcess::PostStepDoIt(track,step);
return particleChange;
}


public:
GateGammaEmPostStepDoIt();

~GateGammaEmPostStepDoIt();

virtual G4VParticleChange *PostStepDoIt(const G4Track &track,
const G4Step &step) override {
const G4MaterialCutsCouple *couple =
step.GetPreStepPoint()->GetMaterialCutsCouple();
currentCouple = couple;
G4VParticleChange *particleChange = G4VEmProcess::PostStepDoIt(track, step);
return particleChange;
}
};

class GateplusannihilAtRestDoIt : public G4eplusAnnihilation {
public :

GateplusannihilAtRestDoIt();
~ GateplusannihilAtRestDoIt();
public:
GateplusannihilAtRestDoIt();
~GateplusannihilAtRestDoIt();

virtual G4VParticleChange* AtRestDoIt(const G4Track& track,
const G4Step& step) override
// Performs the e+ e- annihilation when both particles are assumed at rest.
virtual G4VParticleChange *AtRestDoIt(const G4Track &track,
const G4Step &step) override
// Performs the e+ e- annihilation when both particles are assumed at rest.
{
G4Track copyTrack = G4Track(track);
copyTrack.SetStep(&step);
G4VParticleChange* particleChange = G4eplusAnnihilation::AtRestDoIt(copyTrack,step);
return particleChange;
G4Track copyTrack = G4Track(track);
copyTrack.SetStep(&step);
G4VParticleChange *particleChange =
G4eplusAnnihilation::AtRestDoIt(copyTrack, step);
return particleChange;
}
};
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ namespace py = pybind11;

void init_GateLastVertexInteractionSplittingActor(py::module &m) {

py::class_<GateLastVertexInteractionSplittingActor, GateVActor,
std::unique_ptr<GateLastVertexInteractionSplittingActor, py::nodelete>>(
py::class_<
GateLastVertexInteractionSplittingActor, GateVActor,
std::unique_ptr<GateLastVertexInteractionSplittingActor, py::nodelete>>(
m, "GateLastVertexInteractionSplittingActor")
.def_readwrite(
"fListOfVolumeAncestor",
Expand Down
10 changes: 5 additions & 5 deletions opengate/actors/miscactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,6 @@ def __init__(self, user_info):
g4.GateKillActor.__init__(self, user_info.__dict__)




class ComptSplittingActor(g4.GateOptrComptSplittingActor, ActorBase):
type_name = "ComptSplittingActor"

Expand All @@ -454,9 +452,11 @@ def __init__(self, user_info):
g4.GateOptrComptSplittingActor.__init__(self, user_info.__dict__)


class LastVertexInteractionSplittingActor(g4.GateLastVertexInteractionSplittingActor, ActorBase):
class LastVertexInteractionSplittingActor(
g4.GateLastVertexInteractionSplittingActor, ActorBase
):
type_name = "LastVertexInteractionSplittingActor"

def set_default_user_info(user_info):
ActorBase.set_default_user_info(user_info)
deg = g4_units.deg
Expand All @@ -472,7 +472,7 @@ def __init__(self, user_info):
g4.GateLastVertexInteractionSplittingActor.__init__(self, user_info.__dict__)
self.list_of_volume_name = user_info.list_of_volume_name
self.user_info.mother = user_info.mother

def initialize(self, volume_engine=None):

super().initialize(volume_engine)
Expand Down
5 changes: 2 additions & 3 deletions opengate/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,11 +1033,10 @@ def dump_volume_types(self):
for vt in self.volume_types:
s += f"{vt} "
return s

def get_volume_tree(self):
return self.volume_tree_root



def dump_material_database_names(self):
return list(self.material_database.filenames)

Expand Down
13 changes: 7 additions & 6 deletions opengate/tests/src/test076_last_vertex_splittting.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def validation_test(arr_ref, arr_data, nb_split, tol=0.2, tol_weights=0.04):
# ui.running_verbose_level = gate.logger.EVENT
ui.number_of_threads = 1
# 1236566 seg fault
#12745 double compt
# 12745 double compt
ui.random_seed = 73

# units
Expand Down Expand Up @@ -146,7 +146,7 @@ def validation_test(arr_ref, arr_data, nb_split, tol=0.2, tol_weights=0.04):
W_tubs.mother = world.name

W_tubs.rmin = 0
W_tubs.rmax = 0.4*cm
W_tubs.rmax = 0.4 * cm
W_tubs.dz = 0.05 * m
W_tubs.color = [0.8, 0.2, 0.1, 1]
angle_x = 45
Expand All @@ -160,7 +160,9 @@ def validation_test(arr_ref, arr_data, nb_split, tol=0.2, tol_weights=0.04):

####### Compton Splitting ACTOR #########
nb_split = 25
vertex_splitting_actor = sim.add_actor("LastVertexInteractionSplittingActor", "vertexSplittingW")
vertex_splitting_actor = sim.add_actor(
"LastVertexInteractionSplittingActor", "vertexSplittingW"
)
vertex_splitting_actor.mother = W_tubs.name
vertex_splitting_actor.splitting_factor = nb_split
vertex_splitting_actor.russian_roulette_for_angle = False
Expand All @@ -169,7 +171,7 @@ def validation_test(arr_ref, arr_data, nb_split, tol=0.2, tol_weights=0.04):
plan_tubs = sim.add_volume("Tubs", "phsp_tubs")
plan_tubs.material = "G4_Galactic"
plan_tubs.mother = world.name
plan_tubs.rmin = W_tubs.rmax + 1*cm
plan_tubs.rmin = W_tubs.rmax + 1 * cm
plan_tubs.rmax = plan_tubs.rmin + 1 * nm
plan_tubs.dz = 0.05 * m
plan_tubs.color = [0.2, 1, 0.8, 1]
Expand All @@ -185,7 +187,7 @@ def validation_test(arr_ref, arr_data, nb_split, tol=0.2, tol_weights=0.04):
# source.direction.momentum = [0,0,-1]
source.direction.momentum = np.dot(rotation, np.array([0, 0, -1]))
source.energy.type = "mono"
source.energy.mono = 4* MeV
source.energy.mono = 4 * MeV

####### PHASE SPACE ACTOR ##############

Expand Down Expand Up @@ -233,4 +235,3 @@ def validation_test(arr_ref, arr_data, nb_split, tol=0.2, tol_weights=0.04):
# #
# is_ok = validation_test(arr_ref_data, arr_data, nb_split)
# utility.test_ok(is_ok)

Loading

0 comments on commit 23d4720

Please sign in to comment.