Logo ROOT  
Reference Guide
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
15namespace ROOT {
16namespace Experimental {
17
18/** \class REveVectorT
19\ingroup REve
20Minimal, templated three-vector.
21No TObject inheritance and virtual functions.
22Also used in VSD.
23*/
24
25////////////////////////////////////////////////////////////////////////////////
26/// Dump to stdout as "(x, y, z)\n".
27
28template<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
36template<typename TT> void REveVectorT<TT>::Set(const TVector3& v)
37{
38 fX = v.x(); fY = v.y(); fZ = v.z();
39}
41////////////////////////////////////////////////////////////////////////////////
42/// Calculate eta of the point, pretending it's a momentum vector.
43
44template<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
56template<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
70template<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
87{
88 REveVectorT<TT> v(*this);
89 v.Normalize();
90 a = v.Orthogonal();
91 a.Normalize();
92 b = v.Cross(a);
93 b.Normalize();
95
96template class REveVectorT<Float_t>;
97template class REveVectorT<Double_t>;
98
99/** \class REveVector4T
100\ingroup REve
101Minimal, templated four-vector.
102No TObject inheritance and virtual functions.
103Also used in VSD.
104*/
105
106////////////////////////////////////////////////////////////////////////////////
107/// Dump to stdout as "(x, y, z; t)\n".
108
109template<typename TT> void REveVector4T<TT>::Dump() const
110{
111 printf("(%f, %f, %f; %f)\n", TP::fX, TP::fY, TP::fZ, fT);
112}
115template class REveVector4T<Double_t>;
116
117/** \class REveVector2T
118\ingroup REve
119Minimal, templated two-vector.
120No TObject inheritance and virtual functions.
121Also used in VSD.
122*/
123
124
125////////////////////////////////////////////////////////////////////////////////
126/// Normalize the vector to length if current length is non-zero.
127
128template<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
141template<typename TT> void REveVector2T<TT>::Dump() const
142{
143 printf("(%f, %f)\n", fX, fY);
144}
145
146template class REveVector2T<Float_t>;
147template class REveVector2T<Double_t>;
148
149} // namespace Experimental
150} // namespace ROOT
#define b(i)
Definition: RSha256.hxx:100
float Float_t
Definition: RtypesCore.h:55
void Warning(const char *location, const char *msgfmt,...)
REveVector2T A two-vector template without TObject inheritance and virtual functions.
Definition: REveVector.hxx:305
void Normalize(TT length=1)
Normalize the vector to length if current length is non-zero.
Definition: REveVector.cxx:128
void Dump() const
Dump to stdout as "(x, y)\n".
Definition: REveVector.cxx:141
REveVector4T A four-vector template without TObject inheritance and virtual functions.
Definition: REveVector.hxx:239
void Dump() const
Dump to stdout as "(x, y, z; t)\n".
Definition: REveVector.cxx:109
REveVectorT A three-vector template without TObject inheritance and virtual functions.
Definition: REveVector.hxx:29
TT Normalize(TT length=1)
Normalize the vector to length if current length is non-zero.
Definition: REveVector.cxx:56
REveVectorT Orthogonal() const
Returns an orthogonal vector (not normalized).
Definition: REveVector.cxx:70
void Set(const Float_t *v)
Definition: REveVector.hxx:80
void OrthoNormBase(REveVectorT &a, REveVectorT &b) const
Set vectors a and b to be normal to this and among themselves, both of length 1.
Definition: REveVector.cxx:86
TT Eta() const
Calculate eta of the point, pretending it's a momentum vector.
Definition: REveVector.cxx:44
void Dump() const
Dump to stdout as "(x, y, z)\n".
Definition: REveVector.cxx:28
TVector3 is a general three vector class, which can be used for the description of different vectors ...
Definition: TVector3.h:22
T Mag(const SVector< T, D > &rhs)
Vector magnitude (Euclidian norm) Compute : .
Definition: Functions.h:252
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
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21
Double_t Log(Double_t x)
Definition: TMath.h:750
auto * m
Definition: textangle.C:8
auto * a
Definition: textangle.C:12