77function cluster_detector_hits(
88 detno:: AbstractVector{<:Integer} ,
99 edep:: AbstractVector{TT} ,
10- pos:: AbstractVector{<:StaticVector{3,PT }} ,
10+ pos:: AbstractVector{<:Union{<: StaticVector{PT}, <:CartesianPoint{PT} }} ,
1111 cluster_radius:: RealQuantity
1212) where {TT<: RealQuantity , PT <: RealQuantity }
13- Table = TypedTables . Table
14- unsorted = Table(detno = detno, edep = edep, pos = pos)
13+
14+ unsorted = TypedTables . Table(detno = detno, edep = edep, pos = pos)
1515 sorting_idxs = sortperm(unsorted. detno)
1616 sorted = unsorted[sorting_idxs]
17- grouped = Table(consgroupedview(sorted. detno, TypedTables. columns(sorted)))
17+ grouped = TypedTables . Table(consgroupedview(sorted. detno, TypedTables. columns(sorted)))
1818
1919 r_detno = similar(detno, 0 )
2020 r_edep = similar(edep, 0 )
@@ -24,25 +24,25 @@ function cluster_detector_hits(
2424 ustripped_cradius = ustrip(posunit, cluster_radius)
2525
2626 for d_hits_nt in grouped
27- d_hits = Table(d_hits_nt)
27+ d_hits = TypedTables . Table(d_hits_nt)
2828 d_detno = first(d_hits. detno)
2929 @assert all(isequal(d_detno), d_hits. detno)
3030 if length(d_hits) > 3
31- clusters = Clustering. dbscan(ustrip.(flatview(d_hits. pos)), ustripped_cradius, leafsize = 20 , min_neighbors = 1 , min_cluster_size = 1 )
31+
32+ clusters = Clustering. dbscan(hcat((ustrip.(getindex.(d_hits. pos,i)) for i in 1 : 3 ). .. )' , ustripped_cradius, leafsize = 20 , min_neighbors = 1 , min_cluster_size = 1 )
3233 for c in _get_clusters(clusters)
3334 idxs = vcat(c. boundary_indices, c. core_indices)
3435 @assert length(idxs) == c. size
3536 c_hits = view(d_hits, idxs)
3637
3738 push!(r_detno, d_detno)
38- esum_u = sum(c_hits. edep)
39- push!(r_edep, esum_u)
40- esum = ustrip(esum_u)
41- if esum ≈ 0
39+ esum = sum(c_hits. edep)
40+ push!(r_edep, esum)
41+ if esum ≈ zero(TT)
4242 push!(r_pos, barycenter(c_hits. pos))
4343 else
44- weights = ustrip.(c_hits. edep) .* inv(esum)
45- push!(r_pos, barycenter(c_hits. pos, weights))
44+ weights = ustrip.(Unitful . NoUnits, c_hits. edep .* inv(esum) )
45+ push!(r_pos, barycenter(c_hits. pos, StatsBase . Weights( weights) ))
4646 end
4747 end
4848 else
0 commit comments