Skip to content

HOWTO: McXtrace reflectivity files XrayDB python library

Emmanuel FARHI edited this page Feb 25, 2022 · 7 revisions

This page is intended to document how reflectivity datafiles for use with McXtrace may be generated with the XrayDB python library.

Reflectivity as a function of Energy and glancing angle θ

The top of the file should look like:

#param=eth
#E_min=5.6000000000000005
#E_max=46.0
#E_step=0.20301507537688443
#theta_min=0.0001
#theta_max=2.0
#theta_step=0.0010004502251125566
0.9999542644018437      0.9994968169720015      0.9990395754901166      0.9985825368481897      0.9981256979435801     ...
0.9972126069618438      0.9967563487052595      0.9963002778268547      0.995844391249176       0.995388685899527      ...
...

In this case the energy and theta values are implicit. The columns correspond to theta in degrees, and rows to energy in keV.

Generating files with the XrayDB python library.

Using a version of the script/program found in support/scripts - reflec_xraydb.py we may generate a mirror reflectivity file by means of the following recipe. This script is also available in the data directory (see http://mcxtrace.org/download/components/3.0/data/reflec_xraydb.py).

  1. Install the library, the simplest way is to use pip: pip install xraydb The numpy library also needs to be installed: pip install numpy. On recent Debian systems, one may try: apt install python3-xraydb
  2. Run the script: Example: python reflec_xraydb.py 5600 46000 0.0001 2 Pd 12.023 The first two arguments here (5600 46000) are the energies in eV, the third and fourth arguments (0.0001 2) are the angles in degrees, the fifth argument (Pd) is the name of the material and the sixth argument (12.023) is the density in g.cm^-3

Comparing XrayDB and IMD.

To compare the reflectivities generated by XrayDB and IMD we plot the reflectivity as a function of the incident angle for all the different energies. As an example, to compare the reflectivities for the material Pd run: python plot_diff.py Pd_substrate.dat Pd.dat but first install the matplotlib library

python -m pip install -U pip
python -m pip install -U matplotlib

See here for more information on matplotlib's installation.

XrayDB_IMD_compare_plots

To get the plot_diff.py script see here.

We can also calculate the maximum difference, the mean difference and the Frobenius norm of the matrix M=A-B where A and B are the reflectivity matrices of XrayDB and IMD (the values in the generated files). Run: python diff_compare.py Pd_substrate.dat Pd.dat

max difference:  0.5841119206880385
mean difference:  0.0033012136404630935
Frobenius norm:  7.042547987636111

To get the diff_compare.py script see here.

Even though the maximum difference is significant, the mean difference seems to be negligible. The Frobenius norm is not intuitively easy to understand.

PS: There are other arguments that can be put in the XrayDB function we call that can be interesting to use, see the doc for further details.

Clone this wiki locally