Generate source particles

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

Geant4 Version:10.7.0
Operating System:linux
Compiler/Version:9.4.0
CMake Version:3.16.3


Dear Geant4 experts,
Could you please advise on how to implement a probability distribution function into Geant4 for sampling to generate a particle source? For example, how would I integrate the Maxwell-Boltzmann probability distribution function?

Dear @Tang_Mao

Thank you for your question. One option is to generate the energy probability distribution offline, and sample later using your custom primary generator, or GSP [1]. This example shows how to use the GPS to load a custom distribution [2]

I hope this helps.

Best,

Alvaro

[1] Geant4 General Particle Source — Book For Application Developers 11.3 documentation

[2] geant4/examples/extended/eventgenerator/exgps/macros/test38.mac at master · Geant4/geant4 · GitHub

Thank you for yur reply.

Could you please explain the underlying principle of how the Geant4 General Particle Source (GPS) performs sampling from a user-defined distribution?