Replacing particle gun with general particle source

In the user guide it says that G4ParticleGun can be replaced with G4GeneralParticleSource by a global search and replace, however I’ve encountered problems with this in practice. For example, in exampleB1, a global search and replace of G4ParticleGun doesn’t work, as G4GeneralParticleSource doesn’t have SetParticleEnergy or SetParticleMomentum.
Are there other differences between ParticleGun and GPS?

As you pointed out, G4GPS doesn’t have SetParticleEnergy/SetParticleMomentum. Correct me if I am wrong, but based on my understanding/experience, G4GeneralParticleSource’s feature like angular distribution, particle types, momentum, etc, can be accessed only by command lines or macro files. Meanwhile, G4ParticleGun “can be used from inside UserPrimaryGeneratorAction to model complex source”.

If you haven’t played with the GPS example in the /example/extended/eventgenerator/exgps, I would recommend going through the code (specifically PrimaryGeneratorAction.cc). You can also find the expected results for those examples in this website: http://hurel.hanyang.ac.kr/Geant4/Geant4_GPS/reat.space.qinetiq.com/gps/examples/examples.html. This tutorial (http://geant4.in2p3.fr/2007/prog/GiovanniSantin/GSantin_Geant4_Paris07_PrimaryParticle_v08.pdf) is also great to understand different ways to implement primary particles.

Hope this helps!

Best regards,
lyk