ROOT logo
// @(#)root/eve:$Id$
// Author: Matevz Tadel 2007

/*************************************************************************
 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TEveVector.h"
#include "TVector3.h"

//==============================================================================
// TEveVector
//==============================================================================

//______________________________________________________________________________
//
// Minimal, templated three-vector.
// No TObject inheritance and virtual functions.
// Also used in VSD.

ClassImp(TEveVectorT<Float_t>);
ClassImp(TEveVectorT<Double_t>);

//______________________________________________________________________________
template<typename TT> void TEveVectorT<TT>::Dump() const
{
   // Dump to stdout as "(x, y, z)\n".

   printf("(%f, %f, %f)\n", fX, fY, fZ);
}

//______________________________________________________________________________
template<typename TT> void TEveVectorT<TT>::Set(const TVector3& v)
{
   // Set from TVector3.

   fX = v.x(); fY = v.y(); fZ = v.z();
}

//______________________________________________________________________________
template<typename TT> TT TEveVectorT<TT>::Eta() const
{
   // Calculate eta of the point, pretending it's a momentum vector.

   TT cosTheta = CosTheta();
   if (cosTheta*cosTheta < 1) return -0.5* TMath::Log( (1.0-cosTheta)/(1.0+cosTheta) );
   Warning("Eta","transverse momentum = 0, returning +/- 1e10");
   return (fZ >= 0) ? 1e10 : -1e10;
}

//______________________________________________________________________________
template<typename TT> TT TEveVectorT<TT>::Normalize(TT length)
{
   // Normalize the vector to length if current length is non-zero.
   // Returns the old magnitude.

   TT m = Mag();
   if (m != 0)
   {
      length /= m;
      fX *= length; fY *= length; fZ *= length;
   }
   return m;
}

//______________________________________________________________________________
template<typename TT> TEveVectorT<TT> TEveVectorT<TT>::Orthogonal() const
{
   // Returns an orthogonal vector (not normalized).

   Float_t xx = fX < 0 ? -fX : fX;
   Float_t yy = fY < 0 ? -fY : fY;
   Float_t zz = fZ < 0 ? -fZ : fZ;
   if (xx < yy) {
      return xx < zz ? TEveVectorT<TT>(0,fZ,-fY) : TEveVectorT<TT>(fY,-fX,0);
   } else {
      return yy < zz ? TEveVectorT<TT>(-fZ,0,fX) : TEveVectorT<TT>(fY,-fX,0);
   }
}

//______________________________________________________________________________
template<typename TT> void TEveVectorT<TT>::OrthoNormBase(TEveVectorT<TT>& a, TEveVectorT<TT>& b) const
{
   // Set vectors a and b to be normal to this and among themselves,
   // both of length 1.

   a = Orthogonal();
   TMath::Cross(this->Arr(), a.Arr(), b.Arr());
   a.Normalize();
   b.Normalize();
}

template class TEveVectorT<Float_t>;
template class TEveVectorT<Double_t>;


//==============================================================================
// TEveVector4
//==============================================================================

//______________________________________________________________________________
//
// Minimal, templated four-vector.
// No TObject inheritance and virtual functions.
// Also used in VSD.

ClassImp(TEveVector4T<Float_t>);
ClassImp(TEveVector4T<Double_t>);

//______________________________________________________________________________
template<typename TT> void TEveVector4T<TT>::Dump() const
{
   // Dump to stdout as "(x, y, z; t)\n".

   printf("(%f, %f, %f; %f)\n", TP::fX, TP::fY, TP::fZ, fT);
}

template class TEveVector4T<Float_t>;
template class TEveVector4T<Double_t>;


//==============================================================================
// TEveVector2T
//==============================================================================

//______________________________________________________________________________
//
// Minimal, templated two-vector.
// No TObject inheritance and virtual functions.
// Also used in VSD.

ClassImp(TEveVector2T<Float_t>);
ClassImp(TEveVector2T<Double_t>);

//______________________________________________________________________________
template<typename TT> void TEveVector2T<TT>::Normalize(TT length)
{
   // Normalize the vector to length if current length is non-zero.

   Float_t m = Mag();
   if (m != 0)
   {
      m = length / m;
      fX *= m; fY *= m;
   }
}

//______________________________________________________________________________
template<typename TT> void TEveVector2T<TT>::Dump() const
{
   // Dump to stdout as "(x, y)\n".

   printf("(%f, %f)\n", fX, fY);
}

template class TEveVector2T<Float_t>;
template class TEveVector2T<Double_t>;
 TEveVector.cxx:1
 TEveVector.cxx:2
 TEveVector.cxx:3
 TEveVector.cxx:4
 TEveVector.cxx:5
 TEveVector.cxx:6
 TEveVector.cxx:7
 TEveVector.cxx:8
 TEveVector.cxx:9
 TEveVector.cxx:10
 TEveVector.cxx:11
 TEveVector.cxx:12
 TEveVector.cxx:13
 TEveVector.cxx:14
 TEveVector.cxx:15
 TEveVector.cxx:16
 TEveVector.cxx:17
 TEveVector.cxx:18
 TEveVector.cxx:19
 TEveVector.cxx:20
 TEveVector.cxx:21
 TEveVector.cxx:22
 TEveVector.cxx:23
 TEveVector.cxx:24
 TEveVector.cxx:25
 TEveVector.cxx:26
 TEveVector.cxx:27
 TEveVector.cxx:28
 TEveVector.cxx:29
 TEveVector.cxx:30
 TEveVector.cxx:31
 TEveVector.cxx:32
 TEveVector.cxx:33
 TEveVector.cxx:34
 TEveVector.cxx:35
 TEveVector.cxx:36
 TEveVector.cxx:37
 TEveVector.cxx:38
 TEveVector.cxx:39
 TEveVector.cxx:40
 TEveVector.cxx:41
 TEveVector.cxx:42
 TEveVector.cxx:43
 TEveVector.cxx:44
 TEveVector.cxx:45
 TEveVector.cxx:46
 TEveVector.cxx:47
 TEveVector.cxx:48
 TEveVector.cxx:49
 TEveVector.cxx:50
 TEveVector.cxx:51
 TEveVector.cxx:52
 TEveVector.cxx:53
 TEveVector.cxx:54
 TEveVector.cxx:55
 TEveVector.cxx:56
 TEveVector.cxx:57
 TEveVector.cxx:58
 TEveVector.cxx:59
 TEveVector.cxx:60
 TEveVector.cxx:61
 TEveVector.cxx:62
 TEveVector.cxx:63
 TEveVector.cxx:64
 TEveVector.cxx:65
 TEveVector.cxx:66
 TEveVector.cxx:67
 TEveVector.cxx:68
 TEveVector.cxx:69
 TEveVector.cxx:70
 TEveVector.cxx:71
 TEveVector.cxx:72
 TEveVector.cxx:73
 TEveVector.cxx:74
 TEveVector.cxx:75
 TEveVector.cxx:76
 TEveVector.cxx:77
 TEveVector.cxx:78
 TEveVector.cxx:79
 TEveVector.cxx:80
 TEveVector.cxx:81
 TEveVector.cxx:82
 TEveVector.cxx:83
 TEveVector.cxx:84
 TEveVector.cxx:85
 TEveVector.cxx:86
 TEveVector.cxx:87
 TEveVector.cxx:88
 TEveVector.cxx:89
 TEveVector.cxx:90
 TEveVector.cxx:91
 TEveVector.cxx:92
 TEveVector.cxx:93
 TEveVector.cxx:94
 TEveVector.cxx:95
 TEveVector.cxx:96
 TEveVector.cxx:97
 TEveVector.cxx:98
 TEveVector.cxx:99
 TEveVector.cxx:100
 TEveVector.cxx:101
 TEveVector.cxx:102
 TEveVector.cxx:103
 TEveVector.cxx:104
 TEveVector.cxx:105
 TEveVector.cxx:106
 TEveVector.cxx:107
 TEveVector.cxx:108
 TEveVector.cxx:109
 TEveVector.cxx:110
 TEveVector.cxx:111
 TEveVector.cxx:112
 TEveVector.cxx:113
 TEveVector.cxx:114
 TEveVector.cxx:115
 TEveVector.cxx:116
 TEveVector.cxx:117
 TEveVector.cxx:118
 TEveVector.cxx:119
 TEveVector.cxx:120
 TEveVector.cxx:121
 TEveVector.cxx:122
 TEveVector.cxx:123
 TEveVector.cxx:124
 TEveVector.cxx:125
 TEveVector.cxx:126
 TEveVector.cxx:127
 TEveVector.cxx:128
 TEveVector.cxx:129
 TEveVector.cxx:130
 TEveVector.cxx:131
 TEveVector.cxx:132
 TEveVector.cxx:133
 TEveVector.cxx:134
 TEveVector.cxx:135
 TEveVector.cxx:136
 TEveVector.cxx:137
 TEveVector.cxx:138
 TEveVector.cxx:139
 TEveVector.cxx:140
 TEveVector.cxx:141
 TEveVector.cxx:142
 TEveVector.cxx:143
 TEveVector.cxx:144
 TEveVector.cxx:145
 TEveVector.cxx:146
 TEveVector.cxx:147
 TEveVector.cxx:148
 TEveVector.cxx:149
 TEveVector.cxx:150
 TEveVector.cxx:151
 TEveVector.cxx:152
 TEveVector.cxx:153
 TEveVector.cxx:154
 TEveVector.cxx:155
 TEveVector.cxx:156
 TEveVector.cxx:157
 TEveVector.cxx:158
 TEveVector.cxx:159
 TEveVector.cxx:160
 TEveVector.cxx:161