Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
REveVector.cxx
Go to the documentation of this file.
1 // @(#)root/eve7:$Id$
2 // Author: Matevz Tadel 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2019, 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 <ROOT/REveVector.hxx>
13 #include "TVector3.h"
14 
15 namespace ROOT {
16 namespace Experimental {
17 
18 /** \class REveVectorT
19 \ingroup REve
20 Minimal, templated three-vector.
21 No TObject inheritance and virtual functions.
22 Also used in VSD.
23 */
24 
25 ////////////////////////////////////////////////////////////////////////////////
26 /// Dump to stdout as "(x, y, z)\n".
27 
28 template<typename TT> void REveVectorT<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 REveVectorT<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 REveVectorT<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 REveVectorT<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> REveVectorT<TT> REveVectorT<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 ? REveVectorT<TT>(0,fZ,-fY) : REveVectorT<TT>(fY,-fX,0);
77  } else {
78  return yy < zz ? REveVectorT<TT>(-fZ,0,fX) : REveVectorT<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 
86 template<typename TT> void REveVectorT<TT>::OrthoNormBase(REveVectorT<TT>& a, REveVectorT<TT>& b) const
87 {
88  REveVectorT<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 REveVectorT<Float_t>;
97 template class REveVectorT<Double_t>;
98 
99 /** \class REveVector4T
100 \ingroup REve
101 Minimal, templated four-vector.
102 No TObject inheritance and virtual functions.
103 Also used in VSD.
104 */
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Dump to stdout as "(x, y, z; t)\n".
108 
109 template<typename TT> void REveVector4T<TT>::Dump() const
110 {
111  printf("(%f, %f, %f; %f)\n", TP::fX, TP::fY, TP::fZ, fT);
112 }
113 
114 template class REveVector4T<Float_t>;
115 template class REveVector4T<Double_t>;
116 
117 /** \class REveVector2T
118 \ingroup REve
119 Minimal, templated two-vector.
120 No TObject inheritance and virtual functions.
121 Also used in VSD.
122 */
123 
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// Normalize the vector to length if current length is non-zero.
127 
128 template<typename TT> void REveVector2T<TT>::Normalize(TT length)
129 {
130  Float_t m = Mag();
131  if (m != 0)
132  {
133  m = length / m;
134  fX *= m; fY *= m;
135  }
136 }
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// Dump to stdout as "(x, y)\n".
140 
141 template<typename TT> void REveVector2T<TT>::Dump() const
142 {
143  printf("(%f, %f)\n", fX, fY);
144 }
145 
146 template class REveVector2T<Float_t>;
147 template class REveVector2T<Double_t>;
148 
149 } // namespace Experimental
150 } // namespace ROOT