@@ -151,6 +151,45 @@ function ee_check_consistency(clusterseq, eereco, N)
151151 @debug " Consistency check passed at $msg "
152152end
153153
154+ function fill_reco_array! (eereco, particles, R2, p)
155+ for i in eachindex (particles)
156+ eereco. index[i] = i
157+ eereco. nni[i] = 0
158+ eereco. nndist[i] = R2
159+ # eereco.dijdist[i] = UNDEF # Does not need to be initialised
160+ eereco. nx[i] = nx (particles[i])
161+ eereco. ny[i] = ny (particles[i])
162+ eereco. nz[i] = nz (particles[i])
163+ eereco. E2p[i] = energy (particles[i])^ (2 p)
164+ end
165+ end
166+
167+ @inline function insert_new_jet! (eereco, i, newjet_k, R2, merged_jet, p)
168+ eereco. index[i] = newjet_k
169+ eereco. nni[i] = 0
170+ eereco. nndist[i] = R2
171+ eereco. nx[i] = nx (merged_jet)
172+ eereco. ny[i] = ny (merged_jet)
173+ eereco. nz[i] = nz (merged_jet)
174+ eereco. E2p[i] = energy (merged_jet)^ (2 p)
175+ end
176+
177+ """
178+ copy_to_slot!(eereco, i, j)
179+
180+ Copy the contents of slot `i` in the `eereco` array to slot `j`.
181+ """
182+ @inline function copy_to_slot! (eereco, i, j)
183+ eereco. index[j] = eereco. index[i]
184+ eereco. nni[j] = eereco. nni[i]
185+ eereco. nndist[j] = eereco. nndist[i]
186+ eereco. dijdist[j] = eereco. dijdist[i]
187+ eereco. nx[j] = eereco. nx[i]
188+ eereco. ny[j] = eereco. ny[i]
189+ eereco. nz[j] = eereco. nz[i]
190+ eereco. E2p[j] = eereco. E2p[i]
191+ end
192+
154193"""
155194 ee_genkt_algorithm(particles::Vector{T}; p = -1, R = 4.0,
156195 algorithm::JetAlgorithm.Algorithm = JetAlgorithm.Durham,
@@ -251,16 +290,7 @@ function _ee_genkt_algorithm(; particles::Vector{EEjet}, p = 1, R = 4.0,
251290 # jet information and populate it accordingly
252291 # We need N slots for this array
253292 eereco = StructArray {EERecoJet} (undef, N)
254- for i in eachindex (particles)
255- eereco. index[i] = i
256- eereco. nni[i] = 0
257- eereco. nndist[i] = R2
258- # eereco[i].dijdist = UNDEF # Not needed
259- eereco. nx[i] = nx (particles[i])
260- eereco. ny[i] = ny (particles[i])
261- eereco. nz[i] = nz (particles[i])
262- eereco. E2p[i] = energy (particles[i])^ (2 p)
263- end
293+ fill_reco_array! (eereco, particles, R2, p)
264294
265295 # Setup the initial history and get the total energy
266296 history, Qtot = initial_history (particles)
@@ -301,13 +331,17 @@ function _ee_genkt_algorithm(; particles::Vector{EEjet}, p = 1, R = 4.0,
301331 ijetA, ijetB = ijetB, ijetA
302332 end
303333
334+ # Resolve the jet indexes to access the actual jets
335+ jetA_idx = eereco[ijetA]. index
336+ jetB_idx = eereco[ijetB]. index
337+
304338 # Source "history" for merge
305- hist_jetA = clusterseq. jets[eereco[ijetA] . index ]. _cluster_hist_index
306- hist_jetB = clusterseq. jets[eereco[ijetB] . index ]. _cluster_hist_index
339+ hist_jetA = clusterseq. jets[jetA_idx ]. _cluster_hist_index
340+ hist_jetB = clusterseq. jets[jetB_idx ]. _cluster_hist_index
307341
308342 # Recombine jetA and jetB into the next jet
309- merged_jet = recombine (clusterseq. jets[eereco[ijetA] . index ],
310- clusterseq. jets[eereco[ijetB] . index ])
343+ merged_jet = recombine (clusterseq. jets[jetA_idx ],
344+ clusterseq. jets[jetB_idx ])
311345 merged_jet. _cluster_hist_index = length (clusterseq. history) + 1
312346
313347 # Now add the jet to the sequence, and update the history
@@ -317,26 +351,13 @@ function _ee_genkt_algorithm(; particles::Vector{EEjet}, p = 1, R = 4.0,
317351 newjet_k, dij_min)
318352
319353 # Update the compact arrays, reusing the JetA slot
320- eereco. index[ijetA] = newjet_k
321- eereco. nni[ijetA] = 0
322- eereco. nndist[ijetA] = R2
323- eereco. nx[ijetA] = nx (merged_jet)
324- eereco. ny[ijetA] = ny (merged_jet)
325- eereco. nz[ijetA] = nz (merged_jet)
326- eereco. E2p[ijetA] = energy (merged_jet)^ (2 p)
354+ insert_new_jet! (eereco, ijetA, newjet_k, R2, merged_jet, p)
327355 end
328356
329357 # Squash step - copy the final jet's compact data into the jetB slot
330358 # unless we are at the end of the array, in which case do nothing
331359 if ijetB != N
332- eereco. index[ijetB] = eereco. index[N]
333- eereco. nni[ijetB] = eereco. nni[N]
334- eereco. nndist[ijetB] = eereco. nndist[N]
335- eereco. dijdist[ijetB] = eereco. dijdist[N]
336- eereco. nx[ijetB] = eereco. nx[N]
337- eereco. ny[ijetB] = eereco. ny[N]
338- eereco. nz[ijetB] = eereco. nz[N]
339- eereco. E2p[ijetB] = eereco. E2p[N]
360+ copy_to_slot! (eereco, N, ijetB)
340361 end
341362
342363 # Now number of active jets is decreased by one
0 commit comments