Error in get the translation of PhysicsVolume

Hi! Segmentation fault happened when I tried to get the translation of the PhysicsVolume where the thePostPoint() of a step pointed to in the UserSteppingAction. Like:

 G4StepPoint* thePrePoint = step->GetPreStepPoint();
 G4VPhysicalVolume* thePrePV = thePrePoint->GetPhysicalVolume();
 G4StepPoint* thePostPoint = step->GetPostStepPoint();
 G4VPhysicalVolume* thePostPV = thePostPoint->GetPhysicalVolume();
 G4ThreeVector depos = thePrePV->GetTranslation();

This simulation wanted to track the energy deposition of a 511 keV gamma. I tried to output something like ProcessName, only “compt” was output for the first several events, but no “phot” was output before the segmentation fault happened. I added a line of code and then the error disappeared:

if(! thePrePV || ! thePostPV) return;

It seems that the postpoint of the final step (maybe phot is the final process) is not in any PV.
The Physicslist I used is G4EmStandardPhysics.
Thanks for your reply!

_Geant4 Version:_geant4-11-02
_Operating System:_Ubuntu 5.4.0-6ubuntu1~16.04.10
_Compiler/Version:_gcc 5.4.0
_CMake Version:_3.16.3


This is certainly possible if the track traversed your World volume and then “left the world.” The pre-step volume is guaranteed to exist, but not the post-step volume.

Thanks a lot for your reply! I think “left the world” might be the right trigger for the error. I tried using heavier material as target and it outputed phot before the error.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.