49 mPrimaryVertices.emplace_back(vert);
50 if (!isBeamPositionOverridden) {
51 const float w = vert.getNContributors();
52 mBeamPos[0] = (mBeamPos[0] * mBeamPosWeight + vert.getX() *
w) / (mBeamPosWeight +
w);
53 mBeamPos[1] = (mBeamPos[1] * mBeamPosWeight + vert.getY() *
w) / (mBeamPosWeight +
w);
60 gsl::span<const itsmft::CompClusterExt>
clusters,
61 gsl::span<const unsigned char>::iterator& pattIt,
68 resetROFrameData(
layer);
73 const auto& timing = mROFOverlapTableView.getLayer(
layer >= 0 ?
layer : 0);
74 if (timing.mNROFsTF != rofs.size()) {
75 LOGP(fatal,
"Received inconsistent number of rofs on layer:{} expected:{} received:{}",
layer, timing.mNROFsTF, rofs.size());
78 for (int32_t iRof{0}; iRof < rofs.size(); ++iRof) {
79 const auto& rof = rofs[iRof];
80 for (
int clusterId{rof.getFirstEntry()}; clusterId < rof.getFirstEntry() + rof.getNEntries(); ++clusterId) {
82 int lay = geom->
getLayer(
c.getSensorID());
83 auto pattID =
c.getPatternID();
104 auto sensorID =
c.getSensorID();
109 addTrackingFrameInfoToLayer(lay, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), trkXYZ.x(), geom->
getSensorRefAlpha(sensorID),
110 std::array<float, 2>{trkXYZ.y(), trkXYZ.z()},
111 std::array<float, 3>{sigmaY2, sigmaYZ, sigmaZ2});
113 addClusterToLayer(lay, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), mUnsortedClusters[lay].size());
114 addClusterExternalIndexToLayer(lay, clusterId);
118 mROFramesClusters[
layer][iRof + 1] = mUnsortedClusters[
layer].size();
120 for (
unsigned int iL{0}; iL < mUnsortedClusters.size(); ++iL) {
121 mROFramesClusters[iL][iRof + 1] = mUnsortedClusters[iL].size();
127 for (
auto i = 0;
i < mNTrackletsPerCluster.size(); ++
i) {
128 mNTrackletsPerCluster[
i].resize(mUnsortedClusters[1].
size());
129 mNTrackletsPerClusterSum[
i].resize(mUnsortedClusters[1].
size() + 1);
133 if (mcLabels !=
nullptr) {
134 mClusterLabels[
layer >= 0 ?
layer : 0] = mcLabels;
136 mClusterLabels[
layer >= 0 ?
layer : 0] =
nullptr;
140template <
int NLayers>
149 for (
int iLayer{0}; iLayer < NLayers; ++iLayer) {
150 deepVectorClear(mUnsortedClusters[iLayer], getMaybeFrameworkHostResource());
151 deepVectorClear(mTrackingFrameInfo[iLayer], getMaybeFrameworkHostResource());
153 clearResizeBoundedVector(mROFramesClusters[iLayer], mROFOverlapTableView.getLayer(iLayer).mNROFsTF + 1, getMaybeFrameworkHostResource());
158template <
int NLayers>
169 std::array<size_t, NLayers> clusterCountPerLayer{0};
171 ++clusterCountPerLayer[geom->
getLayer(cls.getChipID())];
173 for (
int iLayer{0}; iLayer < NLayers; ++iLayer) {
174 mUnsortedClusters[iLayer].reserve(clusterCountPerLayer[iLayer]);
175 mTrackingFrameInfo[iLayer].reserve(clusterCountPerLayer[iLayer]);
176 mClusterExternalIndices[iLayer].reserve(clusterCountPerLayer[iLayer]);
181template <
int NLayers>
185 const int stride{numBins + 1};
189 for (
int iLayer{0}, stopLayer = std::min(trkParam.
NLayers, maxLayers); iLayer < stopLayer; ++iLayer) {
190 for (
int rof{0}; rof < getNrof(iLayer); ++rof) {
191 if (!mROFMaskView.isROFEnabled(iLayer, rof)) {
194 const auto& unsortedClusters{getUnsortedClustersOnLayer(rof, iLayer)};
195 const int clustersNum{
static_cast<int>(unsortedClusters.size())};
196 auto* tableBase = mIndexTables[iLayer].data() + rof *
stride;
198 cHelper.resize(clustersNum);
200 for (
int iCluster{0}; iCluster < clustersNum; ++iCluster) {
201 const Cluster&
c = unsortedClusters[iCluster];
202 ClusterHelper&
h = cHelper[iCluster];
204 const float x =
c.xCoordinate - mBeamPos[0];
205 const float y =
c.yCoordinate - mBeamPos[1];
206 const float z =
c.zCoordinate;
208 float phi = math_utils::computePhi(
x,
y);
209 int zBin{mIndexTableUtils.getZBinIndex(iLayer,
z)};
210 if (zBin < 0 || zBin >= trkParam.
ZBins) {
211 zBin = std::clamp(zBin, 0, trkParam.
ZBins - 1);
212 mBogusClusters[iLayer]++;
214 int bin = mIndexTableUtils.getBinIndex(zBin, mIndexTableUtils.getPhiBinIndex(phi));
216 h.r = math_utils::hypot(
x,
y);
217 mMinR[iLayer] = o2::gpu::GPUCommonMath::Min(
h.r, mMinR[iLayer]);
218 mMaxR[iLayer] = o2::gpu::GPUCommonMath::Max(
h.r, mMaxR[iLayer]);
220 h.ind = clsPerBin[bin]++;
222 std::exclusive_scan(clsPerBin.begin(), clsPerBin.end(), lutPerBin.begin(), 0);
224 auto clusters2beSorted{getClustersOnLayer(rof, iLayer)};
225 for (
int iCluster{0}; iCluster < clustersNum; ++iCluster) {
226 const ClusterHelper&
h = cHelper[iCluster];
227 Cluster&
c = clusters2beSorted[lutPerBin[
h.bin] +
h.ind];
229 c = unsortedClusters[iCluster];
232 c.indexTableBinIndex =
h.bin;
234 std::copy_n(lutPerBin.data(), clsPerBin.size(), tableBase);
235 std::fill_n(tableBase + clsPerBin.size(),
stride - clsPerBin.size(), clustersNum);
237 std::fill(clsPerBin.begin(), clsPerBin.end(), 0);
243template <
int NLayers>
246 if (iteration == 0) {
264 mIndexTableUtils.setTrackingParameters(trkParam);
268 for (
unsigned int iLayer{0}; iLayer < std::min((
int)mClusters.size(), maxLayers); ++iLayer) {
276 for (
int iLayer{0}; iLayer < NLayers; ++iLayer) {
279 for (
int iLayer{0}; iLayer < trkParam.
NLayers; ++iLayer) {
281 for (
auto& tfInfo : mTrackingFrameInfo[iLayer]) {
283 tfInfo.covarianceTrackingFrame[0] += trkParam.
SystErrorY2[iLayer];
284 tfInfo.covarianceTrackingFrame[2] += trkParam.
SystErrorZ2[iLayer];
289 mMinR.fill(std::numeric_limits<float>::max());
290 mMaxR.fill(std::numeric_limits<float>::min());
292 mNTrackletsPerROF.resize(2);
293 for (
auto&
v : mNTrackletsPerROF) {
296 if (iteration == 0 || iteration == 3) {
297 prepareClusters(trkParam, maxLayers);
299 mTotalTracklets = {0, 0};
300 if (maxLayers < trkParam.
NLayers) {
301 for (
size_t iLayer{0}; iLayer < maxLayers; ++iLayer) {
307 mMSangles.resize(trkParam.
NLayers);
308 mPhiCuts.resize(mClusters.size() - 1, 0.f);
309 float oneOverR{0.001f * 0.3f * std::abs(mBz) / trkParam.
TrackletMinPt};
310 for (
unsigned int iLayer{0}; iLayer < NLayers; ++iLayer) {
313 if (iLayer < mClusters.size() - 1) {
314 const float& r1 = trkParam.
LayerRadii[iLayer];
315 const float& r2 = trkParam.
LayerRadii[iLayer + 1];
317 const float res1 = o2::gpu::CAMath::Hypot(trkParam.
PVres, mPositionResolution[iLayer]);
318 const float res2 = o2::gpu::CAMath::Hypot(trkParam.
PVres, mPositionResolution[iLayer + 1]);
319 const float cosTheta1half = o2::gpu::CAMath::Sqrt(1.f - math_utils::Sq(0.5f * r1 * oneOverR));
320 const float cosTheta2half = o2::gpu::CAMath::Sqrt(1.f - math_utils::Sq(0.5f * r2 * oneOverR));
321 float x = (r2 * cosTheta1half) - (r1 * cosTheta2half);
322 float delta = o2::gpu::CAMath::Sqrt(1.f / (1.f - 0.25f * math_utils::Sq(
x * oneOverR)) * (math_utils::Sq((0.25f * r1 * r2 * math_utils::Sq(oneOverR) / cosTheta2half) + cosTheta1half) * math_utils::Sq(res1) + math_utils::Sq((0.25f * r1 * r2 * math_utils::Sq(oneOverR) / cosTheta1half) + cosTheta2half) * math_utils::Sq(res2)));
324 mPhiCuts[iLayer] = std::min(o2::gpu::CAMath::ASin(0.5f *
x * oneOverR) + 2.f * mMSangles[iLayer] + delta,
o2::constants::math::PI * 0.5f);
328 for (
int iLayer{0}; iLayer < std::min((
int)mTracklets.size(), maxLayers); ++iLayer) {
331 if (iLayer < (
int)mCells.size()) {
334 mTrackletsLookupTable[iLayer].resize(mClusters[iLayer + 1].
size() + 1, 0);
338 if (iLayer < (
int)mCells.size() - 1) {
346template <
int NLayers>
349 unsigned long size{0};
350 for (
const auto& trkl : mTracklets) {
353 for (
const auto&
cells : mCells) {
356 for (
const auto& cellsN : mCellsNeighbours) {
357 size +=
sizeof(
int) * cellsN.size();
362template <
int NLayers>
365 LOGP(info,
"TimeFrame: Artefacts occupy {:.2f} MB", getArtefactsMemory() /
constants::MB);
368template <
int NLayers>
371 for (ushort iLayer = 0; iLayer < 2; ++iLayer) {
372 for (
unsigned int iRof{0}; iRof < getNrof(1); ++iRof) {
373 if (mROFMaskView.isROFEnabled(1, iRof)) {
374 mTotalTracklets[iLayer] += mNTrackletsPerROF[iLayer][iRof];
377 std::exclusive_scan(mNTrackletsPerROF[iLayer].begin(), mNTrackletsPerROF[iLayer].
end(), mNTrackletsPerROF[iLayer].begin(), 0);
378 std::exclusive_scan(mNTrackletsPerCluster[iLayer].begin(), mNTrackletsPerCluster[iLayer].
end(), mNTrackletsPerClusterSum[iLayer].begin(), 0);
382template <
int NLayers>
392 auto initContainers = [&]<
typename Container>(Container& container,
bool useExternal =
false) {
393 for (
auto&
v : container) {
394 initVector(
v, useExternal);
399 initContainers(mClusterExternalIndices);
400 initContainers(mNTrackletsPerCluster);
401 initContainers(mNTrackletsPerClusterSum);
402 initContainers(mNClustersPerROF);
403 initVector(mPrimaryVertices);
404 initVector(mMSangles);
405 initVector(mPhiCuts);
406 initVector(mPositionResolution);
407 initContainers(mClusterSize);
408 initVector(mPValphaX);
409 initVector(mBogusClusters);
410 initContainers(mTrackletsIndexROF);
412 initContainers(mTracklets);
413 initContainers(mCells);
414 initContainers(mCellsNeighbours);
415 initContainers(mCellsLookupTable);
417 initVector(mPrimaryVerticesLabels);
418 initContainers(mLinesLabels);
419 initContainers(mTrackletLabels);
420 initContainers(mCellLabels);
421 initVector(mTracksLabel);
423 initContainers(mClusters, hasFrameworkAllocator());
424 initContainers(mUsedClusters, hasFrameworkAllocator());
425 initContainers(mUnsortedClusters, hasFrameworkAllocator());
426 initContainers(mIndexTables, hasFrameworkAllocator());
427 initContainers(mTrackingFrameInfo, hasFrameworkAllocator());
428 initContainers(mROFramesClusters, hasFrameworkAllocator());
431template <
int NLayers>
434 mExternalAllocator = ext;
435 mExtMemoryPool = std::make_shared<BoundedMemoryResource>(mExternalAllocator);
438template <
int NLayers>
463 if (!hasFrameworkAllocator()) {
472 if (hasMCinformation()) {
483#ifdef ENABLE_UPGRADES
Definition of the ITSMFT compact cluster.
Definition of the GeometryTGeo class.
Definition of the SegmentationAlpide class.
Class for time synchronization of RawReader instances.
const Mat3D & getMatrixL2G(int sensID) const
HMPID cluster implementation.
CellSeed: connections of three clusters.
const Mat3D & getMatrixT2L(int lay, int hba, int sta, int det) const
float getSensorRefAlpha(int isn) const
static GeometryTGeo * Instance()
int getLayer(int index) const final
Get chip layer, from 0.
void fillMatrixCache(int mask) override
static constexpr unsigned short InvalidPatternID
static constexpr float PitchCol
static constexpr float PitchRow
math_utils::Point3D< T > getClusterCoordinates(const CompCluster &cl) const
float getErr2X(int n) const
Returns the error^2 on the x position of the COG for the n_th element.
int getNpixels(int n) const
Returns the number of fired pixels of the n_th element.
bool isGroup(int n) const
Returns true if the element corresponds to a group of rare topologies.
float getErr2Z(int n) const
Returns the error^2 on the z position of the COG for the n_th element.
GLint GLenum GLboolean GLsizei stride
GLenum GLuint GLint GLint layer
GLubyte GLubyte GLubyte GLubyte w
GLdouble GLdouble GLdouble z
void deepVectorClear(std::vector< T > &vec)
std::pmr::vector< T > bounded_vector
constexpr float DefClusError2Col
constexpr float DefClusError2Row
constexpr float DefClusErrorRow
constexpr float DefClusErrorCol
void clearResizeBoundedVector(bounded_vector< T > &vec, size_t sz, std::pmr::memory_resource *mr=nullptr, T def=T())
void prepareClusters(const TrackingParameters &trkParam, const int maxLayers=NLayers)
void setMemoryPool(std::shared_ptr< BoundedMemoryResource > pool)
memory management
void printArtefactsMemory() const
void setFrameworkAllocator(ExternalAllocator *ext)
void prepareROFrameData(gsl::span< const itsmft::CompClusterExt > clusters, int layer)
void computeTrackletsPerROFScans()
void addPrimaryVertex(const Vertex &vertex)
void loadROFrameData(gsl::span< const o2::itsmft::ROFRecord > rofs, gsl::span< const itsmft::CompClusterExt > clusters, gsl::span< const unsigned char >::iterator &pattIt, const itsmft::TopologyDictionary *dict, int layer, const dataformats::MCTruthContainer< MCCompLabel > *mcLabels=nullptr)
void resetROFrameData(int iLayer)
void initialise(const int iteration, const TrackingParameters &trkParam, const int maxLayers=NLayers, bool resetVertices=true)
unsigned long getArtefactsMemory() const
std::vector< float > LayerRadii
std::vector< float > SystErrorY2
std::vector< float > SystErrorZ2
float TrackletMinPt
Trackleting cuts.
std::vector< float > LayerResolution
std::vector< float > LayerxX0
int CellsPerRoad() const noexcept
int TrackletsPerRoad() const noexcept
std::vector< o2::ctf::BufferType > vec
std::vector< Cluster > clusters
std::vector< Cell > cells