VMC Examples Version 6.6
Loading...
Searching...
No Matches
GarfieldG4FastSimulationModel.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Virtual Monte Carlo examples
3// Copyright (C) 2007 - 2016 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
10/// \file Garfield/geant4/src/GarfieldG4FastSimulationModel.cxx
11/// \brief Implementation of the GarfieldG4FastSimulationModel class
12///
13/// Garfield garfieldpp example adapted to Virtual Monte Carlo.
14/// This class is imported from garfieldpp example.
15/// There is disabled WriteGeometryToGDML function in order to avoid
16/// requiring Geant4 optional library.
17///
18/// \date 28/10/2015
19/// \author D. Pheiffer, CERN
20
21/*
22 * GarfieldModel.cpp
23 *
24 * Created on: Apr 9, 2014
25 * Author: dpfeiffe
26 */
28#include "G4Electron.hh"
29#include "G4Gamma.hh"
30#include "G4VPhysicalVolume.hh"
31#include <iostream>
32
33#include "G4SystemOfUnits.hh"
34
35// I.H. make this optional
36// #include "G4GDMLParser.hh"
37
45
53
55
56// I.H. make this optional
57// void GarfieldG4FastSimulationModel::WriteGeometryToGDML(
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{
69
70 G4String particleName = particleType.GetParticleName();
71
72 if (fGarfieldPhysics->FindParticleName(particleName)) {
73 return true;
74 }
75 return false;
76}
77
78G4bool GarfieldG4FastSimulationModel::ModelTrigger(const G4FastTrack& fastTrack)
79{
80 double ekin_MeV = fastTrack.GetPrimaryTrack()->GetKineticEnergy() / MeV;
81 G4String particleName =
82 fastTrack.GetPrimaryTrack()->GetParticleDefinition()->GetParticleName();
83 if (fGarfieldPhysics->FindParticleNameEnergy(particleName, ekin_MeV)) {
84 return true;
85 }
86 return false;
87}
88
90 const G4FastTrack& fastTrack, G4FastStep& fastStep)
91{
92
93 G4TouchableHandle theTouchable =
94 fastTrack.GetPrimaryTrack()->GetTouchableHandle();
95 G4String name = theTouchable->GetVolume()->GetName();
96
97 G4ThreeVector pdirection = fastTrack.GetPrimaryTrack()->GetMomentum().unit();
98 G4ThreeVector localdir = fastTrack.GetPrimaryTrackLocalDirection();
99
100 G4ThreeVector worldPosition = fastTrack.GetPrimaryTrack()->GetPosition();
101 G4ThreeVector localPosition = fastTrack.GetPrimaryTrackLocalPosition();
102
103 double ekin_MeV = fastTrack.GetPrimaryTrack()->GetKineticEnergy() / MeV;
104 G4double globalTime = fastTrack.GetPrimaryTrack()->GetGlobalTime();
105
106 G4String particleName =
107 fastTrack.GetPrimaryTrack()->GetParticleDefinition()->GetParticleName();
108
109 fastStep.KillPrimaryTrack();
110 fastStep.SetPrimaryTrackPathLength(0.0);
111
112 if (particleName == "kaon+") {
113 particleName = "K+";
114 }
115 else if (particleName == "kaon-") {
116 particleName = "K-";
117 }
118 else if (particleName == "anti_proton") {
119 particleName = "anti-proton";
120 }
121
122 fGarfieldPhysics->DoIt(particleName, ekin_MeV, globalTime,
123 localPosition.x() / CLHEP::cm, localPosition.y() / CLHEP::cm,
124 localPosition.z() / CLHEP::cm, localdir.x(), localdir.y(), localdir.z());
125
126 fastStep.SetTotalEnergyDeposited(fGarfieldPhysics->GetEnergyDeposit_MeV());
127
129 std::vector<GarfieldParticle*>* secondaryParticles =
131
132 if (secondaryParticles->size() > 0) {
133 fastStep.SetNumberOfSecondaryTracks(secondaryParticles->size());
134
135 G4double totalEnergySecondaries_MeV = 0;
136
137 for (std::vector<GarfieldParticle*>::iterator it =
138 secondaryParticles->begin();
139 it != secondaryParticles->end(); ++it) {
140 G4double x = (*it)->getX_mm();
141 G4double y = (*it)->getY_mm();
142 G4double z = (*it)->getZ_mm();
143 G4double eKin_MeV = (*it)->getEkin_MeV();
144 G4double dx = (*it)->getDX();
145 G4double dy = (*it)->getDY();
146 G4double dz = (*it)->getDZ();
147 G4double time = (*it)->getTime();
148 G4ThreeVector momentumDirection(dx, dy, dz);
149 G4ThreeVector position(x, y, z);
150 if ((*it)->getParticleName() == "e-") {
151 G4DynamicParticle particle(
152 G4Electron::ElectronDefinition(), momentumDirection, eKin_MeV);
153 fastStep.CreateSecondaryTrack(particle, position, time, true);
154 totalEnergySecondaries_MeV += eKin_MeV;
155 }
156 else if ((*it)->getParticleName() == "gamma") {
157 G4DynamicParticle particle(
158 G4Gamma::GammaDefinition(), momentumDirection, eKin_MeV);
159 fastStep.CreateSecondaryTrack(particle, position, time, true);
160 totalEnergySecondaries_MeV += eKin_MeV;
161 }
162 }
163 }
164 }
165}
Definition of the GarfieldG4FastSimulationModel class.
virtual G4bool ModelTrigger(const G4FastTrack &)
virtual void DoIt(const G4FastTrack &, G4FastStep &)
virtual G4bool IsApplicable(const G4ParticleDefinition &)
bool GetCreateSecondariesInGeant4()
static GarfieldPhysics * GetInstance()
std::vector< GarfieldParticle * > * GetSecondaryParticles()
double GetEnergyDeposit_MeV()
bool FindParticleNameEnergy(std::string name, double ekin_keV)
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 FindParticleName(const std::string name)