Control the sampling behavior of multiple sources defined by GPS

Hi, G4ers,

I’m simulating multiple sources defined by GPS. I used /gps/source/add for different sources. I know this would randomly sample the sources according to the intensity. However, I would like to have my own sampling scheme, for example, based on the source activity and half-life. In the meantime, I still wanted to use GPS because it’s convenient to define complicated sources… Is there an easy way to do that?

The /gps/source/add command just takes a floating point value as argument. If you have a way to calculate the relative probabilities for your sources, just do that and put the number in.

Thanks for your response!
Yeah,the thing is because the activity ratio between multiple sources changes during the simulation, the relative probability also changes. Besides, the customized sampling scheme will also determine which source should be used for the next event…

You can’t do time-driven changes during an event, because Geant4 is not a time-stepping simulation. What you describe requires that you write your own PrimaryGeneratorAction. If you do that, then you can set up your code to collect the information from each event, calculate what you think the new ratios should be (of course, the effect of a single atom chane on a material is absurdly negligible), and update the ratios to be used for the next event.

Thanks! I guess I need to write my own PrimaryGeneratorAction…

dear @WenHe95 ,

another possibility would be to simulate each source independently since you know the activities and the measurement time for each of the source and simple add the simulations.

Learning to create your own particle source is nice but if you are only modifying intensities… you might get away with capitalizing on the independence of all the events.

In Geant4 you would have to go through hoops if you want to get pile ups from different sources.

Hope this helps.

/Pico

Dear /Pico,

Thank you for your suggestion!
That’s a simple but effective idea to just simulate these sources independently instead of simultaneously. I’m doing a 511 keV photon pair coincidence simulation, in this case, I can output all the singles from each of the sources, add them up, and sort these events by timestamps. The output data might be very large, but that’s doable.
After @mkelsey 's responses, I’ve been also thinking, that maybe I just need a customized class that inherits the G4GeneralParticleSource and modifies the GeneratePrimaryVertex method. So, I can keep using GPS and use my own sampling scheme for the primary generation.

Wen