Skip to content

Commit 46c6f3c

Browse files
authoredMar 14, 2025··
Add HPGeEnvironment (#91)
1 parent 05e5fb7 commit 46c6f3c

5 files changed

+63
-43
lines changed
 

‎Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Pkg = "1"
6262
Plots = "<0.0.1, 1"
6363
Printf = "<0.0.1, 1"
6464
ProgressMeter = "1.5"
65-
PropDicts = "0.2.4"
65+
PropDicts = "0.2.9"
6666
PropertyDicts = "0.2.1"
6767
PropertyFunctions = "0.2.2"
6868
RecipesBase = "1"

‎ext/LegendDataManagementSolidStateDetectorsExt.jl

+25-42
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,27 @@ LegendDataManagement provides an extension for SolidStateDetectors, a
1919
`SolidStateDetector` can be constructed from LEGEND metadata using the
2020
methods above.
2121
"""
22-
function SolidStateDetectors.SolidStateDetector(data::LegendData, detector::DetectorIdLike)
23-
SolidStateDetectors.SolidStateDetector{_SSDDefaultNumtype}(data, detector)
22+
function SolidStateDetectors.SolidStateDetector(data::LegendData, meta::Union{<:String, <:AbstractDict, <:DetectorIdLike}, env::HPGeEnvironment = HPGeEnvironment())
23+
SolidStateDetector{_SSDDefaultNumtype}(data, meta, env)
2424
end
2525

26-
function SolidStateDetectors.SolidStateDetector{T}(data::LegendData, detector::DetectorIdLike) where {T<:AbstractFloat}
26+
function SolidStateDetectors.SolidStateDetector{T}(data::LegendData, detector::DetectorIdLike, env::HPGeEnvironment = HPGeEnvironment()) where {T<:AbstractFloat}
2727
detector_props = getproperty(data.metadata.hardware.detectors.germanium.diodes, Symbol(detector))
2828
xtal_props = getproperty(data.metadata.hardware.detectors.germanium.crystals, Symbol(string(detector)[1:end-1]))
29-
SolidStateDetector{T}(LegendData, detector_props, xtal_props)
29+
SolidStateDetector{T}(LegendData, detector_props, xtal_props, env)
3030
end
3131

32-
function SolidStateDetectors.SolidStateDetector{T}(::Type{LegendData}, filename::String) where {T<:AbstractFloat}
33-
SolidStateDetector{T}(LegendData, readprops(filename, subst_pathvar = false, subst_env = false, trim_null = false))
32+
function SolidStateDetectors.SolidStateDetector{T}(::Type{LegendData}, filename::String, env::HPGeEnvironment = HPGeEnvironment()) where {T<:AbstractFloat}
33+
SolidStateDetector{T}(LegendData, readprops(filename, subst_pathvar = false, subst_env = false, trim_null = false), env)
3434
end
3535

36-
function SolidStateDetectors.SolidStateDetector(::Type{LegendData}, filename::String)
37-
SolidStateDetector{_SSDDefaultNumtype}(LegendData, filename)
36+
function SolidStateDetectors.SolidStateDetector{T}(::Type{LegendData}, meta::AbstractDict, env::HPGeEnvironment = HPGeEnvironment()) where {T<:AbstractFloat}
37+
SolidStateDetector{T}(LegendData, convert(PropDict, meta), LegendDataManagement.NoSuchPropsDBEntry("",[]), env)
3838
end
3939

40-
function SolidStateDetectors.SolidStateDetector(::Type{LegendData}, meta::AbstractDict)
41-
SolidStateDetectors.SolidStateDetector{_SSDDefaultNumtype}(LegendData, meta)
42-
end
43-
44-
function SolidStateDetectors.SolidStateDetector{T}(::Type{LegendData}, meta::AbstractDict) where {T<:AbstractFloat}
45-
SolidStateDetectors.SolidStateDetector{T}(LegendData, convert(PropDict, meta), LegendDataManagement.NoSuchPropsDBEntry("",[]))
46-
end
47-
48-
function SolidStateDetectors.SolidStateDetector{T}(::Type{LegendData}, meta::PropDict, xtal_meta::Union{PropDict, LegendDataManagement.NoSuchPropsDBEntry}) where {T<:AbstractFloat}
49-
config_dict = create_SSD_config_dict_from_LEGEND_metadata(meta, xtal_meta)
50-
return SolidStateDetector{T}(config_dict, SolidStateDetectors.construct_units(config_dict))
40+
function SolidStateDetectors.SolidStateDetector{T}(::Type{LegendData}, meta::PropDict, xtal_meta::Union{PropDict, LegendDataManagement.NoSuchPropsDBEntry}, env::HPGeEnvironment = HPGeEnvironment()) where {T<:AbstractFloat}
41+
config_dict = create_SSD_config_dict_from_LEGEND_metadata(meta, xtal_meta, env)
42+
SolidStateDetector{T}(config_dict, SolidStateDetectors.construct_units(config_dict))
5143
end
5244

5345
"""
@@ -59,39 +51,30 @@ LegendDataManagement provides an extension for SolidStateDetectors, a
5951
`Simulation` can be constructed from LEGEND metadata using the
6052
methods above.
6153
"""
62-
function SolidStateDetectors.Simulation(data::LegendData, detector::DetectorIdLike)
63-
SolidStateDetectors.Simulation{_SSDDefaultNumtype}(data, detector)
54+
function SolidStateDetectors.Simulation(::Type{LegendData}, meta::Union{<:String, <:AbstractDict, <:DetectorIdLike}, env::HPGeEnvironment = HPGeEnvironment())
55+
Simulation{_SSDDefaultNumtype}(LegendData, meta, env)
6456
end
6557

66-
function SolidStateDetectors.Simulation{T}(data::LegendData, detector::DetectorIdLike) where {T<:AbstractFloat}
58+
function SolidStateDetectors.Simulation{T}(data::LegendData, detector::DetectorIdLike, env::HPGeEnvironment = HPGeEnvironment()) where {T<:AbstractFloat}
6759
detector_props = getproperty(data.metadata.hardware.detectors.germanium.diodes, Symbol(detector))
6860
xtal_props = getproperty(data.metadata.hardware.detectors.germanium.crystals, Symbol(string(detector)[1:end-1]))
69-
Simulation{T}(LegendData, detector_props, xtal_props)
61+
Simulation{T}(LegendData, detector_props, xtal_props, env)
7062
end
7163

72-
function SolidStateDetectors.Simulation{T}(::Type{LegendData}, filename::String) where {T<:AbstractFloat}
73-
Simulation{T}(LegendData, readprops(filename, subst_pathvar = false, subst_env = false, trim_null = false))
64+
function SolidStateDetectors.Simulation{T}(::Type{LegendData}, filename::String, env::HPGeEnvironment = HPGeEnvironment()) where {T<:AbstractFloat}
65+
Simulation{T}(LegendData, readprops(filename, subst_pathvar = false, subst_env = false, trim_null = false), env)
7466
end
7567

76-
function SolidStateDetectors.Simulation(::Type{LegendData}, filename::String)
77-
Simulation{_SSDDefaultNumtype}(LegendData, filename)
68+
function SolidStateDetectors.Simulation{T}(::Type{LegendData}, meta::AbstractDict, env::HPGeEnvironment = HPGeEnvironment()) where {T<:AbstractFloat}
69+
Simulation{T}(LegendData, convert(PropDict, meta), LegendDataManagement.NoSuchPropsDBEntry("", []), env)
7870
end
7971

80-
function SolidStateDetectors.Simulation(::Type{LegendData}, meta::AbstractDict)
81-
SolidStateDetectors.Simulation{_SSDDefaultNumtype}(LegendData, meta)
72+
function SolidStateDetectors.Simulation{T}(::Type{LegendData}, meta::PropDict, xtal_meta::Union{PropDict, LegendDataManagement.NoSuchPropsDBEntry}, env::HPGeEnvironment = HPGeEnvironment()) where {T<:AbstractFloat}
73+
config_dict = create_SSD_config_dict_from_LEGEND_metadata(meta, xtal_meta, env)
74+
Simulation{T}(config_dict)
8275
end
8376

84-
function SolidStateDetectors.Simulation{T}(::Type{LegendData}, meta::AbstractDict) where {T<:AbstractFloat}
85-
SolidStateDetectors.Simulation{T}(LegendData, convert(PropDict, meta), LegendDataManagement.NoSuchPropsDBEntry("", []))
86-
end
87-
88-
function SolidStateDetectors.Simulation{T}(::Type{LegendData}, meta::PropDict, xtal_meta::Union{PropDict, LegendDataManagement.NoSuchPropsDBEntry}) where {T<:AbstractFloat}
89-
config_dict = create_SSD_config_dict_from_LEGEND_metadata(meta, xtal_meta)
90-
return Simulation{T}(config_dict)
91-
end
92-
93-
94-
function create_SSD_config_dict_from_LEGEND_metadata(meta::PropDict, xtal_meta::X; dicttype = Dict{String,Any}) where {X <: Union{PropDict, LegendDataManagement.NoSuchPropsDBEntry}}
77+
function create_SSD_config_dict_from_LEGEND_metadata(meta::PropDict, xtal_meta::X, env::HPGeEnvironment = HPGeEnvironment(); dicttype = Dict{String,Any}) where {X <: Union{PropDict, LegendDataManagement.NoSuchPropsDBEntry}}
9578

9679
# Not all possible configurations are yet implemented!
9780
# https://github.com/legend-exp/legend-metadata/blob/main/hardware/detectors/detector-metadata_1.pdf
@@ -139,7 +122,7 @@ function create_SSD_config_dict_from_LEGEND_metadata(meta::PropDict, xtal_meta::
139122
)
140123
)
141124
),
142-
"medium" => "vacuum",
125+
"medium" => env.medium,
143126
"detectors" => []
144127
)
145128

@@ -151,7 +134,7 @@ function create_SSD_config_dict_from_LEGEND_metadata(meta::PropDict, xtal_meta::
151134
),
152135
# "impurity_density" => dicttype("parameters" => Vector()),
153136
"geometry" => dicttype(),
154-
"temperature" => 78
137+
"temperature" => ustrip(u"K", env.temperature)
155138
),
156139
"contacts" => []
157140
))

‎src/LegendDataManagement.jl

+3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ using TypedTables
3535
import Markdown
3636
using MIMEs: mime_from_extension
3737

38+
export HPGeEnvironment
39+
3840
include("legend_report.jl")
3941
include("status_types.jl")
4042
include("atomic_fcreate.jl")
4143
include("filekey.jl")
44+
include("hpge_environment.jl")
4245
include("dataset.jl")
4346
include("data_config.jl")
4447
include("props_db.jl")

‎src/hpge_environment.jl

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
struct HPGeEnvironment{T}
3+
4+
Struct to describe the environment of a HPGe detector which are not set in metadata.
5+
6+
## Parametric types
7+
* `T`: Temperature type
8+
9+
## Fields
10+
* `medium::AbstractString`: Name of the medium.
11+
* `temperature::T`: Temperature of detector/medium with units.
12+
13+
## Default constructor for vacuum cryostat at 78 K:
14+
15+
* `HPGeEnvironment()`.
16+
"""
17+
18+
struct HPGeEnvironment{T<:Unitful.Temperature{<:Number}}
19+
medium::AbstractString
20+
temperature::T
21+
22+
HPGeEnvironment(m::AbstractString,t::T) where {T} = new{T}(m,t)
23+
end
24+
25+
HPGeEnvironment() = HPGeEnvironment("vacuum", 78u"K")

‎test/test_ext_ssd.jl

+9
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,13 @@ include("testing_utils.jl")
3535
@test !isfile(lh5name)
3636
end
3737
end
38+
39+
@testset "Test HPGeEnvironment" begin
40+
detname = :V99000A
41+
env = LegendDataManagement.HPGeEnvironment("LAr", 87u"K")
42+
sim = Simulation{Float64}(l200, detname, env)
43+
@test sim isa Simulation
44+
@test sim.medium == SolidStateDetectors.material_properties[:LAr]
45+
@test sim.detector.semiconductor.temperature == 87
46+
end
3847
end

0 commit comments

Comments
 (0)
Please sign in to comment.