Logo ROOT   6.08/07
Reference Guide
TEveVector.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Author: Matevz Tadel 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TEveVector.h"
13 #include "TVector3.h"
14 
15 /** \class TEveVectorT
16 \ingroup TEve
17 Minimal, templated three-vector.
18 No TObject inheritance and virtual functions.
19 Also used in VSD.
20 */
21 
24 
25 ////////////////////////////////////////////////////////////////////////////////
26 /// Dump to stdout as "(x, y, z)\n".
27 
28 template<typename TT> void TEveVectorT<TT>::Dump() const
29 {
30  printf("(%f, %f, %f)\n", fX, fY, fZ);
31 }
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// Set from TVector3.
35 
36 template<typename TT> void TEveVectorT<TT>::Set(const TVector3& v)
37 {
38  fX = v.x(); fY = v.y(); fZ = v.z();
39 }
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// Calculate eta of the point, pretending it's a momentum vector.
43 
44 template<typename TT> TT TEveVectorT<TT>::Eta() const
45 {
46  TT cosTheta = CosTheta();
47  if (cosTheta*cosTheta < 1) return -0.5* TMath::Log( (1.0-cosTheta)/(1.0+cosTheta) );
48  Warning("Eta","transverse momentum = 0, returning +/- 1e10");
49  return (fZ >= 0) ? 1e10 : -1e10;
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Normalize the vector to length if current length is non-zero.
54 /// Returns the old magnitude.
55 
56 template<typename TT> TT TEveVectorT<TT>::Normalize(TT length)
57 {
58  TT m = Mag();
59  if (m != 0)
60  {
61  length /= m;
62  fX *= length; fY *= length; fZ *= length;
63  }
64  return m;
65 }
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// Returns an orthogonal vector (not normalized).
69 
70 template<typename TT> TEveVectorT<TT> TEveVectorT<TT>::Orthogonal() const
71 {
72  Float_t xx = fX < 0 ? -fX : fX;
73  Float_t yy = fY < 0 ? -fY : fY;
74  Float_t zz = fZ < 0 ? -fZ : fZ;
75  if (xx < yy) {
76  return xx < zz ? TEveVectorT<TT>(0,fZ,-fY) : TEveVectorT<TT>(fY,-fX,0);
77  } else {
78  return yy < zz ? TEveVectorT<TT>(-fZ,0,fX) : TEveVectorT<TT>(fY,-fX,0);
79  }
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Set vectors a and b to be normal to this and among themselves,
84 /// both of length 1.
85 
87 {
88  a = Orthogonal();
89  TMath::Cross(this->Arr(), a.Arr(), b.Arr());
90  a.Normalize();
91  b.Normalize();
92 }
93 
94 template class TEveVectorT<Float_t>;
95 template class TEveVectorT<Double_t>;
96 
97 /** \class TEveVector4T
98 \ingroup TEve
99 Minimal, templated four-vector.
100 No TObject inheritance and virtual functions.
101 Also used in VSD.
102 */
103 
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 /// Dump to stdout as "(x, y, z; t)\n".
109 
110 template<typename TT> void TEveVector4T<TT>::Dump() const
111 {
112  printf("(%f, %f, %f; %f)\n", TP::fX, TP::fY, TP::fZ, fT);
113 }
114 
115 template class TEveVector4T<Float_t>;
116 template class TEveVector4T<Double_t>;
117 
118 /** \class TEveVector2T
119 \ingroup TEve
120 Minimal, templated two-vector.
121 No TObject inheritance and virtual functions.
122 Also used in VSD.
123 */
124 
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// Normalize the vector to length if current length is non-zero.
130 
131 template<typename TT> void TEveVector2T<TT>::Normalize(TT length)
132 {
133  Float_t m = Mag();
134  if (m != 0)
135  {
136  m = length / m;
137  fX *= m; fY *= m;
138  }
139 }
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 /// Dump to stdout as "(x, y)\n".
143 
144 template<typename TT> void TEveVector2T<TT>::Dump() const
145 {
146  printf("(%f, %f)\n", fX, fY);
147 }
148 
149 template class TEveVector2T<Float_t>;
150 template class TEveVector2T<Double_t>;
Double_t Log(Double_t x)
Definition: TMath.h:526
float Float_t
Definition: RtypesCore.h:53
void Set(const Float_t *v)
Definition: TEveVector.h:52
void Dump() const
Dump to stdout as "(x, y, z; t)\n".
Definition: TEveVector.cxx:110
void Dump() const
Dump to stdout as "(x, y, z)\n".
Definition: TEveVector.cxx:28
T Mag(const SVector< T, D > &rhs)
Vector magnitude (Euclidian norm) Compute : .
Definition: Functions.h:254
TArc * a
Definition: textangle.C:12
Double_t y() const
Definition: TVector3.h:222
Minimal, templated four-vector.
Definition: TEveVector.h:212
const TT * Arr() const
Definition: TEveVector.h:45
TVector3 is a general three vector class, which can be used for the description of different vectors ...
Definition: TVector3.h:30
SVector< double, 2 > v
Definition: Dict.h:5
void OrthoNormBase(TEveVectorT &a, TEveVectorT &b) const
Set vectors a and b to be normal to this and among themselves, both of length 1.
Definition: TEveVector.cxx:86
TMarker * m
Definition: textangle.C:8
Minimal, templated two-vector.
Definition: TEveVector.h:280
T * Cross(const T v1[3], const T v2[3], T out[3])
Definition: TMath.h:1007
void Warning(const char *location, const char *msgfmt,...)
void Normalize(TT length=1)
Normalize the vector to length if current length is non-zero.
Definition: TEveVector.cxx:131
Double_t z() const
Definition: TVector3.h:223
#define ClassImp(name)
Definition: Rtypes.h:279
TT Eta() const
Calculate eta of the point, pretending it&#39;s a momentum vector.
Definition: TEveVector.cxx:44
Double_t x() const
Definition: TVector3.h:221
TT Normalize(TT length=1)
Normalize the vector to length if current length is non-zero.
Definition: TEveVector.cxx:56
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
TEveVectorT Orthogonal() const
Returns an orthogonal vector (not normalized).
Definition: TEveVector.cxx:70
void Dump() const
Dump to stdout as "(x, y)\n".
Definition: TEveVector.cxx:144
double CosTheta(const Vector1 &v1, const Vector2 &v2)
Find CosTheta Angle between two generic 3D vectors pre-requisite: vectors implement the X()...
Definition: VectorUtil.h:114