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 { >> 300 if (verboseLevel>2) >> 301 { >> 302 G4cerr << "G4FastStep::G4FastStep()" << G4endl; >> 303 } >> 304 } >> 305 >> 306 G4FastStep::~G4FastStep() >> 307 { >> 308 if (verboseLevel>2) >> 309 { >> 310 G4cerr << "G4FastStep::~G4FastStep()" << G4endl; >> 311 } >> 312 } >> 313 >> 314 // copy and assignment operators are implemented as "shallow copy" >> 315 G4FastStep::G4FastStep(const G4FastStep &right) >> 316 : G4VParticleChange() >> 317 { >> 318 *this = right; >> 319 } >> 320 >> 321 >> 322 G4FastStep & G4FastStep::operator=(const G4FastStep &right) >> 323 { >> 324 if (this != &right) >> 325 { >> 326 G4VParticleChange::operator=(right); >> 327 theListOfSecondaries = right.theListOfSecondaries; >> 328 theSizeOftheListOfSecondaries = right.theSizeOftheListOfSecondaries; >> 329 theNumberOfSecondaries = right.theNumberOfSecondaries; >> 330 theStatusChange = right.theStatusChange; >> 331 theMomentumChange = right.theMomentumChange; >> 332 thePolarizationChange = right.thePolarizationChange; >> 333 thePositionChange = right.thePositionChange; >> 334 theProperTimeChange = right.theProperTimeChange; >> 335 theTimeChange = right.theTimeChange; >> 336 theEnergyChange = right.theEnergyChange; >> 337 theTrueStepLength = right.theTrueStepLength; >> 338 theLocalEnergyDeposit = right.theLocalEnergyDeposit; >> 339 theSteppingControlFlag = right.theSteppingControlFlag; >> 340 theWeightChange = right.theWeightChange; >> 341 fFastTrack = right.fFastTrack; >> 342 } >> 343 return *this; >> 344 } >> 345 >> 346 >> 347 >> 348 >> 349 >> 350 G4bool G4FastStep::operator==(const G4FastStep &right) const >> 351 { >> 352 return ((G4VParticleChange *)this == (G4VParticleChange *) &right); >> 353 } >> 354 >> 355 G4bool G4FastStep::operator!=(const G4FastStep &right) const >> 356 { >> 357 return ((G4VParticleChange *)this != (G4VParticleChange *) &right); 254 } 358 } 255 359 256 //-------------------------------------------- 360 //---------------------------------------------------------------- 257 // methods for updating G4Step << 361 // methods for updating G4Step 258 // 362 // 259 363 260 G4Step* G4FastStep::UpdateStepForPostStep(G4St 364 G4Step* G4FastStep::UpdateStepForPostStep(G4Step* pStep) 261 { << 365 { 262 // A physics process always calculates the f 366 // A physics process always calculates the final state of the particle 263 367 264 // Take note that the return type of GetMome 368 // Take note that the return type of GetMomentumChange is a 265 // pointer to G4ParticleMometum. Also it is << 369 // pointer to G4ParticleMometum. Also it is a normalized 266 // momentum vector. 370 // momentum vector. 267 371 268 // G4StepPoint* pPreStepPoint = pStep->Get << 372 // G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint(); 269 G4StepPoint* pPostStepPoint = pStep->GetPost << 373 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint(); 270 G4Track* aTrack = pStep->GetTrack(); << 374 G4Track* aTrack = pStep->GetTrack(); 271 // G4double mass = aTrack->GetDynamicPa 375 // G4double mass = aTrack->GetDynamicParticle()->GetMass(); 272 << 376 273 // update kinetic energy and momentum direct 377 // update kinetic energy and momentum direction 274 pPostStepPoint->SetMomentumDirection(theMome 378 pPostStepPoint->SetMomentumDirection(theMomentumChange); 275 pPostStepPoint->SetKineticEnergy(theEnergyCh << 379 pPostStepPoint->SetKineticEnergy( theEnergyChange ); 276 << 277 // update polarization << 278 pPostStepPoint->SetPolarization(thePolarizat << 279 380 >> 381 // update polarization >> 382 pPostStepPoint->SetPolarization( thePolarizationChange ); >> 383 280 // update position and time 384 // update position and time 281 pPostStepPoint->SetPosition(thePositionChang << 385 pPostStepPoint->SetPosition( thePositionChange ); 282 pPostStepPoint->SetGlobalTime(theTimeChange) << 386 pPostStepPoint->SetGlobalTime( theTimeChange ); 283 pPostStepPoint->AddLocalTime(theTimeChange - << 387 pPostStepPoint->AddLocalTime( theTimeChange 284 pPostStepPoint->SetProperTime(theProperTimeC << 388 - aTrack->GetGlobalTime()); >> 389 pPostStepPoint->SetProperTime( theProperTimeChange ); 285 390 286 // update weight 391 // update weight 287 pPostStepPoint->SetWeight(theWeightChange); << 392 pPostStepPoint->SetWeight( theWeightChange ); 288 393 289 if (debugFlag) CheckIt(*aTrack); 394 if (debugFlag) CheckIt(*aTrack); 290 395 291 // Update the G4Step specific attributes << 396 >> 397 // Update the G4Step specific attributes 292 return UpdateStepInfo(pStep); 398 return UpdateStepInfo(pStep); 293 } 399 } 294 400 295 G4Step* G4FastStep::UpdateStepForAtRest(G4Step 401 G4Step* G4FastStep::UpdateStepForAtRest(G4Step* pStep) 296 { << 402 { 297 // A physics process always calculates the f 403 // A physics process always calculates the final state of the particle 298 404 299 // G4StepPoint* pPreStepPoint = pStep->GetP << 405 // G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint(); 300 G4StepPoint* pPostStepPoint = pStep->GetPost << 406 G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint(); 301 G4Track* aTrack = pStep->GetTrack(); << 407 G4Track* aTrack = pStep->GetTrack(); 302 // G4double mass = aTrack->GetDynamicPar 408 // G4double mass = aTrack->GetDynamicParticle()->GetMass(); 303 << 409 304 // update kinetic energy and momentum direct 410 // update kinetic energy and momentum direction 305 pPostStepPoint->SetMomentumDirection(theMome 411 pPostStepPoint->SetMomentumDirection(theMomentumChange); 306 pPostStepPoint->SetKineticEnergy(theEnergyCh << 412 pPostStepPoint->SetKineticEnergy( theEnergyChange ); 307 413 308 // update polarization 414 // update polarization 309 pPostStepPoint->SetPolarization(thePolarizat << 415 pPostStepPoint->SetPolarization( thePolarizationChange ); 310 << 416 311 // update position and time 417 // update position and time 312 pPostStepPoint->SetPosition(thePositionChang << 418 pPostStepPoint->SetPosition( thePositionChange ); 313 pPostStepPoint->SetGlobalTime(theTimeChange) << 419 pPostStepPoint->SetGlobalTime( theTimeChange ); 314 pPostStepPoint->AddLocalTime(theTimeChange - << 420 pPostStepPoint->AddLocalTime( theTimeChange 315 pPostStepPoint->SetProperTime(theProperTimeC << 421 - aTrack->GetGlobalTime()); >> 422 pPostStepPoint->SetProperTime( theProperTimeChange ); 316 423 317 // update weight 424 // update weight 318 pPostStepPoint->SetWeight(theWeightChange); << 425 pPostStepPoint->SetWeight( theWeightChange ); 319 426 320 if (debugFlag) CheckIt(*aTrack); 427 if (debugFlag) CheckIt(*aTrack); 321 428 322 // Update the G4Step specific attributes << 429 // Update the G4Step specific attributes 323 return UpdateStepInfo(pStep); 430 return UpdateStepInfo(pStep); 324 } 431 } 325 432 326 //-------------------------------------------- 433 //---------------------------------------------------------------- 327 // methods for printing messages << 434 // methods for printing messages 328 // 435 // 329 436 330 void G4FastStep::DumpInfo() const 437 void G4FastStep::DumpInfo() const 331 { 438 { 332 // use base-class DumpInfo << 439 // use base-class DumpInfo 333 G4VParticleChange::DumpInfo(); 440 G4VParticleChange::DumpInfo(); 334 << 441 335 G4cout << " Position - x (mm) : " < << 442 G4cout << " Position - x (mm) : " << G4BestUnit( thePositionChange.x(), "Length" ) << G4endl; 336 << G4endl; << 443 G4cout << " Position - y (mm) : " << G4BestUnit( thePositionChange.y(), "Length" ) << G4endl; 337 G4cout << " Position - y (mm) : " < << 444 G4cout << " Position - z (mm) : " << G4BestUnit( thePositionChange.z(), "Length" ) << G4endl; 338 << G4endl; << 445 G4cout << " Time (ns) : " << G4BestUnit( theTimeChange, "Time" ) << G4endl; 339 G4cout << " Position - z (mm) : " < << 446 G4cout << " Proper Time (ns) : " << G4BestUnit( theProperTimeChange, "Time" ) << G4endl; 340 << G4endl; << 447 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 : " < 448 G4cout << " Momentum Direct - x : " << std::setw(20) << theMomentumChange.x() << G4endl; 345 G4cout << " Momentum Direct - y : " < 449 G4cout << " Momentum Direct - y : " << std::setw(20) << theMomentumChange.y() << G4endl; 346 G4cout << " Momentum Direct - z : " < 450 G4cout << " Momentum Direct - z : " << std::setw(20) << theMomentumChange.z() << G4endl; 347 G4cout.precision(olprc); 451 G4cout.precision(olprc); 348 G4cout << " Kinetic Energy (MeV): " < << 452 G4cout << " Kinetic Energy (MeV): " << G4BestUnit( theEnergyChange, "Energy" ) << G4endl; 349 G4cout.precision(3); 453 G4cout.precision(3); 350 G4cout << " Polarization - x : " < << 454 G4cout << " Polarization - x : " << std::setw(20) << thePolarizationChange.x() << G4endl; 351 << G4endl; << 455 G4cout << " Polarization - y : " << std::setw(20) << thePolarizationChange.y() << G4endl; 352 G4cout << " Polarization - y : " < << 456 G4cout << " Polarization - z : " << std::setw(20) << thePolarizationChange.z() << G4endl; 353 << G4endl; << 354 G4cout << " Polarization - z : " < << 355 << G4endl; << 356 G4cout.precision(olprc); 457 G4cout.precision(olprc); 357 } 458 } 358 459 359 G4bool G4FastStep::CheckIt(const G4Track& aTra 460 G4bool G4FastStep::CheckIt(const G4Track& aTrack) 360 { 461 { 361 // 462 // 362 // In the G4FastStep::CheckIt 463 // In the G4FastStep::CheckIt 363 // We only check a bit 464 // We only check a bit 364 // << 465 // 365 // If the user violates the energy, 466 // If the user violates the energy, 366 // We don't care, we agree. 467 // We don't care, we agree. 367 // 468 // 368 // But for theMomentumDirectionChange, 469 // But for theMomentumDirectionChange, 369 // We do pay attention. 470 // We do pay attention. 370 // And if too large is its range, 471 // And if too large is its range, 371 // We issue an Exception. 472 // We issue an Exception. 372 // 473 // 373 // 474 // 374 // It means, the G4FastStep::CheckIt issues 475 // It means, the G4FastStep::CheckIt issues an exception only for the 375 // theMomentumDirectionChange which should b 476 // theMomentumDirectionChange which should be an unit vector 376 // and it corrects it because it could cause 477 // and it corrects it because it could cause problems for the ulterior 377 // tracking.For the rest, only warning are i 478 // tracking.For the rest, only warning are issued. 378 479 379 G4bool itsOK = true; << 480 G4bool itsOK = true; 380 G4bool exitWithError = false; << 481 G4bool exitWithError = false; 381 G4double accuracy; << 482 G4double accuracy; 382 << 483 383 // Energy should not be larger than the init 484 // Energy should not be larger than the initial value 384 accuracy = (theEnergyChange - aTrack.GetKine << 485 accuracy = ( theEnergyChange - aTrack.GetKineticEnergy())/MeV; 385 if (accuracy > GetAccuracyForWarning()) { << 486 if (accuracy > GetAccuracyForWarning()) 386 G4ExceptionDescription ed; << 487 { 387 ed << "The energy becomes larger than the << 488 G4ExceptionDescription ed; 388 << G4endl; << 489 ed << "The energy becomes larger than the initial value, difference = " << accuracy << " MeV" << G4endl; 389 G4Exception("G4FastStep::CheckIt(const G4T << 490 G4Exception("G4FastStep::CheckIt(const G4Track& aTrack)", 390 itsOK = false; << 491 "FastSim006", 391 if (accuracy > GetAccuracyForException()) << 492 JustWarning, ed); 392 exitWithError = true; << 493 itsOK = false; >> 494 if (accuracy > GetAccuracyForException()) {exitWithError = true;} 393 } 495 } 394 } << 496 395 << 396 G4bool itsOKforMomentum = true; 497 G4bool itsOKforMomentum = true; 397 if (theEnergyChange > 0.) { << 498 if ( theEnergyChange >0.) 398 accuracy = std::abs(theMomentumChange.mag2 << 499 { 399 if (accuracy > GetAccuracyForWarning()) { << 500 accuracy = std::abs(theMomentumChange.mag2()-1.0); >> 501 if (accuracy > GetAccuracyForWarning()) >> 502 { >> 503 G4ExceptionDescription ed; >> 504 ed << "The Momentum Change is not a unit vector, difference = " << accuracy << G4endl; >> 505 G4Exception("G4FastStep::CheckIt(const G4Track& aTrack)", >> 506 "FastSim007", >> 507 JustWarning, ed); >> 508 itsOK = itsOKforMomentum = false; >> 509 if (accuracy > GetAccuracyForException()) {exitWithError = true;} >> 510 } >> 511 } >> 512 >> 513 accuracy = (aTrack.GetGlobalTime()- theTimeChange)/ns; >> 514 if (accuracy > GetAccuracyForWarning()) >> 515 { 400 G4ExceptionDescription ed; 516 G4ExceptionDescription ed; 401 ed << "The Momentum Change is not a unit << 517 ed << "The global time is getting backward, difference = " << accuracy << " ns" << G4endl; 402 G4Exception("G4FastStep::CheckIt(const G << 518 G4Exception("G4FastStep::CheckIt(const G4Track& aTrack)", 403 itsOK = itsOKforMomentum = false; << 519 "FastSim008", 404 if (accuracy > GetAccuracyForException() << 520 JustWarning, ed); 405 exitWithError = true; << 521 itsOK = false; 406 } << 407 } 522 } 408 } << 523 409 << 524 accuracy = (aTrack.GetProperTime() - theProperTimeChange )/ns; 410 accuracy = (aTrack.GetGlobalTime() - theTime << 525 if (accuracy > GetAccuracyForWarning()) 411 if (accuracy > GetAccuracyForWarning()) { << 526 { 412 G4ExceptionDescription ed; << 527 G4ExceptionDescription ed; 413 ed << "The global time is getting backward << 528 ed << "The proper time is getting backward, difference = " << accuracy << " ns" << G4endl; 414 G4Exception("G4FastStep::CheckIt(const G4T << 529 G4Exception("G4FastStep::CheckIt(const G4Track& aTrack)", 415 itsOK = false; << 530 "FastSim009", 416 } << 531 JustWarning, ed); 417 << 532 itsOK = false; 418 accuracy = (aTrack.GetProperTime() - theProp << 533 } 419 if (accuracy > GetAccuracyForWarning()) { << 534 420 G4ExceptionDescription ed; << 535 if (!itsOK) 421 ed << "The proper time is getting backward << 536 { 422 G4Exception("G4FastStep::CheckIt(const G4T << 537 G4cout << "ERROR - G4FastStep::CheckIt() " << G4endl; 423 itsOK = false; << 538 G4cout << " Pointer : " << this << G4endl ; 424 } << 539 DumpInfo(); 425 << 540 } 426 if (!itsOK) { << 541 427 G4cout << "ERROR - G4FastStep::CheckIt() " << 428 G4cout << " Pointer : " << this << << 429 DumpInfo(); << 430 } << 431 << 432 // Exit with error 542 // Exit with error 433 if (exitWithError) { << 543 if (exitWithError) 434 G4ExceptionDescription ed; << 544 { 435 ed << "An inaccuracy in G4FastStep is beyo << 545 G4ExceptionDescription ed; 436 G4Exception("G4FastStep::CheckIt(const G4T << 546 ed << "An inaccuracy in G4FastStep is beyond tolerance." << G4endl; 437 } << 547 G4Exception("G4FastStep::CheckIt(const G4Track& aTrack)", 438 << 548 "FastSim010", 439 // correction for Momentum only. << 549 FatalException, ed); >> 550 } >> 551 >> 552 //correction for Momentum only. 440 if (!itsOKforMomentum) { 553 if (!itsOKforMomentum) { 441 G4double vmag = theMomentumChange.mag(); 554 G4double vmag = theMomentumChange.mag(); 442 theMomentumChange = (1. / vmag) * theMomen << 555 theMomentumChange = (1./vmag)*theMomentumChange; 443 } 556 } 444 << 557 445 itsOK = (itsOK) && G4VParticleChange::CheckI << 558 itsOK = (itsOK) && G4VParticleChange::CheckIt(aTrack); 446 return itsOK; 559 return itsOK; 447 } 560 } 448 561