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.
This is supported in BornAgain by setting
fit_objective.setObjectiveMetric("chi2")
Note that in order to obtain good results, one needs to provide the uncertainties
of the reflectivity.
If no uncertainties are available, using the relative difference fit_objective.setObjectiveMetric("reldiff")
yields better results.
If the relative difference is selected and uncertainties are provided, BornAgain automatically falls back to the above $\chi^2$ metric.
The fitting of polarized reflectometry data proceeds similar to the lines presented in the tutorial on multiple datasets. We need to add the reflectivity curves for the up-up and down-down channel to the fit objective:
fit_objective.addSimulationAndData( SimulationFunctionPlusplus,
r_data_pp, r_uncertainty_pp, 1.0)
fit_objective.addSimulationAndData( SimulationFunctionMinusMinus,
r_data_mm, r_uncertainty_mm, 1.0)
SimulationFunctionPlusplus
and SimulationFunctionMinusMinus
are two function objects that return a simulation result for
the up-up and down-down channels, respectively.
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