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 "MathUtils/Cartesian.h"
32#include <gsl/span>
33#include <vector>
34#include <array>
35#include <memory>
36#include <cstring>
37#include <utility>
38
39namespace o2::trk
40{
41
42class GeometryTGeo;
43
45{
46 public:
47 static constexpr int MaxLabels = 10;
48 static constexpr int MaxHugeClusWarn = 5;
49
56
57 //----------------------------------------------
58 struct BBox {
59 uint16_t chipID = 0xffff;
60 uint16_t rowMin = 0xffff, colMin = 0xffff;
61 uint16_t rowMax = 0, colMax = 0;
62 explicit BBox(uint16_t c) : chipID(c) {}
63 bool isInside(uint16_t r, uint16_t c) const { return r >= rowMin && r <= rowMax && c >= colMin && c <= colMax; }
64 uint16_t rowSpan() const { return rowMax - rowMin + 1; }
65 uint16_t colSpan() const { return colMax - colMin + 1; }
71 void adjust(uint16_t r, uint16_t c)
72 {
73 if (r < rowMin) {
74 rowMin = r;
75 }
76 if (r > rowMax) {
77 rowMax = r;
78 }
79 if (c < colMin) {
80 colMin = c;
81 }
82 if (c > colMax) {
83 colMax = c;
84 }
85 }
86 };
87
88 //----------------------------------------------
90 Clusterer* parent = nullptr;
91 // column buffers (pre-cluster state); extra sentinel entries at [0] and [size-1]
92 int* column1 = nullptr;
93 int* column2 = nullptr;
94 int* curr = nullptr;
95 int* prev = nullptr;
97
98 // pixels[i] = {next_in_chain, global_digit_index}
99 std::vector<std::pair<int, uint32_t>> pixels;
100 std::vector<int> preClusterHeads;
101 std::vector<int> preClusterIndices;
102 uint16_t currCol = 0xffff;
103 bool noLeftCol = true;
104
105 std::array<Label, MaxLabels> labelsBuff;
106 std::vector<std::pair<uint16_t, uint16_t>> pixArrBuff;
107
108 // per-thread output (accumulated, then merged back by caller)
109 std::vector<Cluster> clusters;
110 std::vector<unsigned char> patterns;
112
114 void resetColumn(int* buff) const { std::memset(buff, -1, sizeof(int) * (size - 2)); }
116 void swapColumnBuffers() { std::swap(prev, curr); }
117
119 void expandPreCluster(uint32_t ip, uint16_t row, int preClusterIndex)
120 {
121 auto& firstIndex = preClusterHeads[preClusterIndices[preClusterIndex]];
122 pixels.emplace_back(firstIndex, ip);
123 firstIndex = pixels.size() - 1;
124 curr[row] = preClusterIndex;
125 }
126
128 void addNewPreCluster(uint32_t ip, uint16_t row)
129 {
130 preClusterHeads.push_back(pixels.size());
131 pixels.emplace_back(-1, ip);
132 int lastIndex = preClusterIndices.size();
133 preClusterIndices.push_back(lastIndex);
134 curr[row] = lastIndex;
135 }
136
137 void fetchMCLabels(uint32_t digID, const ConstDigitTruth* labelsDig, int& nfilled);
138 void initChip(gsl::span<const Digit> digits, uint32_t first, GeometryTGeo* geom);
139 void updateChip(gsl::span<const Digit> digits, uint32_t ip);
140 void finishChip(gsl::span<const Digit> digits,
141 const ConstDigitTruth* labelsDigPtr, ClusterTruth* labelsClusPtr,
142 GeometryTGeo* geom);
143 void finishChipSingleHitFast(gsl::span<const Digit> digits, uint32_t hit,
144 const ConstDigitTruth* labelsDigPtr, ClusterTruth* labelsClusPtr,
145 GeometryTGeo* geom);
146 void processChip(gsl::span<const Digit> digits, int chipFirst, int chipN,
147 std::vector<Cluster>* clustersOut, std::vector<unsigned char>* patternsOut,
148 const ConstDigitTruth* labelsDigPtr, ClusterTruth* labelsClusPtr,
149 GeometryTGeo* geom);
150 void streamCluster(const BBox& bbox, const std::vector<std::pair<uint16_t, uint16_t>>& pixbuf,
151 uint32_t totalCharge, bool doLabels, int nlab,
152 uint16_t chipID, int subDetID, int layer, int disk);
153
155 {
156 delete[] column1;
157 delete[] column2;
158 }
159 explicit ClustererThread(Clusterer* par = nullptr) : parent(par) {}
162 };
163 //----------------------------------------------
164
165 virtual void process(gsl::span<const Digit> digits,
166 gsl::span<const DigROFRecord> digitROFs,
167 std::vector<o2::trk::Cluster>& clusters,
168 std::vector<unsigned char>& patterns,
169 std::vector<o2::trk::ROFRecord>& clusterROFs,
170 const ConstDigitTruth* digitLabels = nullptr,
171 ClusterTruth* clusterLabels = nullptr,
172 gsl::span<const DigMC2ROFRecord> digMC2ROFs = {},
173 std::vector<o2::trk::MC2ROFRecord>* clusterMC2ROFs = nullptr);
174
175 static o2::math_utils::Point3D<float> getClusterLocalCoordinates(const Cluster& cluster, const uint8_t* patt,
176 float yPlaneMLOT = 0.f) noexcept;
177
178 protected:
179 int mNHugeClus = 0;
181 std::vector<int> mSortIdx;
182};
183
184} // namespace o2::trk
185
186#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.
#define protected
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 o2::math_utils::Point3D< float > getClusterLocalCoordinates(const Cluster &cluster, const uint8_t *patt, float yPlaneMLOT=0.f) noexcept
Definition Clusterer.cxx:26
std::unique_ptr< ClustererThread > mThread
Definition Clusterer.h:180
virtual void process(gsl::span< const Digit > digits, gsl::span< const DigROFRecord > digitROFs, std::vector< o2::trk::Cluster > &clusters, std::vector< unsigned char > &patterns, std::vector< o2::trk::ROFRecord > &clusterROFs, const ConstDigitTruth *digitLabels=nullptr, ClusterTruth *clusterLabels=nullptr, gsl::span< const DigMC2ROFRecord > digMC2ROFs={}, std::vector< o2::trk::MC2ROFRecord > *clusterMC2ROFs=nullptr)
Definition Clusterer.cxx:71
std::vector< int > mSortIdx
reusable per-ROF sort buffer
Definition Clusterer.h:181
static constexpr int MaxLabels
Definition Clusterer.h:47
static constexpr int MaxHugeClusWarn
Definition Clusterer.h:48
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:65
void adjust(uint16_t r, uint16_t c)
Definition Clusterer.h:71
uint16_t rowSpan() const
Definition Clusterer.h:64
bool isAcceptableSize() const
Definition Clusterer.h:66
bool isInside(uint16_t r, uint16_t c) const
Definition Clusterer.h:63
void resetColumn(int *buff) const
swap current and previous column buffers
Definition Clusterer.h:114
std::vector< Cluster > clusters
Definition Clusterer.h:109
void updateChip(gsl::span< const Digit > digits, uint32_t ip)
std::vector< std::pair< int, uint32_t > > pixels
Definition Clusterer.h:99
int * curr
current column pre-cluster indices
Definition Clusterer.h:94
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)
std::vector< int > preClusterHeads
Definition Clusterer.h:100
ClusterTruth labels
reset column buffer
Definition Clusterer.h:111
int * prev
previous column pre-cluster indices
Definition Clusterer.h:95
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:119
std::vector< unsigned char > patterns
Definition Clusterer.h:110
ClustererThread(Clusterer *par=nullptr)
Definition Clusterer.h:159
void addNewPreCluster(uint32_t ip, uint16_t row)
Definition Clusterer.h:128
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:106
ClustererThread & operator=(const ClustererThread &)=delete
void initChip(gsl::span< const Digit > digits, uint32_t first, GeometryTGeo *geom)
std::vector< int > preClusterIndices
Definition Clusterer.h:101
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:105
void swapColumnBuffers()
append pixel ip to the pre-cluster headed at preClusterIndex
Definition Clusterer.h:116
std::vector< Cluster > clusters
std::vector< Digit > digits
std::vector< int > row