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

Add aoecorrectionplot! and lplot! for fits with components and A/E correction plots #3

Merged
merged 6 commits into from
Feb 20, 2025

Conversation

fhagemann
Copy link
Contributor

Just as shown in the tests:

using LegendMakie, CairoMakie
using LegendSpecFits

using Distributions
using Unitful

e_cal = rand(Distributions.Exponential(300), 5_000_000) .+ 300
μA, μB, σA, σB = 1.01, 4e-6, 5e-3, 12.0
myμ(E) = μA - μB * E
myσ(E) = sqrt(σA^2 + σB^2/E^2)
aoe = [let= myμ(E), _σ = myσ(E); (rand() < 0.2 ? -rand(Distributions.Exponential(5*_σ)) : 0) +*randn() + _μ; end for E in e_cal]

compton_bands = collect((550:50:2350)u"keV")
compton_window = 20u"keV"
compton_band_peakhists = LegendSpecFits.generate_aoe_compton_bands(aoe, e_cal*u"keV", compton_bands, compton_window)
result_fit, report_fit = LegendSpecFits.fit_aoe_compton(compton_band_peakhists.peakhists, compton_band_peakhists.peakstats, compton_bands, uncertainty=true)
μs = [result_fit[band].μ for band in compton_bands]
σs = [result_fit[band].σ for band in compton_bands]
result_fit_single, report_fit_single = LegendSpecFits.fit_aoe_corrections(compton_bands, μs, σs)

# Compton band (individual) fit
lplot(report_fit[first(compton_bands)])

# A/E correction plots
lplot(report_fit_single.report_μ, col = 1, figsize = (1200,420))
lplot!(report_fit_single.report_σ, col = 2)
LegendMakie.add_watermarks!()

image

image

Copy link

codecov bot commented Feb 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.58%. Comparing base (e95e826) to head (9eb0e34).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main       #3      +/-   ##
==========================================
+ Coverage   81.25%   88.58%   +7.33%     
==========================================
  Files           7        8       +1     
  Lines         112      184      +72     
==========================================
+ Hits           91      163      +72     
  Misses         21       21              

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

@fhagemann
Copy link
Contributor Author

The last commit also includes testing the plots for the A/E combined fit.

result_fit_combined, report_fit_combined = LegendSpecFits.fit_aoe_compton_combined(compton_band_peakhists.peakhists, compton_band_peakhists.peakstats, compton_bands, result_fit_single, uncertainty=true)

# A/E combined fit plots
lplot(report_fit_single.report_μ, report_fit_combined.report_μ, col = 1, figsize = (1200,420))
lplot!(report_fit_single.report_σ, report_fit_combined.report_σ, col = 2)

image

@fhagemann fhagemann merged commit c2294aa into main Feb 20, 2025
9 checks passed
@fhagemann fhagemann deleted the fit_components branch February 20, 2025 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant