Skip to content

Commit 5ac85d7

Browse files
Add more documentation for constructors
Also support type switching constructor for PseudoJet
1 parent 7e30a8a commit 5ac85d7

File tree

2 files changed

+101
-6
lines changed

2 files changed

+101
-6
lines changed

src/EEjet.jl

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,94 @@ Return the element type of the `EEjet` struct.
3535
"""
3636
Base.eltype(::Type{EEjet{T}}) where T = T
3737

38+
39+
"""
40+
EEjet(px::T, py::T, pz::T, E::T, _cluster_hist_index::Integer) where {T <: Real}
41+
42+
Constructs an `EEjet` object with the given momentum components `px`, `py`,
43+
`pz`, energy `E`, and cluster histogram index `_cluster_hist_index`.
44+
45+
The constructed EEjet object will be parametrised by the type `T`.
46+
47+
# Arguments
48+
- `px::T`: The x-component of the momentum.
49+
- `py::T`: The y-component of the momentum.
50+
- `pz::T`: The z-component of the momentum.
51+
- `E::T`: The energy of the jet.
52+
- `_cluster_hist_index::Integer`: The index of the cluster histogram.
53+
54+
# Returns
55+
- The initialised `EEjet` object.
56+
57+
# Note
58+
- `T` must be a subtype of `Real`.
59+
- The `@muladd` macro is used to perform fused multiply-add operations for
60+
computing `p2`.
61+
- The `@fastmath` macro is used to allow the compiler to perform optimizations
62+
for computing `inv_p`.
63+
"""
3864
function EEjet(px::T, py::T, pz::T, E::T, _cluster_hist_index::Integer) where {T <: Real}
3965
@muladd p2 = px * px + py * py + pz * pz
4066
inv_p = @fastmath 1.0 / sqrt(p2)
4167
EEjet{T}(px, py, pz, E, p2, inv_p, _cluster_hist_index)
4268
end
4369

44-
# Constructor with type T passes through without history index
70+
"""
71+
EEjet(px::T, py::T, pz::T, E::T) where {T <: Real}
72+
73+
Constructs an `EEjet` object with the given momentum components `px`, `py`,
74+
`pz`, energy `E`, and the cluster histogram index set to zero.
75+
76+
The constructed EEjet object will be parametrised by the type `T`.
77+
78+
# Arguments
79+
- `px::T`: The x-component of the momentum.
80+
- `py::T`: The y-component of the momentum.
81+
- `pz::T`: The z-component of the momentum.
82+
- `E::T`: The energy of the jet.
83+
84+
# Returns
85+
- The initialised `EEjet` object.
86+
"""
4587
EEjet(px::T, py::T, pz::T, E::T) where {T <: Real} = EEjet(px, py, pz, E, 0)
4688

47-
# Constructor with type U does type conversion before initialising
89+
"""
90+
EEjet{U}(px::T, py::T, pz::T, E::T) where {T <: Real, U <: Real}
91+
92+
Constructs an `EEjet` object with conversion of the given momentum components
93+
(`px`, `py`, `pz`) and energy (`E`) from type `T` to type `U`.
94+
95+
# Arguments
96+
- `px::T`: The x-component of the momentum.
97+
- `py::T`: The y-component of the momentum.
98+
- `pz::T`: The z-component of the momentum.
99+
- `E::T`: The energy.
100+
101+
# Type Parameters
102+
- `T <: Real`: The type of the input momentum components and energy.
103+
- `U <: Real`: The type to which the input values will be converted
104+
105+
# Returns
106+
An `EEjet` object with the momentum components and energy parametrised to type
107+
`U`.
108+
"""
48109
EEjet{U}(px::T, py::T, pz::T, E::T) where {T <: Real, U <: Real} = EEjet(U(px), U(py), U(pz), U(E), 0)
49110

111+
112+
"""
113+
EEjet(pj::PseudoJet) -> EEjet
114+
115+
Constructs an `EEjet` object from a given `PseudoJet` object `pj`.
116+
117+
# Arguments
118+
- `pj::PseudoJet`: A `PseudoJet` object used to create the `EEjet`.
119+
120+
# Returns
121+
- An `EEjet` object initialized with the same properties of the given `PseudoJet`.
122+
"""
50123
EEjet(pj::PseudoJet) = EEjet(px(pj), py(pj), pz(pj), energy(pj), cluster_hist_index(pj))
51124

125+
52126
p2(eej::EEjet) = eej._p2
53127
pt2(eej::EEjet) = eej.px^2 + eej.py^2
54128
const kt2 = pt2

src/Pseudojet.jl

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ caching of the more expensive calculations for rapidity and azimuthal angle.
3535
- `_inv_pt2::T`: The inverse squared transverse momentum.
3636
- `_rap::T`: The rapidity.
3737
- `_phi::T`: The azimuthal angle.
38-
3938
"""
4039
mutable struct PseudoJet{T <: Real} <: FourMomentum
4140
px::T
@@ -81,6 +80,25 @@ PseudoJet(px::T, py::T, pz::T, E::T,
8180
py, pz, E, _cluster_hist_index,
8281
pt2, 1.0 / pt2, _invalid_rap, _invalid_phi)
8382

83+
"""
84+
PseudoJet{T}(px::T, py::T, pz::T, E::T,
85+
_cluster_hist_index::Int,
86+
pt2::T) where {T <: Real}
87+
88+
Constructs a parametrised PseudoJet object with the given momentum components
89+
and energy and history index.
90+
91+
# Arguments
92+
- `px::T`: The x-component of the momentum.
93+
- `py::T`: The y-component of the momentum.
94+
- `pz::T`: The z-component of the momentum.
95+
- `E::T`: The energy.
96+
- `_cluster_hist_index::Int`: The cluster history index.
97+
- `pt2::T`: The transverse momentum squared.
98+
99+
# Returns
100+
A `PseudoJet` object.
101+
"""
84102
PseudoJet{T}(px::T, py::T, pz::T, E::T,
85103
_cluster_hist_index::Int,
86104
pt2::T) where {T <: Real} = PseudoJet{T}(px,
@@ -99,12 +117,15 @@ Constructs a PseudoJet object with the given momentum components and energy.
99117
- `E::T`: The energy.
100118
101119
# Returns
102-
A PseudoJet object.
120+
A PseudoJet object, with type parameter `T`.
103121
"""
104122
PseudoJet(px::T, py::T,
105123
pz::T, E::T) where {T <: Real} = PseudoJet(px, py, pz, E, 0, px^2 + py^2)
106-
PseudoJet{T}(px::T, py::T,
107-
pz::T, E::T) where {T <: Real} = PseudoJet{T}(px, py, pz, E, 0, px^2 + py^2)
124+
125+
"""
126+
PseudoJet{U}(px::T, py::T, pz::T, E::T) where T <: Real, U <: Real
127+
"""
128+
PseudoJet{U}(px::T, py::T, pz::T, E::T) where {T <: Real, U <: Real} = PseudoJet{U}(U(px), U(py), U(pz), U(E), 0, U(px^2 + py^2))
108129

109130

110131
import Base.show

0 commit comments

Comments
 (0)