The energy lost by a particle (to the medium and to secondaries) during a step is obtained with GetDeltaEnergy(). The energy lost to the medium is obtained with GetTotalEnergyDeposit. The energy available for ionization is: GetTotalEnergyDeposit() - GetNonIonizingEnergyDeposit(). All this can be obtained from the G4Step object and you do not have to code anything inside StackingAction. A photon does not deposit energy except when it produces a secondary that is below the range cut you specify for it. In that case, the energy is deposited where the Compton, PhotoElectric or PairProduction takes place (PostStep). Simulation tracks are always limited by geometry boundaries so an interaction always takes place inside the (correct) volume. Charged secondaries above the range cut deposit energy both along their step (locations between PreStep and PostStepPoint) and at discrete points at the end of simulation steps. There isn't an easy/obvious way - to my knowledge - for the user to ascertain what fraction of GetTotalEnergyDeposit is from either AlongStep or PostStep processes.