Keeping track of parent particle?

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?

Hi again Jacopo,

This is extremely similar to something my colleague Peter Kim has done previously. You can reach him at shingyu.kim@mail.mcgill.ca . I shared your forum post with him and he confirmed he should be able to help.

Joseph

Hello,

Of course, it is not recommended trying to substitute Geant4 kernel classes (like G4Track). Most probably code will not work or will provide unreliable results.

The problem you want to solve is called “Monte Carlo truth” analysis. Many users do this and there are many methods. In particular, G4VUserTrackingAction and G4VUserStackingAction are designed for this. We do not provide the default variant of MC truth handling, because each new user will need something different.

For this analysis, you may consider G4VUserTrackInformation. You create this object in your tracking or stacking action class and to attach
to G4Track. This is optional but useful way to control MC truth.

VI

2 Likes