Content
Here we discuss how to apply fit to data using absolute errors on peak position, get fit parameters with errors, estimate fit quality.
Data
exp=cxif5315:run=169
Fit in the processing script
cxif5315/proc-cxif5315-r0169-peaks-from-file-v4.py
from scipy.optimize import curve_fit from scipy.stats import chi2 xn = np.array([pk.x/L for pk in sp.lst_equ_evt_peaks], dtype=np.double) yn = np.array([pk.y/L for pk in sp.lst_equ_evt_peaks], dtype=np.double) en = np.array([pk.csigma*sp.PIXEL_SIZE/L for pk in sp.lst_equ_evt_peaks], dtype=np.double) #en = np.array([max(pk.rsigma,pk.csigma)*sp.PIXEL_SIZE/L for pk in sp.lst_equ_evt_peaks], dtype=np.double) p0 = [-3.2,-16.0] # phi, beta angle central values popt, pcov = curve_fit(funcy, xn, yn, p0, en, absolute_sigma=True) sp.fib_chi2 = np.sum(((funcy(xn, *popt) - yn) / en)**2) sp.fib_ndof = len(xn) - 1 sp.fib_prob = chi2.sf(sp.fib_chi2, sp.fib_ndof, loc=0, scale=1)
Plots
Distribution of parameters for peaks found by peak_finder_v2:
For 2-peak events fit does not have any freedom - curve can exactly be fitted to 3 points (including origin); chi2=0 and probability is always 1.
For >2-peak events chi2 and probability show some distribution.
Peak list with phi-beta fit results
After phi-beta fit peaks are saved in the file with name like
result/peak-fit-cxif5315-r0169-2016-04-04T16:16:38.txt
Comparing to regular peak parameters this file has extended data for each peak by
... fit-phi fit-beta phi-err beta-err fit-chi2 ndof fit-prob ... 1.30 -42.98 3.800454 10.236941 0.000000 1 1.000000 ... -4.75 -23.85 0.265462 1.212093 1.734365 3 0.629321
If someone want to load this file using pyimgalgos.TDFileContainer
, the class pyimgalgos.TDPeakRecord
needs to be updated.
References