StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SimpleVector.h
1 // SimpleVector.h
4 #ifndef HEPMC_SIMPLEVECTOR_H
5 #define HEPMC_SIMPLEVECTOR_H
6 
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 //
24 
25 
26 #include "HepMC/enable_if.h"
27 #include "HepMC/is_arithmetic.h"
28 
29 
30 namespace HepMC {
31 
33 
42 class FourVector {
43 
44 public:
45 
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 
51  FourVector(double tin)
52  : m_x(0), m_y(0), m_z(0), m_t(tin) {}
53 
54  FourVector()
55  : m_x(0), m_y(0), m_z(0), m_t(0) {}
56 
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 
66  : m_x(v.x()), m_y(v.y()), m_z(v.z()), m_t(v.t()) {}
67 
68  void swap( FourVector & other );
69 
70  double px() const { return m_x; }
71  double py() const { return m_y; }
72  double pz() const { return m_z; }
73  double e() const { return m_t; }
74 
75  double x() const { return m_x; }
76  double y() const { return m_y; }
77  double z() const { return m_z; }
78  double t() const { return m_t; }
79 
80  double m2() const;
81  double m() const;
82 
83  double perp2() const;
84  double perp() const;
85 
86  // Get spatial vector components in spherical coordinate system.
87  double theta() const;
88  double phi() const;
89  double rho() const;
90 
91  FourVector & operator = (const FourVector &);
92 
93  bool operator == (const FourVector &) const;
94  bool operator != (const FourVector &) const;
95 
96  double pseudoRapidity() const;
97  double eta() const;
98 
100  void set (double x, double y, double z, double t);
101 
102  void setX(double xin) { m_x=xin; }
103  void setY(double yin) { m_y=yin; }
104  void setZ(double zin) { m_z=zin; }
105  void setT(double tin) { m_t=tin; }
106 
107  void setPx(double xin) { m_x=xin; }
108  void setPy(double yin) { m_y=yin; }
109  void setPz(double zin) { m_z=zin; }
110  void setE(double tin) { m_t=tin; }
111 
112 private:
113 
114  double m_x;
115  double m_y;
116  double m_z;
117  double m_t;
118 
119 };
120 
122 
131 class ThreeVector {
132 
133 public:
134 
136  ThreeVector( double xin, double yin =0, double zin =0 )
137  : m_x(xin), m_y(yin), m_z(zin) {}
138 
139  ThreeVector( )
140  : m_x(0), m_y(0), m_z(0) {}
141 
144  template <class T >
145  ThreeVector( const T& v,
146  typename detail::disable_if< detail::is_arithmetic<T>::value, void >::type * = 0 )
147  : m_x(v.x()), m_y(v.y()), m_z(v.z()) {}
148 
151  : m_x(v.x()), m_y(v.y()), m_z(v.z()) {}
152 
153  void swap( ThreeVector & other );
154 
155  double x() const { return m_x; }
156  double y() const { return m_y; }
157  double z() const { return m_z; }
158 
159  void setX(double xin) { m_x=xin; }
160  void setY(double yin) { m_y=yin; }
161  void setZ(double zin) { m_z=zin; }
162  void set( double x, double y, double z);
163 
164  double phi() const;
165  double theta() const;
166  double r() const;
167 
168  void setPhi(double);
169  void setTheta(double);
170 
171  double perp2() const;
172  double perp() const;
173 
174  ThreeVector & operator = (const ThreeVector &);
175 
176  bool operator == (const ThreeVector &) const;
177  bool operator != (const ThreeVector &) const;
178 
179 private:
180 
181  double m_x;
182  double m_y;
183  double m_z;
184 
185 };
186 
187 
188 } // HepMC
189 
190 #include "HepMC/SimpleVector.icc"
191 
192 #endif // HEPMC_SIMPLEVECTOR_H
193 
double z() const
return z
Definition: SimpleVector.h:157
void setT(double tin)
set t
Definition: SimpleVector.h:105
bool operator==(const FourVector &) const
equality
FourVector & operator=(const FourVector &)
make a copy
double perp() const
The transverse component (rho in cylindrical coordinate system).
FourVector(double xin, double yin, double zin, double tin=0)
constructor requiring at least x, y, and z
Definition: SimpleVector.h:47
double theta() const
The polar angle.
void setPz(double zin)
set pz
Definition: SimpleVector.h:109
double r() const
The magnitude.
bool operator==(const ThreeVector &) const
equality
double x() const
return x
Definition: SimpleVector.h:155
double z() const
return z
Definition: SimpleVector.h:77
bool operator!=(const FourVector &) const
inequality
void setY(double yin)
set y
Definition: SimpleVector.h:160
ThreeVector(const T &v, typename detail::disable_if< detail::is_arithmetic< T >::value, void >::type *=0)
Definition: SimpleVector.h:145
double theta() const
The polar angle.
double e() const
return E
Definition: SimpleVector.h:73
double m() const
Invariant mass. If m2() is negative then -sqrt(-m2()) is returned.
double y() const
return y
Definition: SimpleVector.h:76
double px() const
return px
Definition: SimpleVector.h:70
double y() const
return y
Definition: SimpleVector.h:156
double rho() const
spatial vector component magnitude
ThreeVector(double xin, double yin=0, double zin=0)
construct using x, y, and z (only x is required)
Definition: SimpleVector.h:136
double phi() const
The azimuth angle.
void swap(FourVector &other)
swap
double pz() const
return pz
Definition: SimpleVector.h:72
void setPhi(double)
Set phi keeping magnitude and theta constant (BaBar).
void setX(double xin)
set x
Definition: SimpleVector.h:159
FourVector(const T &v, typename detail::disable_if< detail::is_arithmetic< T >::value, void >::type *=0)
Definition: SimpleVector.h:60
bool operator!=(const ThreeVector &) const
inequality
ThreeVector is a simple representation of a position or displacement 3 vector.
Definition: SimpleVector.h:131
ThreeVector(const ThreeVector &v)
copy constructor
Definition: SimpleVector.h:150
double x() const
return x
Definition: SimpleVector.h:75
void set(double x, double y, double z, double t)
set x, y, z, and t
double phi() const
The azimuth angle.
internal - used by SimpleVector to decide if a class is arithmetic
Definition: enable_if.h:33
ThreeVector & operator=(const ThreeVector &)
make a copy
double eta() const
Pseudorapidity (of the space part)
void setZ(double zin)
set z
Definition: SimpleVector.h:104
FourVector(const FourVector &v)
copy constructor
Definition: SimpleVector.h:65
double perp() const
Transverse component of the spatial vector (R in cylindrical system).
undefined and therefore non-arithmetic
Definition: is_arithmetic.h:22
void setY(double yin)
set y
Definition: SimpleVector.h:103
FourVector(double tin)
constructor requiring only t
Definition: SimpleVector.h:51
FourVector is a simple representation of a physics 4 vector.
Definition: SimpleVector.h:42
double m2() const
Invariant mass squared.
double perp2() const
Transverse component of the spatial vector squared.
void setE(double tin)
set E
Definition: SimpleVector.h:110
void setPx(double xin)
set px
Definition: SimpleVector.h:107
void setX(double xin)
set x
Definition: SimpleVector.h:102
void setPy(double yin)
set py
Definition: SimpleVector.h:108
double py() const
return py
Definition: SimpleVector.h:71
double pseudoRapidity() const
Returns the pseudo-rapidity, i.e. -ln(tan(theta/2))
void swap(ThreeVector &other)
swap
double perp2() const
The transverse component squared (rho^2 in cylindrical coordinate system).
double t() const
return t
Definition: SimpleVector.h:78
void setTheta(double)
Set theta keeping magnitude and phi constant (BaBar).
void setZ(double zin)
set z
Definition: SimpleVector.h:161
void set(double x, double y, double z)
set x, y, and z