I would like to generate two protons with different momentum directions in the same event. Actually i want to plot the envelope of my beam trajectory. my code is based on GPS commands. do you have any suggestion or guidance? or there is any example in source that i can use to help?
You can substitute G4GeneralParticleSource in place of G4ParticleGun. The former includes all of the “simple” commands that the latter has, but then you get all of the additional stuff, too. So take a look at Maire’s example, and you should be able to adapt it to your use case.