-
Notifications
You must be signed in to change notification settings - Fork 9
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
A/E ctc correction #87
base: dev
Are you sure you want to change the base?
Conversation
…tc.jl, but needs some fixes before it can be applied)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #87 +/- ##
==========================================
- Coverage 21.89% 21.41% -0.49%
==========================================
Files 34 35 +1
Lines 2973 3031 +58
==========================================
- Hits 651 649 -2
- Misses 2322 2382 +60 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `func_generic`: generic function to correct aoe | ||
""" | ||
|
||
function ctc_aoe(aoe_all::Vector{<:Real}, ecal_all::Vector{<:Unitful.RealOrRealQuantity}, qdrift_e_all::Vector{<:Real}, compton_bands::Vector{<:Unitful.RealOrRealQuantity}, peak::Real = 0.0, window::Tuple{<:Real, <:Real} = (50.0, 8.0), hist_start::Real = -20.0, hist_end::Real = 5.0, bin_width::Real = 0.05; aoe_expression::Union{Symbol, String}="aoe", e_expression::Union{Symbol, String} = "e", pseudo_prior::NamedTupleDist = NamedTupleDist(empty = true), pseudo_prior_all::NamedTupleDist = NamedTupleDist(empty = true), pol_order::Int=1) # deleted m_cal since no calibration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put all default values from @verenaaur as default values of the arguments.
# calculate optimal bin width (if needed for other purposes) | ||
bin_width_window = 5.0 ### this parameter might be modified since it's copied from the energy case | ||
bin_width = get_friedman_diaconis_bin_width(aoe[peak - bin_width_window .< aoe .< peak + bin_width_window]) ### or use 0.05 | ||
bin_width_qdrift = get_friedman_diaconis_bin_width(qdrift_e[peak - bin_width_window .< aoe .< peak + bin_width_window]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bin_width
of the histograms need some engineering
# get σ and peak height | ||
μ = mvalue(result_peak.μ) | ||
σ = mvalue(result_peak.σ) | ||
p_height = maximum(report_peak.f_fit.(μ-0.2*σ:0.001:μ+0.2*σ)) # hardcoded 0.001 for now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hard-coded 0.001
to determine the maximum. Assuming a normalization to μ = 0
and σ = 1
, this should be sufficiently fine.
# minimize function | ||
qdrift_median = median(qdrift_e_cut) | ||
# upper bound | ||
fct_lb = [(1e-4 / qdrift_median)^(i) for i in 1:pol_order] | ||
@debug "Lower bound: $fct_lb" | ||
# lower bound | ||
fct_ub = [(50.0 / qdrift_median)^(i) for i in 1:pol_order] | ||
@debug "Upper bound: $fct_ub" | ||
# start value | ||
fct_start = [(1 / qdrift_median)^(i) for i in 1:pol_order] | ||
@debug "Start value: $fct_start" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The boundary values for fitting
_aoe_ctc = aoe_all .+ PolCalFunc(0.0, fct...).(qdrift_e_all) | ||
|
||
# normalize once again to μ = 0 and σ = 1 | ||
h_norm = fit(Histogram, _aoe_ctc, -50:bin_width:30) ### hard-coded values: should include some tolerance to higher values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, the histogram edges are hard-coded to -50
and 30
. I remember agreeing on something like -20
to 3
, but the charge trapping correction introduces a bias towards higher values (that is afterwards normalized), so 3
might be a bit too little. Maybe let this depend on peakstats?
aoe_ctc_func = "( $(aoe_expression) + " * join(["$(fct[i]) * ( qdrift / $(e_expression) )^$(i)" for i in eachindex(fct)], " + ") * " - $(μ_norm) ) / $(σ_norm) " | ||
|
||
# create final histograms | ||
h_after = fit(Histogram, aoe_ctc, -50:bin_width:30) ### hard-coded values: should include some tolerance to higher values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, -50
and 30
as histogram edges
Plotting code for now (very much inspired by the energy_ctc calibration in #67): # This should become a plot recipe at some point
let aoe_final = ljl_propfunc(result.func).(hit_cal), _aoe = ljl_propfunc(result_correction.func).(hit_cal), _qdrift_e = hit_cal.qdrift ./ hit_cal.e_cusp
sel = abs.(aoe_final) .< 100 #.&& mask
plot(fit(Histogram, _aoe[sel], -9:0.1:9), fill = true, xlims = (-9,5), color = :darkgrey, subplot = 1, link = :x, framestyle = :semi, size = (1000,1000), margins = (0,:mm), layout = (2,1), grid = false, st = :stepbins, left_margin = (5,:mm), right_margin = (5,:mm), bottom_margin = (-4,:mm), label = "Before correction")
plot!(fit(Histogram, aoe_final[sel], -9:0.1:9), fill = true, xlims = (-9,5), alpha = 0.5, color = :purple, subplot = 1, link = :x, framestyle = :semi, size = (1000,1000), margins = (0,:mm), layout = (2,1), grid = false, st = :stepbins, left_margin = (5,:mm), right_margin = (5,:mm), bottom_margin = (-4,:mm), label = "After correction", legend = :topleft, ylabel = "counts / 0.1")
plot!(kde((_aoe[sel], (_qdrift_e)[sel])), subplot = 2, c = :binary, colorbar = :none, st = :line, fill = true, label = "After correction", yformatter = :plain, link = :x)
plot!(kde((aoe_final[sel], (_qdrift_e)[sel])), subplot = 2, c = :plasma, link = :x, framestyle = :semi, colorbar = :none, st = :line, fill = false, label = "After correction", yformatter = :plain, xlims = (-9,5), ylims = (0,11), ylabel = "Eff. Drift time / Energy (a.u.)")
plot!(xlabel = "A/E classifier", xtickfontsize = 12, xlabelfontsize = 14, ylabelfontsize = 14, ytickfontsize = 12, legendfontsize = 12, foreground_color_legend = :silver, background_color_legend = :white, fmt = :png)
end |
So, this is @verenaaur's and my approach to the charge trapping correction of the$(A/E) \text{classifier}$ :
The idea is to determine a charge trapping factor$fct$ such that a linear correction of the $(A/E) \text{classifier}$ $Q\text{drift}/E$ results in corrected, $Q\text{drift}/E$ -independent $(A/E) \text{classifier}$ -values.
with respect to
The steps of the algorithm are as follows:
mask
to select all events that fill into thecompton_bands
provided to the function.compton_bands
-->h_before
f_optimize_ctc
h_norm
h_norm
and normalize the resulting peak again toμ = 0
andσ = 1
-->h_after
aoe_ctc_func
.Some things that would need some manual testing
There are some hard-coded values and some pseudo priors need to be improved for the fit to converge towards something reasonable. I will mark the hard coded values right after opening the PR.$fct$ in the fit, etc.
These include histogram ranges, boundaries for
How to use it