77Calibrate all channels in the given datastore, using the metadata
88processing configuration for `data` and `sel`.
99"""
10- function calibrate_all (data:: LegendData , sel:: AnyValiditySelection , datastore:: AbstractDict ; tier:: DataTierLike = :jldsp )
10+ function calibrate_all (data:: LegendData , sel:: AnyValiditySelection , datastore:: AbstractDict , tier:: DataTierLike = :jldsp )
1111 ds = datastore
1212
13+ @debug " Calibrating all channels in for `ValiditySelection` $(sel) in `DataTier` $(tier) "
1314 chinfo = channelinfo (data, sel)
14- geds_channels:: Vector{ChannelId} = filterby (@pf $ system == :geds && $ processable && $ usability != :off && $ is_blinded)(chinfo). channel
15- spms_channels:: Vector{ChannelId} = filterby (@pf $ system == :spms && $ processable)(chinfo). channel
16- puls_channels:: Vector{ChannelId} = filterby (@pf $ system in [:puls , :bsln ])(chinfo). channel
17-
15+ geds_channels:: Vector{ChannelId} = filterby (get_ged_evt_chsel_propfunc (data, sel))(chinfo). channel
16+ @debug " Loaded $(length (geds_channels)) HPGe channels"
17+ hitgeds_channels:: Vector{ChannelId} = filterby (get_ged_evt_hitchsel_propfunc (data, sel))(chinfo). channel
18+ @debug " Loaded $(length (hitgeds_channels)) HPGe hit channels"
19+ spms_channels:: Vector{ChannelId} = filterby (get_spms_evt_chsel_propfunc (data, sel))(chinfo). channel
20+ @debug " Loaded $(length (spms_channels)) SiPM channels"
21+ aux_channels:: Vector{ChannelId} = filterby (get_aux_evt_chsel_propfunc (data, sel))(chinfo). channel
22+ @debug " Loaded auxiliary channels: $(join (string .(filterby (get_aux_evt_chsel_propfunc (data, sel))(chinfo). detector), " , " )) "
1823
1924 # HPGe:
20-
21- ged_caldata = Dict ([
22- let detector = channelinfo (data, sel, channel). detector,
23- chdata = ds[channel, tier][:]
24- channel => calibrate_ged_channel_data (data, sel, detector, chdata)
25+ @debug " Calibrating HPGe channels"
26+ ged_kwargs = get_ged_evt_kwargs (data, sel)
27+ ged_caldata_v = Vector {StructVector} (undef, length (geds_channels))
28+ Threads. @threads for i in eachindex (geds_channels)
29+ let detector = channelinfo (data, sel, geds_channels[i]). detector, chdata = ds[geds_channels[i], tier][:]
30+ ged_caldata_v[i] = calibrate_ged_channel_data (data, sel, detector, chdata; ged_kwargs... )
2531 end
26- for channel in geds_channels
27- ] )
32+ end
33+ ged_caldata = Dict (geds_channels .=> ged_caldata_v )
2834
35+ @debug " Building global events for HPGe channels"
2936 ged_events_pre = build_global_events (ged_caldata, geds_channels)
3037
3138 min_t0 (t0:: AbstractVector{<:Number} ) = isempty (t0) ? eltype (t0)(NaN ) : minimum (t0)
@@ -47,23 +54,29 @@ function calibrate_all(data::LegendData, sel::AnyValiditySelection, datastore::A
4754
4855 maximum_with_init (A) = maximum (A, init= zero (eltype ((A))))
4956
57+ is_valid_hit (trig_chs:: AbstractVector{<:Int} , hit_channels:: AbstractVector{<:Int} ) = all (x -> x in hit_channels, trig_chs)
58+ # Main.@infiltrate
59+
5060 ged_additional_cols = (
5161 t0_start = min_t0 .(trig_t0),
5262 trig_t0 = trig_t0,
5363 multiplicity = n_trig,
54- max_e_ch = max_e_ch,
64+ max_e_ch_idxs = max_e_ch,
65+ max_e_ch = only .(getindex .(ged_events_pre. channel, max_e_ch)),
5566 max_e_trap_cal = maximum_with_init .(trig_e_trap_cal),
5667 max_e_cusp_cal = maximum_with_init .(trig_e_cusp_cal),
5768 max_e_trap_ctc_cal = maximum_with_init .(trig_e_trap_ctc_cal),
5869 max_e_cusp_ctc_cal = maximum_with_init .(trig_e_cusp_ctc_cal),
5970 max_e_short_cal = maximum_with_init .(trig_e_short_cal),
60- trig_e_ch = trig_e_ch,
71+ trig_e_ch_idxs = trig_e_ch,
72+ trig_e_ch = getindex .(ged_events_pre. channel, trig_e_ch),
6173 trig_e_trap_cal = trig_e_trap_cal,
6274 trig_e_cusp_cal = trig_e_cusp_cal,
6375 trig_e_trap_ctc_cal = trig_e_trap_ctc_cal,
6476 trig_e_cusp_ctc_cal = trig_e_cusp_ctc_cal,
6577 trig_e_short_cal = trig_e_short_cal,
6678 is_valid_qc = count .(ged_events_pre. is_baseline) .== n_expected_baseline,
79+ is_valid_hit = is_valid_hit .(getindex .(ged_events_pre. channel, trig_e_ch), Ref (Int .(hitgeds_channels))),
6780 is_discharge_recovery = any .(ged_events_pre. is_discharge_recovery_ml),
6881 is_saturated = any .(ged_events_pre. is_saturated),
6982 is_discharge = any .(ged_events_pre. is_discharge),
@@ -72,41 +85,41 @@ function calibrate_all(data::LegendData, sel::AnyValiditySelection, datastore::A
7285
7386
7487 # SiPM:
75-
76- spm_caldata = Dict ([
77- let detector = channelinfo (data, sel, channel) . detector,
78- chdata = ds[channel , tier][:]
79- channel => calibrate_spm_channel_data (data, sel, detector, chdata)
88+ @debug " Calibrating SiPM channels "
89+ spm_caldata_v = Vector {StructVector} (undef, length (spms_channels))
90+ Threads . @threads for i in eachindex (spms_channels)
91+ let detector = channelinfo (data, sel, spms_channels[i]) . detector, chdata = ds[spms_channels[i] , tier][:]
92+ spm_caldata_v[i] = calibrate_spm_channel_data (data, sel, detector, chdata)
8093 end
81- for channel in spms_channels
82- ])
94+ end
95+ spm_caldata = Dict (spms_channels .=> spm_caldata_v)
96+ @debug " Building global events for SiPM channels"
8397 spm_events_novov = build_global_events (spm_caldata, spms_channels)
8498 spm_events = StructArray (map (_fix_vov, columns (spm_events_novov)))
8599
86-
87- # Pulser:
88-
89- pls_caldata = Dict ([
90- let detector = channelinfo (data, sel, channel). detector,
91- chdata = ds[channel, tier][:]
92- channel => calibrate_pls_channel_data (data, sel, detector, chdata)
93- end
94- for channel in puls_channels if haskey (ds, string (channel))
95- ])
96- pls_events = build_global_events (pls_caldata, puls_channels)
97100
101+ @debug " Calibrating auxiliary channels"
102+ # aux & Forced Trigger
103+ aux_caldata =
104+ [Dict (
105+ let detector = channelinfo (data, sel, channel). detector,
106+ chdata = ds[channel, tier][:]
107+ channel => calibrate_aux_channel_data (data, sel, detector, chdata)
108+ end
109+ ) for channel in aux_channels]
110+ @debug " Building global events for auxiliary channels"
111+ aux_events = NamedTuple {Tuple(get_aux_evt_levelname_propfunc.(Ref(data), Ref(sel), reduce(vcat, collect.(keys.(aux_caldata)))))} (build_global_events .(aux_caldata))
98112
99113 # Cross-system:
100-
101- system_events = (
114+ @debug " Building cross-system events "
115+ system_events = merge ( (
102116 geds = ged_events,
103117 spms = spm_events,
104- puls = pls_events,
105- )
118+ ), aux_events)
106119
107120 global_events_pre = build_cross_system_events (system_events)
108- single_pls_col = StructVector (map (Broadcast. BroadcastFunction (only), columns (global_events_pre. puls)) )
109- global_events = StructVector (merge (columns (global_events_pre), (puls = single_pls_col ,)))
121+ aux_cols = NamedTuple {keys(aux_events)} ([ StructVector (map (Broadcast. BroadcastFunction (only), columns (getproperty ( global_events_pre, k)))) for k in keys (aux_events)] )
122+ global_events = StructVector (merge (Base . structdiff ( columns (global_events_pre), NamedTuple{ keys (aux_events)}), (aux = StructArray (aux_cols) ,)))
110123
111124 cross_systems_cols = (
112125 ged_spm = _build_lar_cut (global_events),
0 commit comments