Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
GarfieldG4FastSimulationModel.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// $Id: GarfieldG4FastSimulationModel.cc 999994 2015-12-11 14:47:43Z dpfeiffe $
27//
28/// \file GarfieldG4FastSimulationModel.cc
29/// \brief Implementation of the GarfieldG4FastSimulationModel class
30
32
33#include <iostream>
34
35#include "G4Electron.hh"
36#include "G4GDMLParser.hh"
37#include "G4Gamma.hh"
38#include "G4SystemOfUnits.hh"
39#include "G4VPhysicalVolume.hh"
40
42 G4Region* envelope)
43 : G4VFastSimulationModel(modelName, envelope) {
44 fGarfieldPhysics = GarfieldPhysics::GetInstance();
45 fGarfieldPhysics->InitializePhysics();
46}
47
49 : G4VFastSimulationModel(modelName) {
50 fGarfieldPhysics = GarfieldPhysics::GetInstance();
51 fGarfieldPhysics->InitializePhysics();
52}
53
55
57 G4VPhysicalVolume* physicalVolume) {
58 G4GDMLParser* parser = new G4GDMLParser();
59 remove("garfieldGeometry.gdml");
60 parser->Write("garfieldGeometry.gdml", physicalVolume, false);
61 delete parser;
62}
63
65 const G4ParticleDefinition& particleType) {
66 G4String particleName = particleType.GetParticleName();
67 if (fGarfieldPhysics->FindParticleName(particleName, "garfield")) {
68 return true;
69 }
70 return false;
71}
72
74 const G4FastTrack& fastTrack) {
75 double ekin_MeV = fastTrack.GetPrimaryTrack()->GetKineticEnergy() / MeV;
76 G4String particleName =
77 fastTrack.GetPrimaryTrack()->GetParticleDefinition()->GetParticleName();
78 if (fGarfieldPhysics->FindParticleNameEnergy(particleName, ekin_MeV,
79 "garfield")) {
80 return true;
81 }
82 return false;
83}
84
85void GarfieldG4FastSimulationModel::DoIt(const G4FastTrack& fastTrack,
86 G4FastStep& fastStep) {
87
88 G4ThreeVector localdir = fastTrack.GetPrimaryTrackLocalDirection();
89 G4ThreeVector localpos = fastTrack.GetPrimaryTrackLocalPosition();
90
91 double ekin_MeV = fastTrack.GetPrimaryTrack()->GetKineticEnergy() / MeV;
92 double globalTime = fastTrack.GetPrimaryTrack()->GetGlobalTime();
93
94 G4String particleName =
95 fastTrack.GetPrimaryTrack()->GetParticleDefinition()->GetParticleName();
96
97 fastStep.KillPrimaryTrack();
98 fastStep.SetPrimaryTrackPathLength(0.0);
99
100 if (particleName == "kaon+") {
101 particleName = "K+";
102 } else if (particleName == "kaon-") {
103 particleName = "K-";
104 } else if (particleName == "anti_proton") {
105 particleName = "anti-proton";
106 }
107
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());
112
113 fastStep.SetTotalEnergyDeposited(fGarfieldPhysics->GetEnergyDeposit_MeV());
114
115 if (!fGarfieldPhysics->GetCreateSecondariesInGeant4()) return;
116 std::vector<GarfieldParticle*>* secondaryParticles =
117 fGarfieldPhysics->GetSecondaryParticles();
118
119 if (secondaryParticles->empty()) return;
120 fastStep.SetNumberOfSecondaryTracks(secondaryParticles->size());
121
122 G4double totalEnergySecondaries_MeV = 0;
123
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(),
128 (*it)->getDZ());
129 G4ThreeVector position((*it)->getX_mm(), (*it)->getY_mm(),
130 (*it)->getZ_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;
141 }
142 }
143
144}
virtual G4bool ModelTrigger(const G4FastTrack &)
virtual void DoIt(const G4FastTrack &, G4FastStep &)
void WriteGeometryToGDML(G4VPhysicalVolume *physicalVolume)
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")