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