Fork me on GitHub

source: svn/trunk/Utilities/HepMC/interface/SimpleVector.h@ 496

Last change on this file since 496 was 349, checked in by severine ovyn, 16 years ago

first test

File size: 6.3 KB
RevLine 
[349]1//////////////////////////////////////////////////////////////////////////
2// SimpleVector.h
3//////////////////////////////////////////////////////////////////////////
4#ifndef HEPMC_SIMPLEVECTOR_H
5#define HEPMC_SIMPLEVECTOR_H
6
7//////////////////////////////////////////////////////////////////////////
8// garren@fnal.gov, July 2006
9//
10// This header provides a place to hold the doubles which are part of one of
11// three types of physics vectors:
12// momentum 4 vector
13// position or displacement 4 vector
14// position or displacement 3 vector
15//
16// For compatibility with existing code,
17// the basic expected geometrical access methods are povided
18// Also, both FourVector and ThreeVector have a templated constructor that will
19// take another vector (HepLorentzVector, GenVector, ...)
20// --> this vector must have the following methods: x(), y(), z()
21// --> FourVector also requires the t() method
22//
23//////////////////////////////////////////////////////////////////////////
24
25
26#include "enable_if.h"
27#include "is_arithmetic.h"
28
29
30namespace HepMC {
31
32//! FourVector is a simple representation of a physics 4 vector
33
34///
35/// \class FourVector
36/// For compatibility with existing code,
37/// the basic expected geometrical access methods are povided.
38/// Also, there is a templated constructor that will
39/// take another vector (HepLorentzVector, GenVector, ...)
40/// which must have the following methods: x(), y(), z(), t().
41///
42class FourVector {
43
44public:
45
46 /// constructor requiring at least x, y, and z
47 FourVector( double xin, double yin, double zin, double tin=0)
48 : m_x(xin), m_y(yin), m_z(zin), m_t(tin) {}
49
50 /// constructor requiring only t
51 FourVector(double t)
52 : m_x(0), m_y(0), m_z(0), m_t(t) {}
53
54 FourVector()
55 : m_x(0), m_y(0), m_z(0), m_t(0) {}
56
57 /// templated constructor
58 /// this is used ONLY if T is not arithmetic
59 template <class T >
60 FourVector( const T& v,
61 typename detail::disable_if< detail::is_arithmetic<T>::value, void >::type * = 0 )
62 : m_x(v.x()), m_y(v.y()), m_z(v.z()), m_t(v.t()) {}
63
64 /// copy constructor
65 FourVector(const FourVector & v)
66 : m_x(v.x()), m_y(v.y()), m_z(v.z()), m_t(v.t()) {}
67
68 void swap( FourVector & other ); //!< swap
69
70 double px() const { return m_x; } //!< return px
71 double py() const { return m_y; } //!< return py
72 double pz() const { return m_z; } //!< return pz
73 double e() const { return m_t; } //!< return E
74
75 double x() const { return m_x; } //!< return x
76 double y() const { return m_y; } //!< return y
77 double z() const { return m_z; } //!< return z
78 double t() const { return m_t; } //!< return t
79
80 double m2() const; //!< Invariant mass squared.
81 double m() const; //!< Invariant mass. If m2() is negative then -sqrt(-m2()) is returned.
82
83 double perp2() const; //!< Transverse component of the spatial vector squared.
84 double perp() const; //!< Transverse component of the spatial vector (R in cylindrical system).
85 double mag() const; //!< Magnitude of the spatial vector
86
87 // Get spatial vector components in spherical coordinate system.
88 double theta() const; //!< The polar angle.
89 double phi() const; //!< The azimuth angle.
90 double rho() const; //!< spatial vector component magnitude
91
92 FourVector & operator = (const FourVector &); //!< make a copy
93
94 bool operator == (const FourVector &) const; //!< equality
95 bool operator != (const FourVector &) const; //!< inequality
96
97 double pseudoRapidity() const; //!< Returns the pseudo-rapidity, i.e. -ln(tan(theta/2))
98 double eta() const; //!< Pseudorapidity (of the space part)
99
100 /// set x, y, z, and t
101 void set (double x, double y, double z, double t);
102
103 void setX(double x) { m_x=x; } //!< set x
104 void setY(double y) { m_y=y; } //!< set y
105 void setZ(double z) { m_z=z; } //!< set z
106 void setT(double t) { m_t=t; } //!< set t
107
108 void setPx(double x) { m_x=x; } //!< set px
109 void setPy(double y) { m_y=y; } //!< set py
110 void setPz(double z) { m_z=z; } //!< set pz
111 void setE(double t) { m_t=t; } //!< set E
112
113private:
114
115 double m_x;
116 double m_y;
117 double m_z;
118 double m_t;
119
120};
121
122//! ThreeVector is a simple representation of a position or displacement 3 vector
123
124///
125/// \class ThreeVector
126/// For compatibility with existing code,
127/// the basic expected geometrical access methods are povided.
128/// Also, there is a templated constructor that will
129/// take another vector (HepLorentzVector, GenVector, ...)
130/// which must have the following methods: x(), y(), z().
131///
132class ThreeVector {
133
134public:
135
136 /// construct using x, y, and z (only x is required)
137 ThreeVector( double xin, double yin =0, double zin =0 )
138 : m_x(xin), m_y(yin), m_z(zin) {}
139
140 ThreeVector( )
141 : m_x(0), m_y(0), m_z(0) {}
142
143 /// templated constructor
144 /// this is used ONLY if T is not arithmetic
145 template <class T >
146 ThreeVector( const T& v,
147 typename detail::disable_if< detail::is_arithmetic<T>::value, void >::type * = 0 )
148 : m_x(v.x()), m_y(v.y()), m_z(v.z()) {}
149
150 /// copy constructor
151 ThreeVector(const ThreeVector & v)
152 : m_x(v.x()), m_y(v.y()), m_z(v.z()) {}
153
154 void swap( ThreeVector & other ); //!< swap
155
156 double x() const { return m_x; } //!< return x
157 double y() const { return m_y; } //!< return y
158 double z() const { return m_z; } //!< return z
159
160 void setX(double x) { m_x=x; } //!< set x
161 void setY(double y) { m_y=y; } //!< set y
162 void setZ(double z) { m_z=z; } //!< set z
163 void set( double x, double y, double z); //!< set x, y, and z
164
165 double phi() const; //!< The azimuth angle.
166 double theta() const; //!< The polar angle.
167 double r() const; //!< The magnitude
168
169 double mag() const; //!< The magnitude (r in spherical coordinate system).
170
171 void setPhi(double); //!< Set phi keeping mag and theta constant (BaBar).
172 void setTheta(double); //!< Set theta keeping mag and phi constant (BaBar).
173
174 double perp2() const; //!< The transverse component squared (rho^2 in cylindrical coordinate system).
175 double perp() const; //!< The transverse component (rho in cylindrical coordinate system).
176
177 ThreeVector & operator = (const ThreeVector &); //!< make a copy
178
179 bool operator == (const ThreeVector &) const; //!< equality
180 bool operator != (const ThreeVector &) const; //!< inequality
181
182private:
183
184 double m_x;
185 double m_y;
186 double m_z;
187
188};
189
190
191} // HepMC
192
193#include "SimpleVector.icc"
194
195#endif // HEPMC_SIMPLEVECTOR_H
196
Note: See TracBrowser for help on using the repository browser.