Logo ROOT   6.14/05
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  TEveVectorT<TT> v(*this);
89  v.Normalize();
90  a = v.Orthogonal();
91  a.Normalize();
92  b = v.Cross(a);
93  b.Normalize();
94 }
95 
96 template class TEveVectorT<Float_t>;
97 template class TEveVectorT<Double_t>;
98 
99 /** \class TEveVector4T
100 \ingroup TEve
101 Minimal, templated four-vector.
102 No TObject inheritance and virtual functions.
103 Also used in VSD.
104 */
105 
108 
109 ////////////////////////////////////////////////////////////////////////////////
110 /// Dump to stdout as "(x, y, z; t)\n".
111 
112 template<typename TT> void TEveVector4T<TT>::Dump() const
113 {
114  printf("(%f, %f, %f; %f)\n", TP::fX, TP::fY, TP::fZ, fT);
115 }
116 
117 template class TEveVector4T<Float_t>;
118 template class TEveVector4T<Double_t>;
119 
120 /** \class TEveVector2T
121 \ingroup TEve
122 Minimal, templated two-vector.
123 No TObject inheritance and virtual functions.
124 Also used in VSD.
125 */
126 
129 
130 ////////////////////////////////////////////////////////////////////////////////
131 /// Normalize the vector to length if current length is non-zero.
132 
133 template<typename TT> void TEveVector2T<TT>::Normalize(TT length)
134 {
135  Float_t m = Mag();
136  if (m != 0)
137  {
138  m = length / m;
139  fX *= m; fY *= m;
140  }
141 }
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Dump to stdout as "(x, y)\n".
145 
146 template<typename TT> void TEveVector2T<TT>::Dump() const
147 {
148  printf("(%f, %f)\n", fX, fY);
149 }
150 
151 template class TEveVector2T<Float_t>;
152 template class TEveVector2T<Double_t>;
auto * m
Definition: textangle.C:8
Double_t Log(Double_t x)
Definition: TMath.h:759
float Float_t
Definition: RtypesCore.h:53
void Set(const Float_t *v)
Definition: TEveVector.h:78
void Dump() const
Dump to stdout as "(x, y, z; t)\n".
Definition: TEveVector.cxx:112
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:252
TEveVectorT Cross(const TEveVectorT &a) const
Definition: TEveVector.h:171
Double_t y() const
Definition: TVector3.h:214
Minimal, templated four-vector.
Definition: TEveVector.h:238
TVector3 is a general three vector class, which can be used for the description of different vectors ...
Definition: TVector3.h:22
SVector< double, 2 > v
Definition: Dict.h:5
auto * a
Definition: textangle.C:12
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
Minimal, templated two-vector.
Definition: TEveVector.h:306
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:133
Double_t z() const
Definition: TVector3.h:215
#define ClassImp(name)
Definition: Rtypes.h:359
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:213
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:146
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:112