### Beam Angular Spread in Specular Simulations

This example demonstrates beam angular spread effects in reflectivity computations. It also offers a comparison with data generated using another well known code: GenX. Further information about reflectometry simulations can be found in the Reflectometry Simulation Tutorial.

The observed reflectometry signal can be affected either by a spread in the beam wavelength or in the incident angle.

In this example, a Gaussian distribution is used to spread the incident angle, with a standard deviation of $\sigma_{\alpha} = 0.01^{\circ}$.

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68  #!/usr/bin/env python3 """ Reflectivity of a multilayer, taking into account beam angular divergence and beam footprint correction, simulated with BornAgain and GenX. """ import numpy as np, os, sys from matplotlib import pyplot as plt import bornagain as ba from bornagain import angstrom, ba_plot as bp, deg, std_samples # input parameters wavelength = 1.54*angstrom beam_sample_ratio = 0.01 # beam-to-sample size ratio def reference_data(filename): """ Loads and returns reference data from GenX simulation """ ax_values, real_data = np.loadtxt(filename, usecols=(0, 1), skiprows=3, unpack=True) # translate axis values from double incident angle to incident angle ax_values *= 0.5 return ax_values, real_data def get_sample(): return std_samples.alternating_layers() def get_simulation(sample, **kwargs): """ Returns a specular simulation with beam and detector defined. """ n = bp.simargs['n'] footprint = ba.FootprintSquare(beam_sample_ratio) alpha_distr = ba.DistributionGaussian(0, 0.01 * deg, 25, 3.) scan = ba.AlphaScan(n, 2*deg/n, 2*deg) scan.setWavelength(1.54*angstrom) scan.setFootprintFactor(footprint) scan.setAngleDistribution(alpha_distr) return ba.SpecularSimulation(scan, sample) if __name__ == '__main__': bp.parse_args(sim_n=500) datadir = os.getenv('BA_EXAMPLE_DATA_DIR', '') data_fname = os.path.join(datadir, "genx_angular_divergence.dat.gz") print(f"Loading GenX reference data from {data_fname}") genx_axis, genx_values = reference_data(data_fname) plt.yscale('log') plt.plot(genx_axis, genx_values, 'ko', markevery=300) sample = get_sample() simulation = get_simulation(sample) result = simulation.simulate() bp.plot_simulation_result(result) plt.legend(['GenX', 'BornAgain'], loc='upper right') if bp.do_show: plt.show() 
Examples/specular/VsGenx.py

Reference data: Examples/data/genx_angular_divergence.dat.gz