Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ParticleChangeForGamma.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// G4ParticleChangeForGamma class implementation
27//
28// Author: Hisaya Kurashige, 23 March 1998
29// Revision: Vladimir Ivantchenko, 15 April 2005
30// --------------------------------------------------------------------
31
33#include "G4SystemOfUnits.hh"
34#include "G4Track.hh"
35#include "G4Step.hh"
36#include "G4DynamicParticle.hh"
38
39// --------------------------------------------------------------------
42{
44 debugFlag = false;
45}
46
47// --------------------------------------------------------------------
49{
50}
51
52// --------------------------------------------------------------------
55 : G4VParticleChange(right)
56{
57 currentTrack = right.currentTrack;
58 proposedKinEnergy = right.proposedKinEnergy;
59 proposedMomentumDirection = right.proposedMomentumDirection;
60 proposedPolarization = right.proposedPolarization;
61}
62
63// --------------------------------------------------------------------
66{
67 if(this != &right)
68 {
70 {
71 for(G4int index = 0; index < theNumberOfSecondaries; ++index)
72 {
73 if((*theListOfSecondaries)[index])
74 delete(*theListOfSecondaries)[index];
75 }
76 }
80 for(G4int index = 0; index < theNumberOfSecondaries; ++index)
81 {
82 G4Track* newTrack = new G4Track(*((*right.theListOfSecondaries)[index]));
83 theListOfSecondaries->SetElement(index, newTrack);
84 }
85
90
91 currentTrack = right.currentTrack;
92 proposedKinEnergy = right.proposedKinEnergy;
93 proposedMomentumDirection = right.proposedMomentumDirection;
94 proposedPolarization = right.proposedPolarization;
95 }
96 return *this;
97}
98
99// --------------------------------------------------------------------
101{
102 // create track
103 G4Track* aTrack = new G4Track(aParticle, currentTrack->GetGlobalTime(),
104 currentTrack->GetPosition());
105
106 // touchable handle is copied to keep the pointer
107 aTrack->SetTouchableHandle(currentTrack->GetTouchableHandle());
108
109 // add a secondary
111}
112
113// --------------------------------------------------------------------
115{
117 pStep->SetStepLength(0.0);
118
120 {
122 }
123
124 return pStep;
125}
126
127// --------------------------------------------------------------------
129{
130 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
131 G4Track* pTrack = pStep->GetTrack();
132
133 pPostStepPoint->SetKineticEnergy(proposedKinEnergy);
134 pPostStepPoint->SetMomentumDirection(proposedMomentumDirection);
135 pPostStepPoint->SetPolarization(proposedPolarization);
136
137 // update velocity for scattering process and particles with mass
138 if(proposedKinEnergy > 0.0)
139 {
140 if(pTrack->GetParticleDefinition()->GetPDGMass() > 0.0)
141 {
142 pPostStepPoint->SetVelocity(pTrack->CalculateVelocity());
143 }
144 }
145
147 {
148 pPostStepPoint->SetWeight(theParentWeight);
149 }
150
153 return pStep;
154}
155
156// --------------------------------------------------------------------
158{
159 // use base-class DumpInfo
161
162 G4int oldprc = G4cout.precision(3);
163 G4cout << " Kinetic Energy (MeV): " << std::setw(20)
164 << proposedKinEnergy / MeV << G4endl;
165 G4cout << " Momentum Direction: " << std::setw(20)
166 << proposedMomentumDirection << G4endl;
167 G4cout << " Polarization: " << std::setw(20) << proposedPolarization
168 << G4endl;
169 G4cout.precision(oldprc);
170}
171
172// --------------------------------------------------------------------
174{
175 G4bool itsOK = true;
176 G4bool exitWithError = false;
177
178 G4double accuracy;
179
180 // Energy should not be lager than initial value
181 accuracy = (proposedKinEnergy - aTrack.GetKineticEnergy()) / MeV;
182 if(accuracy > accuracyForWarning)
183 {
184 itsOK = false;
185 exitWithError = (accuracy > accuracyForException);
186#ifdef G4VERBOSE
187 G4cout << "G4ParticleChangeForGamma::CheckIt: ";
188 G4cout << "KinEnergy become larger than the initial value!"
189 << " Difference: " << accuracy << "[MeV] " << G4endl;
191 << " E=" << aTrack.GetKineticEnergy() / MeV
192 << " pos=" << aTrack.GetPosition().x() / m << ", "
193 << aTrack.GetPosition().y() / m << ", "
194 << aTrack.GetPosition().z() / m << G4endl;
195#endif
196 }
197
198 // dump out information of this particle change
199#ifdef G4VERBOSE
200 if(!itsOK) { DumpInfo(); }
201#endif
202
203 // Exit with error
204 if(exitWithError)
205 {
206 G4Exception("G4ParticleChangeForGamma::CheckIt()", "TRACK004",
207 EventMustBeAborted, "energy was illegal");
208 }
209
210 // correction
211 if(!itsOK)
212 {
213 proposedKinEnergy = aTrack.GetKineticEnergy();
214 }
215
216 itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
217 return itsOK;
218}
@ 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 * UpdateStepForAtRest(G4Step *pStep)
G4ParticleChangeForGamma & operator=(const G4ParticleChangeForGamma &right)
virtual G4bool CheckIt(const G4Track &)
void AddSecondary(G4DynamicParticle *aParticle)
G4Step * UpdateStepForPostStep(G4Step *Step)
const G4String & GetParticleName() const
void SetKineticEnergy(const G4double aValue)
void SetWeight(G4double aValue)
void SetVelocity(G4double v)
void SetMomentumDirection(const G4ThreeVector &aValue)
void SetPolarization(const G4ThreeVector &aValue)
Definition: G4Step.hh:62
G4Track * GetTrack() const
void SetStepLength(G4double value)
void AddNonIonizingEnergyDeposit(G4double value)
void AddTotalEnergyDeposit(G4double value)
G4StepPoint * GetPostStepPoint() const
const G4ParticleDefinition * GetParticleDefinition() const
const G4ThreeVector & GetPosition() const
void SetTouchableHandle(const G4TouchableHandle &apValue)
G4double GetGlobalTime() const
G4ParticleDefinition * GetDefinition() const
const G4TouchableHandle & GetTouchableHandle() const
G4double GetKineticEnergy() const
G4double CalculateVelocity() const
virtual G4bool CheckIt(const G4Track &)
static const G4double accuracyForException
G4TrackStatus theStatusChange
G4TrackFastVector * theListOfSecondaries
G4SteppingControl theSteppingControlFlag
static const G4double accuracyForWarning
G4double theNonIonizingEnergyDeposit
void AddSecondary(G4Track *aSecondary)
virtual void DumpInfo() const