Last step in a volume

In my implementation of G4VSensitiveDetector::ProcessHits I’d need to check if the current step is the last step inside the current volume. To my knowledge, this can happen due to quite some reasons:

  • the step ends on a geometry boundary
  • the particle is stopped
  • the particle energy goes below the user limit
  • the particle is destroyed by an interaction

and maybe others that I’m missing at the moment. Is there an “easy” way to check if the current step is the last one or do I need to check all the above conditions (and maybe others?) one by one? Thanks.

This:

G4Step::IsLastStepInVolume()

slipped under my radar, and is almost was looking for. “Almost” because from my tests it seems that when a particle is going to be killed inside the volume (e.g. because it is stopped) then G4Step::IsLastStepInVolume() returns false. So I guess that it is just a geometric check on the particle being on an exit boundary, and thus I see no difference with aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary

It seems that also:

G4Step::IsFirstStepInVolume()

behaves in a way I cannot understand. I dumped the information about first step in volume and the step being or not on a boundary for a given track ID for two consecutive steps:

Track ID     firstStep     preBoundary     postBoundary
11744425         1                 1            0         
11744425         1                 0            0  

From this I understand that on first step the particle enters in the volume from a boundary, and then on second steps it enters again in the same volume but without crossing boundaries. Which does not make sense to me…