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

Patch channelinfo #88

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/exposure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,7 @@ function _get_exposure(data::LegendData, det::DetectorIdLike, rinfo::Table, is_a
mass = if !iszero(livetime) && !isempty(filekeys)
# read in the channelinfo
filekey = first(filekeys)
_chinfo = channelinfo(data, filekey, det, extended = true, verbose = false)
chinfo = if !all(x -> hasproperty(_chinfo, x), (:enrichment, :mass, :active_volume, :total_volume))
empty!(_cached_channelinfo)
channelinfo(data, filekey, det, extended = true, verbose = false)
else
_chinfo
end
# chinfo.active_volume == chinfo.total_volume && @warn "No FCCD value given for detector $(det)"
chinfo = channelinfo(data, filekey, det, extended = true, verbose = false)
chinfo.mass * chinfo.enrichment * chinfo.active_volume / chinfo.total_volume
else
0.0u"kg"
Expand Down
13 changes: 7 additions & 6 deletions src/legend_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function find_filekey(data::LegendData, ts; kwargs...)
end


const _cached_channelinfo = LRU{Tuple{UInt, AnyValiditySelection}, StructVector}(maxsize = 10^3)
const _cached_channelinfo = LRU{Tuple{UInt, AnyValiditySelection, Bool}, StructVector}(maxsize = 10^3)

"""
channelinfo(data::LegendData, sel::AnyValiditySelection; system::Symbol = :all, only_processable::Bool = false, only_usability::Symbol = :all, extended::Bool = false)
Expand All @@ -304,7 +304,7 @@ Get all channel information for the given [`LegendData`](@ref) and
[`ValiditySelection`](@ref).
"""
function channelinfo(data::LegendData, sel::AnyValiditySelection; system::Symbol = :all, only_processable::Bool = false, only_usability::Symbol = :all, sort_by::Symbol=:detector, extended::Bool = false, verbose::Bool = true)
key = (objectid(data), sel)
key = (objectid(data), sel, extended)
chinfo = get!(_cached_channelinfo, key) do
chmap = data.metadata(sel).hardware.configuration.channelmaps
diodmap = data.metadata.hardware.detectors.germanium.diodes
Expand Down Expand Up @@ -351,13 +351,14 @@ function channelinfo(data::LegendData, sel::AnyValiditySelection; system::Symbol
low_aoe_status::Symbol = Symbol(get(get(get(dpcfg[k], :psd, PropDict()), :status, PropDict()), Symbol("low_aoe"), :unknown))
high_aoe_status::Symbol = Symbol(get(get(get(dpcfg[k], :psd, PropDict()), :status, PropDict()), Symbol("high_aoe"), :unknown))
lq_status::Symbol = Symbol(get(get(get(dpcfg[k], :psd, PropDict()), :status, PropDict()), Symbol("lq"), :unknown))
batch5_dt_cut::Symbol = Symbol(get(get(get(dpcfg[k], :psd, PropDict()), :status, PropDict()), Symbol("batch5_dt_cut"), :unknown))
ann_status::Symbol = Symbol(get(get(get(dpcfg[k], :psd, PropDict()), :status, PropDict()), Symbol("ann"), :unknown))
coax_rt_status::Symbol = Symbol(get(get(get(dpcfg[k], :psd, PropDict()), :status, PropDict()), Symbol("coax_rt"), :unknown))
theHenks marked this conversation as resolved.
Show resolved Hide resolved
is_bb_like::String = replace(get(get(dpcfg[k], :psd, PropDict()), :is_bb_like, ""), "&" => "&&")

location::Symbol, detstring::Int, position::Int, fiber::StaticString{8} = _convert_location(chmap[k].location)

c = (;
detector, channel, fcid, rawid, system, processable, usability, is_blinded, low_aoe_status, high_aoe_status, lq_status, batch5_dt_cut, is_bb_like, det_type,
detector, channel, fcid, rawid, system, processable, usability, is_blinded, low_aoe_status, high_aoe_status, lq_status, ann_status, coax_rt_status, is_bb_like, det_type,
location, detstring, fiber, position
)

Expand All @@ -375,8 +376,8 @@ function channelinfo(data::LegendData, sel::AnyValiditySelection; system::Symbol
total_volume::Unitful.Volume{<:Float64} = if haskey(diodmap, k) get_active_volume(diodmap[k], 0.0) else Float64(NaN) * u"cm^3" end
fccds = diodmap[k].characterization.l200_site.fccd_in_mm
fccd::Float64 = if isa(fccds, NoSuchPropsDBEntry) ||
isa(fccds, PropDicts.MissingProperty) ||
isa(fccds[first(keys(fccds))].value, PropDicts.MissingProperty)
isa(fccds, PropDicts.MissingProperty) ||
isa(fccds[first(keys(fccds))].value, PropDicts.MissingProperty)

verbose && haskey(diodmap, k) && @warn "No FCCD value given for detector $(detector)"
0.0
Expand Down
3 changes: 0 additions & 3 deletions test/test_legend_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ include("testing_utils.jl")
@test all(filterby(@pf $processable && $usability == :on)(chinfo).processable)
@test all(filterby(@pf $processable && $usability == :on)(chinfo).usability .== :on)

# Delete the channelinfo cache
empty!(LegendDataManagement._cached_channelinfo)

# Test the extended channel info with active volume calculation
extended = channelinfo(l200, filekey, only_usability = :on, extended = true)
@test extended isa TypedTables.Table
Expand Down
Loading