Line data Source code
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 "HepMC/enable_if.h"
27 : #include "HepMC/is_arithmetic.h"
28 :
29 :
30 : namespace 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 : ///
42 : class FourVector {
43 :
44 : public:
45 :
46 : /// constructor requiring at least x, y, and z
47 : FourVector( double xin, double yin, double zin, double tin=0)
48 0 : : m_x(xin), m_y(yin), m_z(zin), m_t(tin) {}
49 :
50 : /// constructor requiring only t
51 : FourVector(double tin)
52 0 : : 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 :
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 0 : : 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 0 : double px() const { return m_x; } //!< return px
71 0 : double py() const { return m_y; } //!< return py
72 0 : double pz() const { return m_z; } //!< return pz
73 0 : double e() const { return m_t; } //!< return E
74 :
75 0 : double x() const { return m_x; } //!< return x
76 0 : double y() const { return m_y; } //!< return y
77 0 : double z() const { return m_z; } //!< return z
78 0 : 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 :
86 : // Get spatial vector components in spherical coordinate system.
87 : double theta() const; //!< The polar angle.
88 : double phi() const; //!< The azimuth angle.
89 : double rho() const; //!< spatial vector component magnitude
90 :
91 : FourVector & operator = (const FourVector &); //!< make a copy
92 :
93 : bool operator == (const FourVector &) const; //!< equality
94 : bool operator != (const FourVector &) const; //!< inequality
95 :
96 : double pseudoRapidity() const; //!< Returns the pseudo-rapidity, i.e. -ln(tan(theta/2))
97 : double eta() const; //!< Pseudorapidity (of the space part)
98 :
99 : /// set x, y, z, and t
100 : void set (double x, double y, double z, double t);
101 :
102 0 : void setX(double xin) { m_x=xin; } //!< set x
103 0 : void setY(double yin) { m_y=yin; } //!< set y
104 0 : void setZ(double zin) { m_z=zin; } //!< set z
105 0 : void setT(double tin) { m_t=tin; } //!< set t
106 :
107 0 : void setPx(double xin) { m_x=xin; } //!< set px
108 0 : void setPy(double yin) { m_y=yin; } //!< set py
109 0 : void setPz(double zin) { m_z=zin; } //!< set pz
110 0 : void setE(double tin) { m_t=tin; } //!< set E
111 :
112 : private:
113 :
114 : double m_x;
115 : double m_y;
116 : double m_z;
117 : double m_t;
118 :
119 : };
120 :
121 : //! ThreeVector is a simple representation of a position or displacement 3 vector
122 :
123 : ///
124 : /// \class ThreeVector
125 : /// For compatibility with existing code,
126 : /// the basic expected geometrical access methods are povided.
127 : /// Also, there is a templated constructor that will
128 : /// take another vector (HepLorentzVector, GenVector, ...)
129 : /// which must have the following methods: x(), y(), z().
130 : ///
131 : class ThreeVector {
132 :
133 : public:
134 :
135 : /// construct using x, y, and z (only x is required)
136 : ThreeVector( double xin, double yin =0, double zin =0 )
137 0 : : m_x(xin), m_y(yin), m_z(zin) {}
138 :
139 : ThreeVector( )
140 : : m_x(0), m_y(0), m_z(0) {}
141 :
142 : /// templated constructor
143 : /// this is used ONLY if T is not arithmetic
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 :
149 : /// copy constructor
150 : ThreeVector(const ThreeVector & v)
151 0 : : m_x(v.x()), m_y(v.y()), m_z(v.z()) {}
152 :
153 : void swap( ThreeVector & other ); //!< swap
154 :
155 0 : double x() const { return m_x; } //!< return x
156 0 : double y() const { return m_y; } //!< return y
157 0 : double z() const { return m_z; } //!< return z
158 :
159 0 : void setX(double xin) { m_x=xin; } //!< set x
160 0 : void setY(double yin) { m_y=yin; } //!< set y
161 0 : void setZ(double zin) { m_z=zin; } //!< set z
162 : void set( double x, double y, double z); //!< set x, y, and z
163 :
164 : double phi() const; //!< The azimuth angle.
165 : double theta() const; //!< The polar angle.
166 : double r() const; //!< The magnitude
167 :
168 : void setPhi(double); //!< Set phi keeping magnitude and theta constant (BaBar).
169 : void setTheta(double); //!< Set theta keeping magnitude and phi constant (BaBar).
170 :
171 : double perp2() const; //!< The transverse component squared (rho^2 in cylindrical coordinate system).
172 : double perp() const; //!< The transverse component (rho in cylindrical coordinate system).
173 :
174 : ThreeVector & operator = (const ThreeVector &); //!< make a copy
175 :
176 : bool operator == (const ThreeVector &) const; //!< equality
177 : bool operator != (const ThreeVector &) const; //!< inequality
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 :
|