Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ParticleChangeForLoss.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// G4ParticleChangeForLoss class implementation
27//
28// Author: Hisaya Kurashige, 23 March 1998
29// Revision: Vladimir Ivantchenko, 16 January 2004
30// --------------------------------------------------------------------
31
33#include "G4SystemOfUnits.hh"
34#include "G4Track.hh"
35#include "G4Step.hh"
36#include "G4DynamicParticle.hh"
38
39// --------------------------------------------------------------------
42 , lowEnergyLimit(1.0 * eV)
43{
45 debugFlag = false;
46}
47
48// --------------------------------------------------------------------
50{
51}
52
53// --------------------------------------------------------------------
55 const G4ParticleChangeForLoss& right)
56 : G4VParticleChange(right)
57{
58 currentTrack = right.currentTrack;
59 proposedKinEnergy = right.proposedKinEnergy;
60 lowEnergyLimit = right.lowEnergyLimit;
61 currentCharge = right.currentCharge;
62 proposedMomentumDirection = right.proposedMomentumDirection;
63}
64
65// --------------------------------------------------------------------
67 const G4ParticleChangeForLoss& right)
68{
69 if(this != &right)
70 {
72 {
73 for(G4int index = 0; index < theNumberOfSecondaries; ++index)
74 {
75 if((*theListOfSecondaries)[index])
76 delete(*theListOfSecondaries)[index];
77 }
78 }
82 for(G4int index = 0; index < theNumberOfSecondaries; ++index)
83 {
84 G4Track* newTrack = new G4Track(*((*right.theListOfSecondaries)[index]));
85 theListOfSecondaries->SetElement(index, newTrack);
86 }
87
94
95 currentTrack = right.currentTrack;
96 proposedKinEnergy = right.proposedKinEnergy;
97 currentCharge = right.currentCharge;
98 proposedMomentumDirection = right.proposedMomentumDirection;
99 }
100 return *this;
101}
102
103// --------------------------------------------------------------------
105{
106 // use base-class DumpInfo
108
109 G4int oldprc = G4cout.precision(3);
110 G4cout << " Charge (eplus) : " << std::setw(20)
111 << currentCharge / eplus << G4endl;
112 G4cout << " Kinetic Energy (MeV): " << std::setw(20)
113 << proposedKinEnergy / MeV << G4endl;
114 G4cout << " Momentum Direct - x : " << std::setw(20)
115 << proposedMomentumDirection.x() << G4endl;
116 G4cout << " Momentum Direct - y : " << std::setw(20)
117 << proposedMomentumDirection.y() << G4endl;
118 G4cout << " Momentum Direct - z : " << std::setw(20)
119 << proposedMomentumDirection.z() << G4endl;
120 G4cout.precision(oldprc);
121}
122
123// --------------------------------------------------------------------
125{
126 G4bool itsOK = true;
127 G4bool exitWithError = false;
128
129 G4double accuracy;
130
131 // Energy should not be lager than initial value
132 accuracy = (proposedKinEnergy - aTrack.GetKineticEnergy()) / MeV;
133 if(accuracy > accuracyForWarning)
134 {
135 itsOK = false;
136 exitWithError = (accuracy > accuracyForException);
137#ifdef G4VERBOSE
138 G4cout << "G4ParticleChangeForLoss::CheckIt: ";
139 G4cout << "KinEnergy become larger than the initial value!"
140 << " Difference: " << accuracy << "[MeV] " << G4endl;
142 << " E=" << aTrack.GetKineticEnergy() / MeV
143 << " pos=" << aTrack.GetPosition().x() / m << ", "
144 << aTrack.GetPosition().y() / m << ", "
145 << aTrack.GetPosition().z() / m << G4endl;
146#endif
147 }
148
149 // dump out information of this particle change
150#ifdef G4VERBOSE
151 if(!itsOK) { DumpInfo(); }
152#endif
153
154 // exit with error
155 if(exitWithError)
156 {
157 G4Exception("G4ParticleChangeForLoss::CheckIt()", "TRACK004",
158 EventMustBeAborted, "energy was illegal");
159 }
160
161 // correction
162 if(!itsOK)
163 {
164 proposedKinEnergy = aTrack.GetKineticEnergy();
165 }
166
167 itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
168 return itsOK;
169}
170
171// --------------------------------------------------------------------
173{
174 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
175 G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint();
176 G4Track* pTrack = pStep->GetTrack();
177
178 // accumulate change of the kinetic energy
179 G4double preKinEnergy = pPreStepPoint->GetKineticEnergy();
180 G4double kinEnergy =
181 pPostStepPoint->GetKineticEnergy() + (proposedKinEnergy - preKinEnergy);
182
183 // update kinetic energy and charge
184 if(kinEnergy < lowEnergyLimit)
185 {
186 theLocalEnergyDeposit += kinEnergy;
187 kinEnergy = 0.0;
188 pPostStepPoint->SetVelocity(0.0);
189 }
190 else
191 {
192 pPostStepPoint->SetCharge(currentCharge);
193 // calculate velocity
194 pTrack->SetKineticEnergy(kinEnergy);
195 pPostStepPoint->SetVelocity(pTrack->CalculateVelocity());
196 pTrack->SetKineticEnergy(preKinEnergy);
197 }
198 pPostStepPoint->SetKineticEnergy(kinEnergy);
199
201 {
202 pPostStepPoint->SetWeight(theParentWeight);
203 }
204
207 return pStep;
208}
209
210// --------------------------------------------------------------------
212{
213 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
214 G4Track* pTrack = pStep->GetTrack();
215
216 pPostStepPoint->SetCharge(currentCharge);
217 pPostStepPoint->SetMomentumDirection(proposedMomentumDirection);
218 pPostStepPoint->SetKineticEnergy(proposedKinEnergy);
219 pTrack->SetKineticEnergy(proposedKinEnergy);
220 if(proposedKinEnergy > 0.0)
221 {
222 pPostStepPoint->SetVelocity(pTrack->CalculateVelocity());
223 }
224 else
225 {
226 pPostStepPoint->SetVelocity(0.0);
227 }
228 pPostStepPoint->SetPolarization(proposedPolarization);
229
231 {
232 pPostStepPoint->SetWeight(theParentWeight);
233 }
234
237 return pStep;
238}
@ EventMustBeAborted
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
@ NormalCondition
G4FastVector< G4Track, G4TrackFastVectorSize > G4TrackFastVector
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
double z() const
double x() const
double y() const
void SetElement(G4int anIndex, Type *anElement)
Definition: G4FastVector.hh:72
G4Step * UpdateStepForPostStep(G4Step *Step)
virtual G4bool CheckIt(const G4Track &)
G4ParticleChangeForLoss & operator=(const G4ParticleChangeForLoss &right)
G4Step * UpdateStepForAlongStep(G4Step *Step)
const G4String & GetParticleName() const
void SetKineticEnergy(const G4double aValue)
void SetWeight(G4double aValue)
void SetCharge(G4double value)
void SetVelocity(G4double v)
G4double GetKineticEnergy() const
void SetMomentumDirection(const G4ThreeVector &aValue)
void SetPolarization(const G4ThreeVector &aValue)
Definition: G4Step.hh:62
G4Track * GetTrack() const
void AddNonIonizingEnergyDeposit(G4double value)
void AddTotalEnergyDeposit(G4double value)
G4StepPoint * GetPreStepPoint() const
G4StepPoint * GetPostStepPoint() const
const G4ThreeVector & GetPosition() const
G4ParticleDefinition * GetDefinition() const
G4double GetKineticEnergy() const
G4double CalculateVelocity() const
void SetKineticEnergy(const G4double aValue)
virtual G4bool CheckIt(const G4Track &)
static const G4double accuracyForException
G4TrackStatus theStatusChange
G4TrackFastVector * theListOfSecondaries
G4SteppingControl theSteppingControlFlag
static const G4double accuracyForWarning
G4double theNonIonizingEnergyDeposit
virtual void DumpInfo() const