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
2223namespace o2 ::its
2324{
2425struct 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
6360GPUhdi () 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-
9574GPUhdi () 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
131108GPUhdi () 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
145122GPUhdi () 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
176144GPUhdi () 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
200168inline 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
209173GPUhdi () void Line::print () const
0 commit comments