Changing beam's starting position after building the program


I have a detector volume set up as shown in the image below. The envelope material is water and the world material is concrete.

I use the G4ParticleGun to shoot 1 mu- from outside the right side of the water towards the left. I want to change the starting Z position of the gun, e.g. for the gun to be 1m, 10m and 100m away from the water/concrete boundary. I want to do it after my simulation has been compiled and built, hence in the macro files. I tried /gun/position command in the visual mode but based on the graphics it seemed like it didn’t work. I also tried to define a customised command through PrimaryGeneratorMessenger class to set the initial Z value, but the root output file I got after using my own command is empty.

I’m wondering if I’m doing something wrong?

Many thanks,

Do you create your world volume large enough to include all of those gun positions? if your world volume is only 3 m across, for example, you can’t set Z to -10 m.

Thanks for the reply. Yes the world volume is big enough for all the distances I want to try as I have previously set the distances in the PrimaryGeneratorAction class before building the program and it worked.