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