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 A/E ctc plot recipe #121

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions ext/LegendSpecFitsRecipesBaseExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,76 @@
end
end

@recipe function f(report::NamedTuple{(:peak, :window, :fct, :bin_width, :bin_width_qdrift, :aoe_peak, :aoe_ctc, :qdrift_peak, :h_before, :h_after, :σ_before, :σ_after, :report_before, :report_after)})

Check warning on line 1303 in ext/LegendSpecFitsRecipesBaseExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendSpecFitsRecipesBaseExt.jl#L1303

Added line #L1303 was not covered by tests

size --> (1000,1000)
layout := @layout [a{0.4h}; b{0.6h}]
link := :x

Check warning on line 1307 in ext/LegendSpecFitsRecipesBaseExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendSpecFitsRecipesBaseExt.jl#L1305-L1307

Added lines #L1305 - L1307 were not covered by tests

xtickfontsize --> 12
xlabelfontsize --> 14
ylabelfontsize --> 14
ytickfontsize --> 12
legendfontsize --> 12
foreground_color_legend --> :silver
background_color_legend --> :white

Check warning on line 1315 in ext/LegendSpecFitsRecipesBaseExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendSpecFitsRecipesBaseExt.jl#L1309-L1315

Added lines #L1309 - L1315 were not covered by tests

grid --> false
framestyle --> :semi
left_margin --> (5,:mm)
right_margin --> (5,:mm)
bottom_margin --> (-4,:mm)

Check warning on line 1321 in ext/LegendSpecFitsRecipesBaseExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendSpecFitsRecipesBaseExt.jl#L1317-L1321

Added lines #L1317 - L1321 were not covered by tests

@series begin
subplot := 1
color := :darkgrey
fill := true
alpha := 0.5
seriestype := :stepbins
label := "Before correction"
report.h_before

Check warning on line 1330 in ext/LegendSpecFitsRecipesBaseExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendSpecFitsRecipesBaseExt.jl#L1323-L1330

Added lines #L1323 - L1330 were not covered by tests
end

@series begin
subplot := 1
ylabel := "Counts / $(round(step(first(report.h_after.edges)), digits = 2))"
xlims --> (-9,5)
xticks := []
ylims := (0, Inf)
legend := :topleft
color := :purple
fill := true
alpha := 0.5
seriestype := :stepbins
label := "After correction"
report.h_after

Check warning on line 1345 in ext/LegendSpecFitsRecipesBaseExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendSpecFitsRecipesBaseExt.jl#L1333-L1345

Added lines #L1333 - L1345 were not covered by tests
end

@series begin
subplot := 2
colorbar := :none
fill := true
color := :binary
st := :line
label := "Before correction"
yformatter := :plain
kde((report.aoe_peak, report.qdrift_peak))

Check warning on line 1356 in ext/LegendSpecFitsRecipesBaseExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendSpecFitsRecipesBaseExt.jl#L1348-L1356

Added lines #L1348 - L1356 were not covered by tests
end

@series begin
subplot := 2
xlims --> (-9,5)
ylims --> (0,12)
xlabel --> "A/E classifier"
ylabel := "Eff. Drift time / Energy (a.u.)"
colorbar := :none
color := :plasma
st := :line
label := "After correction"
kde((report.aoe_ctc, report.qdrift_peak))

Check warning on line 1369 in ext/LegendSpecFitsRecipesBaseExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendSpecFitsRecipesBaseExt.jl#L1359-L1369

Added lines #L1359 - L1369 were not covered by tests
end
end


### lq recipe functions

Expand Down
4 changes: 2 additions & 2 deletions src/aoe_ctc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
if !converged @warn "CTC did not converge" end

# calculate drift time corrected aoe
_aoe_ctc = aoe_all .+ PolCalFunc(0.0, fct...).(qdrift_e_all)
_aoe_ctc = aoe_cut .+ PolCalFunc(0.0, fct...).(qdrift_e_cut)

Check warning on line 100 in src/aoe_ctc.jl

View check run for this annotation

Codecov / codecov/patch

src/aoe_ctc.jl#L100

Added line #L100 was not covered by tests

# normalize once again to μ = 0 and σ = 1
h_norm = fit(Histogram, _aoe_ctc, -20:bin_width:3) ### hard-coded values: should include some tolerance to higher values
Expand All @@ -111,7 +111,7 @@
aoe_ctc_func = "( ( $(aoe_expression) ) + " * join(["$(fct[i]) * ( $(qdrift_expression) )^$(i)" for i in eachindex(fct)], " + ") * " - $(μ_norm) ) / $(σ_norm) "

# create final histograms
h_after = fit(Histogram, aoe_ctc, -20:bin_width:3) ### hard-coded values: should include some tolerance to higher values
h_after = fit(Histogram, aoe_ctc, hist_start:bin_width:hist_end) ### hard-coded values: should include some tolerance to higher values

Check warning on line 114 in src/aoe_ctc.jl

View check run for this annotation

Codecov / codecov/patch

src/aoe_ctc.jl#L114

Added line #L114 was not covered by tests
ps_after = estimate_single_peak_stats(h_after)
result_after, report_after = fit_single_aoe_compton(h_after, ps_after, fit_func=:aoe_two_bck, pseudo_prior = pseudo_prior, uncertainty=true)

Expand Down
Loading