From 5281386442042dbb1634cbc0bcc49fc4e98b947b Mon Sep 17 00:00:00 2001 From: Tamas Gal <himself@tamasgal.com> Date: Thu, 25 Jul 2024 14:11:10 +0200 Subject: [PATCH] Use a custom container for fit information (0-based indexing) --- src/root/offline.jl | 19 +++++++++++++++++-- test/root.jl | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/root/offline.jl b/src/root/offline.jl index 5dadd79c..856e94c1 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) ? 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/root.jl b/test/root.jl index a277b950..5d3c92bb 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")) -- GitLab