Skip to content

Commit c0b228b

Browse files
committed
Coverity
1 parent bd6ef24 commit c0b228b

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

test/_common.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ using Logging
1010
using LorentzVectorHEP
1111
using JSON
1212
using Test
13+
using StructArrays
14+
15+
using JetReconstruction: EERecoJet,
16+
fill_reco_array!, insert_new_jet!, copy_to_slot!,
17+
dij_dist, valencia_distance, valencia_distance_inv
1318

1419
logger = ConsoleLogger(stdout, Logging.Warn)
1520
global_logger(logger)

test/test-ee-reconstruction.jl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,57 @@ for r in [2.0, 4.0]
2626
(cs) -> exclusive_jets(cs; njets = 4), "exclusive njets")
2727
run_reco_test(eekt_njets)
2828
end
29+
30+
# Optimization/helper coverage
31+
32+
@testset "E2p integer fast paths in fill/insert (e+e-)" begin
33+
E1, E2 = 3.0, 2.0
34+
# PseudoJet signature is (px, py, pz, E); give nonzero momentum to avoid 1/0 in EEJet
35+
pj1 = PseudoJet(1.0, 0.0, 0.0, E1)
36+
pj2 = PseudoJet(1.0, 0.0, 0.0, E2)
37+
particles = EEJet[]
38+
push!(particles, EEJet(pj1; cluster_hist_index = 1))
39+
push!(particles, EEJet(pj2; cluster_hist_index = 2))
40+
41+
eereco = StructArray{EERecoJet}(undef, 2)
42+
R = 1.0
43+
R2 = R^2
44+
45+
fill_reco_array!(eereco, particles, R2, 1)
46+
@test eereco.E2p[1] E1^2
47+
@test eereco.E2p[2] E2^2
48+
49+
fill_reco_array!(eereco, particles, R2, 2)
50+
@test eereco.E2p[1] E1^4
51+
@test eereco.E2p[2] E2^4
52+
53+
merged = EEJet(1.0, 0.0, 0.0, 5.0; cluster_hist_index = 0)
54+
insert_new_jet!(eereco, 1, 3, R2, merged, 1)
55+
@test eereco.E2p[1] 5.0^2
56+
57+
insert_new_jet!(eereco, 2, 4, R2, merged, 2)
58+
@test eereco.E2p[2] 5.0^4
59+
end
60+
61+
@testset "copy_to_slot! copies fields" begin
62+
eereco = StructArray{EERecoJet}(undef, 2)
63+
eereco.index[1] = 10
64+
eereco.nni[1] = 1
65+
eereco.nndist[1] = 3.14
66+
eereco.dijdist[1] = 2.71
67+
eereco.nx[1] = 0.1
68+
eereco.ny[1] = 0.2
69+
eereco.nz[1] = 0.3
70+
eereco.E2p[1] = 7.0
71+
copy_to_slot!(eereco, 1, 2)
72+
@test eereco.index[2] == 10
73+
@test eereco.dijdist[2] == 2.71
74+
@test eereco.E2p[2] == 7.0
75+
end
76+
77+
@testset "dij_dist fallback error (non-Algorithm)" begin
78+
eereco = StructArray{EERecoJet}(undef, 1)
79+
eereco.nndist[1] = 0.0
80+
eereco.E2p[1] = 1.0
81+
@test_throws ArgumentError dij_dist(eereco, 1, 0, 1.0, :Foo, 1.0)
82+
end

test/test-valencia.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ valencia_exclusive_d500_b1g1 = ComparisonTestValencia(events_file_ee,
6565
"exclusive dcut=500 beta=1.0 gamma=1.0 R=1.0")
6666
run_reco_test(valencia_exclusive_d500_b1g1)
6767

68-
# Bring required types/functions into scope for targeted unit tests
69-
using JetReconstruction: EERecoJet, PseudoJet, EEJet, ee_genkt_algorithm, dij_dist,
70-
valencia_distance
71-
7268
# Test dij_dist for Valencia algorithm
7369
@testset "dij_dist Valencia" begin
7470
# Minimal eereco with two reco jets; only nx,ny,nz,E2p are used by valencia_distance
@@ -78,6 +74,17 @@ using JetReconstruction: EERecoJet, PseudoJet, EEJet, ee_genkt_algorithm, dij_di
7874
@test dij valencia_distance(eereco, 1, 2, 0.8)
7975
end
8076

77+
# Valencia distance wrapper coverage
78+
@testset "Valencia distance wrappers" begin
79+
# Minimal eereco with two reco jets and identical directions so angle=0
80+
eereco = EERecoJet[EERecoJet(1, 0, Inf, Inf, 1.0, 0.0, 0.0, 9.0),
81+
EERecoJet(2, 0, Inf, Inf, 1.0, 0.0, 0.0, 4.0)]
82+
R = 2.0
83+
invR2 = inv(R * R)
84+
@test valencia_distance_inv(eereco, 1, 2, invR2) == 0.0
85+
@test valencia_distance(eereco, 1, 2, R) == 0.0
86+
end
87+
8188
# Test ee_genkt_algorithm for Valencia algorithm (covers β override and dij_factor selection)
8289
@testset "ee_genkt_algorithm Valencia" begin
8390
particles = [PseudoJet(1.0, 0.0, 0.0, 1.0)]

0 commit comments

Comments
 (0)