Skip to content

Commit

Permalink
Rename rap to rapidity
Browse files Browse the repository at this point in the history
This is the same method name as ScikitHEP's Vector package
Add a note that we adopt the ROOT convention of returning a negative
mass for space-like 4-vectors
  • Loading branch information
graeme-a-stewart committed Oct 13, 2023
1 parent 1672128 commit 2e3acce
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ you can also use `fromPtEtaPhiE(pt, eta, phi, energy) --> LorentzVectorCyl`.
and these functions for both of them:

```julia
px, py, pz, energy, pt, rap, eta, phi, mass
px, py, pz, energy, pt, rapidity, eta, phi, mass
```

as well as these utility functions:
Expand Down
2 changes: 1 addition & 1 deletion src/LorentzVectorHEP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using LorentzVectors # provides x, y, z, t

export LorentzVectorCyl, LorentzVector

export px, py, pz, energy, fast_mass, pt, rap, eta, phi, mass
export px, py, pz, energy, fast_mass, pt, rapidity, eta, phi, mass
export deltaphi, deltar, deltaeta
export ΔR, Δϕ, Δη
export fromPtEtaPhiE
Expand Down
3 changes: 2 additions & 1 deletion src/cartesian.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Base.zero(lv::T) where T<:LorentzVector = T(0,0,0,0)
mass2(lv::LorentzVector) = dot(lv, lv)
"""mass value - returns a negative number for spacelike 4-vectors"""
mass(lv::LorentzVector) = mass2(lv) < 0.0 ? sqrt(-mass2(lv)) : sqrt(mass2(lv))
pt2(lv::LorentzVector) = muladd(lv.x, lv.x, lv.y^2)
pt(lv::LorentzVector) = sqrt(pt2(lv))
Expand Down Expand Up @@ -30,7 +31,7 @@ end
const η = eta

"""Rapidity"""
function rap(lv::LorentzVector)
function rapidity(lv::LorentzVector)
pt_squared = pt2(lv)
abspz = abs(pz(lv))
if (energy(lv) == abspz) && (pt_squared == 0.0)
Expand Down
2 changes: 1 addition & 1 deletion src/cylindrical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function fast_mass(v1::LorentzVectorCyl, v2::LorentzVectorCyl)
end

"Rapidity"
function rap(lv::LorentzVectorCyl)
function rapidity(lv::LorentzVectorCyl)
num = sqrt(lv.mass^2 + lv.pt^2 * cosh(lv.eta)^2) + lv.pt * sinh(lv.eta)
den = sqrt(lv.mass^2 + lv.pt^2)
return log(num/den)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using Test
@test px(v1) -1424.610065192358 atol=1e-6
@test py(v1) -1036.2899616674022 atol=1e-6
@test pz(v1) -8725.817601790963 atol=1e-6
@test rap(v1) -2.3032199982371715 atol=1e-6
@test rapidity(v1) -2.3032199982371715 atol=1e-6

@test isapprox((v1+v2).mass, 8.25741602000877, atol=1e-6)
@test isapprox(fast_mass(v1,v2), 8.25741602000877, atol=1e-6)
Expand Down

0 comments on commit 2e3acce

Please sign in to comment.