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 <type_traits>
38#include <utility>
39
40namespace o2::ft3
41{
42class GeometryTGeo;
43}
44
45namespace o2::trk
46{
47
48class GeometryTGeo;
49
50template <int DetID>
52{
53 static_assert(DetID == o2::detectors::DetID::TRK || DetID == o2::detectors::DetID::FT3, "only TRK and FT3 clusterers are supported");
54
55 public:
56 static constexpr int MaxLabels = 10;
57 static constexpr int MaxHugeClusWarn = 5;
58
66 using GeometryTGeo = std::conditional_t<DetID == o2::detectors::DetID::TRK, o2::trk::GeometryTGeo, o2::ft3::GeometryTGeo>;
67
68 //----------------------------------------------
69 struct BBox {
70 uint16_t chipID = 0xffff;
71 uint16_t rowMin = 0xffff, colMin = 0xffff;
73 explicit BBox(uint16_t c) : chipID(c) {}
74 bool isInside(uint16_t r, uint16_t c) const { return r >= rowMin && r <= rowMax && c >= colMin && c <= colMax; }
75 uint16_t rowSpan() const { return rowMax - rowMin + 1; }
76 uint16_t colSpan() const { return colMax - colMin + 1; }
83 {
84 if (r < rowMin) {
85 rowMin = r;
86 }
87 if (r > rowMax) {
88 rowMax = r;
89 }
90 if (c < colMin) {
91 colMin = c;
92 }
93 if (c > colMax) {
94 colMax = c;
95 }
96 }
97 };
98
99 //----------------------------------------------
102 // column buffers (pre-cluster state); extra sentinel entries at [0] and [size-1]
103 int* column1 = nullptr;
104 int* column2 = nullptr;
105 int* curr = nullptr;
106 int* prev = nullptr;
108
109 // pixels[i] = {next_in_chain, global_digit_index}
110 std::vector<std::pair<int, uint32_t>> pixels;
111 std::vector<int> preClusterHeads;
112 std::vector<int> preClusterIndices;
114 bool noLeftCol = true;
115
116 std::array<Label, MaxLabels> labelsBuff;
117 std::vector<std::pair<uint16_t, uint16_t>> pixArrBuff;
118
119 // per-thread output (accumulated, then merged back by caller)
120 std::vector<ClusterType> clusters;
121 std::vector<unsigned char> patterns;
123
125 void resetColumn(int* buff) const { std::memset(buff, -1, sizeof(int) * (size - 2)); }
127 void swapColumnBuffers() { std::swap(prev, curr); }
128
130 void expandPreCluster(uint32_t ip, uint16_t row, int preClusterIndex)
131 {
132 auto& firstIndex = preClusterHeads[preClusterIndices[preClusterIndex]];
133 pixels.emplace_back(firstIndex, ip);
134 firstIndex = pixels.size() - 1;
135 curr[row] = preClusterIndex;
136 }
137
140 {
141 preClusterHeads.push_back(pixels.size());
142 pixels.emplace_back(-1, ip);
143 int lastIndex = preClusterIndices.size();
144 preClusterIndices.push_back(lastIndex);
145 curr[row] = lastIndex;
146 }
147
148 void fetchMCLabels(uint32_t digID, const ConstDigitTruth* labelsDig, int& nfilled);
149 void initChip(gsl::span<const Digit> digits, uint32_t first, GeometryTGeo* geom);
150 void updateChip(gsl::span<const Digit> digits, uint32_t ip);
151 void finishChip(gsl::span<const Digit> digits,
152 const ConstDigitTruth* labelsDigPtr, ClusterTruth* labelsClusPtr,
153 GeometryTGeo* geom);
154 void finishChipSingleHitFast(gsl::span<const Digit> digits, uint32_t hit,
155 const ConstDigitTruth* labelsDigPtr, ClusterTruth* labelsClusPtr,
156 GeometryTGeo* geom);
157 void processChip(gsl::span<const Digit> digits, int chipFirst, int chipN,
158 std::vector<ClusterType>* clustersOut, std::vector<unsigned char>* patternsOut,
159 const ConstDigitTruth* labelsDigPtr, ClusterTruth* labelsClusPtr,
160 GeometryTGeo* geom);
161 void streamCluster(const BBox& bbox, const std::vector<std::pair<uint16_t, uint16_t>>& pixbuf,
162 uint32_t totalCharge, bool doLabels, int nlab,
163 uint16_t chipID, int subDetID, int layer);
164
166 {
167 delete[] column1;
168 delete[] column2;
169 }
170 explicit ClustererThread(Clusterer<DetID>* par = nullptr) : parent(par) {}
173 };
174 //----------------------------------------------
175
176 virtual void process(gsl::span<const Digit> digits,
177 gsl::span<const DigROFRecord> digitROFs,
178 std::vector<ClusterType>& clusters,
179 std::vector<unsigned char>& patterns,
180 std::vector<o2::trkft3::ROFRecord>& clusterROFs,
181 const ConstDigitTruth* digitLabels = nullptr,
182 ClusterTruth* clusterLabels = nullptr);
183
185 float yPlaneMLOT = 0.f) noexcept;
186
187 protected:
188 int mNHugeClus = 0;
190 std::vector<int> mSortIdx;
191};
192
193using TRKClusterer = Clusterer<o2::detectors::DetID::TRK>;
194using FT3Clusterer = Clusterer<o2::detectors::DetID::FT3>;
195
196} // namespace o2::trk
197
198#endif
A const (ready only) version of MCTruthContainer.
unsigned short int uint16_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to process
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:60
static constexpr uint8_t MaxRowSpan
static constexpr uint8_t MaxColSpan
std::conditional_t< DetID==o2::detectors::DetID::TRK, o2::trk::GeometryTGeo, o2::ft3::GeometryTGeo > GeometryTGeo
The geometry that gives a chip's sub-detector and layer.
Definition Clusterer.h:66
std::unique_ptr< ClustererThread > mThread
Definition Clusterer.h:189
std::vector< int > mSortIdx
reusable per-ROF sort buffer
Definition Clusterer.h:190
static constexpr int MaxLabels
Definition Clusterer.h:56
static constexpr int MaxHugeClusWarn
Definition Clusterer.h:57
static o2::math_utils::Point3D< float > getClusterLocalCoordinates(const ClusterType &cluster, const uint8_t *patt, float yPlaneMLOT=0.f) noexcept
Definition Clusterer.cxx:28
GLsizeiptr size
Definition glcorearb.h:659
GLint first
Definition glcorearb.h:399
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:74
void adjust(uint16_t r, uint16_t c)
Definition Clusterer.h:82
uint16_t colSpan() const
Definition Clusterer.h:76
bool isAcceptableSize() const
Definition Clusterer.h:77
uint16_t rowSpan() const
Definition Clusterer.h:75
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:116
std::vector< std::pair< int, uint32_t > > pixels
Definition Clusterer.h:110
int * prev
previous column pre-cluster indices
Definition Clusterer.h:106
void addNewPreCluster(uint32_t ip, uint16_t row)
Definition Clusterer.h:139
void finishChipSingleHitFast(gsl::span< const Digit > digits, uint32_t hit, const ConstDigitTruth *labelsDigPtr, ClusterTruth *labelsClusPtr, GeometryTGeo *geom)
std::vector< int > preClusterIndices
Definition Clusterer.h:112
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:117
void swapColumnBuffers()
append pixel ip to the pre-cluster headed at preClusterIndex
Definition Clusterer.h:127
ClustererThread(Clusterer< DetID > *par=nullptr)
Definition Clusterer.h:170
void resetColumn(int *buff) const
swap current and previous column buffers
Definition Clusterer.h:125
std::vector< int > preClusterHeads
Definition Clusterer.h:111
ClustererThread(const ClustererThread &)=delete
std::vector< unsigned char > patterns
Definition Clusterer.h:121
ClusterTruth labels
reset column buffer
Definition Clusterer.h:122
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:120
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:130
int * curr
current column pre-cluster indices
Definition Clusterer.h:105
std::vector< Cluster > clusters
std::vector< Digit > digits
std::vector< int > row