TEveVector.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveVector.cxx 32934 2010-04-09 19:55:19Z matevz $
00002 // Author: Matevz Tadel 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, 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 "TEveVector.h"
00013 #include "TVector3.h"
00014 
00015 //==============================================================================
00016 // TEveVector
00017 //==============================================================================
00018 
00019 //______________________________________________________________________________
00020 //
00021 // Minimal, templated three-vector.
00022 // No TObject inheritance and virtual functions.
00023 // Also used in VSD.
00024 
00025 ClassImp(TEveVectorT<Float_t>);
00026 ClassImp(TEveVectorT<Double_t>);
00027 
00028 //______________________________________________________________________________
00029 template<typename TT> void TEveVectorT<TT>::Dump() const
00030 {
00031    // Dump to stdout as "(x, y, z)\n".
00032 
00033    printf("(%f, %f, %f)\n", fX, fY, fZ);
00034 }
00035 
00036 //______________________________________________________________________________
00037 template<typename TT> void TEveVectorT<TT>::Set(const TVector3& v)
00038 {
00039    // Set from TVector3.
00040 
00041    fX = v.x(); fY = v.y(); fZ = v.z();
00042 }
00043 
00044 //______________________________________________________________________________
00045 template<typename TT> TT TEveVectorT<TT>::Eta() const
00046 {
00047    // Calculate eta of the point, pretending it's a momentum vector.
00048 
00049    TT cosTheta = CosTheta();
00050    if (cosTheta*cosTheta < 1) return -0.5* TMath::Log( (1.0-cosTheta)/(1.0+cosTheta) );
00051    Warning("Eta","transverse momentum = 0, returning +/- 1e10");
00052    return (fZ >= 0) ? 1e10 : -1e10;
00053 }
00054 
00055 //______________________________________________________________________________
00056 template<typename TT> TT TEveVectorT<TT>::Normalize(TT length)
00057 {
00058    // Normalize the vector to length if current length is non-zero.
00059    // Returns the old magnitude.
00060 
00061    TT m = Mag();
00062    if (m != 0)
00063    {
00064       length /= m;
00065       fX *= length; fY *= length; fZ *= length;
00066    }
00067    return m;
00068 }
00069 
00070 //______________________________________________________________________________
00071 template<typename TT> TEveVectorT<TT> TEveVectorT<TT>::Orthogonal() const
00072 {
00073    // Returns an orthogonal vector (not normalized).
00074 
00075    Float_t xx = fX < 0 ? -fX : fX;
00076    Float_t yy = fY < 0 ? -fY : fY;
00077    Float_t zz = fZ < 0 ? -fZ : fZ;
00078    if (xx < yy) {
00079       return xx < zz ? TEveVectorT<TT>(0,fZ,-fY) : TEveVectorT<TT>(fY,-fX,0);
00080    } else {
00081       return yy < zz ? TEveVectorT<TT>(-fZ,0,fX) : TEveVectorT<TT>(fY,-fX,0);
00082    }
00083 }
00084 
00085 //______________________________________________________________________________
00086 template<typename TT> void TEveVectorT<TT>::OrthoNormBase(TEveVectorT<TT>& a, TEveVectorT<TT>& b) const
00087 {
00088    // Set vectors a and b to be normal to this and among themselves,
00089    // both of length 1.
00090 
00091    a = Orthogonal();
00092    TMath::Cross(this->Arr(), a.Arr(), b.Arr());
00093    a.Normalize();
00094    b.Normalize();
00095 }
00096 
00097 template class TEveVectorT<Float_t>;
00098 template class TEveVectorT<Double_t>;
00099 
00100 
00101 //==============================================================================
00102 // TEveVector4
00103 //==============================================================================
00104 
00105 //______________________________________________________________________________
00106 //
00107 // Minimal, templated four-vector.
00108 // No TObject inheritance and virtual functions.
00109 // Also used in VSD.
00110 
00111 ClassImp(TEveVector4T<Float_t>);
00112 ClassImp(TEveVector4T<Double_t>);
00113 
00114 //______________________________________________________________________________
00115 template<typename TT> void TEveVector4T<TT>::Dump() const
00116 {
00117    // Dump to stdout as "(x, y, z; t)\n".
00118 
00119    printf("(%f, %f, %f; %f)\n", TP::fX, TP::fY, TP::fZ, fT);
00120 }
00121 
00122 template class TEveVector4T<Float_t>;
00123 template class TEveVector4T<Double_t>;
00124 
00125 
00126 //==============================================================================
00127 // TEveVector2T
00128 //==============================================================================
00129 
00130 //______________________________________________________________________________
00131 //
00132 // Minimal, templated two-vector.
00133 // No TObject inheritance and virtual functions.
00134 // Also used in VSD.
00135 
00136 ClassImp(TEveVector2T<Float_t>);
00137 ClassImp(TEveVector2T<Double_t>);
00138 
00139 //______________________________________________________________________________
00140 template<typename TT> void TEveVector2T<TT>::Normalize(TT length)
00141 {
00142    // Normalize the vector to length if current length is non-zero.
00143 
00144    Float_t m = Mag();
00145    if (m != 0)
00146    {
00147       m = length / m;
00148       fX *= m; fY *= m;
00149    }
00150 }
00151 
00152 //______________________________________________________________________________
00153 template<typename TT> void TEveVector2T<TT>::Dump() const
00154 {
00155    // Dump to stdout as "(x, y)\n".
00156 
00157    printf("(%f, %f)\n", fX, fY);
00158 }
00159 
00160 template class TEveVector2T<Float_t>;
00161 template class TEveVector2T<Double_t>;

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