Dear @horvathd,
Sorry to open this thread again. Can you please explain the codes you wrote for spectrum sampling in your spare time ?
What does this LUNOUT refer to ?
if ( first_run ) then
write ( LUNOUT, * ) '# '
write ( LUNOUT, * ) '#'
write ( LUNOUT, * ) '# Sampling from spectrum requested'
write ( LUNOUT, * ) '#'
What is the scale factor here ? What does this energy_unit refer to?
scale_factor = energy_unit_to_scale_factor(energy_unit)
bins = 1
call OAUXFI( filename, LUNRDB, 'OLD', ierr )
if ( ierr .eq. 1 ) then
call FLABRT('sample_spectrum_momentum_energy', 'Unable to open spectrum file')
end if
What are t1, t2 here ? Are these the the data present in spectrum txt file?
do
read ( LUNRDB, *, iostat = io ) t1, t2
if ( io .eq. 0 ) then
bins = bins + 1

Failed to read line corretly, possible comment  skipping
else if ( io .gt. 0 ) then
cycle

End of file
else if ( io .lt. 0 ) then
exit
end if
end do
allocate( energy( 0:bins ) )
allocate( intensity( 0:bins ) )
allocate( probability( 0:bins ) )
write ( LUNOUT, "(A, I6)" ) ' # Number of points: ', bins
write ( LUNOUT, * ) '#'
write ( LUNOUT, * ) '# Processed spectrum:'
write ( LUNOUT, * ) '#'
Which line ensures the conversion of eV to GeV? The spectrum file had units in GeV. Don’t we have to incorporate a factor of 1E9 with the input energy data?
write ( LUNOUT, * ) '# E [GeV], Intensity'
line = 0
rewind( LUNRDB )
do
read ( LUNRDB, *, iostat = io ) t1, t2
if ( io .eq. 0 ) then
What is the purpose of scale_factor multiplication here ? Is it for the conversion of eV to GeV?
energy(line) = t1 * scale_factor
intensity(line) = t2 * scale_factor
write ( LUNOUT, "(2ES15.7)" ) energy(line), intensity(line)
line = line + 1

Failed to read line corretly, possible comment  skipping
else if ( io .gt. 0 ) then
cycle

End of file
else if ( io .lt. 0) then
exit
end if
end do
probability(0) = ZERZER
Does this block represent the formulation of CDF?
do line = 1, bins
probability(line) = (energy(line)  energy(line1)) * (intensity(line) + intensity(line  1)) + probability(line  1)
end do
write ( LUNOUT, * ) '#'
write ( LUNOUT, * ) '# End of spectrum'
write ( LUNOUT, * ) '#'
write ( LUNOUT, * ) '# '
probability = probability / probability(bins)
first_run = .false.
end if
random_probability = FLRNDM( xdummy )
do line = 1, bins
if (probability(line) .ge. random_probability) then
random_bin = line
exit
end if
end do
sample = (random_probability  probability(line  1)) / (probability(line)  probability(line  1))
if (intensity(line) == intensity(line  1)) then
continue
else
What does this first line of sample mean? What is the role of sqrt value?
sample = sample * (intensity(line)  intensity(line  1)) * (intensity(line) + intensity(line  1))
sample = (sqrt(sample + intensity(line  1)**2)  intensity(line  1)) / (intensity(line)  intensity(line  1))
end if
sample = sample * (energy(line)  energy(line  1)) + energy(line  1)
What is this ANGLGB?
if ( sample .lt. ANGLGB ) then
sample = sample_spectrum ( filename, energy_unit )
end if
return
end
Regards,
Riya