Warning, file /include/root/TEveVector.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TEveVector
0013 #define ROOT_TEveVector
0014
0015 #include "Rtypes.h"
0016 #include "TMath.h"
0017 #include <cstddef>
0018
0019 class TVector3;
0020
0021
0022
0023
0024
0025
0026 template <typename TT>
0027 class TEveVectorT
0028 {
0029 public:
0030 TT fX, fY, fZ;
0031
0032 TEveVectorT() : fX(0), fY(0), fZ(0) {}
0033 template <typename OO>
0034 TEveVectorT(const TEveVectorT<OO>& v) : fX(v.fX), fY(v.fY), fZ(v.fZ) {}
0035 TEveVectorT(const Float_t* v) : fX(v[0]), fY(v[1]), fZ(v[2]) {}
0036 TEveVectorT(const Double_t* v) : fX(v[0]), fY(v[1]), fZ(v[2]) {}
0037 TEveVectorT(TT x, TT y, TT z) : fX(x), fY(y), fZ(z) {}
0038
0039 void Dump() const;
0040
0041 #ifdef R__WIN32
0042
0043
0044
0045 const TT *Arr() const
0046 {
0047 if (offsetof(TEveVectorT, fZ) != offsetof(TEveVectorT, fX) + 2 * sizeof(TT))
0048 Error("TEveVectorT", "Subsequent nembers cannot be accessed as array!");
0049 return &fX;
0050 }
0051 TT *Arr()
0052 {
0053 if (offsetof(TEveVectorT, fZ) != offsetof(TEveVectorT, fX) + 2 * sizeof(TT))
0054 Error("TEveVectorT", "Subsequent nembers cannot be accessed as array!");
0055 return &fX;
0056 }
0057 #else
0058 const TT *Arr() const
0059 {
0060 static_assert(offsetof(TEveVectorT, fZ) == offsetof(TEveVectorT, fX) + 2 * sizeof(TT),
0061 "Subsequent nembers cannot be accessed as array!");
0062 return &fX;
0063 }
0064 TT *Arr()
0065 {
0066 static_assert(offsetof(TEveVectorT, fZ) == offsetof(TEveVectorT, fX) + 2 * sizeof(TT),
0067 "Subsequent nembers cannot be accessed as array!");
0068 return &fX;
0069 }
0070 #endif
0071
0072 operator const TT*() const { return Arr(); }
0073 operator TT*() { return Arr(); }
0074
0075 TT operator [] (Int_t idx) const { return Arr()[idx]; }
0076 TT& operator [] (Int_t idx) { return Arr()[idx]; }
0077
0078 TEveVectorT& operator*=(TT s) { fX *= s; fY *= s; fZ *= s; return *this; }
0079 TEveVectorT& operator+=(const TEveVectorT& v) { fX += v.fX; fY += v.fY; fZ += v.fZ; return *this; }
0080 TEveVectorT& operator-=(const TEveVectorT& v) { fX -= v.fX; fY -= v.fY; fZ -= v.fZ; return *this; }
0081
0082 void Set(const Float_t* v) { fX = v[0]; fY = v[1]; fZ = v[2]; }
0083 void Set(const Double_t* v) { fX = v[0]; fY = v[1]; fZ = v[2]; }
0084 void Set(TT x, TT y, TT z) { fX = x; fY = y; fZ = z; }
0085 void Set(const TVector3& v);
0086
0087 template <typename OO>
0088 void Set(const TEveVectorT<OO>& v) { fX = v.fX; fY = v.fY; fZ = v.fZ; }
0089
0090 void NegateXYZ() { fX = - fX; fY = -fY; fZ = -fZ; }
0091 TT Normalize(TT length=1);
0092
0093 TT Phi() const;
0094 TT Theta() const;
0095 TT CosTheta() const;
0096 TT Eta() const;
0097
0098 TT Mag2() const { return fX*fX + fY*fY + fZ*fZ; }
0099 TT Mag() const { return TMath::Sqrt(Mag2()); }
0100
0101 TT Perp2() const { return fX*fX + fY*fY; }
0102 TT Perp() const { return TMath::Sqrt(Perp2()); }
0103 TT R() const { return Perp(); }
0104
0105 TT Distance(const TEveVectorT& v) const;
0106 TT SquareDistance(const TEveVectorT& v) const;
0107
0108 TT Dot(const TEveVectorT& a) const;
0109
0110 TEveVectorT Cross(const TEveVectorT& a) const;
0111
0112 TEveVectorT& Sub(const TEveVectorT& a, const TEveVectorT& b);
0113 TEveVectorT& Mult(const TEveVectorT& a, TT af);
0114
0115 TEveVectorT Orthogonal() const;
0116 void OrthoNormBase(TEveVectorT& a, TEveVectorT& b) const;
0117
0118 Bool_t IsZero() const { return fX == 0 && fY == 0 && fZ == 0; }
0119
0120 ClassDefNV(TEveVectorT, 2);
0121 };
0122
0123 typedef TEveVectorT<Float_t> TEveVector;
0124 typedef TEveVectorT<Float_t> TEveVectorF;
0125 typedef TEveVectorT<Double_t> TEveVectorD;
0126
0127
0128 template<typename TT>
0129 inline TT TEveVectorT<TT>::Phi() const
0130 {
0131 return fX == 0 && fY == 0 ? 0 : TMath::ATan2(fY, fX);
0132 }
0133
0134
0135 template<typename TT>
0136 inline TT TEveVectorT<TT>::Theta() const
0137 {
0138 return fX == 0 && fY == 0 && fZ == 0 ? 0 : TMath::ATan2(Perp(), fZ);
0139 }
0140
0141
0142 template<typename TT>
0143 inline TT TEveVectorT<TT>::CosTheta() const
0144 {
0145 Float_t ptot = Mag(); return ptot == 0 ? 1 : fZ/ptot;
0146 }
0147
0148
0149 template<typename TT>
0150 inline TT TEveVectorT<TT>::Distance(const TEveVectorT& b) const
0151 {
0152 return TMath::Sqrt((fX - b.fX)*(fX - b.fX) +
0153 (fY - b.fY)*(fY - b.fY) +
0154 (fZ - b.fZ)*(fZ - b.fZ));
0155 }
0156
0157
0158 template<typename TT>
0159 inline TT TEveVectorT<TT>::SquareDistance(const TEveVectorT& b) const
0160 {
0161 return ((fX - b.fX) * (fX - b.fX) +
0162 (fY - b.fY) * (fY - b.fY) +
0163 (fZ - b.fZ) * (fZ - b.fZ));
0164 }
0165
0166
0167 template<typename TT>
0168 inline TT TEveVectorT<TT>::Dot(const TEveVectorT& a) const
0169 {
0170 return a.fX*fX + a.fY*fY + a.fZ*fZ;
0171 }
0172
0173
0174 template<typename TT>
0175 inline TEveVectorT<TT> TEveVectorT<TT>::Cross(const TEveVectorT<TT>& a) const
0176 {
0177 TEveVectorT<TT> r;
0178 r.fX = fY * a.fZ - fZ * a.fY;
0179 r.fY = fZ * a.fX - fX * a.fZ;
0180 r.fZ = fX * a.fY - fY * a.fX;
0181 return r;
0182 }
0183
0184
0185 template<typename TT>
0186 inline TEveVectorT<TT>& TEveVectorT<TT>::Sub(const TEveVectorT<TT>& a, const TEveVectorT<TT>& b)
0187 {
0188 fX = a.fX - b.fX;
0189 fY = a.fY - b.fY;
0190 fZ = a.fZ - b.fZ;
0191 return *this;
0192 }
0193
0194
0195 template<typename TT>
0196 inline TEveVectorT<TT>& TEveVectorT<TT>::Mult(const TEveVectorT<TT>& a, TT af)
0197 {
0198 fX = a.fX * af;
0199 fY = a.fY * af;
0200 fZ = a.fZ * af;
0201 return *this;
0202 }
0203
0204
0205 template<typename TT>
0206 inline TEveVectorT<TT> operator+(const TEveVectorT<TT>& a, const TEveVectorT<TT>& b)
0207 {
0208 TEveVectorT<TT> r(a);
0209 return r += b;
0210 }
0211
0212
0213 template<typename TT>
0214 inline TEveVectorT<TT> operator-(const TEveVectorT<TT>& a, const TEveVectorT<TT>& b)
0215 {
0216 TEveVectorT<TT> r(a);
0217 return r -= b;
0218 }
0219
0220
0221 template<typename TT>
0222 inline TEveVectorT<TT> operator*(const TEveVectorT<TT>& a, TT b)
0223 {
0224 TEveVectorT<TT> r(a);
0225 return r *= b;
0226 }
0227
0228
0229 template<typename TT>
0230 inline TEveVectorT<TT> operator*(TT b, const TEveVectorT<TT>& a)
0231 {
0232 TEveVectorT<TT> r(a);
0233 return r *= b;
0234 }
0235
0236
0237
0238
0239
0240
0241 template <typename TT>
0242 class TEveVector4T : public TEveVectorT<TT>
0243 {
0244 typedef TEveVectorT<TT> TP;
0245
0246 public:
0247 TT fT;
0248
0249 TEveVector4T() : TP(), fT(0) {}
0250 template <typename OO>
0251 TEveVector4T(const TEveVectorT<OO>& v) : TP(v.fX, v.fY, v.fZ), fT(0) {}
0252 template <typename OO>
0253 TEveVector4T(const TEveVectorT<OO>& v, Float_t t) : TP(v.fX, v.fY, v.fZ), fT(t) {}
0254 template <typename OO>
0255 TEveVector4T(const TEveVector4T<OO>& v) : TP(v.fX, v.fY, v.fZ), fT(v.fT) {}
0256 TEveVector4T(const Float_t* v) : TP(v), fT(v[3]) {}
0257 TEveVector4T(const Double_t* v) : TP(v), fT(v[3]) {}
0258 TEveVector4T(TT x, TT y, TT z, TT t=0) : TP(x, y, z), fT(t) {}
0259
0260 void Dump() const;
0261
0262 TEveVector4T& operator*=(TT s) { TP::operator*=(s); fT *= s; return *this; }
0263 TEveVector4T& operator+=(const TEveVector4T& v) { TP::operator+=(v); fT += v.fT; return *this; }
0264 TEveVector4T& operator-=(const TEveVector4T& v) { TP::operator-=(v); fT -= v.fT; return *this; }
0265
0266 using TP::operator+=;
0267 using TP::operator-=;
0268
0269 ClassDefNV(TEveVector4T, 1);
0270 };
0271
0272 typedef TEveVector4T<Float_t> TEveVector4;
0273 typedef TEveVector4T<Float_t> TEveVector4F;
0274 typedef TEveVector4T<Double_t> TEveVector4D;
0275
0276
0277 template<typename TT>
0278 inline TEveVector4T<TT> operator+(const TEveVector4T<TT>& a, const TEveVector4T<TT>& b)
0279 {
0280 return TEveVector4T<TT>(a.fX + b.fX, a.fY + b.fY, a.fZ + b.fZ, a.fT + b.fT);
0281 }
0282
0283
0284 template<typename TT>
0285 inline TEveVector4T<TT> operator-(const TEveVector4T<TT>& a, const TEveVector4T<TT>& b)
0286 {
0287 return TEveVector4T<TT>(a.fX - b.fX, a.fY - b.fY, a.fZ - b.fZ, a.fT - b.fT);
0288 }
0289
0290
0291 template<typename TT>
0292 inline TEveVector4T<TT> operator*(const TEveVector4T<TT>& a, TT b)
0293 {
0294 return TEveVector4T<TT>(a.fX*b, a.fY*b, a.fZ*b, a.fT*b);
0295 }
0296
0297
0298 template<typename TT>
0299 inline TEveVector4T<TT> operator*(TT b, const TEveVector4T<TT>& a)
0300 {
0301 return TEveVector4T<TT>(a.fX*b, a.fY*b, a.fZ*b, a.fT*b);
0302 }
0303
0304
0305
0306
0307
0308
0309 template <typename TT>
0310 class TEveVector2T
0311 {
0312 public:
0313 TT fX, fY;
0314
0315 TEveVector2T() : fX(0), fY(0) {}
0316 template <typename OO>
0317 TEveVector2T(const TEveVector2T<OO>& v) : fX(v.fX), fY(v.fY) {}
0318 TEveVector2T(const Float_t* v) : fX(v[0]), fY(v[1]) {}
0319 TEveVector2T(const Double_t* v) : fX(v[0]), fY(v[1]) {}
0320 TEveVector2T(TT x, TT y) : fX(x), fY(y) {}
0321
0322 void Dump() const;
0323
0324 operator const TT*() const { return &fX; }
0325 operator TT*() { return &fX; }
0326
0327 TEveVector2T& operator*=(TT s) { fX *= s; fY *= s; return *this; }
0328 TEveVector2T& operator+=(const TEveVector2T& v) { fX += v.fX; fY += v.fY; return *this; }
0329 TEveVector2T& operator-=(const TEveVector2T& v) { fX -= v.fX; fY -= v.fY; return *this; }
0330
0331 TT& operator[](Int_t idx) { return (&fX)[idx]; }
0332 TT operator[](Int_t idx) const { return (&fX)[idx]; }
0333
0334 const TT* Arr() const { return &fX; }
0335 TT* Arr() { return &fX; }
0336
0337 void Set(const Float_t* v) { fX = v[0]; fY = v[1]; }
0338 void Set(const Double_t* v) { fX = v[0]; fY = v[1]; }
0339 void Set(TT x, TT y) { fX = x; fY = y; }
0340
0341 template <typename OO>
0342 void Set(const TEveVector2T<OO>& v) { fX = v.fX; fY = v.fY; }
0343
0344 void NegateXY() { fX = - fX; fY = -fY; }
0345 void Normalize(TT length=1);
0346
0347 TT Phi() const;
0348
0349 TT Mag2() const { return fX*fX + fY*fY;}
0350 TT Mag() const { return TMath::Sqrt(Mag2());}
0351
0352 TT Distance(const TEveVector2T& v) const;
0353 TT SquareDistance(const TEveVector2T& v) const;
0354
0355 TT Dot(const TEveVector2T& a) const;
0356 TT Cross(const TEveVector2T& a) const;
0357
0358 TEveVector2T& Sub(const TEveVector2T& p, const TEveVector2T& q);
0359
0360 TEveVector2T& Mult(const TEveVector2T& a, TT af);
0361
0362 ClassDefNV(TEveVector2T, 1);
0363 };
0364
0365 typedef TEveVector2T<Float_t> TEveVector2;
0366 typedef TEveVector2T<Float_t> TEveVector2F;
0367 typedef TEveVector2T<Double_t> TEveVector2D;
0368
0369
0370 template<typename TT>
0371 inline TT TEveVector2T<TT>::Phi() const
0372 {
0373 return fX == 0.0 && fY == 0.0 ? 0.0 : TMath::ATan2(fY, fX);
0374 }
0375
0376
0377 template<typename TT>
0378 inline TT TEveVector2T<TT>::Distance( const TEveVector2T<TT>& b) const
0379 {
0380 return TMath::Sqrt((fX - b.fX)*(fX - b.fX) +
0381 (fY - b.fY)*(fY - b.fY));
0382 }
0383
0384
0385 template<typename TT>
0386 inline TT TEveVector2T<TT>::SquareDistance(const TEveVector2T<TT>& b) const
0387 {
0388 return ((fX - b.fX) * (fX - b.fX) +
0389 (fY - b.fY) * (fY - b.fY));
0390 }
0391
0392
0393 template<typename TT>
0394 inline TT TEveVector2T<TT>::Dot(const TEveVector2T<TT>& a) const
0395 {
0396 return a.fX*fX + a.fY*fY;
0397 }
0398
0399
0400 template<typename TT>
0401 inline TT TEveVector2T<TT>::Cross(const TEveVector2T<TT>& a) const
0402 {
0403 return fX * a.fY - fY * a.fX;
0404 }
0405
0406
0407 template<typename TT>
0408 inline TEveVector2T<TT>& TEveVector2T<TT>::Sub(const TEveVector2T<TT>& p, const TEveVector2T<TT>& q)
0409 {
0410 fX = p.fX - q.fX;
0411 fY = p.fY - q.fY;
0412 return *this;
0413 }
0414
0415
0416 template<typename TT>
0417 inline TEveVector2T<TT>& TEveVector2T<TT>::Mult(const TEveVector2T<TT>& a, TT af)
0418 {
0419 fX = a.fX * af;
0420 fY = a.fY * af;
0421 return *this;
0422 }
0423
0424
0425 template<typename TT>
0426 inline TEveVector2T<TT> operator+(const TEveVector2T<TT>& a, const TEveVector2T<TT>& b)
0427 {
0428 TEveVector2T<TT> r(a);
0429 return r += b;
0430 }
0431
0432
0433 template<typename TT>
0434 inline TEveVector2T<TT> operator-(const TEveVector2T<TT>& a, const TEveVector2T<TT>& b)
0435 {
0436 TEveVector2T<TT> r(a);
0437 return r -= b;
0438 }
0439
0440
0441 template<typename TT>
0442 inline TEveVector2T<TT> operator*(const TEveVector2T<TT>& a, TT b)
0443 {
0444 TEveVector2T<TT> r(a);
0445 return r *= b;
0446 }
0447
0448
0449 template<typename TT>
0450 inline TEveVector2T<TT> operator*(TT b, const TEveVector2T<TT>& a)
0451 {
0452 TEveVector2T<TT> r(a);
0453 return r *= b;
0454 }
0455
0456 #endif