Question about the position of gps

Hello Geant4 experts,

Why is the position of source got by using “gps->GetParticlePosition()” different with that I set it in macro file?

If I set the position for the gps in macro file by using “/gps/position 0. 0. 20 mm”, can I chang it again by using gps->GetCurrentSource()->SetParticlePosition(G4ThreeVector(Px, Py, Pz)) before generating a event in GeneratorAction.cc?


It dosn’t work. But I try to use the following orders:
G4GeneralParticleSourceData* GPSData = G4GeneralParticleSourceData::Instance();
G4SingleParticleSource* thisSrc = GPSData->GetCurrentSource(0);
G4SPSPosDistribution* thisPosDis = thisSrc->GetPosDist();
thisPosDis->SetCentreCoords(G4ThreeVector(Px, Py, Pz));

Even it’m more complicated, but does work!