Skip to content
Snippets Groups Projects
Verified Commit 9c51757b authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

Add readout for mechanics

parent 5e2715ee
No related branches found
No related tags found
1 merge request!17Add readout for mechanics
......@@ -62,6 +62,9 @@ write(::AbstractString, ::Vector{Tripod})
piezoenabled
hydrophoneenabled
center
StringMechanics
StringMechanicsParameters
read(::AbstractString, ::Type{StringMechanics})
```
## Optical Data
......
......@@ -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
......
......@@ -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
......@@ -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)
......
# some comment
-1 0.00094 294.291
23 1.2 3.4
5 5.6 7.8
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment