How to detect movement of secondary electrons between volume

_Geant4 Version:11.1.0
_Operating System:Ubuntu
_CMake Version:3.22.1

Hi! As i wrote in header i would like to find second electrons which is moved from one volume to another. I do the following;

void SteppingAction:UserSteppingAction(const G4Step* step){
//0 - not secondary, 1 - secondary, 2 - not electron
unsigned secon = 2;
if( step->GetTrack()->GetDynamicParticle()->GetDefinition()-.GetParticleName() == "e-"){
           if(step->GetTrack()->GetParentID() != 0) secon = 1;
           else secon = 0;
//0 - not penetrated, 1 - penetrated
unsigned penet = 0;

if(step->GetTrack()->GetVolume()->GetName() != step->GetTrack()->GetNextVolume()->GetName()){

However when i chek output i dont get any penet = 1. When i have been trying to print names of this and next volumes, i recive the same names. How to find next Volume properly?

Hello Alex,

As you are using SteppingAction, you can use the PreStepPoint and PostStepPoint to compare which volume the next step will be in. Here is a suggestion, using your same method of comparing the string names:

G4String preVolName = (step->GetPreStepPoint()->GetPhysicalVolume()->GetName());

// Need to check if the next volume exists (ie. not out-of-world), or it will have seg fault
G4String postVolName;
if (step->GetTrack()->GetNextVolume()) {postVolName = (step->GetPostStepPoint()->GetPhysicalVolume()->GetName());}
else {postVolName = "OutOfWorld";}

// Your comparison as above:
if(preVolName != postVolName){

Kind Regards,