66 fParticleIsLooping( false ),
67 fPreviousSftOrigin( 0.,0.,0. ),
68 fPreviousMassSafety( 0.0 ),
69 fPreviousFullSafety( 0.0 ),
71 fMassGeometryLimitedStep( false ),
72 fAnyGeometryLimitedStep( false ),
73 endpointDistance( -1.0 ),
75 fThreshold_Warning_Energy( 100 *
MeV ),
76 fThreshold_Important_Energy( 250 *
MeV ),
77 fThresholdTrials( 10 ),
79 fSumEnergyKilled( 0.0 ), fMaxEnergyKilled( 0.0 ),
80 fUseMagneticMoment( false ),
81 fVerboseLevel( verbosity )
94 if( fVerboseLevel > 0 )
96 G4cout <<
" G4CoupledTransportation constructor: ----- " <<
G4endl;
97 G4cout <<
" Verbose level is " << fVerboseLevel <<
G4endl;
98 G4cout <<
" Navigator Id obtained in G4CoupledTransportation constructor "
107 fCurrentTouchableHandle = *pNullTouchableHandle;
111 fGlobalFieldExists= globalFieldMgr ? globalFieldMgr->
GetDetectorField() : 0 ;
113 fEndGlobalTimeComputed =
false;
114 fCandidateEndGlobalTime = 0;
123 if( (fVerboseLevel > 0) || (fSumEnergyKilled > 0.0 ) )
125 G4cout <<
" G4CoupledTransportation: Statistics for looping particles " <<
G4endl;
126 G4cout <<
" Sum of energy of loopers killed: " << fSumEnergyKilled <<
G4endl;
127 G4cout <<
" Max energy of loopers killed: " << fMaxEnergyKilled <<
G4endl;
153 fParticleIsLooping = false ;
174 #ifdef G4DEBUG_TRANSPORT
175 if( fVerboseLevel > 1 )
177 G4cout <<
"G4CoupledTransportation::AlongStepGPIL> called in volume "
187 G4ThreeVector OriginShift = startPosition - fPreviousSftOrigin ;
189 startMassSafety = 0.0;
190 startFullSafety= 0.0;
194 if( MagSqShift <
sqr(fPreviousFullSafety) )
196 G4double mag_shift= std::sqrt(MagSqShift);
197 startMassSafety =
std::max( (fPreviousMassSafety - mag_shift), 0.0);
198 startFullSafety =
std::max( (fPreviousFullSafety - mag_shift), 0.0);
212 fMassGeometryLimitedStep = false ;
213 fAnyGeometryLimitedStep =
false;
224 G4bool fieldExertsForce = false ;
243 if( (particleCharge != 0.0)
244 || (fUseMagneticMoment && (magneticMoment != 0.0) )
245 || (gravityOn && (restMass != 0.0))
248 fieldExertsForce =
true;
254 if( fieldExertsForce )
286 if( equationOfMotion )
309 fMassGeometryLimitedStep = false ;
310 fAnyGeometryLimitedStep = false ;
311 if( currentMinimumStep > 0 )
317 lengthAlongCurve = fPathFinder->
ComputeStep( theFieldTrack,
333 fMassGeometryLimitedStep = true ;
339 if( fMassGeometryLimitedStep && !fAnyGeometryLimitedStep )
341 G4cerr <<
" Error in determining geometries limiting the step" <<
G4endl;
342 G4cerr <<
" Limiting: mass=" << fMassGeometryLimitedStep
343 <<
" any= " << fAnyGeometryLimitedStep <<
G4endl;
344 G4Exception(
"G4CoupledTransportation::AlongStepGetPhysicalInteractionLength()",
346 "Incompatible conditions - was limited by a geometry?");
356 geometryStepLength =
std::min( lengthAlongCurve, currentMinimumStep);
360 fMomentumChanged = true ;
364 fPreviousSftOrigin = startPosition ;
365 fPreviousMassSafety = newMassSafety ;
366 fPreviousFullSafety = newFullSafety ;
369 #ifdef G4DEBUG_TRANSPORT
370 if( fVerboseLevel > 1 )
372 G4cout <<
"G4Transport:CompStep> "
373 <<
" called the pathfinder for a new step at " << startPosition
374 <<
" and obtained step = " << lengthAlongCurve <<
G4endl;
375 G4cout <<
" New safety (preStep) = " << newMassSafety
376 <<
" versus precalculated = " << startMassSafety <<
G4endl;
381 startMassSafety = newMassSafety ;
382 startFullSafety = newFullSafety ;
385 fTransportEndPosition = endTrackState.
GetPosition() ;
390 geometryStepLength = lengthAlongCurve= 0.0 ;
391 fMomentumChanged = false ;
397 fTransportEndPosition = startPosition;
400 if( startMassSafety == 0.0 )
402 fMassGeometryLimitedStep = true ;
403 fAnyGeometryLimitedStep =
true;
409 if( !fieldExertsForce )
411 fParticleIsLooping = false ;
412 fMomentumChanged = false ;
413 fEndGlobalTimeComputed = false ;
419 #ifdef G4DEBUG_TRANSPORT
420 if( fVerboseLevel > 1 )
422 G4cout <<
" G4CT::CS End Position = " << fTransportEndPosition <<
G4endl;
423 G4cout <<
" G4CT::CS End Direction = " << fTransportEndMomentumDir <<
G4endl;
432 fEndGlobalTimeComputed =
true;
442 fEndGlobalTimeComputed =
false;
447 G4double endEnergy= fTransportEndKineticEnergy;
450 G4double absEdiff = std::fabs(startEnergy- endEnergy);
457 if( (fVerboseLevel > 1) && ( absEdiff >
perThousand * endEnergy) )
469 endpointDistance = (fTransportEndPosition - startPosition).mag() ;
472 fTransportEndSpin = endTrackState.
GetSpin();
475 safetyProposal= startFullSafety;
480 if( (startFullSafety < endpointDistance )
481 && ( particleCharge != 0.0 ) )
499 fPreviousMassSafety = endMassSafety ;
500 fPreviousFullSafety = endFullSafety;
501 fPreviousSftOrigin = fTransportEndPosition ;
505 safetyProposal = endFullSafety + endpointDistance;
511 #ifdef G4DEBUG_TRANSPORT
513 G4cout <<
"***Transportation::AlongStepGPIL ** " <<
G4endl ;
514 G4cout <<
" Revised Safety at endpoint " << fTransportEndPosition
515 <<
" give safety values: Mass= " << endMassSafety
516 <<
" All= " << endFullSafety <<
G4endl ;
517 G4cout <<
" Adding endpoint distance " << endpointDistance
518 <<
" to obtain pseudo-safety= " << safetyProposal <<
G4endl ;
524 G4cout <<
"***Transportation::AlongStepGPIL ** " <<
G4endl ;
525 G4cout <<
" Quick Safety estimate at endpoint " << fTransportEndPosition
526 <<
" gives safety endpoint value = " << startFullSafety - endpointDistance
527 <<
" using start-point value " << startFullSafety
528 <<
" and endpointDistance " << endpointDistance <<
G4endl;
533 proposedSafetyForStart= safetyProposal;
536 return geometryStepLength ;
571 if (!fEndGlobalTimeComputed)
578 if( finalVelocity > 0.0 ) { finalInverseVel= 1.0 / finalVelocity; }
580 if( initialVelocity > 0.0 ) { initialInverseVel= 1.0 / initialVelocity; }
583 if (finalVelocity > 0.0)
586 G4double meanInverseVelocity = 0.5 * ( initialInverseVel + finalInverseVel );
587 deltaTime = stepLength * meanInverseVelocity ;
593 deltaTime = stepLength * initialInverseVel ;
598 fCandidateEndGlobalTime = startTime + deltaTime ;
606 deltaTime = fCandidateEndGlobalTime - startTime ;
628 if ( fParticleIsLooping )
630 G4double endEnergy= fTransportEndKineticEnergy;
632 if( (endEnergy < fThreshold_Important_Energy)
633 || (fNoLooperTrials >= fThresholdTrials ) )
640 fSumEnergyKilled += endEnergy;
641 if( endEnergy > fMaxEnergyKilled) { fMaxEnergyKilled= endEnergy; }
644 if((fVerboseLevel > 1) && ( endEnergy > fThreshold_Warning_Energy ))
646 G4cout <<
" G4CoupledTransportation is killing track that is looping or stuck " <<
G4endl
648 <<
" MeV energy." <<
G4endl;
650 if( fVerboseLevel > 0 )
661 if( (fVerboseLevel > 2) )
663 G4cout <<
" ** G4CoupledTransportation::AlongStepDoIt(): Particle looping - " <<
G4endl
664 <<
" Number of consecutive problem step (this track) = " << fNoLooperTrials <<
G4endl
666 <<
" Total no of calls to this method (all tracks) = " << noCalls <<
G4endl;
684 return &fParticleChange ;
709 <<
"**************************************************************" <<
G4endl;
710 G4cerr <<
"Endpoint has moved between value expected from TransportEndPosition "
711 <<
" and value from Track in PostStepDoIt. " << G4endl
712 <<
"Change of " << Quantity <<
" is " << moveVec.
mag() /
mm <<
" mm long, "
713 <<
" and its vector is " << (1.0/
mm) * moveVec <<
" mm " << G4endl
714 <<
"Endpoint of ComputeStep was " << OldVector
715 <<
" and current position to locate is " << NewVector << G4endl;
734 #ifdef G4DEBUG_TRANSPORT
735 if( ( fVerboseLevel > 0 ) && ((fTransportEndPosition - track.
GetPosition()).mag2() >= 1.0e-16) )
738 G4cerr <<
" Problem in G4CoupledTransportation::PostStepDoIt " <<
G4endl;
744 if( fVerboseLevel > 0 )
746 G4cout <<
" Calling PathFinder::Locate() from "
747 <<
" G4CoupledTransportation::PostStepDoIt " <<
G4endl;
748 G4cout <<
" fAnyGeometryLimitedStep is " << fAnyGeometryLimitedStep <<
G4endl;
753 if(fAnyGeometryLimitedStep)
763 fCurrentTouchableHandle=
766 #ifdef G4DEBUG_TRANSPORT
767 if( fVerboseLevel > 0 )
769 G4cout <<
"G4CoupledTransportation::PostStepDoIt --- fNavigatorId = "
770 << fNavigatorId <<
G4endl;
772 if( fVerboseLevel > 1 )
775 G4cout <<
"CHECK !!!!!!!!!!! fCurrentTouchableHandle->GetVolume() = " << vol;
776 if( vol ) {
G4cout <<
"Name=" << vol->GetName(); }
784 if( fCurrentTouchableHandle->
GetVolume() == 0 )
788 retCurrentTouchable = fCurrentTouchableHandle ;
796 #ifdef G4DEBUG_TRANSPORT
797 if( fVerboseLevel > 1 )
799 G4cout <<
"G4CoupledTransportation::PostStepDoIt -- "
800 <<
" fAnyGeometryLimitedStep = " << fAnyGeometryLimitedStep
801 <<
" must be false " <<
G4endl;
846 if( pNewMaterialCutsCouple!=0
847 && pNewMaterialCutsCouple->
GetMaterial()!=pNewMaterial )
851 pNewMaterialCutsCouple =
862 return &fParticleChange ;
904 fPreviousMassSafety = 0.0 ;
905 fPreviousFullSafety = 0.0 ;
916 if( fGlobalFieldExists )
930 #ifdef G4DEBUG_TRANSPORT
931 if( fVerboseLevel > 1 )
933 G4cout <<
" Returning touchable handle " << fCurrentTouchableHandle <<
G4endl;
952 static G4ThreadLocal G4int no_warnings= 0, warnModulo=1, moduloFactor= 10, no_large_ediff= 0;
954 if( std::fabs(startEnergy- endEnergy) >
perThousand * endEnergy )
957 if( (no_large_ediff% warnModulo) == 0 )
960 G4cout <<
"WARNING - G4CoupledTransportation::AlongStepGetPIL() "
961 <<
" Energy change in Step is above 1^-3 relative value. " <<
G4endl
962 <<
" Relative change in 'tracking' step = "
963 << std::setw(15) << (endEnergy-startEnergy)/startEnergy <<
G4endl
964 <<
" Starting E= " << std::setw(12) << startEnergy /
MeV <<
" MeV " <<
G4endl
965 <<
" Ending E= " << std::setw(12) << endEnergy /
MeV <<
" MeV " <<
G4endl;
966 G4cout <<
" Energy has been corrected -- however, review"
967 <<
" field propagation parameters for accuracy." <<
G4endl;
968 if( (fVerboseLevel > 2 ) || (no_warnings<4) || (no_large_ediff == warnModulo * moduloFactor) )
970 G4cout <<
" These include EpsilonStepMax(/Min) in G4FieldManager "
971 <<
" which determine fractional error per step for integrated quantities. " << G4endl
972 <<
" Note also the influence of the permitted number of integration steps."
975 G4cerr <<
"ERROR - G4CoupledTransportation::AlongStepGetPIL()" << G4endl
976 <<
" Bad 'endpoint'. Energy change detected"
977 <<
" and corrected. "
978 <<
" Has occurred already "
979 << no_large_ediff <<
" times." <<
G4endl;
980 if( no_large_ediff == warnModulo * moduloFactor )
982 warnModulo *= moduloFactor;
void PrepareNewTrack(const G4ThreeVector &position, const G4ThreeVector &direction, G4VPhysicalVolume *massStartVol=0)
static G4PathFinder * GetInstance()
void SetMaterialInTouchable(G4Material *fMaterial)
void SetTouchableHandle(const G4TouchableHandle &fTouchable)
const G4ThreeVector & GetPolarization() const
G4double ObtainSafety(G4int navId, G4ThreeVector &globalCenterPoint)
void Locate(const G4ThreeVector &position, const G4ThreeVector &direction, G4bool relativeSearch=true)
G4SafetyHelper * GetSafetyHelper() const
G4double GetLocalTime() const
void ReportMove(G4ThreeVector OldVector, G4ThreeVector NewVector, const G4String &Quantity)
void SetMaterialCutsCoupleInTouchable(const G4MaterialCutsCouple *fMaterialCutsCouple)
void StartTracking(G4Track *aTrack)
virtual void SetChargeMomentumMass(G4ChargeState particleCharge, G4double MomentumXc, G4double MassXc2)=0
G4double GetProperTime() const
CLHEP::Hep3Vector G4ThreeVector
G4double GetVelocity() const
G4double GetCurrentSafety() const
G4double GetKineticEnergy() const
const G4DynamicParticle * GetDynamicParticle() const
const G4MagIntegratorStepper * GetStepper() const
G4double AlongStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4double currentMinimumStep, G4double ¤tSafety, G4GPILSelection *selection)
G4VParticleChange * AlongStepDoIt(const G4Track &track, const G4Step &stepData)
void ClearAllChordFindersState()
G4Material * GetMaterial() const
G4bool DoesGlobalFieldExist()
void ReLocate(const G4ThreeVector &position)
const G4ThreeVector & GetPosition() const
~G4CoupledTransportation()
const G4ThreeVector & GetMomentumDir() const
G4TrackStatus GetTrackStatus() const
G4ThreeVector GetSpin() const
G4Navigator * GetNavigatorForTracking() const
G4TouchableHandle CreateTouchableHandle(G4int navId) const
void ProposePolarization(G4double Px, G4double Py, G4double Pz)
G4ParticleDefinition * GetDefinition() const
G4double GetVelocity() const
void ProposePosition(G4double x, G4double y, G4double z)
G4ReferenceCountedHandle< G4VTouchable > G4TouchableHandle
unsigned int GetNumberGeometriesLimitingStep() const
G4double GetTotalMomentum() const
G4StepPoint * GetPreStepPoint() const
virtual void Initialize(const G4Track &)
virtual void ConfigureForTrack(const G4Track *)
G4double GetKineticEnergy() const
G4EquationOfMotion * GetEquationOfMotion()
G4ThreeVector GetPosition() const
G4GLOB_DLL std::ostream G4cout
void ReportInexactEnergy(G4double startEnergy, G4double endEnergy)
G4int GetCurrentStepNumber() const
const G4String & GetName() const
const G4ThreeVector & GetMomentumDirection() const
G4double GetCharge() const
void ProposeTrueStepLength(G4double truePathLength)
G4double ComputeStep(const G4FieldTrack &pFieldTrack, G4double pCurrentProposedStepLength, G4int navigatorId, G4int stepNo, G4double &pNewSafety, ELimited &limitedStep, G4FieldTrack &EndState, G4VPhysicalVolume *currentVolume)
void SetProcessSubType(G4int)
G4bool DoesFieldChangeEnergy() const
G4double ComputeSafety(const G4ThreeVector &globalPoint)
G4double GetGlobalTime() const
G4FieldManager * FindAndSetFieldManager(G4VPhysicalVolume *pCurrentPhysVol)
const G4TouchableHandle & GetTouchableHandle() const
G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &stepData)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
static G4TransportationManager * GetTransportationManager()
G4FieldManager * GetFieldManager() const
static G4ProductionCutsTable * GetProductionCutsTable()
G4int ActivateNavigator(G4Navigator *aNavigator)
const G4ThreeVector & GetMomentumDirection() const
G4LogicalVolume * GetLogicalVolume() const
void ProposeProperTime(G4double finalProperTime)
G4double GetPDGMass() const
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
static G4FieldManagerStore * GetInstance()
void SetSensitiveDetectorInTouchable(G4VSensitiveDetector *fSensitiveDetector)
G4bool IsParticleLooping() const
G4double GetLabTimeOfFlight() const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
G4bool IsGravityActive() const
void ProposeGlobalTime(G4double t)
G4ChordFinder * GetChordFinder()
G4FieldManager * GetCurrentFieldManager()
void ProposeEnergy(G4double finalEnergy)
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4VPhysicalVolume * GetVolume() const
G4double GetTotalEnergy() const
G4double GetPDGSpin() const
void SetCurrentSafety(G4double val, const G4ThreeVector &pos)
void ClearPropagatorState()
void ProposeLastStepInVolume(G4bool flag)
void ProposeMomentumDirection(G4double Px, G4double Py, G4double Pz)
const G4MaterialCutsCouple * GetMaterialCutsCouple() const
void ProposeTrackStatus(G4TrackStatus status)
const G4Field * GetDetectorField() const
G4MagInt_Driver * GetIntegrationDriver()
void SetMomentumChanged(G4bool b)
G4PropagatorInField * GetPropagatorInField() const
G4ProductionCuts * GetProductionCuts() const
G4VSensitiveDetector * GetSensitiveDetector() const
G4double GetMagneticMoment() const
G4double PostStepGetPhysicalInteractionLength(const G4Track &, G4double previousStepSize, G4ForceCondition *pForceCond)
void ProposeLocalTime(G4double t)
G4double GetStepLength() const
const G4Material * GetMaterial() const
G4GLOB_DLL std::ostream G4cerr
G4CoupledTransportation(G4int verbosityLevel=0)