Skip to content

Commit 427eb2d

Browse files
Update input particles to be AbstractVector (#150)
* Update input particles to be AbstractVector Take an AbstractVector for the algorithm entry points, which allows EDM4hep data to be used correctly again. (cherry picked from commit b935be9) * Allow AbstractVector for backend algorithms To avoid the situation where the input particle collection is copied from an AbstractVector, relax the stipulation that the algorithm imlemenation must be a Vector. For consistency, the main user entry point, jet_reconstruct() also should take an AbstractVector as input. (cherry picked from commit f8ad488)
1 parent 8e3db85 commit 427eb2d

File tree

4 files changed

+34
-30
lines changed

4 files changed

+34
-30
lines changed

src/EEAlgorithm.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,14 @@ Copy the contents of slot `i` in the `eereco` array to slot `j`.
191191
end
192192

193193
"""
194-
ee_genkt_algorithm(particles::Vector{T}; p = -1, R = 4.0,
194+
ee_genkt_algorithm(particles::AbstractVector{T}; p = -1, R = 4.0,
195195
algorithm::JetAlgorithm.Algorithm = JetAlgorithm.Durham,
196196
recombine = +) where {T}
197197
198198
Run an e+e- reconstruction algorithm on a set of initial particles.
199199
200200
# Arguments
201-
- `particles::Vector{T}`: A vector of particles to be clustered.
201+
- `particles::AbstractVector{T}`: A vector of particles to be clustered.
202202
- `p = 1`: The power parameter for the algorithm. Not required / ignored for
203203
the Durham algorithm when it is set to 1.
204204
- `R = 4.0`: The jet radius parameter. Not required / ignored for the Durham
@@ -221,7 +221,7 @@ If the algorithm is Durham, `p` is set to 1 and `R` is nominally set to 4.
221221
Note that unlike `pp` reconstruction the algorithm has to be specified
222222
explicitly.
223223
"""
224-
function ee_genkt_algorithm(particles::Vector{T}; p = 1,
224+
function ee_genkt_algorithm(particles::AbstractVector{T}; p = 1,
225225
algorithm::JetAlgorithm.Algorithm = JetAlgorithm.Durham,
226226
R = 4.0, recombine = +) where {T}
227227

@@ -258,13 +258,13 @@ function ee_genkt_algorithm(particles::Vector{T}; p = 1,
258258
end
259259

260260
"""
261-
_ee_genkt_algorithm(; particles::Vector{EEJet}, p = 1, R = 4.0,
261+
_ee_genkt_algorithm(; particles::AbstractVector{EEJet}, p = 1, R = 4.0,
262262
algorithm::JetAlgorithm.Algorithm = JetAlgorithm.Durham,
263263
recombine = +)
264264
265265
This function is the actual implementation of the e+e- jet clustering algorithm.
266266
"""
267-
function _ee_genkt_algorithm(; particles::Vector{EEJet}, p = 1, R = 4.0,
267+
function _ee_genkt_algorithm(; particles::AbstractVector{EEJet}, p = 1, R = 4.0,
268268
algorithm::JetAlgorithm.Algorithm = JetAlgorithm.Durham,
269269
recombine = +)
270270
# Bounds

src/GenericAlgo.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
jet_reconstruct(particles; p::Union{Real, Nothing} = nothing,
2+
jet_reconstruct(particles::AbstractVector; p::Union{Real, Nothing} = nothing,
33
algorithm::Union{JetAlgorithm.Algorithm, Nothing} = nothing,
44
R = 1.0, recombine = +,
55
strategy::RecoStrategy.Strategy = RecoStrategy.Best)
@@ -8,10 +8,11 @@ Reconstructs jets from a collection of particles using a specified algorithm and
88
strategy.
99
1010
# Arguments
11-
- `particles`: A collection of particles used for jet reconstruction.
12-
- `p::Union{Real, Nothing} = nothing`: The power value used for the distance measure
13-
for generalised k_T, which maps to a particular reconstruction algorithm (-1 =
14-
AntiKt, 0 = Cambridge/Aachen, 1 = Kt).
11+
- `particles::AbstractVector`: A collection of particles used for jet
12+
reconstruction.
13+
- `p::Union{Real, Nothing} = nothing`: The power value used for the distance
14+
measure for generalised k_T, which maps to a particular reconstruction
15+
algorithm (-1 = AntiKt, 0 = Cambridge/Aachen, 1 = Kt).
1516
- `algorithm::Union{JetAlgorithm.Algorithm, Nothing} = nothing`: The algorithm
1617
to use for jet reconstruction.
1718
- `R = 1.0`: The jet radius parameter.
@@ -20,7 +21,8 @@ strategy.
2021
strategy to use. `RecoStrategy.Best` makes a dynamic decision based on the
2122
number of starting particles.
2223
23-
Note that one of `p` or `algorithm` must be specified, with `algorithm` preferred.
24+
Note that one of `p` or `algorithm` must be specified, with `algorithm`
25+
preferred.
2426
2527
# Returns
2628
A cluster sequence object containing the reconstructed jets and the merging
@@ -44,8 +46,8 @@ it or `nothing`. If the algorithm is one where `p` can vary, then it has to be
4446
given, along with the algorithm.
4547
4648
If the `p` parameter is passed and `algorithm=nothing`, then pp-type
47-
reconstruction is implied (i.e., AntiKt, CA, Kt or GenKt will be used,
48-
depending on the value of `p`).
49+
reconstruction is implied (i.e., AntiKt, CA, Kt or GenKt will be used, depending
50+
on the value of `p`).
4951
5052
When an algorithm has no `R` dependence the `R` parameter is ignored.
5153
@@ -57,7 +59,7 @@ jet_reconstruct(particles; algorithm = JetAlgorithm.Durham)
5759
jet_reconstruct(particles; algorithm = JetAlgorithm.GenKt, p = 0.5, R = 1.0)
5860
```
5961
"""
60-
function jet_reconstruct(particles; p::Union{Real, Nothing} = nothing,
62+
function jet_reconstruct(particles::AbstractVector; p::Union{Real, Nothing} = nothing,
6163
algorithm::Union{JetAlgorithm.Algorithm, Nothing} = nothing,
6264
R = 1.0, recombine = +,
6365
strategy::RecoStrategy.Strategy = RecoStrategy.Best)

src/PlainAlgo.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,17 @@ Base.@propagate_inbounds function upd_nn_step!(i, j, k, N, Nn, kt2_array, rapidi
187187
end
188188

189189
"""
190-
plain_jet_reconstruct(particles::Vector{T}; p::Union{Real, Nothing} = -1,
190+
plain_jet_reconstruct(particles::AbstractVector{T}; p::Union{Real, Nothing} = -1,
191191
algorithm::Union{JetAlgorithm.Algorithm, Nothing} = nothing,
192192
R = 1.0, recombine = +) where {T}
193193
194194
Perform pp jet reconstruction using the plain algorithm.
195195
196196
# Arguments
197-
- `particles::Vector{T}`: A vector of particles used for jet reconstruction, any
198-
array of particles, which supports suitable 4-vector methods, viz. pt2(),
199-
phi(), rapidity(), px(), py(), pz(), energy(), can be used. for each element.
197+
- `particles::AbstractVector{T}`: A vector of particles used for jet
198+
reconstruction, any array of particles, which supports suitable 4-vector
199+
methods, viz. pt2(), phi(), rapidity(), px(), py(), pz(), energy(), can be
200+
used. for each element.
200201
- `p::Union{Real, Nothing} = -1`: The power value used for jet reconstruction.
201202
- `algorithm::Union{JetAlgorithm, Nothing} = nothing`: The explicit jet
202203
algorithm to use.
@@ -207,7 +208,8 @@ Perform pp jet reconstruction using the plain algorithm.
207208
**Note** for the `particles` argument, the 4-vector methods need to exist in the
208209
JetReconstruction package namespace.
209210
210-
This code will use the `k_t` algorithm types, operating in `(rapidity, φ)` space.
211+
This code will use the `k_t` algorithm types, operating in `(rapidity, φ)`
212+
space.
211213
212214
It is not necessary to specify both the `algorithm` and the `p` (power) value.
213215
If both are given they must be consistent or an exception is thrown.
@@ -221,7 +223,7 @@ jets = plain_jet_reconstruct(particles; p = -1, R = 0.4)
221223
jets = plain_jet_reconstruct(particles; algorithm = JetAlgorithm.Kt, R = 1.0)
222224
```
223225
"""
224-
function plain_jet_reconstruct(particles::Vector{T}; p::Union{Real, Nothing} = -1,
226+
function plain_jet_reconstruct(particles::AbstractVector{T}; p::Union{Real, Nothing} = -1,
225227
algorithm::Union{JetAlgorithm.Algorithm, Nothing} = nothing,
226228
R = 1.0, recombine = +) where {T}
227229

@@ -253,7 +255,7 @@ function plain_jet_reconstruct(particles::Vector{T}; p::Union{Real, Nothing} = -
253255
end
254256

255257
"""
256-
_plain_jet_reconstruct(; particles::Vector{PseudoJet}, p = -1,
258+
_plain_jet_reconstruct(; particles::AbstractVector{PseudoJet}, p = -1,
257259
algorithm::JetAlgorithm.Algorithm = JetAlgorithm.AntiKt,
258260
R = 1.0, recombine = +)
259261
@@ -284,7 +286,7 @@ power parameter.
284286
- `clusterseq`: The resulting `ClusterSequence` object representing the
285287
reconstructed jets.
286288
"""
287-
function _plain_jet_reconstruct(; particles::Vector{PseudoJet}, p = -1,
289+
function _plain_jet_reconstruct(; particles::AbstractVector{PseudoJet}, p = -1,
288290
algorithm::JetAlgorithm.Algorithm = JetAlgorithm.AntiKt,
289291
R = 1.0, recombine = +)
290292
# Bounds

src/TiledAlgoLL.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ function find_tile_neighbours!(tile_union, jetA, jetB, oldB, tiling)
330330
end
331331

332332
"""
333-
tiled_jet_reconstruct(particles::Vector{T}; p::Union{Real, Nothing} = -1,
333+
tiled_jet_reconstruct(particles::AbstractVector{T}; p::Union{Real, Nothing} = -1,
334334
algorithm::Union{JetAlgorithm.Algorithm, Nothing} = nothing,
335335
R = 1.0, recombine = +) where {T}
336336
@@ -347,13 +347,13 @@ It is not necessary to specify both the `algorithm` and the `p` (power) value.
347347
If both are given they must be consistent or an exception is thrown.
348348
349349
## Arguments
350-
- `particles::Vector{T}`: A vector of particles used as input for jet
350+
- `particles::AbstractVector{T}`: A vector of particles used as input for jet
351351
reconstruction. T must support methods px, py, pz and energy (defined in the
352352
JetReconstruction namespace)
353353
- `p::Union{Real, Nothing} = -1`: The power parameter for the jet reconstruction
354354
algorithm, thus switching between different algorithms.
355-
- `algorithm::Union{JetAlgorithm.Algorithm, Nothing} = nothing`: The explicit jet
356-
algorithm to use.
355+
- `algorithm::Union{JetAlgorithm.Algorithm, Nothing} = nothing`: The explicit
356+
jet algorithm to use.
357357
- `R::Float64 = 1.0`: The jet radius parameter for the jet reconstruction
358358
algorithm.
359359
- `recombine::Function = +`: The recombination function used for combining
@@ -367,7 +367,7 @@ If both are given they must be consistent or an exception is thrown.
367367
tiled_jet_reconstruct(particles::Vector{LorentzVectorHEP}; p = -1, R = 0.4, recombine = +)
368368
```
369369
"""
370-
function tiled_jet_reconstruct(particles::Vector{T}; p::Union{Real, Nothing} = -1,
370+
function tiled_jet_reconstruct(particles::AbstractVector{T}; p::Union{Real, Nothing} = -1,
371371
algorithm::Union{JetAlgorithm.Algorithm, Nothing} = nothing,
372372
R = 1.0, recombine = +) where {T}
373373

@@ -399,7 +399,7 @@ Main jet reconstruction algorithm, using PseudoJet objects
399399
"""
400400

401401
"""
402-
_tiled_jet_reconstruct(particles::Vector{PseudoJet}; p::Real = -1,
402+
_tiled_jet_reconstruct(particles::AbstractVector{PseudoJet}; p::Real = -1,
403403
algorithm::JetAlgorithm.Algorithm = JetAlgorithm.AntiKt,
404404
R = 1.0, recombine = +)
405405
@@ -408,7 +408,7 @@ of data types are done. The algorithm parameter must be consistent with the
408408
power parameter.
409409
410410
## Arguments
411-
- `particles::Vector{PseudoJet}`: A vector of `PseudoJet` particles used as input for jet
411+
- `particles::AbstractVector{PseudoJet}`: A vector of `PseudoJet` particles used as input for jet
412412
reconstruction.
413413
- `p::Real = -1`: The power parameter for the jet reconstruction algorithm, thus
414414
switching between different algorithms.
@@ -427,7 +427,7 @@ power parameter.
427427
tiled_jet_reconstruct(particles::Vector{PseudoJet}; p = 1, R = 1.0, recombine = +)
428428
```
429429
"""
430-
function _tiled_jet_reconstruct(particles::Vector{PseudoJet}; p::Real = -1,
430+
function _tiled_jet_reconstruct(particles::AbstractVector{PseudoJet}; p::Real = -1,
431431
algorithm::JetAlgorithm.Algorithm = JetAlgorithm.AntiKt,
432432
R = 1.0, recombine = +)
433433
# Bounds

0 commit comments

Comments
 (0)