Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic simple_calibration #108

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft

Generic simple_calibration #108

wants to merge 16 commits into from

Conversation

LisaSchlueter
Copy link
Contributor

@LisaSchlueter LisaSchlueter commented Dec 16, 2024

  • add a more generic simple_calibration function that can be accessed with keyword calib_type == :gamma which is useful for example for Co-60 data
  • add a minimalistic gamma peak-shape, that contains only Gaussian signal and flat background to fit low-statistics data

@LisaSchlueter LisaSchlueter added the enhancement New feature or request label Dec 16, 2024
@LisaSchlueter LisaSchlueter self-assigned this Dec 16, 2024
e_simple = e_uncal .* c
e_unit = u"keV"
# get peakhists and peakstats
peakhists, peakstats, h_calsimple, bin_widths = get_peakhists_th228(e_simple, gamma_lines, window_sizes; binning_peak_window=binning_peak_window, e_unit=e_unit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_peakhists_th228 also works for generic simple_calibration_gamma?
Or would that also need a get_peakhists_gamma?

Copy link
Contributor Author

@LisaSchlueter LisaSchlueter Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does.
In principle we could consider re-writing/re-naming all ..._th228 calibration functions to be more generic for other gamma spectra. Some don't even need any modification at all and work out of the box for other sources.
I didn't do that to keep the changes as minimal as possible.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to rename it, but maybe this could go along then with a PR onto the dataflow where we do a search and replace for these functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I can take care of this beginning of next year.

In that context, I'd suggest to change the julia energy-calibration metadata as well:

  1. Add a field "source" in the metadata, which is "th228" for LEGEND-200, but can also be something else. Like that the dataflow can pick the correct gamma_lines and gamma_names from the energy calibration config.

OR

  1. Rename "th228_lines" etc in the metadata to "gamma_lines".

I prefer option 1, because this allows you to switch easily back and fourth between different calibration sources.

@LisaSchlueter
Copy link
Contributor Author

Is this for Co60 or Co56?

I wrote and tested this for my local Co60 data, but it should work for any other calibration spectra, because the anticipated gamma energies are passed as an argument.

Copy link

codecov bot commented Dec 16, 2024

Codecov Report

Attention: Patch coverage is 65.85366% with 28 lines in your changes missing coverage. Please review.

Project coverage is 28.82%. Comparing base (6eece2d) to head (cace095).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
ext/LegendSpecFitsRecipesBaseExt.jl 0.00% 11 Missing ⚠️
src/simple_calibration.jl 82.05% 7 Missing ⚠️
src/chi2fit.jl 50.00% 2 Missing ⚠️
src/fit_calibration.jl 0.00% 2 Missing ⚠️
src/pseudo_prior.jl 0.00% 2 Missing ⚠️
src/specfit.jl 90.90% 2 Missing ⚠️
src/specfit_functions.jl 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #108      +/-   ##
==========================================
+ Coverage   28.39%   28.82%   +0.43%     
==========================================
  Files          37       37              
  Lines        3564     3594      +30     
==========================================
+ Hits         1012     1036      +24     
- Misses       2552     2558       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@theHenks theHenks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, the PR looks good. Thanks @LisaSchlueter .
My comments are mainly about the naming.
Do we wanna stick to the isotope naming or start having more generic names?

@@ -490,6 +490,41 @@ end
end
end

@recipe function f(report::NamedTuple{(:h_calsimple, :h_uncal, :c, :peak_guess, :peakhists, :peakstats)}; cal=true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this is a new recipe. Was this not here already before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost a duplicate of the existing recipe. However, the old one has some stuff hardcoded, e.g. "FEP" in the plot label. I didn't want to mess with the existing one, since we're int he middle of the processing.

@@ -820,7 +855,8 @@ end
if plot_ribbon
ribbon := uncertainty.(report.f_fit.(0:1:1.2*value(maximum(report.x))))
end
0:1:1.2*value(maximum(report.x)), value.(report.f_fit.(0:1:1.2*value(maximum(report.x))))
xstep = value(maximum(report.x))/100
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also work for the 228-Th data

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it today on 228-Th data and it worked well, same result.

e_simple = e_uncal .* c
e_unit = u"keV"
# get peakhists and peakstats
peakhists, peakstats, h_calsimple, bin_widths = get_peakhists_th228(e_simple, gamma_lines, window_sizes; binning_peak_window=binning_peak_window, e_unit=e_unit)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to rename it, but maybe this could go along then with a PR onto the dataflow where we do a search and replace for these functions.

@LisaSchlueter
Copy link
Contributor Author

Thanks for your input! I really appreciate it. I suggest the following before merging this PR:

LegendSpecFits:

  • rename everything th228 related into gamma
  • merge the two simple_calibration functions into one combined function. Same for plot recipe.
  • test everything on th228 and co60 data

julia-legend-dataflow:

  • adapt processor to new naming

metadata / legend-jldataflow-config:

  • add source field (see above)

@fhagemann
Copy link
Contributor

That sounds like a great plan.
We can still define functions called simple_calibration_th228 that will just call simple_calibration_gamma, something along

simple_calibration_th228(args...; kwargs...) = simple_calibration_gamma(args...; source = :th228, kwargs...)

where the keyword argument is source, calib_type, ... or whatever.

@LisaSchlueter
Copy link
Contributor Author

In general, the PR looks good. Thanks @LisaSchlueter . My comments are mainly about the naming. Do we wanna stick to the isotope naming or start having more generic names?

We now have generic names peak_search_gamma(), peakhists_gamma(). There are still two options for calib_type

  • calib_type == :th228
  • calib_type == :gamma
    In both cases, we apply the same methods to perform the simple calibration. The difference is that for th228, some values like the peakfinder_threshold, peakfinder_σ, peak_quantile and bin_quantile are harded-coded to good values for a LEGEND-like Th-228 spectrum.
    In the case of :gamma, the user has more options to tune the simple calibration.

@LisaSchlueter
Copy link
Contributor Author

@theHenks Are you happy with your request?

@LisaSchlueter LisaSchlueter marked this pull request as draft March 11, 2025 22:18
@theHenks
Copy link
Collaborator

@theHenks Are you happy with your request?

At a first quick look, this looks great! But I didn't find the time to look through this in detail yet. If it is not super urgently needed I would push this to after the CM.

@LisaSchlueter
Copy link
Contributor Author

Yes, let's do it after the CM then. I'll probably divide this into a few smaller PRs to make it easier to track the many small changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants