Skip to content

Commit 391ed7e

Browse files
authored
Merge pull request #124 from DaGeibl/main
updated LQ sideband selection logic
2 parents c0b6507 + 3632ef8 commit 391ed7e

File tree

2 files changed

+65
-15
lines changed

2 files changed

+65
-15
lines changed

ext/LegendSpecFitsRecipesBaseExt.jl

+40-10
Original file line numberDiff line numberDiff line change
@@ -1390,9 +1390,9 @@ end
13901390
xlabel := "Drift Time"
13911391
ylabel := "LQ (A.U.)"
13921392
framestyle := :box
1393-
left_margin := -2Plots.mm
1394-
bottom_margin := -4Plots.mm
1395-
top_margin := -3Plots.mm
1393+
left_margin := (-2, :mm)
1394+
bottom_margin := (-4, :mm)
1395+
top_margin := (-3, :mm)
13961396
color := :viridis
13971397
formatter := :plain
13981398
thickness_scaling := 1.6
@@ -1476,15 +1476,15 @@ end
14761476

14771477
# recipe for the lq_cut report
14781478

1479-
@recipe function f(report::NamedTuple{(:cut, :fit_result, :temp_hists, :fit_report)}, lq_class::Vector{Float64}, e_cal, plot_type::Symbol)
1479+
@recipe function f(report::NamedTuple{(:cut, :fit_result, :temp_hists, :fit_report, :dep_σ, :edges)}, lq_class::Vector{Float64}, e_cal, plot_type::Symbol)
14801480

14811481
# Extract cutvalue from the report
14821482
cut_value = Measurements.value.(report.cut)
14831483

14841484
# Plot configuration for all types
1485-
left_margin := -2Plots.mm
1486-
bottom_margin := -4Plots.mm
1487-
top_margin := -3Plots.mm
1485+
left_margin := (-2, :mm)
1486+
bottom_margin := (-4, :mm)
1487+
top_margin := (-3, :mm)
14881488
thickness_scaling := 1.6
14891489
size := (1200, 900)
14901490
framestyle := :box
@@ -1662,10 +1662,40 @@ end
16621662
report.temp_hists.hist_sb2
16631663
end
16641664

1665-
1665+
elseif plot_type == :energy_spectrum
1666+
# Plot energy spectrum with DEP and sideband regions
1667+
left_margin := (-2, :mm)
1668+
bottom_margin := (-4, :mm)
1669+
top_margin := (-3, :mm)
1670+
thickness_scaling := 1.6
1671+
size := (1200, 900)
1672+
framestyle := :box
1673+
formatter := :plain
1674+
xlabel := "Energy"
1675+
ylabel := "Counts"
1676+
1677+
@series begin
1678+
seriestype := :stephist
1679+
label := "Energy Spectrum (σ: $(round(u"keV", report.dep_σ, sigdigits=3)))"
1680+
bins := 1000
1681+
e_cal[1500u"keV" .< e_cal .< 1660u"keV"]
1682+
end
1683+
1684+
@series begin
1685+
seriestype := :vline
1686+
label := "DEP Region"
1687+
fillcolor := :red
1688+
[report.edges.DEP_edge_left, report.edges.DEP_edge_right]
1689+
end
1690+
1691+
@series begin
1692+
seriestype := :vline
1693+
label := "Sideband Edges"
1694+
fillcolor := :green
1695+
legend := :topleft
1696+
[report.edges.sb1_edge, report.edges.sb2_edge]
1697+
end
16661698
end
16671699
end
16681700

1669-
1670-
16711701
end # module LegendSpecFitsRecipesBaseExt

src/lqcut.jl

+25-5
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,29 @@ function lq_cut(
159159
dep_µ::Unitful.Energy, dep_σ::Unitful.Energy, e_cal::Vector{<:Unitful.Energy}, lq_classifier::Vector{<:AbstractFloat}; cut_sigma::Float64=3.0, dep_sideband_sigma::Float64=4.5, cut_truncation_sigma::Float64=3.5, uncertainty::Bool=true
160160
)
161161

162-
# define sidebands
163-
lq_dep = lq_classifier[dep_µ - dep_sideband_sigma * dep_σ .< e_cal .< dep_µ + dep_sideband_sigma * dep_σ]
164-
lq_sb1 = lq_classifier[dep_µ - 2 * dep_sideband_sigma * dep_σ .< e_cal .< dep_µ - dep_sideband_sigma * dep_σ]
165-
lq_sb2 = lq_classifier[dep_µ + dep_sideband_sigma * dep_σ .< e_cal .< dep_µ + 2 * dep_sideband_sigma * dep_σ]
166-
162+
# define sidebands; different for low and high energy resolution detectors to avoid sb reaching into 212-Bi FEP
163+
DEP_edge_left = dep_µ - dep_sideband_sigma * dep_σ
164+
DEP_edge_right = dep_µ + dep_sideband_sigma * dep_σ
165+
166+
if dep_σ < 2.0u"keV"
167+
sb1_edge = dep_µ - 2 * dep_sideband_sigma * dep_σ
168+
sb2_edge = dep_µ + 2 * dep_sideband_sigma * dep_σ
169+
170+
lq_dep = lq_classifier[DEP_edge_left .< e_cal .< DEP_edge_right]
171+
lq_sb1 = lq_classifier[sb1_edge .< e_cal .< DEP_edge_left]
172+
lq_sb2 = lq_classifier[DEP_edge_right .< e_cal .< sb2_edge]
173+
else
174+
sb1_edge = dep_µ - 2 * dep_sideband_sigma * dep_σ
175+
sb2_edge = dep_µ - 3 * dep_sideband_sigma * dep_σ
176+
177+
lq_dep = lq_classifier[DEP_edge_left .< e_cal .< DEP_edge_right]
178+
lq_sb1 = lq_classifier[sb1_edge .< e_cal .< DEP_edge_left]
179+
lq_sb2 = lq_classifier[sb2_edge .< e_cal .< sb1_edge]
180+
end
181+
182+
# save edges for crosschecks
183+
edges_for_crosschecks = (;DEP_edge_left, DEP_edge_right, sb1_edge, sb2_edge)
184+
167185
# generate values for histogram edges
168186
combined = filter(isfinite,[lq_dep; lq_sb1; lq_sb2])
169187
ideal_bin_width = get_friedman_diaconis_bin_width(combined)
@@ -206,6 +224,8 @@ function lq_cut(
206224
fit_result = fit_result,
207225
temp_hists = temp_hists,
208226
fit_report = fit_report,
227+
dep_σ = dep_σ,
228+
edges = edges_for_crosschecks,
209229
)
210230

211231
return result, report

0 commit comments

Comments
 (0)