Killing all particles except selected ones

For some calculations, I would want to track only selected particles (gammas and neutrons in my case). I have been trying to look into the different ways of doing this, and I am not quite sure what is the best way to go. These are the things I looked into:

  • Using particle cuts.
    • Not suitable, because cuts can only be applied to gammas, electrons, positrons and protons.
  • Creating a custom process similar to G4NeutronKiller.
    • This would work perfectly, but it would have to be attached to all potential particles which should not be tracked.
  • Killing tracks in G4UserTrackingAction::PreUserTrackingAction().
    • This in principle works, but there are two issues:
      • It requires a const_cast, which suggests that this is not the right way to do it:
      • The remaining energy is not deposited (pretty much a non-issue, but there’s one thing I wanted to check).

Is this correct? Any other option I am missing? Does anyone have other suggestions?

In examples/basic/B3, neutrino are killed in StackingAction.

1 Like

Thank you @maire ! This is exactly what I need, it works like a charm.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.