Project
Loading...
Searching...
No Matches
Clusterer.h
Go to the documentation of this file.
1// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#ifndef ALICEO2_TRK_CLUSTERER_H
16#define ALICEO2_TRK_CLUSTERER_H
17
18// uncomment to allow diagonal clusters, e.g. |* |
19// | *|
20#define _ALLOW_DIAGONAL_TRK_CLUSTERS_
21
30#include "TRKBase/Specs.h"
31#include <gsl/span>
32#include <vector>
33#include <array>
34#include <memory>
35#include <cstring>
36#include <utility>
37
38namespace o2::trk
39{
40
41class GeometryTGeo;
42
44{
45 public:
46 static constexpr int MaxLabels = 10;
47 static constexpr int MaxHugeClusWarn = 5;
48
55
56 //----------------------------------------------
57 struct BBox {
58 uint16_t chipID = 0xffff;
59 uint16_t rowMin = 0xffff, colMin = 0xffff;
60 uint16_t rowMax = 0, colMax = 0;
61 explicit BBox(uint16_t c) : chipID(c) {}
62 bool isInside(uint16_t r, uint16_t c) const { return r >= rowMin && r <= rowMax && c >= colMin && c <= colMax; }
63 uint16_t rowSpan() const { return rowMax - rowMin + 1; }
64 uint16_t colSpan() const { return colMax - colMin + 1; }
70 void adjust(uint16_t r, uint16_t c)
71 {
72 if (r < rowMin) {
73 rowMin = r;
74 }
75 if (r > rowMax) {
76 rowMax = r;
77 }
78 if (c < colMin) {
79 colMin = c;
80 }
81 if (c > colMax) {
82 colMax = c;
83 }
84 }
85 };
86
87 //----------------------------------------------
89 Clusterer* parent = nullptr;
90 // column buffers (pre-cluster state); extra sentinel entries at [0] and [size-1]
91 int* column1 = nullptr;
92 int* column2 = nullptr;
93 int* curr = nullptr;
94 int* prev = nullptr;
96
97 // pixels[i] = {next_in_chain, global_digit_index}
98 std::vector<std::pair<int, uint32_t>> pixels;
99 std::vector<int> preClusterHeads;
100 std::vector<int> preClusterIndices;
101 uint16_t currCol = 0xffff;
102 bool noLeftCol = true;
103
104 std::array<Label, MaxLabels> labelsBuff;
105 std::vector<std::pair<uint16_t, uint16_t>> pixArrBuff;
106
107 // per-thread output (accumulated, then merged back by caller)
108 std::vector<Cluster> clusters;
109 std::vector<unsigned char> patterns;
111
113 void resetColumn(int* buff) const { std::memset(buff, -1, sizeof(int) * (size - 2)); }
115 void swapColumnBuffers() { std::swap(prev, curr); }
116
118 void expandPreCluster(uint32_t ip, uint16_t row, int preClusterIndex)
119 {
120 auto& firstIndex = preClusterHeads[preClusterIndices[preClusterIndex]];
121 pixels.emplace_back(firstIndex, ip);
122 firstIndex = pixels.size() - 1;
123 curr[row] = preClusterIndex;
124 }
125
127 void addNewPreCluster(uint32_t ip, uint16_t row)
128 {
129 preClusterHeads.push_back(pixels.size());
130 pixels.emplace_back(-1, ip);
131 int lastIndex = preClusterIndices.size();
132 preClusterIndices.push_back(lastIndex);
133 curr[row] = lastIndex;
134 }
135
136 void fetchMCLabels(uint32_t digID, const ConstDigitTruth* labelsDig, int& nfilled);
137 void initChip(gsl::span<const Digit> digits, uint32_t first, GeometryTGeo* geom);
138 void updateChip(gsl::span<const Digit> digits, uint32_t ip);
139 void finishChip(gsl::span<const Digit> digits,
140 const ConstDigitTruth* labelsDigPtr, ClusterTruth* labelsClusPtr,
141 GeometryTGeo* geom);
142 void finishChipSingleHitFast(gsl::span<const Digit> digits, uint32_t hit,
143 const ConstDigitTruth* labelsDigPtr, ClusterTruth* labelsClusPtr,
144 GeometryTGeo* geom);
145 void processChip(gsl::span<const Digit> digits, int chipFirst, int chipN,
146 std::vector<Cluster>* clustersOut, std::vector<unsigned char>* patternsOut,
147 const ConstDigitTruth* labelsDigPtr, ClusterTruth* labelsClusPtr,
148 GeometryTGeo* geom);
149 void streamCluster(const BBox& bbox, const std::vector<std::pair<uint16_t, uint16_t>>& pixbuf,
150 uint32_t totalCharge, bool doLabels, int nlab,
151 uint16_t chipID, int subDetID, int layer, int disk);
152
154 {
155 delete[] column1;
156 delete[] column2;
157 }
158 explicit ClustererThread(Clusterer* par = nullptr) : parent(par) {}
161 };
162 //----------------------------------------------
163
164 void process(gsl::span<const Digit> digits,
165 gsl::span<const DigROFRecord> digitROFs,
166 std::vector<o2::trk::Cluster>& clusters,
167 std::vector<unsigned char>& patterns,
168 std::vector<o2::trk::ROFRecord>& clusterROFs,
169 const ConstDigitTruth* digitLabels = nullptr,
170 ClusterTruth* clusterLabels = nullptr,
171 gsl::span<const DigMC2ROFRecord> digMC2ROFs = {},
172 std::vector<o2::trk::MC2ROFRecord>* clusterMC2ROFs = nullptr);
173
174 private:
175 int mNHugeClus = 0;
176 std::unique_ptr<ClustererThread> mThread;
177 std::vector<int> mSortIdx;
178};
179
180} // namespace o2::trk
181
182#endif
A const (ready only) version of MCTruthContainer.
Definition of the ITSMFT digit.
Definition of the ITSMFT ROFrame (trigger) record.
Definition of a container to keep Monte Carlo truth external to simulation objects.
uint32_t c
Definition RawData.h:2
specs of the ALICE3 TRK
static constexpr uint8_t MaxRowSpan
static constexpr uint8_t MaxColSpan
Digit class for the ITS.
Definition Digit.h:30
static constexpr int MaxLabels
Definition Clusterer.h:46
static constexpr int MaxHugeClusWarn
Definition Clusterer.h:47
GLsizeiptr size
Definition glcorearb.h:659
GLint GLint GLsizei GLint GLenum GLenum const void * pixels
Definition glcorearb.h:275
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLboolean r
Definition glcorearb.h:1233
uint16_t colSpan() const
Definition Clusterer.h:64
void adjust(uint16_t r, uint16_t c)
Definition Clusterer.h:70
uint16_t rowSpan() const
Definition Clusterer.h:63
bool isAcceptableSize() const
Definition Clusterer.h:65
bool isInside(uint16_t r, uint16_t c) const
Definition Clusterer.h:62
void resetColumn(int *buff) const
swap current and previous column buffers
Definition Clusterer.h:113
std::vector< Cluster > clusters
Definition Clusterer.h:108
void updateChip(gsl::span< const Digit > digits, uint32_t ip)
std::vector< std::pair< int, uint32_t > > pixels
Definition Clusterer.h:98
int * curr
current column pre-cluster indices
Definition Clusterer.h:93
void processChip(gsl::span< const Digit > digits, int chipFirst, int chipN, std::vector< Cluster > *clustersOut, std::vector< unsigned char > *patternsOut, const ConstDigitTruth *labelsDigPtr, ClusterTruth *labelsClusPtr, GeometryTGeo *geom)
Definition Clusterer.cxx:94
std::vector< int > preClusterHeads
Definition Clusterer.h:99
ClusterTruth labels
reset column buffer
Definition Clusterer.h:110
int * prev
previous column pre-cluster indices
Definition Clusterer.h:94
void finishChip(gsl::span< const Digit > digits, const ConstDigitTruth *labelsDigPtr, ClusterTruth *labelsClusPtr, GeometryTGeo *geom)
void finishChipSingleHitFast(gsl::span< const Digit > digits, uint32_t hit, const ConstDigitTruth *labelsDigPtr, ClusterTruth *labelsClusPtr, GeometryTGeo *geom)
void expandPreCluster(uint32_t ip, uint16_t row, int preClusterIndex)
start a new pre-cluster with pixel ip at given row
Definition Clusterer.h:118
std::vector< unsigned char > patterns
Definition Clusterer.h:109
ClustererThread(Clusterer *par=nullptr)
Definition Clusterer.h:158
void addNewPreCluster(uint32_t ip, uint16_t row)
Definition Clusterer.h:127
void streamCluster(const BBox &bbox, const std::vector< std::pair< uint16_t, uint16_t > > &pixbuf, uint32_t totalCharge, bool doLabels, int nlab, uint16_t chipID, int subDetID, int layer, int disk)
std::vector< std::pair< uint16_t, uint16_t > > pixArrBuff
(row,col) pixel buffer for pattern
Definition Clusterer.h:105
ClustererThread & operator=(const ClustererThread &)=delete
void initChip(gsl::span< const Digit > digits, uint32_t first, GeometryTGeo *geom)
std::vector< int > preClusterIndices
Definition Clusterer.h:100
ClustererThread(const ClustererThread &)=delete
void fetchMCLabels(uint32_t digID, const ConstDigitTruth *labelsDig, int &nfilled)
std::array< Label, MaxLabels > labelsBuff
MC label buffer for one cluster.
Definition Clusterer.h:104
void swapColumnBuffers()
append pixel ip to the pre-cluster headed at preClusterIndex
Definition Clusterer.h:115
std::vector< Cluster > clusters
std::vector< Digit > digits
std::vector< int > row