Belle II Software development
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#pragma once
10
11#include <cmath>
12#include <Math/Vector3D.h>
13
14namespace Belle2 {
21 unsigned short minWeight = 24;
23 unsigned char minPts = 1;
25 bool diagonal = true;
27 unsigned short minTotalWeight = 450;
29 unsigned short minPeakWeight = 32;
31 unsigned char iterations = 5;
33 unsigned char omegaTrim = 5;
35 unsigned char phiTrim = 4;
37 unsigned char thetaTrim = 4;
39 std::vector<bool> varCyclic = {false, true, false};
40 std::vector<std::string> varLabels = {"omega", "phi", "theta"};
41 };
42
43
46 public:
48 {
49 setParams(3);
50 initClCellsNew();
51 }
52 explicit SimpleCluster(cell_index entry)
53 {
54 setParams(3);
55 initClCellsNew();
56 append(entry);
57 }
58 virtual ~SimpleCluster() {}
59 void initClCellsNew()
60 {
61 unsigned short init_ClSize = 0;
62 unsigned short defaultValue = 0;
63 cell_index cell(m_dim, defaultValue);
64 std::vector<cell_index> C(init_ClSize, cell);
65 m_C = C;
66 }
67 void setParams(unsigned short dim)
68 {
69 m_dim = dim;
70 m_orientSum = 0;
71 }
73 std::vector<cell_index> getEntries()
74 {
75 return m_C;
76 }
78 void append(cell_index nextEntry)
79 {
80 m_C.push_back(nextEntry);
81 }
83 void addHit(unsigned short hit, unsigned short weight, unsigned short orient)
84 {
85 m_hits.push_back(hit);
86 m_hitWeights.push_back(weight);
87 m_orientSum += orient;
88 }
90 unsigned long getNAxial()
91 {
92 return m_orientSum;
93 }
95 unsigned long getNStereo()
96 {
97 return m_hits.size() - m_orientSum;
98 }
100 std::vector<unsigned short> getHits()
101 {
102 return m_hits;
103 }
105 std::vector<unsigned short> getWeights()
106 {
107 return m_hitWeights;
108 }
110 private:
112 std::vector<cell_index> m_C;
114 unsigned short m_dim;
116 std::vector<unsigned short> m_hits;
118 std::vector<unsigned short> m_hitWeights;
120 unsigned short m_orientSum;
121 };
122
123
126 public:
128 {
129 }
130 virtual ~Clusterizend() {}
131 explicit Clusterizend(const clustererParams& params): m_params(params)
132 {
133 }
134
135 clustererParams getParams()
136 {
137 return m_params;
138 }
139
140 void setPlaneShape(std::vector<ushort> planeShape)
141 {
142 m_dimSize = planeShape.size();
143 m_planeShape = planeShape;
144 m_valMax = std::vector<ushort>(m_planeShape);
145 for (ushort idim = 0; idim < m_dimSize; idim++) {
146 m_valMax[idim] -= 1;
147 }
148 m_valMax.push_back(1);
149
150 }
153 void setNewPlane(c3array& houghmapPlain)
154 {
155 m_houghVals = &houghmapPlain;
156 m_houghVisit = c3array(m_c3shape);
157 }
158
163 bool hasBefore(cell_index entry, ushort dim);
164
165 cell_index before(cell_index entry, ushort dim);
166
167 bool hasAfter(cell_index entry, ushort dim);
168
169 cell_index after(cell_index entry, ushort dim);
170
171 void blockcheck(std::vector<cell_index>* neighbors, cell_index elem, ushort dim);
172
173 std::vector<cell_index> regionQuery(cell_index entry);
174
175 std::vector<SimpleCluster> dbscan();
176
177 void expandCluster(std::vector<cell_index>& N, SimpleCluster& C);
178
179 std::vector<cell_index> getCandidates();
180
181 std::pair<cell_index, unsigned long> getGlobalMax();
182
183 void deleteMax(cell_index maxIndex);
184
185 std::vector<SimpleCluster> makeClusters();
186
187 std::pair<SimpleCluster, unsigned long> createCluster(cell_index maxIndex);
188
189 unsigned long checkSurroundings(cell_index maxIndex);
190
191 template<class T>
192 std::string printVector(std::vector<T> vecX)
193 {
194 std::stringstream result;
195 result << " ";
196 for (T& elem : vecX) { result << elem << " ";}
197 std::string rest;
198 result >> rest;
199 result >> rest;
200 return result.str();
201 }
202
203 template<class T>
204 std::string printCells(std::vector<T> vecX)
205 {
206 std::stringstream result;
207 for (T& elem : vecX) { result << " {" << printVector(elem) << "}";}
208 return result.str();
209 }
211 private:
213 std::vector<ushort> m_planeShape;
214 std::vector<ushort> m_valMax;
215 ushort m_dimSize;
216 boost::array<c3index, 3> m_c3shape = {{ 40, 384, 9 }};
217 c3array* m_houghVals{0};
218 c3array m_houghVisit = c3array(m_c3shape);
219 };
221}
Clustering module.
Definition: Clusterizend.h:125
void setNewPlane(c3array &houghmapPlain)
Next event initialization: set a new hough space for clustering and track finding.
Definition: Clusterizend.h:153
std::vector< cell_index > getCandidates()
clustererParams m_params
Clusterizend.
Definition: Clusterizend.h:212
bool hasBefore(cell_index entry, ushort dim)
Clustering logic.
Definition: Clusterizend.cc:15
Type for found clusters.
Definition: Clusterizend.h:45
void addHit(unsigned short hit, unsigned short weight, unsigned short orient)
Relate a hit to the cluster.
Definition: Clusterizend.h:83
std::vector< unsigned short > getHits()
Get ids of related hits (indices of the TS StoreArray)
Definition: Clusterizend.h:100
std::vector< unsigned short > m_hitWeights
Cluster related hits weights.
Definition: Clusterizend.h:118
unsigned short m_dim
Dimension of the track space (3 for omega, phi, theta)
Definition: Clusterizend.h:114
unsigned short m_orientSum
Sum of related hit orientations (== number of related axials)
Definition: Clusterizend.h:120
std::vector< cell_index > m_C
SimpleCluster.
Definition: Clusterizend.h:112
unsigned long getNAxial()
Get number related axial hits.
Definition: Clusterizend.h:90
unsigned long getNStereo()
Get number related stereo hits.
Definition: Clusterizend.h:95
std::vector< unsigned short > m_hits
Cluster related hits ids.
Definition: Clusterizend.h:116
std::vector< cell_index > getEntries()
Get member cells in the cluster.
Definition: Clusterizend.h:73
std::vector< unsigned short > getWeights()
Get weight contribution of each related hit to the cluster.
Definition: Clusterizend.h:105
void append(cell_index nextEntry)
Add a track-space cell to the cluster.
Definition: Clusterizend.h:78
Abstract base class for different kinds of events.
unsigned char iterations
Number of iterations of the cluster searching for each Hough space.
Definition: Clusterizend.h:31
unsigned char minPts
minimum number of neighbours for a cluster core cell
Definition: Clusterizend.h:23
std::vector< bool > varCyclic
Ordering of track parameters and position of cyclic variable (phi)
Definition: Clusterizend.h:39
bool diagonal
Consider diagonal adjacent cells as neighbors.
Definition: Clusterizend.h:25
unsigned short minTotalWeight
Cut on the total weight of all cells in the 3d volume.
Definition: Clusterizend.h:27
unsigned short minWeight
minimum weight for a cluster cell
Definition: Clusterizend.h:21
unsigned char omegaTrim
Number of deleted cells in omega in each direction of the maximum.
Definition: Clusterizend.h:33
unsigned char thetaTrim
Number of deleted cells in theta in each direction of the maximum.
Definition: Clusterizend.h:37
unsigned short minPeakWeight
Cut on the peak cell weight.
Definition: Clusterizend.h:29
unsigned char phiTrim
Number of deleted cells in phi in each direction of the maximum.
Definition: Clusterizend.h:35