Project
Loading...
Searching...
No Matches
CombinedTrackingTestSupport.h
Go to the documentation of this file.
1// Copyright 2019-2020 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#ifndef ALICEO2_ITSMFT_TRACKING_TEST_COMBINEDTRACKINGTESTSUPPORT_H_
13#define ALICEO2_ITSMFT_TRACKING_TEST_COMBINEDTRACKINGTESTSUPPORT_H_
14
16#include <algorithm>
17#include <array>
18#include <cstdint>
19#include <memory>
20#include <optional>
21#include <stdexcept>
22#include <utility>
23#include <vector>
24
33
35{
36
37inline constexpr auto CombinedSurfaceCatalog = [] {
38 std::array<SurfaceDescriptor, ITSNLayers + MFTNLayers> surfaces{};
39 auto output = std::copy(kITSSurfaces.begin(), kITSSurfaces.end(), surfaces.begin());
40 std::copy(kMFTSurfaces.begin(), kMFTSurfaces.end(), output);
41 return surfaces;
42}();
43
45{
46 return {CombinedSurfaceCatalog.data(), static_cast<uint32_t>(CombinedSurfaceCatalog.size())};
47}
48
49inline std::vector<LayerId> orderedSurfaceRange(uint16_t first, uint16_t count)
50{
51 std::vector<LayerId> result;
52 result.reserve(count);
53 for (uint16_t i = 0; i < count; ++i) {
54 result.push_back(LayerId{static_cast<uint16_t>(first + i)});
55 }
56 return result;
57}
58
60 const TrackingParameters& mftParams)
61{
62 const std::vector<uint16_t> componentOffsets = {0, ITSNLayers};
63 const auto combine = [&] {
64 auto parameters = itsParams;
65 parameters.NLayers = ITSNLayers + MFTNLayers;
66 const auto concatenate = [](auto& output, const auto& prefix, const auto& suffix) {
67 output = prefix;
68 output.insert(output.end(), suffix.begin(), suffix.end());
69 };
70 concatenate(parameters.AddTimeError, itsParams.AddTimeError, mftParams.AddTimeError);
71 concatenate(parameters.LayerResolution, itsParams.LayerResolution, mftParams.LayerResolution);
72 concatenate(parameters.SystError2Row, itsParams.SystError2Row, mftParams.SystError2Row);
73 concatenate(parameters.SystError2Col, itsParams.SystError2Col, mftParams.SystError2Col);
74 const auto configuredSeedingLayers = [](const auto& input) {
75 return input.SeedingLayers.empty() ? LayerMask::span(0, input.NLayers - 1) : input.SeedingLayers;
76 };
77 parameters.InactiveLayerMask = itsParams.InactiveLayerMask.value() |
78 (mftParams.InactiveLayerMask.value() << itsParams.NLayers);
79 parameters.SeedingLayers = configuredSeedingLayers(itsParams).value() |
80 (configuredSeedingLayers(mftParams).value() << itsParams.NLayers);
81 parameters.StartLayerMask = LayerMask{(uint32_t{1} << (ITSNLayers + MFTNLayers)) - 1u};
82 return parameters;
83 };
84 return {combinedCatalogView(), componentOffsets, {}, makeTrackingPlan(combine()), std::make_shared<BoundedMemoryResource>()};
85}
86
88{
89 public:
90 CombinedTrackingPlan(std::vector<TrackingParameters> itsParams, std::vector<TrackingParameters> mftParams)
91 {
92 if (itsParams.size() != 1 || mftParams.size() != 1) {
93 throw std::invalid_argument{"combined test application plan requires one iteration per detector"};
94 }
95
96 mConfiguration = makeCombinedConfiguration(itsParams[0], mftParams[0]);
97 mTracker = std::make_unique<Tracker>();
98 mTraits = std::make_unique<TrackerTraits>();
99 }
100
103
105 {
106 mFrame = &frame;
107 if (!mTracker->initialize(frame, mConfiguration)) {
108 throw std::runtime_error{"combined test application plan failed to configure the TimeFrame"};
109 }
110 }
111 void setBz(float bz)
112 {
113 mFrame->setBz(bz);
114 }
115 void setNThreads(int n)
116 {
117 mTraits->setNThreads(n, mArena);
118 }
119
120 Tracker& itsTracker() noexcept { return *mTracker; }
121 Tracker& mftTracker() noexcept { return *mTracker; }
122 bool runITS()
123 {
124 auto result = mTracker->run(*mFrame, *mTraits);
125 mLastResult = result;
126 if (result) {
127 const auto& statistics = mTracker->getRunStatistics();
128 const auto configurations = mTracker->getIterationConfigurations();
129 std::size_t firstTrack = 0;
130 for (std::size_t i = 0; i < configurations.size(); ++i) {
131 if (i >= statistics.acceptedTrackCounts.size() ||
132 statistics.acceptedTrackCounts[i] > mFrame->getGenericTracks().size() - firstTrack) {
133 throw std::runtime_error{"failed to prepare ITS shared-cluster flags"};
134 }
135 std::vector<uint32_t> selected;
136 for (std::size_t index = 0; index < statistics.acceptedTrackCounts[i]; ++index) {
137 const auto globalIndex = firstTrack + index;
138 if (mFrame->getGenericTracks()[globalIndex].innerState.kind == SurfaceKind::Cylinder) {
139 selected.push_back(static_cast<uint32_t>(globalIndex));
140 }
141 }
142 if (!mITSPublicationAdapter.completeAccepted(
143 selected, configurations[i].parameters, *mFrame, i + 1 == configurations.size())) {
144 throw std::runtime_error{"failed to prepare ITS shared-cluster flags"};
145 }
146 firstTrack += statistics.acceptedTrackCounts[i];
147 }
148 } else {
149 mITSPublicationAdapter.reset();
150 }
151 return result;
152 }
153 bool runMFT()
154 {
155 if (!mLastResult) {
156 runITS();
157 }
158 auto result = *mLastResult;
159 return result;
160 }
161 RuntimeROFViews getITSROFViews() const noexcept { return {mITSROFOverlapTable.getView(), mITSROFVertexLookupTable.getView(), mITSMultiplicityMask.getView(), mITSUPCMask.getView()}; }
162 RuntimeROFViews getMFTROFViews() const noexcept { return {mMFTROFOverlapTable.getView(), mMFTROFVertexLookupTable.getView(), mMFTMultiplicityMask.getView(), mMFTUPCMask.getView()}; }
164 {
165 mITSPublicationAdapter.reset();
166 mLastResult.reset();
167 }
168
169 void validateSources(const ClusterSourceInput& itsSource,
170 const ClusterSourceInput& mftSource) const
171 {
172 if (itsSource.id != ClusterSourceId{0} || itsSource.detector != o2::detectors::DetID::ITS) {
173 throw std::runtime_error("Invalid ITS source");
174 }
175 if (mftSource.id != ClusterSourceId{1} || mftSource.detector != o2::detectors::DetID::MFT) {
176 throw std::runtime_error("Invalid MFT source");
177 }
178 }
179
181 void configureRofTables(const TestClusterSourceInput& itsSource, const TestClusterSourceInput& mftSource)
182 {
183 auto configure = [](auto& overlap, auto& vertex, auto& mask, const auto& timing, uint32_t nROFs, int layers) {
184 o2::its::LayerTiming layerTiming{};
185 layerTiming.mNROFsTF = nROFs;
186 layerTiming.mROFLength = timing.mROFLength;
187 layerTiming.mROFDelay = timing.mROFDelay;
188 layerTiming.mROFBias = timing.mROFBias;
189 layerTiming.mROFAddTimeErr = timing.mROFAddTimeErr;
190 for (int layer = 0; layer < layers; ++layer) {
191 overlap.defineLayer(layer, layerTiming);
192 vertex.defineLayer(layer, layerTiming);
193 }
194 overlap.init();
195 vertex.init();
196 mask = std::remove_cvref_t<decltype(mask)>{overlap};
197 mask.resetMask();
198 for (int layer = 0; layer < layers; ++layer) {
199 mask.setROFsEnabled(layer, 0, static_cast<int>(nROFs), 1);
200 }
201 };
202 configure(mITSROFOverlapTable, mITSROFVertexLookupTable, mITSMultiplicityMask, itsSource.timing, static_cast<uint32_t>(itsSource.rofs.size()), ITSNLayers);
203 configure(mMFTROFOverlapTable, mMFTROFVertexLookupTable, mMFTMultiplicityMask, mftSource.timing, static_cast<uint32_t>(mftSource.rofs.size()), MFTNLayers);
204 }
205
206 const TimeFrameScratch& getITSScratch() const noexcept { return mFrame->getScratch(); }
207 const TimeFrameScratch& getMFTScratch() const noexcept { return mFrame->getScratch(); }
208 gsl::span<const LayerId> getITSLayerMapping() const noexcept { return mITSLayerMapping; }
209 gsl::span<const LayerId> getMFTLayerMapping() const noexcept { return mMFTLayerMapping; }
210 gsl::span<const uint8_t> getITSSharedClusterFlags() const noexcept
211 {
212 return mITSPublicationAdapter.sharedClusterFlags();
213 }
215 {
216 const auto* configuration = mTracker == nullptr ? nullptr : mTracker->getIterationConfiguration(0);
217 return mFrame != nullptr && configuration != nullptr && mTracker->isConfiguredFor(*mFrame)
218 ? configuration->getTopologyView(mFrame->getDetectorConfiguration().getSurfaceCatalog())
220 }
222
223 private:
224 const std::vector<LayerId> mITSLayerMapping = orderedSurfaceRange(0, ITSNLayers);
225 const std::vector<LayerId> mMFTLayerMapping = orderedSurfaceRange(ITSNLayers, MFTNLayers);
226 TrackerInitialization mConfiguration;
227 TimeFrame* mFrame = nullptr;
228 std::unique_ptr<Tracker> mTracker;
229 std::unique_ptr<TrackerTraits> mTraits;
230 std::optional<bool> mLastResult;
231 o2::its::ca::PublicationAdapter mITSPublicationAdapter;
232 o2::its::ROFOverlapTable<ITSNLayers> mITSROFOverlapTable;
233 o2::its::ROFVertexLookupTable<ITSNLayers> mITSROFVertexLookupTable;
234 o2::its::ROFMaskTable<ITSNLayers> mITSMultiplicityMask;
236 o2::its::ROFOverlapTable<MFTNLayers> mMFTROFOverlapTable;
237 o2::its::ROFVertexLookupTable<MFTNLayers> mMFTROFVertexLookupTable;
238 o2::its::ROFMaskTable<MFTNLayers> mMFTMultiplicityMask;
240 std::shared_ptr<tbb::task_arena> mArena;
241};
242
243} // namespace o2::itsmft::tracking::test
244
245#endif // ALICEO2_ITSMFT_TRACKING_TEST_COMBINEDTRACKINGTESTSUPPORT_H_
Shared CA tracking configuration for ITS and MFT.
Passive common TimeFrame owner.
uint64_t vertex
Definition RawEventData.h:9
int32_t i
Shared cluster I/O utilities for ITS and MFT (based on ITStracking/IOUtils.h)
Tracker orchestrator.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
gsl::span< const uint8_t > sharedClusterFlags() const noexcept
bool completeAccepted(gsl::span< const uint32_t > trackIndices, const o2::itsmft::IterationParameters &params, const o2::itsmft::tracking::TimeFrame &frame, bool final)
SurfaceCatalogView getSurfaceCatalog() const noexcept
TraversalTopologyView getITSLayoutView() const noexcept
CombinedTrackingPlan(std::vector< TrackingParameters > itsParams, std::vector< TrackingParameters > mftParams)
CombinedTrackingPlan & operator=(const CombinedTrackingPlan &)=delete
TraversalTopologyView getMFTLayoutView() const noexcept
void configureRofTables(const TestClusterSourceInput &itsSource, const TestClusterSourceInput &mftSource)
const TimeFrameScratch & getITSScratch() const noexcept
gsl::span< const LayerId > getITSLayerMapping() const noexcept
gsl::span< const uint8_t > getITSSharedClusterFlags() const noexcept
gsl::span< const LayerId > getMFTLayerMapping() const noexcept
void validateSources(const ClusterSourceInput &itsSource, const ClusterSourceInput &mftSource) const
CombinedTrackingPlan(const CombinedTrackingPlan &)=delete
const TimeFrameScratch & getMFTScratch() const noexcept
Shared CA tracker traits: same ITS-style tracklet/cell/road logic; MFT uses x-y LUT and forward refit...
GLdouble n
Definition glcorearb.h:1982
GLint GLsizei count
Definition glcorearb.h:399
GLuint64EXT * result
Definition glcorearb.h:5662
GLuint index
Definition glcorearb.h:781
GLint first
Definition glcorearb.h:399
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLint GLuint mask
Definition glcorearb.h:291
std::vector< LayerId > orderedSurfaceRange(uint16_t first, uint16_t count)
TrackingPlan makeTrackingPlan(const TrackingParameters &parameters)
TrackerInitialization makeCombinedConfiguration(const TrackingParameters &itsParams, const TrackingParameters &mftParams)
uint32_t trackClusterIndicesSize noexcept
constexpr std::array< SurfaceDescriptor, MFTNLayers > kMFTSurfaces
constexpr int MFTNLayers
MFT CA half-disk layer count.
constexpr std::array< SurfaceDescriptor, ITSNLayers > kITSSurfaces
constexpr int ITSNLayers
ITS CA layer count.
std::vector< uint32_t > AddTimeError
std::vector< float > SystError2Col
std::vector< float > SystError2Row
std::vector< float > LayerResolution
tracking::LayerMask InactiveLayerMask
o2::detectors::DetID::ID detector
Definition IOUtils.h:120
gsl::span< const o2::itsmft::ROFRecord > rofs
Definition IOUtils.h:123
const DetectorConfiguration & getDetectorConfiguration() const noexcept
Definition TimeFrame.h:157
TimeFrameScratch & getScratch()