Skip to content

Commit

Permalink
Merge pull request #121 from legend-exp/aoe_ctc_plot_recipe
Browse files Browse the repository at this point in the history
Add A/E ctc plot recipe
  • Loading branch information
theHenks authored Feb 26, 2025
2 parents d58a59e + c463d03 commit 4179a69
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
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
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)})

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

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

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

@series begin
subplot := 1
color := :darkgrey
fill := true
alpha := 0.5
seriestype := :stepbins
label := "Before correction"
report.h_before
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
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))
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))
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 @@ function ctc_aoe(aoe_all::Vector{<:Real}, ecal_all::Vector{<:Unitful.RealOrRealQ
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)

# 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 @@ function ctc_aoe(aoe_all::Vector{<:Real}, ecal_all::Vector{<:Unitful.RealOrRealQ
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
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

0 comments on commit 4179a69

Please sign in to comment.