I’d like to extract the particle type and the positions of tracks in each event. It looks like there are two ways to do this:
- In SteppingAction::UserTrackingAction(), use step->GetPreStepPoint()->GetPosition().
- In TrackingAction::PreUserTrackingAction() or TrackingAction::PostUserTrackingAction(), use
The first option allows for extracting position, momentum, kinetic energy, etc. (but not the particle type) of a step point (pre or post). The second option looks to extract about the same information about the track. As a step is a delta information of track, the pre or post step points should provide the same information as the tracks. Is this correct? Is there a preferred way for any reason?
Each User Action acts on a different level, so that is how you know which one to use (how often do you need to call your code):
tracking action will invoke your user code only at the beginning (
PreUserTrackingAction) or at the end point (
PostUserTrackingAction) of processing of each track (normally when it’s created and when it’s killed).
stepping action will invoke your code much more often, at every step of your simulation - each track processing consists of multiple steps. Step represents what has changed: how long particle travelled, what energy was deposited, etc. PreStepPoint and PostStepPoint give position and volume of start and end of the step, respectively. Post step also contains information on what has happened in the current step (e.g. which process was invoked). Of course each step, as a smallest unit of simulation, is associated with a track, and each track with a particle (
G4Track::GetParticleDefinition()), so from within step you can access information on the track and the particle.
To read more have a look at the user guide.
Thank you so much for the explanation. Just to make sure, can I say like this?
- A track is ‘updated’ at every step (as a step is the delta information of a track), so the information of stepping points can be accessed using G4track or G4step within UserSteppingAction().
- A tracking action is invoked only at the beginning (‘created’) or at the end (‘destroyed’) of track, so those functions (PreUserTrackingAction or PostUserTrackingAction) do not provide the information of all the stepping points, if a track consists of multiple steps (most of the cases).