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 Jun 25, 2024
1 parent f3a0575 commit abd6297
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 78 deletions.
70 changes: 38 additions & 32 deletions core/opengate_core/opengate_lib/GateOptnVGenericSplitting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,57 +49,63 @@

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

GateOptnVGenericSplitting::
GateOptnVGenericSplitting(G4String name)
GateOptnVGenericSplitting::GateOptnVGenericSplitting(G4String name)
: G4VBiasingOperation(name), fParticleChange() {}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

GateOptnVGenericSplitting::
~GateOptnVGenericSplitting() {}
GateOptnVGenericSplitting::~GateOptnVGenericSplitting() {}

void GateOptnVGenericSplitting::TrackInitializationChargedParticle(
G4ParticleChange *particleChange, G4VParticleChange *processFinalState,
const G4Track *track, G4double split) {

void GateOptnVGenericSplitting::TrackInitializationChargedParticle(G4ParticleChange* particleChange,G4VParticleChange* processFinalState, const G4Track* track,G4double split) {

G4ParticleChangeForLoss* processFinalStateForLoss =( G4ParticleChangeForLoss* ) processFinalState ;
G4ParticleChangeForLoss *processFinalStateForLoss =
(G4ParticleChangeForLoss *)processFinalState;
particleChange->Initialize(*track);
particleChange->ProposeTrackStatus(processFinalStateForLoss->GetTrackStatus() );
particleChange->ProposeEnergy(processFinalStateForLoss->GetProposedKineticEnergy() );
particleChange->ProposeMomentumDirection(processFinalStateForLoss->GetProposedMomentumDirection());
particleChange->ProposeTrackStatus(
processFinalStateForLoss->GetTrackStatus());
particleChange->ProposeEnergy(
processFinalStateForLoss->GetProposedKineticEnergy());
particleChange->ProposeMomentumDirection(
processFinalStateForLoss->GetProposedMomentumDirection());
particleChange->SetNumberOfSecondaries(fSplittingFactor);
particleChange->SetSecondaryWeightByProcess(true);
processFinalStateForLoss->Clear();
}

void GateOptnVGenericSplitting::TrackInitializationGamma(G4ParticleChange* particleChange,G4VParticleChange* processFinalState, const G4Track* track,G4double split) {
G4ParticleChangeForGamma* processFinalStateForGamma = (G4ParticleChangeForGamma *)processFinalState;
void GateOptnVGenericSplitting::TrackInitializationGamma(
G4ParticleChange *particleChange, G4VParticleChange *processFinalState,
const G4Track *track, G4double split) {
G4ParticleChangeForGamma *processFinalStateForGamma =
(G4ParticleChangeForGamma *)processFinalState;
particleChange->Initialize(*track);
particleChange->ProposeTrackStatus(processFinalStateForGamma->GetTrackStatus() );
particleChange->ProposeEnergy(processFinalStateForGamma->GetProposedKineticEnergy() );
particleChange->ProposeMomentumDirection(processFinalStateForGamma->GetProposedMomentumDirection() );
particleChange->ProposeTrackStatus(
processFinalStateForGamma->GetTrackStatus());
particleChange->ProposeEnergy(
processFinalStateForGamma->GetProposedKineticEnergy());
particleChange->ProposeMomentumDirection(
processFinalStateForGamma->GetProposedMomentumDirection());
particleChange->SetNumberOfSecondaries(fSplittingFactor);
particleChange->SetSecondaryWeightByProcess(true);
processFinalStateForGamma->Clear();


}

G4double GateOptnVGenericSplitting::RussianRouletteForAngleSurvival(G4ThreeVector dir,G4ThreeVector vectorDirector,G4double maxTheta,G4double split){
G4double cosTheta =vectorDirector * dir;
G4double theta = std::acos(cosTheta);
G4double weightToApply = 1;
if (theta > maxTheta){
G4double probability = G4UniformRand();
if (probability <= 1 / split) {
weightToApply = split;
G4double GateOptnVGenericSplitting::RussianRouletteForAngleSurvival(
G4ThreeVector dir, G4ThreeVector vectorDirector, G4double maxTheta,
G4double split) {
G4double cosTheta = vectorDirector * dir;
G4double theta = std::acos(cosTheta);
G4double weightToApply = 1;
if (theta > maxTheta) {
G4double probability = G4UniformRand();
if (probability <= 1 / split) {
weightToApply = split;
} else {
weightToApply = 0;
}
}
else{
weightToApply = 0;
}
}
return weightToApply;

return weightToApply;
}


//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
21 changes: 13 additions & 8 deletions core/opengate_core/opengate_lib/GateOptnVGenericSplitting.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,20 @@ class GateOptnVGenericSplitting : public G4VBiasingOperation {
return 0;
}

// ----------------------------------------------
// -- Methods for the generic splitting
// ----------------------------------------------

// ----------------------------------------------
// -- Methods for the generic splitting
// ----------------------------------------------

void TrackInitializationChargedParticle(G4ParticleChange* particleChange,G4VParticleChange* processFinalState, const G4Track* track,G4double split);
void TrackInitializationGamma(G4ParticleChange* particleChange,G4VParticleChange* processFinalState, const G4Track* track,G4double split);
static G4double RussianRouletteForAngleSurvival(G4ThreeVector dir,G4ThreeVector vectorDirector,G4double maxTheta,G4double split);

void TrackInitializationChargedParticle(G4ParticleChange *particleChange,
G4VParticleChange *processFinalState,
const G4Track *track, G4double split);
void TrackInitializationGamma(G4ParticleChange *particleChange,
G4VParticleChange *processFinalState,
const G4Track *track, G4double split);
static G4double RussianRouletteForAngleSurvival(G4ThreeVector dir,
G4ThreeVector vectorDirector,
G4double maxTheta,
G4double split);

public:
// ----------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@
#include "G4eplusAnnihilation.hh"
#include "GateOptnPairProdSplitting.h"
#include "GateOptnScatteredGammaSplitting.h"
#include "GateOptnVGenericSplitting.h"
#include "GateOptneBremSplitting.h"
#include "GateOptrComptPseudoTransportationActor.h"
#include "G4UImanager.hh"
#include "G4eplusAnnihilation.hh"
#include "GateOptnVGenericSplitting.h"


//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

Expand Down Expand Up @@ -144,9 +141,8 @@ void GateOptrComptPseudoTransportationActor::StartSimulationAction() {

fPairProdSplittingOperation->SetSplittingFactor(fSplittingFactor);

fFreeFlightOperation->SetRussianRouletteForWeights(fRussianRouletteForWeights);


fFreeFlightOperation->SetRussianRouletteForWeights(
fRussianRouletteForWeights);
}

void GateOptrComptPseudoTransportationActor::StartRun() {
Expand All @@ -171,38 +167,47 @@ void GateOptrComptPseudoTransportationActor::StartRun() {

void GateOptrComptPseudoTransportationActor::SteppingAction(G4Step *step) {
G4String creationProcessName = "None";
if (step->GetTrack()->GetCreatorProcess() != 0){
creationProcessName = step->GetTrack()->GetCreatorProcess()->GetProcessName();

if (step->GetTrack()->GetCreatorProcess() != 0) {
creationProcessName =
step->GetTrack()->GetCreatorProcess()->GetProcessName();
}

if ((fIsFirstStep) && (fRussianRouletteForAngle)){
G4String LogicalVolumeNameOfCreation = step->GetTrack()->GetLogicalVolumeAtVertex()->GetName();
if (std::find(fNameOfBiasedLogicalVolume.begin(), fNameOfBiasedLogicalVolume.end(),LogicalVolumeNameOfCreation ) !=fNameOfBiasedLogicalVolume.end()){
if (creationProcessName == "biasWrapper(annihil)"){

if ((fIsFirstStep) && (fRussianRouletteForAngle)) {
G4String LogicalVolumeNameOfCreation =
step->GetTrack()->GetLogicalVolumeAtVertex()->GetName();
if (std::find(fNameOfBiasedLogicalVolume.begin(),
fNameOfBiasedLogicalVolume.end(),
LogicalVolumeNameOfCreation) !=
fNameOfBiasedLogicalVolume.end()) {
if (creationProcessName == "biasWrapper(annihil)") {
auto dir = step->GetPreStepPoint()->GetMomentumDirection();
G4double w = GateOptnVGenericSplitting::RussianRouletteForAngleSurvival(dir,fVectorDirector,fMaxTheta,fSplittingFactor);
if (w == 0)
{
G4double w = GateOptnVGenericSplitting::RussianRouletteForAngleSurvival(
dir, fVectorDirector, fMaxTheta, fSplittingFactor);
if (w == 0) {
step->GetTrack()->SetTrackStatus(fStopAndKill);
}
else {
} else {
step->GetTrack()->SetWeight(step->GetTrack()->GetWeight() * w);
}
}
}
}
}

if ((isSplitted == true) && (step->GetPostStepPoint()->GetStepStatus() != fWorldBoundary)) {
G4String LogicalVolumeName = step->GetPostStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetName();
if (!(std::find(fNameOfBiasedLogicalVolume.begin(), fNameOfBiasedLogicalVolume.end(),LogicalVolumeName ) !=fNameOfBiasedLogicalVolume.end())
&& (LogicalVolumeName != fMotherVolumeName)) {

if ((isSplitted == true) &&
(step->GetPostStepPoint()->GetStepStatus() != fWorldBoundary)) {
G4String LogicalVolumeName = step->GetPostStepPoint()
->GetPhysicalVolume()
->GetLogicalVolume()
->GetName();
if (!(std::find(fNameOfBiasedLogicalVolume.begin(),
fNameOfBiasedLogicalVolume.end(),
LogicalVolumeName) != fNameOfBiasedLogicalVolume.end()) &&
(LogicalVolumeName != fMotherVolumeName)) {
step->GetTrack()->SetTrackStatus(fStopAndKill);
isSplitted = false;
}
}
}

fIsFirstStep = false;
fIsFirstStep = false;
}

void GateOptrComptPseudoTransportationActor::BeginOfEventAction(
Expand All @@ -218,14 +223,17 @@ void GateOptrComptPseudoTransportationActor::StartTracking(
const G4Track *track) {
G4String creationProcessName = "None";
fIsFirstStep = true;
if (track->GetCreatorProcess() != 0){
if (track->GetCreatorProcess() != 0) {
creationProcessName = track->GetCreatorProcess()->GetProcessName();
}


if (track->GetParticleDefinition()->GetParticleName() == "gamma"){
G4String LogicalVolumeNameOfCreation = track->GetLogicalVolumeAtVertex()->GetName();
if (std::find(fNameOfBiasedLogicalVolume.begin(), fNameOfBiasedLogicalVolume.end(),LogicalVolumeNameOfCreation ) !=fNameOfBiasedLogicalVolume.end()){
if (track->GetParticleDefinition()->GetParticleName() == "gamma") {
G4String LogicalVolumeNameOfCreation =
track->GetLogicalVolumeAtVertex()->GetName();
if (std::find(fNameOfBiasedLogicalVolume.begin(),
fNameOfBiasedLogicalVolume.end(),
LogicalVolumeNameOfCreation) !=
fNameOfBiasedLogicalVolume.end()) {

fInitialWeight = track->GetWeight();
fFreeFlightOperation->SetInitialWeight(fInitialWeight);
Expand Down Expand Up @@ -299,8 +307,10 @@ GateOptrComptPseudoTransportationActor::ProposeFinalStateBiasingOperation(
return feBremSplittingOperation;
}

if (!(std::find(fCreationProcessNameList.begin(), fCreationProcessNameList.end(),CreationProcessName) != fCreationProcessNameList.end())){
if (callingProcess->GetWrappedProcess()->GetProcessName() == "compt"){
if (!(std::find(fCreationProcessNameList.begin(),
fCreationProcessNameList.end(),
CreationProcessName) != fCreationProcessNameList.end())) {
if (callingProcess->GetWrappedProcess()->GetProcessName() == "compt") {

isSplitted = true;
return fScatteredGammaSplittingOperation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ class GateOptrComptPseudoTransportationActor : public G4VBiasingOperator,
G4int ftrackIDAtTheEntrance;
G4int fEventID;
G4double fEventIDKineticEnergy;
G4bool ftestbool= false;
G4bool ftestbool = false;
G4bool fIsFirstStep = false;
const G4VProcess* fAnnihilation =nullptr;
const G4VProcess *fAnnihilation = nullptr;

std::vector<G4String> fNameOfBiasedLogicalVolume = {};
std::vector<G4int> v_EventID = {};
std::vector<G4String> fCreationProcessNameList = {"biasWrapper(compt)", "biasWrapper(eBrem)","biasWrapper(annihil)"};
std::vector<G4String> fCreationProcessNameList = {
"biasWrapper(compt)", "biasWrapper(eBrem)", "biasWrapper(annihil)"};

// Unused but mandatory

Expand Down

0 comments on commit abd6297

Please sign in to comment.