Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 // 27 // 28 //-------------------------------------------- 28 //--------------------------------------------------------------- 29 // 29 // 30 // G4FastStep.cc 30 // G4FastStep.cc 31 // 31 // 32 // Description: 32 // Description: 33 // Encapsulates a G4ParticleChange and insu 33 // Encapsulates a G4ParticleChange and insure friendly interface 34 // methods to manage the primary/secondarie << 34 // methods to manage the primary/secondaries final state for 35 // Fast Simulation Models. 35 // Fast Simulation Models. 36 // 36 // 37 // History: 37 // History: 38 // Oct 97: Verderi && MoraDeFreitas - First 38 // Oct 97: Verderi && MoraDeFreitas - First Implementation. 39 // Apr 98: MoraDeFreitas - G4FastStep becom 39 // Apr 98: MoraDeFreitas - G4FastStep becomes the G4ParticleChange 40 // for the Fast Simulatio 40 // for the Fast Simulation Process. 41 // 41 // 42 //-------------------------------------------- 42 //--------------------------------------------------------------- 43 43 44 #include "G4FastStep.hh" 44 #include "G4FastStep.hh" 45 45 46 #include "G4DynamicParticle.hh" << 47 #include "G4Step.hh" << 48 #include "G4SystemOfUnits.hh" 46 #include "G4SystemOfUnits.hh" >> 47 #include "G4UnitsTable.hh" 49 #include "G4Track.hh" 48 #include "G4Track.hh" >> 49 #include "G4Step.hh" 50 #include "G4TrackFastVector.hh" 50 #include "G4TrackFastVector.hh" 51 #include "G4UnitsTable.hh" << 51 #include "G4DynamicParticle.hh" 52 52 53 void G4FastStep::Initialize(const G4FastTrack& 53 void G4FastStep::Initialize(const G4FastTrack& fastTrack) 54 { 54 { 55 // keeps the fastTrack reference 55 // keeps the fastTrack reference 56 fFastTrack = &fastTrack; << 56 fFastTrack=&fastTrack; 57 57 58 // currentTrack will be used to Initialize t 58 // currentTrack will be used to Initialize the other data members 59 const G4Track& currentTrack = *(fFastTrack-> 59 const G4Track& currentTrack = *(fFastTrack->GetPrimaryTrack()); 60 60 61 // use base class's method at first 61 // use base class's method at first 62 G4VParticleChange::Initialize(currentTrack); 62 G4VParticleChange::Initialize(currentTrack); 63 63 64 // set Energy/Momentum etc. equal to those o 64 // set Energy/Momentum etc. equal to those of the parent particle 65 const G4DynamicParticle* pParticle = current << 65 const G4DynamicParticle* pParticle = currentTrack.GetDynamicParticle(); 66 theEnergyChange = pParticle->GetKineticEnerg << 66 theEnergyChange = pParticle->GetKineticEnergy(); 67 theMomentumChange = pParticle->GetMomentumDi << 67 theMomentumChange = pParticle->GetMomentumDirection(); 68 thePolarizationChange = pParticle->GetPolari << 68 thePolarizationChange = pParticle->GetPolarization(); 69 theProperTimeChange = pParticle->GetProperTi << 69 theProperTimeChange = pParticle->GetProperTime(); 70 70 71 // set Position/Time etc. equal to those of 71 // set Position/Time etc. equal to those of the parent track 72 thePositionChange = currentTrack.GetPosition << 72 thePositionChange = currentTrack.GetPosition(); 73 theTimeChange = currentTrack.GetGlobalTime() << 73 theTimeChange = currentTrack.GetGlobalTime(); 74 74 75 // switch off stepping hit invokation by def 75 // switch off stepping hit invokation by default: 76 theSteppingControlFlag = AvoidHitInvocation; 76 theSteppingControlFlag = AvoidHitInvocation; 77 77 78 // event biasing weigth: 78 // event biasing weigth: 79 theWeightChange = currentTrack.GetWeight(); << 79 theWeightChange = currentTrack.GetWeight(); 80 } << 80 } 81 81 82 //---------------------------------------- 82 //---------------------------------------- 83 // -- Set the StopAndKilled signal 83 // -- Set the StopAndKilled signal 84 // -- and put kinetic energy to 0.0. in the 84 // -- and put kinetic energy to 0.0. in the 85 // -- G4ParticleChange. 85 // -- G4ParticleChange. 86 //---------------------------------------- 86 //---------------------------------------- 87 void G4FastStep::KillPrimaryTrack() 87 void G4FastStep::KillPrimaryTrack() 88 { 88 { 89 ProposePrimaryTrackFinalKineticEnergy(0.); << 89 SetPrimaryTrackFinalKineticEnergy(0.) ; 90 ProposeTrackStatus(fStopAndKill); << 90 ProposeTrackStatus(fStopAndKill) ; 91 } 91 } 92 92 93 //-------------------- 93 //-------------------- 94 // 94 // 95 //-------------------- 95 //-------------------- 96 void G4FastStep::ProposePrimaryTrackFinalPosit << 96 void 97 << 97 G4FastStep:: >> 98 ProposePrimaryTrackFinalPosition(const G4ThreeVector &position, >> 99 G4bool localCoordinates) 98 { 100 { 99 // Compute the position coordinate in global 101 // Compute the position coordinate in global 100 // reference system if needed ... 102 // reference system if needed ... 101 G4ThreeVector globalPosition = position; 103 G4ThreeVector globalPosition = position; 102 if (localCoordinates) << 104 if (localCoordinates) 103 globalPosition = fFastTrack->GetInverseAff << 105 globalPosition = fFastTrack->GetInverseAffineTransformation()-> >> 106 TransformPoint(position); 104 // ...and feed the globalPosition: 107 // ...and feed the globalPosition: 105 thePositionChange = globalPosition; 108 thePositionChange = globalPosition; 106 } 109 } 107 110 108 void G4FastStep::SetPrimaryTrackFinalPosition( << 111 void 109 << 112 G4FastStep:: >> 113 SetPrimaryTrackFinalPosition(const G4ThreeVector &position, >> 114 G4bool localCoordinates) 110 { 115 { 111 ProposePrimaryTrackFinalPosition(position, l 116 ProposePrimaryTrackFinalPosition(position, localCoordinates); 112 } 117 } 113 118 114 //-------------------- 119 //-------------------- 115 // 120 // 116 //-------------------- 121 //-------------------- 117 void G4FastStep::ProposePrimaryTrackFinalMomen << 122 void 118 << 123 G4FastStep:: >> 124 ProposePrimaryTrackFinalMomentumDirection(const G4ThreeVector &momentum, >> 125 G4bool localCoordinates) 119 { 126 { 120 // Compute the momentum in global reference 127 // Compute the momentum in global reference 121 // system if needed ... 128 // system if needed ... 122 G4ThreeVector globalMomentum = momentum; 129 G4ThreeVector globalMomentum = momentum; 123 if (localCoordinates) 130 if (localCoordinates) 124 globalMomentum = fFastTrack->GetInverseAff << 131 globalMomentum = fFastTrack->GetInverseAffineTransformation()-> >> 132 TransformAxis(momentum); 125 // ...and feed the globalMomentum (ensuring 133 // ...and feed the globalMomentum (ensuring unitarity) 126 SetMomentumChange(globalMomentum.unit()); 134 SetMomentumChange(globalMomentum.unit()); 127 } 135 } 128 136 129 void G4FastStep::SetPrimaryTrackFinalMomentum( << 137 void 130 << 138 G4FastStep:: >> 139 SetPrimaryTrackFinalMomentum(const G4ThreeVector &momentum, >> 140 G4bool localCoordinates) 131 { 141 { 132 ProposePrimaryTrackFinalMomentumDirection(mo 142 ProposePrimaryTrackFinalMomentumDirection(momentum, localCoordinates); 133 } 143 } 134 144 135 //-------------------- 145 //-------------------- 136 // 146 // 137 //-------------------- 147 //-------------------- 138 void G4FastStep::ProposePrimaryTrackFinalKinet << 148 void 139 << 149 G4FastStep:: 140 << 150 ProposePrimaryTrackFinalKineticEnergyAndDirection(G4double kineticEnergy, >> 151 const G4ThreeVector &direction, >> 152 G4bool localCoordinates) 141 { 153 { 142 // Compute global direction if needed... 154 // Compute global direction if needed... 143 G4ThreeVector globalDirection = direction; 155 G4ThreeVector globalDirection = direction; 144 if (localCoordinates) 156 if (localCoordinates) 145 globalDirection = fFastTrack->GetInverseAf << 157 globalDirection =fFastTrack->GetInverseAffineTransformation()-> >> 158 TransformAxis(direction); 146 // ...and feed the globalMomentum (ensuring 159 // ...and feed the globalMomentum (ensuring unitarity) 147 SetMomentumChange(globalDirection.unit()); 160 SetMomentumChange(globalDirection.unit()); 148 ProposePrimaryTrackFinalKineticEnergy(kineti << 161 SetPrimaryTrackFinalKineticEnergy(kineticEnergy); 149 } 162 } 150 163 151 void G4FastStep::SetPrimaryTrackFinalKineticEn << 164 void 152 << 165 G4FastStep:: 153 << 166 SetPrimaryTrackFinalKineticEnergyAndDirection(G4double kineticEnergy, >> 167 const G4ThreeVector &direction, >> 168 G4bool localCoordinates) 154 { 169 { 155 ProposePrimaryTrackFinalKineticEnergyAndDire 170 ProposePrimaryTrackFinalKineticEnergyAndDirection(kineticEnergy, direction, localCoordinates); 156 } 171 } 157 172 158 //-------------------- 173 //-------------------- 159 // 174 // 160 //-------------------- 175 //-------------------- 161 void G4FastStep::ProposePrimaryTrackFinalPolar << 176 void 162 << 177 G4FastStep:: >> 178 ProposePrimaryTrackFinalPolarization(const G4ThreeVector &polarization, >> 179 G4bool localCoordinates) 163 { 180 { 164 // Compute polarization in global system if 181 // Compute polarization in global system if needed: 165 G4ThreeVector globalPolarization(polarizatio 182 G4ThreeVector globalPolarization(polarization); 166 if (localCoordinates) 183 if (localCoordinates) 167 globalPolarization = << 184 globalPolarization = fFastTrack->GetInverseAffineTransformation()-> 168 fFastTrack->GetInverseAffineTransformati << 185 TransformAxis(globalPolarization); 169 // Feed the particle globalPolarization: 186 // Feed the particle globalPolarization: 170 thePolarizationChange = globalPolarization; 187 thePolarizationChange = globalPolarization; 171 } 188 } 172 189 173 void G4FastStep::SetPrimaryTrackFinalPolarizat << 190 void 174 << 191 G4FastStep:: >> 192 SetPrimaryTrackFinalPolarization(const G4ThreeVector &polarization, >> 193 G4bool localCoordinates) 175 { 194 { 176 ProposePrimaryTrackFinalPolarization(polariz 195 ProposePrimaryTrackFinalPolarization(polarization, localCoordinates); 177 } 196 } 178 197 179 //-------------------- 198 //-------------------- 180 // 199 // 181 //-------------------- 200 //-------------------- 182 G4Track* G4FastStep::CreateSecondaryTrack(cons << 201 G4Track* G4FastStep:: 183 G4Th << 202 CreateSecondaryTrack(const G4DynamicParticle& dynamics, 184 G4do << 203 G4ThreeVector polarization, >> 204 G4ThreeVector position, >> 205 G4double time, >> 206 G4bool localCoordinates ) 185 { 207 { 186 G4DynamicParticle dummyDynamics(dynamics); 208 G4DynamicParticle dummyDynamics(dynamics); 187 << 209 188 // ----------------------------------------- 210 // ------------------------------------------ 189 // Add the polarization to the dummyDynamics 211 // Add the polarization to the dummyDynamics: 190 // ----------------------------------------- 212 // ------------------------------------------ 191 dummyDynamics.SetPolarization(polarization.x << 213 dummyDynamics.SetPolarization(polarization.x(), 192 << 214 polarization.y(), >> 215 polarization.z()); >> 216 193 return CreateSecondaryTrack(dummyDynamics, p 217 return CreateSecondaryTrack(dummyDynamics, position, time, localCoordinates); 194 } 218 } 195 219 196 //-------------------- 220 //-------------------- 197 // 221 // 198 //-------------------- 222 //-------------------- 199 G4Track* G4FastStep::CreateSecondaryTrack(cons << 223 G4Track* G4FastStep:: 200 G4do << 224 CreateSecondaryTrack(const G4DynamicParticle& dynamics, >> 225 G4ThreeVector position, >> 226 G4double time, >> 227 G4bool localCoordinates ) 201 { 228 { 202 // ---------------------------------------- 229 // ---------------------------------------- 203 // Quantities in global coordinates system. 230 // Quantities in global coordinates system. 204 // << 231 // 205 // The allocated globalDynamics is deleted 232 // The allocated globalDynamics is deleted 206 // by the destructor of the G4Track. 233 // by the destructor of the G4Track. 207 // ---------------------------------------- 234 // ---------------------------------------- 208 auto globalDynamics = new G4DynamicParticle( << 235 G4DynamicParticle* globalDynamics = >> 236 new G4DynamicParticle(dynamics); 209 G4ThreeVector globalPosition(position); 237 G4ThreeVector globalPosition(position); 210 << 238 211 // ----------------------------------- 239 // ----------------------------------- 212 // Convert to global system if needed: 240 // Convert to global system if needed: 213 // ----------------------------------- 241 // ----------------------------------- 214 if (localCoordinates) { << 242 if (localCoordinates) 215 // -- Momentum Direction: << 243 { 216 globalDynamics->SetMomentumDirection( << 244 // -- Momentum Direction: 217 fFastTrack->GetInverseAffineTransformati << 245 globalDynamics->SetMomentumDirection(fFastTrack-> 218 globalDynamics->GetMomentumDirection() << 246 GetInverseAffineTransformation()-> 219 // -- Polarization: << 247 TransformAxis(globalDynamics-> 220 G4ThreeVector globalPolarization; << 248 GetMomentumDirection())); 221 globalPolarization = fFastTrack->GetInvers << 249 // -- Polarization: 222 globalDynamics->GetPolarization()); << 250 G4ThreeVector globalPolarization; 223 globalDynamics->SetPolarization(globalPola << 251 globalPolarization = fFastTrack->GetInverseAffineTransformation()-> 224 globalPola << 252 TransformAxis(globalDynamics->GetPolarization()); 225 << 253 globalDynamics->SetPolarization( 226 // -- Position: << 254 globalPolarization.x(), 227 globalPosition = fFastTrack->GetInverseAff << 255 globalPolarization.y(), 228 } << 256 globalPolarization.z() 229 << 257 ); >> 258 >> 259 // -- Position: >> 260 globalPosition = fFastTrack->GetInverseAffineTransformation()-> >> 261 TransformPoint(globalPosition); >> 262 } >> 263 230 //------------------------------------- 264 //------------------------------------- 231 // Create the G4Track of the secondary: 265 // Create the G4Track of the secondary: 232 //------------------------------------- 266 //------------------------------------- 233 auto secondary = new G4Track(globalDynamics, << 267 G4Track* secondary = new G4Track( 234 << 268 globalDynamics, >> 269 time, >> 270 globalPosition >> 271 ); >> 272 235 //------------------------------- 273 //------------------------------- 236 // and feed the changes: 274 // and feed the changes: 237 //------------------------------- 275 //------------------------------- 238 AddSecondary(secondary); 276 AddSecondary(secondary); 239 << 277 240 //-------------------------------------- 278 //-------------------------------------- 241 // returns the pointer on the secondary: 279 // returns the pointer on the secondary: 242 //-------------------------------------- 280 //-------------------------------------- 243 return secondary; 281 return secondary; 244 } 282 } 245 283 246 // G4FastStep should never be Initialized in t 284 // G4FastStep should never be Initialized in this way 247 // but we must define it to avoid warnings. 285 // but we must define it to avoid warnings. 248 void G4FastStep::Initialize(const G4Track&) 286 void G4FastStep::Initialize(const G4Track&) 249 { 287 { 250 G4ExceptionDescription tellWhatIsWrong; << 288 G4ExceptionDescription tellWhatIsWrong; 251 tellWhatIsWrong << "G4FastStep can be initia << 289 tellWhatIsWrong << "G4FastStep can be initialised only through G4FastTrack." 252 G4Exception("G4FastStep::Initialize(const G4 << 290 << G4endl; 253 tellWhatIsWrong); << 291 G4Exception("G4FastStep::Initialize(const G4Track&)", >> 292 "FastSim005", >> 293 FatalException, >> 294 tellWhatIsWrong); >> 295 } >> 296 >> 297 G4FastStep::G4FastStep() >> 298 : G4VParticleChange(), >> 299 theEnergyChange ( 0.0 ), >> 300 theTimeChange ( 0.0 ), >> 301 theProperTimeChange( 0.0 ), >> 302 fFastTrack ( nullptr ), >> 303 theWeightChange ( 0.0 ) >> 304 { >> 305 if (verboseLevel>2) >> 306 { >> 307 G4cerr << "G4FastStep::G4FastStep()" << G4endl; >> 308 } >> 309 } >> 310 >> 311 G4FastStep::~G4FastStep() >> 312 { >> 313 if (verboseLevel>2) >> 314 { >> 315 G4cerr << "G4FastStep::~G4FastStep()" << G4endl; >> 316 } >> 317 } >> 318 >> 319 // copy and assignment operators are implemented as "shallow copy" >> 320 G4FastStep::G4FastStep(const G4FastStep &right) >> 321 : G4VParticleChange() >> 322 { >> 323 *this = right; >> 324 } >> 325 >> 326 >> 327 G4FastStep & G4FastStep::operator=(const G4FastStep &right) >> 328 { >> 329 if (this != &right) >> 330 { >> 331 G4VParticleChange::operator=(right); >> 332 theListOfSecondaries = right.theListOfSecondaries; >> 333 theSizeOftheListOfSecondaries = right.theSizeOftheListOfSecondaries; >> 334 theNumberOfSecondaries = right.theNumberOfSecondaries; >> 335 theStatusChange = right.theStatusChange; >> 336 theMomentumChange = right.theMomentumChange; >> 337 thePolarizationChange = right.thePolarizationChange; >> 338 thePositionChange = right.thePositionChange; >> 339 theProperTimeChange = right.theProperTimeChange; >> 340 theTimeChange = right.theTimeChange; >> 341 theEnergyChange = right.theEnergyChange; >> 342 theTrueStepLength = right.theTrueStepLength; >> 343 theLocalEnergyDeposit = right.theLocalEnergyDeposit; >> 344 theSteppingControlFlag = right.theSteppingControlFlag; >> 345 theWeightChange = right.theWeightChange; >> 346 fFastTrack = right.fFastTrack; >> 347 } >> 348 return *this; >> 349 } >> 350 >> 351 >> 352 >> 353 >> 354 >> 355 G4bool G4FastStep::operator==(const G4FastStep &right) const >> 356 { >> 357 return ((G4VParticleChange *)this == (G4VParticleChange *) &right); >> 358 } >> 359 >> 360 G4bool G4FastStep::operator!=(const G4FastStep &right) const >> 361 { >> 362 return ((G4VParticleChange *)this != (G4VParticleChange *) &right); 254 } 363 } 255 364 256 //-------------------------------------------- 365 //---------------------------------------------------------------- 257 // methods for updating G4Step << 366 // methods for updating G4Step 258 // 367 // 259 368 260 G4Step* G4FastStep::UpdateStepForPostStep(G4St 369 G4Step* G4FastStep::UpdateStepForPostStep(G4Step* pStep) 261 { << 370 { 262 // A physics process always calculates the f 371 // A physics process always calculates the final state of the particle 263 372 264 // Take note that the return type of GetMome 373 // Take note that the return type of GetMomentumChange is a 265 // pointer to G4ParticleMometum. Also it is << 374 // pointer to G4ParticleMometum. Also it is a normalized 266 // momentum vector. 375 // momentum vector. 267 376 268 // G4StepPoint* pPreStepPoint = pStep->Get << 377 // G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint(); 269 G4StepPoint* pPostStepPoint = pStep->GetPost << 378 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint(); 270 G4Track* aTrack = pStep->GetTrack(); << 379 G4Track* aTrack = pStep->GetTrack(); 271 // G4double mass = aTrack->GetDynamicPa 380 // G4double mass = aTrack->GetDynamicParticle()->GetMass(); 272 << 381 273 // update kinetic energy and momentum direct 382 // update kinetic energy and momentum direction 274 pPostStepPoint->SetMomentumDirection(theMome 383 pPostStepPoint->SetMomentumDirection(theMomentumChange); 275 pPostStepPoint->SetKineticEnergy(theEnergyCh << 384 pPostStepPoint->SetKineticEnergy( theEnergyChange ); 276 << 277 // update polarization << 278 pPostStepPoint->SetPolarization(thePolarizat << 279 385 >> 386 // update polarization >> 387 pPostStepPoint->SetPolarization( thePolarizationChange ); >> 388 280 // update position and time 389 // update position and time 281 pPostStepPoint->SetPosition(thePositionChang << 390 pPostStepPoint->SetPosition( thePositionChange ); 282 pPostStepPoint->SetGlobalTime(theTimeChange) << 391 pPostStepPoint->SetGlobalTime( theTimeChange ); 283 pPostStepPoint->AddLocalTime(theTimeChange - << 392 pPostStepPoint->AddLocalTime( theTimeChange 284 pPostStepPoint->SetProperTime(theProperTimeC << 393 - aTrack->GetGlobalTime()); >> 394 pPostStepPoint->SetProperTime( theProperTimeChange ); 285 395 286 // update weight 396 // update weight 287 pPostStepPoint->SetWeight(theWeightChange); << 397 pPostStepPoint->SetWeight( theWeightChange ); 288 398 289 if (debugFlag) CheckIt(*aTrack); 399 if (debugFlag) CheckIt(*aTrack); 290 400 291 // Update the G4Step specific attributes << 401 >> 402 // Update the G4Step specific attributes 292 return UpdateStepInfo(pStep); 403 return UpdateStepInfo(pStep); 293 } 404 } 294 405 295 G4Step* G4FastStep::UpdateStepForAtRest(G4Step 406 G4Step* G4FastStep::UpdateStepForAtRest(G4Step* pStep) 296 { << 407 { 297 // A physics process always calculates the f 408 // A physics process always calculates the final state of the particle 298 409 299 // G4StepPoint* pPreStepPoint = pStep->GetP << 410 // G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint(); 300 G4StepPoint* pPostStepPoint = pStep->GetPost << 411 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint(); 301 G4Track* aTrack = pStep->GetTrack(); << 412 G4Track* aTrack = pStep->GetTrack(); 302 // G4double mass = aTrack->GetDynamicPar 413 // G4double mass = aTrack->GetDynamicParticle()->GetMass(); 303 << 414 304 // update kinetic energy and momentum direct 415 // update kinetic energy and momentum direction 305 pPostStepPoint->SetMomentumDirection(theMome 416 pPostStepPoint->SetMomentumDirection(theMomentumChange); 306 pPostStepPoint->SetKineticEnergy(theEnergyCh << 417 pPostStepPoint->SetKineticEnergy( theEnergyChange ); 307 418 308 // update polarization 419 // update polarization 309 pPostStepPoint->SetPolarization(thePolarizat << 420 pPostStepPoint->SetPolarization( thePolarizationChange ); 310 << 421 311 // update position and time 422 // update position and time 312 pPostStepPoint->SetPosition(thePositionChang << 423 pPostStepPoint->SetPosition( thePositionChange ); 313 pPostStepPoint->SetGlobalTime(theTimeChange) << 424 pPostStepPoint->SetGlobalTime( theTimeChange ); 314 pPostStepPoint->AddLocalTime(theTimeChange - << 425 pPostStepPoint->AddLocalTime( theTimeChange 315 pPostStepPoint->SetProperTime(theProperTimeC << 426 - aTrack->GetGlobalTime()); >> 427 pPostStepPoint->SetProperTime( theProperTimeChange ); 316 428 317 // update weight 429 // update weight 318 pPostStepPoint->SetWeight(theWeightChange); << 430 pPostStepPoint->SetWeight( theWeightChange ); 319 431 320 if (debugFlag) CheckIt(*aTrack); 432 if (debugFlag) CheckIt(*aTrack); 321 433 322 // Update the G4Step specific attributes << 434 // Update the G4Step specific attributes 323 return UpdateStepInfo(pStep); 435 return UpdateStepInfo(pStep); 324 } 436 } 325 437 326 //-------------------------------------------- 438 //---------------------------------------------------------------- 327 // methods for printing messages << 439 // methods for printing messages 328 // 440 // 329 441 330 void G4FastStep::DumpInfo() const 442 void G4FastStep::DumpInfo() const 331 { 443 { 332 // use base-class DumpInfo << 444 // use base-class DumpInfo 333 G4VParticleChange::DumpInfo(); 445 G4VParticleChange::DumpInfo(); 334 << 446 335 G4cout << " Position - x (mm) : " < << 447 G4cout << " Position - x (mm) : " << G4BestUnit( thePositionChange.x(), "Length" ) << G4endl; 336 << G4endl; << 448 G4cout << " Position - y (mm) : " << G4BestUnit( thePositionChange.y(), "Length" ) << G4endl; 337 G4cout << " Position - y (mm) : " < << 449 G4cout << " Position - z (mm) : " << G4BestUnit( thePositionChange.z(), "Length" ) << G4endl; 338 << G4endl; << 450 G4cout << " Time (ns) : " << G4BestUnit( theTimeChange, "Time" ) << G4endl; 339 G4cout << " Position - z (mm) : " < << 451 G4cout << " Proper Time (ns) : " << G4BestUnit( theProperTimeChange, "Time" ) << G4endl; 340 << G4endl; << 452 G4int olprc = G4cout.precision(3); 341 G4cout << " Time (ns) : " < << 342 G4cout << " Proper Time (ns) : " < << 343 G4long olprc = G4cout.precision(3); << 344 G4cout << " Momentum Direct - x : " < 453 G4cout << " Momentum Direct - x : " << std::setw(20) << theMomentumChange.x() << G4endl; 345 G4cout << " Momentum Direct - y : " < 454 G4cout << " Momentum Direct - y : " << std::setw(20) << theMomentumChange.y() << G4endl; 346 G4cout << " Momentum Direct - z : " < 455 G4cout << " Momentum Direct - z : " << std::setw(20) << theMomentumChange.z() << G4endl; 347 G4cout.precision(olprc); 456 G4cout.precision(olprc); 348 G4cout << " Kinetic Energy (MeV): " < << 457 G4cout << " Kinetic Energy (MeV): " << G4BestUnit( theEnergyChange, "Energy" ) << G4endl; 349 G4cout.precision(3); 458 G4cout.precision(3); 350 G4cout << " Polarization - x : " < << 459 G4cout << " Polarization - x : " << std::setw(20) << thePolarizationChange.x() << G4endl; 351 << G4endl; << 460 G4cout << " Polarization - y : " << std::setw(20) << thePolarizationChange.y() << G4endl; 352 G4cout << " Polarization - y : " < << 461 G4cout << " Polarization - z : " << std::setw(20) << thePolarizationChange.z() << G4endl; 353 << G4endl; << 354 G4cout << " Polarization - z : " < << 355 << G4endl; << 356 G4cout.precision(olprc); 462 G4cout.precision(olprc); 357 } 463 } 358 464 359 G4bool G4FastStep::CheckIt(const G4Track& aTra 465 G4bool G4FastStep::CheckIt(const G4Track& aTrack) 360 { 466 { 361 // 467 // 362 // In the G4FastStep::CheckIt 468 // In the G4FastStep::CheckIt 363 // We only check a bit 469 // We only check a bit 364 // << 470 // 365 // If the user violates the energy, 471 // If the user violates the energy, 366 // We don't care, we agree. 472 // We don't care, we agree. 367 // 473 // 368 // But for theMomentumDirectionChange, 474 // But for theMomentumDirectionChange, 369 // We do pay attention. 475 // We do pay attention. 370 // And if too large is its range, 476 // And if too large is its range, 371 // We issue an Exception. 477 // We issue an Exception. 372 // 478 // 373 // 479 // 374 // It means, the G4FastStep::CheckIt issues 480 // It means, the G4FastStep::CheckIt issues an exception only for the 375 // theMomentumDirectionChange which should b 481 // theMomentumDirectionChange which should be an unit vector 376 // and it corrects it because it could cause 482 // and it corrects it because it could cause problems for the ulterior 377 // tracking.For the rest, only warning are i 483 // tracking.For the rest, only warning are issued. 378 484 379 G4bool itsOK = true; << 485 G4bool itsOK = true; 380 G4bool exitWithError = false; << 486 G4bool exitWithError = false; 381 G4double accuracy; << 487 G4double accuracy; 382 << 488 383 // Energy should not be larger than the init 489 // Energy should not be larger than the initial value 384 accuracy = (theEnergyChange - aTrack.GetKine << 490 accuracy = ( theEnergyChange - aTrack.GetKineticEnergy())/MeV; 385 if (accuracy > GetAccuracyForWarning()) { << 491 if (accuracy > GetAccuracyForWarning()) 386 G4ExceptionDescription ed; << 492 { 387 ed << "The energy becomes larger than the << 493 G4ExceptionDescription ed; 388 << G4endl; << 494 ed << "The energy becomes larger than the initial value, difference = " << accuracy << " MeV" << G4endl; 389 G4Exception("G4FastStep::CheckIt(const G4T << 495 G4Exception("G4FastStep::CheckIt(const G4Track& aTrack)", 390 itsOK = false; << 496 "FastSim006", 391 if (accuracy > GetAccuracyForException()) << 497 JustWarning, ed); 392 exitWithError = true; << 498 itsOK = false; >> 499 if (accuracy > GetAccuracyForException()) {exitWithError = true;} 393 } 500 } 394 } << 501 395 << 396 G4bool itsOKforMomentum = true; 502 G4bool itsOKforMomentum = true; 397 if (theEnergyChange > 0.) { << 503 if ( theEnergyChange >0.) 398 accuracy = std::abs(theMomentumChange.mag2 << 504 { 399 if (accuracy > GetAccuracyForWarning()) { << 505 accuracy = std::abs(theMomentumChange.mag2()-1.0); >> 506 if (accuracy > GetAccuracyForWarning()) >> 507 { >> 508 G4ExceptionDescription ed; >> 509 ed << "The Momentum Change is not a unit vector, difference = " << accuracy << G4endl; >> 510 G4Exception("G4FastStep::CheckIt(const G4Track& aTrack)", >> 511 "FastSim007", >> 512 JustWarning, ed); >> 513 itsOK = itsOKforMomentum = false; >> 514 if (accuracy > GetAccuracyForException()) {exitWithError = true;} >> 515 } >> 516 } >> 517 >> 518 accuracy = (aTrack.GetGlobalTime()- theTimeChange)/ns; >> 519 if (accuracy > GetAccuracyForWarning()) >> 520 { 400 G4ExceptionDescription ed; 521 G4ExceptionDescription ed; 401 ed << "The Momentum Change is not a unit << 522 ed << "The global time is getting backward, difference = " << accuracy << " ns" << G4endl; 402 G4Exception("G4FastStep::CheckIt(const G << 523 G4Exception("G4FastStep::CheckIt(const G4Track& aTrack)", 403 itsOK = itsOKforMomentum = false; << 524 "FastSim008", 404 if (accuracy > GetAccuracyForException() << 525 JustWarning, ed); 405 exitWithError = true; << 526 itsOK = false; 406 } << 407 } 527 } 408 } << 528 409 << 529 accuracy = (aTrack.GetProperTime() - theProperTimeChange )/ns; 410 accuracy = (aTrack.GetGlobalTime() - theTime << 530 if (accuracy > GetAccuracyForWarning()) 411 if (accuracy > GetAccuracyForWarning()) { << 531 { 412 G4ExceptionDescription ed; << 532 G4ExceptionDescription ed; 413 ed << "The global time is getting backward << 533 ed << "The proper time is getting backward, difference = " << accuracy << " ns" << G4endl; 414 G4Exception("G4FastStep::CheckIt(const G4T << 534 G4Exception("G4FastStep::CheckIt(const G4Track& aTrack)", 415 itsOK = false; << 535 "FastSim009", 416 } << 536 JustWarning, ed); 417 << 537 itsOK = false; 418 accuracy = (aTrack.GetProperTime() - theProp << 538 } 419 if (accuracy > GetAccuracyForWarning()) { << 539 420 G4ExceptionDescription ed; << 540 if (!itsOK) 421 ed << "The proper time is getting backward << 541 { 422 G4Exception("G4FastStep::CheckIt(const G4T << 542 G4cout << "ERROR - G4FastStep::CheckIt() " << G4endl; 423 itsOK = false; << 543 G4cout << " Pointer : " << this << G4endl ; 424 } << 544 DumpInfo(); 425 << 545 } 426 if (!itsOK) { << 546 427 G4cout << "ERROR - G4FastStep::CheckIt() " << 428 G4cout << " Pointer : " << this << << 429 DumpInfo(); << 430 } << 431 << 432 // Exit with error 547 // Exit with error 433 if (exitWithError) { << 548 if (exitWithError) 434 G4ExceptionDescription ed; << 549 { 435 ed << "An inaccuracy in G4FastStep is beyo << 550 G4ExceptionDescription ed; 436 G4Exception("G4FastStep::CheckIt(const G4T << 551 ed << "An inaccuracy in G4FastStep is beyond tolerance." << G4endl; 437 } << 552 G4Exception("G4FastStep::CheckIt(const G4Track& aTrack)", 438 << 553 "FastSim010", 439 // correction for Momentum only. << 554 FatalException, ed); >> 555 } >> 556 >> 557 //correction for Momentum only. 440 if (!itsOKforMomentum) { 558 if (!itsOKforMomentum) { 441 G4double vmag = theMomentumChange.mag(); 559 G4double vmag = theMomentumChange.mag(); 442 theMomentumChange = (1. / vmag) * theMomen << 560 theMomentumChange = (1./vmag)*theMomentumChange; 443 } 561 } 444 << 562 445 itsOK = (itsOK) && G4VParticleChange::CheckI << 563 itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack); 446 return itsOK; 564 return itsOK; 447 } 565 } 448 566