Belle II Software  release-08-01-10
Clusterizend.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #ifndef CLUSTERIZEND_H
10 #define CLUSTERIZEND_H
11 
12 #include <cmath>
13 
14 
15 namespace Belle2 {
22  unsigned short minweight = 24;
24  unsigned short minpts = 1;
26  bool diagonal = true;
28  std::vector<bool> var_cyclic = {false, true, false};
29  std::vector<std::string> var_labels = {"omega", "phi", "theta"};
30  };
31 
32 
34  class SimpleCluster {
35  public:
37  {
38  setParams(3);
39  initClCellsNew();
40  }
41  explicit SimpleCluster(cell_index entry)
42  {
43  setParams(3);
44  initClCellsNew();
45  append(entry);
46  }
47  virtual ~SimpleCluster() {}
48  void initClCellsNew()
49  {
50  unsigned short init_ClSize = 0;
51  unsigned short default_value = 0;
52  cell_index cell(m_dim, default_value);
53  std::vector<cell_index> C(init_ClSize, cell);
54  m_C = C;
55  }
56  void setParams(unsigned short dim)
57  {
58  m_dim = dim;
59  m_orientSum = 0;
60  }
62  std::vector<cell_index> getEntries()
63  {
64  return m_C;
65  }
67  void append(cell_index next_entry)
68  {
69  m_C.push_back(next_entry);
70  }
72  void add_hit(unsigned short hit, unsigned short weight, unsigned short orient)
73  {
74  m_hits.push_back(hit);
75  m_hitWeights.push_back(weight);
76  m_orientSum += orient;
77  }
79  unsigned long get_naxial()
80  {
81  return m_orientSum;
82  }
84  unsigned long get_nstereo()
85  {
86  return m_hits.size() - m_orientSum;
87  }
89  std::vector<unsigned short> get_hits()
90  {
91  return m_hits;
92  }
94  std::vector<unsigned short> get_weights()
95  {
96  return m_hitWeights;
97  }
99  private:
101  std::vector<cell_index> m_C;
103  unsigned short m_dim;
105  std::vector<unsigned short> m_hits;
107  std::vector<unsigned short> m_hitWeights;
109  unsigned short m_orientSum;
110  };
111 
112 
114  class Clusterizend {
115  public:
116  Clusterizend()
117  {
118  }
119  virtual ~Clusterizend() {}
120  explicit Clusterizend(const clusterer_params& params): m_params(params)
121  {
122  }
123 
124  clusterer_params getParams()
125  {
126  return m_params;
127  }
128 
129  void setPlaneShape(std::vector<ushort> planeShape)
130  {
131  m_dimsize = planeShape.size();
132  m_planeShape = planeShape;
133  m_valmax = std::vector<ushort>(m_planeShape);
134  for (ushort idim = 0; idim < m_dimsize; idim++) {
135  m_valmax[idim] -= 1;
136  }
137  m_valmax.push_back(1);
138 
139  }
142  void setNewPlane(c3array& houghmap_plain)
143  {
144  m_houghVals = &houghmap_plain;
145  m_houghVisit = c3array(m_c3shape);
146  }
147 
152  bool has_before(cell_index entry, ushort dim);
153 
154  cell_index before(cell_index entry, ushort dim);
155 
156  bool has_after(cell_index entry, ushort dim);
157 
158  cell_index after(cell_index entry, ushort dim);
159 
160  void blockcheck(std::vector<cell_index>* neighbors, cell_index elem, ushort dim);
161 
162  std::vector<cell_index> regionQuery(cell_index entry);
163 
164  std::vector<SimpleCluster> dbscan();
165 
166  void expandCluster(std::vector<cell_index>& N, SimpleCluster& C);
167 
168  std::vector<cell_index> getCandidates();
169 
170 
171  template<class T>
172  std::string printVector(std::vector<T> vecX)
173  {
174  std::stringstream result;
175  result << " ";
176  for (T& elem : vecX) { result << elem << " ";}
177  std::string rest;
178  result >> rest;
179  result >> rest;
180  return result.str();
181  }
182 
183  template<class T>
184  std::string printCells(std::vector<T> vecX)
185  {
186  std::stringstream result;
187  for (T& elem : vecX) { result << " {" << printVector(elem) << "}";}
188  return result.str();
189  }
191  private:
193  std::vector<ushort> m_planeShape;
194  std::vector<ushort> m_valmax;
195  ushort m_dimsize;
196  boost::array<c3index, 3> m_c3shape = {{ 40, 384, 9 }};
197  c3array* m_houghVals{0};
198  c3array m_houghVisit = c3array(m_c3shape);
199  };
201 }
202 
203 #endif
Clustering module.
Definition: Clusterizend.h:114
bool has_before(cell_index entry, ushort dim)
Clustering logic.
Definition: Clusterizend.cc:17
void setNewPlane(c3array &houghmap_plain)
Next event initialization: set a new hough space for clustering and track finding.
Definition: Clusterizend.h:142
clusterer_params m_params
Clusterizend.
Definition: Clusterizend.h:192
std::vector< cell_index > getCandidates()
Type for found clusters.
Definition: Clusterizend.h:34
void add_hit(unsigned short hit, unsigned short weight, unsigned short orient)
Relate a hit to the cluster.
Definition: Clusterizend.h:72
std::vector< unsigned short > m_hitWeights
Cluster related hits weights.
Definition: Clusterizend.h:107
unsigned short m_dim
Dimension of the track space (3 for omega, phi, theta)
Definition: Clusterizend.h:103
unsigned short m_orientSum
Sum of related hit orientations (== number of related axials)
Definition: Clusterizend.h:109
std::vector< cell_index > m_C
SimpleCluster.
Definition: Clusterizend.h:101
std::vector< unsigned short > get_weights()
Get weight contribution of each related hit to the cluster.
Definition: Clusterizend.h:94
unsigned long get_naxial()
Get number related axial hits.
Definition: Clusterizend.h:79
std::vector< unsigned short > get_hits()
Get ids of related hits (indices of the TS StoreArray)
Definition: Clusterizend.h:89
std::vector< cell_index > getEntries()
Get member cells in the cluster.
Definition: Clusterizend.h:62
std::vector< unsigned short > m_hits
Cluster related hits ids.
Definition: Clusterizend.h:105
void append(cell_index next_entry)
Add a track-space cell to the cluster.
Definition: Clusterizend.h:67
unsigned long get_nstereo()
Get number related stereo hits.
Definition: Clusterizend.h:84
Abstract base class for different kinds of events.
unsigned short minweight
minimum weight for a cluster cell
Definition: Clusterizend.h:22
bool diagonal
Consider diagonal adjacent cells as neighbors.
Definition: Clusterizend.h:26
unsigned short minpts
minimum number of neighbours for a cluster core cell
Definition: Clusterizend.h:24
std::vector< bool > var_cyclic
Ordering of track parameters and position of cyclic variable (phi)
Definition: Clusterizend.h:28