Skip to content

Commit 07a225e

Browse files
committed
Add keyword crystal_impurity to load impurity density from crystal metadata
1 parent f904c0f commit 07a225e

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

ext/LegendDataManagementSolidStateDetectorsExt.jl

+37-31
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,34 @@ LegendDataManagement provides an extension for SolidStateDetectors, a
4646
`SolidStateDetector` can be constructed from LEGEND metadata using the
4747
methods above.
4848
"""
49-
function SolidStateDetectors.SolidStateDetector(data::LegendData, detector::DetectorIdLike)
50-
SolidStateDetectors.SolidStateDetector{_SSDDefaultNumtype}(data, detector)
49+
function SolidStateDetectors.SolidStateDetector(data::LegendData, detector::DetectorIdLike; kwargs...)
50+
SolidStateDetectors.SolidStateDetector{_SSDDefaultNumtype}(data, detector; kwargs...)
5151
end
5252

53-
function SolidStateDetectors.SolidStateDetector{T}(data::LegendData, detector::DetectorIdLike) where {T<:AbstractFloat}
53+
function SolidStateDetectors.SolidStateDetector{T}(data::LegendData, detector::DetectorIdLike; kwargs...) where {T<:AbstractFloat}
5454
detector_props = getproperty(data.metadata.hardware.detectors.germanium.diodes, Symbol(detector))
5555
xtal_props = getproperty(data.metadata.hardware.detectors.germanium.crystals, Symbol(string(detector)[1:end-1]))
56-
SolidStateDetector{T}(LegendData, detector_props, xtal_props)
56+
SolidStateDetector{T}(LegendData, detector_props, xtal_props; kwargs...)
5757
end
5858

59-
function SolidStateDetectors.SolidStateDetector{T}(::Type{LegendData}, filename::String) where {T<:AbstractFloat}
60-
SolidStateDetector{T}(LegendData, readprops(filename, subst_pathvar = false, subst_env = false, trim_null = false))
59+
function SolidStateDetectors.SolidStateDetector{T}(::Type{LegendData}, filename::String; kwargs...) where {T<:AbstractFloat}
60+
SolidStateDetector{T}(LegendData, readprops(filename, subst_pathvar = false, subst_env = false, trim_null = false); kwargs...)
6161
end
6262

63-
function SolidStateDetectors.SolidStateDetector(::Type{LegendData}, filename::String)
64-
SolidStateDetector{_SSDDefaultNumtype}(LegendData, filename)
63+
function SolidStateDetectors.SolidStateDetector(::Type{LegendData}, filename::String; kwargs...)
64+
SolidStateDetector{_SSDDefaultNumtype}(LegendData, filename; kwargs...)
6565
end
6666

67-
function SolidStateDetectors.SolidStateDetector(::Type{LegendData}, meta::AbstractDict)
68-
SolidStateDetectors.SolidStateDetector{_SSDDefaultNumtype}(LegendData, meta)
67+
function SolidStateDetectors.SolidStateDetector(::Type{LegendData}, meta::AbstractDict; kwargs...)
68+
SolidStateDetectors.SolidStateDetector{_SSDDefaultNumtype}(LegendData, meta; kwargs...)
6969
end
7070

71-
function SolidStateDetectors.SolidStateDetector{T}(::Type{LegendData}, meta::AbstractDict) where {T<:AbstractFloat}
72-
SolidStateDetectors.SolidStateDetector{T}(LegendData, convert(PropDict, meta), LegendDataManagement.NoSuchPropsDBEntry("",[]))
71+
function SolidStateDetectors.SolidStateDetector{T}(::Type{LegendData}, meta::AbstractDict; kwargs...) where {T<:AbstractFloat}
72+
SolidStateDetectors.SolidStateDetector{T}(LegendData, convert(PropDict, meta), LegendDataManagement.NoSuchPropsDBEntry("",[]); kwargs...)
7373
end
7474

75-
function SolidStateDetectors.SolidStateDetector{T}(::Type{LegendData}, meta::PropDict, xtal_meta::Union{PropDict, LegendDataManagement.NoSuchPropsDBEntry}) where {T<:AbstractFloat}
76-
config_dict = create_SSD_config_dict_from_LEGEND_metadata(meta, xtal_meta)
75+
function SolidStateDetectors.SolidStateDetector{T}(::Type{LegendData}, meta::PropDict, xtal_meta::Union{PropDict, LegendDataManagement.NoSuchPropsDBEntry}; kwargs...) where {T<:AbstractFloat}
76+
config_dict = create_SSD_config_dict_from_LEGEND_metadata(meta, xtal_meta; kwargs...)
7777
return SolidStateDetector{T}(config_dict, SolidStateDetectors.construct_units(config_dict))
7878
end
7979

@@ -86,39 +86,39 @@ LegendDataManagement provides an extension for SolidStateDetectors, a
8686
`Simulation` can be constructed from LEGEND metadata using the
8787
methods above.
8888
"""
89-
function SolidStateDetectors.Simulation(data::LegendData, detector::DetectorIdLike)
90-
SolidStateDetectors.Simulation{_SSDDefaultNumtype}(data, detector)
89+
function SolidStateDetectors.Simulation(data::LegendData, detector::DetectorIdLike; kwargs...)
90+
SolidStateDetectors.Simulation{_SSDDefaultNumtype}(data, detector; kwargs...)
9191
end
9292

93-
function SolidStateDetectors.Simulation{T}(data::LegendData, detector::DetectorIdLike) where {T<:AbstractFloat}
93+
function SolidStateDetectors.Simulation{T}(data::LegendData, detector::DetectorIdLike; kwargs...) where {T<:AbstractFloat}
9494
detector_props = getproperty(data.metadata.hardware.detectors.germanium.diodes, Symbol(detector))
9595
xtal_props = getproperty(data.metadata.hardware.detectors.germanium.crystals, Symbol(string(detector)[1:end-1]))
96-
Simulation{T}(LegendData, detector_props, xtal_props)
96+
Simulation{T}(LegendData, detector_props, xtal_props; kwargs...)
9797
end
9898

99-
function SolidStateDetectors.Simulation{T}(::Type{LegendData}, filename::String) where {T<:AbstractFloat}
100-
Simulation{T}(LegendData, readprops(filename, subst_pathvar = false, subst_env = false, trim_null = false))
99+
function SolidStateDetectors.Simulation{T}(::Type{LegendData}, filename::String; kwargs...) where {T<:AbstractFloat}
100+
Simulation{T}(LegendData, readprops(filename, subst_pathvar = false, subst_env = false, trim_null = false); kwargs...)
101101
end
102102

103-
function SolidStateDetectors.Simulation(::Type{LegendData}, filename::String)
104-
Simulation{_SSDDefaultNumtype}(LegendData, filename)
103+
function SolidStateDetectors.Simulation(::Type{LegendData}, filename::String; kwargs...)
104+
Simulation{_SSDDefaultNumtype}(LegendData, filename; kwargs...)
105105
end
106106

107-
function SolidStateDetectors.Simulation(::Type{LegendData}, meta::AbstractDict)
108-
SolidStateDetectors.Simulation{_SSDDefaultNumtype}(LegendData, meta)
107+
function SolidStateDetectors.Simulation(::Type{LegendData}, meta::AbstractDict; kwargs...)
108+
SolidStateDetectors.Simulation{_SSDDefaultNumtype}(LegendData, meta; kwargs...)
109109
end
110110

111-
function SolidStateDetectors.Simulation{T}(::Type{LegendData}, meta::AbstractDict) where {T<:AbstractFloat}
112-
SolidStateDetectors.Simulation{T}(LegendData, convert(PropDict, meta), LegendDataManagement.NoSuchPropsDBEntry("", []))
111+
function SolidStateDetectors.Simulation{T}(::Type{LegendData}, meta::AbstractDict; kwargs...) where {T<:AbstractFloat}
112+
SolidStateDetectors.Simulation{T}(LegendData, convert(PropDict, meta), LegendDataManagement.NoSuchPropsDBEntry("", []); kwargs...)
113113
end
114114

115-
function SolidStateDetectors.Simulation{T}(::Type{LegendData}, meta::PropDict, xtal_meta::Union{PropDict, LegendDataManagement.NoSuchPropsDBEntry}) where {T<:AbstractFloat}
116-
config_dict = create_SSD_config_dict_from_LEGEND_metadata(meta, xtal_meta)
115+
function SolidStateDetectors.Simulation{T}(::Type{LegendData}, meta::PropDict, xtal_meta::Union{PropDict, LegendDataManagement.NoSuchPropsDBEntry}; kwargs...) where {T<:AbstractFloat}
116+
config_dict = create_SSD_config_dict_from_LEGEND_metadata(meta, xtal_meta; kwargs...)
117117
return Simulation{T}(config_dict)
118118
end
119119

120120

121-
function create_SSD_config_dict_from_LEGEND_metadata(meta::PropDict, xtal_meta::X; dicttype = Dict{String,Any}) where {X <: Union{PropDict, LegendDataManagement.NoSuchPropsDBEntry}}
121+
function create_SSD_config_dict_from_LEGEND_metadata(meta::PropDict, xtal_meta::X; dicttype = Dict{String,Any}, crystal_impurity::Bool = false) where {X <: Union{PropDict, LegendDataManagement.NoSuchPropsDBEntry}}
122122

123123
# Not all possible configurations are yet implemented!
124124
# https://github.com/legend-exp/legend-metadata/blob/main/hardware/detectors/detector-metadata_1.pdf
@@ -564,8 +564,14 @@ function create_SSD_config_dict_from_LEGEND_metadata(meta::PropDict, xtal_meta::
564564
@warn "No information regarding impurity density for $(xtal_meta.name)"
565565
end
566566

567-
config_dict["detectors"][1]["semiconductor"]["impurity_density"] = \
568-
if X == PropDict && haskey(xtal_meta, :impurity_measurements)
567+
if !crystal_impurity
568+
@warn """
569+
Reading the impurity density from the crystal metadata will be ignored.
570+
Set `crystal_impurity=true` to load the impurity density from the crystal metadata
571+
"""
572+
end
573+
574+
config_dict["detectors"][1]["semiconductor"]["impurity_density"] = if X == PropDict && haskey(xtal_meta, :impurity_measurements) && crystal_impurity
569575
@info "Reading impurity density values from crystal metadata $(xtal_meta.name)"
570576
# Fit the impurity measurement data to a Radford model
571577
@. fit_model(z, p) = p[1] + p[2]*z + p[3]*exp((z-p[5])/p[4])

0 commit comments

Comments
 (0)