LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 121 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()) &&
183  (h1.PeakTime() == h2.PeakTime())) return false;
184 
185  bool touches = false;
186  if ((h1.Wire() >= h2.Wire() - 1) &&
187  (h1.Wire() <= h2.Wire() + 1))
188  {
189  if (((h2.StartTick() <= h1.StartTick()) && (h1.StartTick() <= h2.EndTick() + 1)) ||
190  ((h2.StartTick() <= h1.EndTick() + 1) && (h1.EndTick() <= h2.EndTick())) ||
191  ((h2.StartTick() >= h1.StartTick()) && (h1.EndTick() >= h2.EndTick())))
192  {
193  touches = true;
194  }
195  }
196  return touches;
197 }
unsigned int Wire(void) const
Definition: TssHit2D.h:42
float PeakTime(void) const
Definition: TssHit2D.h:43
int EndTick(void) const
Definition: TssHit2D.h:45
int StartTick(void) const
Definition: TssHit2D.h:44
bool tss::SimpleClustering::hitsTouching ( const tss::Cluster2D c1,
const tss::Hit2D h2 
) const

Definition at line 200 of file SimpleClustering.cxx.

References tss::Cluster2D::size().

201 {
202  for (size_t i = 0; i < c1.size(); i++)
203  {
204  if (hitsTouching(c1[i], h2)) return true;
205  }
206  return false;
207 }
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 210 of file SimpleClustering.cxx.

References tss::Cluster2D::size().

211 {
212  for (unsigned int i = 0; i < c1.size(); i++)
213  {
214  if (hitsTouching(c2, c1[i])) return true;
215  }
216  return false;
217 }
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 220 of file SimpleClustering.cxx.

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

221 {
222  bool merged = true;
223  while (merged)
224  {
225  merged = false;
226 
227  size_t i = 0;
228  while (i < clusters.size() - 1)
229  {
230  size_t j = i + 1;
231  while (j < clusters.size())
232  {
233  if (hitsTouching(clusters[i], clusters[j]))
234  {
235  clusters[i].hits().reserve(clusters[i].size() + clusters[i].size());
236  for (size_t h = 0; h < clusters[j].size(); ++h)
237  clusters[i].hits().push_back(clusters[j].hits()[h]);
238  clusters.erase(clusters.begin() + j);
239  merged = true;
240  }
241  else ++j;
242  }
243  ++i;
244  }
245  }
246 }
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 249 of file SimpleClustering.cxx.

References tss::Cluster2D::merge().

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

250 {
251  std::vector< tss::Cluster2D > result;
252  for (size_t h = 0; h < inp.size(); ++h)
253  {
254  bool found = false;
255  for (size_t r = 0; r < result.size(); ++r)
256  if (hitsTouching(result[r], inp[h]))
257  {
258  result[r].hits().push_back(&(inp[h])); found = true; break;
259  }
260  if (!found)
261  {
262  result.push_back(tss::Cluster2D());
263  result.back().hits().push_back(&(inp[h]));
264  }
265  }
266  merge(result);
267 
268  return result;
269 }
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 272 of file SimpleClustering.cxx.

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

273 {
274  std::vector< tss::Cluster2D > result;
275  for (size_t h = 0; h < inp.size(); ++h)
276  {
277  bool found = false;
278  for (size_t r = 0; r < result.size(); ++r)
279  if (hitsTouching(result[r], inp[h]))
280  {
281  result[r].hits().push_back(inp.hits()[h]); found = true; break;
282  }
283  if (!found)
284  {
285  result.push_back(tss::Cluster2D());
286  result.back().hits().push_back(inp.hits()[h]);
287  }
288  }
289  merge(result);
290 
291  return result;
292 }
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: