Skip to content

Commit 489ffb0

Browse files
committed
clusters based on time are split into multiple rows of output table
1 parent afa8f54 commit 489ffb0

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

src/ChargeClustering/ChargeClustering.jl

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ function cluster_detector_hits(
1414
sorting_idxs = sortperm(unsorted.detno)
1515
sorted = unsorted[sorting_idxs]
1616
grouped = TypedTables.Table(consgroupedview(sorted.detno, TypedTables.columns(sorted)))
17-
18-
r_detno = similar(detno, 0)
19-
r_edep = similar(edep, 0)
20-
r_pos = similar(pos, 0)
21-
r_thit = similar(thit, 0)
22-
17+
18+
results = []
2319
ustripped_cradius = ustrip(internal_length_unit, cluster_radius)
2420

2521
for d_hits_nt in grouped
@@ -36,6 +32,13 @@ function cluster_detector_hits(
3632
@inbounds for i in eachindex(t_vals) .+ 1
3733
if i > lastindex(t_vals) || t_vals[i] - t_vals[current_group] > cluster_time
3834
t_hits = view(d_hits, current_group:i-1)
35+
36+
# Each time cluster gets its own result entry
37+
r_detno = similar(detno, 0)
38+
r_edep = similar(edep, 0)
39+
r_pos = similar(pos, 0)
40+
r_thit = similar(thit, 0)
41+
3942
if length(t_hits) > 3
4043
d_detno = first(t_hits.detno)
4144
@assert all(isequal(d_detno), t_hits.detno)
@@ -64,12 +67,13 @@ function cluster_detector_hits(
6467
append!(r_pos, t_hits.pos)
6568
append!(r_thit, t_hits.thit)
6669
end
70+
71+
push!(results, (detno = r_detno, edep = r_edep, pos = r_pos, thit = r_thit))
6772
current_group = i
6873
end
6974
end
7075
end
71-
72-
(detno = r_detno, edep = r_edep, pos = r_pos, thit = r_thit)
76+
results
7377
end
7478

7579

@@ -82,24 +86,38 @@ function cluster_detector_hits(
8286
@assert :thit in TypedTables.columnnames(table) "Table has no column `thit`"
8387
@assert :edep in TypedTables.columnnames(table) "Table has no column `edep`"
8488
@assert :detno in TypedTables.columnnames(table) "Table has no column `detno`"
85-
clustered_nt = map(
86-
evt -> cluster_detector_hits(
89+
90+
# Collect all time-clustered results
91+
all_results = []
92+
evtno_col = []
93+
94+
for (evtno, evt) in enumerate(table)
95+
time_clusters = cluster_detector_hits(
8796
evt.detno,
8897
evt.edep,
8998
evt.pos,
9099
evt.thit,
91100
cluster_radius,
92101
cluster_time
93-
),
94-
table
95-
)
96-
TypedTables.Table(merge(
97-
TypedTables.columns(table),
98-
map(
99-
VectorOfVectors,
100-
TypedTables.columns(clustered_nt)
101102
)
102-
))
103+
104+
# Each time cluster becomes a separate row
105+
for tc in time_clusters
106+
push!(all_results, tc)
107+
push!(evtno_col, evtno)
108+
end
109+
end
110+
111+
# Build output table
112+
result_columns = (
113+
evtno = evtno_col,
114+
detno = VectorOfVectors([r.detno for r in all_results]),
115+
thit = VectorOfVectors([r.thit for r in all_results]),
116+
edep = VectorOfVectors([r.edep for r in all_results]),
117+
pos = VectorOfVectors([r.pos for r in all_results])
118+
)
119+
120+
TypedTables.Table(result_columns)
103121
end
104122

105123

0 commit comments

Comments
 (0)