00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ROOT_TVector3
00012 #define ROOT_TVector3
00013
00014 #ifndef ROOT_TError
00015 #include "TError.h"
00016 #endif
00017 #ifndef ROOT_TVector2
00018 #include "TVector2.h"
00019 #endif
00020 #ifndef ROOT_TMatrix
00021 #include "TMatrix.h"
00022 #endif
00023
00024 class TRotation;
00025
00026
00027 class TVector3 : public TObject {
00028
00029 public:
00030
00031
00032 TVector3(Double_t x = 0.0, Double_t y = 0.0, Double_t z = 0.0);
00033
00034
00035 TVector3(const Double_t *);
00036 TVector3(const Float_t *);
00037
00038
00039 TVector3(const TVector3 &);
00040
00041
00042 virtual ~TVector3();
00043
00044
00045 Double_t operator () (int) const;
00046 inline Double_t operator [] (int) const;
00047
00048
00049 Double_t & operator () (int);
00050 inline Double_t & operator [] (int);
00051
00052
00053 inline Double_t x() const;
00054 inline Double_t y() const;
00055 inline Double_t z() const;
00056 inline Double_t X() const;
00057 inline Double_t Y() const;
00058 inline Double_t Z() const;
00059 inline Double_t Px() const;
00060 inline Double_t Py() const;
00061 inline Double_t Pz() const;
00062
00063
00064 inline void SetX(Double_t);
00065 inline void SetY(Double_t);
00066 inline void SetZ(Double_t);
00067 inline void SetXYZ(Double_t x, Double_t y, Double_t z);
00068 void SetPtEtaPhi(Double_t pt, Double_t eta, Double_t phi);
00069 void SetPtThetaPhi(Double_t pt, Double_t theta, Double_t phi);
00070
00071 inline void GetXYZ(Double_t *carray) const;
00072 inline void GetXYZ(Float_t *carray) const;
00073
00074
00075
00076 Double_t Phi() const;
00077
00078
00079 Double_t Theta() const;
00080
00081
00082 inline Double_t CosTheta() const;
00083
00084
00085 inline Double_t Mag2() const;
00086
00087
00088 Double_t Mag() const;
00089
00090
00091 void SetPhi(Double_t);
00092
00093
00094 void SetTheta(Double_t);
00095
00096
00097 inline void SetMag(Double_t);
00098
00099
00100 inline Double_t Perp2() const;
00101
00102
00103 inline Double_t Pt() const;
00104 Double_t Perp() const;
00105
00106
00107 inline void SetPerp(Double_t);
00108
00109
00110 inline Double_t Perp2(const TVector3 &) const;
00111
00112
00113 inline Double_t Pt(const TVector3 &) const;
00114 Double_t Perp(const TVector3 &) const;
00115
00116
00117 inline Double_t DeltaPhi(const TVector3 &) const;
00118 Double_t DeltaR(const TVector3 &) const;
00119 inline Double_t DrEtaPhi(const TVector3 &) const;
00120 inline TVector2 EtaPhiVector() const;
00121 void SetMagThetaPhi(Double_t mag, Double_t theta, Double_t phi);
00122
00123 inline TVector3 & operator = (const TVector3 &);
00124
00125
00126 inline Bool_t operator == (const TVector3 &) const;
00127 inline Bool_t operator != (const TVector3 &) const;
00128
00129
00130 inline TVector3 & operator += (const TVector3 &);
00131
00132
00133 inline TVector3 & operator -= (const TVector3 &);
00134
00135
00136 inline TVector3 operator - () const;
00137
00138
00139 inline TVector3 & operator *= (Double_t);
00140
00141
00142 TVector3 Unit() const;
00143
00144
00145 inline TVector3 Orthogonal() const;
00146
00147
00148 inline Double_t Dot(const TVector3 &) const;
00149
00150
00151 inline TVector3 Cross(const TVector3 &) const;
00152
00153
00154 Double_t Angle(const TVector3 &) const;
00155
00156
00157 Double_t PseudoRapidity() const;
00158
00159
00160 inline Double_t Eta() const;
00161
00162 void RotateX(Double_t);
00163
00164
00165 void RotateY(Double_t);
00166
00167
00168 void RotateZ(Double_t);
00169
00170
00171 void RotateUz(const TVector3&);
00172
00173
00174 void Rotate(Double_t, const TVector3 &);
00175
00176
00177 TVector3 & operator *= (const TRotation &);
00178 TVector3 & Transform(const TRotation &);
00179
00180
00181 inline TVector2 XYvector() const;
00182
00183 void Print(Option_t* option="") const;
00184
00185 private:
00186
00187 Double_t fX, fY, fZ;
00188
00189
00190 ClassDef(TVector3,3)
00191
00192 };
00193
00194
00195 TVector3 operator + (const TVector3 &, const TVector3 &);
00196
00197
00198 TVector3 operator - (const TVector3 &, const TVector3 &);
00199
00200
00201 Double_t operator * (const TVector3 &, const TVector3 &);
00202
00203
00204 TVector3 operator * (const TVector3 &, Double_t a);
00205 TVector3 operator * (Double_t a, const TVector3 &);
00206
00207
00208 TVector3 operator * (const TMatrix &, const TVector3 &);
00209
00210
00211 Double_t & TVector3::operator[] (int i) { return operator()(i); }
00212 Double_t TVector3::operator[] (int i) const { return operator()(i); }
00213
00214 inline Double_t TVector3::x() const { return fX; }
00215 inline Double_t TVector3::y() const { return fY; }
00216 inline Double_t TVector3::z() const { return fZ; }
00217 inline Double_t TVector3::X() const { return fX; }
00218 inline Double_t TVector3::Y() const { return fY; }
00219 inline Double_t TVector3::Z() const { return fZ; }
00220 inline Double_t TVector3::Px() const { return fX; }
00221 inline Double_t TVector3::Py() const { return fY; }
00222 inline Double_t TVector3::Pz() const { return fZ; }
00223
00224 inline void TVector3::SetX(Double_t xx) { fX = xx; }
00225 inline void TVector3::SetY(Double_t yy) { fY = yy; }
00226 inline void TVector3::SetZ(Double_t zz) { fZ = zz; }
00227
00228 inline void TVector3::SetXYZ(Double_t xx, Double_t yy, Double_t zz) {
00229 fX = xx;
00230 fY = yy;
00231 fZ = zz;
00232 }
00233
00234 inline void TVector3::GetXYZ(Double_t *carray) const {
00235 carray[0] = fX;
00236 carray[1] = fY;
00237 carray[2] = fZ;
00238 }
00239
00240 inline void TVector3::GetXYZ(Float_t *carray) const {
00241 carray[0] = fX;
00242 carray[1] = fY;
00243 carray[2] = fZ;
00244 }
00245
00246
00247 inline TVector3 & TVector3::operator = (const TVector3 & p) {
00248 fX = p.fX;
00249 fY = p.fY;
00250 fZ = p.fZ;
00251 return *this;
00252 }
00253
00254 inline Bool_t TVector3::operator == (const TVector3& v) const {
00255 return (v.fX==fX && v.fY==fY && v.fZ==fZ) ? kTRUE : kFALSE;
00256 }
00257
00258 inline Bool_t TVector3::operator != (const TVector3& v) const {
00259 return (v.fX!=fX || v.fY!=fY || v.fZ!=fZ) ? kTRUE : kFALSE;
00260 }
00261
00262 inline TVector3& TVector3::operator += (const TVector3 & p) {
00263 fX += p.fX;
00264 fY += p.fY;
00265 fZ += p.fZ;
00266 return *this;
00267 }
00268
00269 inline TVector3& TVector3::operator -= (const TVector3 & p) {
00270 fX -= p.fX;
00271 fY -= p.fY;
00272 fZ -= p.fZ;
00273 return *this;
00274 }
00275
00276 inline TVector3 TVector3::operator - () const {
00277 return TVector3(-fX, -fY, -fZ);
00278 }
00279
00280 inline TVector3& TVector3::operator *= (Double_t a) {
00281 fX *= a;
00282 fY *= a;
00283 fZ *= a;
00284 return *this;
00285 }
00286
00287 inline Double_t TVector3::Dot(const TVector3 & p) const {
00288 return fX*p.fX + fY*p.fY + fZ*p.fZ;
00289 }
00290
00291 inline TVector3 TVector3::Cross(const TVector3 & p) const {
00292 return TVector3(fY*p.fZ-p.fY*fZ, fZ*p.fX-p.fZ*fX, fX*p.fY-p.fX*fY);
00293 }
00294
00295 inline Double_t TVector3::Mag2() const { return fX*fX + fY*fY + fZ*fZ; }
00296
00297
00298 inline TVector3 TVector3::Orthogonal() const {
00299 Double_t xx = fX < 0.0 ? -fX : fX;
00300 Double_t yy = fY < 0.0 ? -fY : fY;
00301 Double_t zz = fZ < 0.0 ? -fZ : fZ;
00302 if (xx < yy) {
00303 return xx < zz ? TVector3(0,fZ,-fY) : TVector3(fY,-fX,0);
00304 } else {
00305 return yy < zz ? TVector3(-fZ,0,fX) : TVector3(fY,-fX,0);
00306 }
00307 }
00308
00309 inline Double_t TVector3::Perp2() const { return fX*fX + fY*fY; }
00310
00311
00312 inline Double_t TVector3::Pt() const { return Perp(); }
00313
00314 inline Double_t TVector3::Perp2(const TVector3 & p) const {
00315 Double_t tot = p.Mag2();
00316 Double_t ss = Dot(p);
00317 Double_t per = Mag2();
00318 if (tot > 0.0) per -= ss*ss/tot;
00319 if (per < 0) per = 0;
00320 return per;
00321 }
00322
00323 inline Double_t TVector3::Pt(const TVector3 & p) const {
00324 return Perp(p);
00325 }
00326
00327 inline Double_t TVector3::CosTheta() const {
00328 Double_t ptot = Mag();
00329 return ptot == 0.0 ? 1.0 : fZ/ptot;
00330 }
00331
00332 inline void TVector3::SetMag(Double_t ma) {
00333 Double_t factor = Mag();
00334 if (factor == 0) {
00335 Warning("SetMag","zero vector can't be stretched");
00336 } else {
00337 factor = ma/factor;
00338 SetX(fX*factor);
00339 SetY(fY*factor);
00340 SetZ(fZ*factor);
00341 }
00342 }
00343
00344 inline void TVector3::SetPerp(Double_t r) {
00345 Double_t p = Perp();
00346 if (p != 0.0) {
00347 fX *= r/p;
00348 fY *= r/p;
00349 }
00350 }
00351
00352 inline Double_t TVector3::DeltaPhi(const TVector3 & v) const {
00353 return TVector2::Phi_mpi_pi(Phi()-v.Phi());
00354 }
00355
00356 inline Double_t TVector3::Eta() const {
00357 return PseudoRapidity();
00358 }
00359
00360 inline Double_t TVector3::DrEtaPhi(const TVector3 & v) const{
00361 return DeltaR(v);
00362 }
00363
00364
00365 inline TVector2 TVector3::EtaPhiVector() const {
00366 return TVector2 (Eta(),Phi());
00367 }
00368
00369 inline TVector2 TVector3::XYvector() const {
00370 return TVector2(fX,fY);
00371 }
00372
00373 #endif