From 010afbfaa16990172ac61819b691adde8eb11550 Mon Sep 17 00:00:00 2001 From: Felix Hagemann Date: Tue, 25 Feb 2025 09:52:51 +0100 Subject: [PATCH 1/2] Add A/E ctc plot recipe --- ext/LegendSpecFitsRecipesBaseExt.jl | 70 +++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/ext/LegendSpecFitsRecipesBaseExt.jl b/ext/LegendSpecFitsRecipesBaseExt.jl index c20b207d..25ecda55 100644 --- a/ext/LegendSpecFitsRecipesBaseExt.jl +++ b/ext/LegendSpecFitsRecipesBaseExt.jl @@ -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 From c463d031a57b990ee978b573a36cba1d5c4a29b4 Mon Sep 17 00:00:00 2001 From: Felix Hagemann Date: Tue, 25 Feb 2025 09:52:58 +0100 Subject: [PATCH 2/2] Restrict A/E ctc after histogram to Compton band events --- src/aoe_ctc.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aoe_ctc.jl b/src/aoe_ctc.jl index 503c974f..f0a5182d 100644 --- a/src/aoe_ctc.jl +++ b/src/aoe_ctc.jl @@ -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 @@ -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)