diff --git a/docs/src/api.md b/docs/src/api.md index 11b3ac01508fb78438b5a999eb21b7146af69da7..a7c8e419e66a09cf0349bdc2c9396615cd4043eb 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -62,6 +62,9 @@ write(::AbstractString, ::Vector{Tripod}) piezoenabled hydrophoneenabled center +StringMechanics +StringMechanicsParameters +read(::AbstractString, ::Type{StringMechanics}) ``` ## Optical Data diff --git a/src/KM3io.jl b/src/KM3io.jl index f59d2e108f5ca4af5194f0efa91383a41abfe633..044a9d83aa0510861141748f27f0d60615cb4561 100644 --- a/src/KM3io.jl +++ b/src/KM3io.jl @@ -21,7 +21,7 @@ export ROOTFile export H5File, H5CompoundDataset, create_dataset, addmeta export Direction, Position, UTMPosition, Location, Quaternion, Track, AbstractCalibratedHit -export Detector, DetectorModule, PMT, Tripod, Hydrophone, center, isbasemodule, getmodule, modules, getpmt, getpmts +export Detector, DetectorModule, PMT, Tripod, Hydrophone, StringMechanics, center, isbasemodule, getmodule, modules, getpmt, getpmts # Acoustics export Waveform, AcousticSignal, AcousticsTriggerParameter, piezoenabled, hydrophoneenabled diff --git a/src/hardware.jl b/src/hardware.jl index ed469bf5f2f1c2071a2c0676a444883b042c7dc9..b018611117a768238519c32154082291dcdd9d0f 100644 --- a/src/hardware.jl +++ b/src/hardware.jl @@ -548,3 +548,56 @@ function write(io::IO, d::Detector; version=:same) end end end + + +""" + +Data structure for parameters of the mechanical model of strings. This data +structure is used to calculate the effective height conform to the mechanical +model of the string. + +""" +struct StringMechanicsParameters + a::Float64 + b::Float64 +end + +""" + +A container structure which holds the mechanical model parameters for multiple +strings, including a default value for strings which have specific parameters. + +""" +struct StringMechanics + default::StringMechanicsParameters + stringparams::Dict{Int, StringMechanicsParameters} +end +Base.getindex(s::StringMechanics, idx::Integer) = get(s.stringparams, idx, s.default) + + +""" + +Reads the mechanical models from a text file. + +""" +function read(filename::AbstractString, T::Type{StringMechanics}) + stringparams = Dict{Int, StringMechanicsParameters}() + default_a = 0.0 + default_b = 0.0 + for line ∈ readlines(filename) + if startswith(line, "#") + continue + end + string, a, b = split(line) + s = parse(Int, string) + a = parse(Float64, a) + b = parse(Float64, b) + if s == -1 # wildcard for any string + default_a = a + default_b = b + else + stringparams[s] = StringMechanicsParameters(a, b) + end + end + T(StringMechanicsParameters(default_a, default_b), stringparams) +end diff --git a/test/hardware.jl b/test/hardware.jl index 90d839b415de028ae54406e0c61d1fe32479d8fc..b62ef3728eb2c575d27c758573740a853e36cf65 100644 --- a/test/hardware.jl +++ b/test/hardware.jl @@ -150,6 +150,18 @@ const SAMPLES_DIR = joinpath(@__DIR__, "samples") @test trigger.nmin == 90 end + @testset "mechanics" begin + mechanics = read(joinpath(SAMPLES_DIR, "mechanics.txt"), StringMechanics) + @test 0.00094 ≈ mechanics[1].a + @test 294.291 ≈ mechanics[1].b + @test 0.00094 ≈ mechanics[-1].a + @test 294.291 ≈ mechanics[-1].b + @test 0.00094 ≈ mechanics[42].a + @test 294.291 ≈ mechanics[42].b + @test 5.6 ≈ mechanics[5].a + @test 7.8 ≈ mechanics[5].b + end + @testset "utilities" begin mod = DetectorModule(1, UTMPosition(0, 0, 0), Location(0, 0), 0, PMT[], missing, 0, 0) @test hydrophoneenabled(mod) diff --git a/test/samples/mechanics.txt b/test/samples/mechanics.txt index 731e272d195b542d0da46f9c863f195a7925f8d9..a118877ad8a8cbf2ab36f3714a43715367b8db8c 100644 --- a/test/samples/mechanics.txt +++ b/test/samples/mechanics.txt @@ -1 +1,4 @@ +# some comment -1 0.00094 294.291 +23 1.2 3.4 +5 5.6 7.8