diff --git a/src/exports.jl b/src/exports.jl index ac9cab1c17d3d1d7af5b83e4f09f1d29bd49eaf6..bb7e003967cf3563b98a62ab7666f1549d7ad777 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -75,6 +75,7 @@ MCTrk, TriggeredHit, Trk, XCalibratedHit, +FitInformation, # Calibration AbstractCalibratedHit, diff --git a/src/root/offline.jl b/src/root/offline.jl index 5dadd79c0acf99392d6a5f3d7f72897f6e414f27..6827c39b5e23ab0a99705e8f13808066597d9a59 100644 --- a/src/root/offline.jl +++ b/src/root/offline.jl @@ -37,6 +37,21 @@ struct CalibratedMCHit dir::Direction{Float64} end +""" +A container object to store fit information which uses 0-based indexing. +""" +struct FitInformation + values::Vector{Float64} +end +Base.getindex(fitinf::FitInformation, idx) = fitinf.values[idx + 1] +Base.length(fitinf::FitInformation) = length(fitinf.values) +Base.firstindex(::FitInformation) = 0 +Base.lastindex(fitinf::FitInformation) = length(fitinf) - 1 +Base.eltype(::FitInformation) = Float64 +function Base.iterate(fitinf::FitInformation, state=0) + state > length(fitinf)-1 ? nothing : (fitinf[state], state+1) +end + """ Represents a reconstructed "track", which can be e.g. a muon track but also a shower. """ @@ -50,7 +65,7 @@ struct Trk lik::Float64 rec_type::Int32 rec_stages::Vector{Int32} - fitinf::Vector{Float64} + fitinf::FitInformation end """ @@ -304,7 +319,7 @@ function Base.getindex(f::OfflineTree, idx::Integer) e.trks_lik[i], e.trks_rec_type[i], e.trks_rec_stages[i], - e.trks_fitinf[i], + FitInformation(e.trks_fitinf[i]), ) ) end diff --git a/test/physics.jl b/test/physics.jl index f7c49908952d48c99ad53abceb8443fed6778868..cc9488bc87ce8a84f2b5258cf7249e91fa94f060 100644 --- a/test/physics.jl +++ b/test/physics.jl @@ -17,7 +17,7 @@ using Test 0, 0, [0], - [0] + FitInformation([0]) ) γs = cherenkov(track, hits) diff --git a/test/root.jl b/test/root.jl index a277b950b5890e4b6916519449d346a4a33db499..5d3c92bb8fd282a54ecb58403edb1870cecfdc2c 100644 --- a/test/root.jl +++ b/test/root.jl @@ -18,7 +18,7 @@ const USRFILE = datapath("offline", "usr-sample.root") @test 56 == length(t[1].trks) @test 0 == length(t[1].w) @test 17 == length(t[1].trks[1].fitinf) - @test 0.009290906625313346 == t[end].trks[1].fitinf[1] + @test 0.009290906625313346 == t[end].trks[1].fitinf[0] close(f) f = ROOTFile(datapath("offline", "numucc.root")) diff --git a/test/tools.jl b/test/tools.jl index 59221d304e70ba6fb7b76ed30f691b201ea81b7d..aff37baaa272fc7c4e8a26af91bff14af2f1b398 100644 --- a/test/tools.jl +++ b/test/tools.jl @@ -91,7 +91,8 @@ const ONLINEFILE = datapath("online", "km3net_online.root") @test 56 == length(t[1].trks) @test 0 == length(t[1].w) @test 17 == length(t[1].trks[1].fitinf) - @test 0.009290906625313346 == t[end].trks[1].fitinf[1] + @test 63.92088448673299 == sum(t[end].trks[2].fitinf) + @test 101.0 == t[1].trks[1].fitinf[end] close(f) f = ROOTFile(datapath("offline", "numucc.root"))