File indexing completed on 2025-01-18 10:12:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TVector2
0013 #define ROOT_TVector2
0014
0015 #include "TObject.h"
0016
0017
0018 class TVector2 : public TObject {
0019
0020
0021
0022 protected:
0023
0024 Double_t fX;
0025 Double_t fY;
0026
0027
0028
0029 public:
0030
0031 typedef Double_t Scalar;
0032
0033 TVector2 ();
0034 TVector2 (const TVector2&) = default;
0035 TVector2 (Double_t *s);
0036 TVector2 (Double_t x0, Double_t y0);
0037 ~TVector2() override;
0038
0039
0040 TVector2& operator = (TVector2 const & v);
0041 TVector2& operator += (TVector2 const & v);
0042 TVector2& operator -= (TVector2 const & v);
0043 Double_t operator *= (TVector2 const & v);
0044 TVector2& operator *= (Double_t s);
0045 TVector2& operator /= (Double_t s);
0046
0047
0048
0049 friend TVector2 operator + (const TVector2&, const TVector2&);
0050 friend TVector2 operator + (const TVector2&, Double_t );
0051 friend TVector2 operator + (Double_t , const TVector2&);
0052 friend TVector2 operator - (const TVector2&, const TVector2&);
0053 friend TVector2 operator - (const TVector2&, Double_t );
0054 friend Double_t operator * (const TVector2&, const TVector2&);
0055 friend TVector2 operator * (const TVector2&, Double_t );
0056 friend TVector2 operator * (Double_t , const TVector2&);
0057 friend TVector2 operator / (const TVector2&, Double_t );
0058 friend Double_t operator ^ (const TVector2&, const TVector2&);
0059
0060
0061 void Set(const TVector2& v);
0062 void Set(Double_t x0, Double_t y0);
0063 void Set(float x0, float y0);
0064 void SetX(Double_t x0);
0065 void SetY(Double_t y0);
0066
0067
0068 Double_t Mod2() const { return fX*fX+fY*fY; };
0069 Double_t Mod () const;
0070
0071 Double_t Px() const { return fX; };
0072 Double_t Py() const { return fY; };
0073 Double_t X () const { return fX; };
0074 Double_t Y () const { return fY; };
0075
0076
0077
0078 Double_t Phi () const;
0079 Double_t DeltaPhi(const TVector2& v) const;
0080 void SetMagPhi(Double_t mag, Double_t phi);
0081
0082
0083
0084 TVector2 Unit() const;
0085 TVector2 Ort () const;
0086
0087
0088
0089
0090 TVector2 Proj(const TVector2& v) const;
0091
0092
0093
0094 TVector2 Norm(const TVector2& v) const;
0095
0096
0097 TVector2 Rotate (Double_t phi) const;
0098
0099
0100 static Double_t Phi_0_2pi(Double_t x);
0101
0102
0103 static Double_t Phi_mpi_pi(Double_t x);
0104
0105
0106 void Print(Option_t* option="") const override;
0107
0108 ClassDefOverride(TVector2,3)
0109
0110 };
0111
0112
0113
0114 inline TVector2& TVector2::operator = (TVector2 const& v) {fX = v.fX; fY = v.fY; return *this;}
0115 inline TVector2& TVector2::operator += (TVector2 const& v) {fX += v.fX; fY += v.fY; return *this;}
0116 inline TVector2& TVector2::operator -= (TVector2 const& v) {fX -= v.fX; fY -= v.fY; return *this;}
0117
0118
0119
0120 inline Double_t TVector2::operator *= (const TVector2& v) { return(fX*v.fX+fY*v.fY); }
0121
0122 inline TVector2& TVector2::operator *= (Double_t s) { fX *=s; fY *=s; return *this; }
0123 inline TVector2& TVector2::operator /= (Double_t s) { fX /=s; fY /=s; return *this; }
0124
0125
0126
0127 inline TVector2 operator + (const TVector2& v1, const TVector2& v2) {
0128 return TVector2(v1.fX+v2.fX,v1.fY+v2.fY);
0129 }
0130
0131 inline TVector2 operator + (const TVector2& v1, Double_t bias) {
0132 return TVector2 (v1.fX+bias,v1.fY+bias);
0133 }
0134
0135 inline TVector2 operator + (Double_t bias, const TVector2& v1) {
0136 return TVector2 (v1.fX+bias,v1.fY+bias);
0137 }
0138
0139 inline TVector2 operator - (const TVector2& v1, const TVector2& v2) {
0140 return TVector2(v1.fX-v2.fX,v1.fY-v2.fY);
0141 }
0142
0143 inline TVector2 operator - (const TVector2& v1, Double_t bias) {
0144 return TVector2 (v1.fX-bias,v1.fY-bias);
0145 }
0146
0147 inline TVector2 operator * (const TVector2& v, Double_t s) {
0148 return TVector2 (v.fX*s,v.fY*s);
0149 }
0150
0151 inline TVector2 operator * (Double_t s, const TVector2& v) {
0152 return TVector2 (v.fX*s,v.fY*s);
0153 }
0154
0155 inline Double_t operator * (const TVector2& v1, const TVector2& v2) {
0156 return v1.fX*v2.fX+v1.fY*v2.fY;
0157 }
0158
0159 inline TVector2 operator / (const TVector2& v, Double_t s) {
0160 return TVector2 (v.fX/s,v.fY/s);
0161 }
0162
0163 inline Double_t operator ^ (const TVector2& v1, const TVector2& v2) {
0164 return v1.fX*v2.fY-v1.fY*v2.fX;
0165 }
0166
0167 inline Double_t TVector2::DeltaPhi(const TVector2& v) const { return Phi_mpi_pi(Phi()-v.Phi()); }
0168
0169 inline TVector2 TVector2::Ort () const { return Unit(); }
0170
0171 inline TVector2 TVector2::Proj(const TVector2& v) const { return v*(((*this)*v)/v.Mod2()); }
0172
0173 inline TVector2 TVector2::Norm(const TVector2& v) const {return *this-Proj(v); }
0174
0175
0176
0177 inline void TVector2::Set(const TVector2& v ) { fX = v.fX; fY = v.fY; }
0178 inline void TVector2::Set(Double_t x0, Double_t y0) { fX = x0 ; fY = y0 ; }
0179 inline void TVector2::Set(float x0, float y0) { fX = x0 ; fY = y0 ; }
0180 inline void TVector2::SetX(Double_t x0) { fX = x0 ; }
0181 inline void TVector2::SetY(Double_t y0) { fY = y0 ; }
0182
0183
0184 #endif