Get particle position at the end of a step

I have 2 methods to get the particle position at the end of a simulation step:

1.
G4ThreeVector position  = track->GetPosition() - step->GetDeltaPosition();

2.
G4ThreeVector position  = step->GetPostStepPoint()->GetPosition();

In my code, I invoke these 2 methods in SteppingAction::UserSteppingAction() method, but these 2 methods returns different results.

Are these 2 methods different?


Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

_Geant4 Version:_4.11.0.p01
_Operating System:_windows subsystem linux (wsl2)
Compiler/Version:
CMake Version:


Dear Saluta,

Yes, they calculate different things. When UserSteppingAction() is called, track->GetPosition() gives already the post-step point position. If you want them to give the same result, you do not need to substract the step delta position.

Miguel

Thank you so much for your answer.

So in UserSteppingAction() any information from track, say,
track->GetMomentum(),
track->GetTotalEnergy(),
track->GetPosition(),
will return identical result as from
step->GetPostStepPoint->GetXXX(),
right?

Yes, that should be correct. My understanding is that step->GetDeltaPosition() is a “convenience function”, so you don’t have to manually do GetPostStepPoint()->GetPosition() - GetPreStepPoint()->GetPosition().

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.