Skip to content

Commit d646253

Browse files
Bug Fix on track definition. New Direction vectors with different
transform properties.
1 parent 6f44459 commit d646253

File tree

6 files changed

+106
-14
lines changed

6 files changed

+106
-14
lines changed

Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ authors = ["mriggire <[email protected]>"]
44
version = "0.1.0"
55

66
[deps]
7+
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
8+
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
9+
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
710
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

src/ToyTracker.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@ include("utils.jl")
1010
include("geometry.jl")
1111
include("intersection.jl")
1212

13+
export GlobalVector, Pose
14+
export ParticleTrack
15+
export SiliconSensor, PlacedSensor, Tracker
16+
export Cluster, Hit
17+
18+
export interaction
19+
1320
end # module ToyTracker

src/geometry.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,25 @@ function Base.inv(p::Pose)
1717
end
1818

1919
Base.:\(p::Pose, c::GlobalVector) = LocalVector(inv(p) * c)
20+
21+
22+
function Base.:*(p::Pose, d::LocalDirection)
23+
rot = SA[
24+
p.rotxx p.rotxy p.rotxz 0
25+
p.rotyx p.rotyy p.rotyz 0
26+
p.rotzx p.rotzy p.rotzz 0
27+
0 0 0 1
28+
]
29+
return GlobalDirection(rot * d)
30+
end
31+
32+
33+
function Base.:\(p::Pose, d::GlobalDirection)
34+
invrot = SA[
35+
p.rotxx p.rotyx p.rotzx 0
36+
p.rotxy p.rotyy p.rotzy 0
37+
p.rotxz p.rotyz p.rotzz 0
38+
0 0 0 1
39+
]
40+
return LocalDirection(invrot * d)
41+
end

src/geometry_types.jl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,60 @@ LocalVector(a::StaticArray{S, T, 1} where {S<:Tuple, T}) = LocalVector(a...)
5454

5555

5656

57+
"""
58+
Direction vector in a global reference frame.
59+
"""
60+
struct GlobalDirection{T} <: FieldVector{4,T}
61+
x::T
62+
y::T
63+
z::T
64+
unity::T
65+
function GlobalDirection{T}(a, b, c, d) where {T}
66+
if !(d 1)
67+
@warn "The 4th element of the input vector is not close to 1 as expected for a GlobalDirection. That element will be discarded."
68+
end
69+
return new{T}(a, b, c, one(T))
70+
end
71+
end
72+
73+
GlobalDirection(a::T, b::T, c::T, d::T) where {T} = GlobalDirection{T}(a, b, c, d)
74+
GlobalDirection(a, b, c, d) = GlobalDirection(promote(a, b, c, d)...)
75+
76+
GlobalDirection{T}(a, b, c) where {T} = GlobalDirection{T}(a, b, c, one(T))
77+
GlobalDirection(a::T, b::T, c::T) where {T} = GlobalDirection{T}(a, b, c, one(T))
78+
79+
GlobalDirection(a, b, c) = GlobalDirection(promote(a, b, c)...)
80+
GlobalDirection(a::StaticArray{S, T, 1} where {S<:Tuple, T}) = GlobalDirection(a...)
81+
82+
83+
84+
"""
85+
Direction vector in a local reference frame.
86+
"""
87+
struct LocalDirection{T} <: FieldVector{4,T}
88+
u::T
89+
v::T
90+
w::T
91+
unity::T
92+
function LocalDirection{T}(a, b, c, d) where {T}
93+
if !(d 1)
94+
@warn "The 4th element of the input vector is not close to 1 as expected for a LocalDirection. That element will be discarded."
95+
end
96+
return new{T}(a, b, c, one(T))
97+
end
98+
end
99+
100+
LocalDirection(a::T, b::T, c::T, d::T) where {T} = LocalDirection{T}(a, b, c, d)
101+
LocalDirection(a, b, c, d) = LocalDirection(promote(a, b, c, d)...)
102+
103+
LocalDirection{T}(a, b, c) where {T} = LocalDirection{T}(a, b, c, one(T))
104+
LocalDirection(a::T, b::T, c::T) where {T} = LocalDirection{T}(a, b, c, one(T))
105+
106+
LocalDirection(a, b, c) = LocalDirection(promote(a, b, c)...)
107+
LocalDirection(a::StaticArray{S, T, 1} where {S<:Tuple, T}) = LocalDirection(a...)
108+
109+
110+
57111
"""
58112
A pose as defined in "A tutorial on SE(3) transformation parameterizations and on-manifold optimization", J. Blanco, 2010.
59113
"""

src/intersection.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ end
4545

4646

4747
function interaction(t::ParticleTrack, d::Tracker)
48-
hits = Dict{String, Hit}()
48+
hits = Dict{String, Union{Hit, Missing}}()
4949
for s in sensors(d)
5050
id = s.first
5151
ss = s.second

src/tracker_types.jl

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@ Simple struct to model basic properties of a silicon tracker sensor.
66
77
Each size should be in mm (TODO ensure that indeed this is the case).
88
"""
9-
struct SiliconSensor
10-
xwidth::Real
11-
ywidth::Real
12-
xpitch::Real
13-
ypitch::Real
14-
thickness::Real
9+
struct SiliconSensor{T}
10+
xwidth::T
11+
ywidth::T
12+
xpitch::T
13+
ypitch::T
14+
thickness::T
1515
end
1616

1717

1818
"""
1919
A Silicon Sensor plus the (active) transformation that describe its position in the global reference frame.
2020
"""
21-
struct PlacedSensor
22-
sensor::SiliconSensor
23-
position::Pose
21+
struct PlacedSensor{T}
22+
sensor::SiliconSensor{T}
23+
position::Pose{T}
2424
end
2525

2626

2727
"""
2828
Collection of SiliconSensors and their position in the global reference frame.
2929
"""
30-
struct Tracker
31-
sensors::Dict{String,PlacedSensor}
30+
struct Tracker{T}
31+
sensors::Dict{String,PlacedSensor{T}}
3232
end
3333

3434

@@ -38,16 +38,22 @@ A straight track.
3838
Each vector element should be in mm (TODO ensure that indeed this is the case).
3939
"""
4040
struct ParticleTrack{T}
41-
direction::GlobalVector{T}
41+
direction::GlobalDirection{T}
4242
position0::GlobalVector{T}
4343
end
4444

4545

46+
ParticleTrack{T}(mx, my, x0, y0) where {T} = ParticleTrack{T}(GlobalDirection{T}(mx, my, 1.), GlobalVector{T}(x0, y0, 0.))
47+
48+
ParticleTrack(mx::T, my::T, x0::T, y0::T) where {T} = ParticleTrack{T}(mx, my, x0, y0)
49+
50+
ParticleTrack(mx, my, x0, y0) = ParticleTrack(promote(mx, my, x0, y0)...)
51+
4652
"""
4753
A straight track in the reference frame of a PlacedSensor.
4854
"""
4955
struct ProjectedTrack{T}
50-
direction::LocalVector{T}
56+
direction::LocalDirection{T}
5157
position0::LocalVector{T}
5258
end
5359

0 commit comments

Comments
 (0)