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
44template <int DetID>
46{
47 static_assert(DetID == o2::detectors::DetID::TRK || DetID == o2::detectors::DetID::FT3, "only TRK and FT3 clusterers are supported");
48
49 public:
50 static constexpr int MaxLabels = 10;
51 static constexpr int MaxHugeClusWarn = 5;
52
59
60 //----------------------------------------------
61 struct BBox {
62 uint16_t chipID = 0xffff;
63 uint16_t rowMin = 0xffff, colMin = 0xffff;
64 uint16_t rowMax = 0, colMax = 0;
65 explicit BBox(uint16_t c) : chipID(c) {}
66 bool isInside(uint16_t r, uint16_t c) const { return r >= rowMin && r <= rowMax && c >= colMin && c <= colMax; }
67 uint16_t rowSpan() const { return rowMax - rowMin + 1; }
68 uint16_t colSpan() const { return colMax - colMin + 1; }
74 void adjust(uint16_t r, uint16_t c)
75 {
76 if (r < rowMin) {
77 rowMin = r;
78 }
79 if (r > rowMax) {
80 rowMax = r;
81 }
82 if (c < colMin) {
83 colMin = c;
84 }
85 if (c > colMax) {
86 colMax = c;
87 }
88 }
89 };
90
91 //----------------------------------------------
94 // column buffers (pre-cluster state); extra sentinel entries at [0] and [size-1]
95 int* column1 = nullptr;
96 int* column2 = nullptr;
97 int* curr = nullptr;
98 int* prev = nullptr;
100
101 // pixels[i] = {next_in_chain, global_digit_index}
102 std::vector<std::pair<int, uint32_t>> pixels;
103 std::vector<int> preClusterHeads;
104 std::vector<int> preClusterIndices;
105 uint16_t currCol = 0xffff;
106 bool noLeftCol = true;
107
108 std::array<Label, MaxLabels> labelsBuff;
109 std::vector<std::pair<uint16_t, uint16_t>> pixArrBuff;
110
111 // per-thread output (accumulated, then merged back by caller)
112 std::vector<ClusterType> clusters;
113 std::vector<unsigned char> patterns;
115
117 void resetColumn(int* buff) const { std::memset(buff, -1, sizeof(int) * (size - 2)); }
119 void swapColumnBuffers() { std::swap(prev, curr); }
120
122 void expandPreCluster(uint32_t ip, uint16_t row, int preClusterIndex)
123 {
124 auto& firstIndex = preClusterHeads[preClusterIndices[preClusterIndex]];
125 pixels.emplace_back(firstIndex, ip);
126 firstIndex = pixels.size() - 1;
127 curr[row] = preClusterIndex;
128 }
129
131 void addNewPreCluster(uint32_t ip, uint16_t row)
132 {
133 preClusterHeads.push_back(pixels.size());
134 pixels.emplace_back(-1, ip);
135 int lastIndex = preClusterIndices.size();
136 preClusterIndices.push_back(lastIndex);
137 curr[row] = lastIndex;
138 }
139
140 void fetchMCLabels(uint32_t digID, const ConstDigitTruth* labelsDig, int& nfilled);
141 void initChip(gsl::span<const Digit> digits, uint32_t first, GeometryTGeo* geom);
142 void updateChip(gsl::span<const Digit> digits, uint32_t ip);
143 void finishChip(gsl::span<const Digit> digits,
144 const ConstDigitTruth* labelsDigPtr, ClusterTruth* labelsClusPtr,
145 GeometryTGeo* geom);
146 void finishChipSingleHitFast(gsl::span<const Digit> digits, uint32_t hit,
147 const ConstDigitTruth* labelsDigPtr, ClusterTruth* labelsClusPtr,
148 GeometryTGeo* geom);
149 void processChip(gsl::span<const Digit> digits, int chipFirst, int chipN,
150 std::vector<ClusterType>* clustersOut, std::vector<unsigned char>* patternsOut,
151 const ConstDigitTruth* labelsDigPtr, ClusterTruth* labelsClusPtr,
152 GeometryTGeo* geom);
153 void streamCluster(const BBox& bbox, const std::vector<std::pair<uint16_t, uint16_t>>& pixbuf,
154 uint32_t totalCharge, bool doLabels, int nlab,
155 uint16_t chipID, int subDetID, int layer);
156
158 {
159 delete[] column1;
160 delete[] column2;
161 }
162 explicit ClustererThread(Clusterer<DetID>* par = nullptr) : parent(par) {}
165 };
166 //----------------------------------------------
167
168 virtual void process(gsl::span<const Digit> digits,
169 gsl::span<const DigROFRecord> digitROFs,
170 std::vector<ClusterType>& clusters,
171 std::vector<unsigned char>& patterns,
172 std::vector<o2::trkft3::ROFRecord>& clusterROFs,
173 const ConstDigitTruth* digitLabels = nullptr,
174 ClusterTruth* clusterLabels = nullptr);
175
176 static o2::math_utils::Point3D<float> getClusterLocalCoordinates(const ClusterType& cluster, const uint8_t* patt,
177 float yPlaneMLOT = 0.f) noexcept;
178
179 protected:
180 int mNHugeClus = 0;
182 std::vector<int> mSortIdx;
183};
184
185using TRKClusterer = Clusterer<o2::detectors::DetID::TRK>;
186using FT3Clusterer = Clusterer<o2::detectors::DetID::FT3>;
187
188} // namespace o2::trk
189
190#endif
A const (ready only) version of MCTruthContainer.
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 class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:58
static constexpr uint8_t MaxRowSpan
static constexpr uint8_t MaxColSpan
std::unique_ptr< ClustererThread > mThread
Definition Clusterer.h:181
std::vector< int > mSortIdx
reusable per-ROF sort buffer
Definition Clusterer.h:182
static constexpr int MaxLabels
Definition Clusterer.h:50
static constexpr int MaxHugeClusWarn
Definition Clusterer.h:51
static o2::math_utils::Point3D< float > getClusterLocalCoordinates(const ClusterType &cluster, const uint8_t *patt, float yPlaneMLOT=0.f) noexcept
Definition Clusterer.cxx:27
virtual void process(gsl::span< const Digit > digits, gsl::span< const DigROFRecord > digitROFs, std::vector< ClusterType > &clusters, std::vector< unsigned char > &patterns, std::vector< o2::trkft3::ROFRecord > &clusterROFs, const ConstDigitTruth *digitLabels=nullptr, ClusterTruth *clusterLabels=nullptr)
Definition Clusterer.cxx:73
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
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
bool isInside(uint16_t r, uint16_t c) const
Definition Clusterer.h:66
void adjust(uint16_t r, uint16_t c)
Definition Clusterer.h:74
uint16_t colSpan() const
Definition Clusterer.h:68
bool isAcceptableSize() const
Definition Clusterer.h:69
uint16_t rowSpan() const
Definition Clusterer.h:67
void updateChip(gsl::span< const Digit > digits, uint32_t ip)
void finishChip(gsl::span< const Digit > digits, const ConstDigitTruth *labelsDigPtr, ClusterTruth *labelsClusPtr, GeometryTGeo *geom)
void initChip(gsl::span< const Digit > digits, uint32_t first, GeometryTGeo *geom)
std::array< Label, MaxLabels > labelsBuff
MC label buffer for one cluster.
Definition Clusterer.h:108
std::vector< std::pair< int, uint32_t > > pixels
Definition Clusterer.h:102
int * prev
previous column pre-cluster indices
Definition Clusterer.h:98
void addNewPreCluster(uint32_t ip, uint16_t row)
Definition Clusterer.h:131
Clusterer< DetID > * parent
Definition Clusterer.h:93
void finishChipSingleHitFast(gsl::span< const Digit > digits, uint32_t hit, const ConstDigitTruth *labelsDigPtr, ClusterTruth *labelsClusPtr, GeometryTGeo *geom)
std::vector< int > preClusterIndices
Definition Clusterer.h:104
void processChip(gsl::span< const Digit > digits, int chipFirst, int chipN, std::vector< ClusterType > *clustersOut, std::vector< unsigned char > *patternsOut, const ConstDigitTruth *labelsDigPtr, ClusterTruth *labelsClusPtr, GeometryTGeo *geom)
std::vector< std::pair< uint16_t, uint16_t > > pixArrBuff
(row,col) pixel buffer for pattern
Definition Clusterer.h:109
void swapColumnBuffers()
append pixel ip to the pre-cluster headed at preClusterIndex
Definition Clusterer.h:119
ClustererThread(Clusterer< DetID > *par=nullptr)
Definition Clusterer.h:162
void resetColumn(int *buff) const
swap current and previous column buffers
Definition Clusterer.h:117
std::vector< int > preClusterHeads
Definition Clusterer.h:103
ClustererThread(const ClustererThread &)=delete
std::vector< unsigned char > patterns
Definition Clusterer.h:113
ClusterTruth labels
reset column buffer
Definition Clusterer.h:114
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)
std::vector< ClusterType > clusters
Definition Clusterer.h:112
void fetchMCLabels(uint32_t digID, const ConstDigitTruth *labelsDig, int &nfilled)
ClustererThread & operator=(const ClustererThread &)=delete
void expandPreCluster(uint32_t ip, uint16_t row, int preClusterIndex)
start a new pre-cluster with pixel ip at given row
Definition Clusterer.h:122
int * curr
current column pre-cluster indices
Definition Clusterer.h:97
std::vector< Cluster > clusters
std::vector< Digit > digits
std::vector< int > row