|
| 1 | +# Generic utility functions for jet structs |
| 2 | + |
| 3 | +""" |
| 4 | + mag(jet::T) where {T <: FourMomentum} |
| 5 | +
|
| 6 | +Return the magnitude of the momentum of a jet, `|p|`. |
| 7 | +
|
| 8 | +# Returns |
| 9 | +The magnitude of the jet. |
| 10 | +""" |
| 11 | +mag(jet::T) where {T <: FourMomentum} = sqrt(muladd(jet.px, jet.px, jet.py^2) + jet.pz^2) |
| 12 | + |
| 13 | +""" |
| 14 | + CosTheta(jet::T) where {T <: FourMomentum} |
| 15 | +
|
| 16 | +Compute the cosine of the angle between the momentum vector of `jet` and the z-axis. |
| 17 | +
|
| 18 | +# Returns |
| 19 | +- The cosine of the angle between the jet and the z-axis. |
| 20 | +""" |
| 21 | +@inline function CosTheta(jet::T) where {T <: FourMomentum} |
| 22 | + fZ = jet.pz |
| 23 | + ptot = mag(jet) |
| 24 | + return ifelse(ptot == 0.0, 1.0, fZ / ptot) |
| 25 | +end |
| 26 | + |
| 27 | +""" |
| 28 | + eta(jet::T) where {T <: FourMomentum} |
| 29 | +
|
| 30 | +Compute the pseudorapidity (η) of a jet. |
| 31 | +
|
| 32 | +# Returns |
| 33 | +- The pseudorapidity (η) of the jet. |
| 34 | +""" |
| 35 | +function eta(jet::T) where {T <: FourMomentum} |
| 36 | + cosTheta = CosTheta(jet) |
| 37 | + (cosTheta^2 < 1.0) && return -0.5 * log((1.0 - cosTheta) / (1.0 + cosTheta)) |
| 38 | + fZ = jet.pz |
| 39 | + iszero(fZ) && return 0.0 |
| 40 | + # Warning("PseudoRapidity","transverse momentum = 0! return +/- 10e10"); |
| 41 | + fZ > 0.0 && return 10e10 |
| 42 | + return -10e10 |
| 43 | +end |
| 44 | + |
| 45 | +""" |
| 46 | + const η = eta |
| 47 | +
|
| 48 | +Alias for the pseudorapidity function, `eta`. |
| 49 | +""" |
| 50 | +const η = eta |
| 51 | + |
| 52 | +""" |
| 53 | + deltaR(jet1::T, jet2::T) where T <: FourMomentum |
| 54 | +
|
| 55 | +Function to calculate the distance in the y-ϕ plane between two jets `jet1` and |
| 56 | +`jet2` (that is using *rapidity* and *azimuthal angle*). |
| 57 | +
|
| 58 | +# Returns |
| 59 | +- The Euclidean distance in the y-ϕ plane for the two jets. |
| 60 | +""" |
| 61 | +function deltaR(jet1::T, jet2::T) where {T <: FourMomentum} |
| 62 | + δy = rapidity(jet1) - rapidity(jet2) |
| 63 | + δϕ = phi(jet1) - phi(jet2) |
| 64 | + δϕ = abs(δϕ) > π ? 2π - abs(δϕ) : δϕ |
| 65 | + |
| 66 | + return sqrt(δy^2 + δϕ^2) |
| 67 | +end |
| 68 | + |
| 69 | +""" |
| 70 | + deltar(jet1::T, jet2::T) where T <: FourMomentum |
| 71 | +
|
| 72 | +Function to calculate the distance in the η-ϕ plane between two jets `jet1` and |
| 73 | +`jet2` (that is, using the *pseudorapidity* and *azimuthal angle*). |
| 74 | +
|
| 75 | +# Returns |
| 76 | +- The Euclidean distance in the η-ϕ plane for the two jets. |
| 77 | +""" |
| 78 | +function deltar(jet1::T, jet2::T) where {T <: FourMomentum} |
| 79 | + δη = eta(jet1) - eta(jet2) |
| 80 | + δϕ = phi(jet1) - phi(jet2) |
| 81 | + δϕ = abs(δϕ) > π ? 2π - abs(δϕ) : δϕ |
| 82 | + |
| 83 | + return sqrt(δη^2 + δϕ^2) |
| 84 | +end |
| 85 | + |
| 86 | +""" |
| 87 | + pt_fraction(jet1::T, jet2::T) where T <: FourMomentum |
| 88 | +
|
| 89 | +Computes the transverse momentum fraction of the softer of two jets. |
| 90 | +
|
| 91 | +# Returns |
| 92 | +- The transverse momentum fraction of the softer of the two jets. |
| 93 | +""" |
| 94 | +function pt_fraction(jet1::T, jet2::T) where {T <: FourMomentum} |
| 95 | + pt1 = JetReconstruction.pt(jet1) |
| 96 | + pt2 = JetReconstruction.pt(jet2) |
| 97 | + return min(pt1, pt2) / (pt1 + pt2) |
| 98 | +end |
| 99 | + |
| 100 | +""" |
| 101 | + kt_scale(jet1::T, jet2::T) where {T <: FourMomentum} |
| 102 | +
|
| 103 | +Computes the transverse momentum scale as the product of the minimum pt and |
| 104 | +the angular separation in the η-ϕ plane (using *pseudorapidity*). |
| 105 | +
|
| 106 | +# Returns |
| 107 | +- The transverse momentum scale of the two jets. |
| 108 | +""" |
| 109 | +function kt_scale(jet1::T, jet2::T) where {T <: FourMomentum} |
| 110 | + pt1 = JetReconstruction.pt(jet1) |
| 111 | + pt2 = JetReconstruction.pt(jet2) |
| 112 | + return min(pt1, pt2) * deltar(jet1, jet2) |
| 113 | +end |
| 114 | + |
| 115 | +""" |
| 116 | + lorentzvector_cyl(jet::T) where T <: FourMomentum -> LorentzVectorHEP.LorentzVectorCyl |
| 117 | +
|
| 118 | +Return a cylindrical `LorentzVectorCyl` from a jet. |
| 119 | +""" |
| 120 | +function lorentzvector_cyl(jet::T) where {T <: FourMomentum} |
| 121 | + return LorentzVectorHEP.fromPtEtaPhiE(JetReconstruction.pt(jet), |
| 122 | + JetReconstruction.eta(jet), |
| 123 | + JetReconstruction.phi(jet), |
| 124 | + JetReconstruction.energy(jet)) |
| 125 | +end |
| 126 | + |
| 127 | +""" |
| 128 | + lorentzvector(jet::T) where {T <: FourMomentum} -> -> LorentzVector |
| 129 | +
|
| 130 | +Return a cartesian `LorentzVector` from a jet. |
| 131 | +""" |
| 132 | +function lorentzvector(jet::T) where {T <: FourMomentum} |
| 133 | + return LorentzVector(JetReconstruction.energy(jet), |
| 134 | + JetReconstruction.px(jet), |
| 135 | + JetReconstruction.py(jet), |
| 136 | + JetReconstruction.pz(jet)) |
| 137 | +end |
0 commit comments