How to Simulate Multiple Particle Types using Gun in Macro?

Hello,

I understand how to implement multiple sources using GPS with each source’s info defined in the macro.

How can I implement this using particle gun in the macro? For instance, in the attached adaptation from rdecay example, I generate 500 events of 100 keV electrons. Can I also define protons of 120 keV energy, such that 250 events are simulated for the 100-keV electrons and the rest 250 for the protons of 120 keV energy?

I tried defining /run/beamOn 250 twice but that overwrites the test.root created from the first instance. If I rename the file after first /run/beamOn 250, two ROOT files are generated and the event number of the second ROOT file starts from zero; which is not desired.

Any suggestions please?

You cannot. G4ParticleGun (which is what the /gun/* macro commands configure) produces one single particle with a fixed direction and fixed energy. No randomness. If you need a more complex source, use GPS or write your own PrimaryGeneratorAction in code.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.