Project
Loading...
Searching...
No Matches
ClusterLines.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_ITS_CLUSTERLINES_H
13#define O2_ITS_CLUSTERLINES_H
14
15#include <array>
16#include <vector>
17#include "ITStracking/Cluster.h"
20#include "GPUCommonMath.h"
21
22namespace o2::its
23{
24struct Line final {
26 GPUhd() Line(const Line&);
27 Line(std::array<float, 3> firstPoint, std::array<float, 3> secondPoint);
28 GPUhd() Line(const float firstPoint[3], const float secondPoint[3]);
29 GPUhd() Line(const Tracklet&, const Cluster*, const Cluster*);
30
31 static float getDistanceFromPoint(const Line& line, const std::array<float, 3>& point);
32 GPUhd() static float getDistanceFromPoint(const Line& line, const float point[3]);
33 static std::array<float, 6> getDCAComponents(const Line& line, const std::array<float, 3> point);
34 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);
37 GPUhd() unsigned char isEmpty() const { return (originPoint[0] == 0.f && originPoint[1] == 0.f && originPoint[2] == 0.f) &&
38 (cosinesDirector[0] == 0.f && cosinesDirector[1] == 0.f && cosinesDirector[2] == 0.f); }
39 GPUhdi() auto getDeltaROF() const { return rof[1] - rof[0]; }
40 GPUhd() void print() const;
41 bool operator==(const Line&) const;
42 bool operator!=(const Line&) const;
43 short getMinROF() const { return rof[0] < rof[1] ? rof[0] : rof[1]; }
44
46 float weightMatrix[6] = {1., 0., 0., 1., 0., 1.};
47 // weightMatrix is a symmetric matrix internally stored as
48 // 0 --> row = 0, col = 0
49 // 1 --> 0,1
50 // 2 --> 0,2
51 // 3 --> 1,1
52 // 4 --> 1,2
53 // 5 --> 2,2
54 short rof[2];
55};
56
57GPUhdi() Line::Line() : weightMatrix{1., 0., 0., 1., 0., 1.}
58{
59 rof[0] = -1;
60 rof[1] = -1;
61}
62
63GPUhdi() Line::Line(const Line& other)
64{
65 for (int i{0}; i < 3; ++i) {
66 originPoint[i] = other.originPoint[i];
67 cosinesDirector[i] = other.cosinesDirector[i];
68 }
69 for (int i{0}; i < 6; ++i) {
70 weightMatrix[i] = other.weightMatrix[i];
71 }
72 for (int i{0}; i < 2; ++i) {
73 rof[i] = other.rof[i];
74 }
75}
76
77GPUhdi() 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
95GPUhdi() Line::Line(const Tracklet& tracklet, const Cluster* innerClusters, const Cluster* outerClusters)
96{
97 originPoint[0] = innerClusters[tracklet.firstClusterIndex].xCoordinate;
98 originPoint[1] = innerClusters[tracklet.firstClusterIndex].yCoordinate;
99 originPoint[2] = innerClusters[tracklet.firstClusterIndex].zCoordinate;
100
101 cosinesDirector[0] = outerClusters[tracklet.secondClusterIndex].xCoordinate - innerClusters[tracklet.firstClusterIndex].xCoordinate;
102 cosinesDirector[1] = outerClusters[tracklet.secondClusterIndex].yCoordinate - innerClusters[tracklet.firstClusterIndex].yCoordinate;
103 cosinesDirector[2] = outerClusters[tracklet.secondClusterIndex].zCoordinate - innerClusters[tracklet.firstClusterIndex].zCoordinate;
104
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 }
111
112 rof[0] = tracklet.rof[0];
113 rof[1] = tracklet.rof[1];
114}
115
116// static functions:
117inline float Line::getDistanceFromPoint(const Line& line, const std::array<float, 3>& point)
118{
119 float DCASquared{0};
120 float cdelta{0};
121 for (int i{0}; i < 3; ++i) {
122 cdelta -= line.cosinesDirector[i] * (line.originPoint[i] - point[i]);
123 }
124 for (int i{0}; i < 3; ++i) {
125 DCASquared += (line.originPoint[i] - point[i] + line.cosinesDirector[i] * cdelta) *
126 (line.originPoint[i] - point[i] + line.cosinesDirector[i] * cdelta);
127 }
128 return o2::gpu::CAMath::Sqrt(DCASquared);
129}
130
131GPUhdi() float Line::getDistanceFromPoint(const Line& line, const float point[3])
132{
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);
143}
144
145GPUhdi() float Line::getDCA(const Line& firstLine, const Line& secondLine, const float precision)
146{
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);
173 }
174}
175
176GPUhdi() void Line::getDCAComponents(const Line& line, const float point[3], float destArray[6])
177{
178 float cdelta{0.};
179 for (int i{0}; i < 3; ++i) {
180 cdelta -= line.cosinesDirector[i] * (line.originPoint[i] - point[i]);
181 }
182
183 destArray[0] = line.originPoint[0] - point[0] + line.cosinesDirector[0] * cdelta;
184 destArray[3] = line.originPoint[1] - point[1] + line.cosinesDirector[1] * cdelta;
185 destArray[5] = line.originPoint[2] - point[2] + line.cosinesDirector[2] * cdelta;
186 destArray[1] = o2::gpu::CAMath::Sqrt(destArray[0] * destArray[0] + destArray[3] * destArray[3]);
187 destArray[2] = o2::gpu::CAMath::Sqrt(destArray[0] * destArray[0] + destArray[5] * destArray[5]);
188 destArray[4] = o2::gpu::CAMath::Sqrt(destArray[3] * destArray[3] + destArray[5] * destArray[5]);
189}
190
191inline bool Line::operator==(const Line& rhs) const
192{
193 bool val{false};
194 for (int i{0}; i < 3; ++i) {
195 val &= this->originPoint[i] == rhs.originPoint[i];
196 }
197 return val;
198}
199
200inline bool Line::operator!=(const Line& rhs) const
201{
202 bool val;
203 for (int i{0}; i < 3; ++i) {
204 val &= this->originPoint[i] != rhs.originPoint[i];
205 }
206 return val;
207}
208
209GPUhdi() void Line::print() const
210{
211 printf("Line: originPoint = (%f, %f, %f), cosinesDirector = (%f, %f, %f), rofs = (%hd, %hd)\n",
212 originPoint[0], originPoint[1], originPoint[2], cosinesDirector[0], cosinesDirector[1], cosinesDirector[2], rof[0], rof[1]);
213}
214
215class ClusterLines final
216{
217 public:
218 ClusterLines() = default;
219 ClusterLines(const int firstLabel, const Line& firstLine, const int secondLabel, const Line& secondLine,
220 const bool weight = false);
221 ClusterLines(const Line& firstLine, const Line& secondLine);
222 void add(const int& lineLabel, const Line& line, const bool& weight = false);
223 void computeClusterCentroid();
224 void updateROFPoll(const Line&);
225 inline std::vector<int>& getLabels()
226 {
227 return mLabels;
228 }
229 inline int getSize() const { return mLabels.size(); }
230 inline short getROF() const { return mROF; }
231 inline std::array<float, 3> getVertex() const { return mVertex; }
232 inline std::array<float, 6> getRMS2() const { return mRMS2; }
233 inline float getAvgDistance2() const { return mAvgDistance2; }
234
235 bool operator==(const ClusterLines&) const;
236
237 protected:
238 std::array<double, 6> mAMatrix; // AX=B
239 std::array<double, 3> mBMatrix; // AX=B
240 std::vector<int> mLabels; // labels
241 std::array<float, 9> mWeightMatrix = {0.f}; // weight matrix
242 std::array<float, 3> mVertex = {0.f}; // cluster centroid position
243 std::array<float, 6> mRMS2 = {0.f}; // symmetric matrix: diagonal is RMS2
244 float mAvgDistance2 = 0.f; // substitute for chi2
245 int mROFWeight = 0; // rof weight for voting
246 short mROF = -1; // rof
247};
248
249} // namespace o2::its
250#endif /* O2_ITS_CLUSTERLINES_H */
void print() const
int32_t i
HMPID cluster implementation.
Definition Cluster.h:27
GLenum array
Definition glcorearb.h:4274
GLuint index
Definition glcorearb.h:781
GLuint GLuint GLfloat weight
Definition glcorearb.h:5477
GLsizei GLsizei GLfloat distance
Definition glcorearb.h:5506
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLfloat * val
Definition glcorearb.h:1582
GLenum GLint GLint * precision
Definition glcorearb.h:1899
GPUhdi() Cell
Definition Cell.h:55
Defining DataPointCompositeObject explicitly as copiable.
bool operator!=(const Line &) const
GPUhd() Line()
float cosinesDirector[3]
GPUhd() void print() const
static std::array< float, 6 > getDCAComponents(const Line &line, const std::array< float, 3 > point)
const float float destArray[6]
bool operator==(const Line &) const
const float point[3]
GPUhdi() auto getDeltaROF() const
float weightMatrix[6]
const Cluster const Cluster *static float getDistanceFromPoint(const Line &line, const std::array< float, 3 > &point)
static bool areParallel(const Line &, const Line &, const float precision=1e-14)
float originPoint[3]
const float secondPoint[3]
short getMinROF() const
bool operator==(const CoarseLocation &a, const CoarseLocation &b)
VectorOfTObjectPtrs other