Skip to content

Commit 19d94af

Browse files
committed
ITS: fix time assignments
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent f13ffb4 commit 19d94af

File tree

12 files changed

+186
-288
lines changed

12 files changed

+186
-288
lines changed

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,64 +23,69 @@ namespace o2::its
2323
{
2424
// Time estimates are given in BC
2525
// error needs to cover maximum 1 orbit
26-
// this is an symmetric time error [t0-tE, t0+tE)
2726
using TimeStampType = uint32_t;
2827
using TimeStampErrorType = uint16_t;
28+
// this is an symmetric time error [t0-tE, t0+tE]
29+
using TimeStamp = o2::dataformats::TimeStampWithError<float, float>;
30+
// this is an asymmetric time interval [t0, t0+tE] used for internal calculations
2931
class TimeEstBC : public o2::dataformats::TimeStampWithError<TimeStampType, TimeStampErrorType>
3032
{
31-
public:
3233
using Base = o2::dataformats::TimeStampWithError<TimeStampType, TimeStampErrorType>;
34+
35+
public:
3336
GPUhdDefault() TimeEstBC() = default;
3437
GPUhdi() TimeEstBC(TimeStampType t, TimeStampErrorType e) : Base(t, e) {}
35-
38+
// convert to symmetric center+-half representation
39+
GPUhdi() its::TimeStamp makeSymmetrical() const noexcept
40+
{
41+
const auto start = static_cast<float>(this->getTimeStamp());
42+
const float half = (float)this->getTimeStampError() / 2.f;
43+
return {start + half, half};
44+
}
3645
// check if timestamps overlap within their interval
3746
GPUhdi() bool isCompatible(const TimeEstBC& o) const noexcept
3847
{
39-
return !(upper() <= o.lower() || o.upper() <= lower());
48+
return this->upper() > o.lower() && o.upper() > this->lower();
4049
}
41-
4250
GPUhdi() TimeEstBC& operator+=(const TimeEstBC& o) noexcept
4351
{
4452
add(o);
4553
return *this;
4654
}
47-
4855
GPUhdi() TimeEstBC operator+(const TimeEstBC& o) const noexcept
4956
{
5057
TimeEstBC res = *this;
5158
res += o;
5259
return res;
5360
}
54-
61+
// upper bound of interval t0+tE
5562
GPUhdi() TimeStampType upper() const noexcept
5663
{
5764
TimeStampType t = this->getTimeStamp();
5865
TimeStampType e = this->getTimeStampError();
5966
constexpr TimeStampType max = std::numeric_limits<TimeStampType>::max();
6067
return (t > (max - e)) ? max : t + e;
6168
}
62-
69+
// lower bound of interval t0
6370
GPUhdi() TimeStampType lower() const noexcept
6471
{
65-
TimeStampType t = this->getTimeStamp();
66-
TimeStampType e = this->getTimeStampError();
67-
return (t > e) ? (t - e) : 0u;
72+
return this->getTimeStamp();
6873
}
6974

7075
private:
71-
// add the other timestmap to this one
76+
// intersect with the other timestamp
7277
// this assumes already that both overlap
7378
GPUhdi() void add(const TimeEstBC& o) noexcept
7479
{
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+
const TimeStampType lo = o2::gpu::CAMath::Max(this->lower(), o.lower());
81+
const TimeStampType hi = o2::gpu::CAMath::Min(this->upper(), o.upper());
82+
this->setTimeStamp(lo);
83+
this->setTimeStampError(static_cast<TimeStampErrorType>(hi - lo));
8084
}
8185

8286
ClassDefNV(TimeEstBC, 1);
8387
};
88+
8489
} // namespace o2::its
8590

8691
#endif

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class TrackITS : public o2::track::TrackParCov
159159
float mChi2 = 0.; ///< Chi2 for this track
160160
uint32_t mPattern = 0; ///< layers pattern
161161
uint32_t mClusterSizes = 0u; ///< 4bit packed cluster sizes
162-
TimeEstBC mTime; ///< track time stamp with error in BC since start of TF, symmetrical
162+
TimeStamp mTime; ///< track time stamp with error in BC since start of TF, symmetrical
163163

164164
ClassDefNV(TrackITS, 7);
165165
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
namespace o2::its
2424
{
25+
// NOTE: this uses the internal asymmetrical time reprenstation!
2526
using Vertex = o2::dataformats::Vertex<o2::its::TimeEstBC>;
2627
using VertexLabel = std::pair<o2::MCCompLabel, float>;
2728
} // namespace o2::its

Detectors/ITSMFT/ITS/tracking/GPU/cuda/TrackerTraitsGPU.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ void TrackerTraitsGPU<NLayers>::findRoads(const int iteration)
399399
ts += rofTS;
400400
}
401401
}
402-
track.getTimeStamp() = ts;
402+
track.getTimeStamp() = ts.makeSymmetrical();
403403
track.setUserField(0);
404404
track.getParamOut().setUserField(0);
405405
mTimeFrameGPU->getTracks().emplace_back(track);

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

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,12 @@ struct Line final {
4848

4949
float originPoint[3] = {0, 0, 0};
5050
float cosinesDirector[3] = {0, 0, 0};
51-
// float weightMatrix[6] = {1., 0., 0., 1., 0., 1.};
52-
// weightMatrix is a symmetric matrix internally stored as
53-
// 0 --> row = 0, col = 0
54-
// 1 --> 0,1
55-
// 2 --> 0,2
56-
// 3 --> 1,1
57-
// 4 --> 1,2
58-
// 5 --> 2,2
5951
TimeEstBC mTime;
6052

6153
ClassDefNV(Line, 1);
6254
};
6355

64-
GPUhdi() Line::Line(const Tracklet& tracklet, const Cluster* innerClusters, const Cluster* outerClusters)
56+
GPUhdi() Line::Line(const Tracklet& tracklet, const Cluster* innerClusters, const Cluster* outerClusters) : mTime(tracklet.mTime)
6557
{
6658
originPoint[0] = innerClusters[tracklet.firstClusterIndex].xCoordinate;
6759
originPoint[1] = innerClusters[tracklet.firstClusterIndex].yCoordinate;
@@ -75,8 +67,6 @@ GPUhdi() Line::Line(const Tracklet& tracklet, const Cluster* innerClusters, cons
7567
cosinesDirector[0] *= inverseNorm;
7668
cosinesDirector[1] *= inverseNorm;
7769
cosinesDirector[2] *= inverseNorm;
78-
79-
mTime = tracklet.mTime;
8070
}
8171

8272
// static functions:
@@ -140,9 +130,9 @@ GPUhdi() void Line::getDCAComponents(const Line& line, const float point[3], flo
140130
destArray[0] = line.originPoint[0] - point[0] + line.cosinesDirector[0] * cdelta;
141131
destArray[3] = line.originPoint[1] - point[1] + line.cosinesDirector[1] * cdelta;
142132
destArray[5] = line.originPoint[2] - point[2] + line.cosinesDirector[2] * cdelta;
143-
destArray[1] = o2::gpu::CAMath::Sqrt(destArray[0] * destArray[0] + destArray[3] * destArray[3]);
144-
destArray[2] = o2::gpu::CAMath::Sqrt(destArray[0] * destArray[0] + destArray[5] * destArray[5]);
145-
destArray[4] = o2::gpu::CAMath::Sqrt(destArray[3] * destArray[3] + destArray[5] * destArray[5]);
133+
destArray[1] = o2::gpu::CAMath::Hypot(destArray[0], destArray[3]);
134+
destArray[2] = o2::gpu::CAMath::Hypot(destArray[0], destArray[5]);
135+
destArray[4] = o2::gpu::CAMath::Hypot(destArray[3], destArray[5]);
146136
}
147137

148138
inline bool Line::operator==(const Line& rhs) const
@@ -163,28 +153,27 @@ class ClusterLines final
163153
{
164154
public:
165155
ClusterLines() = default;
166-
ClusterLines(const int firstLabel, const Line& firstLine, const int secondLabel, const Line& secondLine,
167-
const bool weight = false);
168-
ClusterLines(const Line& firstLine, const Line& secondLine);
169-
void add(const int lineLabel, const Line& line, const bool weight = false);
156+
ClusterLines(const int firstLabel, const Line& firstLine, const int secondLabel, const Line& secondLine);
157+
void add(const int lineLabel, const Line& line);
170158
void computeClusterCentroid();
171-
inline std::array<float, 3> getVertex() const { return mVertex; }
172-
inline std::array<float, 6> getRMS2() const { return mRMS2; }
173-
inline float getAvgDistance2() const { return mAvgDistance2; }
174-
inline auto getSize() const noexcept { return mLabels.size(); }
159+
auto const& getVertex() const { return mVertex; }
160+
std::array<float, 6> getRMS2() const { return mRMS2; }
161+
float getAvgDistance2() const { return mAvgDistance2; }
162+
auto getSize() const noexcept { return mLabels.size(); }
175163
auto& getLabels() noexcept { return mLabels; }
176164
const auto& getTimeStamp() const noexcept { return mTime; }
177165
bool operator==(const ClusterLines& rhs) const noexcept;
166+
float getR2() const noexcept { return (mVertex[0] * mVertex[0]) + (mVertex[1] * mVertex[1]); }
167+
float getR() const noexcept { return std::sqrt(getR2()); }
178168

179169
protected:
180170
std::array<float, 6> mAMatrix = {}; // AX=B
181171
std::array<float, 3> mBMatrix = {}; // AX=B
182-
// std::array<float, 9> mWeightMatrix = {}; // weight matrix
183-
std::array<float, 3> mVertex = {}; // cluster centroid position
184-
std::array<float, 6> mRMS2 = {}; // symmetric matrix: diagonal is RMS2
185-
float mAvgDistance2 = 0.f; // substitute for chi2
186-
TimeEstBC mTime; // time stamp
187-
std::vector<int> mLabels; // contributing labels
172+
std::array<float, 3> mVertex = {}; // cluster centroid position
173+
std::array<float, 6> mRMS2 = {}; // symmetric matrix: diagonal is RMS2
174+
float mAvgDistance2 = 0.f; // substitute for chi2
175+
TimeEstBC mTime; // time stamp
176+
std::vector<int> mLabels; // contributing labels
188177
};
189178

190179
} // namespace o2::its

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
#include <vector>
2020
#ifndef GPUCA_GPUCODE
2121
#include <format>
22-
#endif
2322

23+
#include "Framework/Logger.h"
24+
#endif
2425
#include "CommonConstants/LHCConstants.h"
2526
#include "CommonDataFormat/RangeReference.h"
2627
#include "DataFormatsITS/TimeEstBC.h"
2728
#include "DataFormatsITS/Vertex.h"
28-
#include "GPUCommonLogger.h"
2929
#include "GPUCommonMath.h"
3030
#include "GPUCommonDef.h"
3131

@@ -65,12 +65,9 @@ struct LayerTiming {
6565
int64_t end = getROFEndInBC(rofId);
6666
start = o2::gpu::CAMath::Max(start - mROFAddTimeErr, int64_t(0));
6767
end += mROFAddTimeErr;
68-
const BCType half = (end - start + 1u) / 2u;
69-
return {BCType(start) + half, static_cast<uint16_t>(half)};
68+
return {static_cast<BCType>(start), static_cast<TimeStampErrorType>(end - start)};
7069
}
71-
const BCType start = getROFStartInBC(rofId);
72-
const BCType half = mROFLength / BCType(2);
73-
return {start + half, static_cast<TimeStampErrorType>(half)};
70+
return {getROFStartInBC(rofId), static_cast<TimeStampErrorType>(mROFLength)};
7471
}
7572

7673
// return which ROF this BC belongs to
@@ -83,6 +80,17 @@ struct LayerTiming {
8380
return (bc - offset) / mROFLength;
8481
}
8582

83+
// return which ROF this timestamp belongs by its lower edge
84+
GPUhi() BCType getROF(TimeStamp ts) const noexcept
85+
{
86+
const BCType offset = mROFDelay + mROFBias;
87+
const BCType bc = (ts.getTimeStamp() < ts.getTimeStampError()) ? BCType(0) : static_cast<BCType>(o2::gpu::CAMath::Floor(ts.getTimeStamp() - ts.getTimeStampError()));
88+
if (bc <= offset) {
89+
return 0;
90+
}
91+
return (bc - offset) / mROFLength;
92+
}
93+
8694
#ifndef GPUCA_GPUCODE
8795
GPUh() std::string asString() const
8896
{
@@ -278,7 +286,7 @@ struct ROFOverlapTableView {
278286
mLayers[i].print();
279287
}
280288

281-
const uint32_t totalBytes = (flatTableSize * sizeof(TableEntry)) + (NLayers * NLayers * sizeof(TableIndex));
289+
const uint32_t totalBytes = (flatTableSize * sizeof(TableEntry)) + (static_cast<unsigned long>(NLayers * NLayers) * sizeof(TableIndex));
282290
LOGF(info, "------------------------------------------------------------");
283291
LOGF(info, "Total overlap table size: %u entries", totalEntries);
284292
LOGF(info, "Flat table size: %zu entries", flatTableSize);
@@ -332,7 +340,7 @@ class ROFOverlapTable : public LayerTimingBase<NLayers>
332340
}
333341

334342
GPUh() size_t getFlatTableSize() const noexcept { return mFlatTable.size(); }
335-
static GPUh() constexpr size_t getIndicesSize() { return NLayers * NLayers; }
343+
static GPUh() constexpr size_t getIndicesSize() { return static_cast<size_t>(NLayers * NLayers); }
336344

337345
private:
338346
GPUh() void buildMapping(int32_t from, int32_t to, std::vector<TableEntry>& table)
@@ -346,7 +354,7 @@ class ROFOverlapTable : public LayerTimingBase<NLayers>
346354
int64_t fromEnd = (int64_t)layerFrom.getROFEndInBC(iROF) + layerFrom.mROFAddTimeErr;
347355

348356
int32_t firstROFTo = o2::gpu::CAMath::Max(0, (int32_t)((fromStart - (int64_t)layerTo.mROFAddTimeErr - (int64_t)layerTo.mROFDelay - (int64_t)layerTo.mROFBias) / (int64_t)layerTo.mROFLength));
349-
int32_t lastROFTo = (int32_t)((fromEnd + (int64_t)layerTo.mROFAddTimeErr - (int64_t)layerTo.mROFDelay - (int64_t)layerTo.mROFBias - 1) / (int64_t)layerTo.mROFLength);
357+
auto lastROFTo = (int32_t)((fromEnd + (int64_t)layerTo.mROFAddTimeErr - (int64_t)layerTo.mROFDelay - (int64_t)layerTo.mROFBias - 1) / (int64_t)layerTo.mROFLength);
350358
firstROFTo = o2::gpu::CAMath::Max(0, firstROFTo);
351359
lastROFTo = o2::gpu::CAMath::Min((int32_t)layerTo.mNROFsTF - 1, lastROFTo);
352360

@@ -443,8 +451,8 @@ struct ROFVertexLookupTableView {
443451
const auto& layerDef = mLayers[layer];
444452
int64_t rofLower = o2::gpu::CAMath::Max((int64_t)layerDef.getROFStartInBC(rofIdx) - (int64_t)layerDef.mROFAddTimeErr, int64_t(0));
445453
int64_t rofUpper = (int64_t)layerDef.getROFEndInBC(rofIdx) + layerDef.mROFAddTimeErr;
446-
int64_t vLower = (int64_t)vertex.getTimeStamp().getTimeStamp() - (int64_t)vertex.getTimeStamp().getTimeStampError();
447-
int64_t vUpper = (int64_t)vertex.getTimeStamp().getTimeStamp() + (int64_t)vertex.getTimeStamp().getTimeStampError();
454+
auto vLower = (int64_t)vertex.getTimeStamp().lower();
455+
auto vUpper = (int64_t)vertex.getTimeStamp().upper();
448456
return vUpper >= rofLower && vLower < rofUpper;
449457
}
450458

@@ -601,8 +609,7 @@ class ROFVertexLookupTable : public LayerTimingBase<NLayers>
601609
size_t lastVertex = binarySearchFirst(vertices, nVertices, vertexSearchStart, rofUpper);
602610
size_t firstVertex = vertexSearchStart;
603611
while (firstVertex < lastVertex) {
604-
int64_t vUpper = (int64_t)vertices[firstVertex].getTimeStamp().getTimeStamp() +
605-
(int64_t)vertices[firstVertex].getTimeStamp().getTimeStampError();
612+
auto vUpper = (int64_t)vertices[firstVertex].getTimeStamp().upper();
606613
if (vUpper > rofLower) {
607614
break;
608615
}

0 commit comments

Comments
 (0)