Skip to content

Commit eb63e6c

Browse files
Improved softkiller examples (#193)
* Improved softkiller examples Rename --maxevents and --skip to --pileup-maxevents and --pileup-skip which allow variations in the amount of pileup to be applied. Select the hard scatter event with --eventno (this only even one event). Change hard scatter and pileup files to be positional arguments, which is more consistent with other scripts. Make both scripts a bit more verbose for the user's information. Run a jet reconstruction in softkiller_runtime.jl so that we actually do something with the reduced event. N.B. for now, the reduced event has to be rewritten into a new vector to get the cluster_hist_indexes correct. This can be removed once softkiller returns a good-for-reconstruction output. Add a test.sh script that can be used for a quick test of the examples. * Remove unused arguments
1 parent 79cee14 commit eb63e6c

File tree

4 files changed

+68
-68
lines changed

4 files changed

+68
-68
lines changed

examples/softkiller/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
# JetReconstruction.jl Examples - SoftKiller
22

3+
Here are simple examples of SoftKiller that read from two HepMC3 files and
4+
then run the SoftKiller algorithm.
5+
36
## `softkiller_plots.jl`
47

58
This example can be run as:
69

710
```sh
8-
julia --project softkiller_plots.jl --maxevents=100 --grid-size=0.4 --algorithm=Kt --pileup-file=../../test/data/sk_example_PU.hepmc.zst --hard-file=../../test/data/sk_example_HS.hepmc.zst
11+
julia --project softkiller_plots.jl --pileup-maxevents=100 --eventno=4 --grid-size=0.4 --algorithm=Kt ../../test/data/sk_example_HS.hepmc.zst ../../test/data/sk_example_PU.hepmc.zst
912
```
1013

1114
This is a simple example of SoftKiller that reads from two HepMC3 files
12-
and displays plots of clustering without SoftKiller and with SoftKiller.
15+
and displays plots of clustering with SoftKiller and without SoftKiller.
1316

1417
## `softkiller_runtime.jl`
1518

1619
This example can be run as:
1720

1821
```sh
19-
julia --project softkiller_runtime.jl --maxevents=100 --grid-size=0.4 --algorithm=Kt --pileup-file=../../test/data/sk_example_PU.hepmc.zst --hard-file=../../test/data/sk_example_HS.hepmc.zst
22+
julia --project softkiller_runtime.jl --pileup-maxevents=100 --eventno=4 --grid-size=0.4 --algorithm=Kt ../../test/data/sk_example_HS.hepmc.zst ../../test/data/sk_example_PU.hepmc.zst
2023
```
2124

22-
This is a simple example of SoftKiller that reads from two HepMC3 files
23-
and displays the runtime of the SoftKiller algorithm.
25+
For both scripts the number of pileup events to add to the hard scatter event
26+
can be controlled with `--pileup-maxevents` and `--pileup-skip`; and the hard
27+
scatter event to work with can be changed with `--eventno`.

examples/softkiller/softkiller_plots.jl

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,20 @@ include(joinpath(@__DIR__, "..", "parse-options.jl"))
1212
function parse_command_line(args)
1313
s = ArgParseSettings(autofix_names = true)
1414
@add_arg_table! s begin
15-
"--maxevents", "-n"
16-
help = "Maximum number of events to read. -1 to read all events from the file."
15+
"--pileup-maxevents", "-n"
16+
help = "Maximum number of events to read. -1 to read all events from the pileup events file."
1717
arg_type = Int
1818
default = -1
1919

20-
"--skip", "-s"
21-
help = "Number of events to skip at beginning of the file."
20+
"--pileup-skip", "-s"
21+
help = "Number of events to skip in the pileup events file."
2222
arg_type = Int
2323
default = 0
2424

25-
"--ptmin"
26-
help = "Minimum p_t for final inclusive jets (energy unit is the same as the input clusters, usually GeV)"
27-
arg_type = Float64
28-
default = 5.0
29-
30-
"--exclusive-dcut"
31-
help = "Return all exclusive jets where further merging would have d>d_cut"
32-
arg_type = Float64
33-
34-
"--exclusive-njets"
35-
help = "Return all exclusive jets once clusterisation has produced n jets"
25+
"--eventno", "-e"
26+
help = "Event number to process from the hard scatter events file. If not specified, the first event will be processed."
3627
arg_type = Int
28+
default = 1
3729

3830
"--distance", "-R"
3931
help = "Distance parameter for jet merging"
@@ -53,19 +45,16 @@ function parse_command_line(args)
5345
arg_type = RecoStrategy.Strategy
5446
default = RecoStrategy.Best
5547

56-
"--dump"
57-
help = "Write list of reconstructed jets to a JSON formatted file"
58-
5948
"--grid-size"
6049
help = "Size of Rectangular grid"
6150
arg_type = Float64
6251
default = 0.4
6352

64-
"--hard-file"
53+
"hard-file"
6554
help = "HepMC3 event file in HepMC3 to read."
6655
required = true
6756

68-
"--pileup-file"
57+
"pileup-file"
6958
help = "HepMC3 event file in HepMC3 to read."
7059
required = true
7160
end
@@ -150,6 +139,7 @@ function plot_set_up(y::Vector{Float64}, phi::Vector{Float64}, pt::Vector{Float6
150139
["Pileup", "Hard Event", "Jet"], "Legend")
151140

152141
save(plot_title * ".png", fig)
142+
@info "Plot '$(plot_title)' saved"
153143
end
154144

155145
function main()
@@ -166,21 +156,18 @@ function main()
166156

167157
# Reading pileup and hard event files
168158
events = read_final_state_particles(args[:pileup_file], jet_type;
169-
maxevents = args[:maxevents],
170-
skipevents = args[:skip])
159+
maxevents = args[:pileup_maxevents],
160+
skipevents = args[:pileup_skip])
171161

172162
h_events = read_final_state_particles(args[:hard_file], jet_type;
173-
maxevents = args[:maxevents],
174-
skipevents = args[:skip])
163+
maxevents = args[:eventno],
164+
skipevents = args[:eventno])
175165

176166
# Set up SoftKiller grid and rapidity range
177167
rapmax = 5.0
178168
grid_size = args[:grid_size]
179169
soft_killer = SoftKiller(rapmax, grid_size)
180170

181-
algorithm = args[:algorithm]
182-
p = args[:power]
183-
184171
# Ensure algorithm and power are consistent
185172
if isnothing(args[:algorithm]) && isnothing(args[:power])
186173
@warn "Neither algorithm nor power specified, defaulting to AntiKt"
@@ -205,8 +192,8 @@ function main()
205192
end
206193
end
207194

208-
# Fill hard event jets (from second event in h_events)
209-
for pseudo_jet in h_events[2]
195+
# Fill hard event jets (only the first event will be read)
196+
for pseudo_jet in h_events[1]
210197
push!(hard_only, pseudo_jet)
211198
push!(all_jets_sk, pseudo_jet)
212199
push!(all_jets, pseudo_jet)
@@ -248,6 +235,7 @@ function main()
248235
pt_threshold = 0.00
249236
# Apply SoftKiller to all_jets_sk (hard + pileup)
250237
reduced_event, pt_threshold = softkiller(soft_killer, all_jets_sk)
238+
@info "SoftKiller applied: $(length(reduced_event)) clusters remaining from $(length(all_jets_sk)), pt threshold = $pt_threshold"
251239

252240
# Plot all PseudoJets after SoftKiller, before clustering
253241
y_all_sk, phi_all_sk, pt_all_sk,

examples/softkiller/softkiller_runtime.jl

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,20 @@ include(joinpath(@__DIR__, "..", "parse-options.jl"))
1111
function parse_command_line(args)
1212
s = ArgParseSettings(autofix_names = true)
1313
@add_arg_table! s begin
14-
"--maxevents", "-n"
15-
help = "Maximum number of events to read. -1 to read all events from the file."
14+
"--pileup-maxevents", "-n"
15+
help = "Maximum number of pileup events to read. -1 to read all events from the pileup events file."
1616
arg_type = Int
1717
default = -1
1818

19-
"--skip", "-s"
20-
help = "Number of events to skip at beginning of the file."
19+
"--pileup-skip", "-s"
20+
help = "Number of events to skip in the pileup events file."
2121
arg_type = Int
2222
default = 0
2323

24-
"--ptmin"
25-
help = "Minimum p_t for final inclusive jets (energy unit is the same as the input clusters, usually GeV)"
26-
arg_type = Float64
27-
default = 5.0
28-
29-
"--exclusive-dcut"
30-
help = "Return all exclusive jets where further merging would have d>d_cut"
31-
arg_type = Float64
32-
33-
"--exclusive-njets"
34-
help = "Return all exclusive jets once clusterisation has produced n jets"
24+
"--eventno", "-e"
25+
help = "Event number to process from the hard scatter events file. If not specified, the first event will be processed."
3526
arg_type = Int
27+
default = 1
3628

3729
"--distance", "-R"
3830
help = "Distance parameter for jet merging"
@@ -52,20 +44,17 @@ function parse_command_line(args)
5244
arg_type = RecoStrategy.Strategy
5345
default = RecoStrategy.Best
5446

55-
"--dump"
56-
help = "Write list of reconstructed jets to a JSON formatted file"
57-
5847
"--grid-size"
5948
help = "Size of Rectangular grid"
6049
arg_type = Float64
6150
default = 0.4
6251

63-
"--hard-file"
64-
help = "HepMC3 event file in HepMC3 to read."
52+
"hard-file"
53+
help = "HepMC3 event file containing hard scatter events."
6554
required = true
6655

67-
"--pileup-file"
68-
help = "HepMC3 event file in HepMC3 to read."
56+
"pileup-file"
57+
help = "HepMC3 event file containing pileup events."
6958
required = true
7059
end
7160
return parse_args(args, s; as_symbols = true)
@@ -87,12 +76,12 @@ function main()
8776

8877
# Reading pileup and hard event files
8978
events = read_final_state_particles(args[:pileup_file], jet_type;
90-
maxevents = args[:maxevents],
91-
skipevents = args[:skip])
79+
maxevents = args[:pileup_maxevents],
80+
skipevents = args[:pileup_skip])
9281

9382
h_events = read_final_state_particles(args[:hard_file], jet_type;
94-
maxevents = args[:maxevents],
95-
skipevents = args[:skip])
83+
maxevents = args[:eventno],
84+
skipevents = args[:eventno])
9685

9786
# Set up SoftKiller grid and rapidity range
9887
rapmax = 5.0
@@ -110,18 +99,30 @@ function main()
11099

111100
# Fill pileup jets
112101
for event in events
113-
for pseudo_jet in event
114-
push!(all_jets_sk, pseudo_jet)
115-
end
102+
append!(all_jets_sk, event)
116103
end
117104

118-
# Fill hard event jets (from second event in h_events)
119-
for pseudo_jet in h_events[2]
120-
push!(all_jets_sk, pseudo_jet)
121-
end
105+
# Fill hard event jets from first read event in h_events (actually should be only one event!)
106+
append!(all_jets_sk, h_events[1])
122107

123108
# Apply SoftKiller to all_jets_sk (hard + pileup)
124-
softkiller(soft_killer, all_jets_sk)
109+
reduced_event, pt_threshold = softkiller(soft_killer, all_jets_sk)
110+
@info "SoftKiller applied: $(length(reduced_event)) clusters remaining from $(length(all_jets_sk)), pt threshold = $pt_threshold"
111+
112+
# Workaround for cluster_hist_indedx not being correct after SoftKiller filtering
113+
fixed_reduced_event = PseudoJet[]
114+
sizehint!(fixed_reduced_event, length(reduced_event))
115+
for i in eachindex(reduced_event)
116+
push!(fixed_reduced_event,
117+
PseudoJet(reduced_event[i].px, reduced_event[i].py, reduced_event[i].pz,
118+
reduced_event[i].E, i,
119+
reduced_event[i]._pt2, reduced_event[i]._inv_pt2,
120+
reduced_event[i]._rap, reduced_event[i]._phi))
121+
end
122+
cs = jet_reconstruct(fixed_reduced_event; algorithm = args[:algorithm],
123+
R = args[:distance], p = args[:power],
124+
strategy = args[:strategy])
125+
@info "Reconstructed softkiller filtered clusters with algorithm $(args[:algorithm]), radius $(args[:distance]) and strategy $(args[:strategy])"
125126
end
126127

127128
main()

examples/softkiller/test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#! /bin/sh
2+
3+
# Plain softkiller example
4+
julia --project softkiller_runtime.jl --pileup-maxevents=100 --eventno=4 --grid-size=0.4 --algorithm=Kt ../../test/data/sk_example_HS.hepmc.zst ../../test/data/sk_example_PU.hepmc.zst
5+
6+
# Softkiller with graphics
7+
julia --project softkiller_plots.jl --pileup-maxevents=100 --eventno=4 --grid-size=0.4 --algorithm=Kt ../../test/data/sk_example_HS.hepmc.zst ../../test/data/sk_example_PU.hepmc.zst

0 commit comments

Comments
 (0)