57 fSecondary = fStep->NewSecondaryVector();
58 fPreStepPoint = fStep->GetPreStepPoint();
59 fPostStepPoint = fStep->GetPostStepPoint();
63 if (fVerbose ==
nullptr) {
81 fVerbose->SetManager(
this);
102 fTouchableHandle =
nullptr;
106 fStep->DeleteSecondaryVector();
110 delete fSelectedAtRestDoItVector;
111 delete fSelectedAlongStepDoItVector;
112 delete fSelectedPostStepDoItVector;
113 delete fUserSteppingAction;
115 if (KillVerbose)
delete fVerbose;
127 if (verboseLevel > 0) {
130 else if (verboseLevel == -1) {
141 fStep->CopyPostToPreStepPoint();
142 fStep->ResetTotalEnergyDeposit();
146 fTrack->SetTouchableHandle(fTrack->GetNextTouchableHandle());
150 fN2ndariesAtRestDoIt = 0;
151 fN2ndariesAlongStepDoIt = 0;
152 fN2ndariesPostStepDoIt = 0;
156 fCurrentVolume = fStep->GetPreStepPoint()->GetPhysicalVolume();
160 fStep->SetPointerToVectorOfAuxiliaryPoints(
nullptr);
167 if (MAXofAtRestLoops > 0) {
168 InvokeAtRestDoItProcs();
170 fStep->GetPostStepPoint()->SetStepStatus(fStepStatus);
173 if (verboseLevel > 0) fVerbose->AtRestDoItInvoked();
187 DefinePhysicalStepLength();
190 fStep->SetStepLength(PhysicalStep);
191 fTrack->SetStepLength(PhysicalStep);
192 G4double GeomStepLength = PhysicalStep;
195 fStep->GetPostStepPoint()->SetStepStatus(fStepStatus);
198 InvokeAlongStepDoItProcs();
202 fStepStatus = fStep->GetPostStepPoint()->GetStepStatus();
205 fStep->UpdateTrack();
208 endpointSafOrigin = fPostStepPoint->GetPosition();
210 endpointSafety = std::max(proposedSafety - GeomStepLength, kCarTolerance);
212 fStep->GetPostStepPoint()->SetSafety(endpointSafety);
215 if (verboseLevel > 0) fVerbose->AlongStepDoItAllDone();
219 InvokePostStepDoItProcs();
222 if (verboseLevel > 0) fVerbose->PostStepDoItAllDone();
232 fTrack->AddTrackLength(fStep->GetStepLength());
233 fPreviousStepSize = fStep->GetStepLength();
234 fStep->SetTrack(fTrack);
237 if (verboseLevel > 0) fVerbose->StepInfo();
242 fCurrentVolume = fStep->GetPreStepPoint()->GetPhysicalVolume();
243 StepControlFlag = fStep->GetControlFlag();
245 fSensitive = fStep->GetPreStepPoint()->GetSensitiveDetector();
246 if (fSensitive !=
nullptr) {
247 fSensitive->Hit(fStep);
253 if (fUserSteppingAction !=
nullptr) {
254 fUserSteppingAction->UserSteppingAction(fStep);
258 fCurrentVolume->GetLogicalVolume()->GetRegion()->GetRegionalSteppingAction();
273 PreStepPointIsGeom =
false;
275 fParticleChange =
nullptr;
276 fPreviousStepSize = 0.;
283 GeometricalStep = 0.;
285 PreStepPointIsGeom =
false;
288 TempInitVelocity = 0.;
290 sumEnergyChange = 0.;
297 fTrack->SetTrackStatus(
fAlive);
303 if (fTrack->GetKineticEnergy() <= 0.0) {
309 if (! fTrack->GetTouchableHandle()) {
311 fNavigator->LocateGlobalPointAndSetup(fTrack->GetPosition(), &direction,
false,
false);
312 fTouchableHandle = fNavigator->CreateTouchableHistory();
313 fTrack->SetTouchableHandle(fTouchableHandle);
314 fTrack->SetNextTouchableHandle(fTouchableHandle);
317 fTrack->SetNextTouchableHandle(fTouchableHandle = fTrack->GetTouchableHandle());
319 G4VPhysicalVolume* newTopVolume = fNavigator->ResetHierarchyAndLocate(fTrack->GetPosition(),
320 fTrack->GetMomentumDirection(), *((
G4TouchableHistory*)fTrack->GetTouchableHandle()()));
322 fTouchableHandle = fNavigator->CreateTouchableHistory();
323 fTrack->SetTouchableHandle(fTouchableHandle);
324 fTrack->SetNextTouchableHandle(fTouchableHandle);
330 if (fTrack->GetParentID() == 0) {
331 fTrack->SetOriginTouchableHandle(fTrack->GetTouchableHandle());
336 if (fTrack->GetCurrentStepNumber() == 0) {
337 fTrack->SetVertexPosition(fTrack->GetPosition());
338 fTrack->SetVertexMomentumDirection(fTrack->GetMomentumDirection());
339 fTrack->SetVertexKineticEnergy(fTrack->GetKineticEnergy());
340 fTrack->SetLogicalVolumeAtVertex(fTrack->GetVolume()->GetLogicalVolume());
344 fCurrentVolume = fTouchableHandle->GetVolume();
348 if (fCurrentVolume ==
nullptr) {
350 if (fTrack->GetParentID() == 0) {
351 G4cerr <<
"ERROR - G4SteppingManager::SetInitialStep()" <<
G4endl
352 <<
" Primary particle starting at - " << fTrack->GetPosition()
353 <<
" - is outside of the world volume." <<
G4endl;
355 "Primary vertex outside of the world!");
359 G4cout <<
"WARNING - G4SteppingManager::SetInitialStep()" <<
G4endl
360 <<
" Initial track position is outside world! - " << fTrack->GetPosition()
365 fStep->InitializeStep(fTrack);
369 if (verboseLevel > 0) fVerbose->TrackingStarted();
378 G4cout <<
"G4SteppingManager::GetProcessNumber: is called track=" << fTrack <<
G4endl;
383 G4cerr <<
"ERROR - G4SteppingManager::GetProcessNumber()" <<
G4endl
384 <<
" ProcessManager is NULL for particle = "
385 << fTrack->GetDefinition()->GetParticleName()
386 <<
", PDG_code = " << fTrack->GetDefinition()->GetPDGEncoding() <<
G4endl;
388 "Process Manager is not found.");
399 G4cout <<
"G4SteppingManager::GetProcessNumber: #ofAtRest=" << MAXofAtRestLoops <<
G4endl;
409 G4cout <<
"G4SteppingManager::GetProcessNumber:#ofAlongStp=" << MAXofAlongStepLoops <<
G4endl;
419 G4cout <<
"G4SteppingManager::GetProcessNumber: #ofPostStep=" << MAXofPostStepLoops <<
G4endl;
422 if (SizeOfSelectedDoItVector < MAXofAtRestLoops ||
423 SizeOfSelectedDoItVector < MAXofAlongStepLoops ||
424 SizeOfSelectedDoItVector < MAXofPostStepLoops)
426 G4cerr <<
"ERROR - G4SteppingManager::GetProcessNumber()" <<
G4endl
427 <<
" SizeOfSelectedDoItVector= " << SizeOfSelectedDoItVector
428 <<
" ; is smaller then one of MAXofAtRestLoops= " << MAXofAtRestLoops <<
G4endl
429 <<
" or MAXofAlongStepLoops= " << MAXofAlongStepLoops
430 <<
" or MAXofPostStepLoops= " << MAXofPostStepLoops <<
G4endl;
432 "The array size is smaller than the actual No of processes.");
443void G4SteppingManager::DefinePhysicalStepLength()
457 fPostStepDoItProcTriggered = MAXofPostStepLoops;
459 for (std::size_t np = 0; np < MAXofPostStepLoops; ++np) {
460 fCurrentProcess = (*fPostStepGetPhysIntVector)((
G4int)np);
461 if (fCurrentProcess ==
nullptr) {
466 physIntLength = fCurrentProcess->
PostStepGPIL(*fTrack, fPreviousStepSize, &fCondition);
468 if (verboseLevel > 0) fVerbose->DPSLPostStep();
471 switch (fCondition) {
475 fStep->GetPostStepPoint()->SetProcessDefinedStep(fCurrentProcess);
480 "This feature no more supported");
483 (*fSelectedPostStepDoItVector)[np] =
Forced;
494 for (std::size_t nrest = np + 1; nrest < MAXofPostStepLoops; ++nrest) {
495 (*fSelectedPostStepDoItVector)[nrest] =
InActivated;
500 if (physIntLength < PhysicalStep) {
501 PhysicalStep = physIntLength;
503 fPostStepDoItProcTriggered =
G4int(np);
504 fStep->GetPostStepPoint()->SetProcessDefinedStep(fCurrentProcess);
508 if (fPostStepDoItProcTriggered < MAXofPostStepLoops) {
509 if ((*fSelectedPostStepDoItVector)[fPostStepDoItProcTriggered] ==
InActivated) {
510 (*fSelectedPostStepDoItVector)[fPostStepDoItProcTriggered] =
NotForced;
517 G4double safetyProposedToAndByProcess = proposedSafety;
518 G4bool delegateToTransportation =
false;
520 for (std::size_t kp = 0; kp < MAXofAlongStepLoops; ++kp) {
521 fCurrentProcess = (*fAlongStepGetPhysIntVector)[(
G4int)kp];
522 if (fCurrentProcess ==
nullptr)
continue;
525 physIntLength = fCurrentProcess->AlongStepGPIL(
526 *fTrack, fPreviousStepSize, PhysicalStep, safetyProposedToAndByProcess, &fGPILSelection);
528 if (verboseLevel > 0) fVerbose->DPSLAlongStep();
531 if (physIntLength < PhysicalStep) {
532 PhysicalStep = physIntLength;
539 fStep->GetPostStepPoint()->SetProcessDefinedStep(fCurrentProcess);
541 else if (fCurrentProcess->GetProcessType() ==
fParallel)
544 delegateToTransportation =
true;
549 if (kp == MAXofAlongStepLoops - 1) {
553 delegateToTransportation =
false;
560 if (safetyProposedToAndByProcess < proposedSafety) {
563 proposedSafety = safetyProposedToAndByProcess;
568 safetyProposedToAndByProcess = proposedSafety;
571 if (delegateToTransportation) {
573 fStep->GetPostStepPoint()->SetProcessDefinedStep(fCurrentProcess);
578G4int G4SteppingManager::ProcessSecondariesFromParticleChange()
581 G4Track* tempSecondaryTrack;
583 G4int pushedSecondaries = 0;
585 num2ndaries = fParticleChange->GetNumberOfSecondaries();
586 if (num2ndaries == 0) {
592 const G4VProcess* creatorProcess = fCurrentProcess->GetCreatorProcess();
594 for (
G4int DSecLoop = 0; DSecLoop < num2ndaries; ++DSecLoop) {
595 tempSecondaryTrack = fParticleChange->GetSecondary(DSecLoop);
598 tempSecondaryTrack->
SetParentID(fTrack->GetTrackID());
610 ED <<
"A track without proper process manager is pushed\n"
611 <<
"into the track stack.\n"
614 G4Exception(
"G4SteppingManager::ProcessSecondariesFromParticleChange()",
"Tracking10051",
619 fSecondary->push_back(tempSecondaryTrack);
623 delete tempSecondaryTrack;
627 fSecondary->push_back(tempSecondaryTrack);
632 return pushedSecondaries;
636void G4SteppingManager::InvokeAtRestDoItProcs()
643 G4double lifeTime, shortestLifeTime;
645 fAtRestDoItProcTriggered = 0;
648 for (std::size_t ri = 0; ri < MAXofAtRestLoops; ++ri) {
649 fCurrentProcess = (*fAtRestGetPhysIntVector)[(
G4int)ri];
650 if (fCurrentProcess ==
nullptr) {
655 lifeTime = fCurrentProcess->AtRestGPIL(*fTrack, &fCondition);
657 if (fCondition ==
Forced) {
658 (*fSelectedAtRestDoItVector)[ri] =
Forced;
662 if (lifeTime < shortestLifeTime) {
663 shortestLifeTime = lifeTime;
664 fAtRestDoItProcTriggered =
G4int(ri);
665 fStep->GetPostStepPoint()->SetProcessDefinedStep(fCurrentProcess);
670 (*fSelectedAtRestDoItVector)[fAtRestDoItProcTriggered] =
NotForced;
672 fStep->SetStepLength(0.);
673 fTrack->SetStepLength(0.);
679 if (shortestLifeTime < 1.0e+100)
683 for (std::size_t np = 0; np < MAXofAtRestLoops; ++np) {
688 if ((*fSelectedAtRestDoItVector)[MAXofAtRestLoops - np - 1] !=
InActivated) {
689 fCurrentProcess = (*fAtRestDoItVector)[(
G4int)np];
690 fParticleChange = fCurrentProcess->AtRestDoIt(*fTrack, *fStep);
694 fParticleChange->UpdateStepForAtRest(fStep);
697 fN2ndariesAtRestDoIt += ProcessSecondariesFromParticleChange();
700 fParticleChange->Clear();
707 fStep->GetPostStepPoint()->SetProcessDefinedStep(fNoProcess);
710 fStep->UpdateTrack();
716void G4SteppingManager::InvokeAlongStepDoItProcs()
728 for (std::size_t ci = 0; ci < MAXofAlongStepLoops; ++ci) {
729 fCurrentProcess = (*fAlongStepDoItVector)[(
G4int)ci];
730 if (fCurrentProcess ==
nullptr)
continue;
733 fParticleChange = fCurrentProcess->AlongStepDoIt(*fTrack, *fStep);
736 fParticleChange->UpdateStepForAlongStep(fStep);
739 if (verboseLevel > 0) fVerbose->AlongStepDoItOneByOne();
743 fN2ndariesAlongStepDoIt += ProcessSecondariesFromParticleChange();
748 fTrack->SetTrackStatus(fParticleChange->GetTrackStatus());
751 fParticleChange->Clear();
754 fStep->UpdateTrack();
757 if (fNewStatus ==
fAlive && fTrack->GetKineticEnergy() <=
DBL_MIN) {
758 if (MAXofAtRestLoops > 0)
762 fTrack->SetTrackStatus(fNewStatus);
767void G4SteppingManager::InvokePostStepDoItProcs()
772 for (std::size_t np = 0; np < MAXofPostStepLoops; ++np) {
777 G4int Cond = (*fSelectedPostStepDoItVector)[MAXofPostStepLoops - np - 1];
785 if ((np == 0) && (fTrack->GetNextVolume() ==
nullptr)) {
787 fStep->GetPostStepPoint()->SetStepStatus(fStepStatus);
796 for (std::size_t np1 = np + 1; np1 < MAXofPostStepLoops; ++np1) {
797 G4int Cond2 = (*fSelectedPostStepDoItVector)[MAXofPostStepLoops - np1 - 1];
808void G4SteppingManager::InvokePSDIP(
size_t np)
811 fCurrentProcess = (*fPostStepDoItVector)[(
G4int)np];
812 fParticleChange = fCurrentProcess->PostStepDoIt(*fTrack, *fStep);
815 fParticleChange->UpdateStepForPostStep(fStep);
818 if (verboseLevel > 0) fVerbose->PostStepDoItOneByOne();
822 fStep->UpdateTrack();
825 fStep->GetPostStepPoint()->SetSafety(CalculateSafety());
828 fN2ndariesPostStepDoIt += ProcessSecondariesFromParticleChange();
831 fTrack->SetTrackStatus(fParticleChange->GetTrackStatus());
834 fParticleChange->Clear();
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
std::vector< G4int > G4SelectedPostStepDoItVector
std::vector< G4int > G4SelectedAtRestDoItVector
std::vector< G4int > G4SelectedAlongStepDoItVector
Definition of the G4SteppingVerboseWithUnits class.
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()
G4ProcessManager * GetProcessManager() const
const G4String & GetParticleName() const
G4ProcessVector * GetAlongStepProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
G4ProcessVector * GetPostStepProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
G4ProcessVector * GetAtRestProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
std::size_t entries() const
void SetNavigator(G4Navigator *value)
void SetInitialStep(G4Track *valueTrack)
static G4int BestUnitPrecision()
void SetTrackStatus(const G4TrackStatus aTrackStatus)
G4ParticleDefinition * GetDefinition() const
const G4DynamicParticle * GetDynamicParticle() const
G4double GetKineticEnergy() const
void SetParentID(const G4int aValue)
void SetCreatorProcess(const G4VProcess *aValue)
static G4TransportationManager * GetTransportationManager()
virtual void UserSteppingAction(const G4Step *)
virtual G4int GetRegularStructureId() const =0
G4double PostStepGPIL(const G4Track &track, G4double previousStepSize, G4ForceCondition *condition)
const G4String & GetProcessName() const
static G4VSteppingVerbose * GetInstance()
virtual G4VSteppingVerbose * Clone()
virtual void DPSLStarted()=0
static void SetSilent(G4int fSilent)
static G4VSteppingVerbose * GetMasterInstance()