35#include "G4Electron.hh"
36#include "G4GDMLParser.hh"
38#include "G4SystemOfUnits.hh"
39#include "G4VPhysicalVolume.hh"
43 : G4VFastSimulationModel(modelName, envelope) {
49 : G4VFastSimulationModel(modelName) {
57 G4VPhysicalVolume* physicalVolume) {
58 G4GDMLParser* parser =
new G4GDMLParser();
59 remove(
"garfieldGeometry.gdml");
60 parser->Write(
"garfieldGeometry.gdml", physicalVolume,
false);
65 const G4ParticleDefinition& particleType) {
66 G4String particleName = particleType.GetParticleName();
74 const G4FastTrack& fastTrack) {
75 double ekin_MeV = fastTrack.GetPrimaryTrack()->GetKineticEnergy() / MeV;
76 G4String particleName =
77 fastTrack.GetPrimaryTrack()->GetParticleDefinition()->GetParticleName();
86 G4FastStep& fastStep) {
88 G4ThreeVector localdir = fastTrack.GetPrimaryTrackLocalDirection();
89 G4ThreeVector localpos = fastTrack.GetPrimaryTrackLocalPosition();
91 double ekin_MeV = fastTrack.GetPrimaryTrack()->GetKineticEnergy() / MeV;
92 double globalTime = fastTrack.GetPrimaryTrack()->GetGlobalTime();
94 G4String particleName =
95 fastTrack.GetPrimaryTrack()->GetParticleDefinition()->GetParticleName();
97 fastStep.KillPrimaryTrack();
98 fastStep.SetPrimaryTrackPathLength(0.0);
100 if (particleName ==
"kaon+") {
102 }
else if (particleName ==
"kaon-") {
104 }
else if (particleName ==
"anti_proton") {
105 particleName =
"anti-proton";
108 fGarfieldPhysics->
DoIt(
109 particleName, ekin_MeV, globalTime, localpos.x() / CLHEP::cm,
110 localpos.y() / CLHEP::cm, localpos.z() / CLHEP::cm,
111 localdir.x(), localdir.y(), localdir.z());
116 std::vector<GarfieldParticle*>* secondaryParticles =
119 if (secondaryParticles->empty())
return;
120 fastStep.SetNumberOfSecondaryTracks(secondaryParticles->size());
122 G4double totalEnergySecondaries_MeV = 0;
124 for (
auto it = secondaryParticles->begin(); it != secondaryParticles->end(); ++it) {
125 G4double eKin_MeV = (*it)->getEkin_MeV();
126 G4double time = (*it)->getTime();
127 G4ThreeVector momentumDirection((*it)->getDX(), (*it)->getDY(),
129 G4ThreeVector position((*it)->getX_mm(), (*it)->getY_mm(),
131 if ((*it)->getParticleName() ==
"e-") {
132 G4DynamicParticle particle(G4Electron::ElectronDefinition(),
133 momentumDirection, eKin_MeV);
134 fastStep.CreateSecondaryTrack(particle, position, time,
true);
135 totalEnergySecondaries_MeV += eKin_MeV;
136 }
else if ((*it)->getParticleName() ==
"gamma") {
137 G4DynamicParticle particle(G4Gamma::GammaDefinition(),
138 momentumDirection, eKin_MeV);
139 fastStep.CreateSecondaryTrack(particle, position, time,
true);
140 totalEnergySecondaries_MeV += eKin_MeV;
virtual G4bool ModelTrigger(const G4FastTrack &)
~GarfieldG4FastSimulationModel()
virtual void DoIt(const G4FastTrack &, G4FastStep &)
void WriteGeometryToGDML(G4VPhysicalVolume *physicalVolume)
GarfieldG4FastSimulationModel(G4String, G4Region *)
virtual G4bool IsApplicable(const G4ParticleDefinition &)
bool GetCreateSecondariesInGeant4()
static GarfieldPhysics * GetInstance()
std::vector< GarfieldParticle * > * GetSecondaryParticles()
double GetEnergyDeposit_MeV()
void DoIt(std::string particleName, double ekin_MeV, double time, double x_cm, double y_cm, double z_cm, double dx, double dy, double dz)
bool FindParticleNameEnergy(std::string name, double ekin_MeV, std::string program="garfield")
bool FindParticleName(const std::string name, std::string program="garfield")