Adding Tracking(TrackingAction.cc) to an Example

This might be a stupid question but I’m still a Geant4 novice and I can’t figure it out.
What is the best way to add TrackingAction.cc to a Geant4 example so that you can track?

I’m working with example Hadr01 in /extended/hadronic/, it has histo.cc, histomanager.cc and stackingaction.cc but no trackingaction.cc.
I would like to be able to save produced neutron amount and energy data as a spreadsheet, currently this data is only available from the histograms of the example.

So, what is the optimal way to get a spreadsheet output?
Could I modify stackingaction.cc to work or do I need to force the example to read an inserted trackingaction.cc?

Any advice or help would be greatly appreciated! I am still learning a lot everyday about Geant4!

If it is only to count neutrons, it can easily be done in StackingAction.
If, for some reason, you need to implement a TrackingAction, it has to be registered in ActionInitialization. See Hadr06 or Hadr07 or NeutronSource

2 Likes

I want to count and record (into a .csv file) the energies of secondary neutrons. If this can be done in stacking action great! Could you point me to an example or something using stacking action in such a way?
I would love to learn how to properly use Stacking Action!

There are many examples of stacking action, e.g. in basic/B3/B3a/ examples.
You can read more in the documentation: you have access to G4Track, so the particle’s type, energy, parent ID (which !0 for secondaries), etc.

To store information in the output file you can use analysis tools, and to use CSV in stead of ROOT you just need G4CsvAnalysisManager instead of G4RootAnalysisManager.

1 Like

Thank you, all of this is very helpful!