|
| 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 | + |
| 12 | +/// \file ClustererACTS.cxx |
| 13 | +/// \brief Implementation of the TRK cluster finder with the ACTS |
| 14 | + |
| 15 | +#include "TRKReconstruction/ClustererACTS.h" |
| 16 | +#include "TRKBase/GeometryTGeo.h" |
| 17 | +#include <Acts/Clusterization/Clusterization.hpp> |
| 18 | + |
| 19 | +#include <algorithm> |
| 20 | +#include <numeric> |
| 21 | + |
| 22 | +using namespace o2::trk; |
| 23 | + |
| 24 | +struct Cell2D { |
| 25 | + Cell2D(int rowv, int colv) : row(rowv), col(colv) {} |
| 26 | + int row, col; |
| 27 | + Acts::Ccl::Label label{Acts::Ccl::NO_LABEL}; |
| 28 | +}; |
| 29 | + |
| 30 | +struct Cluster2D { |
| 31 | + std::vector<Cell2D> cells; |
| 32 | + std::size_t hash{0}; |
| 33 | +}; |
| 34 | + |
| 35 | +//__________________________________________________ |
| 36 | +void ClustererACTS::process(gsl::span<const Digit> digits, |
| 37 | + gsl::span<const DigROFRecord> digitROFs, |
| 38 | + std::vector<o2::trk::Cluster>& clusters, |
| 39 | + std::vector<unsigned char>& patterns, |
| 40 | + std::vector<o2::trk::ROFRecord>& clusterROFs, |
| 41 | + const ConstDigitTruth* digitLabels, |
| 42 | + ClusterTruth* clusterLabels, |
| 43 | + gsl::span<const DigMC2ROFRecord> digMC2ROFs, |
| 44 | + std::vector<o2::trk::MC2ROFRecord>* clusterMC2ROFs) |
| 45 | +{ |
| 46 | + if (!mThread) { |
| 47 | + mThread = std::make_unique<ClustererThread>(this); |
| 48 | + } |
| 49 | + |
| 50 | + auto* geom = o2::trk::GeometryTGeo::Instance(); |
| 51 | + |
| 52 | + for (size_t iROF = 0; iROF < digitROFs.size(); ++iROF) { |
| 53 | + const auto& inROF = digitROFs[iROF]; |
| 54 | + const auto outFirst = static_cast<int>(clusters.size()); |
| 55 | + const int first = inROF.getFirstEntry(); |
| 56 | + const int nEntries = inROF.getNEntries(); |
| 57 | + |
| 58 | + if (nEntries == 0) { |
| 59 | + clusterROFs.emplace_back(inROF.getBCData(), inROF.getROFrame(), outFirst, 0); |
| 60 | + continue; |
| 61 | + } |
| 62 | + |
| 63 | + // template <typename CellCollection, typename ClusterCollection, |
| 64 | + // std::size_t GridDim = 2, |
| 65 | + // typename Connect = DefaultConnect<typename CellCollection::value_type, GridDim>> |
| 66 | + // requires(GridDim == 1 || GridDim == 2) |
| 67 | + // void createClusters(Acts::Ccl::ClusteringData& data, |
| 68 | + // CellCollection& cells, |
| 69 | + // ClusterCollection& clusters, |
| 70 | + // Connect&& connect = Connect()); |
| 71 | + using Cell = Cell2D; |
| 72 | + using CellCollection = std::vector<Cell>; |
| 73 | + using Cluster = Cluster2D; |
| 74 | + using ClusterCollection = std::vector<Cluster>; |
| 75 | + CellCollection cells; |
| 76 | + Acts::Ccl::ClusteringData data; |
| 77 | + ClusterCollection collection; |
| 78 | + |
| 79 | + Acts::Ccl::createClusters<CellCollection, ClusterCollection, |
| 80 | + 2>(data, cells, collection, Acts::Ccl::DefaultConnect<Cell, 2>(false)); |
| 81 | + |
| 82 | + // Sort digit indices within this ROF by (chipID, col, row) so we can process |
| 83 | + // chip by chip, column by column -- the same ordering the ALPIDE scanner expects. |
| 84 | + mSortIdx.resize(nEntries); |
| 85 | + std::iota(mSortIdx.begin(), mSortIdx.end(), first); |
| 86 | + std::sort(mSortIdx.begin(), mSortIdx.end(), [&digits](int a, int b) { |
| 87 | + const auto& da = digits[a]; |
| 88 | + const auto& db = digits[b]; |
| 89 | + if (da.getChipIndex() != db.getChipIndex()) { |
| 90 | + return da.getChipIndex() < db.getChipIndex(); |
| 91 | + } |
| 92 | + if (da.getColumn() != db.getColumn()) { |
| 93 | + return da.getColumn() < db.getColumn(); |
| 94 | + } |
| 95 | + return da.getRow() < db.getRow(); |
| 96 | + }); |
| 97 | + |
| 98 | + // Process one chip at a time |
| 99 | + int sliceStart = 0; |
| 100 | + while (sliceStart < nEntries) { |
| 101 | + const int chipFirst = sliceStart; |
| 102 | + const uint16_t chipID = digits[mSortIdx[sliceStart]].getChipIndex(); |
| 103 | + while (sliceStart < nEntries && digits[mSortIdx[sliceStart]].getChipIndex() == chipID) { |
| 104 | + ++sliceStart; |
| 105 | + } |
| 106 | + const int chipN = sliceStart - chipFirst; |
| 107 | + |
| 108 | + mThread->processChip(digits, chipFirst, chipN, &clusters, &patterns, digitLabels, clusterLabels, geom); |
| 109 | + } |
| 110 | + |
| 111 | + clusterROFs.emplace_back(inROF.getBCData(), inROF.getROFrame(), |
| 112 | + outFirst, static_cast<int>(clusters.size()) - outFirst); |
| 113 | + } |
| 114 | + |
| 115 | + if (clusterMC2ROFs && !digMC2ROFs.empty()) { |
| 116 | + clusterMC2ROFs->reserve(clusterMC2ROFs->size() + digMC2ROFs.size()); |
| 117 | + for (const auto& in : digMC2ROFs) { |
| 118 | + clusterMC2ROFs->emplace_back(in.eventRecordID, in.rofRecordID, in.minROF, in.maxROF); |
| 119 | + } |
| 120 | + } |
| 121 | +} |
0 commit comments