Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TVector2.h
Go to the documentation of this file.
1// @(#)root/physics:$Id$
2// Author: Pasha Murat 12/02/99
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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_TVector2
13#define ROOT_TVector2
14
15#include "TObject.h"
16
17
18class TVector2 : public TObject {
19//------------------------------------------------------------------------------
20// data members
21//------------------------------------------------------------------------------
22protected:
23
24 Double_t fX; // components of the vector
26//------------------------------------------------------------------------------
27// function members
28//------------------------------------------------------------------------------
29public:
30
31 typedef Double_t Scalar; // to be able to use it with the ROOT::Math::VectorUtil functions
32
33 TVector2 ();
34 TVector2 (const TVector2&) = default;
35 TVector2 (Double_t *s);
36 TVector2 (Double_t x0, Double_t y0);
37 virtual ~TVector2();
38 // ****** unary operators
39
46
47 // ****** binary operators
48
49 friend TVector2 operator + (const TVector2&, const TVector2&);
50 friend TVector2 operator + (const TVector2&, Double_t );
51 friend TVector2 operator + (Double_t , const TVector2&);
52 friend TVector2 operator - (const TVector2&, const TVector2&);
53 friend TVector2 operator - (const TVector2&, Double_t );
54 friend Double_t operator * (const TVector2&, const TVector2&);
55 friend TVector2 operator * (const TVector2&, Double_t );
56 friend TVector2 operator * (Double_t , const TVector2&);
57 friend TVector2 operator / (const TVector2&, Double_t );
58 friend Double_t operator ^ (const TVector2&, const TVector2&);
59
60 // ****** setters
61 void Set(const TVector2& v);
62 void Set(Double_t x0, Double_t y0);
63 void Set(float x0, float y0);
64 void SetX(Double_t x0);
65 void SetY(Double_t y0);
66 // ****** other member functions
67
68 Double_t Mod2() const { return fX*fX+fY*fY; };
69 Double_t Mod () const;
70
71 Double_t Px() const { return fX; };
72 Double_t Py() const { return fY; };
73 Double_t X () const { return fX; };
74 Double_t Y () const { return fY; };
75
76 // phi() is defined in [0,TWOPI]
77
78 Double_t Phi () const;
79 Double_t DeltaPhi(const TVector2& v) const;
80 void SetMagPhi(Double_t mag, Double_t phi);
81
82 // unit vector in the direction of *this
83
84 TVector2 Unit() const;
85 TVector2 Ort () const;
86
87 // projection of *this to the direction
88 // of TVector2 vector `v'
89
90 TVector2 Proj(const TVector2& v) const;
91
92 // component of *this normal to `v'
93
94 TVector2 Norm(const TVector2& v) const;
95
96 // rotates 2-vector by phi radians
97 TVector2 Rotate (Double_t phi) const;
98
99 // returns phi angle in the interval [0,2*PI)
101
102 // returns phi angle in the interval [-PI,PI)
104
105
106 void Print(Option_t* option="") const;
107
108 ClassDef(TVector2,3) // A 2D physics vector
109
110};
111
112 // ****** unary operators
113
114inline TVector2& TVector2::operator = (TVector2 const& v) {fX = v.fX; fY = v.fY; return *this;}
115inline TVector2& TVector2::operator += (TVector2 const& v) {fX += v.fX; fY += v.fY; return *this;}
116inline TVector2& TVector2::operator -= (TVector2 const& v) {fX -= v.fX; fY -= v.fY; return *this;}
117
118 // scalar product of 2 2-vectors
119
120inline Double_t TVector2::operator *= (const TVector2& v) { return(fX*v.fX+fY*v.fY); }
121
122inline TVector2& TVector2::operator *= (Double_t s) { fX *=s; fY *=s; return *this; }
123inline TVector2& TVector2::operator /= (Double_t s) { fX /=s; fY /=s; return *this; }
124
125 // ****** binary operators
126
127inline TVector2 operator + (const TVector2& v1, const TVector2& v2) {
128 return TVector2(v1.fX+v2.fX,v1.fY+v2.fY);
129}
130
132 return TVector2 (v1.fX+bias,v1.fY+bias);
133}
134
136 return TVector2 (v1.fX+bias,v1.fY+bias);
137}
138
139inline TVector2 operator - (const TVector2& v1, const TVector2& v2) {
140 return TVector2(v1.fX-v2.fX,v1.fY-v2.fY);
141}
142
144 return TVector2 (v1.fX-bias,v1.fY-bias);
145}
146
148 return TVector2 (v.fX*s,v.fY*s);
149}
150
152 return TVector2 (v.fX*s,v.fY*s);
153}
154
155inline Double_t operator * (const TVector2& v1, const TVector2& v2) {
156 return v1.fX*v2.fX+v1.fY*v2.fY;
157}
158
160 return TVector2 (v.fX/s,v.fY/s);
161}
162
163inline Double_t operator ^ (const TVector2& v1, const TVector2& v2) {
164 return v1.fX*v2.fY-v1.fY*v2.fX;
165}
166
167inline Double_t TVector2::DeltaPhi(const TVector2& v) const { return Phi_mpi_pi(Phi()-v.Phi()); }
168
169inline TVector2 TVector2::Ort () const { return Unit(); }
170
171inline TVector2 TVector2::Proj(const TVector2& v) const { return v*(((*this)*v)/v.Mod2()); }
172
173inline TVector2 TVector2::Norm(const TVector2& v) const {return *this-Proj(v); }
174
175 // ****** setters
176
177inline void TVector2::Set(const TVector2& v ) { fX = v.fX; fY = v.fY; }
178inline void TVector2::Set(Double_t x0, Double_t y0) { fX = x0 ; fY = y0 ; }
179inline void TVector2::Set(float x0, float y0) { fX = x0 ; fY = y0 ; }
180inline void TVector2::SetX(Double_t x0) { fX = x0 ; }
181inline void TVector2::SetY(Double_t y0) { fY = y0 ; }
182
183
184#endif
double Double_t
Definition RtypesCore.h:59
const char Option_t
Definition RtypesCore.h:66
#define ClassDef(name, id)
Definition Rtypes.h:325
TVector2 operator*(const TVector2 &v, Double_t s)
Definition TVector2.h:147
Double_t operator^(const TVector2 &v1, const TVector2 &v2)
Definition TVector2.h:163
TVector2 operator/(const TVector2 &v, Double_t s)
Definition TVector2.h:159
TVector2 operator-(const TVector2 &v1, const TVector2 &v2)
Definition TVector2.h:139
TVector2 operator+(const TVector2 &v1, const TVector2 &v2)
Definition TVector2.h:127
Mother of all ROOT objects.
Definition TObject.h:41
TVector2 is a general two vector class, which can be used for the description of different vectors in...
Definition TVector2.h:18
friend TVector2 operator+(const TVector2 &, const TVector2 &)
Definition TVector2.h:127
Double_t Phi() const
Return vector phi.
Definition TVector2.cxx:82
TVector2 & operator=(TVector2 const &v)
Definition TVector2.h:114
void SetY(Double_t y0)
Definition TVector2.h:181
Double_t Scalar
Definition TVector2.h:31
void SetMagPhi(Double_t mag, Double_t phi)
Set vector using mag and phi.
Definition TVector2.cxx:124
virtual ~TVector2()
Definition TVector2.cxx:59
Double_t Py() const
Definition TVector2.h:72
TVector2 & operator-=(TVector2 const &v)
Definition TVector2.h:116
TVector2 & operator+=(TVector2 const &v)
Definition TVector2.h:115
friend TVector2 operator/(const TVector2 &, Double_t)
Definition TVector2.h:159
TVector2 Ort() const
Definition TVector2.h:169
Double_t Y() const
Definition TVector2.h:74
Double_t Px() const
Definition TVector2.h:71
static Double_t Phi_0_2pi(Double_t x)
Returns phi angle in the interval [0,2*PI)
Definition TVector2.cxx:90
void Set(const TVector2 &v)
Definition TVector2.h:177
Double_t Mod2() const
Definition TVector2.h:68
friend TVector2 operator-(const TVector2 &, const TVector2 &)
Definition TVector2.h:139
TVector2()
Constructor.
Definition TVector2.cxx:33
friend Double_t operator^(const TVector2 &, const TVector2 &)
Definition TVector2.h:163
Double_t fX
Definition TVector2.h:24
Double_t X() const
Definition TVector2.h:73
Double_t fY
Definition TVector2.h:25
friend Double_t operator*(const TVector2 &, const TVector2 &)
Definition TVector2.h:155
TVector2 Proj(const TVector2 &v) const
Definition TVector2.h:171
TVector2 Norm(const TVector2 &v) const
Definition TVector2.h:173
static Double_t Phi_mpi_pi(Double_t x)
Returns phi angle in the interval [-PI,PI)
Definition TVector2.cxx:103
TVector2 & operator/=(Double_t s)
Definition TVector2.h:123
TVector2 Rotate(Double_t phi) const
Rotation by phi.
Definition TVector2.cxx:116
Double_t operator*=(TVector2 const &v)
Definition TVector2.h:120
Double_t DeltaPhi(const TVector2 &v) const
Definition TVector2.h:167
void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition TVector2.cxx:154
TVector2(const TVector2 &)=default
void SetX(Double_t x0)
Definition TVector2.h:180
Double_t Mod() const
Return modulo of this vector.
Definition TVector2.cxx:66
TVector2 Unit() const
Return module normalized to 1.
Definition TVector2.cxx:74
Double_t x[n]
Definition legend1.C:17