# ess.sans.beam_center_finder.cost#

ess.sans.beam_center_finder.cost(xy, *args)#

Cost function for determining how close the $$I(Q)$$ curves are in all four quadrants. The cost is defined as

$\text{cost} = \frac{\sum_{Q}\sum_{i=1}^{i=4} \overline{I}(Q)\left(I(Q)_{i} - \overline{I}(Q)\right)^2}{\sum_{Q}\overline{I}(Q)} ~,$

where $$i$$ represents the 4 quadrants and $$\overline{I}(Q)$$ is the mean intensity of the 4 quadrants as a function of $$Q$$. This is basically a weighted mean of the square of the differences between the $$I(Q)$$ curves in the 4 quadrants with respect to the mean, and where the weights are $$\overline{I}(Q)$$. We use a weighted mean, as opposed to relative (percentage) differences to give less importance to regions with low statistics which are potentially noisy and would contribute significantly to the computed cost.

Parameters
Returns

float – The sum of the residuals for $$I(Q)$$ in the 4 quadrants, with respect to the mean $$I(Q)$$ in all quadrants.

Notes

Mantid uses a different cost function. They compute the horizontal (Left - Right) and the vertical (Top - Bottom) costs, and require both to be below the tolerance. The costs are defined as

$\text{cost} = \sum_{Q} \left(I(Q)_{\text{L,T}} - I(Q)_{\text{R,B}}\right)^2 ~.$

Using absolute differences instead of a weighted mean is similar to our cost function in the way that it would give a lot of weight to even a small difference in a high-intensity region. However, it also means that an absolute difference of e.g. 2 in a high-intensity region would be weighted the same as a difference of 2 in a low-intensity region. It is also not documented why two separate costs are computed, instead of a single one. The Mantid implementation is available here <https://github.com/mantidproject/mantid/blob/main/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/SANS/SANSBeamCentreFinder.py_.