|
| 1 | +using Random |
| 2 | +using LorentzVectorBase |
| 3 | + |
| 4 | +const RNG = MersenneTwister(137137) |
| 5 | + |
| 6 | +struct CustomCylMom |
| 7 | + pt |
| 8 | + eta |
| 9 | + phi |
| 10 | + m |
| 11 | +end |
| 12 | + |
| 13 | +LorentzVectorBase.coordinate_system(::CustomCylMom) = LorentzVectorBase.PtEtaPhiM() |
| 14 | +LorentzVectorBase.pt(mom::CustomCylMom) = mom.pt |
| 15 | +LorentzVectorBase.eta(mom::CustomCylMom) = mom.eta |
| 16 | +LorentzVectorBase.phi(mom::CustomCylMom) = mom.phi |
| 17 | +LorentzVectorBase.mass(mom::CustomCylMom) = mom.m |
| 18 | + |
| 19 | +x, y, z = rand(RNG, 3) |
| 20 | +m = abs(rand(RNG)) |
| 21 | +pt = sqrt(x^2 + y^2) |
| 22 | +η = atanh(z / sqrt(x^2 + y^2 + z^2)) |
| 23 | +ϕ = (x == 0.0 && y == 0.0) ? 0.0 : atan(y, x) |
| 24 | + |
| 25 | +mom_onshell = CustomCylMom(pt, η, ϕ, m) |
| 26 | +mom_zero = CustomCylMom(0.0, 0.0, 0.0, 0.0) |
| 27 | + |
| 28 | +@testset "spatial_magnitude consistency" begin |
| 29 | + for mom in [mom_onshell, mom_zero] |
| 30 | + @test isapprox( |
| 31 | + LorentzVectorBase.spatial_magnitude(mom), |
| 32 | + sqrt(LorentzVectorBase.spatial_magnitude2(mom)), |
| 33 | + ) |
| 34 | + end |
| 35 | +end |
| 36 | + |
| 37 | +@testset "spatial_magnitude values" begin |
| 38 | + @test isapprox(LorentzVectorBase.spatial_magnitude2(mom_onshell), x^2 + y^2 + z^2) |
| 39 | + @test isapprox(LorentzVectorBase.spatial_magnitude(mom_onshell), sqrt(x^2 + y^2 + z^2)) |
| 40 | +end |
| 41 | + |
| 42 | +@testset "mass2 consistency" begin |
| 43 | + for mom in [mom_onshell, mom_zero] |
| 44 | + @test isapprox(LorentzVectorBase.mass(mom), sqrt(LorentzVectorBase.mass2(mom))) |
| 45 | + @test LorentzVectorBase.invariant_mass2(mom) == LorentzVectorBase.mass2(mom) |
| 46 | + @test LorentzVectorBase.invariant_mass(mom) == LorentzVectorBase.mass(mom) |
| 47 | + @test isapprox( |
| 48 | + LorentzVectorBase.invariant_mass(mom), sqrt(LorentzVectorBase.invariant_mass2(mom)) |
| 49 | + ) |
| 50 | + end |
| 51 | +end |
| 52 | + |
| 53 | +@testset "mass value" begin |
| 54 | + @test LorentzVectorBase.mass2(mom_onshell) == m^2 |
| 55 | + @test LorentzVectorBase.mass(mom_onshell) == m |
| 56 | + @test LorentzVectorBase.mass(mom_zero) == 0.0 |
| 57 | +end |
| 58 | + |
| 59 | +@testset "energy" begin |
| 60 | + for mom in [mom_onshell, mom_zero] |
| 61 | + @test isapprox( |
| 62 | + LorentzVectorBase.energy(mom)^2, |
| 63 | + LorentzVectorBase.spatial_magnitude2(mom) + LorentzVectorBase.invariant_mass2(mom), |
| 64 | + ) |
| 65 | + end |
| 66 | +end |
| 67 | + |
| 68 | +@testset "momentum components" begin |
| 69 | + @test LorentzVectorBase.pt(mom_onshell) == pt |
| 70 | + @test LorentzVectorBase.eta(mom_onshell) == η |
| 71 | + @test LorentzVectorBase.phi(mom_onshell) == ϕ |
| 72 | + @test LorentzVectorBase.mass(mom_onshell) == m |
| 73 | + @test isapprox( |
| 74 | + LorentzVectorBase.boost_beta(mom_onshell), |
| 75 | + LorentzVectorBase.spatial_magnitude(mom_onshell) / |
| 76 | + LorentzVectorBase.energy(mom_onshell), |
| 77 | + ) |
| 78 | + |
| 79 | + @test LorentzVectorBase.pt(mom_zero) == 0.0 |
| 80 | + @test LorentzVectorBase.eta(mom_zero) == 0.0 |
| 81 | + @test LorentzVectorBase.phi(mom_zero) == 0.0 |
| 82 | + @test LorentzVectorBase.mass(mom_zero) == 0.0 |
| 83 | + @test LorentzVectorBase.boost_beta(mom_zero) == 0.0 |
| 84 | +end |
| 85 | + |
| 86 | +@testset "transverse coordinates values" begin |
| 87 | + @test isapprox(LorentzVectorBase.pt2(mom_onshell), pt^2) |
| 88 | + @test isapprox( |
| 89 | + LorentzVectorBase.mt2(mom_onshell), LorentzVectorBase.energy(mom_onshell)^2 - z^2 |
| 90 | + ) |
| 91 | + @test isapprox( |
| 92 | + LorentzVectorBase.mt(mom_onshell), sqrt(LorentzVectorBase.mt2(mom_onshell)) |
| 93 | + ) |
| 94 | + @test isapprox( |
| 95 | + LorentzVectorBase.rapidity(mom_onshell), |
| 96 | + 0.5 * log( |
| 97 | + (LorentzVectorBase.energy(mom_onshell) + z) / |
| 98 | + (LorentzVectorBase.energy(mom_onshell) - z), |
| 99 | + ), |
| 100 | + ) |
| 101 | + |
| 102 | + @test isapprox(LorentzVectorBase.pt2(mom_zero), 0.0) |
| 103 | + @test isapprox(LorentzVectorBase.mt2(mom_zero), 0.0) |
| 104 | + @test isapprox(LorentzVectorBase.mt(mom_zero), 0.0) |
| 105 | +end |
| 106 | + |
| 107 | +@testset "cartesian coordinate values" begin |
| 108 | + @test isapprox(LorentzVectorBase.px(mom_onshell), x) |
| 109 | + @test isapprox(LorentzVectorBase.py(mom_onshell), y) |
| 110 | + @test isapprox(LorentzVectorBase.pz(mom_onshell), z) |
| 111 | + |
| 112 | + @test isapprox(LorentzVectorBase.px(mom_zero), 0.0) |
| 113 | + @test isapprox(LorentzVectorBase.py(mom_zero), 0.0) |
| 114 | + @test isapprox(LorentzVectorBase.pz(mom_zero), 0.0) |
| 115 | +end |
| 116 | + |
| 117 | +@testset "spherical coordinate values" begin |
| 118 | + if pt != 0 && z != 0 |
| 119 | + @test isapprox(LorentzVectorBase.polar_angle(mom_onshell), atan(pt, z)) |
| 120 | + else |
| 121 | + @test isapprox(LorentzVectorBase.polar_angle(mom_onshell), 0) |
| 122 | + end |
| 123 | + |
| 124 | + r = LorentzVectorBase.spatial_magnitude(mom_onshell) |
| 125 | + @test isapprox(LorentzVectorBase.cos_theta(mom_onshell), iszero(r) ? 1.0 : z / r) |
| 126 | + @test isapprox(LorentzVectorBase.cos_phi(mom_onshell), cos(ϕ)) |
| 127 | + @test isapprox(LorentzVectorBase.sin_phi(mom_onshell), sin(ϕ)) |
| 128 | + |
| 129 | + @test isapprox(LorentzVectorBase.polar_angle(mom_zero), 0.0) |
| 130 | + @test isapprox(LorentzVectorBase.cos_theta(mom_zero), 1.0) |
| 131 | + @test isapprox(LorentzVectorBase.cos_phi(mom_zero), 1.0) |
| 132 | + @test isapprox(LorentzVectorBase.sin_phi(mom_zero), 0.0) |
| 133 | +end |
0 commit comments