7777
7878
7979function cluster_detector_hits(table:: TypedTables.Table , cluster_radius:: RealQuantity , cluster_time:: RealQuantity = Inf * u" s" )
80- @assert is_detector_hits_table(table) " Table does not have the correct format"
8180
82- # Collect all time-clustered results
83- all_results = []
84- evtno_col = Int[]
85-
86- for (evtno, evt) in enumerate(table)
81+ @assert is_detector_hits_table(table)
82+
83+ col_names = TypedTables. columnnames(table)
84+ col_vectors = map(col -> similar(getproperty(table, col), 0 ), col_names)
85+ reduced_col_names = filter(col -> col ∉ (:detno, :edep, :pos, :thit), col_names)
86+
87+ col_nt = NamedTuple{col_names}(col_vectors)
88+
89+ for (idx, evt) in enumerate(table)
8790 time_clusters = cluster_detector_hits(
8891 evt. detno,
8992 evt. edep,
@@ -93,20 +96,18 @@ function cluster_detector_hits(table::TypedTables.Table, cluster_radius::RealQua
9396 cluster_time
9497 )
9598
96- append!(all_results, time_clusters)
97- append!(evtno_col, fill(evtno, length(time_clusters)))
99+ for result in time_clusters
100+ for col in (:detno, :edep, :pos, :thit)
101+ push!(col_nt[col], getfield(result, col))
102+ end
103+
104+ for col in reduced_col_names
105+ push!(col_nt[col], getfield(evt, col))
106+ end
107+ end
98108 end
99-
100- # Build output table
101- result_columns = (
102- evtno = evtno_col,
103- detno = VectorOfVectors([r. detno for r in all_results]),
104- thit = VectorOfVectors([r. thit for r in all_results]),
105- edep = VectorOfVectors([r. edep for r in all_results]),
106- pos = VectorOfVectors([r. pos for r in all_results])
107- )
108-
109- TypedTables. Table(result_columns)
109+
110+ TypedTables. Table(col_nt)
110111end
111112
112113
0 commit comments