|
| 1 | +""" |
| 2 | +
|
| 3 | + XYZT <: AbstractCoordinateSystem |
| 4 | +
|
| 5 | +Cartesian coordinate system for four-vectors. Using this requires the implementation of the following interface functions: |
| 6 | +
|
| 7 | +```julia |
| 8 | +LorentzVectorBase.x(::CustomFourVector) |
| 9 | +LorentzVectorBase.y(::CustomFourVector) |
| 10 | +LorentzVectorBase.z(::CustomFourVector) |
| 11 | +LorentzVectorBase.t(::CustomFourVector) |
| 12 | +``` |
| 13 | +
|
| 14 | +""" |
| 15 | +struct XYZT <: AbstractCoordinateSystem end |
| 16 | +coordinate_names(::XYZT) = (:x, :y, :z, :t) |
| 17 | + |
| 18 | +#### |
| 19 | +# Interface functions |
| 20 | +#### |
| 21 | + |
| 22 | +function t end |
| 23 | + |
| 24 | +function x end |
| 25 | + |
| 26 | +function y end |
| 27 | + |
| 28 | +function z end |
| 29 | + |
| 30 | +#### |
| 31 | +# derived components |
| 32 | +#### |
| 33 | + |
| 34 | +@inline function spatial_magnitude2(::XYZT, mom) |
| 35 | + return x(mom)^2 + y(mom)^2 + z(mom)^2 |
| 36 | +end |
| 37 | + |
| 38 | +@inline function spatial_magnitude(cs::XYZT, mom) |
| 39 | + return sqrt(spatial_magnitude2(mom)) |
| 40 | +end |
| 41 | + |
| 42 | +@inline function mass2(::XYZT, mom) |
| 43 | + return t(mom)^2 - x(mom)^2 - y(mom)^2 - z(mom)^2 |
| 44 | +end |
| 45 | + |
| 46 | +@inline function mass(::XYZT, mom) |
| 47 | + m2 = mass2(mom) |
| 48 | + if m2 < zero(m2) |
| 49 | + # Think about including this warning, maybe optional with a global PRINT_WARNINGS switch. |
| 50 | + #@warn("The square of the invariant mass (m2=P*P) is negative. The value -sqrt(-m2) is returned.") |
| 51 | + return -sqrt(-m2) |
| 52 | + else |
| 53 | + return sqrt(m2) |
| 54 | + end |
| 55 | +end |
| 56 | + |
| 57 | +@inline function boost_beta(::XYZT, mom) |
| 58 | + en = t(mom) |
| 59 | + rho = spatial_magnitude(mom) |
| 60 | + if !iszero(en) |
| 61 | + return rho / en |
| 62 | + elseif iszero(rho) |
| 63 | + return zero(rho) |
| 64 | + else |
| 65 | + throw( |
| 66 | + ArgumentError( |
| 67 | + "there is no beta for a four-vector with vanishing time/energy component" |
| 68 | + ), |
| 69 | + ) |
| 70 | + end |
| 71 | +end |
| 72 | + |
| 73 | +@inline function boost_gamma(::XYZT, mom) |
| 74 | + beta = boost_beta(mom) |
| 75 | + return inv(sqrt(one(beta) - beta^2)) |
| 76 | +end |
| 77 | + |
| 78 | +######################## |
| 79 | +# transverse coordinates |
| 80 | +######################## |
| 81 | +@inline function pt2(::XYZT, mom) |
| 82 | + return x(mom)^2 + y(mom)^2 |
| 83 | +end |
| 84 | + |
| 85 | +@inline function pt(::XYZT, mom) |
| 86 | + return sqrt(pt2(mom)) |
| 87 | +end |
| 88 | + |
| 89 | +@inline function mt2(::XYZT, mom) |
| 90 | + return t(mom)^2 - z(mom)^2 |
| 91 | +end |
| 92 | + |
| 93 | +function mt(::XYZT, mom) |
| 94 | + mT2 = mt2(mom) |
| 95 | + if mT2 < zero(mT2) |
| 96 | + # add optional waring: negative transverse mass -> -sqrt(-mT2) is returned. |
| 97 | + -sqrt(-mT2) |
| 98 | + else |
| 99 | + sqrt(mT2) |
| 100 | + end |
| 101 | +end |
| 102 | + |
| 103 | +@inline function rapidity(::XYZT, mom) |
| 104 | + en = t(mom) |
| 105 | + zcomp = z(mom) |
| 106 | + return 0.5 * log((en + zcomp) / (en - zcomp)) |
| 107 | +end |
| 108 | + |
| 109 | +function eta(::XYZT, mom) |
| 110 | + cth = cos_theta(mom) |
| 111 | + |
| 112 | + if cth^2 < one(cth) |
| 113 | + return -0.5 * log((1 - cth) / (1 + cth)) |
| 114 | + end |
| 115 | + |
| 116 | + zcomp = z(mom) |
| 117 | + if iszero(zcomp) |
| 118 | + return zero(zcomp) |
| 119 | + end |
| 120 | + |
| 121 | + @warn "Pseudorapidity (η): transverse momentum is zero! return +/- 10e10" |
| 122 | + if zcomp > zero(zcomp) |
| 123 | + return 10e10 |
| 124 | + end |
| 125 | + |
| 126 | + return -10e10 |
| 127 | +end |
| 128 | + |
| 129 | +####################### |
| 130 | +# spherical coordinates |
| 131 | +####################### |
| 132 | +@inline function polar_angle(::XYZT, mom) |
| 133 | + xcomp = x(mom) |
| 134 | + ycomp = y(mom) |
| 135 | + zcomp = z(mom) |
| 136 | + |
| 137 | + return if iszero(xcomp) && iszero(ycomp) && iszero(zcomp) |
| 138 | + zero(xcomp) |
| 139 | + else |
| 140 | + atan(transverse_momentum(mom), zcomp) |
| 141 | + end |
| 142 | +end |
| 143 | + |
| 144 | +@inline function cos_theta(::XYZT, mom) |
| 145 | + r = spatial_magnitude(mom) |
| 146 | + return iszero(r) ? one(x(mom)) : z(mom) / r |
| 147 | +end |
| 148 | + |
| 149 | +function phi(::XYZT, mom) |
| 150 | + xcomp = x(mom) |
| 151 | + ycomp = y(mom) |
| 152 | + return iszero(xcomp) && iszero(ycomp) ? zero(xcomp) : atan(ycomp, xcomp) |
| 153 | +end |
| 154 | + |
| 155 | +function cos_phi(::XYZT, mom) |
| 156 | + pT = transverse_momentum(mom) |
| 157 | + return iszero(pT) ? one(pT) : x(mom) / pT |
| 158 | +end |
| 159 | + |
| 160 | +function sin_phi(::XYZT, mom) |
| 161 | + pT = transverse_momentum(mom) |
| 162 | + return iszero(pT) ? zero(pT) : y(mom) / pT |
| 163 | +end |
| 164 | + |
| 165 | +######################## |
| 166 | +# light cone coordinates |
| 167 | +######################## |
| 168 | +@inline function plus_component(::XYZT, mom) |
| 169 | + return 0.5 * (t(mom) + z(mom)) |
| 170 | +end |
| 171 | + |
| 172 | +@inline function minus_component(::XYZT, mom) |
| 173 | + return 0.5 * (t(mom) - z(mom)) |
| 174 | +end |
0 commit comments