Fork me on GitHub

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

Last change on this file since 671 was 572, checked in by cp3-support, 13 years ago

upgrade HepMC to version 2.06.05

File size: 3.9 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::perp2() const { return m_x*m_x + m_y*m_y; }
52
53inline double FourVector::perp() const { return std::sqrt(perp2()); }
54
55inline double FourVector::theta() const {
56 return m_x == 0.0 && m_y == 0.0 && m_z == 0.0 ? 0.0 : std::atan2(perp(),m_z);
57}
58
59inline double FourVector::phi() const {
60 return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
61}
62
63inline double FourVector::rho() const {
64return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
65}
66
67inline bool FourVector::operator == (const FourVector & v) const {
68 return (v.x()==x() && v.y()==y() && v.z()==z() && v.t()==t()) ? true : false;
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 double FourVector::pseudoRapidity() const {
76 double m = std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
77 if ( m== 0 ) return 0.0;
78 if ( m== z() ) return 1.0E72;
79 if ( m== -z() ) return -1.0E72;
80 return 0.5*log( (m+z())/(m-z()) );
81}
82
83inline double FourVector::eta() const { return pseudoRapidity();}
84
85
86//////////////////////////////////////////////////////////////////////////
87// ThreeVector inline methods
88//////////////////////////////////////////////////////////////////////////
89
90inline void ThreeVector::swap( ThreeVector & other ) {
91 std::swap( m_x, other.m_x );
92 std::swap( m_y, other.m_y );
93 std::swap( m_z, other.m_z );
94}
95
96inline double ThreeVector::theta() const {
97 return m_x == 0.0 && m_y == 0.0 && m_z == 0.0 ? 0.0 : std::atan2(perp(),m_z);
98}
99
100inline double ThreeVector::phi() const {
101 return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
102}
103
104inline double ThreeVector::r() const {
105return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
106}
107
108inline void ThreeVector::set(double x, double y, double z) {
109 m_x = x;
110 m_y = y;
111 m_z = z;
112}
113
114inline void ThreeVector::setPhi(double ph) {
115 double xy = perp();
116 setX(xy*std::cos(ph));
117 setY(xy*std::sin(ph));
118}
119
120inline void ThreeVector::setTheta(double th) {
121 double ma = r();
122 double ph = phi();
123 setX(ma*std::sin(th)*std::cos(ph));
124 setY(ma*std::sin(th)*std::sin(ph));
125 setZ(ma*std::cos(th));
126}
127
128inline double ThreeVector::perp2() const { return m_x*m_x + m_y*m_y; }
129
130inline double ThreeVector::perp() const { return std::sqrt(perp2()); }
131
132inline ThreeVector & ThreeVector::operator = (const ThreeVector & p) {
133 m_x = p.x();
134 m_y = p.y();
135 m_z = p.z();
136 return *this;
137}
138
139
140inline bool ThreeVector::operator == (const ThreeVector& v) const {
141 return (v.x()==x() && v.y()==y() && v.z()==z()) ? true : false;
142}
143
144inline bool ThreeVector::operator != (const ThreeVector& v) const {
145 return (v.x()!=x() || v.y()!=y() || v.z()!=z()) ? true : false;
146}
147
148} // HepMC
Note: See TracBrowser for help on using the repository browser.