Skip to content
Snippets Groups Projects
Commit 4d2ea47a authored by Karim Ahmed's avatar Karim Ahmed
Browse files

refactor: change variable names, documentation, or move hardcoded parameters into func arguments

parent 4b8781ed
No related branches found
No related tags found
1 merge request!1055[Jungfrau][FF] Improve Fitting performance and stop using pydetlib + many refactors.
......@@ -168,7 +168,7 @@ def set_histo_range(bin_centers, histogram, h_range):
bin_centers (array, float): the bin centers array
histogram (array, integers): the histogram with shape
(bins, cells, columns, row)
h_range (tuple, float): the (liminf, limsup) of the desired range
h_range (list, float): the (liminf, limsup) of the desired range
Returns: the new bin centers array and the new histogram
......@@ -232,7 +232,8 @@ def fit_histogram(
rebin,
ratio,
noise,
histo,
initial_sigma,
histo, # Added at the end to parallelize with multiprocessing.
):
"""
Wrap around function for fitting of histogram
......@@ -260,7 +261,6 @@ def fit_histogram(
CHARGE_SHARING_2=fit_double_charge_sharing,
GAUSS=fit_gauss,
)
initial_sigma = 15.
fit_func = _funcs[fit_func]
n_cells, n_rows, n_cols = histo.shape[1:]
......@@ -579,13 +579,13 @@ def fit_double_charge_sharing(x, y, yerr, initial_sigma, n_sigma, ratio):
return q, sigma, chi2ndf, alpha
def fit_gauss(x, y, yerr, initial_sigma, n_sigma, ratio):
def fit_gauss(bin_centers, histogram, yerr, initial_sigma, n_sigma, ratio):
"""
Fits histogram with a gaussian function
Args:
x (array, float): x values
y (array, float): y values
bin_centers (array, float): bin_centers values
histogram (array, float): histogram values
yerr (array, float): errors of the y values
initial_sigma (float): rough estimate of peak variance
n_sigma (int): to calculate threshold of the peak finder as
......@@ -597,16 +597,16 @@ def fit_gauss(x, y, yerr, initial_sigma, n_sigma, ratio):
(last one alway == 0)
all of them are kept for compatibility with the wrap around function
"""
norm = np.sum(y) * (x[1] - x[0])/np.sqrt(2.*np.pi*initial_sigma**2)
norm = np.sum(histogram) * (bin_centers[1] - bin_centers[0])/np.sqrt(2.*np.pi*initial_sigma**2)
_peaks, _ = _peak_position(x, y, thr=n_sigma*initial_sigma, ratio=ratio)
_peaks, _ = _peak_position(bin_centers, histogram, thr=n_sigma*initial_sigma, ratio=ratio)
if len(_peaks) > 0:
q0 = np.min(x[_peaks])
q0 = np.min(bin_centers[_peaks])
else:
return -1, -1, -1, -1
x_fit, i1, i2 = set_fit_range(x, q0 - initial_sigma, q0 + 2.*initial_sigma)
y_fit = y[i1:i2]
x_fit, i1, i2 = set_fit_range(bin_centers, q0 - initial_sigma, q0 + 2.*initial_sigma)
y_fit = histogram[i1:i2]
yerr_fit = yerr[i1:i2]
def cost_function(amp, mean, sigma):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment