ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ParticleChangeForLoss.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ParticleChangeForLoss.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 // Implemented for the new scheme 23 Mar. 1998 H.Kurahige
34 // --------------------------------------------------------------
35 //
36 // Modified:
37 // 16.01.04 V.Ivanchenko update for model variant of energy loss
38 // 15.04.05 V.Ivanchenko inline update methods
39 // 28.08.06 V.Ivanchenko Add access to current track and polarizaion
40 //
41 // ------------------------------------------------------------
42 //
44 #include "G4SystemOfUnits.hh"
45 #include "G4Track.hh"
46 #include "G4Step.hh"
47 #include "G4DynamicParticle.hh"
48 #include "G4ExceptionSeverity.hh"
49 //#include "G4VelocityTable.hh"
50 
52  : G4VParticleChange(), currentTrack(0), proposedKinEnergy(0.),
53  lowEnergyLimit(1.0*eV), currentCharge(0.)
54 {
56  debugFlag = false;
57 #ifdef G4VERBOSE
58  if (verboseLevel>2) {
59  G4cout << "G4ParticleChangeForLoss::G4ParticleChangeForLoss() " << G4endl;
60  }
61 #endif
62 }
63 
65 {
66 #ifdef G4VERBOSE
67  if (verboseLevel>2) {
68  G4cout << "G4ParticleChangeForLoss::~G4ParticleChangeForLoss() " << G4endl;
69  }
70 #endif
71 }
72 
75  : G4VParticleChange(right)
76 {
77  if (verboseLevel>1) {
78  G4cout << "G4ParticleChangeForLoss:: copy constructor is called " << G4endl;
79  }
80  currentTrack = right.currentTrack;
85 }
86 
87 // assignment operator
90 {
91 #ifdef G4VERBOSE
92  if (verboseLevel>1) {
93  G4cout << "G4ParticleChangeForLoss:: assignment operator is called " << G4endl;
94  }
95 #endif
96 
97  if (this != &right) {
98  if (theNumberOfSecondaries>0) {
99 #ifdef G4VERBOSE
100  if (verboseLevel>0) {
101  G4cout << "G4ParticleChangeForLoss: assignment operator Warning ";
102  G4cout << "theListOfSecondaries is not empty ";
103  }
104 #endif
105  for (G4int index= 0; index<theNumberOfSecondaries; index++){
106  if ( (*theListOfSecondaries)[index] ) delete (*theListOfSecondaries)[index] ;
107  }
108  }
109  delete theListOfSecondaries;
112  for (G4int index = 0; index<theNumberOfSecondaries; index++){
113  G4Track* newTrack = new G4Track(*((*right.theListOfSecondaries)[index] ));
114  theListOfSecondaries->SetElement(index, newTrack); }
115 
122 
123  currentTrack = right.currentTrack;
127  }
128  return *this;
129 }
130 
131 //----------------------------------------------------------------
132 // methods for printing messages
133 //
134 
136 {
137 // use base-class DumpInfo
139 
140  G4int oldprc = G4cout.precision(3);
141  G4cout << " Charge (eplus) : "
142  << std::setw(20) << currentCharge/eplus
143  << G4endl;
144  G4cout << " Kinetic Energy (MeV): "
145  << std::setw(20) << proposedKinEnergy/MeV
146  << G4endl;
147  G4cout << " Momentum Direct - x : "
148  << std::setw(20) << proposedMomentumDirection.x()
149  << G4endl;
150  G4cout << " Momentum Direct - y : "
151  << std::setw(20) << proposedMomentumDirection.y()
152  << G4endl;
153  G4cout << " Momentum Direct - z : "
154  << std::setw(20) << proposedMomentumDirection.z()
155  << G4endl;
156  G4cout.precision(oldprc);
157 }
158 
160 {
161  G4bool itsOK = true;
162  G4bool exitWithError = false;
163 
164  G4double accuracy;
165 
166  // Energy should not be lager than initial value
167  accuracy = ( proposedKinEnergy - aTrack.GetKineticEnergy())/MeV;
168  if (accuracy > accuracyForWarning) {
169  itsOK = false;
170  exitWithError = (accuracy > accuracyForException);
171 #ifdef G4VERBOSE
172  G4cout << "G4ParticleChangeForLoss::CheckIt: ";
173  G4cout << "KinEnergy become larger than the initial value!"
174  << " Difference: " << accuracy << "[MeV] " <<G4endl;
175  G4cout << aTrack.GetDefinition()->GetParticleName()
176  << " E=" << aTrack.GetKineticEnergy()/MeV
177  << " pos=" << aTrack.GetPosition().x()/m
178  << ", " << aTrack.GetPosition().y()/m
179  << ", " << aTrack.GetPosition().z()/m
180  <<G4endl;
181 #endif
182  }
183 
184  // dump out information of this particle change
185 #ifdef G4VERBOSE
186  if (!itsOK) DumpInfo();
187 #endif
188 
189  // Exit with error
190  if (exitWithError) {
191  G4Exception("G4ParticleChangeForLoss::CheckIt",
192  "TRACK004", EventMustBeAborted,
193  "energy was illegal");
194  }
195 
196  //correction
197  if (!itsOK) {
199  }
200 
201  itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack);
202  return itsOK;
203 }
204 
205 //----------------------------------------------------------------
206 // methods for updating G4Step
207 //
208 
210 {
211  G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
212  G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint();
213  G4Track* pTrack = pStep->GetTrack();
214 
215  // accumulate change of the kinetic energy
216  G4double preKinEnergy = pPreStepPoint->GetKineticEnergy();
217  G4double kinEnergy = pPostStepPoint->GetKineticEnergy() +
218  (proposedKinEnergy - preKinEnergy);
219 
220  // update kinetic energy and charge
221  if (kinEnergy < lowEnergyLimit) {
222  theLocalEnergyDeposit += kinEnergy;
223  kinEnergy = 0.0;
224  pPostStepPoint->SetVelocity(0.0);
225  } else {
226  pPostStepPoint->SetCharge( currentCharge );
227  // calculate velocity
228  pTrack->SetKineticEnergy(kinEnergy);
229  pPostStepPoint->SetVelocity(pTrack->CalculateVelocity());
230  pTrack->SetKineticEnergy(preKinEnergy);
231  }
232  pPostStepPoint->SetKineticEnergy( kinEnergy );
233 
235  pPostStepPoint->SetWeight( theParentWeight );
236  }
237 
240  return pStep;
241 }
242 
244 {
245  G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
246  G4Track* pTrack = pStep->GetTrack();
247 
248  pPostStepPoint->SetCharge( currentCharge );
250  pPostStepPoint->SetKineticEnergy( proposedKinEnergy );
252  if(proposedKinEnergy > 0.0) {
253  pPostStepPoint->SetVelocity(pTrack->CalculateVelocity());
254  } else {
255  pPostStepPoint->SetVelocity(0.0);
256  }
257  pPostStepPoint->SetPolarization( proposedPolarization );
258 
260  pPostStepPoint->SetWeight( theParentWeight );
261  }
262 
265  return pStep;
266 }
267