@@ -130,47 +130,38 @@ inline float Line::getDistanceFromPoint(const Line& line, const std::array<float
130130
131131GPUhdi () float Line::getDistanceFromPoint (const Line& line, const float point[3 ])
132132{
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 );
133+ const float dx = point[ 0 ] - line. originPoint [ 0 ] ;
134+ const float dy = point[ 1 ] - line. originPoint [ 1 ] ;
135+ const float dz = point[ 2 ] - line. originPoint [ 2 ];
136+ const float d = (dx * line.cosinesDirector [0 ]) + (dy * line.cosinesDirector [ 1 ]) + (dz * line. cosinesDirector [ 2 ]);
137+
138+ const float vx = dx - (d * line. cosinesDirector [ 0 ]);
139+ const float vy = dy - (d * line.cosinesDirector [1 ]);
140+ const float vz = dz - (d * line.cosinesDirector [2 ] );
141+
142+ return o2::gpu::CAMath::Hypot (vx, vy, vz );
143143}
144144
145145GPUhdi () float Line::getDCA (const Line& firstLine, const Line& secondLine, const float precision)
146146{
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);
147+ const float nx = (firstLine.cosinesDirector [1 ] * secondLine.cosinesDirector [2 ]) -
148+ (firstLine.cosinesDirector [2 ] * secondLine.cosinesDirector [1 ]);
149+ const float ny = -(firstLine.cosinesDirector [0 ] * secondLine.cosinesDirector [2 ]) +
150+ (firstLine.cosinesDirector [2 ] * secondLine.cosinesDirector [0 ]);
151+ const float nz = (firstLine.cosinesDirector [0 ] * secondLine.cosinesDirector [1 ]) -
152+ (firstLine.cosinesDirector [1 ] * secondLine.cosinesDirector [0 ]);
153+ const float norm2 = (nx * nx) + (ny * ny) + (nz * nz);
154+
155+ if (norm2 <= precision * precision) {
156+ return getDistanceFromPoint (firstLine, secondLine.originPoint );
173157 }
158+
159+ const float dx = secondLine.originPoint [0 ] - firstLine.originPoint [0 ];
160+ const float dy = secondLine.originPoint [1 ] - firstLine.originPoint [1 ];
161+ const float dz = secondLine.originPoint [2 ] - firstLine.originPoint [2 ];
162+ const float triple = (dx * nx) + (dy * ny) + (dz * nz);
163+
164+ return o2::gpu::CAMath::Abs (triple) * o2::gpu::CAMath::InvSqrt (norm2);
174165}
175166
176167GPUhdi () void Line::getDCAComponents (const Line& line, const float point[3 ], float destArray[6 ])
0 commit comments