Skip to content

Commit 606a7dd

Browse files
Internal function improvements (#195)
* Remove extra particle copy This was an unnecessary extra copy that was being made (legacy from when we allowed the internal method to be called directly). * More consistent internal reconstruction interfaces Rename all of the internal reconstruction interfaces to ! functions as they mutate the input particle vector. Make _ee_genkt_algorithm! take particles as a positional parameter for consistency reasons with the other functions. Improve docstrings. * Format fixes * Improved documentation Co-authored-by: Mateusz Jakub Fila <[email protected]> * Additional docstring fixes --------- Co-authored-by: Mateusz Jakub Fila <[email protected]>
1 parent fa265fe commit 606a7dd

File tree

3 files changed

+84
-68
lines changed

3 files changed

+84
-68
lines changed

src/EEAlgorithm.jl

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,12 @@ Run an e+e- reconstruction algorithm on a set of initial particles.
201201
- `particles::AbstractVector{T}`: A vector of particles to be clustered.
202202
- `algorithm::JetAlgorithm.Algorithm`: The jet algorithm to use.
203203
- `p::Union{Real, Nothing} = nothing`: The power parameter for the algorithm.
204-
Must be specified for EEKt algorithm. Other algorithms will ignore this value.
205-
- `R = 4.0`: The jet radius parameter. Not required / ignored for the Durham
204+
This is not required for the `Durham` algorithm, but must be specified for the
205+
`EEKt`` algorithm.
206+
- `R = 4.0`: The jet radius parameter. Not required and ignored for the `Durham`
206207
algorithm.
207-
- `recombine`: The recombination scheme to use.
208-
- `preprocess`: Preprocessing function for input particles.
208+
- `recombine = addjets`: The recombination scheme to use.
209+
- `preprocess = nothing`: Preprocessing function for input particles.
209210
210211
# Returns
211212
- The result of the jet clustering as a `ClusterSequence` object.
@@ -214,10 +215,10 @@ Run an e+e- reconstruction algorithm on a set of initial particles.
214215
This is the public interface to the e+e- jet clustering algorithm. The function
215216
will check for consistency between the algorithm and the power parameter as
216217
needed. It will then prepare the internal EDM particles for the clustering
217-
itself, and call the actual reconstruction method `_ee_genkt_algorithm`.
218+
itself, and call the actual reconstruction method `_ee_genkt_algorithm!`.
218219
219-
If the algorithm is Durham, `R` is nominally set to 4.
220-
If the algorithm is EEkt, power `p` must be specified.
220+
If the algorithm is Durham, `R` is nominally set to 4. If the algorithm is EEkt,
221+
power `p` must also be specified.
221222
"""
222223
function ee_genkt_algorithm(particles::AbstractVector{T}; algorithm::JetAlgorithm.Algorithm,
223224
p::Union{Real, Nothing} = nothing, R = 4.0, recombine = addjets,
@@ -261,21 +262,41 @@ function ee_genkt_algorithm(particles::AbstractVector{T}; algorithm::JetAlgorith
261262
end
262263

263264
# Now call the actual reconstruction method, tuned for our internal EDM
264-
_ee_genkt_algorithm(particles = recombination_particles, p = p, R = R,
265-
algorithm = algorithm,
266-
recombine = recombine)
265+
_ee_genkt_algorithm!(recombination_particles; p = p, R = R,
266+
algorithm = algorithm,
267+
recombine = recombine)
267268
end
268269

269270
"""
270-
_ee_genkt_algorithm(; particles::AbstractVector{EEJet},
271+
_ee_genkt_algorithm!(particles::AbstractVector{EEJet};
271272
algorithm::JetAlgorithm.Algorithm, p::Real, R = 4.0,
272273
recombine = addjets)
273274
274-
This function is the actual implementation of the e+e- jet clustering algorithm.
275+
This function is the internal implementation of the e+e- jet clustering
276+
algorithm. It takes a vector of `EEJet` `particles` representing the input
277+
particles and reconstructs jets based on the specified parameters.
278+
279+
Users of the package should use the `ee_genkt_algorithm` function as their
280+
entry point to this jet reconstruction.
281+
282+
# Arguments
283+
- `particles::AbstractVector{EEJet}`: A vector of `EEJet` particles used
284+
as input for jet reconstruction. This vector must supply the correct
285+
`cluster_hist_index` values and will be *mutated* as part of the returned
286+
`ClusterSequence`.
287+
- `algorithm::JetAlgorithm.Algorithm`: The jet reconstruction algorithm to use.
288+
- `p::Real`: The power to which the transverse momentum (`pt`) of each particle
289+
is raised.
290+
- `R = 4.0`: The jet radius parameter.
291+
- `recombine = addjets`: The recombination function used to merge two jets.
292+
293+
# Returns
294+
- `clusterseq`: The resulting `ClusterSequence` object representing the
295+
reconstructed jets.
275296
"""
276-
function _ee_genkt_algorithm(; particles::AbstractVector{EEJet},
277-
algorithm::JetAlgorithm.Algorithm, p::Real, R = 4.0,
278-
recombine = addjets)
297+
function _ee_genkt_algorithm!(particles::AbstractVector{EEJet};
298+
algorithm::JetAlgorithm.Algorithm, p::Real, R::Real = 4.0,
299+
recombine = addjets)
279300
# Bounds
280301
N::Int = length(particles)
281302

src/PlainAlgo.jl

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,24 @@ end
194194
195195
Perform pp jet reconstruction using the plain algorithm.
196196
197+
The power value maps to specific pp jet reconstruction algorithms, but can be
198+
omitted when the algorithm implies the power value to use. It must be specified
199+
for the `GenKt` algorithm.
200+
197201
# Arguments
198202
- `particles::AbstractVector{T}`: A vector of particles used for jet
199203
reconstruction, any array of particles, which supports suitable 4-vector
200204
methods, viz. pt2(), phi(), rapidity(), px(), py(), pz(), energy(), can be
201205
used for each element.
202206
- `algorithm::JetAlgorithm.Algorithm`: The jet algorithm to use.
203-
- `p::Union{Real, Nothing} = nothing`: The power value used for jet reconstruction.
204-
Must be specified for GenKt algorithm. Other algorithms will ignore this value.
207+
- `p::Union{Real, Nothing} = nothing`: The power value used for jet
208+
reconstruction. Must be specified for GenKt algorithm. Other algorithms will
209+
ignore this value.
205210
- `R = 1.0`: The radius parameter used for jet reconstruction.
206211
- `recombine::Function = addjets`: The recombination function used to combine
207212
particles into a new jet.
208-
- `preprocess::Function = nothing`: A function to preprocess the input particles.
213+
- `preprocess::Function = nothing`: A function to preprocess the input
214+
particles.
209215
210216
**Note** for the `particles` argument, the 4-vector methods need to exist in the
211217
JetReconstruction package namespace.
@@ -214,12 +220,13 @@ This code will use the `k_t` algorithm types, operating in `(rapidity, φ)`
214220
space.
215221
216222
# Returns
217-
- `Vector{PseudoJet}`: A vector of reconstructed jets.
223+
- `clusterseq`: The resulting `ClusterSequence` object representing the
224+
reconstructed jets.
218225
219226
# Example
220227
```julia
221-
jets = plain_jet_reconstruct(particles; algorithm = JetAlgorithm.GenKt, p = -1, R = 0.4)
222228
jets = plain_jet_reconstruct(particles; algorithm = JetAlgorithm.Kt, R = 1.0)
229+
jets = plain_jet_reconstruct(particles; algorithm = JetAlgorithm.GenKt, p = -0.5, R = 0.4)
223230
```
224231
"""
225232
function plain_jet_reconstruct(particles::AbstractVector{T};
@@ -260,45 +267,40 @@ function plain_jet_reconstruct(particles::AbstractVector{T};
260267
end
261268

262269
# Now call the actual reconstruction method, tuned for our internal EDM
263-
_plain_jet_reconstruct(recombination_particles; algorithm = algorithm, p = p, R = R,
264-
recombine = recombine)
270+
_plain_jet_reconstruct!(recombination_particles; algorithm = algorithm, p = p, R = R,
271+
recombine = recombine)
265272
end
266273

267274
"""
268-
_plain_jet_reconstruct(particles::AbstractVector{PseudoJet};
275+
_plain_jet_reconstruct!(particles::AbstractVector{PseudoJet};
269276
algorithm::JetAlgorithm.Algorithm, p::Real, R = 1.0,
270277
recombine = addjets)
271278
272279
This is the internal implementation of jet reconstruction using the plain
273-
algorithm. It takes a vector of `particles` representing the input particles and
274-
reconstructs jets based on the specified parameters. Here the particles must be
275-
of type `PseudoJet`.
280+
algorithm. It takes a vector of `PseudoJet` `particles` representing the input
281+
particles and reconstructs jets based on the specified parameters.
276282
277283
Users of the package should use the `plain_jet_reconstruct` function as their
278284
entry point to this jet reconstruction.
279285
280-
The power value maps to specific pp jet reconstruction algorithms: -1 = AntiKt,
281-
0 = Cambridge/Aachen, 1 = Inclusive Kt. Floating point values are allowed for
282-
generalised k_t algorithm. The algorithm parameter must be consistent with the
283-
power parameter.
284-
285286
# Arguments
286-
- `particles::AbstractVector{PseudoJet}`: A vector of `PseudoJet` objects
287-
representing the input particles.
287+
- `particles::AbstractVector{PseudoJet}`: A vector of `PseudoJet` particles used
288+
as input for jet reconstruction. This vector must supply the correct
289+
`cluster_hist_index` values and will be *mutated* as part of the returned
290+
`ClusterSequence`.
288291
- `algorithm::JetAlgorithm.Algorithm`: The jet reconstruction algorithm to use.
289-
- `p::Real`: The power to which the transverse momentum (`pt`) of each particle is
290-
raised.
292+
- `p::Real`: The power to which the transverse momentum (`pt`) of each particle
293+
is raised.
291294
- `R = 1.0`: The jet radius parameter.
292-
- `recombine`: The recombination function used to merge two jets. Default is `+`
293-
(additive recombination).
295+
- `recombine = addjets`: The recombination scheme to use.
294296
295297
# Returns
296298
- `clusterseq`: The resulting `ClusterSequence` object representing the
297299
reconstructed jets.
298300
"""
299-
function _plain_jet_reconstruct(particles::AbstractVector{PseudoJet};
300-
algorithm::JetAlgorithm.Algorithm, p::Real, R = 1.0,
301-
recombine = addjets)
301+
function _plain_jet_reconstruct!(particles::AbstractVector{PseudoJet};
302+
algorithm::JetAlgorithm.Algorithm, p::Real, R = 1.0,
303+
recombine = addjets)
302304
# Bounds
303305
N::Int = length(particles)
304306
# Parameters
@@ -319,9 +321,6 @@ function _plain_jet_reconstruct(particles::AbstractVector{PseudoJet};
319321

320322
# Setup the initial history and get the total energy
321323
history, Qtot = initial_history(particles)
322-
# Current implementation mutates the particles vector, so need to copy it
323-
# for the cluster sequence (there is too much copying happening, so this
324-
# needs to be rethought and reoptimised)
325324
clusterseq = ClusterSequence(algorithm, p, R, RecoStrategy.N2Plain, particles, history,
326325
Qtot)
327326

src/TiledAlgoLL.jl

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ If both are given they must be consistent or an exception is thrown.
312312
- `preprocess::Function = nothing`: A function to preprocess the input particles.
313313
314314
## Returns
315-
- `Vector{PseudoJet}`: A vector of reconstructed jets.
315+
- `ClusterSequence`: The resulting `ClusterSequence` object representing the
316+
reconstructed jets.
316317
317318
## Example
318319
```julia
@@ -354,22 +355,24 @@ function tiled_jet_reconstruct(particles::AbstractVector{T};
354355
end
355356
end
356357

357-
_tiled_jet_reconstruct(recombination_particles; algorithm = algorithm, p = p, R = R,
358-
recombine = recombine)
358+
_tiled_jet_reconstruct!(recombination_particles; algorithm = algorithm, p = p, R = R,
359+
recombine = recombine)
359360
end
360361

361362
"""
362-
_tiled_jet_reconstruct(particles::AbstractVector{PseudoJet};
363+
_tiled_jet_reconstruct!(particles::AbstractVector{PseudoJet};
363364
algorithm::JetAlgorithm.Algorithm,
364365
p::Real, R = 1.0, recombine = addjets)
365366
366-
Main jet reconstruction algorithm entry point for reconstructing jets once preprocessing
367-
of data types are done. The algorithm parameter must be consistent with the
368-
power parameter.
367+
Main jet internal reconstruction algorithm entry point for reconstructing jets
368+
once preprocessing of data types are done. The algorithm parameter must be
369+
consistent with the power parameter.
369370
370371
## Arguments
371-
- `particles::AbstractVector{PseudoJet}`: A vector of `PseudoJet` particles used as input for jet
372-
reconstruction.
372+
- `particles::AbstractVector{PseudoJet}`: A vector of `PseudoJet` particles used
373+
as input for jet reconstruction. This vector must supply the correct
374+
`cluster_hist_index` values and will be *mutated* as part of the returned
375+
`ClusterSequence`.
373376
- `algorithm::JetAlgorithm.Algorithm`: The jet reconstruction algorithm to use.
374377
- `p::Real`: The power parameter for the jet reconstruction algorithm, thus
375378
switching between different algorithms.
@@ -378,16 +381,17 @@ power parameter.
378381
pseudojets.
379382
380383
## Returns
381-
- `Vector{PseudoJet}`: A vector of reconstructed jets.
384+
- `clusterseq`: The resulting `ClusterSequence` object representing the
385+
reconstructed jets.
382386
383387
## Example
384388
```julia
385-
_tiled_jet_reconstruct(particles::Vector{PseudoJet}; algorithm = JetAlgorithm.Kt, p = 1, R = 0.4)
389+
_tiled_jet_reconstruct!(particles::Vector{PseudoJet}; algorithm = JetAlgorithm.Kt, p = 1, R = 0.4)
386390
```
387391
"""
388-
function _tiled_jet_reconstruct(particles::AbstractVector{PseudoJet};
389-
algorithm::JetAlgorithm.Algorithm,
390-
p::Real, R = 1.0, recombine = addjets)
392+
function _tiled_jet_reconstruct!(particles::AbstractVector{PseudoJet};
393+
algorithm::JetAlgorithm.Algorithm,
394+
p::Real, R = 1.0, recombine = addjets)
391395
# Bounds
392396
N::Int = length(particles)
393397

@@ -407,17 +411,8 @@ function _tiled_jet_reconstruct(particles::AbstractVector{PseudoJet};
407411
# memory (de)allocation gets done only once
408412
tile_union = Vector{Int}(undef, 3 * _n_tile_neighbours)
409413

410-
# Container for pseudojets, sized for all initial particles, plus all of the
411-
# merged jets that can be created during reconstruction
412-
jets = PseudoJet[]
413-
sizehint!(jets, N * 2)
414-
resize!(jets, N)
415-
416-
# Copy input data into the jets container
417-
copyto!(jets, particles)
418-
419414
# Setup the initial history and get the total energy
420-
history, Qtot = initial_history(jets)
415+
history, Qtot = initial_history(particles)
421416

422417
# Now get the tiling setup
423418
_eta = Vector{Float64}(undef, length(particles))
@@ -428,7 +423,8 @@ function _tiled_jet_reconstruct(particles::AbstractVector{PseudoJet};
428423
tiling = Tiling(setup_tiling(_eta, R))
429424

430425
# ClusterSequence is the struct that holds the state of the reconstruction
431-
clusterseq = ClusterSequence(algorithm, p, R, RecoStrategy.N2Tiled, jets, history, Qtot)
426+
clusterseq = ClusterSequence(algorithm, p, R, RecoStrategy.N2Tiled, particles, history,
427+
Qtot)
432428

433429
# Tiled jets is a structure that has additional variables for tracking which tile a jet is in
434430
tiledjets = similar(clusterseq.jets, TiledJet)

0 commit comments

Comments
 (0)