Project
Loading...
Searching...
No Matches
Cartesian.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
15
16#ifndef ALICEO2_CARTESIAN3D_H
17#define ALICEO2_CARTESIAN3D_H
18
19#include "GPUCommonDef.h"
20#include "GPUCommonRtypes.h"
21#if (!defined(GPUCA_STANDALONE) || !defined(DGPUCA_NO_ROOT)) && !defined(GPUCA_GPUCODE) && !defined(GPUCOMMONRTYPES_H_ACTIVE)
22#include <Math/SMatrix.h>
23#include <Math/SVector.h>
24#include <Math/GenVector/DisplacementVector3D.h>
25#include <Math/GenVector/PositionVector3D.h>
26#include <Math/GenVector/Rotation3D.h>
27#include <Math/GenVector/Transform3D.h>
28#include <Math/GenVector/Translation3D.h>
29#include <Math/GenVector/DisplacementVector2D.h>
30#include <Math/GenVector/PositionVector2D.h>
31#include <TGeoMatrix.h>
32#include <iosfwd>
33#else
34#include "GPUCommonMath.h"
35#include "CartesianGPU.h"
36#include "SMatrixGPU.h"
37#endif
38
39#include "GPUROOTCartesianFwd.h"
40#include "GPUROOTSMatrixFwd.h"
41
42namespace o2
43{
44
45namespace math_utils
46{
47
48// more typedefs can follow
49
52
54 static constexpr int L2G = 0;
55 static constexpr int T2L = 1;
56 static constexpr int T2G = 2;
57 static constexpr int T2GRot = 3;
58};
59
60template <typename value_T>
62{
63 //
64 // class to perform rotation of 3D (around Z) and 2D points
65
66 public:
67 using value_t = value_T;
68
69 Rotation2D() = default;
70 Rotation2D(value_t cs, value_t sn) : mCos(cs), mSin(sn) {}
71 Rotation2D(value_t phiZ) : mCos(cos(phiZ)), mSin(sin(phiZ)) {}
72 ~Rotation2D() = default;
73 Rotation2D(const Rotation2D& src) = default;
75 Rotation2D& operator=(const Rotation2D& src) = default;
77
78 void set(value_t phiZ)
79 {
80 mCos = cos(phiZ);
81 mSin = sin(phiZ);
82 }
83
84 void set(value_t cs, value_t sn)
85 {
86 mCos = cs;
87 mSin = sn;
88 }
89
90 void getComponents(value_t& cs, value_t& sn) const
91 {
92 cs = mCos;
93 sn = mSin;
94 }
95
96 value_t getCos() const { return mCos; }
97 value_t getSin() const { return mSin; }
98
99 template <typename T>
101 { // local->master
102 return Point3D<T>(v.X() * mCos - v.Y() * mSin, v.X() * mSin + v.Y() * mCos, v.Z());
103 }
104
105 template <typename T>
107 { // master->local
108 return Point3D<T>(v.X() * mCos + v.Y() * mSin, -v.X() * mSin + v.Y() * mCos, v.Z());
109 }
110
111 template <typename T>
113 { // local->master
114 return Vector3D<T>(v.X() * mCos - v.Y() * mSin, v.X() * mSin + v.Y() * mCos, v.Z());
115 }
116
117 template <typename T>
119 { // master->local
120 return Vector3D<T>(v.X() * mCos + v.Y() * mSin, -v.X() * mSin + v.Y() * mCos, v.Z());
121 }
122
123 template <typename T>
125 { // local->master
126 return Point2D<T>(v.X() * mCos - v.Y() * mSin, v.X() * mSin + v.Y() * mCos);
127 }
128
129 template <typename T>
131 { // master->local
132 return Point2D<T>(v.X() * mCos + v.Y() * mSin, -v.X() * mSin + v.Y() * mCos);
133 }
134
135 template <typename T>
137 { // local->master
138 return Vector2D<T>(v.X() * mCos - v.Y() * mSin, v.X() * mSin + v.Y() * mCos);
139 }
140
141 template <typename T>
143 { // master->local
144 return Vector2D<T>(v.X() * mCos + v.Y() * mSin, -v.X() * mSin + v.Y() * mCos);
145 }
146
147 private:
148 value_t mCos = 1;
149 value_t mSin = 0;
150
151 ClassDefNV(Rotation2D, 2);
152};
153
156
157#if (!defined(GPUCA_STANDALONE) || !defined(DGPUCA_NO_ROOT)) && !defined(GPUCA_GPUCODE) && !defined(GPUCOMMONRTYPES_H_ACTIVE)
158
160{
161 //
162 // Class to perform geom.transformations (rotation and displacements only) in
163 // double precision over the cartesian points and vectors (float or double).
164 // Adds to the base ROOT::Math::Transform3D<double> class a convertor from
165 // TGeoMatrix.
166 // To be used instead of TGeoHMatrix for all transformations of hits,
167 // clusters etc.
168 //
169
170 public:
171 Transform3D() = default;
172 Transform3D(const TGeoMatrix& m);
173 ~Transform3D() = default;
174
175 // inherit assignment operators of the base class
176 using ROOT::Math::Transform3D::operator=;
177
178 // to avoid conflict between the base Transform3D(const ForeignMatrix & m) and
179 // Transform3D(const TGeoMatrix &m) constructors we cannot inherit base c-tors,
180 // therefore we redefine them here
181 Transform3D(const ROOT::Math::Rotation3D& r, const Vector& v) : ROOT::Math::Transform3D(r, v) {}
182 Transform3D(const ROOT::Math::Rotation3D& r, const ROOT::Math::Translation3D& t) : ROOT::Math::Transform3D(r, t) {}
183 template <class IT>
184 Transform3D(IT begin, IT end) : ROOT::Math::Transform3D(begin, end)
185 {
186 }
187
188 // conversion operator to TGeoHMatrix
189 operator TGeoHMatrix&() const
190 {
191 static TGeoHMatrix tmp;
192 double rot[9], tra[3];
193 GetComponents(rot[0], rot[1], rot[2], tra[0], rot[3], rot[4], rot[5], tra[1], rot[6], rot[7], rot[8], tra[2]);
194 tmp.SetRotation(rot);
195 tmp.SetTranslation(tra);
196 return tmp;
197 }
198
199 void set(const TGeoMatrix& m); // set parameters from TGeoMatrix
200
201 using ROOT::Math::Transform3D::operator();
202 // the local->master transformation for points and vectors can be
203 // done in operator form (inherited from base Transform3D) as
204 // Point3D pnt;
205 // Transform3D trans;
206 // auto pntTr0 = trans(pnt); // 1st version
207 // auto pntTr1 = trans*pnt; // 2nd version
208 //
209 // For the inverse transform we define our own operator^
210
211 template <typename T>
213 { // master->local
214 return ApplyInverse(p);
215 }
216
217 template <typename T>
219 { // local->master
220 return ApplyInverse(v);
221 }
222
223 // TGeoHMatrix-like aliases
224 template <typename T>
225 void LocalToMaster(const Point3D<T>& loc, Point3D<T>& mst) const
226 {
227 mst = operator()(loc);
228 }
229
230 template <typename T>
231 void MasterToLocal(const Point3D<T>& mst, Point3D<T>& loc) const
232 {
233 loc = operator^(mst);
234 }
235
236 template <typename T>
237 void LocalToMasterVect(const Point3D<T>& loc, Point3D<T>& mst) const
238 {
239 mst = operator()(loc);
240 }
241
242 template <typename T>
243 void MasterToLocalVect(const Point3D<T>& mst, Point3D<T>& loc) const
244 {
245 loc = operator^(mst);
246 }
247
248 void print() const;
249
251};
252#endif // Disable for GPU
253
254// Aliasing of the Dot(SVector a, SVector b) operation between SVectors
255#if (!defined(GPUCA_STANDALONE) || !defined(DGPUCA_NO_ROOT)) && !defined(GPUCA_GPUCODE) && !defined(GPUCOMMONRTYPES_H_ACTIVE)
256template <class T, unsigned int D>
257inline T Dot(const SVector<T, D>& lhs, const SVector<T, D>& rhs)
258{
259 return ROOT::Math::Dot(lhs, rhs);
260}
261
262template <class T, unsigned int D1, unsigned int D2, class R>
264{
265 return ROOT::Math::Similarity(lhs, rhs);
266}
267#else
268template <class T, unsigned int D>
269GPUdi() T Dot(const SVector<T, D>& lhs, const SVector<T, D>& rhs)
270{
271 return o2::math_utils::detail::Dot(lhs, rhs);
272}
273
274template <class T, unsigned int D1, unsigned int D2, class R>
275GPUdi() SMatrix<T, D1, D1, MatRepSym<T, D1>> Similarity(const SMatrix<T, D1, D2, R>& lhs, const SMatrix<T, D2, D2, MatRepSym<T, D2>>& rhs)
276{
277 return o2::math_utils::detail::Similarity(lhs, rhs);
278}
279#endif // Disable for GPU
280
281} // namespace math_utils
282} // namespace o2
283
284#if (!defined(GPUCA_STANDALONE) || !defined(DGPUCA_NO_ROOT)) && !defined(GPUCA_GPUCODE) && !defined(GPUCOMMONRTYPES_H_ACTIVE)
285std::ostream& operator<<(std::ostream& os, const o2::math_utils::Rotation2Df_t& t);
286std::ostream& operator<<(std::ostream& os, const o2::math_utils::Rotation2Dd_t& t);
287
288namespace std
289{
290
302template <typename T>
303struct is_trivially_copyable<o2::math_utils::Point3D<T>> : std::true_type {
304};
305} // namespace std
306#endif // Disable for GPU
307
308#endif
std::ostream & operator<<(std::ostream &os, const o2::math_utils::Rotation2Df_t &t)
Definition Cartesian.cxx:57
This is a close porting of the SMatrix and SVectorGPU ROOT interfaces. Only parts strictly requiring ...
transformation types
Definition Cartesian.h:62
Rotation2D(value_t phiZ)
Definition Cartesian.h:71
Vector2D< T > operator^(const Vector2D< T > &v) const
Definition Cartesian.h:142
void set(value_t cs, value_t sn)
Definition Cartesian.h:84
value_t getSin() const
Definition Cartesian.h:97
Rotation2D & operator=(const Rotation2D &src)=default
Rotation2D & operator=(Rotation2D &&src)=default
Point3D< T > operator()(const Point3D< T > &v) const
Definition Cartesian.h:100
Vector2D< T > operator()(const Vector2D< T > &v) const
Definition Cartesian.h:136
void getComponents(value_t &cs, value_t &sn) const
Definition Cartesian.h:90
Point2D< T > operator^(const Point2D< T > &v) const
Definition Cartesian.h:130
Point3D< T > operator^(const Point3D< T > &v) const
Definition Cartesian.h:106
Rotation2D(value_t cs, value_t sn)
Definition Cartesian.h:70
Rotation2D(const Rotation2D &src)=default
value_t getCos() const
Definition Cartesian.h:96
Point2D< T > operator()(const Point2D< T > &v) const
Definition Cartesian.h:124
void set(value_t phiZ)
Definition Cartesian.h:78
Vector3D< T > operator()(const Vector3D< T > &v) const
Definition Cartesian.h:112
Rotation2D(Rotation2D &&src)=default
Vector3D< T > operator^(const Vector3D< T > &v) const
Definition Cartesian.h:118
void MasterToLocal(const Point3D< T > &mst, Point3D< T > &loc) const
Definition Cartesian.h:231
Vector3D< T > operator^(const Vector3D< T > &v) const
Definition Cartesian.h:218
void LocalToMasterVect(const Point3D< T > &loc, Point3D< T > &mst) const
Definition Cartesian.h:237
void MasterToLocalVect(const Point3D< T > &mst, Point3D< T > &loc) const
Definition Cartesian.h:243
ClassDefNV(Transform3D, 1)
void set(const TGeoMatrix &m)
Definition Cartesian.cxx:34
Transform3D(const ROOT::Math::Rotation3D &r, const ROOT::Math::Translation3D &t)
Definition Cartesian.h:182
void LocalToMaster(const Point3D< T > &loc, Point3D< T > &mst) const
Definition Cartesian.h:225
Point3D< T > operator^(const Point3D< T > &p) const
Definition Cartesian.h:212
Transform3D(const ROOT::Math::Rotation3D &r, const Vector &v)
Definition Cartesian.h:181
Transform3D(IT begin, IT end)
Definition Cartesian.h:184
const GLfloat * m
Definition glcorearb.h:4066
GLenum src
Definition glcorearb.h:1767
GLuint GLuint end
Definition glcorearb.h:469
const GLdouble * v
Definition glcorearb.h:832
GLboolean r
Definition glcorearb.h:1233
MatRepSymGPU< T, D1 > Similarity(const SMatrixGPU< T, D1, D2, R > &lhs, const SMatrixGPU< T, D2, D2, MatRepSymGPU< T, D2 > > &rhs)
ROOT::Math::MatRepSym< T, D > MatRepSym
GPUdi() float to02Pi(float phi)
Definition Utils.h:30
ROOT::Math::SVector< T, N > SVector
ROOT::Math::SMatrix< T, D1, D2, R > SMatrix
SMatrix< T, D1, D1, MatRepSym< T, D1 > > Similarity(const SMatrix< T, D1, D2, R > &lhs, const SMatrix< T, D2, D2, MatRepSym< T, D2 > > &rhs)
Definition Cartesian.h:263
T Dot(const SVector< T, D > &lhs, const SVector< T, D > &rhs)
Definition Cartesian.h:257
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
static constexpr int L2G
Definition Cartesian.h:54
static constexpr int T2L
Definition Cartesian.h:55
static constexpr int T2GRot
Definition Cartesian.h:57
static constexpr int T2G
Definition Cartesian.h:56