LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
tss::SimpleClustering Class Reference

#include "SimpleClustering.h"

Public Member Functions

std::vector< tss::Cluster2Drun (const std::vector< tss::Hit2D > &inp) const
 
std::vector< tss::Cluster2Drun (const tss::Cluster2D &inp) const
 
bool hitsTouching (const tss::Hit2D &h1, const tss::Hit2D &h2) const
 
bool hitsTouching (const tss::Cluster2D &c1, const tss::Hit2D &h2) const
 
bool hitsTouching (const tss::Cluster2D &c1, const tss::Cluster2D &c2) const
 

Private Member Functions

void merge (std::vector< tss::Cluster2D > &clusters) const
 

Detailed Description

Definition at line 122 of file SimpleClustering.h.

Member Function Documentation

bool tss::SimpleClustering::hitsTouching ( const tss::Hit2D h1,
const tss::Hit2D h2 
) const

Definition at line 180 of file SimpleClustering.cxx.

References tss::Hit2D::EndTick(), tss::Hit2D::PeakTime(), tss::Hit2D::StartTick(), and tss::Hit2D::Wire().

Referenced by tss::Segmentation2D::buildSegment().

181 {
182  if ((h1.Wire() == h2.Wire()) && (h1.PeakTime() == h2.PeakTime())) return false;
183 
184  bool touches = false;
185  if ((h1.Wire() >= h2.Wire() - 1) && (h1.Wire() <= h2.Wire() + 1)) {
186  if (((h2.StartTick() <= h1.StartTick()) && (h1.StartTick() <= h2.EndTick() + 1)) ||
187  ((h2.StartTick() <= h1.EndTick() + 1) && (h1.EndTick() <= h2.EndTick())) ||
188  ((h2.StartTick() >= h1.StartTick()) && (h1.EndTick() >= h2.EndTick()))) {
189  touches = true;
190  }
191  }
192  return touches;
193 }
unsigned int Wire() const
Definition: TssHit2D.h:36
int StartTick() const
Definition: TssHit2D.h:38
float PeakTime() const
Definition: TssHit2D.h:37
int EndTick() const
Definition: TssHit2D.h:39
bool tss::SimpleClustering::hitsTouching ( const tss::Cluster2D c1,
const tss::Hit2D h2 
) const

Definition at line 196 of file SimpleClustering.cxx.

References tss::Cluster2D::size().

197 {
198  for (size_t i = 0; i < c1.size(); i++) {
199  if (hitsTouching(c1[i], h2)) return true;
200  }
201  return false;
202 }
bool hitsTouching(const tss::Hit2D &h1, const tss::Hit2D &h2) const
size_t size(void) const
bool tss::SimpleClustering::hitsTouching ( const tss::Cluster2D c1,
const tss::Cluster2D c2 
) const

Definition at line 205 of file SimpleClustering.cxx.

References tss::Cluster2D::size().

206 {
207  for (unsigned int i = 0; i < c1.size(); i++) {
208  if (hitsTouching(c2, c1[i])) return true;
209  }
210  return false;
211 }
bool hitsTouching(const tss::Hit2D &h1, const tss::Hit2D &h2) const
size_t size(void) const
void tss::SimpleClustering::merge ( std::vector< tss::Cluster2D > &  clusters) const
private

Definition at line 214 of file SimpleClustering.cxx.

References tss::Cluster2D::hits(), and tss::Cluster2D::size().

215 {
216  bool merged = true;
217  while (merged) {
218  merged = false;
219 
220  size_t i = 0;
221  while (i < clusters.size() - 1) {
222  size_t j = i + 1;
223  while (j < clusters.size()) {
224  if (hitsTouching(clusters[i], clusters[j])) {
225  clusters[i].hits().reserve(clusters[i].size() + clusters[i].size());
226  for (size_t h = 0; h < clusters[j].size(); ++h)
227  clusters[i].hits().push_back(clusters[j].hits()[h]);
228  clusters.erase(clusters.begin() + j);
229  merged = true;
230  }
231  else
232  ++j;
233  }
234  ++i;
235  }
236  }
237 }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
void hits()
Definition: readHits.C:15
bool hitsTouching(const tss::Hit2D &h1, const tss::Hit2D &h2) const
std::vector< tss::Cluster2D > tss::SimpleClustering::run ( const std::vector< tss::Hit2D > &  inp) const

Definition at line 240 of file SimpleClustering.cxx.

References tss::Cluster2D::merge(), and r.

Referenced by tss::TrackShowerHits::produce(), and tss::Segmentation2D::run().

241 {
242  std::vector<tss::Cluster2D> result;
243  for (size_t h = 0; h < inp.size(); ++h) {
244  bool found = false;
245  for (size_t r = 0; r < result.size(); ++r)
246  if (hitsTouching(result[r], inp[h])) {
247  result[r].hits().push_back(&(inp[h]));
248  found = true;
249  break;
250  }
251  if (!found) {
252  result.push_back(tss::Cluster2D());
253  result.back().hits().push_back(&(inp[h]));
254  }
255  }
256  merge(result);
257 
258  return result;
259 }
TRandom r
Definition: spectrum.C:23
void merge(std::vector< tss::Cluster2D > &clusters) const
bool hitsTouching(const tss::Hit2D &h1, const tss::Hit2D &h2) const
std::vector< tss::Cluster2D > tss::SimpleClustering::run ( const tss::Cluster2D inp) const

Definition at line 262 of file SimpleClustering.cxx.

References tss::Cluster2D::hits(), tss::Cluster2D::merge(), r, and tss::Cluster2D::size().

263 {
264  std::vector<tss::Cluster2D> result;
265  for (size_t h = 0; h < inp.size(); ++h) {
266  bool found = false;
267  for (size_t r = 0; r < result.size(); ++r)
268  if (hitsTouching(result[r], inp[h])) {
269  result[r].hits().push_back(inp.hits()[h]);
270  found = true;
271  break;
272  }
273  if (!found) {
274  result.push_back(tss::Cluster2D());
275  result.back().hits().push_back(inp.hits()[h]);
276  }
277  }
278  merge(result);
279 
280  return result;
281 }
TRandom r
Definition: spectrum.C:23
const std::vector< const tss::Hit2D * > & hits(void) const
void merge(std::vector< tss::Cluster2D > &clusters) const
bool hitsTouching(const tss::Hit2D &h1, const tss::Hit2D &h2) const
size_t size(void) const

The documentation for this class was generated from the following files: