tschoonj / xraylib

A library for X-ray matter interaction cross sections for X-ray fluorescence applications
https://github.com/tschoonj/xraylib/wiki
Other
120 stars 54 forks source link

The photoelectric cross sections of Hydrogen #222

Closed AtsushiTanimoto closed 8 months ago

AtsushiTanimoto commented 9 months ago

Thank you for maintaining the xraylib code.

I used the following code to calculate the total cross section and K-shell cross section in the photoelectric effect of hydrogen. In the case of hydrogen, though these values should match, they are different. If I am using xraylib incorrectly, I would appreciate it if you could tell me how to write the code.

import numpy
import xraylib

def GetTotalCrossSection(z, energy_array):
    cross_array = numpy.zeros(len(energy_array))

    for i in range(len(energy_array)):
        try:
            cross_array[i] = xraylib.CSb_Photo(z, energy_array[i]/1000)
        except:
            cross_array[i] = 0

    return cross_array

def GetShellCrossSection(z, shell, energy_array):
    cross_array = numpy.zeros(len(energy_array))

    for i in range(len(energy_array)):
        try:
            cross_array[i] = xraylib.CSb_Photo_Partial(z, shell, energy_array[i]/1000)
        except:
            cross_array[i] = 0

    return cross_array

def WriteCrossSection(z, shell, energy_array, cross_array):
    if shell==-1:
        name = "../database/pe-cs-{}.dat".format(z)
    else:
        name = "../database/pe-ss-cs-{}-K.dat".format(z)

    with open(name, mode="w") as data:
        for i in range(len(cross_array)):
            data.write("{0:.8e} {1:.8e}\n".format(1.00e-06*energy_array[i], cross_array[i]))
        else:
            data.write("-1 -1\n")
            data.write("-2 -2\n")

if __name__=="__main__":
    energy_array = numpy.zeros(10991)

    for i in range(len(energy_array)):
        if i==0:
            pass
        elif i<=10000:
            energy_array[i] = energy_array[i-1]+1
        else:
            energy_array[i] = energy_array[i-1]+1000

    for z in range(1, 31):
        cross_total_array   = GetTotalCrossSection(z, energy_array)
        cross_kshell_array  = GetShellCrossSection(z, xraylib.K_SHELL, energy_array)
        WriteCrossSection(z, -1, energy_array, cross_total_array)
        WriteCrossSection(z, xraylib.K_SHELL, energy_array, cross_kshell_array)

Regards, Atsushi Tanimoto

tschoonj commented 9 months ago

Hi Atsushi,

This is expected given that CSb_Photo and CSb_Photo_Partial do not use the same underlying database. Try using CSb_Photo_Total instead of CSb_Photo. Then you should be using the same databases

AtsushiTanimoto commented 9 months ago

Dear Dr. Tom Schoonjans,

Thank you for your reply.

Try using CSb_Photo_Total instead of CSb_Photo . Then you should be using the same databases.

In this case, we obtained the same cross-section.

tschoonj commented 8 months ago

Hi Atsushi,

Thank you for letting me know this proposed solution worked. I will update the documentation with some clarification as this is counter intuitive and unexpected behaviour.

Greetings,

Tom