Skip to content

Commit 53be5e0

Browse files
Reformat with JuliaFormatter
JuliaFormatter in SciML style (see .JuliaFormatter.toml)
1 parent 5c0655d commit 53be5e0

14 files changed

+453
-412
lines changed

.JuliaFormatter.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
style = "sciml"
2+
yas_style_nesting = true

ext/JetVisualisation.jl

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ using WGLMakie
4444
jetsplot(my_objects, cs, Module=Main) #default
4545
```
4646
"""
47-
function JetReconstruction.jetsplot(objects, cs::ClusterSequence; barsize_phi = 0.1, barsize_eta = 0.1, colormap = :glasbey_hv_n256, Module = CairoMakie)
47+
function JetReconstruction.jetsplot(objects, cs::ClusterSequence; barsize_phi = 0.1,
48+
barsize_eta = 0.1, colormap = :glasbey_hv_n256,
49+
Module = CairoMakie)
4850
idx_arrays = Vector{Int}[]
4951
for elt in cs.history
5052
elt.parent2 == JetReconstruction.BeamJet || continue
@@ -84,28 +86,29 @@ using WGLMakie
8486
jetsplot(my_objects, my_colour_arrays, Module=Main) #default
8587
```
8688
"""
87-
function JetReconstruction.jetsplot(objects, idx_arrays; barsize_phi = 0.1, barsize_eta = 0.1, colormap = :glasbey_hv_n256, Module = Main)
89+
function JetReconstruction.jetsplot(objects, idx_arrays; barsize_phi = 0.1,
90+
barsize_eta = 0.1, colormap = :glasbey_hv_n256,
91+
Module = Main)
8892
cs = fill(0, length(objects)) # colours
8993
for i in 1:length(idx_arrays), j in idx_arrays[i]
9094
cs[j] = i
9195
end
9296

9397
pts = sqrt.(JetReconstruction.pt2.(objects))
9498

95-
Module.meshscatter(
96-
Module.Point3f.(JetReconstruction.phi.(objects), JetReconstruction.rapidity.(objects), 0pts);
97-
color = cs,
98-
markersize = Module.Vec3f.(barsize_phi, barsize_eta, pts),
99-
colormap = colormap,
100-
marker = Module.Rect3f(Module.Vec3f(0), Module.Vec3f(1)),
101-
figure = (size = (700, 600),),
102-
axis = (
103-
type = Module.Axis3, perspectiveness = 0.5, azimuth = 2.6, elevation = 0.5,
104-
xlabel = "ϕ", ylabel = "η", zlabel = "kt",
105-
limits = (nothing, nothing, nothing, nothing, 0, findmax(pts)[1] + 10),
106-
),
107-
shading = NoShading,
108-
)
99+
Module.meshscatter(Module.Point3f.(JetReconstruction.phi.(objects),
100+
JetReconstruction.rapidity.(objects), 0pts);
101+
color = cs,
102+
markersize = Module.Vec3f.(barsize_phi, barsize_eta, pts),
103+
colormap = colormap,
104+
marker = Module.Rect3f(Module.Vec3f(0), Module.Vec3f(1)),
105+
figure = (size = (700, 600),),
106+
axis = (type = Module.Axis3, perspectiveness = 0.5, azimuth = 2.6,
107+
elevation = 0.5,
108+
xlabel = "ϕ", ylabel = "η", zlabel = "kt",
109+
limits = (nothing, nothing, nothing, nothing, 0,
110+
findmax(pts)[1] + 10)),
111+
shading = NoShading,)
109112
end
110113

111114
end

src/AlgorithmStrategyEnums.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@
22
using EnumX
33

44
# Valid strategy enum
5-
@enumx T = Strategy RecoStrategy Best N2Plain N2Tiled
5+
@enumx T=Strategy RecoStrategy Best N2Plain N2Tiled
66
const AllJetRecoStrategies = [String(Symbol(x)) for x in instances(RecoStrategy.Strategy)]
77

88
# Algorithm emun
9-
@enumx T = Algorithm JetAlgorithm AntiKt CA Kt EEKt Durham
9+
@enumx T=Algorithm JetAlgorithm AntiKt CA Kt EEKt Durham
1010
const AllJetRecoAlgorithms = [String(Symbol(x)) for x in instances(JetAlgorithm.Algorithm)]
1111

1212
# Map from algorithms to power values used
1313
power2algorithm = Dict(-1 => JetAlgorithm.AntiKt,
14-
0 => JetAlgorithm.CA,
15-
1 => JetAlgorithm.Kt)
14+
0 => JetAlgorithm.CA,
15+
1 => JetAlgorithm.Kt)
1616
algorithm2power = Dict(JetAlgorithm.AntiKt => -1,
17-
JetAlgorithm.CA => 0,
18-
JetAlgorithm.Kt => 1)
17+
JetAlgorithm.CA => 0,
18+
JetAlgorithm.Kt => 1)
1919

2020
# Map from string to an enum value (used for CLI parsing)
21-
Base.tryparse(E::Type{<:Enum}, str::String) =
21+
function Base.tryparse(E::Type{<:Enum}, str::String)
2222
let insts = instances(E),
2323
p = findfirst(==(Symbol(str)) Symbol, insts)
2424

2525
p !== nothing ? insts[p] : nothing
2626
end
27+
end

src/ClusterSequence.jl

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ struct HistoryElement
5252
end
5353

5454
"""Used for initial particles"""
55-
HistoryElement(jetp_index) = HistoryElement(NonexistentParent, NonexistentParent, Invalid, jetp_index, 0.0, 0.0)
56-
55+
HistoryElement(jetp_index) = HistoryElement(NonexistentParent, NonexistentParent, Invalid,
56+
jetp_index, 0.0, 0.0)
5757

5858
"""
5959
Convienence structure holding all of the relevant parameters for
@@ -63,7 +63,7 @@ struct ClusterSequence
6363
"""Algorithm and strategy used"""
6464
algorithm::JetAlgorithm.Algorithm
6565
strategy::RecoStrategy.Strategy
66-
66+
6767
"""
6868
This contains the physical PseudoJets; for each PseudoJet one can find
6969
the corresponding position in the history by looking at
@@ -96,14 +96,19 @@ ClusterSequence(p::Int, strategy::RecoStrategy.Strategy, jets, history, Qtot) =
9696
end
9797

9898
"""ClusterSequence constructor, with direct algorithm specified"""
99-
ClusterSequence(alg::JetAlgorithm.Algorithm, strategy::RecoStrategy.Strategy, jets, history, Qtot) =
100-
ClusterSequence(alg, strategy, jets, length(jets), history, Qtot)
99+
ClusterSequence(alg::JetAlgorithm.Algorithm, strategy::RecoStrategy.Strategy, jets, history, Qtot) = ClusterSequence(alg,
100+
strategy,
101+
jets,
102+
length(jets),
103+
history,
104+
Qtot)
101105

102106
"""Add a new jet's history into the recombination sequence"""
103107
add_step_to_history!(clusterseq::ClusterSequence, parent1, parent2, jetp_index, dij) = begin
104108
max_dij_so_far = max(dij, clusterseq.history[end].max_dij_so_far)
105-
push!(clusterseq.history, HistoryElement(parent1, parent2, Invalid,
106-
jetp_index, dij, max_dij_so_far))
109+
push!(clusterseq.history,
110+
HistoryElement(parent1, parent2, Invalid,
111+
jetp_index, dij, max_dij_so_far))
107112

108113
local_step = length(clusterseq.history)
109114

@@ -122,10 +127,11 @@ add_step_to_history!(clusterseq::ClusterSequence, parent1, parent2, jetp_index,
122127
clusterseq.history[parent1] = @set hist_elem.child = local_step
123128

124129
if parent2 >= 1
125-
clusterseq.history[parent2].child == Invalid || error(
126-
"Internal error. Trying to recombine an object that has previsously been recombined. Parent " * string(parent2) * "'s child index " * string(clusterseq.history[parent1].child) * ". Parent jet index: " *
127-
string(clusterseq.history[parent2].jetp_index) * ".",
128-
)
130+
clusterseq.history[parent2].child == Invalid ||
131+
error("Internal error. Trying to recombine an object that has previsously been recombined. Parent " *
132+
string(parent2) * "'s child index " *
133+
string(clusterseq.history[parent1].child) * ". Parent jet index: " *
134+
string(clusterseq.history[parent2].jetp_index) * ".")
129135
hist_elem = clusterseq.history[parent2]
130136
clusterseq.history[parent2] = @set hist_elem.child = local_step
131137
end
@@ -158,24 +164,24 @@ function inclusive_jets(clusterseq::ClusterSequence, ptmin = 0.0)
158164
jets_local
159165
end
160166

161-
162167
"""Return all exclusive jets of a ClusterSequence"""
163168
function exclusive_jets(clusterseq::ClusterSequence; dcut = nothing, njets = nothing)
164169
if isnothing(dcut) && isnothing(njets)
165170
throw(ArgumentError("Must pass either a dcut or an njets value"))
166171
end
167172

168173
if !isnothing(dcut)
169-
njets = n_exclusive_jets(clusterseq, dcut=dcut)
174+
njets = n_exclusive_jets(clusterseq, dcut = dcut)
170175
end
171176

172177
# Check that an algorithm was used that makes sense for exclusive jets
173-
if !(clusterseq.algorithm (JetAlgorithm.CA, JetAlgorithm.Kt, JetAlgorithm.EEKt, JetAlgorithm.Durham))
178+
if !(clusterseq.algorithm
179+
(JetAlgorithm.CA, JetAlgorithm.Kt, JetAlgorithm.EEKt, JetAlgorithm.Durham))
174180
throw(ArgumentError("Algorithm used is not suitable for exclusive jets ($(clusterseq.algorithm))"))
175181
end
176182

177183
# njets search
178-
stop_point = 2*clusterseq.n_initial_jets - njets + 1
184+
stop_point = 2 * clusterseq.n_initial_jets - njets + 1
179185

180186
# Sanity check - never return more jets than initial particles
181187
if stop_point < clusterseq.n_initial_jets
@@ -194,26 +200,27 @@ function exclusive_jets(clusterseq::ClusterSequence; dcut = nothing, njets = not
194200
if (parent < stop_point && parent > 0)
195201
@debug "Added exclusive jet index $(clusterseq.history[parent].jetp_index)"
196202
jet = clusterseq.jets[clusterseq.history[parent].jetp_index]
197-
push!(excl_jets, LorentzVectorCyl(pt(jet), rapidity(jet), phi(jet), mass(jet)))
203+
push!(excl_jets,
204+
LorentzVectorCyl(pt(jet), rapidity(jet), phi(jet), mass(jet)))
198205
end
199206
end
200207
end
201208

202209
excl_jets
203210
end
204211

205-
206212
"""Return all number of exclusive jets of a ClusterSequence that are above a certain dcut value"""
207213
function n_exclusive_jets(clusterseq::ClusterSequence; dcut::AbstractFloat)
208214
# Check that an algorithm was used that makes sense for exclusive jets
209-
if !(clusterseq.algorithm (JetAlgorithm.CA, JetAlgorithm.Kt, JetAlgorithm.EEKt, JetAlgorithm.Durham))
215+
if !(clusterseq.algorithm
216+
(JetAlgorithm.CA, JetAlgorithm.Kt, JetAlgorithm.EEKt, JetAlgorithm.Durham))
210217
throw(ArgumentError("Algorithm used is not suitable for exclusive jets ($(clusterseq.algorithm))"))
211218
end
212219

213220
# Locate the point where clustering would have stopped (i.e. the
214221
# first time max_dij_so_far > dcut)
215222
i_dcut = length(clusterseq.history)
216-
for i_history length(clusterseq.history):-1:1
223+
for i_history in length(clusterseq.history):-1:1
217224
@debug "Examining $i_history, max_dij=$(clusterseq.history[i_history].max_dij_so_far)"
218225
if clusterseq.history[i_history].max_dij_so_far <= dcut
219226
i_dcut = i_history
@@ -223,5 +230,4 @@ function n_exclusive_jets(clusterseq::ClusterSequence; dcut::AbstractFloat)
223230

224231
# The number of jets is then given by this formula
225232
length(clusterseq.history) - i_dcut
226-
227-
end
233+
end

src/GenericAlgo.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# switch based on the strategy, or based on the event density
33
# if the "Best" strategy is to be employed
44

5-
function jet_reconstruct(particles; p = -1, R = 1.0, recombine = +, strategy = RecoStrategy.Best)
5+
function jet_reconstruct(particles; p = -1, R = 1.0, recombine = +,
6+
strategy = RecoStrategy.Best)
67
# Either map to the fixed algorithm corresponding to the strategy
78
# or to an optimal choice based on the density of initial particles
89

src/HepMC3.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ struct Particle{T}
3838
vertex::Integer
3939
end
4040

41-
Particle{T}() where T = Particle(LorentzVector{T}(0., 0., 0., 0.), 0, 0, 0, 0)
41+
Particle{T}() where {T} = Particle(LorentzVector{T}(0.0, 0.0, 0.0, 0.0), 0, 0, 0, 0)
4242

4343
""" Read a [HepMC3](https://doi.org/10.1016/j.cpc.2020.107310) ascii file.
4444
4545
Each event is passed to the provided function f as a vector of Particles. A
4646
maximum number of events to read (value -1 to read all availble events) and
4747
a number of events to skip at the beginning of the file can be provided.
4848
"""
49-
function read_events(f, fin; maxevents=-1, skipevents=0)
49+
function read_events(f, fin; maxevents = -1, skipevents = 0)
5050
T = Float64
5151
particles = Particle{T}[]
5252
ievent = 0
5353
ipart = 0
5454
toskip = skipevents
55-
55+
5656
for (il, l) in enumerate(eachline(fin))
5757
if occursin(r"HepMC::.*-END_EVENT_LISTING", l)
5858
break
@@ -82,13 +82,14 @@ function read_events(f, fin; maxevents=-1, skipevents=0)
8282
px = parse(T, tok[5])
8383
py = parse(T, tok[6])
8484
pz = parse(T, tok[7])
85-
e = parse(T, tok[8])
85+
e = parse(T, tok[8])
8686
status = parse(Int, tok[10])
87-
push!(particles, Particle{T}(LorentzVector(e,px,py,pz), status, pdgid, barcode, vertex))
87+
push!(particles,
88+
Particle{T}(LorentzVector(e, px, py, pz), status, pdgid, barcode, vertex))
8889
end
8990
end
9091
#processing the last event:
9192
ievent > 0 && f(particles)
9293
end
9394

94-
end
95+
end

src/JetReconstruction.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export savejets, loadjets!, loadjets
5959

6060
# utility functions, useful for different primary scripts
6161
include("Utils.jl")
62-
export read_final_state_particles, read_final_state_particles_lv, pseudojets2vectors, final_jets
62+
export read_final_state_particles, read_final_state_particles_lv, pseudojets2vectors,
63+
final_jets
6364

6465
# Jet visualisation is an extension, see ext/JetVisualisation.jl
6566
function jetsplot() end

0 commit comments

Comments
 (0)