00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TROOT.h"
00013 #include "TVector2.h"
00014 #include "TClass.h"
00015 #include "TMath.h"
00016
00017 Double_t const kPI = TMath::Pi();
00018 Double_t const kTWOPI = 2.*kPI;
00019
00020 ClassImp(TVector2)
00021
00022
00023 TVector2::TVector2()
00024 {
00025
00026 fX = 0.;
00027 fY = 0.;
00028 }
00029
00030
00031 TVector2::TVector2(Double_t *v)
00032 {
00033
00034 fX = v[0];
00035 fY = v[1];
00036 }
00037
00038
00039 TVector2::TVector2(Double_t x0, Double_t y0)
00040 {
00041
00042 fX = x0;
00043 fY = y0;
00044 }
00045
00046
00047 TVector2::~TVector2()
00048 {
00049 }
00050
00051
00052 Double_t TVector2::Mod() const
00053 {
00054
00055 return TMath::Sqrt(fX*fX+fY*fY);
00056 }
00057
00058
00059 TVector2 TVector2::Unit() const
00060 {
00061
00062 return (Mod2()) ? *this/Mod() : TVector2();
00063 }
00064
00065
00066 Double_t TVector2::Phi() const
00067 {
00068
00069 return TMath::Pi()+TMath::ATan2(-fY,-fX);
00070 }
00071
00072
00073 Double_t TVector2::Phi_0_2pi(Double_t x) {
00074
00075 if(TMath::IsNaN(x)){
00076 gROOT->Error("TVector2::Phi_0_2pi","function called with NaN");
00077 return x;
00078 }
00079 while (x >= kTWOPI) x -= kTWOPI;
00080 while (x < 0.) x += kTWOPI;
00081 return x;
00082 }
00083
00084
00085 Double_t TVector2::Phi_mpi_pi(Double_t x) {
00086
00087 if(TMath::IsNaN(x)){
00088 gROOT->Error("TVector2::Phi_mpi_pi","function called with NaN");
00089 return x;
00090 }
00091 while (x >= kPI) x -= kTWOPI;
00092 while (x < -kPI) x += kTWOPI;
00093 return x;
00094 }
00095
00096
00097 TVector2 TVector2::Rotate (Double_t phi) const
00098 {
00099
00100 return TVector2( fX*TMath::Cos(phi)-fY*TMath::Sin(phi), fX*TMath::Sin(phi)+fY*TMath::Cos(phi) );
00101 }
00102
00103
00104 void TVector2::SetMagPhi(Double_t mag, Double_t phi)
00105 {
00106
00107 Double_t amag = TMath::Abs(mag);
00108 fX = amag * TMath::Cos(phi);
00109 fY = amag * TMath::Sin(phi);
00110 }
00111
00112 void TVector2::Streamer(TBuffer &R__b)
00113 {
00114
00115
00116 if (R__b.IsReading()) {
00117 UInt_t R__s, R__c;
00118 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
00119 if (R__v > 2) {
00120 R__b.ReadClassBuffer(TVector2::Class(), this, R__v, R__s, R__c);
00121 return;
00122 }
00123
00124 if (R__v < 2) TObject::Streamer(R__b);
00125 R__b >> fX;
00126 R__b >> fY;
00127 R__b.CheckByteCount(R__s, R__c, TVector2::IsA());
00128
00129
00130 } else {
00131 R__b.WriteClassBuffer(TVector2::Class(),this);
00132 }
00133 }
00134
00135 void TVector2::Print(Option_t*)const
00136 {
00137
00138 Printf("%s %s (x,y)=(%f,%f) (rho,phi)=(%f,%f)",GetName(),GetTitle(),X(),Y(),
00139 Mod(),Phi()*TMath::RadToDeg());
00140 }
00141