|
34 | 34 | #include "Framework/DataProcessorSpec.h" |
35 | 35 | #include "Framework/Logger.h" |
36 | 36 | #include "ITSMFTTracking/Tracker.h" |
37 | | -#include "ITSMFTTracking/GenericTrackOutputAdapter.h" |
| 37 | +#include "ITSMFTTracking/TrackPublicationHelpers.h" |
38 | 38 | #include "ITSMFTTracking/IOUtils.h" |
39 | 39 | #include "ITSMFTTracking/SurfaceTiming.h" |
40 | 40 | #include "ITSMFTTracking/ITSMFTDetectorDefinitions.h" |
@@ -69,6 +69,153 @@ constexpr std::array<LayerId, NLayers> detectorLocalToLayoutLayers() |
69 | 69 |
|
70 | 70 | inline constexpr auto kLayerToLayout = detectorLocalToLayoutLayers<MFTNLayers>(); |
71 | 71 |
|
| 72 | +struct TrackOutput { |
| 73 | + std::vector<o2::mft::TrackMFT> tracks; |
| 74 | + std::vector<int> clusterIndices; |
| 75 | + std::vector<o2::itsmft::ROFRecord> trackROFs; |
| 76 | + std::vector<uint16_t> seedPatterns; |
| 77 | + std::vector<o2::MCCompLabel> labels; |
| 78 | +}; |
| 79 | + |
| 80 | +bool exportTrackState(const SurfaceTrackState& source, o2::track::TrackParCovFwd& destination) noexcept |
| 81 | +{ |
| 82 | + if (source.kind != SurfaceKind::Disk) { |
| 83 | + return false; |
| 84 | + } |
| 85 | + o2::track::SMatrix5 parameters{}; |
| 86 | + o2::track::SMatrix55Sym covariance{}; |
| 87 | + for (uint8_t i = 0; i < 5; ++i) { |
| 88 | + if (!o2::gpu::GPUCommonMath::Finite(source.parameters[i])) { |
| 89 | + return false; |
| 90 | + } |
| 91 | + parameters[i] = source.parameters[i]; |
| 92 | + } |
| 93 | + for (uint8_t row = 0; row < 5; ++row) { |
| 94 | + for (uint8_t column = 0; column <= row; ++column) { |
| 95 | + const auto value = source.covariance[packedCovarianceIndex(row, column)]; |
| 96 | + if (!o2::gpu::GPUCommonMath::Finite(value)) { |
| 97 | + return false; |
| 98 | + } |
| 99 | + covariance(row, column) = value; |
| 100 | + } |
| 101 | + } |
| 102 | + if (!o2::gpu::GPUCommonMath::Finite(source.referenceCoordinate)) { |
| 103 | + return false; |
| 104 | + } |
| 105 | + destination = o2::track::TrackParCovFwd{source.referenceCoordinate, parameters, covariance, 0.}; |
| 106 | + return true; |
| 107 | +} |
| 108 | + |
| 109 | +bool collectReferences(const TimeFrame& frame, const GenericTrack& common, std::vector<int>& outputIndices, o2::mft::TrackMFT& output, |
| 110 | + uint32_t& pattern, |
| 111 | + const std::vector<std::vector<uint32_t>>* externalIndicesBySurface, |
| 112 | + const std::vector<std::vector<uint32_t>>* clusterSizesBySurface) |
| 113 | +{ |
| 114 | + constexpr uint32_t maxLayers = MFTNLayers; |
| 115 | + const auto& layerMapping = kLayerToLayout; |
| 116 | + const auto& references = frame.getTrackClusterIndices(); |
| 117 | + std::array<const TrackClusterReference*, maxLayers> byLayer{}; |
| 118 | + for (uint32_t ref = common.firstClusterRef; ref < common.clusterRefEnd; ++ref) { |
| 119 | + const auto& key = references[ref]; |
| 120 | + if (!key.isValid()) { |
| 121 | + return false; |
| 122 | + } |
| 123 | + const auto where = std::find(layerMapping.begin(), layerMapping.end(), key.layer); |
| 124 | + if (where == layerMapping.end() || static_cast<uint32_t>(where - layerMapping.begin()) >= maxLayers) { |
| 125 | + return false; |
| 126 | + } |
| 127 | + const auto layer = static_cast<uint32_t>(where - layerMapping.begin()); |
| 128 | + if (byLayer[layer] != nullptr) { |
| 129 | + return false; |
| 130 | + } |
| 131 | + byLayer[layer] = &key; |
| 132 | + } |
| 133 | + const int first = static_cast<int>(outputIndices.size()); |
| 134 | + uint32_t count = 0; |
| 135 | + for (uint32_t layer = maxLayers; layer-- > 0;) { |
| 136 | + const auto* reference = byLayer[layer]; |
| 137 | + if (reference == nullptr) { |
| 138 | + continue; |
| 139 | + } |
| 140 | + uint32_t externalIndex = reference->clusterId; |
| 141 | + if (externalIndicesBySurface != nullptr) { |
| 142 | + if (reference->layer.value() >= externalIndicesBySurface->size() || |
| 143 | + reference->clusterId >= (*externalIndicesBySurface)[reference->layer.value()].size()) { |
| 144 | + return false; |
| 145 | + } |
| 146 | + externalIndex = (*externalIndicesBySurface)[reference->layer.value()][reference->clusterId]; |
| 147 | + } |
| 148 | + if (externalIndex > static_cast<uint32_t>(std::numeric_limits<int>::max())) { |
| 149 | + return false; |
| 150 | + } |
| 151 | + if (clusterSizesBySurface == nullptr || |
| 152 | + reference->layer.value() >= clusterSizesBySurface->size() || |
| 153 | + reference->clusterId >= (*clusterSizesBySurface)[reference->layer.value()].size()) { |
| 154 | + return false; |
| 155 | + } |
| 156 | + outputIndices.push_back(static_cast<int>(externalIndex)); |
| 157 | + output.setClusterSize(layer, (*clusterSizesBySurface)[reference->layer.value()][reference->clusterId]); |
| 158 | + pattern |= 1u << layer; |
| 159 | + ++count; |
| 160 | + } |
| 161 | + output.setExternalClusterIndexOffset(first); |
| 162 | + output.setNumberOfPoints(static_cast<int>(count)); |
| 163 | + return true; |
| 164 | +} |
| 165 | + |
| 166 | +std::optional<TrackOutput> stageTrackOutput(const TimeFrame& frame, |
| 167 | + const TrackPublicationTimingContext& context, |
| 168 | + bool withMC, |
| 169 | + const std::vector<std::vector<uint32_t>>* externalIndicesBySurface = nullptr, |
| 170 | + const std::vector<std::vector<uint32_t>>* clusterSizesBySurface = nullptr) |
| 171 | +{ |
| 172 | + const auto selection = selectGenericTracksForSurfaces(frame, kLayerToLayout); |
| 173 | + if (!selection) |
| 174 | + return std::nullopt; |
| 175 | + if (withMC && frame.getTrackLabels().size() != frame.getGenericTracks().size()) { |
| 176 | + return std::nullopt; |
| 177 | + } |
| 178 | + const auto ordered = makeLegacyOutputOrder(frame, *selection, context.clock); |
| 179 | + if (!ordered) { |
| 180 | + return std::nullopt; |
| 181 | + } |
| 182 | + TrackOutput staged; |
| 183 | + staged.trackROFs.assign(context.inputROFs.begin(), context.inputROFs.end()); |
| 184 | + staged.tracks.reserve(ordered->size()); |
| 185 | + staged.seedPatterns.reserve(ordered->size()); |
| 186 | + std::vector<o2::its::TimeStamp> times; |
| 187 | + times.reserve(ordered->size()); |
| 188 | + for (const auto& orderedTrack : *ordered) { |
| 189 | + const auto index = orderedTrack.globalIndex; |
| 190 | + const auto& common = frame.getGenericTracks()[index]; |
| 191 | + o2::track::TrackParCovFwd inner, outer; |
| 192 | + if (!exportTrackState(common.innerState, inner) || !exportTrackState(common.outerState, outer)) { |
| 193 | + return std::nullopt; |
| 194 | + } |
| 195 | + // Preserve the legacy TrackMFT object shape without claiming a seed-pT |
| 196 | + // estimate from this tracker. TrackMFT does not initialize mInvQPtSeed. |
| 197 | + outer.setTrackChi2(0.f); |
| 198 | + o2::mft::TrackMFT output; |
| 199 | + static_cast<o2::track::TrackParCovFwd&>(output) = inner; |
| 200 | + output.setOutParam(outer); |
| 201 | + output.setTrackChi2(common.chi2); |
| 202 | + output.setCA(true); |
| 203 | + output.setInvQPtSeed(0.); |
| 204 | + output.setChi2QPtSeed(0.); |
| 205 | + uint32_t pattern = 0; |
| 206 | + if (!collectReferences(frame, common, staged.clusterIndices, output, pattern, |
| 207 | + externalIndicesBySurface, clusterSizesBySurface)) |
| 208 | + return std::nullopt; |
| 209 | + staged.tracks.push_back(std::move(output)); |
| 210 | + staged.seedPatterns.push_back(static_cast<uint16_t>(pattern)); |
| 211 | + times.push_back(orderedTrack.timestamp); |
| 212 | + if (withMC) |
| 213 | + staged.labels.push_back(frame.getTrackLabels()[index]); |
| 214 | + } |
| 215 | + finalizeROFs(staged.trackROFs, times, context); |
| 216 | + return staged; |
| 217 | +} |
| 218 | + |
72 | 219 | bool rofOverlapsIRFrames(const o2::itsmft::ROFRecord& rof, int rofLengthInBC, |
73 | 220 | gsl::span<const o2::dataformats::IRFrame> irFrames) |
74 | 221 | { |
@@ -219,12 +366,10 @@ void CATrackerDPL::run(ProcessingContext& pc) |
219 | 366 |
|
220 | 367 | { |
221 | 368 | mSession.publicationClock.emplace(mSession.overlap.getView().getClockLayer()); |
222 | | - const o2::itsmft::tracking::GenericTrackPublicationContext context{ |
223 | | - o2::detectors::DetID::MFT, o2::itsmft::tracking::ClusterSourceId{0}, |
224 | | - gsl::span<const o2::itsmft::ROFRecord>{rofsinput.data(), rofsinput.size()}, *mSession.publicationClock, |
225 | | - kLayerToLayout, |
226 | | - &mSession.externalIndices, &mSession.clusterSizes}; |
227 | | - const auto staged = o2::itsmft::tracking::stageMFTGenericTrackOutput(mSession.frame, context, mUseMC); |
| 369 | + const o2::itsmft::tracking::TrackPublicationTimingContext context{ |
| 370 | + gsl::span<const o2::itsmft::ROFRecord>{rofsinput.data(), rofsinput.size()}, *mSession.publicationClock}; |
| 371 | + const auto staged = stageTrackOutput(mSession.frame, context, mUseMC, |
| 372 | + &mSession.externalIndices, &mSession.clusterSizes); |
228 | 373 | if (!staged) { |
229 | 374 | throw std::runtime_error{"MFT GenericTrack output staging failed"}; |
230 | 375 | } |
|
0 commit comments