Counting particles

Hi everybody,

I want to make a simulation that counts the total number of particles that didnt suffer any interaction (hence deposited no energy) in my detector, but i dont know how to code it… Till now, I created my volumes, added the physics list and the primary generator.

Any help would be amazing!

There are multiple ways to do this, but a convenient hook is the UserTrackingAction, which has a method PostUserTrackingAction that fires after a particle is done being tracked. There you can compare the particle’s current kinetic energy to the vertex kinetic energy (both methods available within the G4Track class) to identify those that did not deposit any energy.