9#include "framework/logging/Logger.h"
10#include "trg/cdc/NDFinderDefs.h"
11#include "trg/cdc/Clusterizend.h"
22cell_index Clusterizend::before(cell_index entry, ushort dim)
28 entry[dim] = m_valMax[dim];
31 B2ERROR(
"no before(), check with hasBefore");
36bool Clusterizend::hasAfter(cell_index entry, ushort dim)
43cell_index Clusterizend::after(cell_index entry, ushort dim)
45 if (entry[dim] < m_valMax[dim]) {
52 B2ERROR(
"no after(), check with hasBefore()");
58void Clusterizend::blockcheck(std::vector<cell_index>* neighbors, cell_index elem, ushort dim)
61 B2ERROR(
"dim too large, dim=" << dim);
64 cell_index ind = before(elem, dim);
65 ushort leftwe = (*m_houghVals)[ind[0]][ind[1]][ind[2]];
66 ushort leftvi = m_houghVisit[ind[0]][ind[1]][ind[2]];
68 neighbors->push_back(ind);
71 blockcheck(neighbors, ind, dim - 1);
74 if (hasAfter(elem, dim)) {
75 cell_index ind = after(elem, dim);
76 ushort rightwe = (*m_houghVals)[ind[0]][ind[1]][ind[2]];
77 ushort rightvi = m_houghVisit[ind[0]][ind[1]][ind[2]];
79 neighbors->push_back(ind);
82 blockcheck(neighbors, ind, dim - 1);
87 blockcheck(neighbors, elem, dim - 1);
91std::vector<cell_index>
92Clusterizend::regionQuery(cell_index entry)
94 std::vector<cell_index> neighbours;
95 blockcheck(&neighbours, entry, m_dimSize - 1);
99std::vector<SimpleCluster>
100Clusterizend::dbscan()
102 std::vector<SimpleCluster> C;
104 for (
unsigned long icand = 0; icand < candidates.size(); icand++) {
105 cell_index entry = candidates[icand];
106 c3index iom = entry[0];
107 c3index iph = entry[1];
108 c3index ith = entry[2];
110 if (m_houghVisit[iom][iph][ith] == 0) {
112 m_houghVisit[iom][iph][ith] = 1;
113 std::vector<cell_index> N = regionQuery(entry);
117 expandCluster(N, newCluster);
118 C.push_back(newCluster);
126Clusterizend::expandCluster(std::vector<cell_index>& N,
SimpleCluster& C)
128 while (N.size() > 0) {
129 cell_index nextP = N.back();
131 ushort iom = nextP[0];
132 ushort iph = nextP[1];
133 ushort ith = nextP[2];
134 if (m_houghVisit[iom][iph][ith] == 0) {
135 m_houghVisit[iom][iph][ith] = 1;
139 std::vector<cell_index> nextN = regionQuery(nextP);
141 N.insert(N.end(), nextN.begin(), nextN.end());
148std::vector<cell_index>
151 std::vector<cell_index> candidates;
153 for (c3index iom = 0; iom < 40; iom++) {
154 for (c3index iph = 0; iph < 384; iph++) {
155 for (c3index ith = 0; ith < 9; ith++) {
157 cell_index elem = {iom, iph, ith};
158 candidates.push_back(elem);
166std::pair<cell_index, unsigned long> Clusterizend::getGlobalMax()
168 unsigned long maxValue = 0;
169 cell_index maxIndex = {0, 0, 0};
170 for (c3index iom = 0; iom < 40; iom++) {
171 for (c3index iph = 0; iph < 384; iph++) {
172 for (c3index ith = 0; ith < 9; ith++) {
173 if ((*m_houghVals)[iom][iph][ith] > maxValue) {
174 maxValue = (*m_houghVals)[iom][iph][ith];
175 maxIndex = {iom, iph, ith};
180 return {maxIndex, maxValue};
183void Clusterizend::deleteMax(cell_index maxIndex)
185 c3index omIndex = maxIndex[0];
186 c3index phIndex = maxIndex[1];
187 c3index thIndex = maxIndex[2];
192 c3index phiIndex = phIndex + omIndex - iom;
193 c3index relativePhi = phiIndex - phIndex;
194 if (relativePhi > 0) {
196 c3index iphMod = (iph + 384) % 384;
197 (*m_houghVals)[iom][iphMod][ith] = 0;
199 }
else if (relativePhi < 0) {
201 c3index iphMod = (iph + 384) % 384;
202 (*m_houghVals)[iom][iphMod][ith] = 0;
206 c3index iphMod = (iph + 384) % 384;
207 (*m_houghVals)[iom][iphMod][ith] = 0;
214std::vector<SimpleCluster> Clusterizend::makeClusters()
216 std::vector<SimpleCluster> candidates;
218 auto [globalMax, peakWeight] = getGlobalMax();
222 auto [newCluster, totalWeight] = createCluster(globalMax);
224 candidates.push_back(newCluster);
226 deleteMax(globalMax);
231std::pair<SimpleCluster, unsigned long> Clusterizend::createCluster(cell_index maxIndex)
234 c3index omIndex = maxIndex[0];
235 c3index phIndex = maxIndex[1];
236 c3index thIndex = maxIndex[2];
237 unsigned long totalClusterWeight = 0;
239 for (c3index ith = std::max<int>(0, thIndex - 1); ith < std::min<int>(9, thIndex + 2); ith++) {
240 for (c3index iph = phIndex - 1; iph < phIndex + 2; iph++) {
241 c3index iphMod = (iph + 384) % 384;
242 cell_index newMemberIndex = {omIndex, iphMod, ith};
243 fixedCluster.
append(newMemberIndex);
244 totalClusterWeight += (*m_houghVals)[omIndex][iphMod][ith];
247 if (omIndex - 1 >= 0) {
248 for (c3index ith = std::max<int>(0, thIndex - 1); ith < std::min<int>(9, thIndex + 2); ith++) {
249 for (c3index iph = phIndex + 1; iph < phIndex + 4; iph++) {
250 c3index iphMod = (iph + 384) % 384;
251 cell_index newMemberIndex = {omIndex - 1, iphMod, ith};
252 fixedCluster.
append(newMemberIndex);
253 totalClusterWeight += (*m_houghVals)[omIndex - 1][iphMod][ith];
257 if (omIndex + 1 < 40) {
258 for (c3index ith = std::max<int>(0, thIndex - 1); ith < std::min<int>(9, thIndex + 2); ith++) {
259 for (c3index iph = phIndex - 3; iph < phIndex; iph++) {
260 c3index iphMod = (iph + 384) % 384;
261 cell_index newMemberIndex = {omIndex + 1, iphMod, ith};
262 fixedCluster.
append(newMemberIndex);
263 totalClusterWeight += (*m_houghVals)[omIndex + 1][iphMod][ith];
267 return {fixedCluster, totalClusterWeight};
std::vector< cell_index > getCandidates()
clustererParams m_params
Clusterizend.
bool hasBefore(cell_index entry, ushort dim)
Clustering logic.
void append(cell_index nextEntry)
Add a track-space cell to the cluster.
Abstract base class for different kinds of events.
unsigned char iterations
Number of iterations of the cluster searching for each Hough space.
unsigned char minPts
minimum number of neighbours for a cluster core cell
std::vector< bool > varCyclic
Ordering of track parameters and position of cyclic variable (phi)
bool diagonal
Consider diagonal adjacent cells as neighbors.
unsigned short minTotalWeight
Cut on the total weight of all cells in the 3d volume.
unsigned short minWeight
minimum weight for a cluster cell
unsigned char omegaTrim
Number of deleted cells in omega in each direction of the maximum.
unsigned char thetaTrim
Number of deleted cells in theta in each direction of the maximum.
unsigned short minPeakWeight
Cut on the peak cell weight.
unsigned char phiTrim
Number of deleted cells in phi in each direction of the maximum.