Beam direction distribution

Dear FLUKA experts:
Here is a question when I was using Source.newgen.f to define the direction distribution of the photon, I found there is no function to define the Beams’ direction distribution of sampling from histogram spectrum, how do I solve this problem?

Dear @22111140001,

First of all, let me apologize for the rather delayed answer.

Indeed, the user routine source_newgen.f does not have a dedicated function to define a beam direction distribution from sampling from a histogram. However, you can nevertheless use a work-around using the sample_histogram_momentum_energy function, e.g. as follows:

      !    Histogram file has to have 3 columns:
      !       - Emin (of the bin)
      !       - Emax (of the bin)
      !       - dN/dE (bin height; NOTE: doesn't need to be normalized)

      direction_cosx = sample_histogram_momentum_energy('histogram.txt', "GeV")
      direction_cosy = 0.2
      direction_cosz = 0.

I recommend to activate the debugging flag (debug_logical_flag = .true.) which will print the source particle information in the log file, for example:

 source_newgen.f - Debug output
 -------------------------------
 Particle  Mom. [GeV/c]   X [cm]         Y [cm]         Z [cm]         Cosx           Cosy           Cosz           Weight
        7  1.0000000E+01  0.0000000E+00  0.0000000E+00  0.0000000E+00  7.7268944E-01  6.3478424E-01  0.0000000E+00  1.0000000E+00
        7  1.0000000E+01  0.0000000E+00  0.0000000E+00  0.0000000E+00  8.2323275E-01  5.6770400E-01  0.0000000E+00  1.0000000E+00
        7  1.0000000E+01  0.0000000E+00  0.0000000E+00  0.0000000E+00  8.5146799E-01  5.2440659E-01  0.0000000E+00  1.0000000E+00
        7  1.0000000E+01  0.0000000E+00  0.0000000E+00  0.0000000E+00  9.0702924E-01  4.2106764E-01  0.0000000E+00  1.0000000E+00
        7  1.0000000E+01  0.0000000E+00  0.0000000E+00  0.0000000E+00  8.9768122E-01  4.4064547E-01  0.0000000E+00  1.0000000E+00
        7  1.0000000E+01  0.0000000E+00  0.0000000E+00  0.0000000E+00  8.1779441E-01  5.7551046E-01  0.0000000E+00  1.0000000E+00
        7  1.0000000E+01  0.0000000E+00  0.0000000E+00  0.0000000E+00  8.3873502E-01  5.4453978E-01  0.0000000E+00  1.0000000E+00
        7  1.0000000E+01  0.0000000E+00  0.0000000E+00  0.0000000E+00  8.4157193E-01  5.4014505E-01  0.0000000E+00  1.0000000E+00
        7  1.0000000E+01  0.0000000E+00  0.0000000E+00  0.0000000E+00  9.1174499E-01  4.1075672E-01  0.0000000E+00  1.0000000E+00
        7  1.0000000E+01  0.0000000E+00  0.0000000E+00  0.0000000E+00  8.8365788E-01  4.6813326E-01  0.0000000E+00  1.0000000E+00

Please note:
i) Use “GeV” as units such that your values will not be rescaled.
ii) The cosines will be renormalized to 1 (pay attention to the direction_flag as well).
iii) There will also be a sampling within the bin itself (i.e. from the bin Emin to Emax).
iv) It should be pointed out that the ‘sample_histogram_momentum_energy()’ function can only sample from a positive energy range, any negative value is rejected.

Let me know if this helps and if I can be of further assistance.

Regards,
Daniel

Dear Daniel Prelipcean
Thank you so much for your helpful reply, I have solved the problem, I really appreciate your kind help.

Best wishes,
liuyuCui