Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ParticleChangeForMSC.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// G4ParticleChangeForMSC 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{
43}
44
45// --------------------------------------------------------------------
47{
48}
49
50// --------------------------------------------------------------------
53 : G4VParticleChange(right)
54{
55 theMomentumDirection = right.theMomentumDirection;
56 thePosition = right.thePosition;
57}
58
59// --------------------------------------------------------------------
62{
63 if(this != &right)
64 {
72
73 theMomentumDirection = right.theMomentumDirection;
74 thePosition = right.thePosition;
75 }
76 return *this;
77}
78
79// --------------------------------------------------------------------
81{
82 // update the G4Step specific attributes
85
86 // multiple scattering calculates the final state of the particle
87 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
88
89 // update momentum direction
90 pPostStepPoint->SetMomentumDirection(theMomentumDirection);
91
92 // update position
93 pPostStepPoint->SetPosition(thePosition);
94 return pStep;
95}
96
97// --------------------------------------------------------------------
99{
100 // multiple scattering calculates the final state of the particle
101 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
102
103 // update momentum direction
104 pPostStepPoint->SetMomentumDirection(theMomentumDirection);
105
106 // update position
107 pPostStepPoint->SetPosition(thePosition);
108
109 // update the G4Step specific attributes
110 return pStep;
111}
112
113// --------------------------------------------------------------------
115{
116 // use base-class DumpInfo
118
119 G4int oldprc = G4cout.precision(3);
120 G4cout << " Position - x (mm) : " << std::setw(20)
121 << thePosition.x() / mm << G4endl;
122 G4cout << " Position - y (mm) : " << std::setw(20)
123 << thePosition.y() / mm << G4endl;
124 G4cout << " Position - z (mm) : " << std::setw(20)
125 << thePosition.z() / mm << G4endl;
126 G4cout << " Momentum Direct - x : " << std::setw(20)
127 << theMomentumDirection.x() << G4endl;
128 G4cout << " Momentum Direct - y : " << std::setw(20)
129 << theMomentumDirection.y() << G4endl;
130 G4cout << " Momentum Direct - z : " << std::setw(20)
131 << theMomentumDirection.z() << G4endl;
132 G4cout.precision(oldprc);
133}
134
135// --------------------------------------------------------------------
137{
138 G4bool itsOK = true;
139 G4bool exitWithError = false;
140
141 G4double accuracy;
142
143 // check
144
145 // MomentumDirection should be unit vector
146 accuracy = std::fabs(theMomentumDirection.mag2() - 1.0);
147 if(accuracy > accuracyForWarning)
148 {
149 itsOK = false;
150 exitWithError = (accuracy > accuracyForException);
151#ifdef G4VERBOSE
152 G4cout << " G4ParticleChangeForMSC::CheckIt : ";
153 G4cout << "the Momentum Change is not unit vector !!"
154 << " Difference: " << accuracy << G4endl;
156 << " E=" << aTrack.GetKineticEnergy() / MeV
157 << " pos=" << aTrack.GetPosition().x() / m << ", "
158 << aTrack.GetPosition().y() / m << ", "
159 << aTrack.GetPosition().z() / m << G4endl;
160#endif
161 }
162
163 // dump out information of this particle change
164#ifdef G4VERBOSE
165 if(!itsOK) { DumpInfo(); }
166#endif
167
168 // exit with error
169 if(exitWithError)
170 {
171 G4Exception("G4ParticleChangeForMSC::CheckIt()", "300", EventMustBeAborted,
172 "momentum direction was illegal");
173 }
174 // correction
175 if(!itsOK)
176 {
177 G4double vmag = theMomentumDirection.mag();
178 theMomentumDirection = (1. / vmag) * theMomentumDirection;
179 }
180
181 itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
182 return itsOK;
183}
@ EventMustBeAborted
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
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 mag2() const
double y() const
double mag() const
virtual G4Step * UpdateStepForPostStep(G4Step *Step)
virtual G4Step * UpdateStepForAlongStep(G4Step *Step)
G4ParticleChangeForMSC & operator=(const G4ParticleChangeForMSC &right)
virtual void DumpInfo() const
virtual G4bool CheckIt(const G4Track &)
const G4String & GetParticleName() const
void SetPosition(const G4ThreeVector &aValue)
void SetMomentumDirection(const G4ThreeVector &aValue)
Definition: G4Step.hh:62
G4Track * GetTrack() const
void SetStepLength(G4double value)
G4StepPoint * GetPostStepPoint() const
G4TrackStatus GetTrackStatus() const
const G4ThreeVector & GetPosition() const
G4ParticleDefinition * GetDefinition() const
G4double GetKineticEnergy() const
virtual G4bool CheckIt(const G4Track &)
static const G4double accuracyForException
G4TrackStatus theStatusChange
G4TrackFastVector * theListOfSecondaries
G4SteppingControl theSteppingControlFlag
static const G4double accuracyForWarning
virtual void DumpInfo() const