Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
calibration
pycalibration
Commits
4d2ea47a
Commit
4d2ea47a
authored
3 months ago
by
Karim Ahmed
Browse files
Options
Downloads
Patches
Plain Diff
refactor: change variable names, documentation, or move hardcoded parameters into func arguments
parent
4b8781ed
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1055
[Jungfrau][FF] Improve Fitting performance and stop using pydetlib + many refactors.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cal_tools/jungfrau/jungfrau_ff.py
+11
-11
11 additions, 11 deletions
src/cal_tools/jungfrau/jungfrau_ff.py
with
11 additions
and
11 deletions
src/cal_tools/jungfrau/jungfrau_ff.py
+
11
−
11
View file @
4d2ea47a
...
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment