Skip to content

Commit 27ac784

Browse files
committed
Add keyword argument group_distance to Event
1 parent cdf8b57 commit 27ac784

File tree

1 file changed

+42
-10
lines changed

1 file changed

+42
-10
lines changed

src/Event/Event.jl

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ function Event(location::AbstractCoordinatePoint{T}, energy::RealQuantity = one(
2626
return evt
2727
end
2828

29-
function Event(locations::Vector{<:AbstractCoordinatePoint{T}}, energies::Vector{<:RealQuantity} = ones(T, length(locations)))::Event{T} where {T <: SSDFloat}
29+
function Event(locations::Vector{<:AbstractCoordinatePoint{T}}, energies::Vector{<:RealQuantity} = ones(T, length(locations)); group_distance::Union{<:Real, <:LengthQuantity} = NaN)::Event{T} where {T <: SSDFloat}
30+
d::T = T(to_internal_units(group_distance))
31+
@assert isnan(d) || d >= 0 "Group distance must be positive or NaN (no grouping), but $(group_distance) was given."
3032
evt = Event{T}()
31-
evt.locations = VectorOfArrays(broadcast(pt -> [CartesianPoint(pt)], locations))
32-
evt.energies = VectorOfArrays(broadcast(E -> [T(to_internal_units(E))], energies))
33+
if isnan(d) # default: no grouping, the charges from different hits drift independently
34+
evt.locations = VectorOfArrays(broadcast(pt -> [CartesianPoint(pt)], locations))
35+
evt.energies = VectorOfArrays(broadcast(E -> [T(to_internal_units(E))], energies))
36+
else
37+
evt.locations, evt.energies = group_points_by_distance(CartesianPoint.(locations), T.(to_internal_units.(energies)), d)
38+
end
3339
return evt
3440
end
3541

@@ -42,6 +48,7 @@ end
4248

4349
function Event(nbcc::NBodyChargeCloud{T})::Event{T} where {T <: SSDFloat}
4450
evt = Event{T}()
51+
# charges in one NBodyChargeCloud should see each other by default
4552
evt.locations = VectorOfArrays([nbcc.locations])
4653
evt.energies = VectorOfArrays([nbcc.energies])
4754
return evt
@@ -55,15 +62,40 @@ function Event(nbccs::Vector{<:NBodyChargeCloud{T}})::Event{T} where {T <: SSDFl
5562
end
5663

5764
function Event(locations::Vector{<:AbstractCoordinatePoint{T}}, energies::Vector{<:RealQuantity}, N::Int;
58-
particle_type::Type{PT} = Gamma, number_of_shells::Int = 2,
59-
radius::Vector{<:RealQuantity} = radius_guess.(T.(to_internal_units.(energies)), particle_type)
60-
)::Event{T} where {T <: SSDFloat, PT <: ParticleType}
61-
65+
particle_type::Type{PT} = Gamma, number_of_shells::Int = 2,
66+
radius::Vector{<:Union{<:Real, <:LengthQuantity}} = radius_guess.(T.(to_internal_units.(energies)), particle_type),
67+
group_distance::Union{<:Real, <:LengthQuantity} = NaN
68+
)::Event{T} where {T <: SSDFloat, PT <: ParticleType}
69+
70+
6271
@assert eachindex(locations) == eachindex(energies) == eachindex(radius)
63-
return Event(broadcast(i ->
64-
NBodyChargeCloud(locations[i], energies[i], N, particle_type,
72+
73+
d::T = T(to_internal_units(group_distance))
74+
@assert isnan(d) || d >= 0 "Group distance must be positive or NaN (no grouping), but $(group_distance) was given."
75+
76+
if isnan(d) # default: no grouping, the charges from different hits drift independently
77+
Event(
78+
broadcast(i ->
79+
NBodyChargeCloud(locations[i], energies[i], N,
6580
radius = T(to_internal_units(radius[i])), number_of_shells = number_of_shells),
66-
eachindex(locations)))
81+
eachindex(locations))
82+
)
83+
else # otherwise: group the CENTERS by distance and compose the NBodyChargeClouds around them
84+
loc, ene, rad = group_points_by_distance(CartesianPoint.(locations), T.(to_internal_units.(energies)), T.(to_internal_units.(radius)), d)
85+
nbccs = broadcast(i ->
86+
broadcast(j ->
87+
let nbcc = NBodyChargeCloud(loc[i][j], ene[i][j], N,
88+
radius = rad[i][j], number_of_shells = number_of_shells)
89+
nbcc.locations, nbcc.energies
90+
end,
91+
eachindex(loc[i])),
92+
eachindex(loc))
93+
94+
Event(
95+
broadcast(nbcc -> vcat(getindex.(nbcc, 1)...), nbccs),
96+
broadcast(nbcc -> vcat(getindex.(nbcc, 2)...), nbccs)
97+
)
98+
end
6799
end
68100

69101
function Event(

0 commit comments

Comments
 (0)