I want to make a program where each track contains the information about its parent particle, more or less in the following way:
-
each track should have variable, let’s call it parentParticle, storing a G4ParticleDefinition
-
for a primary particle (which if I’m not mistaken I can identify with ID==0) parentParticle should be set for its particle type
-
for a secondary particle (ID!=0), when the track is created at ClassifyNewTrack, if the new track is a photon, an electron, or a positron, parentParticle should be set to the same value of the parent; for all other particle it should be set to the particle type of the new particle
The problem I’m encountering with this is that I don’t know how to create this parentParticle in such a way that it’s kept for the whole track, and I can’t figure out how to access the parent particle in ClassifyNewTrack: I can only get a pointer to the process that created the track, but not the particle that originates the process. Another post suggested using the GimmeSecondaries method from the tracking manager, but again I can’t figure out how to implement it.
EDIT 1: I’ve just figured out how to use GimmeSecondaries, it was actually quite trivial; this page has the following example:
void UserTrackingAction::PostUserTrackingAction(const G4Track*) {
G4TrackVector* secTracks = fpTrackingManager -> GimmeSecondaries();
if(secTracks) {
size_t nmbSecTracks = (*secTracks).size();
for(size_t i = 0; i < nmbSecTracks; i++) {
if((*secTracks)[i] -> GetDefinition() == G4Electron::Definition())
counter++;
}
}
}
Now, what I need to do is add to each track object the parentParticle I mentioned at the beginning. Would it make sense to create a class that inherits G4Track? And if so, how would I tell the kernel to use it? Or is there a better way to keep a G4ParticleDefinition variable?