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

Add more helpers to deal with modules

parent 626f05fc
No related branches found
No related tags found
1 merge request!28Add more helpers to deal with modules
......@@ -52,6 +52,9 @@ Detector
modules
getmodule
getpmt
haslocation
isbasemodule
isopticalmodule
write(::AbstractString, ::Detector)
write(::IO, ::Detector)
Hydrophone
......@@ -154,4 +157,5 @@ hashistory
### Math
```@docs
angle
distance
```
......@@ -27,7 +27,8 @@ export ROOTFile
export H5File, H5CompoundDataset, create_dataset, addmeta
export Direction, Position, UTMPosition, Location, Quaternion, Track, AbstractCalibratedHit
export Detector, DetectorModule, PMT, Tripod, Hydrophone, StringMechanics, StringMechanicsParameters, center, isbasemodule, getmodule, modules, getpmt, getpmts
export Detector, DetectorModule, PMT, Tripod, Hydrophone, StringMechanics, StringMechanicsParameters,
center, isbasemodule, isopticalmodule, getmodule, modules, getpmt, getpmts, haslocation
# Acoustics
export Waveform, AcousticSignal, AcousticsTriggerParameter, piezoenabled, hydrophoneenabled
......@@ -60,6 +61,8 @@ export MCEventMatcher
export CHClient, CHTag, subscribe, @ip_str
export distance
@template (FUNCTIONS, METHODS, MACROS) =
"""
$(TYPEDSIGNATURES)
......
......@@ -81,7 +81,11 @@ end
The index in this context is the DAQ channel ID of the PMT, which is counting from 0.
"""
Base.getindex(d::DetectorModule, i) = d.pmts[i+1]
"""
Returns true if the module is a basemodule.
"""
isbasemodule(d::DetectorModule) = d.location.floor == 0
isopticalmodule(d::DetectorModule) = d.n_pmts > 0
getpmts(d::DetectorModule) = d.pmts
"""
Get the PMT for a given DAQ channel ID (TDC)
......@@ -294,6 +298,10 @@ end
Base.getindex(d::Detector, module_id::Integer) = d.modules[module_id]
Base.getindex(d::Detector, string::Integer, floor::Integer) = d.locations[string, floor]
"""
Return the detector module for a given module ID.
"""
@inline getmodule(d::Detector, module_id::Integer) = d[module_id]
"""
Return the detector module for a given string and floor.
"""
@inline getmodule(d::Detector, string::Integer, floor::Integer) = d[string, floor]
......@@ -305,6 +313,10 @@ Return the detector module for a given string and floor (as `Tuple`).
Return the detector module for a given location.
"""
@inline getmodule(d::Detector, loc::Location) = d[loc.string, loc.floor]
"""
Return the `PMT` for a given hit.
"""
@inline getpmt(d::Detector, hit) = getpmt(getmodule(d, hit.dom_id), hit.channel_id)
Base.getindex(d::Detector, string::Int, ::Colon) = sort!(filter(m->m.location.string == string, modules(d)))
Base.getindex(d::Detector, string::Int, floors::T) where T<:Union{AbstractArray, UnitRange} = [d[string, floor] for floor in sort(floors)]
Base.getindex(d::Detector, ::Colon, floor::Int) = sort!(filter(m->m.location.floor == floor, modules(d)))
......@@ -326,6 +338,13 @@ end
"""
Returns true if there is a module at the given location.
"""
haslocation(d::Detector, loc::Location) = haskey(d.locations, (loc.string, loc.floor))
"""
Calculate the center of the detector based on the location of the optical modules.
"""
......
......@@ -5,3 +5,10 @@ Base.angle(d1::Direction, d2::Direction) = acos(min(dot(normalize(d1), normalize
Base.angle(a::T, b::T) where {T<:Union{KM3io.AbstractCalibratedHit, KM3io.PMT}} = Base.angle(a.dir, b.dir)
Base.angle(a, b::Union{KM3io.AbstractCalibratedHit, KM3io.PMT}) = Base.angle(a, b.dir)
Base.angle(a::Union{KM3io.AbstractCalibratedHit, KM3io.PMT}, b) = Base.angle(a.dir, b)
"""
Calculates the disance between two points.
"""
distance(a::Position, b::Position) = norm(a - b)
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