SimpleClustering.h
Go to the documentation of this file.
1 /**
2  * @file SimpleClustering.h
3  *
4  * @author D.Stefan and R.Sulej
5  *
6  * @brief Trivial, collect hits "touching" each other (next wire or consecutive ticks),
7  * plus Cluster2D class to hold data needed by tss algorithms.
8  */
9 
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  class SimpleClustering;
21 }
22 
24  public std::binary_function<const tss::Hit2D*, const tss::Hit2D*, bool>
25 {
26  bDistToPointLess(const TVector2& point) : p0(point) { }
27 
28  bool operator() (const tss::Hit2D* h1, const tss::Hit2D* h2)
29  {
30  if (h1 && h2) return pma::Dist2(h1->Point2D(), p0) < pma::Dist2(h2->Point2D(), p0);
31  else return false;
32  }
33 
34  private: TVector2 p0;
35 };
36 
38 {
39 public:
40 
41  Cluster2D(void) : fTag(false), fDenseStart(false), fDenseEnd(false), fIsEM(false) { }
42  Cluster2D(const std::vector< const tss::Hit2D* > & hits);
43 
44  size_t size(void) const { return fHits.size(); }
45 
46  const Hit2D & operator [] (size_t index) const { return *(fHits[index]); }
47 
48  const std::vector< const tss::Hit2D* > & hits(void) const { return fHits; }
49  std::vector< const tss::Hit2D* > & hits(void) { return fHits; }
50 
51  bool has(const tss::Hit2D* hit) const;
52 
53  double length2(void) const
54  {
55  if (size() > 1) return pma::Dist2(fHits.front()->Point2D(), fHits.back()->Point2D());
56  else 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()) fHits.push_back(h);
75  clu.hits().clear();
76  }
77 
78  const tss::Hit2D* start(void) const
79  {
80  if (fHits.size()) return fHits.front();
81  else return 0;
82  }
83  const tss::Hit2D* end(void) const
84  {
85  if (fHits.size()) return fHits.back();
86  else return 0;
87  }
88  void sort(void)
89  {
90  if (fHits.size() > 2)
91  std::sort(fHits.begin() + 1, fHits.end(),
92  tss::bDistToPointLess(fHits.front()->Point2D()));
93  }
94 
95  bool isTagged(void) const { return fTag; }
96  void setTag(bool b) { fTag = b; }
97 
98  bool isDenseStart(void) const { return fDenseStart; }
99  void tagDenseStart(bool b) { fDenseStart = b; }
100  bool isDenseEnd(void) const { return fDenseEnd; }
101  void tagDenseEnd(bool b) { fDenseEnd = b; }
102 
103  bool isEM(void) const { return fIsEM; }
104  void tagEM(bool b) { fIsEM = b; }
105 
106  const Hit2D* closest(const TVector2 & p2d, size_t & idx) const;
107  const Hit2D* outermost(size_t & idx) const;
108 
109  const TVector2 min(void) const;
110  const TVector2 max(void) const;
111 
112 private:
113 
114  std::vector< const tss::Hit2D* > fHits;
115 
116  bool fTag, fDenseStart, fDenseEnd, fIsEM;
117 
118 };
119 
121 {
122 public:
123 
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 
133  void merge(std::vector< tss::Cluster2D > & clusters) const;
134 };
135 
136 #endif
bDistToPointLess(const TVector2 &point)
TVector2 const & Point2D() const
Definition: TssHit2D.h:36
void tagEM(bool b)
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:37
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
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
bool operator()(const tss::Hit2D *h1, const tss::Hit2D *h2)
void tagDenseStart(bool b)
const std::vector< const tss::Hit2D * > & hits(void) const
fInnerVessel push_back(Point(-578.400000, 0.000000, 0.000000))
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.
static int max(int a, int b)
Detector simulation of raw signals on wires.
bool isEM(void) const
bool isTagged(void) const
string release
Definition: conf.py:24
Implementation of the Projection Matching Algorithm.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
void merge(tss::Cluster2D &clu)
static bool * b
Definition: config.cpp:1043
double length2(void) const
size_t size(void) const
void setTag(bool b)