@@ -13,6 +13,8 @@ function calibrate_spm_channel_data(data::LegendData, sel::AnyValiditySelection,
1313 chdata = channel_data[:]
1414
1515 spmcal_pf = get_spm_cal_propfunc (data, sel, detector)
16+ spmdc_sel_pf = get_spm_dc_sel_propfunc (data, sel, detector)
17+ spmdc_cal_pf = get_spm_dc_cal_propfunc (data, sel, detector)
1618
1719 # get additional cols to be parsed into the event tier
1820 chdata_output_pf = if keep_chdata
@@ -24,9 +26,12 @@ function calibrate_spm_channel_data(data::LegendData, sel::AnyValiditySelection,
2426 cal_output_novv = spmcal_pf .(chdata)
2527 cal_output = StructArray (map (VectorOfArrays, columns (cal_output_novv)))
2628
29+ dc_output_novv = NamedTuple {keys(spmdc_sel_pf)} ([spmdc_cal_pf[e_type]. (spmdc_sel_pf[e_type]. (chdata)) for e_type in keys (spmdc_sel_pf)])
30+ dc_output = StructArray (map (VectorOfArrays, columns (dc_output_novv)))
31+
2732 chdata_output = chdata_output_pf .(chdata)
2833
29- return StructVector (merge (columns (cal_output), columns (chdata_output)))
34+ return StructVector (merge (columns (cal_output), columns (dc_output), columns ( chdata_output)))
3035end
3136export calibrate_spm_channel_data
3237
@@ -45,34 +50,55 @@ function _single_fiber_esum(
4550end
4651
4752
48- # ToDo: Make cut criteria configurable:
4953function _lar_cut (
54+ colnames:: Tuple{Symbol, Symbol, Symbol} ,
5055 t_win:: AbstractInterval , spm_t:: AbstractVector{<:AbstractVector{<:Number}} ,
51- spmdc:: AbstractVector{<:AbstractVector{<:Number}} , spm_pe:: AbstractVector{<:AbstractVector{<:Number}}
56+ spmdc:: AbstractVector{<:AbstractVector{<:Number}} , spm_pe:: AbstractVector{<:AbstractVector{<:Number}} ,
57+ pe_ch_threshold:: Quantity{<:Real} , pe_sum_threshold:: Quantity{<:Real} , multiplicity_threshold:: Int
5258)
5359 n_over_thresh:: Int = 0
5460 pe_sum:: eltype (eltype (spm_pe)) = zero (eltype (eltype (spm_pe)))
5561 for i in eachindex (spm_t)
5662 s_i = _single_fiber_esum (t_win, spm_t[i], spmdc[i], spm_pe[i])
57- if s_i > 0.5
63+ if s_i > pe_ch_threshold
5864 n_over_thresh += 1
5965 end
6066 pe_sum += s_i
6167 end
6268
63- lar_cut = n_over_thresh >= 4 || pe_sum >= 4
69+ lar_cut = Bool ( n_over_thresh >= multiplicity_threshold || pe_sum >= pe_sum_threshold)
6470
65- return (lar_cut = lar_cut, spms_win_pe_sum = pe_sum, spms_win_multiplicity = n_over_thresh)
71+ return NamedTuple {colnames, Tuple{Bool, eltype(eltype(spm_pe)), Int}} ([ lar_cut, pe_sum, n_over_thresh] )
6672end
6773
68-
69- # ToDo: Make time window configurable:
70- function _build_lar_cut (global_events:: AbstractVector{<:NamedTuple} )
74+ function _build_lar_cut (data:: LegendData , sel:: AnyValiditySelection , global_events:: AbstractVector{<:NamedTuple} , e_filter:: Symbol )
7175 geds_t0 = global_events. geds. t0_start
72- spm_t = global_events. spms. trig_pos
73- spmdc = global_events. spms. trig_is_dc
74- spm_pe = global_events. spms. trig_pe
76+
77+ dataprod_larcut = get_spms_evt_lar_cut_props (data, sel)
78+ dataprod_larcut_filter = dataprod_larcut. energy_types[e_filter]
79+
80+ spm_t = getproperty (global_events. spms, Symbol (dataprod_larcut_filter. pos))
81+ spmdc = getproperty (global_events. spms, Symbol (dataprod_larcut_filter. is_dc))
82+ spm_pe = getproperty (global_events. spms, e_filter)
83+
84+ ged_sum_window = dataprod_larcut. ged_sum_window
85+
86+ t_wins = ClosedInterval .(geds_t0 .+ first (ged_sum_window), geds_t0 .+ last (ged_sum_window))
87+
88+ pe_ch_threshold = dataprod_larcut. pe_ch_threshold
89+ pe_sum_threshold = dataprod_larcut. pe_sum_threshold
90+ multiplicity_threshold = dataprod_larcut. multiplicity_threshold
91+
92+ colnames = Tuple (Symbol .(" $(e_filter) _" .* [" lar_cut" , " spms_win_pe_sum" , " spms_win_multiplicity" ]))
93+ return StructArray (_lar_cut .(Ref (colnames), t_wins, spm_t, spmdc, spm_pe, Ref (pe_ch_threshold), Ref (pe_sum_threshold), Ref (multiplicity_threshold)))
94+ end
95+
96+ function _build_lar_cut (data:: LegendData , sel:: AnyValiditySelection , global_events:: AbstractVector{<:NamedTuple} )
97+ dataprod_larcut = get_spms_evt_lar_cut_props (data, sel)
98+ energy_types = keys (dataprod_larcut. energy_types)
99+
100+ is_valid_lar_propfunc = ljl_propfunc (dataprod_larcut. is_valid_lar)
75101
76- t_wins = @. ClosedInterval (geds_t0 - 1 u " μs " , geds_t0 + 5 u " μs " )
77- return StructArray (_lar_cut .(t_wins, spm_t, spmdc, spm_pe ))
102+ lar_cut = StructArray ( merge ( columns .( _build_lar_cut .( Ref (data), Ref (sel), Ref (global_events), energy_types)) ... ) )
103+ return StructArray (merge ((is_valid_lar = is_valid_lar_propfunc .(lar_cut),), columns (lar_cut) ))
78104end
0 commit comments