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 combined A/E fit routine #65

Merged
merged 22 commits into from
Sep 17, 2024
Merged

Add combined A/E fit routine #65

merged 22 commits into from
Sep 17, 2024

Conversation

fhagemann
Copy link
Contributor

Right now, this routine still uses the result of the old routine as starting parameters for the combined fit.

How to use it:

# ...

compton_bands  = aoe_config_ch.compton_bands
compton_window = aoe_config_ch.compton_window

result_fit, report_fit, compton_band_peakhists = nothing, nothing, nothing
try
    # get compton band peak histograms with generated peakstats
    compton_band_peakhists = generate_aoe_compton_bands(aoe, e_cal, compton_bands, compton_window)

    result_fit, report_fit = fit_aoe_compton(compton_band_peakhists.peakhists, compton_band_peakhists.peakstats, compton_bands,; uncertainty=true)
catch e
    @error "AoE compton bands cannot be fitted: $e"
    throw(ErrorException("AoE compton bands cannot be fitted"))
end

_compton_bands = [band for band in keys(result_fit) if result_fit[band].gof.pvalue >= p_value_cut] # end here 
μ = [result_fit[band].μ for band in _compton_bands]
σ = [result_fit[band].σ for band in _compton_bands]

# fit μ and σ with correction functions
result_corrections, report_corrections = nothing, nothing
try
    @time result_corrections, report_corrections = fit_aoe_corrections(_compton_bands, μ, σ,; e_expression = e_type_aoe_cal)
catch e
    @error "AoE corrections cannot be fitted: $e"
    throw(ErrorException("AoE corrections cannot be fitted"))
end

# use the result_corrections as input to the combined fit
combined_result = fit_aoe_compton_combined(compton_band_peakhists.peakhists, compton_band_peakhists.peakstats, compton_bands, result_corrections)

Copy link

codecov bot commented Aug 12, 2024

Codecov Report

Attention: Patch coverage is 0.89286% with 222 lines in your changes missing coverage. Please review.

Project coverage is 15.46%. Comparing base (392f2cc) to head (79f52b7).
Report is 74 commits behind head on dev.

Files with missing lines Patch % Lines
src/aoefit_combined.jl 0.00% 150 Missing ⚠️
ext/LegendSpecFitsRecipesBaseExt.jl 0.00% 70 Missing ⚠️
src/aoefit.jl 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev      #65      +/-   ##
==========================================
+ Coverage   15.38%   15.46%   +0.08%     
==========================================
  Files          24       32       +8     
  Lines        2035     2489     +454     
==========================================
+ Hits          313      385      +72     
- Misses       1722     2104     +382     

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

@fhagemann fhagemann mentioned this pull request Aug 12, 2024
@theHenks theHenks linked an issue Aug 16, 2024 that may be closed by this pull request
@theHenks theHenks added the enhancement New feature or request label Aug 16, 2024
@fhagemann
Copy link
Contributor Author

I was assigned to this PR?
Does that mean I should merge it?

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.

@theHenks
Copy link
Collaborator

Check binning in generate_aoe_compton_bands and adapt if necessary

@fhagemann
Copy link
Contributor Author

fit_aoe_compton_combined now returns a report (format/naming can still be discussed/changed), which includes the fits and fit parameters to the individual Compton bands.
CC @theHenks @verenaaur

@fhagemann
Copy link
Contributor Author

fhagemann commented Aug 31, 2024

So, to incorporate this code into the legend-julia-dataflow, one would need to insert

result_fit_combined, report_fit_combined = nothing, nothing
try
    result_fit_combined, report_fit_combined = fit_aoe_compton_combined(compton_band_peakhists.peakhists, compton_band_peakhists.peakstats, compton_bands, result_correction; e_expression = e_type_aoe_cal, uncertainty = true);
catch e
    @error "AoE compton bands cannot be fitted using a combined fit: $e"
    throw(ErrorException("AoE compton bands cannot be fitted using a combined fit"))
end

after the block where fit_aoe_corrections is called.

The plots afterwards can be adjusted to also include the combined fit result by adding an extra argument:

# instead of: p = plot(report_correction.report_µ)
p = plot(report_correction.report_μ, report_fit_combined.report_μ)

One thing to note: The combined fits took way longer yesterday than they used to do before (which is surprising to me because I didn't touch any of the maximum likelihood fit code in the last commits I added (?) --> https://github.com/fhagemann/LegendSpecFits.jl/compare/e728750..7707a3e). Not sure why this is and I hope this does not affect data production..

@fhagemann
Copy link
Contributor Author

Never mind, false alarm: I reused a variable name and caused some type instabilities. This should be fixed with the latest force push.

@fhagemann
Copy link
Contributor Author

fhagemann commented Aug 31, 2024

There might still be changes on some internal functions (but just code style, no change of functionality),
so @theHenks you can safely merge this PR and use fit_aoe_compton_combined and the new plot recipe taking two arguments to start data production ;)

(Maybe check for a small run that I didn't mess up the func strings returned in result.. )

@fhagemann
Copy link
Contributor Author

My last commit is just a clean-up, it does not change any functionality.
It just increases type stability.

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.

Very nice! :)

@fhagemann fhagemann merged commit 8b98185 into legend-exp:dev Sep 17, 2024
1 of 7 checks passed
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.

Revise A/E routines
3 participants