Skip to content

Commit 7606e68

Browse files
committed
ITS: tracking same as dev
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent a4501d5 commit 7606e68

File tree

11 files changed

+147
-93
lines changed

11 files changed

+147
-93
lines changed

DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TimeEstBC.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,6 @@ class TimeEstBC : public o2::dataformats::TimeStampWithError<TimeStampType, Time
5252
return res;
5353
}
5454

55-
private:
56-
// add the other timestmap to this one
57-
// this assumes already that both overlap
58-
GPUhdi() void add(const TimeEstBC& o) noexcept
59-
{
60-
const TimeStampType lo = o2::gpu::CAMath::Max(lower(), o.lower());
61-
const TimeStampType hi = o2::gpu::CAMath::Min(upper(), o.upper());
62-
const TimeStampType half = (hi - lo) / 2u;
63-
this->setTimeStamp(lo + half);
64-
this->setTimeStampError(static_cast<TimeStampErrorType>(half));
65-
}
66-
6755
GPUhdi() TimeStampType upper() const noexcept
6856
{
6957
TimeStampType t = this->getTimeStamp();
@@ -79,8 +67,20 @@ class TimeEstBC : public o2::dataformats::TimeStampWithError<TimeStampType, Time
7967
return (t > e) ? (t - e) : 0u;
8068
}
8169

70+
private:
71+
// add the other timestmap to this one
72+
// this assumes already that both overlap
73+
GPUhdi() void add(const TimeEstBC& o) noexcept
74+
{
75+
const TimeStampType lo = o2::gpu::CAMath::Max(lower(), o.lower());
76+
const TimeStampType hi = o2::gpu::CAMath::Min(upper(), o.upper());
77+
const TimeStampType half = (hi - lo) / 2u;
78+
this->setTimeStamp(lo + half);
79+
this->setTimeStampError(static_cast<TimeStampErrorType>(half));
80+
}
81+
8282
ClassDefNV(TimeEstBC, 1);
8383
};
8484
} // namespace o2::its
8585

86-
#endif
86+
#endif

DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TrackITS.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
1+
// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
22
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
33
// All rights not expressly granted are reserved.
44
//
@@ -21,7 +21,7 @@
2121
#include "GPUCommonDef.h"
2222
#include "ReconstructionDataFormats/Track.h"
2323
#include "CommonDataFormat/RangeReference.h"
24-
#include "CommonDataFormat/TimeStamp.h"
24+
#include "DataFormatsITS/TimeEstBC.h"
2525

2626
namespace o2
2727
{
@@ -41,7 +41,6 @@ class TrackITS : public o2::track::TrackParCov
4141

4242
using Cluster = o2::itsmft::Cluster;
4343
using ClusRefs = o2::dataformats::RangeRefComp<4>;
44-
using Timestamp = o2::dataformats::TimeStampWithError<uint32_t, uint16_t>;
4544

4645
public:
4746
using o2::track::TrackParCov::TrackParCov; // inherit base constructors
@@ -160,7 +159,7 @@ class TrackITS : public o2::track::TrackParCov
160159
float mChi2 = 0.; ///< Chi2 for this track
161160
uint32_t mPattern = 0; ///< layers pattern
162161
uint32_t mClusterSizes = 0u; ///< 4bit packed cluster sizes
163-
Timestamp mTime; ///< track time stamp with error in BC since start of TF, symmetrical
162+
TimeEstBC mTime; ///< track time stamp with error in BC since start of TF, symmetrical
164163

165164
ClassDefNV(TrackITS, 7);
166165
};

Detectors/ITSMFT/ITS/tracking/include/ITStracking/ROFLookupTables.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <limits>
1818
#include <format>
1919
#include <string>
20-
#include <numeric>
2120
#include <vector>
2221

2322
#include "CommonConstants/LHCConstants.h"
@@ -33,7 +32,7 @@ namespace o2::its
3332

3433
// Layer timing definition
3534
struct LayerTiming {
36-
using BCType = uint32_t;
35+
using BCType = TimeStampType;
3736
BCType mNROFsTF{0}; // number of ROFs per timeframe
3837
BCType mROFLength{0}; // ROF length in BC
3938
BCType mROFDelay{0}; // delay of ROFs wrt start of first orbit in TF in BC
@@ -69,7 +68,14 @@ struct LayerTiming {
6968
}
7069
const BCType start = getROFStartInBC(rofId);
7170
const BCType half = mROFLength / BCType(2);
72-
return {start + half, static_cast<uint16_t>(half)};
71+
return {start + half, static_cast<TimeStampErrorType>(half)};
72+
}
73+
74+
// return which ROF this BC belongs to
75+
GPUhi() BCType getROF(BCType bc) const noexcept
76+
{
77+
BCType rof = (bc - mROFDelay - mROFBias) / mROFLength;
78+
return rof >= 0 ? rof : 0;
7379
}
7480

7581
GPUh() std::string asString() const
@@ -136,7 +142,7 @@ struct ROFOverlapTableView {
136142
return mLayers[layer];
137143
}
138144

139-
GPUh() const LayerTiming& getClockLayer() const noexcept
145+
GPUh() int getClock() const noexcept
140146
{
141147
// we take the fastest layer as clock
142148
int fastest = 0;
@@ -145,10 +151,14 @@ struct ROFOverlapTableView {
145151
const auto& layer = getLayer(iL);
146152
if (layer.mROFLength < shortestROF) {
147153
fastest = iL;
148-
shortestROF = layer.mROFLength;
149154
}
150155
}
151-
return mLayers[fastest];
156+
return fastest;
157+
}
158+
159+
GPUh() const LayerTiming& getClockLayer() const noexcept
160+
{
161+
return mLayers[getClock()];
152162
}
153163

154164
GPUhdi() const TableEntry& getOverlap(int32_t from, int32_t to, size_t rofIdx) const noexcept
@@ -246,7 +256,7 @@ struct ROFOverlapTableView {
246256
for (int32_t i = 0; i < NLayers; ++i) {
247257
for (int32_t j = 0; j < NLayers; ++j) {
248258
if (i != j) {
249-
const size_t linearIdx = i * NLayers + j;
259+
const size_t linearIdx = (i * NLayers) + j;
250260
const auto& idx = mIndices[linearIdx];
251261
totalEntries += idx.getEntries();
252262
flatTableSize += idx.getEntries();
@@ -580,8 +590,9 @@ class ROFVertexLookupTable : public LayerTimingBase<NLayers>
580590
while (firstVertex < lastVertex) {
581591
int64_t vUpper = (int64_t)vertices[firstVertex].getTimeStamp().getTimeStamp() +
582592
(int64_t)vertices[firstVertex].getTimeStamp().getTimeStampError();
583-
if (vUpper > rofLower)
593+
if (vUpper > rofLower) {
584594
break;
595+
}
585596
++firstVertex;
586597
}
587598
size_t count = (lastVertex > firstVertex) ? (lastVertex - firstVertex) : 0;
@@ -601,8 +612,9 @@ class ROFVertexLookupTable : public LayerTimingBase<NLayers>
601612
while (firstVertex < lastVertex) {
602613
int64_t vUpper = (int64_t)vertices[firstVertex].getTimeStamp().getTimeStamp() +
603614
(int64_t)vertices[firstVertex].getTimeStamp().getTimeStampError();
604-
if (vUpper > rofLower)
615+
if (vUpper > rofLower) {
605616
break;
617+
}
606618
++firstVertex;
607619
}
608620
size_t count = (lastVertex > firstVertex) ? (lastVertex - firstVertex) : 0;

Detectors/ITSMFT/ITS/tracking/src/TimeFrame.cxx

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void TimeFrame<NLayers>::loadROFrameData(gsl::span<const o2::itsmft::ROFRecord>
7373

7474
// check for missing/empty/unset rofs
7575
// the code requires consistent monotonically increasing input without gaps
76-
const auto& timing = mROFOverlapTableView.getLayer(layer);
76+
const auto& timing = mROFOverlapTableView.getLayer(layer >= 0 ? layer : 0);
7777
if (timing.mNROFsTF != rofs.size()) {
7878
LOGP(fatal, "Received inconsistent number of rofs on layer:{} expected:{} received:{}", layer, timing.mNROFsTF, rofs.size());
7979
}
@@ -103,52 +103,82 @@ void TimeFrame<NLayers>::loadROFrameData(gsl::span<const o2::itsmft::ROFRecord>
103103
locXYZ = dict->getClusterCoordinates(c, patt, false);
104104
clusterSize = patt.getNPixels();
105105
}
106-
mClusterSize[layer][clusterId] = std::clamp(clusterSize, 0u, 255u);
106+
mClusterSize[layer >= 0 ? layer : 0][clusterId] = std::clamp(clusterSize, 0u, 255u);
107107
auto sensorID = c.getSensorID();
108108
// Inverse transformation to the local --> tracking
109109
auto trkXYZ = geom->getMatrixT2L(sensorID) ^ locXYZ;
110110
// Transformation to the local --> global
111111
auto gloXYZ = geom->getMatrixL2G(sensorID) * locXYZ;
112-
addTrackingFrameInfoToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), trkXYZ.x(), geom->getSensorRefAlpha(sensorID),
112+
addTrackingFrameInfoToLayer(lay, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), trkXYZ.x(), geom->getSensorRefAlpha(sensorID),
113113
std::array<float, 2>{trkXYZ.y(), trkXYZ.z()},
114114
std::array<float, 3>{sigmaY2, sigmaYZ, sigmaZ2});
115115
/// Rotate to the global frame
116-
addClusterToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), mUnsortedClusters[layer].size());
117-
addClusterExternalIndexToLayer(layer, clusterId);
116+
addClusterToLayer(lay, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), mUnsortedClusters[lay].size());
117+
addClusterExternalIndexToLayer(lay, clusterId);
118+
}
119+
// effectively calculating an exclusive sum
120+
if (layer >= 0) {
121+
mROFramesClusters[layer][iRof + 1] = mUnsortedClusters[layer].size();
122+
} else {
123+
for (unsigned int iL{0}; iL < mUnsortedClusters.size(); ++iL) {
124+
mROFramesClusters[iL][iRof + 1] = mUnsortedClusters[iL].size();
125+
}
118126
}
119-
mROFramesClusters[layer][iRof + 1] = mUnsortedClusters[layer].size(); // effectively calculating an exclusive sum
120127
}
121128

122-
if (layer == 1) {
129+
if (layer == 1 || layer == -1) {
123130
for (auto i = 0; i < mNTrackletsPerCluster.size(); ++i) {
124131
mNTrackletsPerCluster[i].resize(mUnsortedClusters[1].size());
125132
mNTrackletsPerClusterSum[i].resize(mUnsortedClusters[1].size() + 1);
126133
}
127134
}
128135

129136
if (mcLabels != nullptr) {
130-
mClusterLabels[layer] = mcLabels;
137+
mClusterLabels[layer >= 0 ? layer : 0] = mcLabels;
131138
} else {
132-
mClusterLabels[layer] = nullptr;
139+
mClusterLabels[layer >= 0 ? layer : 0] = nullptr;
133140
}
134141
}
135142

136143
template <int NLayers>
137144
void TimeFrame<NLayers>::resetROFrameData(int layer)
138145
{
139-
deepVectorClear(mUnsortedClusters[layer], getMaybeFrameworkHostResource());
140-
deepVectorClear(mTrackingFrameInfo[layer], getMaybeFrameworkHostResource());
141-
deepVectorClear(mClusterExternalIndices[layer], mMemoryPool.get());
142-
clearResizeBoundedVector(mROFramesClusters[layer], mROFOverlapTableView.getLayer(layer).mNROFsTF + 1, getMaybeFrameworkHostResource());
146+
if (layer >= 0) {
147+
deepVectorClear(mUnsortedClusters[layer], getMaybeFrameworkHostResource());
148+
deepVectorClear(mTrackingFrameInfo[layer], getMaybeFrameworkHostResource());
149+
deepVectorClear(mClusterExternalIndices[layer], mMemoryPool.get());
150+
clearResizeBoundedVector(mROFramesClusters[layer], mROFOverlapTableView.getLayer(layer).mNROFsTF + 1, getMaybeFrameworkHostResource());
151+
} else {
152+
for (int iLayer{0}; iLayer < NLayers; ++iLayer) {
153+
deepVectorClear(mUnsortedClusters[iLayer], getMaybeFrameworkHostResource());
154+
deepVectorClear(mTrackingFrameInfo[iLayer], getMaybeFrameworkHostResource());
155+
deepVectorClear(mClusterExternalIndices[iLayer], mMemoryPool.get());
156+
clearResizeBoundedVector(mROFramesClusters[iLayer], mROFOverlapTableView.getLayer(iLayer).mNROFsTF + 1, getMaybeFrameworkHostResource());
157+
}
158+
}
143159
}
144160

145161
template <int NLayers>
146162
void TimeFrame<NLayers>::prepareROFrameData(gsl::span<const itsmft::CompClusterExt> clusters, int layer)
147163
{
148-
mUnsortedClusters[layer].reserve(clusters.size());
149-
mTrackingFrameInfo[layer].reserve(clusters.size());
150-
mClusterExternalIndices[layer].reserve(clusters.size());
151-
clearResizeBoundedVector(mClusterSize[layer], clusters.size(), mMemoryPool.get());
164+
if (layer >= 0) {
165+
mUnsortedClusters[layer].reserve(clusters.size());
166+
mTrackingFrameInfo[layer].reserve(clusters.size());
167+
mClusterExternalIndices[layer].reserve(clusters.size());
168+
clearResizeBoundedVector(mClusterSize[layer], clusters.size(), mMemoryPool.get());
169+
} else {
170+
auto* geom = GeometryTGeo::Instance();
171+
clearResizeBoundedVector(mClusterSize[0], clusters.size(), mMemoryPool.get());
172+
std::array<size_t, NLayers> clusterCountPerLayer{0};
173+
for (const auto& cls : clusters) {
174+
++clusterCountPerLayer[geom->getLayer(cls.getChipID())];
175+
}
176+
for (int iLayer{0}; iLayer < NLayers; ++iLayer) {
177+
mUnsortedClusters[iLayer].reserve(clusterCountPerLayer[iLayer]);
178+
mTrackingFrameInfo[iLayer].reserve(clusterCountPerLayer[iLayer]);
179+
mClusterExternalIndices[iLayer].reserve(clusterCountPerLayer[iLayer]);
180+
}
181+
}
152182
}
153183

154184
template <int NLayers>

Detectors/ITSMFT/ITS/tracking/src/TrackerTraits.cxx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,15 @@ void TrackerTraits<NLayers>::computeLayerCells(const int iteration)
278278
int foundCells{0};
279279
for (int iNextTracklet{nextLayerFirstTrackletIndex}; iNextTracklet < nextLayerLastTrackletIndex; ++iNextTracklet) {
280280
const Tracklet& nextTracklet{mTimeFrame->getTracklets()[iLayer + 1][iNextTracklet]};
281-
const auto& nextLbl = mTimeFrame->getTrackletsLabel(iLayer + 1)[iNextTracklet];
282281
if (mTimeFrame->getTracklets()[iLayer + 1][iNextTracklet].firstClusterIndex != nextLayerClusterIndex) {
283282
break;
284283
}
285284
if (!currentTracklet.getTimeStamp().isCompatible(nextTracklet.getTimeStamp())) {
286285
continue;
287286
}
288-
const float deltaTanLambda{std::abs(currentTracklet.tanLambda - nextTracklet.tanLambda)};
289287

290-
if (deltaTanLambda / mTrkParams[iteration].CellDeltaTanLambdaSigma < mTrkParams[iteration].NSigmaCut) {
288+
const float deltaTanLambdaSigma = std::abs(currentTracklet.tanLambda - nextTracklet.tanLambda) / mTrkParams[iteration].CellDeltaTanLambdaSigma;
289+
if (deltaTanLambdaSigma < mTrkParams[iteration].NSigmaCut) {
291290

292291
/// Track seed preparation. Clusters are numbered progressively from the innermost going outward.
293292
const int clusId[3]{

Detectors/ITSMFT/ITS/tracking/src/TrackingInterface.cxx

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12+
#include <algorithm>
1213
#include <memory>
1314

1415
#include <oneapi/tbb/task_arena.h>
@@ -129,9 +130,9 @@ void ITSTrackingInterface::run(framework::ProcessingContext& pc)
129130
}
130131
const auto& alpParams = o2::itsmft::DPLAlpideParam<o2::detectors::DetID::ITS>::Instance();
131132
for (int iLayer = 0; iLayer < ((mDoStaggering) ? NLayers : 1); ++iLayer) {
132-
LOGP(info, "ITSTracker:{} pulled {} clusters, {} RO frames", iLayer, compClusters[iLayer].size(), rofsinput[iLayer].size());
133+
LOGP(info, "ITSTracker{} pulled {} clusters, {} RO frames", ((mDoStaggering) ? std::format(":{}", iLayer) : ""), compClusters[iLayer].size(), rofsinput[iLayer].size());
133134
if (compClusters[iLayer].empty()) {
134-
LOGP(warn, " -> received no processable data on layer {}", iLayer);
135+
LOGP(warn, " -> received no processable data{}", (mDoStaggering) ? std::format(" on layer {}", iLayer) : "");
135136
}
136137
if (mIsMC) {
137138
LOG(info) << " -> " << labels[iLayer]->getIndexedSize() << " MC label objects";
@@ -186,9 +187,9 @@ void ITSTrackingInterface::run(framework::ProcessingContext& pc)
186187

187188
mTracker->setBz(o2::base::Propagator::Instance()->getNominalBz());
188189

189-
for (int iLayer = 0; iLayer < NLayers; ++iLayer) {
190+
for (int iLayer = 0; iLayer < ((mDoStaggering) ? NLayers : 1); ++iLayer) {
190191
gsl::span<const unsigned char>::iterator pattIt = patterns[iLayer].begin();
191-
loadROF(rofsinput[iLayer], compClusters[iLayer], pattIt, iLayer, labels[iLayer]);
192+
loadROF(rofsinput[iLayer], compClusters[iLayer], pattIt, ((mDoStaggering) ? iLayer : -1), labels[iLayer]);
192193
}
193194

194195
auto logger = [&](const std::string& s) { LOG(info) << s; };
@@ -299,30 +300,46 @@ void ITSTrackingInterface::run(framework::ProcessingContext& pc)
299300
auto& tracks = mTimeFrame->getTracks();
300301
allTrackLabels.reserve(mTimeFrame->getTracksLabel().size()); // should be 0 if not MC
301302
std::copy(mTimeFrame->getTracksLabel().begin(), mTimeFrame->getTracksLabel().end(), std::back_inserter(allTrackLabels));
302-
// Some conversions that needs to be moved in the tracker internals
303-
// also we create the track to clock ROF association here
304-
// the clock ROF is just the fastest ROF (the number of ROFs does not necessarily reflect the actual ROFs due to
305-
// possible delay of other layers)
303+
304+
// create the track to clock ROF association here
305+
// the clock ROF is just the fastest ROF
306+
// the number of ROFs does not necessarily reflect the actual ROFs
307+
// due to possible delay of other layers, however it is guaranteed to be >=0
306308
// tracks are guaranteed to be sorted here by their lower edge
307-
const auto& clockROF = mTimeFrame->getROFOverlapTableView().getClockLayer();
308-
// TODO:
309+
// NOTE: we are not setting the BCData of these ROFs (should we?)
310+
const auto& clockLayer = mTimeFrame->getROFOverlapTableView().getClockLayer();
311+
int highestROF{0};
312+
for (const auto& trc : tracks) {
313+
highestROF = std::max(highestROF, (int)clockLayer.getROF(trc.getTimeStamp().lower()));
314+
}
315+
allTrackROFs.resize(highestROF);
309316

317+
// Some conversions that needs to be moved in the tracker internals
318+
std::vector<int> rofEntries(highestROF + 1, 0);
310319
for (unsigned int iTrk{0}; iTrk < tracks.size(); ++iTrk) {
311320
auto& trc{tracks[iTrk]};
312-
trc.setFirstClusterEntry(allClusIdx.size()); // before adding tracks, create final cluster indices
321+
trc.setFirstClusterEntry((int)allClusIdx.size()); // before adding tracks, create final cluster indices
313322
int ncl = trc.getNumberOfClusters(), nclf = 0;
314323
for (int ic = TrackITSExt::MaxClusters; ic--;) { // track internally keeps in->out cluster indices, but we want to store the references as out->in!!!
315324
auto clid = trc.getClusterIndex(ic);
316325
if (clid >= 0) {
317-
trc.setClusterSize(ic, mTimeFrame->getClusterSize(ic, clid));
326+
trc.setClusterSize(ic, mTimeFrame->getClusterSize((mDoStaggering) ? ic : 0, clid));
318327
allClusIdx.push_back(clid);
319328
nclf++;
320329
}
321330
}
322331
assert(ncl == nclf);
323332
allTracks.emplace_back(trc);
333+
auto rof = clockLayer.getROF(trc.getTimeStamp().lower());
334+
++rofEntries[rof];
335+
}
336+
std::exclusive_scan(rofEntries.begin(), rofEntries.end(), rofEntries.begin(), 0);
337+
for (size_t iROF{0}; iROF < allTrackROFs.size(); ++iROF) {
338+
allTrackROFs[iROF].setFirstEntry(rofEntries[iROF]);
339+
allTrackROFs[iROF].setNEntries(rofEntries[iROF + 1] - rofEntries[iROF]);
324340
}
325341
}
342+
326343
LOGP(info, "ITSTracker pushed {} tracks in {} rofs and {} vertices", allTracks.size(), allTrackROFs.size(), vertices.size());
327344
if (mIsMC) {
328345
LOGP(info, "ITSTracker pushed {} track labels", allTrackLabels.size());

0 commit comments

Comments
 (0)