Geant4-11
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // Disable flag that is enabled in G4VParticleChange if G4VERBOSE.
46 debugFlag = false;
47}
48
49// --------------------------------------------------------------------
51{
52}
53
54// --------------------------------------------------------------------
56 const G4ParticleChangeForLoss& right)
57 : G4VParticleChange(right)
58{
64}
65
66// --------------------------------------------------------------------
68 const G4ParticleChangeForLoss& right)
69{
70 if(this != &right)
71 {
73 {
74 for(G4int index = 0; index < theNumberOfSecondaries; ++index)
75 {
76 if((*theListOfSecondaries)[index])
77 delete(*theListOfSecondaries)[index];
78 }
79 }
83 for(G4int index = 0; index < theNumberOfSecondaries; ++index)
84 {
85 G4Track* newTrack = new G4Track(*((*right.theListOfSecondaries)[index]));
86 theListOfSecondaries->SetElement(index, newTrack);
87 }
88
95
100 }
101 return *this;
102}
103
104// --------------------------------------------------------------------
106{
107 // use base-class DumpInfo
109
110 G4int oldprc = G4cout.precision(3);
111 G4cout << " Charge (eplus) : " << std::setw(20)
112 << currentCharge / eplus << G4endl;
113 G4cout << " Kinetic Energy (MeV): " << std::setw(20)
115 G4cout << " Momentum Direct - x : " << std::setw(20)
117 G4cout << " Momentum Direct - y : " << std::setw(20)
119 G4cout << " Momentum Direct - z : " << std::setw(20)
121 G4cout.precision(oldprc);
122}
123
124// --------------------------------------------------------------------
126{
127 G4bool itsOK = true;
128 G4bool exitWithError = false;
129
130 G4double accuracy;
131
132 // Energy should not be lager than initial value
133 accuracy = (proposedKinEnergy - aTrack.GetKineticEnergy()) / MeV;
134 if(accuracy > accuracyForWarning)
135 {
136 itsOK = false;
137 exitWithError = (accuracy > accuracyForException);
138#ifdef G4VERBOSE
139 G4cout << "G4ParticleChangeForLoss::CheckIt: ";
140 G4cout << "KinEnergy become larger than the initial value!"
141 << " Difference: " << accuracy << "[MeV] " << G4endl;
143 << " E=" << aTrack.GetKineticEnergy() / MeV
144 << " pos=" << aTrack.GetPosition().x() / m << ", "
145 << aTrack.GetPosition().y() / m << ", "
146 << aTrack.GetPosition().z() / m << G4endl;
147#endif
148 }
149
150 // dump out information of this particle change
151#ifdef G4VERBOSE
152 if(!itsOK) { DumpInfo(); }
153#endif
154
155 // exit with error
156 if(exitWithError)
157 {
158 G4Exception("G4ParticleChangeForLoss::CheckIt()", "TRACK004",
159 EventMustBeAborted, "energy was illegal");
160 }
161
162 // correction
163 if(!itsOK)
164 {
166 }
167
168 itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
169 return itsOK;
170}
171
172// --------------------------------------------------------------------
174{
175 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
176 G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint();
177 G4Track* pTrack = pStep->GetTrack();
178
179 // accumulate change of the kinetic energy
180 G4double preKinEnergy = pPreStepPoint->GetKineticEnergy();
181 G4double kinEnergy =
182 pPostStepPoint->GetKineticEnergy() + (proposedKinEnergy - preKinEnergy);
183
184 // update kinetic energy and charge
185 if(kinEnergy < lowEnergyLimit)
186 {
187 theLocalEnergyDeposit += kinEnergy;
188 kinEnergy = 0.0;
189 pPostStepPoint->SetVelocity(0.0);
190 }
191 else
192 {
193 pPostStepPoint->SetCharge(currentCharge);
194 // calculate velocity
195 pTrack->SetKineticEnergy(kinEnergy);
196 pPostStepPoint->SetVelocity(pTrack->CalculateVelocity());
197 pTrack->SetKineticEnergy(preKinEnergy);
198 }
199 pPostStepPoint->SetKineticEnergy(kinEnergy);
200
202 {
203 pPostStepPoint->SetWeight(theParentWeight);
204 }
205
208 return pStep;
209}
210
211// --------------------------------------------------------------------
213{
214 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
215 G4Track* pTrack = pStep->GetTrack();
216
217 pPostStepPoint->SetCharge(currentCharge);
219 pPostStepPoint->SetKineticEnergy(proposedKinEnergy);
221 if(proposedKinEnergy > 0.0)
222 {
223 pPostStepPoint->SetVelocity(pTrack->CalculateVelocity());
224 }
225 else
226 {
227 pPostStepPoint->SetVelocity(0.0);
228 }
229 pPostStepPoint->SetPolarization(proposedPolarization);
230
232 {
233 pPostStepPoint->SetWeight(theParentWeight);
234 }
235
238 return pStep;
239}
@ EventMustBeAborted
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
static constexpr double m
Definition: G4SIunits.hh:109
static constexpr double eplus
Definition: G4SIunits.hh:184
static constexpr double eV
Definition: G4SIunits.hh:201
static constexpr double MeV
Definition: G4SIunits.hh:200
@ 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