forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEveVector.cxx
150 lines (121 loc) · 4.26 KB
/
TEveVector.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// @(#)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"
/** \class TEveVectorT
\ingroup TEve
Minimal, templated three-vector.
No TObject inheritance and virtual functions.
Also used in VSD.
*/
ClassImp(TEveVectorT<Float_t>);
ClassImp(TEveVectorT<Double_t>);
////////////////////////////////////////////////////////////////////////////////
/// Dump to stdout as "(x, y, z)\n".
template<typename TT> void TEveVectorT<TT>::Dump() const
{
printf("(%f, %f, %f)\n", fX, fY, fZ);
}
////////////////////////////////////////////////////////////////////////////////
/// Set from TVector3.
template<typename TT> void TEveVectorT<TT>::Set(const TVector3& v)
{
fX = v.x(); fY = v.y(); fZ = v.z();
}
////////////////////////////////////////////////////////////////////////////////
/// Calculate eta of the point, pretending it's a momentum vector.
template<typename TT> TT TEveVectorT<TT>::Eta() const
{
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;
}
////////////////////////////////////////////////////////////////////////////////
/// Normalize the vector to length if current length is non-zero.
/// Returns the old magnitude.
template<typename TT> TT TEveVectorT<TT>::Normalize(TT length)
{
TT m = Mag();
if (m != 0)
{
length /= m;
fX *= length; fY *= length; fZ *= length;
}
return m;
}
////////////////////////////////////////////////////////////////////////////////
/// Returns an orthogonal vector (not normalized).
template<typename TT> TEveVectorT<TT> TEveVectorT<TT>::Orthogonal() const
{
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);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Set vectors a and b to be normal to this and among themselves,
/// both of length 1.
template<typename TT> void TEveVectorT<TT>::OrthoNormBase(TEveVectorT<TT>& a, TEveVectorT<TT>& b) const
{
a = Orthogonal();
TMath::Cross(this->Arr(), a.Arr(), b.Arr());
a.Normalize();
b.Normalize();
}
template class TEveVectorT<Float_t>;
template class TEveVectorT<Double_t>;
/** \class TEveVector4T
\ingroup TEve
Minimal, templated four-vector.
No TObject inheritance and virtual functions.
Also used in VSD.
*/
ClassImp(TEveVector4T<Float_t>);
ClassImp(TEveVector4T<Double_t>);
////////////////////////////////////////////////////////////////////////////////
/// Dump to stdout as "(x, y, z; t)\n".
template<typename TT> void TEveVector4T<TT>::Dump() const
{
printf("(%f, %f, %f; %f)\n", TP::fX, TP::fY, TP::fZ, fT);
}
template class TEveVector4T<Float_t>;
template class TEveVector4T<Double_t>;
/** \class TEveVector2T
\ingroup TEve
Minimal, templated two-vector.
No TObject inheritance and virtual functions.
Also used in VSD.
*/
ClassImp(TEveVector2T<Float_t>);
ClassImp(TEveVector2T<Double_t>);
////////////////////////////////////////////////////////////////////////////////
/// Normalize the vector to length if current length is non-zero.
template<typename TT> void TEveVector2T<TT>::Normalize(TT length)
{
Float_t m = Mag();
if (m != 0)
{
m = length / m;
fX *= m; fY *= m;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Dump to stdout as "(x, y)\n".
template<typename TT> void TEveVector2T<TT>::Dump() const
{
printf("(%f, %f)\n", fX, fY);
}
template class TEveVector2T<Float_t>;
template class TEveVector2T<Double_t>;