Skip to content

Commit ff18bf6

Browse files
authored
Merge pull request #553 from hervasa2/main
Use vectors instead of points to `move_charges_inside_semiconductor`
2 parents 056a94e + 556e861 commit ff18bf6

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Rotations = "1"
7979
SpecialFunctions = "1.6.1, 2"
8080
StaticArrays = "1"
8181
Statistics = "<0.0.1, 1"
82-
StatsBase = "0.33.7, 0.34"
82+
StatsBase = "0.33.14, 0.34"
8383
Suppressor = "0.2"
8484
Tables = "1.1"
8585
TypedTables = "1.2"

src/Event/Event.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ function move_charges_inside_semiconductor!(
156156
proj::T = (i - charge_center) (l - charge_center) / sum((l - charge_center).^2)
157157
if 0 proj 1
158158
if i in det.semiconductor
159-
locations[n][m] = (1 - fraction * proj) * i + fraction * proj * charge_center
159+
locations[n][m] = cartesian_zero + (1 - fraction * proj) * (i - cartesian_zero) + fraction * proj * (charge_center - cartesian_zero)
160160
end
161161
end
162162
end
163163
end
164164
end
165165
charge_center_new = mean(locations[n], Weights(edep_weights))
166166
if verbose
167-
@warn "$(sum(.!idx_in)) charges of the charge cloud at $(round.(charge_center, digits = (T == Float64 ? 12 : 6)))"*
168-
" are outside. Moving them inside...\nThe new charge center is at $(round.(charge_center_new, digits = (T == Float64 ? 12 : 6))).\n"
167+
@warn "$(sum(.!idx_in)) charges of the charge cloud at $(round.(charge_center - cartesian_zero, digits = (T == Float64 ? 12 : 6)))"*
168+
" are outside. Moving them inside...\nThe new charge center is at $(round.(charge_center_new - cartesian_zero, digits = (T == Float64 ? 12 : 6))).\n"
169169
end
170170
end
171171
end

src/MCEventsProcessing/MCEventsProcessing.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ function _convertEnergyDepsToChargeDeps(
135135
particle_type::Type{PT} = Gamma,
136136
radius::AbstractVector{<:AbstractVector{<:Union{<:Real, <:LengthQuantity}}} = map(e -> radius_guess.(to_internal_units.(e), particle_type), edep),
137137
number_of_carriers::Int = 1, number_of_shells::Int = 1,
138-
max_interaction_distance::Union{<:Real, <:LengthQuantity} = NaN # is ignored here
138+
max_interaction_distance::Union{<:Real, <:LengthQuantity} = NaN, # is ignored here
139+
kwargs...
139140
) where {T <: SSDFloat, PT <: ParticleType}
140141

141142
charge_clouds = broadcast(
@@ -148,7 +149,7 @@ function _convertEnergyDepsToChargeDeps(
148149
number_of_shells = number_of_shells,
149150
radius = T(to_internal_units(radius[iEdep_indep][i_together]))
150151
)
151-
move_charges_inside_semiconductor!([nbcc.locations], [nbcc.energies], det)
152+
move_charges_inside_semiconductor!([nbcc.locations], [nbcc.energies], det; kwargs...)
152153
nbcc
153154
end,
154155
eachindex(edep[iEdep_indep])
@@ -172,7 +173,7 @@ function _simulate_charge_drifts( mcevents::TypedTables.Table, sim::Simulation{T
172173
geometry_check::Bool,
173174
verbose::Bool ) where {T <: SSDFloat}
174175
@showprogress map(mcevents) do phyevt
175-
locations, edeps = _convertEnergyDepsToChargeDeps(phyevt.pos, phyevt.edep, sim.detector; number_of_carriers, number_of_shells, max_interaction_distance)
176+
locations, edeps = _convertEnergyDepsToChargeDeps(phyevt.pos, phyevt.edep, sim.detector; number_of_carriers, number_of_shells, max_interaction_distance, verbose)
176177
drift_paths = map( i -> _drift_charges(sim.detector, sim.electric_field.grid, sim.point_types,
177178
VectorOfArrays(locations[i]), VectorOfArrays(edeps[i]), electric_field, T(Δt.val) * unit(Δt);
178179
max_nsteps, diffusion, self_repulsion, end_drift_when_no_field, geometry_check, verbose

test/test_charge_drift_models.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,27 @@ nbcc = NBodyChargeCloud(pos, Edep, 40, radius = T(0.0005), number_of_shells = 2)
3131
@test isapprox( signalsum, T(2), atol = 5e-3 )
3232
end
3333

34+
@timed_testset "Move charges inside semiconductor" begin
35+
36+
# define a charge cloud very outside of the detector => should throw an AssertionError
37+
nbcc_top = NBodyChargeCloud(CartesianPoint{T}(0.01,0,0.081), Edep, 10, radius = T(0.002), number_of_shells = 1)
38+
evt = Event(nbcc_top)
39+
@test_throws AssertionError timed_simulate!(evt, sim, self_repulsion = true, diffusion = true)
40+
41+
# define a charge cloud very close to the top surface of the example inverted coax detector (top = 80mm) => should throw a warning
42+
nbcc_top = NBodyChargeCloud(CartesianPoint{T}(0.01,0,0.079), Edep, 10, radius = T(0.002), number_of_shells = 1)
43+
evt = Event(nbcc_top)
44+
@test_logs (:warn, r".*Moving them inside.*") timed_simulate!(evt, sim, self_repulsion = true, diffusion = true)
45+
46+
signalsum = T(0)
47+
for i in 1:length(evt.waveforms)
48+
signalsum += abs(ustrip(evt.waveforms[i].signal[end]))
49+
end
50+
signalsum *= inv(ustrip(SolidStateDetectors._convert_internal_energy_to_external_charge(sim.detector.semiconductor.material)))
51+
@test isapprox( signalsum, T(2), atol = 5e-3 )
52+
end
53+
54+
3455
@timed_testset "Charge Trapping: BoggsChargeTrappingModel" begin
3556
sim.detector = SolidStateDetector(sim.detector, BoggsChargeTrappingModel{T}())
3657
evt = Event(pos, Edep)

0 commit comments

Comments
 (0)