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 "GPUCommonRtypes.h"
21#include "GPUCommonMath.h"
22
23namespace o2::its
24{
25struct Line final {
26 GPUhdDefault() Line() = default;
27 GPUhd() Line(const Line&);
28 Line(std::array<float, 3> firstPoint, std::array<float, 3> secondPoint);
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 = constants::Tolerance);
36 static bool areParallel(const Line&, const Line&, const float precision = constants::Tolerance);
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
45 float originPoint[3] = {0, 0, 0};
46 float cosinesDirector[3] = {0, 0, 0};
47 // float weightMatrix[6] = {1., 0., 0., 1., 0., 1.};
48 // weightMatrix is a symmetric matrix internally stored as
49 // 0 --> row = 0, col = 0
50 // 1 --> 0,1
51 // 2 --> 0,2
52 // 3 --> 1,1
53 // 4 --> 1,2
54 // 5 --> 2,2
56
58};
59
61{
62 for (int i{0}; i < 3; ++i) {
63 originPoint[i] = other.originPoint[i];
64 cosinesDirector[i] = other.cosinesDirector[i];
65 }
66 // for (int i{0}; i < 6; ++i) {
67 // weightMatrix[i] = other.weightMatrix[i];
68 // }
69 for (int i{0}; i < 2; ++i) {
70 rof[i] = other.rof[i];
71 }
72}
73
74GPUhdi() Line::Line(const Tracklet& tracklet, const Cluster* innerClusters, const Cluster* outerClusters)
75{
76 originPoint[0] = innerClusters[tracklet.firstClusterIndex].xCoordinate;
77 originPoint[1] = innerClusters[tracklet.firstClusterIndex].yCoordinate;
78 originPoint[2] = innerClusters[tracklet.firstClusterIndex].zCoordinate;
79
80 cosinesDirector[0] = outerClusters[tracklet.secondClusterIndex].xCoordinate - innerClusters[tracklet.firstClusterIndex].xCoordinate;
81 cosinesDirector[1] = outerClusters[tracklet.secondClusterIndex].yCoordinate - innerClusters[tracklet.firstClusterIndex].yCoordinate;
82 cosinesDirector[2] = outerClusters[tracklet.secondClusterIndex].zCoordinate - innerClusters[tracklet.firstClusterIndex].zCoordinate;
83
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;
88
89 rof[0] = tracklet.rof[0];
90 rof[1] = tracklet.rof[1];
91}
92
93// static functions:
94inline float Line::getDistanceFromPoint(const Line& line, const std::array<float, 3>& point)
95{
96 float DCASquared{0};
97 float cdelta{0};
98 for (int i{0}; i < 3; ++i) {
99 cdelta -= line.cosinesDirector[i] * (line.originPoint[i] - point[i]);
100 }
101 for (int i{0}; i < 3; ++i) {
102 DCASquared += (line.originPoint[i] - point[i] + line.cosinesDirector[i] * cdelta) *
103 (line.originPoint[i] - point[i] + line.cosinesDirector[i] * cdelta);
104 }
105 return o2::gpu::CAMath::Sqrt(DCASquared);
106}
107
108GPUhdi() float Line::getDistanceFromPoint(const Line& line, const float point[3])
109{
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);
120}
121
122GPUhdi() float Line::getDCA(const Line& firstLine, const Line& secondLine, const float precision)
123{
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);
134 }
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);
142}
143
144GPUhdi() void Line::getDCAComponents(const Line& line, const float point[3], float destArray[6])
145{
146 float cdelta{0.};
147 for (int i{0}; i < 3; ++i) {
148 cdelta -= line.cosinesDirector[i] * (line.originPoint[i] - point[i]);
149 }
150
151 destArray[0] = line.originPoint[0] - point[0] + line.cosinesDirector[0] * cdelta;
152 destArray[3] = line.originPoint[1] - point[1] + line.cosinesDirector[1] * cdelta;
153 destArray[5] = line.originPoint[2] - point[2] + line.cosinesDirector[2] * cdelta;
154 destArray[1] = o2::gpu::CAMath::Sqrt(destArray[0] * destArray[0] + destArray[3] * destArray[3]);
155 destArray[2] = o2::gpu::CAMath::Sqrt(destArray[0] * destArray[0] + destArray[5] * destArray[5]);
156 destArray[4] = o2::gpu::CAMath::Sqrt(destArray[3] * destArray[3] + destArray[5] * destArray[5]);
157}
158
159inline bool Line::operator==(const Line& rhs) const
160{
161 bool val{false};
162 for (int i{0}; i < 3; ++i) {
163 val &= this->originPoint[i] == rhs.originPoint[i];
164 }
165 return val;
166}
167
168inline bool Line::operator!=(const Line& rhs) const
169{
170 return !(*this == rhs);
171}
172
173GPUhdi() void Line::print() const
174{
175 printf("Line: originPoint = (%f, %f, %f), cosinesDirector = (%f, %f, %f), rofs = (%hd, %hd)\n",
176 originPoint[0], originPoint[1], originPoint[2], cosinesDirector[0], cosinesDirector[1], cosinesDirector[2], rof[0], rof[1]);
177}
178
179class ClusterLines final
180{
181 public:
182 ClusterLines() = default;
183 ClusterLines(const int firstLabel, const Line& firstLine, const int secondLabel, const Line& secondLine,
184 const bool weight = false);
185 ClusterLines(const Line& firstLine, const Line& secondLine);
186 void add(const int& lineLabel, const Line& line, const bool& weight = false);
187 void computeClusterCentroid();
188 void updateROFPoll(const Line&);
189 inline std::vector<int>& getLabels()
190 {
191 return mLabels;
192 }
193 inline int getSize() const { return mLabels.size(); }
194 inline short getROF() const { return mROF; }
195 inline std::array<float, 3> getVertex() const { return mVertex; }
196 inline std::array<float, 6> getRMS2() const { return mRMS2; }
197 inline float getAvgDistance2() const { return mAvgDistance2; }
198
199 bool operator==(const ClusterLines&) const;
200
201 protected:
202 std::array<double, 6> mAMatrix; // AX=B
203 std::array<double, 3> mBMatrix; // AX=B
204 std::vector<int> mLabels; // labels
205 std::array<float, 9> mWeightMatrix = {0.f}; // weight matrix
206 std::array<float, 3> mVertex = {0.f}; // cluster centroid position
207 std::array<float, 6> mRMS2 = {0.f}; // symmetric matrix: diagonal is RMS2
208 float mAvgDistance2 = 0.f; // substitute for chi2
209 int mROFWeight = 0; // rof weight for voting
210 short mROF = constants::UnusedIndex; // rof
211};
212
213} // namespace o2::its
214#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 GLuint GLfloat weight
Definition glcorearb.h:5477
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLfloat * val
Definition glcorearb.h:1582
GLenum GLint GLint * precision
Definition glcorearb.h:1899
int32_t const char int32_t line
constexpr int UnusedIndex
Definition Constants.h:30
GPUhdi() Line
Defining DataPointCompositeObject explicitly as copiable.
bool operator!=(const Line &) const
ClassDefNV(Line, 1)
float cosinesDirector[3]
GPUhd() void print() const
static std::array< float, 6 > getDCAComponents(const Line &line, const std::array< float, 3 > point)
GPUhd() unsigned char isEmpty() const
const float float destArray[6]
bool operator==(const Line &) const
const float point[3]
GPUhdi() auto getDeltaROF() const
GPUhdDefault() Line()=default
const Cluster const Cluster *static float getDistanceFromPoint(const Line &line, const std::array< float, 3 > &point)
float originPoint[3]
static bool areParallel(const Line &, const Line &, const float precision=constants::Tolerance)
short getMinROF() const
bool operator==(const CoarseLocation &a, const CoarseLocation &b)
VectorOfTObjectPtrs other