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

A/E ctc correction #87

Merged
merged 6 commits into from
Dec 10, 2024
Merged

A/E ctc correction #87

merged 6 commits into from
Dec 10, 2024

Conversation

fhagemann
Copy link
Contributor

@fhagemann fhagemann commented Nov 6, 2024

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}$
with respect to $Q\text{drift}/E$ results in corrected, $Q\text{drift}/E$-independent $(A/E) \text{classifier}$-values.

$$(A/E)_\text{classifier}^\text{corrected} = (A/E)^\text{raw}_\text{classifier} + fct * Q\text{drift} / E$$

The steps of the algorithm are as follows:

  1. Create a mask to select all events that fill into the compton_bands provided to the function.
    image
  2. Create a histogram over all $(A/E)\text{classifier}$ in these compton_bands --> h_before
    image
  3. Apply different values of $fct$ and find the one resulting in the narrowest peak --> f_optimize_ctc
    image
  4. Apply the charge trapping correction for the optimal $fct$ and create a histogram --> h_norm
    image
  5. Fit h_norm and normalize the resulting peak again to μ = 0 and σ = 1 --> h_after
    image
  6. Return the value of $fct$ and a string to get to the charge-trapping-corrected, normalized $(A/E)\text{classifier}$ --> 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.
These include histogram ranges, boundaries for $fct$ in the fit, etc.

How to use it

# determine ecal, aoe and qdrift/e
e_expression = :e_cusp
ecal_all = getproperty(hit_cal, :e_cusp_ctc_cal)
aoe_all  = ljl_propfunc(result_correction.func).(hit_cal)
qdrift_e_all = hit_cal.qdrift ./ getproperty(hit_cal, e_expression);

# for the processor
result, report = LegendSpecFits.ctc_aoe(aoe_all, ecal_all, qdrift_e_all, compton_bands,
    aoe_expression = result_correction.func, e_expression = e_expression,
    pseudo_prior = NamedTupleDist(B = LogUniform(0.01,10000000), B2 = LogUniform(0.01,1000000)),
    pseudo_prior_all = NamedTupleDist(B = LogUniform(5,1000000000), B2 = LogUniform(0.01,1000000000)));

image

Copy link

codecov bot commented Nov 6, 2024

Codecov Report

Attention: Patch coverage is 0% with 58 lines in your changes missing coverage. Please review.

Project coverage is 21.00%. Comparing base (fe962f7) to head (7158782).
Report is 55 commits behind head on dev.

Files with missing lines Patch % Lines
src/aoe_ctc.jl 0.00% 57 Missing ⚠️
src/aoe_pseudo_prior.jl 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev      #87      +/-   ##
==========================================
- Coverage   21.89%   21.00%   -0.89%     
==========================================
  Files          34       36       +2     
  Lines        2973     3356     +383     
==========================================
+ Hits          651      705      +54     
- Misses       2322     2651     +329     

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

Copy link
Contributor Author

@fhagemann fhagemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to adjust the pseudo priors on B and B2 in order to obtain a fit that looks like the distribution. The choice of prior on B and B2 seems to influence the fit result:

No prior on B2
image

B2 = LogUniform(0.01,100000)
image

B2 = LogUniform(0.01,1000000)
image

@fhagemann fhagemann changed the title Aoe fit A/E ctc correction Nov 6, 2024
@fhagemann
Copy link
Contributor Author

fhagemann commented Nov 6, 2024

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

@fhagemann fhagemann linked an issue Nov 7, 2024 that may be closed by this pull request
@theHenks theHenks self-requested a review November 27, 2024 16:41
@theHenks theHenks added the enhancement New feature or request label Nov 27, 2024
@fhagemann
Copy link
Contributor Author

fhagemann commented Dec 2, 2024

With the latest commit, I updated the A/E pseudo priors for the double Gaussian mixture model, without modifying the priors used for the single low A/E tail one. It, therefore, should not affect the correction of the energy dependence of μ and σ.

I still need to see if these new priors perform well for ALL detectors. They seem to work well on detectors that were problematic before, though. Fingers crossed!

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.

Great work! @fhagemann and @verenaaur

@theHenks theHenks merged commit 3f5581d into legend-exp:dev Dec 10, 2024
7 of 9 checks passed
@fhagemann
Copy link
Contributor Author

Still missing: plot recipe for the ctc code (comparing before and after)

@fhagemann fhagemann deleted the aoe_fit branch December 11, 2024 13:50
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