Getting the generator particle positions at source


I need to pass the source particle positions from my PrimaryGeneratorAction to SensitiveDetector function where I generate many particles in one event like the following

/gps/particle gamma
/gps/pos/type Volume
/gps/pos/shape Sphere #Cylinder
/gps/pos/centre 0 0 0 mm
/gps/pos/radius 60. mm
/gps/ang/type iso
/gps/number 10000
/run/beamOn 1

I can retrieve the number of particles in my PrimaryGeneratorAction, however I’m not able to get the positions of those when I have many particles in one event. I end up getting the “Segmentation fault” error. I’m using class of “Geant4: G4GeneralParticleSource Class Reference” in my code, I’m having a hard time finding the particle index in one source event. Based on the “classG4GeneralParticleSource”, there is an index associated to the source but not to the particle. I just wonder if there is any example that provide the similar implementation of the source position of many particles, and I appreciate any help in this regard.

FYI, here is the excerpt of the

Thank you!