Creating and Plotting Histograms For Secondary Particles in Example B2a

I am interested in creating histograms for the secondary particles produces in Basic Example B2a. However, doing so exceeds my knowledge of the operations and inner workings of GEANT4. I was told about three months ago that it would be best to take a GEANT4 class to learn how to do this. Yet the only upcoming online class at that time was already full, and there is currently no upcoming classes listed on the schedule. Nonetheless, my group needs to press ahead on this simulation work. If this is too big of a question to tackle on the forum, I would appreciate discussing this with a subject matter expert via Skype or Zoom.

Dear jabowen,

I recommend you try to use TrackingAction class. It is similar to SteppingAction or EventAction.

When new secondary particles are produced, a track-ID is provided to each particle.

For example, let’s assume a primary particle(600 MeV Proton) bombards carbon.

It will cause the cascade of a carbon atom, pions, neutrons, e.t.c. will be produced.

In this situation, the initial proton’s track-ID is 0, and secondary particles are 1,2,3,…

You can use GetTrackID() and GetParentID() function in TrackingAction to get each track and it’s mother track’s trackID.

The below example will be helpful to you.

void TrackingAction::BeginOfTrackingAction(const G4Track* track)
if(track->GetTrackID() != 0)
if (track->GetParentID() == 0)
~~~~~~(get information of particle and make histogram)

Best regards,
Jaeyoung Jeong
1 Like

Thank you Mr. Jeong. I will look at this, and let you know if I have any more questions.

Mr. Jeong,

It does not look like there is a in the src files for Basic Example B2. Do I need to create this?

Dear Mr. jabowen,

Yes, I think there are several examples using TrackingAction in example/extended

I wish your luck!


1 Like