|
| 1 | +# Inspired by the PseudoJet class of c++ code of Fastjet (https://fastjet.fr, |
| 2 | +# hep-ph/0512210, arXiv:1111.6097) |
| 3 | +# |
| 4 | +# Some of the implementation is taken from LorentzVectorHEP.jl, by Jerry Ling |
| 5 | + |
| 6 | +""" |
| 7 | + struct PseudoJet <: FourMomentum |
| 8 | +
|
| 9 | +The `PseudoJet` struct represents a pseudojet, a four-momentum object used in |
| 10 | +jet reconstruction algorithms. Additional information for the link back into the |
| 11 | +history of the clustering is stored in the `_cluster_hist_index` field. There is |
| 12 | +caching of the more expensive calculations for rapidity and azimuthal angle. |
| 13 | +
|
| 14 | +# Fields |
| 15 | +- `px::Float64`: The x-component of the momentum. |
| 16 | +- `py::Float64`: The y-component of the momentum. |
| 17 | +- `pz::Float64`: The z-component of the momentum. |
| 18 | +- `E::Float64`: The energy component of the momentum. |
| 19 | +- `_cluster_hist_index::Int`: The index of the cluster history. |
| 20 | +- `_pt2::Float64`: The squared transverse momentum. |
| 21 | +- `_inv_pt2::Float64`: The inverse squared transverse momentum. |
| 22 | +- `_rap::Float64`: The rapidity. |
| 23 | +- `_phi::Float64`: The azimuthal angle. |
| 24 | +
|
| 25 | +""" |
| 26 | +struct PseudoJet <: FourMomentum |
| 27 | + px::Float64 |
| 28 | + py::Float64 |
| 29 | + pz::Float64 |
| 30 | + E::Float64 |
| 31 | + _cluster_hist_index::Int |
| 32 | + _pt2::Float64 |
| 33 | + _inv_pt2::Float64 |
| 34 | + _rap::Float64 |
| 35 | + _phi::Float64 |
| 36 | + function PseudoJet(px, py, pz, E, cluster_hist_index) |
| 37 | + @muladd pt2 = px * px + py * py |
| 38 | + inv_pt2 = @fastmath 1.0 / pt2 |
| 39 | + phi = pt2 == 0.0 ? 0.0 : atan(py, px) |
| 40 | + phi = phi < 0.0 ? phi + 2π : phi |
| 41 | + if E == abs(pz) && iszero(pt2) |
| 42 | + # Point has infinite rapidity - convert that into a very large |
| 43 | + # number, but in such a way that different 0-pt momenta will have |
| 44 | + # different rapidities (so as to lift the degeneracy between |
| 45 | + # them) [this can be relevant at parton-level] |
| 46 | + MaxRapHere = _MaxRap + abs(pz) |
| 47 | + rap = pz >= 0.0 ? MaxRapHere : -MaxRapHere |
| 48 | + else |
| 49 | + # get the rapidity in a way that's modestly insensitive to roundoff |
| 50 | + # error when things pz,E are large (actually the best we can do without |
| 51 | + # explicit knowledge of mass) |
| 52 | + effective_m2 = (E + pz) * (E - pz) - pt2 |
| 53 | + effective_m2 = max(0.0, effective_m2) # force non tachyonic mass |
| 54 | + E_plus_pz = E + abs(pz) # the safer of p+, p- |
| 55 | + rap = 0.5 * log((pt2 + effective_m2) / (E_plus_pz * E_plus_pz)) |
| 56 | + rap = pz > 0.0 ? -rap : rap |
| 57 | + end |
| 58 | + new(px, py, pz, E, cluster_hist_index, pt2, inv_pt2, rap, phi) |
| 59 | + end |
| 60 | +end |
| 61 | + |
| 62 | +""" |
| 63 | + PseudoJet(px::Real, py::Real, pz::Real, E::Real) |
| 64 | +
|
| 65 | +Constructs a PseudoJet object with the given momentum components and energy. |
| 66 | +
|
| 67 | +# Returns |
| 68 | +A PseudoJet object with **no** cluster index. |
| 69 | +""" |
| 70 | +PseudoJet(px::Real, py::Real, pz::Real, E::Real) = PseudoJet(px, py, pz, E, 0) |
| 71 | + |
| 72 | +""" |
| 73 | + PseudoJet(jet::PseudoJet) |
| 74 | +
|
| 75 | +Create a copy of a PseudoJet object. |
| 76 | +""" |
| 77 | +PseudoJet(jet::PseudoJet) = deepcopy(jet) |
| 78 | + |
| 79 | +""" |
| 80 | + const invalid_pseudojet = PseudoJet(0.0, 0.0, 0.0, 0.0) |
| 81 | +
|
| 82 | +Used to mark an invalid result in case the corresponding substructure tagging fails.""" |
| 83 | +const invalid_pseudojet = PseudoJet(0.0, 0.0, 0.0, 0.0) |
| 84 | + |
| 85 | +import Base.isvalid |
| 86 | +""" |
| 87 | + isvalid(j::PseudoJet) |
| 88 | +
|
| 89 | +Function to check whether a given `PseudoJet` object is non-zero or not. |
| 90 | +Primarily to use for checking the validity of outputs of substructure tagging. |
| 91 | +
|
| 92 | +# Returns |
| 93 | +- `Bool`: `true` if the `PseudoJet` object is non-zero (valid), `false` otherwise. |
| 94 | +""" |
| 95 | +isvalid(j::PseudoJet) = !(j === invalid_pseudojet) |
| 96 | + |
| 97 | +""" |
| 98 | + phi(p::PseudoJet) |
| 99 | +
|
| 100 | +Return the azimuthal angle, ϕ, of a `PseudoJet` object `p` in the range [0, 2π). |
| 101 | +""" |
| 102 | +phi(p::PseudoJet) = p._phi |
| 103 | + |
| 104 | +""" |
| 105 | + rapidity(p::PseudoJet) |
| 106 | +
|
| 107 | +Compute the rapidity of a `PseudoJet` object. |
| 108 | +
|
| 109 | +# Returns |
| 110 | +The rapidity of the `PseudoJet` object. |
| 111 | +""" |
| 112 | +rapidity(p::PseudoJet) = p._rap |
| 113 | + |
| 114 | +""" |
| 115 | + pt2(p::PseudoJet) |
| 116 | +
|
| 117 | +Get the squared transverse momentum of a PseudoJet. |
| 118 | +
|
| 119 | +# Returns |
| 120 | +- The squared transverse momentum of the PseudoJet. |
| 121 | +""" |
| 122 | +pt2(p::PseudoJet) = p._pt2 |
| 123 | + |
| 124 | +""" |
| 125 | + pt(p::PseudoJet) |
| 126 | +
|
| 127 | +Compute the scalar transverse momentum (pt) of a PseudoJet. |
| 128 | +
|
| 129 | +# Returns |
| 130 | +- The transverse momentum (pt) of the PseudoJet. |
| 131 | +""" |
| 132 | +pt(p::PseudoJet) = sqrt(p._pt2) |
0 commit comments