BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
//  $Id: BrVector3D.cxx,v 1.3 2002/04/16 13:22:41 hagel Exp $
//
//  $Log: BrVector3D.cxx,v $
//  Revision 1.3  2002/04/16 13:22:41  hagel
//  Made ostream output 'prettier'
//
//  Revision 1.2  2001/08/14 19:27:52  pchristi
//  Removed copy constructors and destructors where the default was good enough.
//
//  Revision 1.1.1.1  2001/06/21 14:55:20  hagel
//  Initial revision of brat2
//
//  Revision 1.12  2001/06/17 17:10:11  pchristi
//  Cleaned up and modified the line 3D and vector3D classes.
//  No major new stuff.
//
//  Revision 1.11  1999/12/23 15:55:47  videbaek
//  Added the SetRelativeSystem
//  Fully debugged.
//
//  Revision 1.10  1999/01/27 22:59:32  hagel
//  Added Distance()
//
//  Revision 1.9  1998/12/01 20:50:12  videbaek
//  Added several classes to Geometry. Updated source and makefile(s)
//  - BrLine3D
//  - BrCoordinateSystem
//  - BrRotMatrix
//
//  Revision 1.8  1998/11/13 19:28:11  videbaek
//  Added operators for setting vector elements by index; i.e.
//  vector[2]=x; and vector(i)=cv[i]; as example.
//
//  Revision 1.7  1998/09/18 15:45:00  videbaek
//  Removed BrPoint3D class
//  Added iostream operator to BrVector3Dn
//
//  Revision 1.6  1998/09/15 13:08:34  videbaek
//  Id and Log had disappeared from header
//
//  Revision 1.4  1998/07/28 21:30:13  videbaek
//  Added Theta()  and Phi() members
//
//  Revision 1.3  1998/07/27 14:41:43  videbaek
//  small fixes to vector class
//
//  Revision 1.2  1998/07/24 13:18:22  videbaek
//  Added many functions to vector and point
//
//  Revision 1.1  1998/07/20 17:35:52  videbaek
//  simple geometry class
//
//
//
#ifndef BRAT_BrVector3D
#include "BrVector3D.h"
#endif
#include "math.h"

#ifndef WIN32
#include <iostream>
#include <iomanip>
#else
#include <iostream.h>
#include <iomanip.h>
#endif



ClassImp(BrVector3D)

//////////////////////////////////////////////////////////////////////////////////
//
//
//  BrVector3D defines a general 3-vector class. It can be used to represent space 
//  points, directions, and momenta.BrVector3D is part of the geometry classes. 
//  This is a general class only coupled to ROOT by having the objects being derived from
//  TObject. The main reasons for doing this is to be able to use the ROOTs
//  interactive features. 
//  It is intended to be used
//  by detector geometry , tracking, and display classes by using common
//  geometry concepts. It is also intended to work together with other geometry clasess
//  like BrLine3D, BrPlane3D and likely other 
//  The coupling to ROOT is loose. The classes are derived from TObject, mainly
//  to be able to use browsers and other general ROOT utilities. Drawing has not
//  been implemented here again to maintain a very loose coupling.
//
//  Vectors are intrinsicly represented by doubles, particular to maintain precesion
//  in calculation of angles, intercepts.   
//
//  Such general classes has of course been implemented by numerous people, and
//  design choices made. As such example the CLHEP should be acknowledged.
//
//
//
/////////////////////////////////////////////////////////////////////////////////


const Double_t& BrVector3D::operator [] (size_t i) const {
  if (i==0)
    return fX;
  else if (i == 1)
    return fY;
  else
    return fZ;
}

Double_t& BrVector3D::operator [] (size_t i) {
  if (i==0)
    return fX;
  else if (i == 1)
    return fY;
  else
    return fZ;
}

const Double_t& BrVector3D::operator () (size_t i) const {
  if (i==0)
    return fX;
  else if (i == 1)
    return fY;
  else
    return fZ;
}

Double_t& BrVector3D::operator () (size_t i) {
  if (i==0)
    return fX;
  else if (i == 1)
    return fY;
  else
    return fZ;
}


//  BrVector3D & BrVector3D::operator = (const BrVector3D& vec){
//    //
//    // assignement operator
//    //
//    fX = vec.fX;
//    fY = vec.fY;
//    fZ = vec.fZ;
//    return *this;
//  }


BrVector3D operator+(const BrVector3D& vec1, const BrVector3D& vec2){
  BrVector3D tmp;
  tmp.fX = vec1.fX + vec2.fX;
  tmp.fY = vec1.fY + vec2.fY;
  tmp.fZ = vec1.fZ + vec2.fZ;
  return tmp;
}

BrVector3D operator-(const BrVector3D& vec1, const BrVector3D& vec2){
  BrVector3D tmp;
  tmp.fX = vec1.fX - vec2.fX;
  tmp.fY = vec1.fY - vec2.fY;
  tmp.fZ = vec1.fZ - vec2.fZ;
  return tmp;
}

BrVector3D& BrVector3D::operator += (const BrVector3D& vec){
  fX += vec.fX;
  fY += vec.fY;
  fZ += vec.fZ;
  return *this;
}

BrVector3D& BrVector3D::operator -= (const BrVector3D& vec){
  fX -= vec.fX;
  fY -= vec.fY;
  fZ -= vec.fZ;
  return *this;
}

BrVector3D BrVector3D::operator - () const{
  BrVector3D tmp(-fX, -fY, -fZ);
  return tmp;
}

BrVector3D BrVector3D::operator + () const{
   return *this;
}

Bool_t BrVector3D::operator== (const BrVector3D& vec2) const{
  // Boolean equal
  return ((fX == vec2.fX) && (fY == vec2.fY) && (fZ == vec2.fZ));
} 

Bool_t BrVector3D::operator!= (const BrVector3D& vec2)const {
  // Boolean not equal
  return !(*this==vec2);
} 

//______________________________________________________________
 Double_t BrVector3D::Norm() const {
  //
  // Magnitude of norm of vector
  //
  Double_t tmp;
  tmp = fX*fX + fY*fY + fZ*fZ;
  return sqrt(tmp);
}

//______________________________________________________________
 Double_t BrVector3D::NormSq() const {
  //
  // Squared Magnitude of vector
  //
  return fX*fX + fY*fY + fZ*fZ;
  }

//______________________________________________________________
 Double_t BrVector3D::Dot(const BrVector3D& vec) const{
  //
  // Dot product of two vector
  //
  Double_t tmp;
  tmp = fX*vec.fX + fY*vec.fY + fZ*vec.fZ;
  return tmp;
}

//______________________________________________________________
 BrVector3D BrVector3D::Cross(const BrVector3D& vec) const{
  //
  // Cross product of two vectors
  //
  BrVector3D tmp( fY*vec.fZ - fZ*vec.fY,
                  fZ*vec.fX - fX*vec.fZ,
                  fX*vec.fY - fY*vec.fX);
  return tmp;
}

//______________________________________________________________
 BrVector3D BrVector3D::Unit() const {
  return *this/(this->Norm());
}

//______________________________________________________________
 Double_t BrVector3D::Theta() const {
  //
  // Polar angle with regard to z axis
  //
  if( fX == 0.0 && fY == 0.0)
    {
      return 0;
    }
  else {
    Double_t perp = sqrt(fX*fX+fY*fY);
    return atan2(perp, fZ);
  }
}

//______________________________________________________________
 Double_t BrVector3D::Phi() const {
  //
  // Azimuth  angle with regard to z axis
  //
  if( fX == 0.0 && fY == 0.0)
    {
      return 0;
    }
  else
    return atan2(fY, fX);
}

//______________________________________________________________
 void BrVector3D::Print(Option_t* option = "") const 
{
  cout << "("  << setw(10) << fX 
       << ", " << setw(10) << fY 
       << ", " << setw(10) << fZ << ")" << endl;
}

//______________________________________________________________
Double_t 
 BrVector3D::Distance(const BrVector3D &vec) const {
Double_t dist;
dist = sqrt(
         (fX-vec.GetX())*(fX-vec.GetX())
       + (fY-vec.GetY())*(fY-vec.GetY())
       + (fZ-vec.GetZ())*(fZ-vec.GetZ())
         );
return dist;
}

//
//  friend global functions
//  =======================

BrVector3D operator*(Double_t a, const BrVector3D& vec){
  //
  //  number multiply
  //
  BrVector3D tmp;
  tmp.fX = a*vec.fX;
  tmp.fY = a*vec.fY;
  tmp.fZ = a*vec.fZ;
  return tmp;
}

BrVector3D operator/(const BrVector3D& vec, Double_t a){
  //
  //  number multiply
  //
  BrVector3D tmp;
  tmp.fX = vec.fX / a;
  tmp.fY = vec.fY / a;
  tmp.fZ = vec.fZ / a;
  return tmp;
}

BrVector3D operator*(const BrVector3D& vec, Double_t a){
  //
  //  number multiply
  //
  BrVector3D tmp;
  tmp.fX = a*vec.fX;
  tmp.fY = a*vec.fY;
  tmp.fZ = a*vec.fZ;
  return tmp;
}

//
// Related Functions (global non-member functions)
//

ostream& operator<<(ostream& os, const BrVector3D& vec){
  //
  // Write in default layout
  //
  //os << setprecision(9) <<"(" 
  os << setprecision(6) << setiosflags(ios::fixed) << "(" 
     << vec.GetX() << ", "
     << vec.GetY() << ", " 
     << vec.GetZ() << ")";
  return os; 
}

istream& operator>>(istream& is, BrVector3D& vec){
  //
  // Input stream operator
  //
  Double_t x, y, z;
  is >> x >> y >> z;
  vec.SetX(x);
  vec.SetY(y);
  vec.SetZ(z);
  return is;
}


BrVector3D Cross(const BrVector3D& vec1, const BrVector3D& vec2){
  //
  //  Cross product of two vectors
  //
  return vec1.Cross(vec2);
}

Double_t Dot(const BrVector3D& vec1, const BrVector3D& vec2){
  //
  //  Dot product of two vectors
  //
  return vec1.Dot(vec2);
}





This page automatically generated by script docBrat by Christian Holm

Copyright ; 2002 BRAHMS Collaboration <brahmlib@rcf.rhic.bnl.gov>
Last Update on by

Validate HTML
Validate CSS