Skip to content

Commit b8d6494

Browse files
authored
ITS: cleanup lines and tracklet/clusterlines changes (#14511)
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch> FullCi is green, merging.
1 parent 8252a1f commit b8d6494

File tree

4 files changed

+86
-154
lines changed

4 files changed

+86
-154
lines changed

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

Lines changed: 46 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@
1515
#include <array>
1616
#include <vector>
1717
#include "ITStracking/Cluster.h"
18-
#include "ITStracking/Definitions.h"
18+
#include "ITStracking/Constants.h"
1919
#include "ITStracking/Tracklet.h"
20+
#include "GPUCommonRtypes.h"
2021
#include "GPUCommonMath.h"
2122

2223
namespace o2::its
2324
{
2425
struct Line final {
25-
GPUhd() Line();
26+
GPUhdDefault() Line() = default;
2627
GPUhd() Line(const Line&);
2728
Line(std::array<float, 3> firstPoint, std::array<float, 3> secondPoint);
28-
GPUhd() Line(const float firstPoint[3], const float secondPoint[3]);
2929
GPUhd() Line(const Tracklet&, const Cluster*, const Cluster*);
3030

3131
static float getDistanceFromPoint(const Line& line, const std::array<float, 3>& point);
3232
GPUhd() static float getDistanceFromPoint(const Line& line, const float point[3]);
3333
static std::array<float, 6> getDCAComponents(const Line& line, const std::array<float, 3> point);
3434
GPUhd() static void getDCAComponents(const Line& line, const float point[3], float destArray[6]);
35-
GPUhd() static float getDCA(const Line&, const Line&, const float precision = 1e-14);
36-
static bool areParallel(const Line&, const Line&, const float precision = 1e-14);
35+
GPUhd() static float getDCA(const Line&, const Line&, const float precision = constants::Tolerance);
36+
static bool areParallel(const Line&, const Line&, const float precision = constants::Tolerance);
3737
GPUhd() unsigned char isEmpty() const { return (originPoint[0] == 0.f && originPoint[1] == 0.f && originPoint[2] == 0.f) &&
3838
(cosinesDirector[0] == 0.f && cosinesDirector[1] == 0.f && cosinesDirector[2] == 0.f); }
3939
GPUhdi() auto getDeltaROF() const { return rof[1] - rof[0]; }
@@ -42,56 +42,35 @@ struct Line final {
4242
bool operator!=(const Line&) const;
4343
short getMinROF() const { return rof[0] < rof[1] ? rof[0] : rof[1]; }
4444

45-
float originPoint[3], cosinesDirector[3];
46-
float weightMatrix[6] = {1., 0., 0., 1., 0., 1.};
45+
float originPoint[3] = {0};
46+
float cosinesDirector[3] = {0};
47+
// float weightMatrix[6] = {1., 0., 0., 1., 0., 1.};
4748
// weightMatrix is a symmetric matrix internally stored as
4849
// 0 --> row = 0, col = 0
4950
// 1 --> 0,1
5051
// 2 --> 0,2
5152
// 3 --> 1,1
5253
// 4 --> 1,2
5354
// 5 --> 2,2
54-
short rof[2];
55-
};
55+
short rof[2] = {-1, -1};
5656

57-
GPUhdi() Line::Line() : weightMatrix{1., 0., 0., 1., 0., 1.}
58-
{
59-
rof[0] = -1;
60-
rof[1] = -1;
61-
}
57+
ClassDefNV(Line, 1);
58+
};
6259

6360
GPUhdi() Line::Line(const Line& other)
6461
{
6562
for (int i{0}; i < 3; ++i) {
6663
originPoint[i] = other.originPoint[i];
6764
cosinesDirector[i] = other.cosinesDirector[i];
6865
}
69-
for (int i{0}; i < 6; ++i) {
70-
weightMatrix[i] = other.weightMatrix[i];
71-
}
66+
// for (int i{0}; i < 6; ++i) {
67+
// weightMatrix[i] = other.weightMatrix[i];
68+
// }
7269
for (int i{0}; i < 2; ++i) {
7370
rof[i] = other.rof[i];
7471
}
7572
}
7673

77-
GPUhdi() Line::Line(const float firstPoint[3], const float secondPoint[3])
78-
{
79-
for (int i{0}; i < 3; ++i) {
80-
originPoint[i] = firstPoint[i];
81-
cosinesDirector[i] = secondPoint[i] - firstPoint[i];
82-
}
83-
84-
float inverseNorm{1.f / o2::gpu::CAMath::Sqrt(cosinesDirector[0] * cosinesDirector[0] + cosinesDirector[1] * cosinesDirector[1] +
85-
cosinesDirector[2] * cosinesDirector[2])};
86-
87-
for (int index{0}; index < 3; ++index) {
88-
cosinesDirector[index] *= inverseNorm;
89-
}
90-
91-
rof[0] = -1;
92-
rof[1] = -1;
93-
}
94-
9574
GPUhdi() Line::Line(const Tracklet& tracklet, const Cluster* innerClusters, const Cluster* outerClusters)
9675
{
9776
originPoint[0] = innerClusters[tracklet.firstClusterIndex].xCoordinate;
@@ -102,12 +81,10 @@ GPUhdi() Line::Line(const Tracklet& tracklet, const Cluster* innerClusters, cons
10281
cosinesDirector[1] = outerClusters[tracklet.secondClusterIndex].yCoordinate - innerClusters[tracklet.firstClusterIndex].yCoordinate;
10382
cosinesDirector[2] = outerClusters[tracklet.secondClusterIndex].zCoordinate - innerClusters[tracklet.firstClusterIndex].zCoordinate;
10483

105-
float inverseNorm{1.f / o2::gpu::CAMath::Sqrt(cosinesDirector[0] * cosinesDirector[0] + cosinesDirector[1] * cosinesDirector[1] +
106-
cosinesDirector[2] * cosinesDirector[2])};
107-
108-
for (int index{0}; index < 3; ++index) {
109-
cosinesDirector[index] *= inverseNorm;
110-
}
84+
float inverseNorm{1.f / o2::gpu::CAMath::Hypot(cosinesDirector[0], cosinesDirector[1], cosinesDirector[2])};
85+
cosinesDirector[0] *= inverseNorm;
86+
cosinesDirector[1] *= inverseNorm;
87+
cosinesDirector[2] *= inverseNorm;
11188

11289
rof[0] = tracklet.rof[0];
11390
rof[1] = tracklet.rof[1];
@@ -130,47 +107,38 @@ inline float Line::getDistanceFromPoint(const Line& line, const std::array<float
130107

131108
GPUhdi() float Line::getDistanceFromPoint(const Line& line, const float point[3])
132109
{
133-
float DCASquared{0};
134-
float cdelta{0};
135-
for (int i{0}; i < 3; ++i) {
136-
cdelta -= line.cosinesDirector[i] * (line.originPoint[i] - point[i]);
137-
}
138-
for (int i{0}; i < 3; ++i) {
139-
DCASquared += (line.originPoint[i] - point[i] + line.cosinesDirector[i] * cdelta) *
140-
(line.originPoint[i] - point[i] + line.cosinesDirector[i] * cdelta);
141-
}
142-
return o2::gpu::CAMath::Sqrt(DCASquared);
110+
const float dx = point[0] - line.originPoint[0];
111+
const float dy = point[1] - line.originPoint[1];
112+
const float dz = point[2] - line.originPoint[2];
113+
const float d = (dx * line.cosinesDirector[0]) + (dy * line.cosinesDirector[1]) + (dz * line.cosinesDirector[2]);
114+
115+
const float vx = dx - (d * line.cosinesDirector[0]);
116+
const float vy = dy - (d * line.cosinesDirector[1]);
117+
const float vz = dz - (d * line.cosinesDirector[2]);
118+
119+
return o2::gpu::CAMath::Hypot(vx, vy, vz);
143120
}
144121

145122
GPUhdi() float Line::getDCA(const Line& firstLine, const Line& secondLine, const float precision)
146123
{
147-
float normalVector[3];
148-
normalVector[0] = firstLine.cosinesDirector[1] * secondLine.cosinesDirector[2] -
149-
firstLine.cosinesDirector[2] * secondLine.cosinesDirector[1];
150-
normalVector[1] = -firstLine.cosinesDirector[0] * secondLine.cosinesDirector[2] +
151-
firstLine.cosinesDirector[2] * secondLine.cosinesDirector[0];
152-
normalVector[2] = firstLine.cosinesDirector[0] * secondLine.cosinesDirector[1] -
153-
firstLine.cosinesDirector[1] * secondLine.cosinesDirector[0];
154-
155-
float norm{0.f}, distance{0.f};
156-
for (int i{0}; i < 3; ++i) {
157-
norm += normalVector[i] * normalVector[i];
158-
distance += (secondLine.originPoint[i] - firstLine.originPoint[i]) * normalVector[i];
159-
}
160-
if (norm > precision) {
161-
return o2::gpu::CAMath::Abs(distance / o2::gpu::CAMath::Sqrt(norm));
162-
} else {
163-
#if defined(__CUDACC__) || defined(__HIPCC__)
164-
float stdOriginPoint[3];
165-
for (int i{0}; i < 3; ++i) {
166-
stdOriginPoint[i] = secondLine.originPoint[1];
167-
}
168-
#else
169-
std::array<float, 3> stdOriginPoint = {};
170-
std::copy_n(secondLine.originPoint, 3, stdOriginPoint.begin());
171-
#endif
172-
return getDistanceFromPoint(firstLine, stdOriginPoint);
124+
const float nx = (firstLine.cosinesDirector[1] * secondLine.cosinesDirector[2]) -
125+
(firstLine.cosinesDirector[2] * secondLine.cosinesDirector[1]);
126+
const float ny = -(firstLine.cosinesDirector[0] * secondLine.cosinesDirector[2]) +
127+
(firstLine.cosinesDirector[2] * secondLine.cosinesDirector[0]);
128+
const float nz = (firstLine.cosinesDirector[0] * secondLine.cosinesDirector[1]) -
129+
(firstLine.cosinesDirector[1] * secondLine.cosinesDirector[0]);
130+
const float norm2 = (nx * nx) + (ny * ny) + (nz * nz);
131+
132+
if (norm2 <= precision * precision) {
133+
return getDistanceFromPoint(firstLine, secondLine.originPoint);
173134
}
135+
136+
const float dx = secondLine.originPoint[0] - firstLine.originPoint[0];
137+
const float dy = secondLine.originPoint[1] - firstLine.originPoint[1];
138+
const float dz = secondLine.originPoint[2] - firstLine.originPoint[2];
139+
const float triple = (dx * nx) + (dy * ny) + (dz * nz);
140+
141+
return o2::gpu::CAMath::Abs(triple) / o2::gpu::CAMath::Sqrt(norm2);
174142
}
175143

176144
GPUhdi() void Line::getDCAComponents(const Line& line, const float point[3], float destArray[6])
@@ -199,11 +167,7 @@ inline bool Line::operator==(const Line& rhs) const
199167

200168
inline bool Line::operator!=(const Line& rhs) const
201169
{
202-
bool val;
203-
for (int i{0}; i < 3; ++i) {
204-
val &= this->originPoint[i] != rhs.originPoint[i];
205-
}
206-
return val;
170+
return !(*this == rhs);
207171
}
208172

209173
GPUhdi() void Line::print() const

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

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,53 +20,48 @@
2020
#include "GPUCommonRtypes.h"
2121
#include "GPUCommonMath.h"
2222
#include "GPUCommonDef.h"
23+
#include "GPUCommonLogger.h"
2324

2425
#ifndef GPUCA_GPUCODE_DEVICE
26+
#ifndef GPU_NO_FMT
2527
#include <string>
28+
#include <fmt/format.h>
29+
#endif
2630
#endif
2731

2832
namespace o2::its
2933
{
3034

3135
struct Tracklet final {
32-
GPUhdi() Tracklet();
36+
GPUhdDefault() Tracklet() = default;
3337
GPUhdi() Tracklet(const int, const int, const Cluster&, const Cluster&, short rof0, short rof1);
3438
GPUhdi() Tracklet(const int, const int, float tanL, float phi, short rof0, short rof1);
35-
GPUhdi() bool operator==(const Tracklet&) const;
36-
GPUhdi() bool operator!=(const Tracklet&) const;
39+
GPUhdDefault() bool operator==(const Tracklet&) const = default;
3740
GPUhdi() unsigned char isEmpty() const
3841
{
3942
return firstClusterIndex < 0 || secondClusterIndex < 0;
4043
}
4144
GPUhdi() auto getDeltaRof() const { return rof[1] - rof[0]; }
42-
GPUhdi() void dump();
4345
GPUhdi() void dump() const;
44-
GPUhdi() void dump(const int, const int);
4546
GPUhdi() void dump(const int, const int) const;
4647
GPUhdi() unsigned char operator<(const Tracklet&) const;
47-
#ifndef GPUCA_GPUCODE_DEVICE
48+
#if !defined(GPUCA_NO_FMT) && !defined(GPUCA_GPUCODE_DEVICE)
4849
std::string asString() const
4950
{
50-
return "fClIdx: " + std::to_string(firstClusterIndex) + " sClIdx: " + std::to_string(secondClusterIndex) +
51-
" rof1: " + std::to_string(rof[0]) + " rof2: " + std::to_string(rof[1]) + " delta: " + std::to_string(getDeltaRof());
51+
return fmt::format("fClIdx:{} fROF:{} sClIdx:{} sROF:{} (DROF:{})", firstClusterIndex, rof[0], secondClusterIndex, rof[1], getDeltaRof());
5252
}
53+
void print() const { LOG(info) << asString(); }
5354
#endif
5455

55-
int firstClusterIndex;
56-
int secondClusterIndex;
57-
float tanLambda;
58-
float phi;
59-
short rof[2];
56+
int firstClusterIndex{-1};
57+
int secondClusterIndex{-1};
58+
float tanLambda{-999};
59+
float phi{-999};
60+
short rof[2] = {-1, -1};
6061

6162
ClassDefNV(Tracklet, 1);
6263
};
6364

64-
GPUhdi() Tracklet::Tracklet() : firstClusterIndex{-1}, secondClusterIndex{-1}, tanLambda{0.0f}, phi{0.0f}
65-
{
66-
rof[0] = -1;
67-
rof[1] = -1;
68-
}
69-
7065
GPUhdi() Tracklet::Tracklet(const int firstClusterOrderingIndex, const int secondClusterOrderingIndex,
7166
const Cluster& firstCluster, const Cluster& secondCluster, short rof0 = -1, short rof1 = -1)
7267
: firstClusterIndex{firstClusterOrderingIndex},
@@ -90,24 +85,6 @@ GPUhdi() Tracklet::Tracklet(const int idx0, const int idx1, float tanL, float ph
9085
// Nothing to do
9186
}
9287

93-
GPUhdi() bool Tracklet::operator==(const Tracklet& rhs) const
94-
{
95-
return this->firstClusterIndex == rhs.firstClusterIndex &&
96-
this->secondClusterIndex == rhs.secondClusterIndex &&
97-
this->tanLambda == rhs.tanLambda &&
98-
this->phi == rhs.phi &&
99-
this->rof[0] == rhs.rof[0] &&
100-
this->rof[1] == rhs.rof[1];
101-
}
102-
103-
GPUhdi() bool Tracklet::operator!=(const Tracklet& rhs) const
104-
{
105-
return this->firstClusterIndex != rhs.firstClusterIndex ||
106-
this->secondClusterIndex != rhs.secondClusterIndex ||
107-
this->tanLambda != rhs.tanLambda ||
108-
this->phi != rhs.phi;
109-
}
110-
11188
GPUhdi() unsigned char Tracklet::operator<(const Tracklet& t) const
11289
{
11390
if (isEmpty()) {
@@ -116,21 +93,11 @@ GPUhdi() unsigned char Tracklet::operator<(const Tracklet& t) const
11693
return true;
11794
}
11895

119-
GPUhdi() void Tracklet::dump(const int offsetFirst, const int offsetSecond)
120-
{
121-
printf("fClIdx: %d sClIdx: %d rof1: %hu rof2: %hu\n", firstClusterIndex + offsetFirst, secondClusterIndex + offsetSecond, rof[0], rof[1]);
122-
}
123-
12496
GPUhdi() void Tracklet::dump(const int offsetFirst, const int offsetSecond) const
12597
{
12698
printf("fClIdx: %d sClIdx: %d rof1: %hu rof2: %hu\n", firstClusterIndex + offsetFirst, secondClusterIndex + offsetSecond, rof[0], rof[1]);
12799
}
128100

129-
GPUhdi() void Tracklet::dump()
130-
{
131-
printf("fClIdx: %d sClIdx: %d rof1: %hu rof2: %hu\n", firstClusterIndex, secondClusterIndex, rof[0], rof[1]);
132-
}
133-
134101
GPUhdi() void Tracklet::dump() const
135102
{
136103
printf("fClIdx: %d sClIdx: %d rof1: %hu rof2: %hu\n", firstClusterIndex, secondClusterIndex, rof[0], rof[1]);

0 commit comments

Comments
 (0)