-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #600 from OpenGATE/new_kill_interacting_particle
New kill interacting particle
- Loading branch information
Showing
9 changed files
with
591 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
core/opengate_core/opengate_lib/GateKillAccordingProcessesActor.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* -------------------------------------------------- | ||
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 "GateKillAccordingProcessesActor.h" | ||
#include "G4LogicalVolumeStore.hh" | ||
#include "G4ParticleTable.hh" | ||
#include "G4PhysicalVolumeStore.hh" | ||
#include "G4ProcessManager.hh" | ||
#include "G4VProcess.hh" | ||
#include "G4ios.hh" | ||
#include "GateHelpers.h" | ||
#include "GateHelpersDict.h" | ||
|
||
G4Mutex SetNbKillAccordingProcessesMutex = G4MUTEX_INITIALIZER; | ||
|
||
GateKillAccordingProcessesActor::GateKillAccordingProcessesActor( | ||
py::dict &user_info) | ||
: GateVActor(user_info, true) {} | ||
|
||
std::vector<G4String> | ||
GateKillAccordingProcessesActor::GetListOfPhysicsListProcesses() { | ||
std::vector<G4String> listOfAllProcesses = {}; | ||
|
||
G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable(); | ||
|
||
for (G4int i = 0; i < particleTable->size(); ++i) { | ||
G4ParticleDefinition *particle = particleTable->GetParticle(i); | ||
G4String particleName = particle->GetParticleName(); | ||
G4ProcessManager *processManager = particle->GetProcessManager(); | ||
if (!processManager) | ||
continue; | ||
G4int numProcesses = processManager->GetProcessListLength(); | ||
for (G4int j = 0; j < numProcesses; ++j) { | ||
const G4VProcess *process = (*(processManager->GetProcessList()))[j]; | ||
G4String processName = process->GetProcessName(); | ||
if (std::find(listOfAllProcesses.begin(), listOfAllProcesses.end(), | ||
processName) == listOfAllProcesses.end()) | ||
listOfAllProcesses.push_back(processName); | ||
} | ||
} | ||
return listOfAllProcesses; | ||
} | ||
|
||
void GateKillAccordingProcessesActor::InitializeUserInfo(py::dict &user_info) { | ||
GateVActor::InitializeUserInfo(user_info); | ||
fProcessesToKill = DictGetVecStr(user_info, "processes_to_kill"); | ||
fIsRayleighAnInteraction = | ||
DictGetBool(user_info, "is_rayleigh_an_interaction"); | ||
} | ||
|
||
void GateKillAccordingProcessesActor::BeginOfRunAction(const G4Run *run) { | ||
fNbOfKilledParticles = 0; | ||
std::vector<G4String> listOfAllProcesses = GetListOfPhysicsListProcesses(); | ||
listOfAllProcesses.push_back("all"); | ||
for (auto process : fProcessesToKill) { | ||
if (std::find(listOfAllProcesses.begin(), listOfAllProcesses.end(), | ||
process) == listOfAllProcesses.end()) { | ||
G4String errorMessage = | ||
"Process '" + process + "' not found. Existing processes are '"; | ||
for (auto aProcess : listOfAllProcesses) { | ||
errorMessage = errorMessage + aProcess + "', "; | ||
} | ||
errorMessage.pop_back(); | ||
errorMessage.pop_back(); | ||
G4Exception("CheckProcessExistence", // Exception origin | ||
"ProcessNotFound.1", // Exception code | ||
FatalException, // Exception severity | ||
errorMessage); | ||
} | ||
} | ||
if (fProcessesToKill[0] == "all") { | ||
if (fProcessesToKill.size() == 1) { | ||
fKillIfAnyInteraction = true; | ||
} | ||
} | ||
} | ||
|
||
void GateKillAccordingProcessesActor::PreUserTrackingAction( | ||
const G4Track *track) { | ||
fIsFirstStep = true; | ||
} | ||
|
||
void GateKillAccordingProcessesActor::SteppingAction(G4Step *step) { | ||
|
||
G4String logNameMotherVolume = G4LogicalVolumeStore::GetInstance() | ||
->GetVolume(fAttachedToVolumeName) | ||
->GetName(); | ||
G4String physicalVolumeNamePreStep = "None"; | ||
|
||
G4String processName = "None"; | ||
const G4VProcess *process = step->GetPostStepPoint()->GetProcessDefinedStep(); | ||
if (process != 0) | ||
processName = process->GetProcessName(); | ||
|
||
// Positron exception to retrieve the annihilation process, since it's an at | ||
// rest process most of the time | ||
|
||
if ((step->GetTrack()->GetParticleDefinition()->GetParticleName() == "e+") && | ||
(step->GetTrack()->GetTrackStatus() == 1)) | ||
processName = "annihil"; | ||
|
||
if (fKillIfAnyInteraction) { | ||
if (processName != "Transportation") { | ||
if (fIsRayleighAnInteraction == true) { | ||
step->GetTrack()->SetTrackStatus(fKillTrackAndSecondaries); | ||
G4AutoLock mutex(&SetNbKillAccordingProcessesMutex); | ||
fNbOfKilledParticles++; | ||
} else { | ||
if (processName != "Rayl") { | ||
step->GetTrack()->SetTrackStatus(fKillTrackAndSecondaries); | ||
G4AutoLock mutex(&SetNbKillAccordingProcessesMutex); | ||
fNbOfKilledParticles++; | ||
} | ||
} | ||
} | ||
} else { | ||
if (std::find(fProcessesToKill.begin(), fProcessesToKill.end(), | ||
processName) != fProcessesToKill.end()) { | ||
step->GetTrack()->SetTrackStatus(fKillTrackAndSecondaries); | ||
G4AutoLock mutex(&SetNbKillAccordingProcessesMutex); | ||
fNbOfKilledParticles++; | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
core/opengate_core/opengate_lib/GateKillAccordingProcessesActor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GateKillAccordingProcessesActor_h | ||
#define GateKillAccordingProcessesActor_h | ||
|
||
#include "G4Cache.hh" | ||
#include "GateVActor.h" | ||
#include <pybind11/stl.h> | ||
|
||
namespace py = pybind11; | ||
|
||
class GateKillAccordingProcessesActor : public GateVActor { | ||
|
||
public: | ||
// Constructor | ||
GateKillAccordingProcessesActor(py::dict &user_info); | ||
std::vector<G4String> GetListOfPhysicsListProcesses(); | ||
|
||
void InitializeUserInfo(py::dict &user_info) override; | ||
|
||
void BeginOfRunAction(const G4Run *) override; | ||
|
||
// Main function called every step in attached volume | ||
void SteppingAction(G4Step *) override; | ||
|
||
void PreUserTrackingAction(const G4Track *) override; | ||
|
||
std::vector<G4String> fParticlesTypeToKill; | ||
G4bool fIsFirstStep = true; | ||
std::vector<std::string> fProcessesToKill; | ||
std::vector<std::string> fListOfVolumeAncestor; | ||
G4bool fKillIfAnyInteraction = false; | ||
G4bool fIsRayleighAnInteraction = false; | ||
|
||
long fNbOfKilledParticles{}; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
core/opengate_core/opengate_lib/pyGateKillAccordingProcessesActor.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* -------------------------------------------------- | ||
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 <pybind11/pybind11.h> | ||
|
||
namespace py = pybind11; | ||
|
||
#include "GateKillAccordingProcessesActor.h" | ||
|
||
void init_GateKillAccordingProcessesActor(py::module &m) { | ||
py::class_<GateKillAccordingProcessesActor, | ||
std::unique_ptr<GateKillAccordingProcessesActor, py::nodelete>, | ||
GateVActor>(m, "GateKillAccordingProcessesActor") | ||
.def_readwrite("fListOfVolumeAncestor", | ||
&GateKillAccordingProcessesActor::fListOfVolumeAncestor) | ||
.def(py::init<py::dict &>()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.