Skip to content

Commit 1b82703

Browse files
Access cached values when available (#227)
* Access cached values when available For LorentzVectorBase accessors use cached values in PseudoJet and EEJet when these exist. For LorentzVectorBase.phi(::PseudoJet) there is no use of the cached value because of the different range conventions in LorentzVectorBase, [-pi, pi], vs. JetReconstruction, which uses [0, 2pi]. * Add tests for LVB accessors
1 parent 94e1af9 commit 1b82703

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

src/CommonJet.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ const m = mass
120120
phi(j::FourMomentum)
121121
122122
Return the azimuthal angle, ϕ, of the four momentum `j` in the range [0, 2π).
123+
124+
Note that the range [0, 2π) differs from the convention in LorentzVectorBase,
125+
which is [-π, π].
123126
"""
124127
function phi(j::FourMomentum)
125128
phi = LorentzVectorBase.phi(j)

src/EEJet.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ Return the squared momentum of the `EEJet` object `eej`. This accessor uses the
128128
pre-calculated value that the struct has.
129129
"""
130130
p2(eej::EEJet) = eej._p2
131+
LorentzVectorBase.spatial_magnitude2(eej::EEJet) = eej._p2
131132

132133
"""
133134
nx(eej::EEJet)

src/PseudoJet.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ isvalid(j::PseudoJet) = !(j === invalid_pseudojet)
177177
178178
Return the azimuthal angle, ϕ, of a `PseudoJet` object `p` in the range
179179
[0, 2π). This accessor uses the pre-calculated value that the struct has.
180+
181+
Note that the range [0, 2π) differs from the convention in LorentzVectorBase,
182+
which is [-π, π].
180183
"""
181184
phi(p::PseudoJet) = p._phi
182185

@@ -187,6 +190,7 @@ Return the rapidity of a `PseudoJet` object. This accessor uses the
187190
pre-calculated value that the struct has.
188191
"""
189192
rapidity(p::PseudoJet) = p._rap
193+
LorentzVectorBase.rapidity(p::PseudoJet) = p._rap
190194

191195
"""
192196
pt2(p::PseudoJet)
@@ -195,6 +199,7 @@ Return the squared transverse momentum of a `PseudoJet`. This accessor uses the
195199
pre-calculated value that the struct has.
196200
"""
197201
pt2(p::PseudoJet) = p._pt2
202+
LorentzVectorBase.pt2(p::PseudoJet) = p._pt2
198203

199204
"""
200205
pt(p::PseudoJet)
@@ -203,3 +208,4 @@ Return the scalar transverse momentum (pt) of a PseudoJet. This accessor uses
203208
the precalculated value that the struct has.
204209
"""
205210
pt(p::PseudoJet) = sqrt(p._pt2)
211+
LorentzVectorBase.pt(p::PseudoJet) = sqrt(p._pt2)

test/test-jet-types.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ pj_beam = PseudoJet(0.0, 0.0, 5.0, 5.0)
2626
@test LorentzVectorBase.spatial_magnitude2(pj) JetReconstruction.p2(pj)
2727
@test LorentzVectorBase.cos_theta(pj) JetReconstruction.CosTheta(pj)
2828

29+
# These accessors should compare exactly as they use cached values
30+
@test LorentzVectorBase.rapidity(pj) == JetReconstruction.rapidity(pj)
31+
@test LorentzVectorBase.pt2(pj) == JetReconstruction.pt2(pj)
32+
@test LorentzVectorBase.pt(pj) == JetReconstruction.pt(pj)
33+
2934
# This isn't really a test of the output, but rather that the object
3035
# can be printed without error
3136
@test string(pj) == "PseudoJet(px: 1.0 py: 2.0 pz: 3.0 E: 10.0 cluster_hist_index: 7)"

0 commit comments

Comments
 (0)