Variance and centroid optimisation in x-ray diffraction analysis