Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TEveVector.h
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Author: Matevz Tadel 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TEveVector
13#define ROOT_TEveVector
14
15#include "Rtypes.h"
16#include "TMath.h"
17#include <cstddef>
18
19class TVector3;
20
21
22//==============================================================================
23// TEveVectorT
24//==============================================================================
25
26template <typename TT>
28{
29public:
30 TT fX, fY, fZ; // Components of the vector.
31
32 TEveVectorT() : fX(0), fY(0), fZ(0) {}
33 template <typename OO>
34 TEveVectorT(const TEveVectorT<OO>& v) : fX(v.fX), fY(v.fY), fZ(v.fZ) {}
35 TEveVectorT(const Float_t* v) : fX(v[0]), fY(v[1]), fZ(v[2]) {}
36 TEveVectorT(const Double_t* v) : fX(v[0]), fY(v[1]), fZ(v[2]) {}
37 TEveVectorT(TT x, TT y, TT z) : fX(x), fY(y), fZ(z) {}
38
39 void Dump() const;
40
41#ifdef R__WIN32
42 // This fixes the following rootcling error when generating the dictionary:
43 // error G34C21FBE: static_assert expression is not an integral constant expression
44 // FIXME: check if the error is fixed when upgrading llvm/clang
45 const TT *Arr() const
46 {
47 if (offsetof(TEveVectorT, fZ) != offsetof(TEveVectorT, fX) + 2 * sizeof(TT))
48 Error("TEveVectorT", "Subsequent nembers cannot be accessed as array!");
49 return &fX;
50 }
51 TT *Arr()
52 {
53 if (offsetof(TEveVectorT, fZ) != offsetof(TEveVectorT, fX) + 2 * sizeof(TT))
54 Error("TEveVectorT", "Subsequent nembers cannot be accessed as array!");
55 return &fX;
56 }
57#else
58 const TT *Arr() const
59 {
60 static_assert(offsetof(TEveVectorT, fZ) == offsetof(TEveVectorT, fX) + 2 * sizeof(TT),
61 "Subsequent nembers cannot be accessed as array!");
62 return &fX;
63 }
64 TT *Arr()
65 {
66 static_assert(offsetof(TEveVectorT, fZ) == offsetof(TEveVectorT, fX) + 2 * sizeof(TT),
67 "Subsequent nembers cannot be accessed as array!");
68 return &fX;
69 }
70#endif
71
72 operator const TT*() const { return Arr(); }
73 operator TT*() { return Arr(); }
74
75 TT operator [] (Int_t idx) const { return Arr()[idx]; }
76 TT& operator [] (Int_t idx) { return Arr()[idx]; }
77
78 TEveVectorT& operator*=(TT s) { fX *= s; fY *= s; fZ *= s; return *this; }
79 TEveVectorT& operator+=(const TEveVectorT& v) { fX += v.fX; fY += v.fY; fZ += v.fZ; return *this; }
80 TEveVectorT& operator-=(const TEveVectorT& v) { fX -= v.fX; fY -= v.fY; fZ -= v.fZ; return *this; }
81
82 void Set(const Float_t* v) { fX = v[0]; fY = v[1]; fZ = v[2]; }
83 void Set(const Double_t* v) { fX = v[0]; fY = v[1]; fZ = v[2]; }
84 void Set(TT x, TT y, TT z) { fX = x; fY = y; fZ = z; }
85 void Set(const TVector3& v);
86
87 template <typename OO>
88 void Set(const TEveVectorT<OO>& v) { fX = v.fX; fY = v.fY; fZ = v.fZ; }
89
90 void NegateXYZ() { fX = - fX; fY = -fY; fZ = -fZ; }
91 TT Normalize(TT length=1);
92
93 TT Phi() const;
94 TT Theta() const;
95 TT CosTheta() const;
96 TT Eta() const;
97
98 TT Mag2() const { return fX*fX + fY*fY + fZ*fZ; }
99 TT Mag() const { return TMath::Sqrt(Mag2()); }
100
101 TT Perp2() const { return fX*fX + fY*fY; }
102 TT Perp() const { return TMath::Sqrt(Perp2()); }
103 TT R() const { return Perp(); }
104
105 TT Distance(const TEveVectorT& v) const;
106 TT SquareDistance(const TEveVectorT& v) const;
107
108 TT Dot(const TEveVectorT& a) const;
109
111
113 TEveVectorT& Mult(const TEveVectorT& a, TT af);
114
115 TEveVectorT Orthogonal() const;
116 void OrthoNormBase(TEveVectorT& a, TEveVectorT& b) const;
117
118 Bool_t IsZero() const { return fX == 0 && fY == 0 && fZ == 0; }
119
120 ClassDefNV(TEveVectorT, 2); // A three-vector template without TObject inheritance and virtual functions.
121};
122
126
127//______________________________________________________________________________
128template<typename TT>
129inline TT TEveVectorT<TT>::Phi() const
130{
131 return fX == 0 && fY == 0 ? 0 : TMath::ATan2(fY, fX);
132}
133
134//______________________________________________________________________________
135template<typename TT>
136inline TT TEveVectorT<TT>::Theta() const
137{
138 return fX == 0 && fY == 0 && fZ == 0 ? 0 : TMath::ATan2(Perp(), fZ);
139}
140
141//______________________________________________________________________________
142template<typename TT>
144{
145 Float_t ptot = Mag(); return ptot == 0 ? 1 : fZ/ptot;
146}
147
148//______________________________________________________________________________
149template<typename TT>
151{
152 return TMath::Sqrt((fX - b.fX)*(fX - b.fX) +
153 (fY - b.fY)*(fY - b.fY) +
154 (fZ - b.fZ)*(fZ - b.fZ));
155}
156
157//______________________________________________________________________________
158template<typename TT>
160{
161 return ((fX - b.fX) * (fX - b.fX) +
162 (fY - b.fY) * (fY - b.fY) +
163 (fZ - b.fZ) * (fZ - b.fZ));
164}
165
166//______________________________________________________________________________
167template<typename TT>
168inline TT TEveVectorT<TT>::Dot(const TEveVectorT& a) const
169{
170 return a.fX*fX + a.fY*fY + a.fZ*fZ;
171}
172
173//______________________________________________________________________________
174template<typename TT>
176{
178 r.fX = fY * a.fZ - fZ * a.fY;
179 r.fY = fZ * a.fX - fX * a.fZ;
180 r.fZ = fX * a.fY - fY * a.fX;
181 return r;
182}
183
184//______________________________________________________________________________
185template<typename TT>
187{
188 fX = a.fX - b.fX;
189 fY = a.fY - b.fY;
190 fZ = a.fZ - b.fZ;
191 return *this;
192}
193
194//______________________________________________________________________________
195template<typename TT>
197{
198 fX = a.fX * af;
199 fY = a.fY * af;
200 fZ = a.fZ * af;
201 return *this;
202}
203
204//______________________________________________________________________________
205template<typename TT>
207{
209 return r += b;
210}
211
212//______________________________________________________________________________
213template<typename TT>
215{
217 return r -= b;
218}
219
220//______________________________________________________________________________
221template<typename TT>
223{
225 return r *= b;
226}
227
228//______________________________________________________________________________
229template<typename TT>
231{
233 return r *= b;
234}
235
236
237//==============================================================================
238// TEveVector4T
239//==============================================================================
240
241template <typename TT>
242class TEveVector4T : public TEveVectorT<TT>
243{
245
246public:
247 TT fT;
248
249 TEveVector4T() : TP(), fT(0) {}
250 template <typename OO>
251 TEveVector4T(const TEveVectorT<OO>& v) : TP(v.fX, v.fY, v.fZ), fT(0) {}
252 template <typename OO>
253 TEveVector4T(const TEveVectorT<OO>& v, Float_t t) : TP(v.fX, v.fY, v.fZ), fT(t) {}
254 template <typename OO>
256 TEveVector4T(const Float_t* v) : TP(v), fT(v[3]) {}
257 TEveVector4T(const Double_t* v) : TP(v), fT(v[3]) {}
258 TEveVector4T(TT x, TT y, TT z, TT t=0) : TP(x, y, z), fT(t) {}
259
260 void Dump() const;
261
262 TEveVector4T& operator*=(TT s) { TP::operator*=(s); fT *= s; return *this; }
263 TEveVector4T& operator+=(const TEveVector4T& v) { TP::operator+=(v); fT += v.fT; return *this; }
264 TEveVector4T& operator-=(const TEveVector4T& v) { TP::operator-=(v); fT -= v.fT; return *this; }
265
266 using TP::operator+=;
267 using TP::operator-=;
268
269 ClassDefNV(TEveVector4T, 1); // A four-vector template without TObject inheritance and virtual functions.
270};
271
275
276//______________________________________________________________________________
277template<typename TT>
279{
280 return TEveVector4T<TT>(a.fX + b.fX, a.fY + b.fY, a.fZ + b.fZ, a.fT + b.fT);
281}
282
283//______________________________________________________________________________
284template<typename TT>
286{
287 return TEveVector4T<TT>(a.fX - b.fX, a.fY - b.fY, a.fZ - b.fZ, a.fT - b.fT);
288}
289
290//______________________________________________________________________________
291template<typename TT>
293{
294 return TEveVector4T<TT>(a.fX*b, a.fY*b, a.fZ*b, a.fT*b);
295}
296
297//______________________________________________________________________________
298template<typename TT>
300{
301 return TEveVector4T<TT>(a.fX*b, a.fY*b, a.fZ*b, a.fT*b);
302}
303
304
305//==============================================================================
306// TEveVector2T
307//==============================================================================
308
309template <typename TT>
311{
312public:
313 TT fX, fY; // Components of the point.
314
315 TEveVector2T() : fX(0), fY(0) {}
316 template <typename OO>
318 TEveVector2T(const Float_t* v) : fX(v[0]), fY(v[1]) {}
319 TEveVector2T(const Double_t* v) : fX(v[0]), fY(v[1]) {}
320 TEveVector2T(TT x, TT y) : fX(x), fY(y) {}
321
322 void Dump() const;
323
324 operator const TT*() const { return &fX; }
325 operator TT*() { return &fX; }
326
327 TEveVector2T& operator*=(TT s) { fX *= s; fY *= s; return *this; }
328 TEveVector2T& operator+=(const TEveVector2T& v) { fX += v.fX; fY += v.fY; return *this; }
329 TEveVector2T& operator-=(const TEveVector2T& v) { fX -= v.fX; fY -= v.fY; return *this; }
330
331 TT& operator[](Int_t idx) { return (&fX)[idx]; }
332 TT operator[](Int_t idx) const { return (&fX)[idx]; }
333
334 const TT* Arr() const { return &fX; }
335 TT* Arr() { return &fX; }
336
337 void Set(const Float_t* v) { fX = v[0]; fY = v[1]; }
338 void Set(const Double_t* v) { fX = v[0]; fY = v[1]; }
339 void Set(TT x, TT y) { fX = x; fY = y; }
340
341 template <typename OO>
342 void Set(const TEveVector2T<OO>& v) { fX = v.fX; fY = v.fY; }
343
344 void NegateXY() { fX = - fX; fY = -fY; }
345 void Normalize(TT length=1);
346
347 TT Phi() const;
348
349 TT Mag2() const { return fX*fX + fY*fY;}
350 TT Mag() const { return TMath::Sqrt(Mag2());}
351
352 TT Distance(const TEveVector2T& v) const;
353 TT SquareDistance(const TEveVector2T& v) const;
354
355 TT Dot(const TEveVector2T& a) const;
356 TT Cross(const TEveVector2T& a) const;
357
358 TEveVector2T& Sub(const TEveVector2T& p, const TEveVector2T& q);
359
360 TEveVector2T& Mult(const TEveVector2T& a, TT af);
361
362 ClassDefNV(TEveVector2T, 1); // // A two-vector template without TObject inheritance and virtual functions.
363};
364
368
369//______________________________________________________________________________
370template<typename TT>
371inline TT TEveVector2T<TT>::Phi() const
372{
373 return fX == 0.0 && fY == 0.0 ? 0.0 : TMath::ATan2(fY, fX);
374}
375
376//______________________________________________________________________________
377template<typename TT>
379{
380 return TMath::Sqrt((fX - b.fX)*(fX - b.fX) +
381 (fY - b.fY)*(fY - b.fY));
382}
383
384//______________________________________________________________________________
385template<typename TT>
387{
388 return ((fX - b.fX) * (fX - b.fX) +
389 (fY - b.fY) * (fY - b.fY));
390}
391
392//______________________________________________________________________________
393template<typename TT>
395{
396 return a.fX*fX + a.fY*fY;
397}
398
399//______________________________________________________________________________
400template<typename TT>
402{
403 return fX * a.fY - fY * a.fX;
404}
405
406//______________________________________________________________________________
407template<typename TT>
409{
410 fX = p.fX - q.fX;
411 fY = p.fY - q.fY;
412 return *this;
413}
414
415//______________________________________________________________________________
416template<typename TT>
418{
419 fX = a.fX * af;
420 fY = a.fY * af;
421 return *this;
422}
423
424//______________________________________________________________________________
425template<typename TT>
427{
429 return r += b;
430}
431
432//______________________________________________________________________________
433template<typename TT>
435{
437 return r -= b;
438}
439
440//______________________________________________________________________________
441template<typename TT>
443{
445 return r *= b;
446}
447
448//______________________________________________________________________________
449template<typename TT>
451{
453 return r *= b;
454}
455
456#endif
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
float Float_t
Definition RtypesCore.h:57
#define ClassDefNV(name, id)
Definition Rtypes.h:345
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
TEveVector2T< Float_t > TEveVector2
Definition TEveVector.h:365
TEveVectorT< Float_t > TEveVectorF
Definition TEveVector.h:124
TEveVectorT< TT > operator+(const TEveVectorT< TT > &a, const TEveVectorT< TT > &b)
Definition TEveVector.h:206
TEveVectorT< Double_t > TEveVectorD
Definition TEveVector.h:125
TEveVectorT< TT > operator*(const TEveVectorT< TT > &a, TT b)
Definition TEveVector.h:222
TEveVectorT< Float_t > TEveVector
Definition TEveVector.h:123
TEveVector4T< Float_t > TEveVector4F
Definition TEveVector.h:273
TEveVector4T< Double_t > TEveVector4D
Definition TEveVector.h:274
TEveVector2T< Double_t > TEveVector2D
Definition TEveVector.h:367
TEveVector2T< Float_t > TEveVector2F
Definition TEveVector.h:366
TEveVectorT< TT > operator-(const TEveVectorT< TT > &a, const TEveVectorT< TT > &b)
Definition TEveVector.h:214
TEveVector4T< Float_t > TEveVector4
Definition TEveVector.h:272
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
float * q
Minimal, templated two-vector.
Definition TEveVector.h:311
TEveVector2T(const TEveVector2T< OO > &v)
Definition TEveVector.h:317
TEveVector2T(TT x, TT y)
Definition TEveVector.h:320
void Set(const Double_t *v)
Definition TEveVector.h:338
TT Cross(const TEveVector2T &a) const
Definition TEveVector.h:401
void Dump() const
Dump to stdout as "(x, y)\n".
TT Distance(const TEveVector2T &v) const
Definition TEveVector.h:378
void Set(TT x, TT y)
Definition TEveVector.h:339
TT Dot(const TEveVector2T &a) const
Definition TEveVector.h:394
TEveVector2T(const Double_t *v)
Definition TEveVector.h:319
TEveVector2T & Mult(const TEveVector2T &a, TT af)
Definition TEveVector.h:417
void Normalize(TT length=1)
Normalize the vector to length if current length is non-zero.
TT SquareDistance(const TEveVector2T &v) const
Definition TEveVector.h:386
TT Mag2() const
Definition TEveVector.h:349
TT operator[](Int_t idx) const
Definition TEveVector.h:332
TEveVector2T(const Float_t *v)
Definition TEveVector.h:318
TEveVector2T & operator-=(const TEveVector2T &v)
Definition TEveVector.h:329
TT Mag() const
Definition TEveVector.h:350
const TT * Arr() const
Definition TEveVector.h:334
TT Phi() const
Definition TEveVector.h:371
void Set(const Float_t *v)
Definition TEveVector.h:337
TT & operator[](Int_t idx)
Definition TEveVector.h:331
void Set(const TEveVector2T< OO > &v)
Definition TEveVector.h:342
TEveVector2T & operator+=(const TEveVector2T &v)
Definition TEveVector.h:328
void NegateXY()
Definition TEveVector.h:344
TEveVector2T & operator*=(TT s)
Definition TEveVector.h:327
TEveVector2T & Sub(const TEveVector2T &p, const TEveVector2T &q)
Definition TEveVector.h:408
Minimal, templated four-vector.
Definition TEveVector.h:243
TEveVector4T(const TEveVectorT< OO > &v)
Definition TEveVector.h:251
TEveVector4T(const Float_t *v)
Definition TEveVector.h:256
void Dump() const
Dump to stdout as "(x, y, z; t)\n".
TEveVectorT< TT > TP
Definition TEveVector.h:244
TEveVector4T(TT x, TT y, TT z, TT t=0)
Definition TEveVector.h:258
TEveVector4T & operator-=(const TEveVector4T &v)
Definition TEveVector.h:264
TEveVector4T & operator*=(TT s)
Definition TEveVector.h:262
TEveVector4T & operator+=(const TEveVector4T &v)
Definition TEveVector.h:263
TEveVector4T(const TEveVectorT< OO > &v, Float_t t)
Definition TEveVector.h:253
TEveVector4T(const TEveVector4T< OO > &v)
Definition TEveVector.h:255
TEveVector4T(const Double_t *v)
Definition TEveVector.h:257
Minimal, templated three-vector.
Definition TEveVector.h:28
TEveVectorT Cross(const TEveVectorT &a) const
Definition TEveVector.h:175
TT Perp2() const
Definition TEveVector.h:101
const TT * Arr() const
Definition TEveVector.h:58
void OrthoNormBase(TEveVectorT &a, TEveVectorT &b) const
Set vectors a and b to be normal to this and among themselves, both of length 1.
void Set(TT x, TT y, TT z)
Definition TEveVector.h:84
void Set(const Double_t *v)
Definition TEveVector.h:83
TT Distance(const TEveVectorT &v) const
Definition TEveVector.h:150
TT Phi() const
Definition TEveVector.h:129
TEveVectorT(TT x, TT y, TT z)
Definition TEveVector.h:37
TEveVectorT & Mult(const TEveVectorT &a, TT af)
Definition TEveVector.h:196
TT CosTheta() const
Definition TEveVector.h:143
TT Normalize(TT length=1)
Normalize the vector to length if current length is non-zero.
TEveVectorT(const Float_t *v)
Definition TEveVector.h:35
TEveVectorT & operator+=(const TEveVectorT &v)
Definition TEveVector.h:79
TT Eta() const
Calculate eta of the point, pretending it's a momentum vector.
TEveVectorT & operator-=(const TEveVectorT &v)
Definition TEveVector.h:80
TT Dot(const TEveVectorT &a) const
Definition TEveVector.h:168
TT Perp() const
Definition TEveVector.h:102
void Set(const TEveVectorT< OO > &v)
Definition TEveVector.h:88
TEveVectorT & operator*=(TT s)
Definition TEveVector.h:78
TEveVectorT(const Double_t *v)
Definition TEveVector.h:36
TT operator[](Int_t idx) const
Definition TEveVector.h:75
TEveVectorT Orthogonal() const
Returns an orthogonal vector (not normalized).
void Dump() const
Dump to stdout as "(x, y, z)\n".
TT Mag() const
Definition TEveVector.h:99
TT * Arr()
Definition TEveVector.h:64
TEveVectorT & Sub(const TEveVectorT &a, const TEveVectorT &b)
Definition TEveVector.h:186
TT Mag2() const
Definition TEveVector.h:98
Bool_t IsZero() const
Definition TEveVector.h:118
void Set(const Float_t *v)
Definition TEveVector.h:82
TT Theta() const
Definition TEveVector.h:136
TEveVectorT(const TEveVectorT< OO > &v)
Definition TEveVector.h:34
TT SquareDistance(const TEveVectorT &v) const
Definition TEveVector.h:159
TT R() const
Definition TEveVector.h:103
void NegateXYZ()
Definition TEveVector.h:90
SCoord_t fY
Definition TPoint.h:36
SCoord_t fX
Definition TPoint.h:35
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Double_t ATan2(Double_t y, Double_t x)
Returns the principal value of the arc tangent of y/x, expressed in radians.
Definition TMath.h:646
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662
#define Dot(u, v)
Definition normal.c:49