In this example, we want to demonstrate how to fit a more complex sample. For this purpose, we utilize the reflectometry data of an artificial magnetic honeycomb lattice published by A. Glavic et al., in this paper
The experiment was performed with polarized neutrons, but without polarization analysis. Since the magnetization of the sample was parallel to the neutron spin, there is no spin flip and we apply the scalar theory to this problem. This is primarily done to speed up computations: when the polarized computational engine is utilized the fitting procedure takes roughly three times as long.
The experimental data consists of four datasets that should be fitted simultaneously. These datasets arise from the two polarization channels for up and down polarization of the incoming beam and both of these channels are measured at two temperatures (300K and 150K).
All of this is measured on the same sample, so all parameters are assumed to be the same, except the magnetization being temperature dependent. Therefore, we introduce a scaling parameter for the magnetization as the ratio of the magnetizations at 150K and 300K: $M_{s150} = M_{150K} / M_{300K}$.
The fifth column of each exported GenX dataset contains the pointwise standard deviation of $q$. The simulation uses these values directly rather than replacing them with a constant relative resolution. This interpretation is consistent with the Gaussian varying-resolution convolution implemented by GenX.
To model a magnetic material, one can assign a magnetization vector to any material, as is demonstrated in the magnetic material tutorial. When a non-vanishing magnetization vector is specified for at least one layer in a sample, BornAgain will automatically utilize the polarized computational engine. This leads to lower performance as the computations are more invovled.
In this example, the magnetization is (anti)parallel to the neutron spin and hence we instead parametrize the magnetic layers with an effective SLD that is the sum/difference of the nuclear and their magnetic SLD:
$$\rho_\pm = \rho_{\text{N}} \pm \rho_{\text{M}}$$
Here the $+$ is chosen for incoming neutrons with spin up and $-$ is chosen for spin down neutrons.
We simulate this experiment by bulding a 6 layer model: As usual the top layer is the vacuum and the bottom layer is a silicon substrate. On top of the silicon substrate, we simulate a thin oxide layer, where we fit its roughness and thickness The SLDs of these three layers are taken from the literature and kept constant.
Then we model the lattice structure with a three-layer model: two layers to account for density fluctuations in $z$-direction and another oxide layer on top. This lattice structure is assumed to be magnetic and we fit all of their SLDs, magnetic SLDs, thicknesses and roughnesses. The magnetic SLD depends on the temperature of the dataset, according to the scaling described above, where the $M_{s150}$ parameter is fitted.
All layers are modeled without absorption, i.e. no imaginary part of the SLD.
We apply the pointwise resolution correction with
QzScan.setVectorResolution. The experimental data is normalized to unity,
but we still fit the intensity.
The common simulation function receives both the $q$ values and their pointwise resolutions:
def run_simulation(q_axis, q_resolution, P, *, spin_sign, temperature):
resolution_profile = ba.DistributionGaussian(0., 1., 25, 3.)
scan = ba.QzScan(q_axis)
scan.setVectorResolution(resolution_profile, q_resolution)
scan.setIntensity(P["intensity"])
sample = get_sample(P, spin_sign, temperature)
simulation = ba.SpecularSimulation(scan, sample)
simulation.setBackground(ba.ConstantBackground(5e-7))
return simulation.simulate().intensities()
Each dataset stores its spin sign and temperature alongside the measured values. During the fit, all matching values are read from that one record:
for dataset in datasets:
simulated = run_simulation(
dataset["q"], dataset["q_resolution"], parameters,
spin_sign=dataset["spin_sign"],
temperature=dataset["temperature"])
We choose some sensible initial parameters and these yield the following simulation result
We have chosen the initial magnetization to be zero, hence there is only a single SLD curve for both spin directions.
We fit this example with the differential evolution algorithm exposed by lmfit. As a measure for the goodness of the fit, we use the relative difference:
$$\Delta = \sum_{j = 1}^4 \frac{1}{N_j} \sum_{i = 1}^N \left( \frac{d_{ji} - s_{ji}}{d_{ji} + s_{ji}} \right)^2$$
Here the sum over $i$ sums up the fitting error at every data point as usual and the sum over $j$ adds the contributions from all four datasets. This is implemented directly in the Python objective function. The function loops over the four NumPy datasets, runs the matching simulation for each channel, and returns one weighted residual vector. lmfit minimizes its sum of squares.
The given uncercainty of the experimental data is not taken into account.
As usual, the fit can be run with the following command:
python3 Honeycomb_fit.py fit
On a four-core workstation, the fitting procedure takes roughly 45 minutes to complete and we obtain the following result:
As can be seen from the plot of the SLDs, the magnetization is indeed larger for the measurement at lower temperature, exactly as expected.
|
|
Data to be fitted: honeycomb150m.dat , honeycomb150p.dat , honeycomb300m.dat , honeycomb300p.dat