This example shows how to fit the parameters in the spin-asymmetry example.
For this demonstration, we choose initial parameters that are not too far from the fitting results. In particular, the magnetization is initially set to zero, such that the spin asymmetry identically vanishes.
With the initial parameters, we obtain the following reflectivity and spin-asymmetry curves:
For fitting of reflectometry data covering several orders of magnitude we use the $\chi^2$ metric
$$\chi^2 = \sum_{i = 1}^N \frac{\left( d_i - s_i \right)^2}{\sigma_i^2}$$
Here $d_i$ is the $i$-thexperimental data point, $\sigma_i$ is its uncertainty and $s_i$ is the corresponding simulation result.
In a BornAgain fit script this metric is written explicitly in the Python residual function. If no uncertainties are available, a relative difference can be written just as explicitly.
The fitting of polarized reflectometry data proceeds similar to the tutorial on multiple datasets. The residual function compares both reflectivity curves and concatenates the two residual vectors:
def residuals(P):
values = P.valuesdict()
r_pp = get_Simulation_pp(data_pp_q, values).simulate().intensities()
r_mm = get_Simulation_mm(data_mm_q, values).simulate().intensities()
return numpy.concatenate([data_pp["r"] - r_pp, data_mm["r"] - r_mm])
The fit parameters are defined in the dictionary startParams, where they are defined as a triple of values (start, min, max).
If no fit is performed the values obtained from our own fit are stored in fixedParams and are subsequently used
to simulate the system.
We want to fit the following parameters:
q_res: Relative $Q$-resolutionq_offset: Shift of the $Q$-axis.t_Mafo: The thickness of the layerrho_Mafo: The SLD of the layerrhoM_Mafo: The magnetic SLD of the layerr_Mao: The roughness on top of the substrater_Mafo: The roughness on top of the magnetic layerAfter running the fit using
python3 PolarizedSpinAsymmetryFit.py
we get the result
This result was already presented in the spin-asymmetry tutorial and can also be plotted by runnning
python3 PolarizedSpinAsymmetry.py
Here is the complete example:
|
|
Data to be fitted: MAFO_Saturated_mm.tab , MAFO_Saturated_pp.tab