TVector2.cxx

Go to the documentation of this file.
00001 // @(#)root/physics:$Id: TVector2.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Pasha Murat   12/02/99
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
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    //constructor
00026    fX = 0.;
00027    fY = 0.;
00028 }
00029 
00030 //______________________________________________________________________________
00031 TVector2::TVector2(Double_t *v)
00032 {
00033    //constructor
00034    fX = v[0];
00035    fY = v[1];
00036 }
00037 
00038 //______________________________________________________________________________
00039 TVector2::TVector2(Double_t x0, Double_t y0)
00040 {
00041    //constructor
00042    fX = x0;
00043    fY = y0;
00044 }
00045 
00046 //______________________________________________________________________________
00047 TVector2::~TVector2()
00048 {
00049 }
00050 
00051 //______________________________________________________________________________
00052 Double_t TVector2::Mod() const
00053 {
00054    // return modulo of this vector
00055    return TMath::Sqrt(fX*fX+fY*fY);
00056 }
00057 
00058 //______________________________________________________________________________
00059 TVector2 TVector2::Unit() const
00060 {
00061    // return module normalized to 1
00062    return (Mod2()) ? *this/Mod() : TVector2(); 
00063 }
00064 
00065 //______________________________________________________________________________
00066 Double_t TVector2::Phi() const
00067 {
00068    // return vector phi
00069    return TMath::Pi()+TMath::ATan2(-fY,-fX); 
00070 } 
00071 
00072 //______________________________________________________________________________
00073 Double_t TVector2::Phi_0_2pi(Double_t x) {
00074    // (static function) returns phi angle in the interval [0,2*PI)
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    // (static function) returns phi angle in the interval [-PI,PI)
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    //rotation by phi
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    //set vector using mag and phi
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    // Stream an object of class TVector2.
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       //====process old versions before automatic schema evolution
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       //====end of old versions
00129 
00130    } else {
00131       R__b.WriteClassBuffer(TVector2::Class(),this);
00132    }
00133 }
00134 
00135 void TVector2::Print(Option_t*)const
00136 {
00137    //print vector parameters
00138    Printf("%s %s (x,y)=(%f,%f) (rho,phi)=(%f,%f)",GetName(),GetTitle(),X(),Y(),
00139                                           Mod(),Phi()*TMath::RadToDeg());
00140 }
00141 

Generated on Tue Jul 5 14:37:48 2011 for ROOT_528-00b_version by  doxygen 1.5.1