LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SimpleClustering.h
Go to the documentation of this file.
1 
10 #ifndef SimpleClustering_h
11 #define SimpleClustering_h
12 
15 
16 namespace tss {
17  struct bDistToPointLess;
18  class Cluster2D;
19  class SimpleClustering;
20 }
21 
23  bDistToPointLess(const TVector2& point) : p0(point) {}
24 
25  bool operator()(const tss::Hit2D* h1, const tss::Hit2D* h2) const
26  {
27  if (h1 && h2)
28  return pma::Dist2(h1->Point2D(), p0) < pma::Dist2(h2->Point2D(), p0);
29  else
30  return false;
31  }
32 
33 private:
34  TVector2 p0;
35 };
36 
38 public:
39  Cluster2D(void) : fTag(false), fDenseStart(false), fDenseEnd(false), fIsEM(false) {}
40  Cluster2D(const std::vector<const tss::Hit2D*>& hits);
41 
42  size_t size(void) const { return fHits.size(); }
43 
44  const Hit2D& operator[](size_t index) const { return *(fHits[index]); }
45 
46  const std::vector<const tss::Hit2D*>& hits(void) const { return fHits; }
47  std::vector<const tss::Hit2D*>& hits(void) { return fHits; }
48 
49  bool has(const tss::Hit2D* hit) const;
50 
51  double length2(void) const
52  {
53  if (size() > 1)
54  return pma::Dist2(fHits.front()->Point2D(), fHits.back()->Point2D());
55  else
56  return 0.0;
57  }
58 
59  double dist2(const TVector2& p2d) const;
60  double dist2(const TVector2& p2d, size_t& hIdx) const;
61  double dist2(const tss::Cluster2D& clu) const;
62 
63  const Hit2D* release_at(size_t idx);
64  bool release(const tss::Hit2D* hit);
65 
66  void push_back(const tss::Hit2D* hit) { fHits.push_back(hit); }
67  void take_from(tss::Cluster2D& clu, size_t idx)
68  {
69  const tss::Hit2D* hit = clu.release_at(idx);
70  if (hit) push_back(hit);
71  }
72  void merge(tss::Cluster2D& clu)
73  {
74  for (const auto h : clu.hits())
75  fHits.push_back(h);
76  clu.hits().clear();
77  }
78 
79  const tss::Hit2D* start(void) const
80  {
81  if (fHits.size())
82  return fHits.front();
83  else
84  return 0;
85  }
86  const tss::Hit2D* end(void) const
87  {
88  if (fHits.size())
89  return fHits.back();
90  else
91  return 0;
92  }
93  void sort(void)
94  {
95  if (fHits.size() > 2)
96  std::sort(fHits.begin() + 1, fHits.end(), tss::bDistToPointLess(fHits.front()->Point2D()));
97  }
98 
99  bool isTagged(void) const { return fTag; }
100  void setTag(bool b) { fTag = b; }
101 
102  bool isDenseStart(void) const { return fDenseStart; }
103  void tagDenseStart(bool b) { fDenseStart = b; }
104  bool isDenseEnd(void) const { return fDenseEnd; }
105  void tagDenseEnd(bool b) { fDenseEnd = b; }
106 
107  bool isEM(void) const { return fIsEM; }
108  void tagEM(bool b) { fIsEM = b; }
109 
110  const Hit2D* closest(const TVector2& p2d, size_t& idx) const;
111  const Hit2D* outermost(size_t& idx) const;
112 
113  const TVector2 min(void) const;
114  const TVector2 max(void) const;
115 
116 private:
117  std::vector<const tss::Hit2D*> fHits;
118 
119  bool fTag, fDenseStart, fDenseEnd, fIsEM;
120 };
121 
123 public:
124  std::vector<tss::Cluster2D> run(const std::vector<tss::Hit2D>& inp) const;
125  std::vector<tss::Cluster2D> run(const tss::Cluster2D& inp) const;
126 
127  bool hitsTouching(const tss::Hit2D& h1, const tss::Hit2D& h2) const;
128  bool hitsTouching(const tss::Cluster2D& c1, const tss::Hit2D& h2) const;
129  bool hitsTouching(const tss::Cluster2D& c1, const tss::Cluster2D& c2) const;
130 
131 private:
132  void merge(std::vector<tss::Cluster2D>& clusters) const;
133 };
134 
135 #endif
bool operator()(const tss::Hit2D *h1, const tss::Hit2D *h2) const
bDistToPointLess(const TVector2 &point)
TVector2 const & Point2D() const
Definition: TssHit2D.h:31
void tagEM(bool b)
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:39
std::vector< const tss::Hit2D * > & hits(void)
const tss::Hit2D * start(void) const
void push_back(const tss::Hit2D *hit)
bool isDenseEnd(void) const
void tagDenseEnd(bool b)
const std::vector< const tss::Hit2D * > & hits(void) const
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
void tagDenseStart(bool b)
void hits()
Definition: readHits.C:15
TCanvas * c1
Definition: plotHisto.C:7
TCanvas * c2
Definition: plot_hist.C:75
bool isDenseStart(void) const
std::vector< const tss::Hit2D * > fHits
void take_from(tss::Cluster2D &clu, size_t idx)
const tss::Hit2D * end(void) const
const Hit2D * release_at(size_t idx)
Hit pos in cm and original recob hit ptr.
Detector simulation of raw signals on wires.
bool isEM(void) const
TH1F * h2
Definition: plot.C:44
bool isTagged(void) const
Implementation of the Projection Matching Algorithm.
void merge(tss::Cluster2D &clu)
TH1F * h1
Definition: plot.C:41
const Hit2D & operator[](size_t index) const
double length2(void) const
size_t size(void) const
void setTag(bool b)