Initial position sampling

Dear Fluka experts,
I would like to simulate a photon beam based on a previous simulation (not from Fluka). I have an intensity matrix, when each element corresponds to the intensity in the area, say 500*500 nanometer. The beam itself is a plane beam (2D), about several millimeters on each side.
Following the presentation about user routine, I tried to understand how to perform the starting position sampling, and what is the most efficient way to perform it based on a matrix in Fluka.

Thank you in advance,
Hen Shukrun

Dear Hen Shukrun,

if you treat the the matrix as a list of probabilities with the x and y position in the matrix attached to each one. Then you can implement a sampling method similar to the one used for histograms in the function sample_histogram_momentum_energy() located in the source_library.inc file.

When you sampled which matrix element will be used, you can used two separate random number to sample the position within an element.

I hope this is enough to start.

Cheers,
David