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 // GEANT 4 class implementation file 28 // GEANT 4 class implementation file 29 // ------------------------------------------- 29 // ------------------------------------------------------------ 30 // 30 // 31 31 32 #include "G4ErrorPropagator.hh" 32 #include "G4ErrorPropagator.hh" 33 #include "G4ErrorPropagatorData.hh" 33 #include "G4ErrorPropagatorData.hh" 34 #include "G4ErrorFreeTrajState.hh" 34 #include "G4ErrorFreeTrajState.hh" 35 #include "G4ErrorSurfaceTrajState.hh" 35 #include "G4ErrorSurfaceTrajState.hh" 36 #include "G4ErrorGeomVolumeTarget.hh" 36 #include "G4ErrorGeomVolumeTarget.hh" 37 #include "G4ErrorSurfaceTarget.hh" 37 #include "G4ErrorSurfaceTarget.hh" 38 38 39 #include "G4SystemOfUnits.hh" 39 #include "G4SystemOfUnits.hh" 40 #include "G4DynamicParticle.hh" 40 #include "G4DynamicParticle.hh" 41 #include "G4Track.hh" 41 #include "G4Track.hh" 42 #include "G4SteppingManager.hh" 42 #include "G4SteppingManager.hh" 43 #include "G4EventManager.hh" 43 #include "G4EventManager.hh" 44 #include "G4TrackingManager.hh" 44 #include "G4TrackingManager.hh" 45 #include "G4ParticleTable.hh" 45 #include "G4ParticleTable.hh" 46 #include "G4StateManager.hh" 46 #include "G4StateManager.hh" 47 47 48 #include "G4VPhysicalVolume.hh" 48 #include "G4VPhysicalVolume.hh" 49 #include "G4PhysicalVolumeStore.hh" 49 #include "G4PhysicalVolumeStore.hh" 50 #include "G4UnitsTable.hh" 50 #include "G4UnitsTable.hh" 51 51 52 #include <vector> 52 #include <vector> 53 53 54 //-------------------------------------------- 54 //--------------------------------------------------------------------------- 55 G4ErrorPropagator::G4ErrorPropagator() 55 G4ErrorPropagator::G4ErrorPropagator() 56 : theStepLength(0.) 56 : theStepLength(0.) 57 , theInitialTrajState(0) 57 , theInitialTrajState(0) 58 , theStepN(0) 58 , theStepN(0) 59 , theG4Track(0) 59 , theG4Track(0) 60 { 60 { 61 verbose = G4ErrorPropagatorData::verbose(); 61 verbose = G4ErrorPropagatorData::verbose(); 62 #ifdef G4EVERBOSE 62 #ifdef G4EVERBOSE 63 if(verbose >= 5) 63 if(verbose >= 5) 64 { 64 { 65 G4cout << "G4ErrorPropagator " << this << 65 G4cout << "G4ErrorPropagator " << this << G4endl; 66 } 66 } 67 #endif 67 #endif 68 68 69 fpSteppingManager = G4EventManager::GetEvent 69 fpSteppingManager = G4EventManager::GetEventManager() 70 ->GetTrackingManager() 70 ->GetTrackingManager() 71 ->GetSteppingManager() 71 ->GetSteppingManager(); 72 thePropIsInitialized = false; 72 thePropIsInitialized = false; 73 } 73 } 74 74 75 //-------------------------------------------- 75 //----------------------------------------------------------------------- 76 G4int G4ErrorPropagator::Propagate(G4ErrorTraj 76 G4int G4ErrorPropagator::Propagate(G4ErrorTrajState* currentTS, 77 const G4Err 77 const G4ErrorTarget* target, 78 G4ErrorMode 78 G4ErrorMode mode) 79 { 79 { 80 // to start ierror is set to 1 (= OK) 80 // to start ierror is set to 1 (= OK) 81 // 81 // 82 G4int ierr = 1; 82 G4int ierr = 1; 83 83 84 G4ErrorPropagatorData* g4edata = 84 G4ErrorPropagatorData* g4edata = 85 G4ErrorPropagatorData::GetErrorPropagatorD 85 G4ErrorPropagatorData::GetErrorPropagatorData(); 86 86 87 //----- Do not propagate zero or too low ene 87 //----- Do not propagate zero or too low energy particles 88 // 88 // 89 if(currentTS->GetMomentum().mag() < 1.E-9 * 89 if(currentTS->GetMomentum().mag() < 1.E-9 * MeV) 90 { 90 { 91 std::ostringstream message; 91 std::ostringstream message; 92 message << "Energy too low to be propagate 92 message << "Energy too low to be propagated: " 93 << G4BestUnit(currentTS->GetMoment 93 << G4BestUnit(currentTS->GetMomentum().mag(), "Energy"); 94 G4Exception("G4ErrorPropagator::Propagate( 94 G4Exception("G4ErrorPropagator::Propagate()", "GEANT4e-Notification", 95 JustWarning, message); 95 JustWarning, message); 96 return -3; 96 return -3; 97 } 97 } 98 98 99 g4edata->SetMode(mode); 99 g4edata->SetMode(mode); 100 100 101 #ifdef G4EVERBOSE 101 #ifdef G4EVERBOSE 102 if(verbose >= 1) 102 if(verbose >= 1) 103 { 103 { 104 G4cout << " =====> starting GEANT4E tracki 104 G4cout << " =====> starting GEANT4E tracking for " 105 << currentTS->GetParticleType() 105 << currentTS->GetParticleType() 106 << " Forwards= " << g4edata->GetMo 106 << " Forwards= " << g4edata->GetMode() << G4endl; 107 } 107 } 108 if(verbose >= 1) 108 if(verbose >= 1) 109 { 109 { 110 G4cout << G4endl << "@@@@@@@@@@@@@@@@@@@@@ 110 G4cout << G4endl << "@@@@@@@@@@@@@@@@@@@@@@@@@ NEW STEP " << G4endl; 111 } 111 } 112 112 113 if(verbose >= 3) 113 if(verbose >= 3) 114 { 114 { 115 G4cout << " G4ErrorPropagator::Propagate i 115 G4cout << " G4ErrorPropagator::Propagate initialTS "; 116 G4cout << *currentTS << G4endl; 116 G4cout << *currentTS << G4endl; 117 target->Dump(G4String(" to target ")); 117 target->Dump(G4String(" to target ")); 118 } 118 } 119 #endif 119 #endif 120 120 121 g4edata->SetTarget(target); 121 g4edata->SetTarget(target); 122 122 123 //----- Create a track 123 //----- Create a track 124 // 124 // 125 if(theG4Track != 0) 125 if(theG4Track != 0) 126 { 126 { 127 delete theG4Track; 127 delete theG4Track; 128 } 128 } 129 theG4Track = InitG4Track(*currentTS); 129 theG4Track = InitG4Track(*currentTS); 130 130 131 //----- Create a G4ErrorFreeTrajState 131 //----- Create a G4ErrorFreeTrajState 132 // 132 // 133 G4ErrorFreeTrajState* currentTS_FREE = InitF 133 G4ErrorFreeTrajState* currentTS_FREE = InitFreeTrajState(currentTS); 134 134 135 //----- Track the particle 135 //----- Track the particle 136 // 136 // 137 ierr = MakeSteps(currentTS_FREE); 137 ierr = MakeSteps(currentTS_FREE); 138 138 139 //------ Tracking ended, check if target has 139 //------ Tracking ended, check if target has been reached 140 // if target not found 140 // if target not found 141 // 141 // 142 if(g4edata->GetState() != G4ErrorState_Stopp 142 if(g4edata->GetState() != G4ErrorState_StoppedAtTarget) 143 { 143 { 144 if(theG4Track->GetKineticEnergy() > 0.) 144 if(theG4Track->GetKineticEnergy() > 0.) 145 { 145 { 146 ierr = -ierr - 10; 146 ierr = -ierr - 10; 147 } 147 } 148 else 148 else 149 { 149 { 150 ierr = -ierr - 20; 150 ierr = -ierr - 20; 151 } 151 } 152 *currentTS = *currentTS_FREE; 152 *currentTS = *currentTS_FREE; 153 if(verbose >= 0) 153 if(verbose >= 0) 154 { 154 { 155 std::ostringstream message; 155 std::ostringstream message; 156 message << "Particle does not reach targ 156 message << "Particle does not reach target: " << *currentTS; 157 G4Exception("G4ErrorPropagator::Propagat 157 G4Exception("G4ErrorPropagator::Propagate()", "GEANT4e-Notification", 158 JustWarning, message); 158 JustWarning, message); 159 } 159 } 160 } 160 } 161 else 161 else 162 { 162 { 163 GetFinalTrajState(currentTS, currentTS_FRE 163 GetFinalTrajState(currentTS, currentTS_FREE, target); 164 } 164 } 165 165 166 #ifdef G4EVERBOSE 166 #ifdef G4EVERBOSE 167 if(verbose >= 1) 167 if(verbose >= 1) 168 { 168 { 169 G4cout << " G4ErrorPropagator: propagation 169 G4cout << " G4ErrorPropagator: propagation ended " << G4endl; 170 } 170 } 171 if(verbose >= 2) 171 if(verbose >= 2) 172 { 172 { 173 G4cout << " Current TrajState " << current 173 G4cout << " Current TrajState " << currentTS << G4endl; 174 } 174 } 175 #endif 175 #endif 176 176 177 // Inform end of tracking to physics process 177 // Inform end of tracking to physics processes 178 // 178 // 179 theG4Track->GetDefinition()->GetProcessManag 179 theG4Track->GetDefinition()->GetProcessManager()->EndTracking(); 180 180 181 InvokePostUserTrackingAction(theG4Track); 181 InvokePostUserTrackingAction(theG4Track); 182 182 183 // delete currentTS_FREE; 183 // delete currentTS_FREE; 184 184 185 return ierr; 185 return ierr; 186 } 186 } 187 187 188 //-------------------------------------------- 188 //----------------------------------------------------------------------- 189 G4int G4ErrorPropagator::PropagateOneStep(G4Er 189 G4int G4ErrorPropagator::PropagateOneStep(G4ErrorTrajState* currentTS) 190 { 190 { 191 G4ErrorPropagatorData* g4edata = 191 G4ErrorPropagatorData* g4edata = 192 G4ErrorPropagatorData::GetErrorPropagatorD 192 G4ErrorPropagatorData::GetErrorPropagatorData(); 193 193 194 if((g4edata->GetState() == G4ErrorState_PreI 194 if((g4edata->GetState() == G4ErrorState_PreInit) || 195 (G4StateManager::GetStateManager()->GetCu 195 (G4StateManager::GetStateManager()->GetCurrentState() != 196 G4State_GeomClosed)) 196 G4State_GeomClosed)) 197 { 197 { 198 std::ostringstream message; 198 std::ostringstream message; 199 message << "Called before initialization i 199 message << "Called before initialization is done for this track!"; 200 G4Exception("G4ErrorPropagator::PropagateO 200 G4Exception("G4ErrorPropagator::PropagateOneStep()", "InvalidCall", 201 FatalException, message, 201 FatalException, message, 202 "Please call G4ErrorPropagator 202 "Please call G4ErrorPropagatorManager::InitGeant4e()."); 203 } 203 } 204 204 205 // to start ierror is set to 0 (= OK) 205 // to start ierror is set to 0 (= OK) 206 // 206 // 207 G4int ierr = 0; 207 G4int ierr = 0; 208 208 209 //--- Do not propagate zero or too low energ 209 //--- Do not propagate zero or too low energy particles 210 // 210 // 211 if(currentTS->GetMomentum().mag() < 1.E-9 * 211 if(currentTS->GetMomentum().mag() < 1.E-9 * MeV) 212 { 212 { 213 std::ostringstream message; 213 std::ostringstream message; 214 message << "Energy too low to be propagate 214 message << "Energy too low to be propagated: " 215 << G4BestUnit(currentTS->GetMoment 215 << G4BestUnit(currentTS->GetMomentum().mag(), "Energy"); 216 G4Exception("G4ErrorPropagator::PropagateO 216 G4Exception("G4ErrorPropagator::PropagateOneStep()", "GEANT4e-Notification", 217 JustWarning, message); 217 JustWarning, message); 218 return -3; 218 return -3; 219 } 219 } 220 220 221 #ifdef G4EVERBOSE 221 #ifdef G4EVERBOSE 222 if(verbose >= 1) 222 if(verbose >= 1) 223 { 223 { 224 G4cout << " =====> starting GEANT4E tracki 224 G4cout << " =====> starting GEANT4E tracking for " 225 << currentTS->GetParticleType() 225 << currentTS->GetParticleType() 226 << " Forwards= " << g4edata->GetMo 226 << " Forwards= " << g4edata->GetMode() << G4endl; 227 } 227 } 228 if(verbose >= 3) 228 if(verbose >= 3) 229 { 229 { 230 G4cout << " G4ErrorPropagator::Propagate i 230 G4cout << " G4ErrorPropagator::Propagate initialTS "; 231 G4cout << *currentTS << G4endl; 231 G4cout << *currentTS << G4endl; 232 } 232 } 233 #endif 233 #endif 234 234 235 //----- If it is the first step, create a tr 235 //----- If it is the first step, create a track 236 // 236 // 237 if(theStepN == 0) 237 if(theStepN == 0) 238 { 238 { 239 if(theG4Track != 0) 239 if(theG4Track != 0) 240 { 240 { 241 delete theG4Track; 241 delete theG4Track; 242 } 242 } 243 theG4Track = InitG4Track(*currentTS); 243 theG4Track = InitG4Track(*currentTS); 244 } 244 } 245 // set to 0 by the initialization in G4Error 245 // set to 0 by the initialization in G4ErrorPropagatorManager 246 theStepN++; 246 theStepN++; 247 247 248 //----- Create a G4ErrorFreeTrajState 248 //----- Create a G4ErrorFreeTrajState 249 // 249 // 250 G4ErrorFreeTrajState* currentTS_FREE = InitF 250 G4ErrorFreeTrajState* currentTS_FREE = InitFreeTrajState(currentTS); 251 251 252 //----- Track the particle one step 252 //----- Track the particle one step 253 // 253 // 254 ierr = MakeOneStep(currentTS_FREE); 254 ierr = MakeOneStep(currentTS_FREE); 255 255 256 //----- Get the state on target 256 //----- Get the state on target 257 // 257 // 258 GetFinalTrajState(currentTS, currentTS_FREE, 258 GetFinalTrajState(currentTS, currentTS_FREE, g4edata->GetTarget()); 259 259 260 return ierr; 260 return ierr; 261 } 261 } 262 262 263 //-------------------------------------------- 263 //--------------------------------------------------------------------------- 264 G4Track* G4ErrorPropagator::InitG4Track(G4Erro 264 G4Track* G4ErrorPropagator::InitG4Track(G4ErrorTrajState& initialTS) 265 { 265 { 266 if(verbose >= 5) 266 if(verbose >= 5) 267 { 267 { 268 G4cout << "InitG4Track " << G4endl; 268 G4cout << "InitG4Track " << G4endl; 269 } 269 } 270 270 271 //----- Create Particle 271 //----- Create Particle 272 // 272 // 273 const G4String partType = initialTS.G 273 const G4String partType = initialTS.GetParticleType(); 274 G4ParticleTable* particleTable = G4ParticleT 274 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); 275 G4ParticleDefinition* particle = particleTab 275 G4ParticleDefinition* particle = particleTable->FindParticle(partType); 276 if(particle == 0) 276 if(particle == 0) 277 { 277 { 278 std::ostringstream message; 278 std::ostringstream message; 279 message << "Particle type not defined: " < 279 message << "Particle type not defined: " << partType; 280 G4Exception("G4ErrorPropagator::InitG4Trac 280 G4Exception("G4ErrorPropagator::InitG4Track()", "InvalidSetup", 281 FatalException, message); 281 FatalException, message); 282 } 282 } 283 283 284 G4DynamicParticle* DP = 284 G4DynamicParticle* DP = 285 new G4DynamicParticle(particle, initialTS. 285 new G4DynamicParticle(particle, initialTS.GetMomentum()); 286 286 287 DP->SetPolarization(0., 0., 0.); 287 DP->SetPolarization(0., 0., 0.); 288 288 289 // Set Charge 289 // Set Charge 290 // 290 // 291 if(particle->GetPDGCharge() < 0) 291 if(particle->GetPDGCharge() < 0) 292 { 292 { 293 DP->SetCharge(-eplus); 293 DP->SetCharge(-eplus); 294 } 294 } 295 else 295 else 296 { 296 { 297 DP->SetCharge(eplus); 297 DP->SetCharge(eplus); 298 } 298 } 299 299 300 //----- Create Track 300 //----- Create Track 301 // 301 // 302 theG4Track = new G4Track(DP, 0., initialTS.G 302 theG4Track = new G4Track(DP, 0., initialTS.GetPosition()); 303 theG4Track->SetParentID(0); 303 theG4Track->SetParentID(0); 304 304 305 #ifdef G4EVERBOSE 305 #ifdef G4EVERBOSE 306 if(verbose >= 3) 306 if(verbose >= 3) 307 { 307 { 308 G4cout << " G4ErrorPropagator new track of 308 G4cout << " G4ErrorPropagator new track of energy: " 309 << theG4Track->GetKineticEnergy() < 309 << theG4Track->GetKineticEnergy() << G4endl; 310 } 310 } 311 #endif 311 #endif 312 312 313 //---- Reproduce G4TrackingManager::ProcessO 313 //---- Reproduce G4TrackingManager::ProcessOneTrack initialization 314 InvokePreUserTrackingAction(theG4Track); 314 InvokePreUserTrackingAction(theG4Track); 315 315 316 if(fpSteppingManager == 0) 316 if(fpSteppingManager == 0) 317 { 317 { 318 G4Exception("G4ErrorPropagator::InitG4Trac 318 G4Exception("G4ErrorPropagator::InitG4Track()", "InvalidSetup", 319 FatalException, "G4SteppingMan 319 FatalException, "G4SteppingManager not initialized yet!"); 320 } 320 } 321 else 321 else 322 { 322 { 323 fpSteppingManager->SetInitialStep(theG4Tra 323 fpSteppingManager->SetInitialStep(theG4Track); 324 } 324 } 325 325 326 // Give SteppingManger the maximum number of 326 // Give SteppingManger the maximum number of processes 327 // 327 // 328 fpSteppingManager->GetProcessNumber(); 328 fpSteppingManager->GetProcessNumber(); 329 329 330 // Give track the pointer to the Step 330 // Give track the pointer to the Step 331 // 331 // 332 theG4Track->SetStep(fpSteppingManager->GetSt 332 theG4Track->SetStep(fpSteppingManager->GetStep()); 333 333 334 // Inform beginning of tracking to physics p 334 // Inform beginning of tracking to physics processes 335 // 335 // 336 theG4Track->GetDefinition()->GetProcessManag 336 theG4Track->GetDefinition()->GetProcessManager()->StartTracking(theG4Track); 337 337 338 initialTS.SetG4Track(theG4Track); 338 initialTS.SetG4Track(theG4Track); 339 339 340 return theG4Track; 340 return theG4Track; 341 } 341 } 342 342 343 //-------------------------------------------- 343 //----------------------------------------------------------------------- 344 G4int G4ErrorPropagator::MakeSteps(G4ErrorFree 344 G4int G4ErrorPropagator::MakeSteps(G4ErrorFreeTrajState* currentTS_FREE) 345 { 345 { 346 G4int ierr = 0; 346 G4int ierr = 0; 347 347 348 //----- Track the particle Step-by-Step whil 348 //----- Track the particle Step-by-Step while it is alive 349 // 349 // 350 theStepLength = 0.; 350 theStepLength = 0.; 351 351 352 while((theG4Track->GetTrackStatus() == fAliv 352 while((theG4Track->GetTrackStatus() == fAlive) || 353 (theG4Track->GetTrackStatus() == fStop 353 (theG4Track->GetTrackStatus() == fStopButAlive)) 354 { 354 { 355 ierr = MakeOneStep(currentTS_FREE); 355 ierr = MakeOneStep(currentTS_FREE); 356 if(ierr != 0) 356 if(ierr != 0) 357 { 357 { 358 break; 358 break; 359 } 359 } 360 360 361 //----- Check if last step for error propa 361 //----- Check if last step for error propagation 362 // 362 // 363 if(CheckIfLastStep(theG4Track)) 363 if(CheckIfLastStep(theG4Track)) 364 { 364 { 365 break; 365 break; 366 } 366 } 367 } // Loop checking, 06.08.2015, G.Cosmo 367 } // Loop checking, 06.08.2015, G.Cosmo 368 return ierr; 368 return ierr; 369 } 369 } 370 370 371 //-------------------------------------------- 371 //----------------------------------------------------------------------- 372 G4int G4ErrorPropagator::MakeOneStep(G4ErrorFr 372 G4int G4ErrorPropagator::MakeOneStep(G4ErrorFreeTrajState* currentTS_FREE) 373 { 373 { 374 G4ErrorPropagatorData* g4edata = 374 G4ErrorPropagatorData* g4edata = 375 G4ErrorPropagatorData::GetErrorPropagatorD 375 G4ErrorPropagatorData::GetErrorPropagatorData(); 376 G4int ierr = 0; 376 G4int ierr = 0; 377 377 378 //---------- Track one step 378 //---------- Track one step 379 #ifdef G4EVERBOSE 379 #ifdef G4EVERBOSE 380 if(verbose >= 2) 380 if(verbose >= 2) 381 { 381 { 382 G4cout << G4endl << "@@@@@@@@@@@@@@@@@@@@@ 382 G4cout << G4endl << "@@@@@@@@@@@@@@@@@@@@@@@@@ NEW STEP " << G4endl; 383 } 383 } 384 #endif 384 #endif 385 385 386 theG4Track->IncrementCurrentStepNumber(); 386 theG4Track->IncrementCurrentStepNumber(); 387 387 388 fpSteppingManager->Stepping(); 388 fpSteppingManager->Stepping(); 389 389 390 //---------- Check if Target has been reache 390 //---------- Check if Target has been reached (and then set G4ErrorState) 391 391 392 // G4ErrorPropagationNavigator limits the st 392 // G4ErrorPropagationNavigator limits the step if target is closer than 393 // boundary (but the winner process is alway 393 // boundary (but the winner process is always "Transportation": then 394 // error propagator will stop the track 394 // error propagator will stop the track 395 395 396 if(theG4Track->GetStep() 396 if(theG4Track->GetStep() 397 ->GetPostStepPoint() 397 ->GetPostStepPoint() 398 ->GetProcessDefinedStep() 398 ->GetProcessDefinedStep() 399 ->GetProcessName() == "Transportation") 399 ->GetProcessName() == "Transportation") 400 { 400 { 401 if(g4edata->GetState() == 401 if(g4edata->GetState() == 402 G4ErrorState(G4ErrorState_TargetCloserT 402 G4ErrorState(G4ErrorState_TargetCloserThanBoundary)) 403 { // target or step length reached 403 { // target or step length reached 404 404 405 #ifdef G4EVERBOSE 405 #ifdef G4EVERBOSE 406 if(verbose >= 5) 406 if(verbose >= 5) 407 { 407 { 408 G4cout << " transportation determined 408 G4cout << " transportation determined by geant4e " << G4endl; 409 } 409 } 410 #endif 410 #endif 411 g4edata->SetState(G4ErrorState_StoppedAt 411 g4edata->SetState(G4ErrorState_StoppedAtTarget); 412 } 412 } 413 else if(g4edata->GetTarget()->GetType() == 413 else if(g4edata->GetTarget()->GetType() == G4ErrorTarget_GeomVolume) 414 { 414 { 415 G4ErrorGeomVolumeTarget* target = 415 G4ErrorGeomVolumeTarget* target = 416 (G4ErrorGeomVolumeTarget*) (g4edata->G 416 (G4ErrorGeomVolumeTarget*) (g4edata->GetTarget()); 417 if(static_cast<G4ErrorGeomVolumeTarget*> 417 if(static_cast<G4ErrorGeomVolumeTarget*>(target)->TargetReached( 418 theG4Track->GetStep())) 418 theG4Track->GetStep())) 419 { 419 { 420 g4edata->SetState(G4ErrorState_Stopped 420 g4edata->SetState(G4ErrorState_StoppedAtTarget); 421 } 421 } 422 } 422 } 423 } 423 } 424 else if(theG4Track->GetStep() 424 else if(theG4Track->GetStep() 425 ->GetPostStepPoint() 425 ->GetPostStepPoint() 426 ->GetProcessDefinedStep() 426 ->GetProcessDefinedStep() 427 ->GetProcessName() == "G4ErrorTrac 427 ->GetProcessName() == "G4ErrorTrackLengthTarget") 428 { 428 { 429 g4edata->SetState(G4ErrorState_StoppedAtTa 429 g4edata->SetState(G4ErrorState_StoppedAtTarget); 430 } 430 } 431 431 432 //---------- Propagate error 432 //---------- Propagate error 433 433 434 #ifdef G4EVERBOSE 434 #ifdef G4EVERBOSE 435 if(verbose >= 2) 435 if(verbose >= 2) 436 { 436 { 437 G4cout << " propagating error " << *curren 437 G4cout << " propagating error " << *currentTS_FREE << G4endl; 438 } 438 } 439 #endif 439 #endif 440 const G4Track* cTrack = const_cast<G4Track*> 440 const G4Track* cTrack = const_cast<G4Track*>(theG4Track); 441 ierr = currentTS_FREE->Prop 441 ierr = currentTS_FREE->PropagateError(cTrack); 442 442 443 #ifdef G4EVERBOSE 443 #ifdef G4EVERBOSE 444 if(verbose >= 3) 444 if(verbose >= 3) 445 { 445 { 446 G4cout << " PropagateError returns " << ie 446 G4cout << " PropagateError returns " << ierr << G4endl; 447 } 447 } 448 #endif 448 #endif 449 449 450 currentTS_FREE->Update(cTrack); 450 currentTS_FREE->Update(cTrack); 451 451 452 theStepLength += theG4Track->GetStepLength() 452 theStepLength += theG4Track->GetStepLength(); 453 453 454 if(ierr != 0) 454 if(ierr != 0) 455 { 455 { 456 std::ostringstream message; 456 std::ostringstream message; 457 message << "Error returned: " << ierr; 457 message << "Error returned: " << ierr; 458 G4Exception("G4ErrorPropagator::MakeOneSte 458 G4Exception("G4ErrorPropagator::MakeOneStep()", "GEANT4e-Notification", 459 JustWarning, message, "Geant4 459 JustWarning, message, "Geant4 tracking will be stopped !"); 460 } 460 } 461 461 462 return ierr; 462 return ierr; 463 } 463 } 464 464 465 //-------------------------------------------- 465 //----------------------------------------------------------------------- 466 G4ErrorFreeTrajState* G4ErrorPropagator::InitF 466 G4ErrorFreeTrajState* G4ErrorPropagator::InitFreeTrajState( 467 G4ErrorTrajState* currentTS) 467 G4ErrorTrajState* currentTS) 468 { 468 { 469 G4ErrorFreeTrajState* currentTS_FREE = 0; 469 G4ErrorFreeTrajState* currentTS_FREE = 0; 470 470 471 //----- Transform the TrajState to Free coor 471 //----- Transform the TrajState to Free coordinates if it is OnSurface 472 // 472 // 473 if(currentTS->GetTSType() == G4eTS_OS) 473 if(currentTS->GetTSType() == G4eTS_OS) 474 { 474 { 475 G4ErrorSurfaceTrajState* tssd = 475 G4ErrorSurfaceTrajState* tssd = 476 static_cast<G4ErrorSurfaceTrajState*>(cu 476 static_cast<G4ErrorSurfaceTrajState*>(currentTS); 477 currentTS_FREE = new G4ErrorFreeTrajState( 477 currentTS_FREE = new G4ErrorFreeTrajState(*tssd); 478 } 478 } 479 else if(currentTS->GetTSType() == G4eTS_FREE 479 else if(currentTS->GetTSType() == G4eTS_FREE) 480 { 480 { 481 currentTS_FREE = static_cast<G4ErrorFreeTr 481 currentTS_FREE = static_cast<G4ErrorFreeTrajState*>(currentTS); 482 } 482 } 483 else 483 else 484 { 484 { 485 std::ostringstream message; 485 std::ostringstream message; 486 message << "Wrong trajectory state: " << c 486 message << "Wrong trajectory state: " << currentTS->GetTSType(); 487 G4Exception("G4ErrorPropagator::InitFreeTr 487 G4Exception("G4ErrorPropagator::InitFreeTrajState()", "InvalidState", 488 FatalException, message); 488 FatalException, message); 489 } 489 } 490 return currentTS_FREE; 490 return currentTS_FREE; 491 } 491 } 492 492 493 //-------------------------------------------- 493 //----------------------------------------------------------------------- 494 void G4ErrorPropagator::GetFinalTrajState(G4Er 494 void G4ErrorPropagator::GetFinalTrajState(G4ErrorTrajState* currentTS, 495 G4Er 495 G4ErrorFreeTrajState* currentTS_FREE, 496 cons 496 const G4ErrorTarget* target) 497 { 497 { 498 G4ErrorPropagatorData* g4edata = 498 G4ErrorPropagatorData* g4edata = 499 G4ErrorPropagatorData::GetErrorPropagatorD 499 G4ErrorPropagatorData::GetErrorPropagatorData(); 500 500 501 #ifdef G4EVERBOSE 501 #ifdef G4EVERBOSE 502 if(verbose >= 1) 502 if(verbose >= 1) 503 { 503 { 504 G4cout << " G4ErrorPropagator::Propagate: 504 G4cout << " G4ErrorPropagator::Propagate: final state " 505 << G4int(g4edata->GetState()) << " 505 << G4int(g4edata->GetState()) << " TSType " << currentTS->GetTSType() 506 << G4endl; 506 << G4endl; 507 } 507 } 508 #endif 508 #endif 509 509 510 if((currentTS->GetTSType() == G4eTS_FREE) || 510 if((currentTS->GetTSType() == G4eTS_FREE) || 511 (g4edata->GetState() != G4ErrorState_Stop 511 (g4edata->GetState() != G4ErrorState_StoppedAtTarget)) 512 { 512 { 513 currentTS = currentTS_FREE; 513 currentTS = currentTS_FREE; 514 } 514 } 515 else if(currentTS->GetTSType() == G4eTS_OS) 515 else if(currentTS->GetTSType() == G4eTS_OS) 516 { 516 { 517 if(target->GetType() == G4ErrorTarget_TrkL 517 if(target->GetType() == G4ErrorTarget_TrkL) 518 { 518 { 519 G4Exception("G4ErrorPropagator:GetFinalT 519 G4Exception("G4ErrorPropagator:GetFinalTrajState()", "InvalidSetup", 520 FatalException, 520 FatalException, 521 "Using a G4ErrorSurfaceTrajS 521 "Using a G4ErrorSurfaceTrajState with wrong target"); 522 } 522 } 523 const G4ErrorTanPlaneTarget* targetWTP = 523 const G4ErrorTanPlaneTarget* targetWTP = 524 static_cast<const G4ErrorTanPlaneTarget* 524 static_cast<const G4ErrorTanPlaneTarget*>(target); 525 *currentTS = G4ErrorSurfaceTrajState( 525 *currentTS = G4ErrorSurfaceTrajState( 526 *(static_cast<G4ErrorFreeTrajState*>(cur 526 *(static_cast<G4ErrorFreeTrajState*>(currentTS_FREE)), 527 targetWTP->GetTangentPlane(currentTS_FRE 527 targetWTP->GetTangentPlane(currentTS_FREE->GetPosition())); 528 #ifdef G4EVERBOSE 528 #ifdef G4EVERBOSE 529 if(verbose >= 1) 529 if(verbose >= 1) 530 { 530 { 531 G4cout << currentTS << " returning tssd 531 G4cout << currentTS << " returning tssd " << *currentTS << G4endl; 532 } 532 } 533 #endif 533 #endif 534 delete currentTS_FREE; 534 delete currentTS_FREE; 535 } 535 } 536 } 536 } 537 537 538 //-------------------------------------------- 538 //------------------------------------------------------------------------- 539 G4bool G4ErrorPropagator::CheckIfLastStep(G4Tr 539 G4bool G4ErrorPropagator::CheckIfLastStep(G4Track* aTrack) 540 { 540 { 541 G4bool lastG4eStep = false; 541 G4bool lastG4eStep = false; 542 G4ErrorPropagatorData* g4edata = 542 G4ErrorPropagatorData* g4edata = 543 G4ErrorPropagatorData::GetErrorPropagatorD 543 G4ErrorPropagatorData::GetErrorPropagatorData(); 544 544 545 #ifdef G4EVERBOSE 545 #ifdef G4EVERBOSE 546 if(verbose >= 4) 546 if(verbose >= 4) 547 { 547 { 548 G4cout << " G4ErrorPropagator::CheckIfLast 548 G4cout << " G4ErrorPropagator::CheckIfLastStep G4ErrorState= " 549 << G4int(g4edata->GetState()) << G4 549 << G4int(g4edata->GetState()) << G4endl; 550 } 550 } 551 #endif 551 #endif 552 552 553 //----- Check if this is the last step: trac 553 //----- Check if this is the last step: track has reached the target 554 // or the end of world 554 // or the end of world 555 // 555 // 556 if(g4edata->GetState() == G4ErrorState(G4Err 556 if(g4edata->GetState() == G4ErrorState(G4ErrorState_StoppedAtTarget)) 557 { 557 { 558 lastG4eStep = true; 558 lastG4eStep = true; 559 #ifdef G4EVERBOSE 559 #ifdef G4EVERBOSE 560 if(verbose >= 5) 560 if(verbose >= 5) 561 { 561 { 562 G4cout << " G4ErrorPropagator::CheckIfLa 562 G4cout << " G4ErrorPropagator::CheckIfLastStep " << lastG4eStep << " " 563 << G4int(g4edata->GetState()) << 563 << G4int(g4edata->GetState()) << G4endl; 564 } 564 } 565 #endif 565 #endif 566 } 566 } 567 else if(aTrack->GetNextVolume() == 0) 567 else if(aTrack->GetNextVolume() == 0) 568 { 568 { 569 //----- If particle is out of world, witho 569 //----- If particle is out of world, without finding the G4ErrorTarget, 570 // give a n error/warning 570 // give a n error/warning 571 // 571 // 572 lastG4eStep = true; 572 lastG4eStep = true; 573 if(verbose >= 1) 573 if(verbose >= 1) 574 { 574 { 575 std::ostringstream message; 575 std::ostringstream message; 576 message << "Track extrapolated until end 576 message << "Track extrapolated until end of World" << G4endl 577 << "without finding the defined 577 << "without finding the defined target."; 578 G4Exception("G4ErrorPropagator::CheckIfL 578 G4Exception("G4ErrorPropagator::CheckIfLastStep()", 579 "GEANT4e-Notification", Just 579 "GEANT4e-Notification", JustWarning, message); 580 } 580 } 581 } //----- not last step from G4e, but track 581 } //----- not last step from G4e, but track is stopped (energy exhausted) 582 else if(aTrack->GetTrackStatus() == fStopAnd 582 else if(aTrack->GetTrackStatus() == fStopAndKill) 583 { 583 { 584 if(verbose >= 1) 584 if(verbose >= 1) 585 { 585 { 586 std::ostringstream message; 586 std::ostringstream message; 587 message << "Track extrapolated until ene 587 message << "Track extrapolated until energy is exhausted" << G4endl 588 << "without finding the defined 588 << "without finding the defined target."; 589 G4Exception("G4ErrorPropagator::CheckIfL 589 G4Exception("G4ErrorPropagator::CheckIfLastStep()", 590 "GEANT4e-Notification", Just 590 "GEANT4e-Notification", JustWarning, message); 591 } 591 } 592 lastG4eStep = 1; 592 lastG4eStep = 1; 593 } 593 } 594 594 595 #ifdef G4EVERBOSE 595 #ifdef G4EVERBOSE 596 if(verbose >= 5) 596 if(verbose >= 5) 597 { 597 { 598 G4cout << " return CheckIfLastStep " << la 598 G4cout << " return CheckIfLastStep " << lastG4eStep << G4endl; 599 } 599 } 600 #endif 600 #endif 601 601 602 return lastG4eStep; 602 return lastG4eStep; 603 } 603 } 604 604 605 //-------------------------------------------- 605 //--------------------------------------------------------------------------- 606 void G4ErrorPropagator::InvokePreUserTrackingA 606 void G4ErrorPropagator::InvokePreUserTrackingAction(G4Track* fpTrack) 607 { 607 { 608 const G4UserTrackingAction* fpUserTrackingAc 608 const G4UserTrackingAction* fpUserTrackingAction = 609 G4EventManager::GetEventManager()->GetUser 609 G4EventManager::GetEventManager()->GetUserTrackingAction(); 610 if(fpUserTrackingAction != 0) 610 if(fpUserTrackingAction != 0) 611 { 611 { 612 const_cast<G4UserTrackingAction*>(fpUserTr 612 const_cast<G4UserTrackingAction*>(fpUserTrackingAction) 613 ->PreUserTrackingAction((fpTrack)); 613 ->PreUserTrackingAction((fpTrack)); 614 } 614 } 615 } 615 } 616 616 617 //-------------------------------------------- 617 //--------------------------------------------------------------------------- 618 void G4ErrorPropagator::InvokePostUserTracking 618 void G4ErrorPropagator::InvokePostUserTrackingAction(G4Track* fpTrack) 619 { 619 { 620 const G4UserTrackingAction* fpUserTrackingAc 620 const G4UserTrackingAction* fpUserTrackingAction = 621 G4EventManager::GetEventManager()->GetUser 621 G4EventManager::GetEventManager()->GetUserTrackingAction(); 622 if(fpUserTrackingAction != 0) 622 if(fpUserTrackingAction != 0) 623 { 623 { 624 const_cast<G4UserTrackingAction*>(fpUserTr 624 const_cast<G4UserTrackingAction*>(fpUserTrackingAction) 625 ->PostUserTrackingAction((fpTrack)); 625 ->PostUserTrackingAction((fpTrack)); 626 } 626 } 627 } 627 } 628 628