Skip to content

Commit 94cecd9

Browse files
Fix default p value and refactor tests (#128)
Fix default value for p in jet_reconstruct() The default value was wrongly set to -1, meaning that passing an algorithm which required p!=-1 caused an algorithm/power inconsistency when the power was not explicit. Now default set to nothing. Add unittests for this, including cases where things should throw. Refactor the alg/power consistency checks to their own file, as done for all other tests. Also refactor type comparison test to separate file. Expand the example test.sh to more cases (however, these did not trigger the bug, as then the value p=nothing was explicitly passed).
1 parent 59f3f70 commit 94cecd9

6 files changed

+157
-84
lines changed

examples/test.sh

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ julia --project instrumented-jetreco.jl --algorithm=AntiKt -R 0.4 ../test/data/e
66
echo "pp 14 TeV Plain profile"
77
julia --project instrumented-jetreco.jl --algorithm=AntiKt -R 0.4 ../test/data/events.pp13TeV.hepmc3.gz -S N2Plain -m 2 --profile test
88

9+
echo "pp 14TeV CA"
10+
julia --project instrumented-jetreco.jl --algorithm=CA -R 1.0 ../test/data/events.pp13TeV.hepmc3.gz
11+
12+
echo "pp 14TeV Kt"
13+
julia --project instrumented-jetreco.jl --algorithm=Kt -R 1.0 ../test/data/events.pp13TeV.hepmc3.gz
14+
915
echo "ee H Durham allocation test"
1016
julia --project instrumented-jetreco.jl --algorithm=Durham --alloc ../test/data/events.eeH.hepmc3.gz
1117

src/GenericAlgo.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jet_reconstruct(particles; algorithm = JetAlgorithm.Durham)
5252
jet_reconstruct(particles; algorithm = JetAlgorithm.GenKt, p = 0.5, R = 1.0)
5353
```
5454
"""
55-
function jet_reconstruct(particles; p::Union{Real, Nothing} = -1, R = 1.0,
55+
function jet_reconstruct(particles; p::Union{Real, Nothing} = nothing, R = 1.0,
5656
algorithm::Union{JetAlgorithm.Algorithm, Nothing} = nothing,
5757
recombine = +,
5858
strategy = RecoStrategy.Best)

test/runtests.jl

+5-83
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,11 @@
33
include("common.jl")
44

55
function main()
6-
# A few unit tests
7-
@testset "Algorithm/power consistency" begin
8-
@test JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.AntiKt,
9-
p = -1)
10-
@test JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.CA,
11-
p = 0)
12-
@test JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.Kt,
13-
p = 1)
6+
# Algorithm/power consistency checks
7+
include("test-algpower-consistency.jl")
148

15-
@test JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.AntiKt,
16-
p = nothing)
17-
@test JetReconstruction.check_algorithm_power_consistency(algorithm = nothing,
18-
p = -1)
19-
20-
@test_throws ArgumentError JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.AntiKt,
21-
p = 0)
22-
@test_throws ArgumentError JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.Kt,
23-
p = 1.5)
24-
25-
@test JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.GenKt,
26-
p = 1.5)
27-
@test JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.GenKt,
28-
p = -0.5)
29-
30-
@test_throws ArgumentError JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.GenKt,
31-
p = nothing)
32-
end
9+
# jet_reconstruct() interface check
10+
include("test-jet_reconstruct-interface.jl")
3311

3412
# New test structure, factorised tests for pp and e+e-
3513
include("test-pp-reconstruction.jl")
@@ -39,8 +17,7 @@ function main()
3917
include("test-selection.jl")
4018

4119
# Compare inputting data in PseudoJet with using a LorentzVector
42-
do_test_compare_types(RecoStrategy.N2Plain, algname = pp_algorithms[-1], power = -1)
43-
do_test_compare_types(RecoStrategy.N2Tiled, algname = pp_algorithms[-1], power = -1)
20+
include("test-compare-types.jl")
4421

4522
# Check jet constituents
4623
include("test-constituents.jl")
@@ -58,61 +35,6 @@ function main()
5835
include("test-aqua.jl")
5936
end
6037

61-
function do_test_compare_types(strategy::RecoStrategy.Strategy;
62-
algname = "Unknown",
63-
ptmin::Float64 = 5.0,
64-
distance::Float64 = 0.4,
65-
power::Integer = -1)
66-
67-
# Strategy
68-
if (strategy == RecoStrategy.N2Plain)
69-
jet_reconstruction = plain_jet_reconstruct
70-
strategy_name = "N2Plain"
71-
elseif (strategy == RecoStrategy.N2Tiled)
72-
jet_reconstruction = tiled_jet_reconstruct
73-
strategy_name = "N2Tiled"
74-
else
75-
throw(ErrorException("Strategy not yet implemented"))
76-
end
77-
78-
# Now run our jet reconstruction...
79-
# From PseudoJets
80-
events::Vector{Vector{PseudoJet}} = read_final_state_particles(events_file_pp)
81-
jet_collection = FinalJets[]
82-
for (ievt, event) in enumerate(events)
83-
finaljets = final_jets(inclusive_jets(jet_reconstruction(event, R = distance,
84-
p = power), ptmin = ptmin))
85-
sort_jets!(finaljets)
86-
push!(jet_collection, FinalJets(ievt, finaljets))
87-
end
88-
89-
# From LorentzVector
90-
events_lv::Vector{Vector{LorentzVector}} = read_final_state_particles(events_file_pp;
91-
T = LorentzVector)
92-
jet_collection_lv = FinalJets[]
93-
for (ievt, event) in enumerate(events_lv)
94-
finaljets = final_jets(inclusive_jets(jet_reconstruction(event, R = distance,
95-
p = power), ptmin = ptmin))
96-
sort_jets!(finaljets)
97-
push!(jet_collection_lv, FinalJets(ievt, finaljets))
98-
end
99-
100-
@testset "Jet Reconstruction Compare PseudoJet and LorentzVector, Strategy $strategy_name, Algorithm $algname" begin
101-
# Here we test that inputting LorentzVector gave the same results as PseudoJets
102-
for (ievt, (event, event_lv)) in enumerate(zip(jet_collection, jet_collection_lv))
103-
@testset "Event $(ievt)" begin
104-
@test size(event.jets) == size(event_lv.jets)
105-
# Test each jet in turn
106-
for (jet, jet_lv) in zip(event.jets, event_lv.jets)
107-
@test jet.rapjet_lv.rap atol=1e-7
108-
@test jet.phijet_lv.phi atol=1e-7
109-
@test jet.ptjet_lv.pt rtol=1e-6
110-
end
111-
end
112-
end
113-
end
114-
end
115-
11638
logger = ConsoleLogger(stdout, Logging.Warn)
11739
global_logger(logger)
11840
main()

test/test-algpower-consistency.jl

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Tests of algorithm/power consistency checks
2+
3+
include("common.jl")
4+
5+
@testset "Algorithm/power consistency" begin
6+
@test JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.AntiKt,
7+
p = -1)
8+
@test JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.CA,
9+
p = 0)
10+
@test JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.Kt,
11+
p = 1)
12+
13+
@test JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.AntiKt,
14+
p = nothing)
15+
@test JetReconstruction.check_algorithm_power_consistency(algorithm = nothing,
16+
p = -1)
17+
18+
@test_throws ArgumentError JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.AntiKt,
19+
p = 0)
20+
@test_throws ArgumentError JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.Kt,
21+
p = 1.5)
22+
23+
@test JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.GenKt,
24+
p = 1.5)
25+
@test JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.GenKt,
26+
p = -0.5)
27+
28+
@test_throws ArgumentError JetReconstruction.check_algorithm_power_consistency(algorithm = JetAlgorithm.GenKt,
29+
p = nothing)
30+
end

test/test-compare-types.jl

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Compare inputting data in PseudoJet with using a LorentzVector
2+
3+
include("common.jl")
4+
5+
function do_test_compare_types(strategy::RecoStrategy.Strategy;
6+
algname = "Unknown",
7+
ptmin::Float64 = 5.0,
8+
distance::Float64 = 0.4,
9+
power::Integer = -1)
10+
11+
# Strategy
12+
if (strategy == RecoStrategy.N2Plain)
13+
jet_reconstruction = plain_jet_reconstruct
14+
strategy_name = "N2Plain"
15+
elseif (strategy == RecoStrategy.N2Tiled)
16+
jet_reconstruction = tiled_jet_reconstruct
17+
strategy_name = "N2Tiled"
18+
else
19+
throw(ErrorException("Strategy not yet implemented"))
20+
end
21+
22+
# Now run our jet reconstruction...
23+
# From PseudoJets
24+
events::Vector{Vector{PseudoJet}} = read_final_state_particles(events_file_pp)
25+
jet_collection = FinalJets[]
26+
for (ievt, event) in enumerate(events)
27+
finaljets = final_jets(inclusive_jets(jet_reconstruction(event, R = distance,
28+
p = power), ptmin = ptmin))
29+
sort_jets!(finaljets)
30+
push!(jet_collection, FinalJets(ievt, finaljets))
31+
end
32+
33+
# From LorentzVector
34+
events_lv::Vector{Vector{LorentzVector}} = read_final_state_particles(events_file_pp;
35+
T = LorentzVector)
36+
jet_collection_lv = FinalJets[]
37+
for (ievt, event) in enumerate(events_lv)
38+
finaljets = final_jets(inclusive_jets(jet_reconstruction(event, R = distance,
39+
p = power), ptmin = ptmin))
40+
sort_jets!(finaljets)
41+
push!(jet_collection_lv, FinalJets(ievt, finaljets))
42+
end
43+
44+
@testset "Jet Reconstruction Compare PseudoJet and LorentzVector, Strategy $strategy_name, Algorithm $algname" begin
45+
# Here we test that inputting LorentzVector gave the same results as PseudoJets
46+
for (ievt, (event, event_lv)) in enumerate(zip(jet_collection, jet_collection_lv))
47+
@testset "Event $(ievt)" begin
48+
@test size(event.jets) == size(event_lv.jets)
49+
# Test each jet in turn
50+
for (jet, jet_lv) in zip(event.jets, event_lv.jets)
51+
@test jet.rapjet_lv.rap atol=1e-7
52+
@test jet.phijet_lv.phi atol=1e-7
53+
@test jet.ptjet_lv.pt rtol=1e-6
54+
end
55+
end
56+
end
57+
end
58+
end
59+
60+
do_test_compare_types(RecoStrategy.N2Plain, algname = pp_algorithms[-1], power = -1)
61+
do_test_compare_types(RecoStrategy.N2Tiled, algname = pp_algorithms[-1], power = -1)
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Test the different interface modes of the main jet_reconstruct() function
2+
3+
include("common.jl")
4+
5+
let inputs = JetReconstruction.read_final_state_particles(events_file_ee)
6+
@testset "jet_reconstruct() interface" begin
7+
# EE Algorithms
8+
@test typeof(jet_reconstruct(inputs[1]; algorithm = JetAlgorithm.Durham)) ==
9+
ClusterSequence{EEjet}
10+
@test typeof(jet_reconstruct(inputs[1]; algorithm = JetAlgorithm.EEKt, p = -1,
11+
R = 1.0)) == ClusterSequence{EEjet}
12+
@test_throws ArgumentError jet_reconstruct(inputs[1];
13+
algorithm = JetAlgorithm.EEKt)
14+
15+
# PP Algorithms
16+
@test typeof(jet_reconstruct(inputs[1]; algorithm = JetAlgorithm.AntiKt)) ==
17+
ClusterSequence{PseudoJet}
18+
@test typeof(jet_reconstruct(inputs[1]; algorithm = JetAlgorithm.CA)) ==
19+
ClusterSequence{PseudoJet}
20+
@test typeof(jet_reconstruct(inputs[1]; algorithm = JetAlgorithm.Kt)) ==
21+
ClusterSequence{PseudoJet}
22+
@test typeof(jet_reconstruct(inputs[1]; algorithm = JetAlgorithm.AntiKt, p = -1)) ==
23+
ClusterSequence{PseudoJet}
24+
@test typeof(jet_reconstruct(inputs[1]; algorithm = JetAlgorithm.CA, p = 0)) ==
25+
ClusterSequence{PseudoJet}
26+
@test typeof(jet_reconstruct(inputs[1]; algorithm = JetAlgorithm.Kt, p = 1)) ==
27+
ClusterSequence{PseudoJet}
28+
@test typeof(jet_reconstruct(inputs[1]; algorithm = JetAlgorithm.GenKt, p = 1.0,
29+
R = 0.4)) == ClusterSequence{PseudoJet}
30+
31+
@test_throws ArgumentError jet_reconstruct(inputs[1];
32+
algorithm = JetAlgorithm.AntiKt,
33+
p = 0)
34+
@test_throws ArgumentError jet_reconstruct(inputs[1];
35+
algorithm = JetAlgorithm.CA,
36+
p = 1)
37+
@test_throws ArgumentError jet_reconstruct(inputs[1];
38+
algorithm = JetAlgorithm.Kt,
39+
p = -1)
40+
@test_throws ArgumentError jet_reconstruct(inputs[1];
41+
algorithm = JetAlgorithm.GenKt,
42+
R = 0.4)
43+
44+
# Supported for now, but will deprecate this calling mode, where only
45+
# the power is given, at the next major release
46+
@test typeof(jet_reconstruct(inputs[1]; p = -1)) == ClusterSequence{PseudoJet}
47+
@test typeof(jet_reconstruct(inputs[1]; p = 0)) == ClusterSequence{PseudoJet}
48+
@test typeof(jet_reconstruct(inputs[1]; p = 1)) == ClusterSequence{PseudoJet}
49+
@test_throws KeyError jet_reconstruct(inputs[1]; p = 0.5)
50+
51+
# No algorithm or power will throw
52+
@test_throws ArgumentError jet_reconstruct(inputs[1])
53+
end
54+
end

0 commit comments

Comments
 (0)