Skip to content

Commit

Permalink
Merge pull request #87 from fhagemann/fccd
Browse files Browse the repository at this point in the history
Add uncertainties for active volume calculation
  • Loading branch information
fhagemann authored Jan 24, 2025
2 parents f559492 + 769ce11 commit 41eb3c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
24 changes: 11 additions & 13 deletions src/legend_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,24 +370,22 @@ function channelinfo(data::LegendData, sel::AnyValiditySelection; system::Symbol
hvcard::Int = get(chmap[k].voltage.card, :id, -1)
hvch::Int = get(chmap[k].voltage, :channel, -1)

enrichment::Unitful.Quantity{<:Measurement{<:Float64}} = if haskey(diodmap, k) && haskey(diodmap[k].production, :enrichment) measurement(diodmap[k].production.enrichment.val, diodmap[k].production.enrichment.unc) else measurement(Float64(NaN), Float64(NaN)) end *100u"percent"
mass::Unitful.Mass{<:Float64} = if haskey(diodmap, k) && haskey(diodmap[k].production, :mass_in_g) diodmap[k].production.mass_in_g else Float64(NaN) end *1e-3*u"kg"
enrichment::Unitful.Quantity{<:Measurement{Float64}} = if haskey(diodmap, k) && haskey(diodmap[k].production, :enrichment) measurement(diodmap[k].production.enrichment.val, diodmap[k].production.enrichment.unc) else measurement(Float64(NaN), Float64(NaN)) end *100u"percent"
mass::Unitful.Mass{Float64} = if haskey(diodmap, k) && haskey(diodmap[k].production, :mass_in_g) diodmap[k].production.mass_in_g else Float64(NaN) end *1e-3*u"kg"

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)

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.combined_0vbb_analysis
fccd::Unitful.Length{<:Measurement{Float64}} = if isa(fccds, NoSuchPropsDBEntry) ||
isa(fccds, PropDicts.MissingProperty) ||
!haskey(fccds, :fccd_in_mm)
verbose && haskey(diodmap, k) && @warn "No FCCD value given for detector $(detector)"
0.0
measurement(0.0, 0.0) * u"mm"
else
fccds[first(keys(fccds))].value
measurement(fccds.fccd_in_mm.value, maximum(values(fccds.fccd_in_mm.uncertainty))) * u"mm"
end
active_volume::Unitful.Volume{<:Float64} = if haskey(diodmap, k) get_active_volume(diodmap[k], fccd) else Float64(NaN) * u"cm^3" end
c = merge(c, (; cc4, cc4ch, daqcrate, daqcard, hvcard, hvch, enrichment, mass, total_volume, active_volume))
active_volume::Unitful.Volume{<:Measurement{Float64}} = if haskey(diodmap, k) get_active_volume(diodmap[k], ustrip(u"mm", fccd)) else measurement(NaN, NaN) * u"cm^3" end
c = merge(c, (; cc4, cc4ch, daqcrate, daqcard, hvcard, hvch, enrichment, mass, total_volume, active_volume, fccd))
end

c
end

Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
Documenter = "1"
LegendTestData = "0.2.9"
LegendTestData = "0.2.10"
3 changes: 3 additions & 0 deletions test/test_legend_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using LegendDataManagement
using Test

using StructArrays, PropertyFunctions, TypedTables
using Measurements: uncertainty

include("testing_utils.jl")

Expand Down Expand Up @@ -38,6 +39,8 @@ include("testing_utils.jl")
extended_keywords = (:cc4, :cc4ch, :daqcrate, :daqcard, :hvcard, :hvch, :enrichment, :mass, :total_volume, :active_volume)
@test !any(in(columnnames(chinfo)), extended_keywords)
@test all(in(columnnames(extended)), extended_keywords)
@test !any(iszero.(uncertainty.(extended.fccd)))
@test !any(iszero.(uncertainty.(extended.active_volume)))

# ToDo: Make type-stable:
# @test #=@inferred=#(channel_info(l200, filekey)) isa StructArray
Expand Down

0 comments on commit 41eb3c8

Please sign in to comment.