Garfield++ 3.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
31#include <iostream>
33#include "G4VPhysicalVolume.hh"
34#include "G4GDMLParser.hh"
35#include "G4Electron.hh"
36#include "G4Gamma.hh"
37
38#include "G4SystemOfUnits.hh"
39
41 G4Region* envelope) :
42 G4VFastSimulationModel(modelName, envelope) {
43 fGarfieldPhysics = GarfieldPhysics::GetInstance();
44 fGarfieldPhysics->InitializePhysics();
45
46}
47
49 G4VFastSimulationModel(modelName) {
50 fGarfieldPhysics = GarfieldPhysics::GetInstance();
51 fGarfieldPhysics->InitializePhysics();
52}
53
55}
56
58 G4VPhysicalVolume* physicalVolume) {
59
60 G4GDMLParser* parser = new G4GDMLParser();
61 remove("garfieldGeometry.gdml");
62 parser->Write("garfieldGeometry.gdml", physicalVolume, false);
63 delete parser;
64}
65
67 const G4ParticleDefinition& particleType) {
68 G4String particleName = particleType.GetParticleName();
69 if (fGarfieldPhysics->FindParticleName(particleName, "garfield")) {
70 return true;
71 }
72 return false;
73}
74
76 const G4FastTrack& fastTrack) {
77 double ekin_MeV = fastTrack.GetPrimaryTrack()->GetKineticEnergy() / MeV;
78 G4String particleName =
79 fastTrack.GetPrimaryTrack()->GetParticleDefinition()->GetParticleName();
80 if (fGarfieldPhysics->FindParticleNameEnergy(particleName, ekin_MeV,
81 "garfield")) {
82 return true;
83 }
84 return false;
85}
86
87void GarfieldG4FastSimulationModel::DoIt(const G4FastTrack& fastTrack,
88 G4FastStep& fastStep) {
89
90 G4TouchableHandle theTouchable =
91 fastTrack.GetPrimaryTrack()->GetTouchableHandle();
92 G4String name = theTouchable->GetVolume()->GetName();
93
94 G4ThreeVector pdirection =
95 fastTrack.GetPrimaryTrack()->GetMomentum().unit();
96 G4ThreeVector localdir = fastTrack.GetPrimaryTrackLocalDirection();
97
98 G4ThreeVector worldPosition = fastTrack.GetPrimaryTrack()->GetPosition();
99 G4ThreeVector localPosition = fastTrack.GetPrimaryTrackLocalPosition();
100
101 double ekin_MeV = fastTrack.GetPrimaryTrack()->GetKineticEnergy() / MeV;
102 G4double globalTime = fastTrack.GetPrimaryTrack()->GetGlobalTime();
103
104 G4String particleName =
105 fastTrack.GetPrimaryTrack()->GetParticleDefinition()->GetParticleName();
106
107 fastStep.KillPrimaryTrack();
108 fastStep.SetPrimaryTrackPathLength(0.0);
109
110 if (particleName == "kaon+") {
111 particleName = "K+";
112 } else if (particleName == "kaon-") {
113 particleName = "K-";
114 } else if (particleName == "anti_proton") {
115 particleName = "anti-proton";
116 }
117
118 fGarfieldPhysics->DoIt(particleName, ekin_MeV, globalTime,
119 localPosition.x() / CLHEP::cm, localPosition.y() / CLHEP::cm,
120 localPosition.z() / CLHEP::cm, localdir.x(), localdir.y(),
121 localdir.z());
122
123 fastStep.SetTotalEnergyDeposited(fGarfieldPhysics->GetEnergyDeposit_MeV());
124
125 if (fGarfieldPhysics->GetCreateSecondariesInGeant4()) {
126 std::vector<GarfieldParticle*>* secondaryParticles =
127 fGarfieldPhysics->GetSecondaryParticles();
128
129 if (secondaryParticles->size() > 0) {
130 fastStep.SetNumberOfSecondaryTracks(secondaryParticles->size());
131
132 G4double totalEnergySecondaries_MeV = 0;
133
134 for (std::vector<GarfieldParticle*>::iterator it =
135 secondaryParticles->begin();
136 it != secondaryParticles->end(); ++it) {
137 G4double x = (*it)->getX_mm();
138 G4double y = (*it)->getY_mm();
139 G4double z = (*it)->getZ_mm();
140 G4double eKin_MeV = (*it)->getEkin_MeV();
141 G4double dx = (*it)->getDX();
142 G4double dy = (*it)->getDY();
143 G4double dz = (*it)->getDZ();
144 G4double time = (*it)->getTime();
145 G4ThreeVector momentumDirection(dx, dy, dz);
146 G4ThreeVector position(x, y, z);
147 if ((*it)->getParticleName() == "e-") {
148 G4DynamicParticle particle(G4Electron::ElectronDefinition(),
149 momentumDirection, eKin_MeV);
150 fastStep.CreateSecondaryTrack(particle, position, time,
151 true);
152 totalEnergySecondaries_MeV += eKin_MeV;
153 } else if ((*it)->getParticleName() == "gamma") {
154 G4DynamicParticle particle(G4Gamma::GammaDefinition(),
155 momentumDirection, eKin_MeV);
156 fastStep.CreateSecondaryTrack(particle, position, time,
157 true);
158 totalEnergySecondaries_MeV += eKin_MeV;
159 }
160
161 }
162 }
163 }
164}
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")