51 {
52
53
54
55
56 std::map<int, const ldmx::FittedSiStripHit*> channel_map;
57 for (const auto& h : hits) {
58 const int ch = h.getStripID();
59 auto it = channel_map.find(ch);
60 if (it == channel_map.end()) {
61 channel_map[ch] = &h;
62 } else {
63
64 if (std::abs(h.getT0() - mean_time_ns_) <
65 std::abs(it->second->getT0() - mean_time_ns_)) {
66 it->second = &h;
67 }
68 }
69 }
70
71
72
73
74
75
76
77
78
79
80 std::set<int> clusterable_set;
81 std::vector<int> seed_channels;
82
83 for (const auto& [ch, hp] : channel_map) {
84 const double amp = hp->getAmplitude();
86 if (amp >= neighbor_threshold_ * noise) {
87 clusterable_set.insert(ch);
88 }
89 if (amp >= seed_threshold_ * noise && passesSeedCuts(*hp)) {
90 seed_channels.push_back(ch);
91 }
92 }
93
94
95 std::sort(seed_channels.begin(), seed_channels.end(), [&](int a, int b) {
96 return channel_map.at(a)->getAmplitude() >
97 channel_map.at(b)->getAmplitude();
98 });
99
100
101
102
103 std::vector<ClusterCandidate> clusters;
104
105 for (int seed_ch : seed_channels) {
106
107 if (clusterable_set.find(seed_ch) == clusterable_set.end()) continue;
108
109 ClusterCandidate cand;
110 double cluster_weighted_t = 0.0;
111 double cluster_total_amp = 0.0;
112 double cluster_noise_sq = 0.0;
113
114 std::deque<int> unchecked;
115 unchecked.push_back(seed_ch);
116 clusterable_set.erase(seed_ch);
117
118 while (!unchecked.empty()) {
119 const int cur_ch = unchecked.front();
120 unchecked.pop_front();
121
124
125
127 cand.strip_ids.push_back(cur_ch);
128 cluster_total_amp += amp;
129 cluster_weighted_t += amp * hit.
getT0();
130 cluster_noise_sq += noise * noise;
131
132
133 for (int delta : {-1, +1}) {
134 const int nb_ch = cur_ch + delta;
135 if (clusterable_set.find(nb_ch) == clusterable_set.end()) continue;
136
137
138 if (!passesNeighborCuts(*channel_map.at(nb_ch), cluster_weighted_t,
139 cluster_total_amp)) {
140 continue;
141 }
142
143 unchecked.push_back(nb_ch);
144 clusterable_set.erase(nb_ch);
145 }
146 }
147
148
149 if (cluster_noise_sq <= 0.0) continue;
150 if (cluster_total_amp / std::sqrt(cluster_noise_sq) < cluster_threshold_) {
151 continue;
152 }
153
154
155
156
157 double sum_amp_strip = 0.0;
158 for (int ch : cand.strip_ids) {
159 sum_amp_strip += channel_map.at(ch)->getAmplitude() * ch;
160 }
161
162 cand.centroid_strip = sum_amp_strip / cluster_total_amp;
163 cand.total_amplitude = cluster_total_amp;
164 cand.time_ns = cluster_weighted_t / cluster_total_amp;
165 cand.n_strips = static_cast<int>(cand.strip_ids.size());
166
167
168
169
170
171
172 double sum_amp_dsq = 0.0;
173 for (int ch : cand.strip_ids) {
174 double d = ch - cand.centroid_strip;
175 sum_amp_dsq += channel_map.at(ch)->getAmplitude() * d * d;
176 }
177 constexpr double k_single_strip_sigma = 1.0 / 3.4641;
178 const double rms = std::sqrt(sum_amp_dsq / cluster_total_amp);
179 cand.sigma_strip = (rms > 0.0) ? rms : k_single_strip_sigma;
180 cand.layer_id = channel_map.at(seed_ch)->getLayerID();
181
182 clusters.push_back(std::move(cand));
183 }
184
185 return clusters;
186}
Result of fitting a pulse shape to the ADC samples of a single readout strip.
float getAmplitude() const
Fitted pedestal-subtracted peak amplitude [ADC counts].
float getT0() const
Fitted hit arrival time [ns] in the sample-window reference frame.
double hitNoise(const ldmx::FittedSiStripHit &h) const
Per-strip noise RMS to use for h: the hit's own measured noise if set (> 0), otherwise the uniform no...