Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
17Minimal, templated three-vector.
18No TObject inheritance and virtual functions.
19Also used in VSD.
20*/
21
22
23////////////////////////////////////////////////////////////////////////////////
24/// Dump to stdout as "(x, y, z)\n".
25
26template<typename TT> void TEveVectorT<TT>::Dump() const
27{
28 printf("(%f, %f, %f)\n", fX, fY, fZ);
29}
30
31////////////////////////////////////////////////////////////////////////////////
32/// Set from TVector3.
33
34template<typename TT> void TEveVectorT<TT>::Set(const TVector3& v)
35{
36 fX = v.x(); fY = v.y(); fZ = v.z();
37}
38
39////////////////////////////////////////////////////////////////////////////////
40/// Calculate eta of the point, pretending it's a momentum vector.
41
42template<typename TT> TT TEveVectorT<TT>::Eta() const
43{
44 TT cosTheta = CosTheta();
45 if (cosTheta*cosTheta < 1) return -0.5* TMath::Log( (1.0-cosTheta)/(1.0+cosTheta) );
46 Warning("Eta","transverse momentum = 0, returning +/- 1e10");
47 return (fZ >= 0) ? 1e10 : -1e10;
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Normalize the vector to length if current length is non-zero.
52/// Returns the old magnitude.
53
54template<typename TT> TT TEveVectorT<TT>::Normalize(TT length)
55{
56 TT m = Mag();
57 if (m != 0)
58 {
59 length /= m;
60 fX *= length; fY *= length; fZ *= length;
61 }
62 return m;
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Returns an orthogonal vector (not normalized).
67
68template<typename TT> TEveVectorT<TT> TEveVectorT<TT>::Orthogonal() const
69{
70 Float_t xx = fX < 0 ? -fX : fX;
71 Float_t yy = fY < 0 ? -fY : fY;
72 Float_t zz = fZ < 0 ? -fZ : fZ;
73 if (xx < yy) {
74 return xx < zz ? TEveVectorT<TT>(0,fZ,-fY) : TEveVectorT<TT>(fY,-fX,0);
75 } else {
76 return yy < zz ? TEveVectorT<TT>(-fZ,0,fX) : TEveVectorT<TT>(fY,-fX,0);
77 }
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Set vectors a and b to be normal to this and among themselves,
82/// both of length 1.
83
86 TEveVectorT<TT> v(*this);
87 v.Normalize();
88 a = v.Orthogonal();
89 a.Normalize();
90 b = v.Cross(a);
91 b.Normalize();
92}
93
94template class TEveVectorT<Float_t>;
95template class TEveVectorT<Double_t>;
97/** \class TEveVector4T
98\ingroup TEve
99Minimal, templated four-vector.
100No TObject inheritance and virtual functions.
101Also used in VSD.
102*/
103
104
105////////////////////////////////////////////////////////////////////////////////
106/// Dump to stdout as "(x, y, z; t)\n".
107
108template<typename TT> void TEveVector4T<TT>::Dump() const
109{
110 printf("(%f, %f, %f; %f)\n", TP::fX, TP::fY, TP::fZ, fT);
111}
112
113template class TEveVector4T<Float_t>;
114template class TEveVector4T<Double_t>;
116/** \class TEveVector2T
117\ingroup TEve
118Minimal, templated two-vector.
119No TObject inheritance and virtual functions.
120Also used in VSD.
121*/
122
123
124////////////////////////////////////////////////////////////////////////////////
125/// Normalize the vector to length if current length is non-zero.
126
127template<typename TT> void TEveVector2T<TT>::Normalize(TT length)
128{
129 Float_t m = Mag();
130 if (m != 0)
131 {
132 m = length / m;
133 fX *= m; fY *= m;
134 }
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// Dump to stdout as "(x, y)\n".
139
140template<typename TT> void TEveVector2T<TT>::Dump() const
141{
142 printf("(%f, %f)\n", fX, fY);
143}
144
145template class TEveVector2T<Float_t>;
146template class TEveVector2T<Double_t>;
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
void Dump() const
Dump to stdout as "(x, y)\n".
void Normalize(TT length=1)
Normalize the vector to length if current length is non-zero.
void Dump() const
Dump to stdout as "(x, y, z; t)\n".
void OrthoNormBase(TEveVectorT &a, TEveVectorT &b) const
Set vectors a and b to be normal to this and among themselves, both of length 1.
TT Normalize(TT length=1)
Normalize the vector to length if current length is non-zero.
TT Eta() const
Calculate eta of the point, pretending it's a momentum vector.
TEveVectorT Orthogonal() const
Returns an orthogonal vector (not normalized).
void Dump() const
Dump to stdout as "(x, y, z)\n".
void Set(const Float_t *v)
Definition TEveVector.h:82
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Definition TMath.h:767
TMarker m
Definition textangle.C:8