Using probability distribution to generate neutrons with random selection

Hi all,

I have a neutron source defined in a text or binary file, with the probability P(r, theta, phi, E) where r is the position, (theta,phi) the direction and E the energy of a neutron . The idea is to use particleGun by assigning to the particle with random selection the parameters [(theta,phi), direction,E] accordingly to the probability P(r, theta, phi, E), by generating N neutrons (events). Do you have some suggestion to implement it, please?
Thanks in advance for your time.
Best regards,

Christian

1 Like

Hi Christian,

What if you store all the distributions in separate files and let the energy and angles being sampled via those files in a macro? If yes, see my response here.. This is implemented via GPS, which I highly suggest as it is straightforward to implement.

With ParticleGun I have always generated random numbers from 0 to 1 and defined the angular range using those numbers. For example, for each event a random number is sampled, hence a random angle.

2 Likes

Dear @mksharma_iitk ,

thank you very much for your answer. As I see from here, the distribution of a particle is a single point or a sphere at x=20 cm. How do you store the distribution in a single file, in order to be used with GPS? You mean to define in these files the energy and the direction, in addition to the position?

About the adoption of ParticleGun, how did you generate the random number for the sample?

Thanks in advance for your time.
Best regards,

Christian

1 Like

Hi @christian_castagna,

I have the same problematic, please tell me if you found the solution. For my case I have electron source defined in txt file with the probability P( theta, phi, E).

Thanks in advance for any replies.

Best regards,
Abdl

Dear @abdel23-dev ,

the only way that I find to overcome this problem is to generate in post-processing in python the position, energy, direction for each source neutron via the random.choices function, with the probability density functions that I obtained previously.
After that, I exported in a ROOT file these data.
My Geant4 solver reads the information of each source neutron from the ROOT file and generate each source neutron with ParticleGun.
If anyone found a straightforward way to do it, I would be still interested in.

Christian