ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ParticleChangeForMSC.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ParticleChangeForMSC.cc
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 //
27 //
28 //
29 // --------------------------------------------------------------
30 // GEANT 4 class implementation file
31 //
32 //
33 //
34 // ------------------------------------------------------------
35 // Implemented for the new scheme 23 Mar. 1998 H.Kurahige
36 // Update for model variant of msc 16 Jan 2004 V.Ivanchenko
37 // --------------------------------------------------------------
38 
40 #include "G4SystemOfUnits.hh"
41 #include "G4Track.hh"
42 #include "G4Step.hh"
43 #include "G4DynamicParticle.hh"
44 #include "G4ExceptionSeverity.hh"
45 
48 {
49 #ifdef G4VERBOSE
50  if (verboseLevel>2) {
51  G4cout << "G4ParticleChangeForMSC::G4ParticleChangeForMSC() " << G4endl;
52  }
53 #endif
54 }
55 
57 {
58 #ifdef G4VERBOSE
59  if (verboseLevel>2) {
60  G4cout << "G4ParticleChangeForMSC::~G4ParticleChangeForMSC() " << G4endl;
61  }
62 #endif
63 }
64 
67  : G4VParticleChange(right)
68 {
69  if (verboseLevel>1) {
70  G4cout << "G4ParticleChangeForMSC:: copy constructor is called " << G4endl;
71  }
73  thePosition = right.thePosition;
74 }
75 
76 // assignment operator
79 {
80  if (verboseLevel>1) {
81  G4cout << "G4ParticleChangeForMSC:: assignment operator is called " << G4endl;
82  }
83  if (this != &right)
84  {
92 
94  thePosition = right.thePosition;
95  }
96  return *this;
97 }
98 
99 //----------------------------------------------------------------
100 // methods for updating G4Step
101 //
102 
104 {
105  // Update the G4Step specific attributes
108 
109  // Multiple scattering calculates the final state of the particle
110  G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
111 
112  // update momentum direction
114 
115  // update position
116  pPostStepPoint->SetPosition( thePosition );
117  return pStep;
118 }
119 
121 {
122  // Multiple scattering calculates the final state of the particle
123  G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
124 
125  // update momentum direction
127 
128  // update position
129  pPostStepPoint->SetPosition( thePosition );
130 
131  // Update the G4Step specific attributes
132  return pStep;
133 }
134 
135 
136 //----------------------------------------------------------------
137 // methods for printing messages
138 //
139 
141 {
142 // use base-class DumpInfo
144 
145  G4int oldprc = G4cout.precision(3);
146  G4cout << " Position - x (mm) : "
147  << std::setw(20) << thePosition.x()/mm
148  << G4endl;
149  G4cout << " Position - y (mm) : "
150  << std::setw(20) << thePosition.y()/mm
151  << G4endl;
152  G4cout << " Position - z (mm) : "
153  << std::setw(20) << thePosition.z()/mm
154  << G4endl;
155  G4cout << " Momentum Direct - x : "
156  << std::setw(20) << theMomentumDirection.x()
157  << G4endl;
158  G4cout << " Momentum Direct - y : "
159  << std::setw(20) << theMomentumDirection.y()
160  << G4endl;
161  G4cout << " Momentum Direct - z : "
162  << std::setw(20) << theMomentumDirection.z()
163  << G4endl;
164  G4cout.precision(oldprc);
165 }
166 
167 
169 {
170  G4bool itsOK = true;
171  G4bool exitWithError = false;
172 
173  G4double accuracy;
174 
175  // check
176 
177  // MomentumDirection should be unit vector
178  accuracy = std::fabs(theMomentumDirection.mag2()-1.0);
179  if (accuracy > accuracyForWarning) {
180  itsOK = false;
181  exitWithError = (accuracy > accuracyForException);
182 #ifdef G4VERBOSE
183  G4cout << " G4ParticleChangeForMSC::CheckIt : ";
184  G4cout << "the Momentum Change is not unit vector !!"
185  << " Difference: " << accuracy << G4endl;
186  G4cout << aTrack.GetDefinition()->GetParticleName()
187  << " E=" << aTrack.GetKineticEnergy()/MeV
188  << " pos=" << aTrack.GetPosition().x()/m
189  << ", " << aTrack.GetPosition().y()/m
190  << ", " << aTrack.GetPosition().z()/m
191  <<G4endl;
192 #endif
193  }
194 
195  // dump out information of this particle change
196 #ifdef G4VERBOSE
197  if (!itsOK) DumpInfo();
198 #endif
199 
200  // Exit with error
201  if (exitWithError) {
202  G4Exception("G4ParticleChangeForMSC::CheckIt",
203  "300",
205  "momentum direction was illegal");
206  }
207  //correction
208  if (!itsOK) {
211  }
212 
213  itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
214  return itsOK;
215 }
216 
217 
218 
219