Get particle info in SteppingAction if particle pass through specific volume

Hello Experts,
I need to get information such as the particle position in void SteppingAction :: UserSteppingAction (const G4Step * step) but only if particle passes through a thin (0.01 mm) sheet of air. For this, I get the name of the volume and use If conditional:

G4String volName = step-> GetTrack () -> GetTouchable () -> GetVolume () -> GetName ();
if (volName == “fakeTop”) {

}

The problem is that it never enters to IF scope even when in visualization mode I see that the particle passes through the thin sheet (“fakeTop”). How could I solve this?
If anyone can help me I would appreciate it. Thank you so much in advance.

Best, Dayron

Instead of going through the track, why aren’t you checking the step information directly?

G4VPhysicalVolume* pv = step->GetPostStepPoint()->GetPhysicalVolume();
if (pv->GetName() == "fakeTop") {
  // Here if you've just entered the volume, or are within it
} else {
  pv = step->GetPreStepPoint()->GetPhysicalVolume();
  if (pv->GetName() == "fakeTop") {
    // Here if you are just leaving the volume (postStep volume will be different)
  }
}

I added that else block just to show you how the volume names will be set. If you only care about steps fully within the volume, you can combine the postStepPoint volume name test with a test on postStepPoint->GetStepStatus() != fGeomBoundary, which will exclude the step where the track enters the volume from outside. Test the PV first, then the status code, otherwise you’ll exclude the last step in the volume as the particle leaves.

First of all, thank you for your answer. I tried follow your advice but still the same happend. The program never enters to if scope because I checked with a cout. The problem is that neither pv->GetName() == “fakeTop” nor volName == “fakeTop” never, even when particle through the thinner layer. Do you have any other suggestions? The idea is to do something after particle pass through the “fakeTop”
Thank you again.

Best, D

There should always be a step at the boundary of a volume, both entering and exiting. 10 microns of air is almost certainly too thin for any kind of interaction, so for your test, you might need to look for the fGeomBoundary condition in order to see anything at all.

Thanks!!! I will check

Hi @dramoslo , Did you figure out this problem? I am having the exact same situation.

I’m not sure if they solved their problem. But make sure that you are using the string name provided as an argument, not the variable name of the logic/physical volume.

A simple test would be to have your run print the name that is retrieved. You can look at all of the physical volumes that are interacted with. It might flood your terminal if your run is long.

G4VPhysicalVolume* pv = step->GetPostStepPoint()->GetPhysicalVolume();
G4cout << pv->GetName() << G4endl;

Yes, when I check the geometry boundary I released that there was a problem in the position of the volume. Once that was solved, was working.