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