Fork me on GitHub

source: svn/trunk/Utilities/HepMC/interface/SimpleVector.icc@ 406

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

first test

File size: 4.0 KB
Line 
1//////////////////////////////////////////////////////////////////////////
2// SimpleVector.icc
3//////////////////////////////////////////////////////////////////////////
4
5//////////////////////////////////////////////////////////////////////////
6// garren@fnal.gov, July 2006
7//
8//
9//////////////////////////////////////////////////////////////////////////
10
11#include <cmath>
12#include <algorithm> // for swap
13
14namespace HepMC {
15
16//////////////////////////////////////////////////////////////////////////
17// FourVector inline methods
18//////////////////////////////////////////////////////////////////////////
19
20inline void FourVector::swap( FourVector & other ) {
21 std::swap( m_x, other.m_x );
22 std::swap( m_y, other.m_y );
23 std::swap( m_z, other.m_z );
24 std::swap( m_t, other.m_t );
25}
26
27inline FourVector & FourVector::operator=(const FourVector & v) {
28 m_x = v.x();
29 m_y = v.y();
30 m_z = v.z();
31 m_t = v.t();
32 return *this;
33}
34
35inline void FourVector::set(double x, double y, double z, double t) {
36 m_x = x;
37 m_y = y;
38 m_z = z;
39 m_t = t;
40}
41
42inline double FourVector::m2() const {
43 return m_t*m_t - (m_x*m_x + m_y*m_y + m_z*m_z);
44}
45
46inline double FourVector::m() const {
47 double mm = m2();
48 return mm < 0.0 ? -std::sqrt(-mm) : std::sqrt(mm);
49}
50
51inline double FourVector::mag() const {
52return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
53}
54
55inline double FourVector::perp2() const { return m_x*m_x + m_y*m_y; }
56
57inline double FourVector::perp() const { return std::sqrt(perp2()); }
58
59inline double FourVector::theta() const {
60 return m_x == 0.0 && m_y == 0.0 && m_z == 0.0 ? 0.0 : std::atan2(perp(),m_z);
61}
62
63inline double FourVector::phi() const {
64 return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
65}
66
67inline double FourVector::rho() const {
68return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
69}
70
71inline bool FourVector::operator == (const FourVector & v) const {
72 return (v.x()==x() && v.y()==y() && v.z()==z() && v.t()==t()) ? true : false;
73}
74
75inline bool FourVector::operator != (const FourVector & v) const {
76 return (v.x()!=x() || v.y()!=y() || v.z()!=z() || v.t()!=t()) ? true : false;
77}
78
79inline double FourVector::pseudoRapidity() const {
80 double m = mag();
81 if ( m== 0 ) return 0.0;
82 if ( m== z() ) return 1.0E72;
83 if ( m== -z() ) return -1.0E72;
84 return 0.5*log( (m+z())/(m-z()) );
85}
86
87inline double FourVector::eta() const { return pseudoRapidity();}
88
89
90//////////////////////////////////////////////////////////////////////////
91// ThreeVector inline methods
92//////////////////////////////////////////////////////////////////////////
93
94inline void ThreeVector::swap( ThreeVector & other ) {
95 std::swap( m_x, other.m_x );
96 std::swap( m_y, other.m_y );
97 std::swap( m_z, other.m_z );
98}
99
100inline double ThreeVector::theta() const {
101 return m_x == 0.0 && m_y == 0.0 && m_z == 0.0 ? 0.0 : std::atan2(perp(),m_z);
102}
103
104inline double ThreeVector::phi() const {
105 return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
106}
107
108inline double ThreeVector::mag() const {
109return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
110}
111
112inline double ThreeVector::r() const { return mag(); }
113
114inline void ThreeVector::set(double x, double y, double z) {
115 m_x = x;
116 m_y = y;
117 m_z = z;
118}
119
120inline void ThreeVector::setPhi(double ph) {
121 double xy = perp();
122 setX(xy*std::cos(ph));
123 setY(xy*std::sin(ph));
124}
125
126inline void ThreeVector::setTheta(double th) {
127 double ma = mag();
128 double ph = phi();
129 setX(ma*std::sin(th)*std::cos(ph));
130 setY(ma*std::sin(th)*std::sin(ph));
131 setZ(ma*std::cos(th));
132}
133
134inline double ThreeVector::perp2() const { return m_x*m_x + m_y*m_y; }
135
136inline double ThreeVector::perp() const { return std::sqrt(perp2()); }
137
138inline ThreeVector & ThreeVector::operator = (const ThreeVector & p) {
139 m_x = p.x();
140 m_y = p.y();
141 m_z = p.z();
142 return *this;
143}
144
145
146inline bool ThreeVector::operator == (const ThreeVector& v) const {
147 return (v.x()==x() && v.y()==y() && v.z()==z()) ? true : false;
148}
149
150inline bool ThreeVector::operator != (const ThreeVector& v) const {
151 return (v.x()!=x() || v.y()!=y() || v.z()!=z()) ? true : false;
152}
153
154} // HepMC
Note: See TracBrowser for help on using the repository browser.