source: trunk/CLHEP/Vector/Boost.icc@ 20

Last change on this file since 20 was 4, checked in by Pavel Demin, 16 years ago

first commit

File size: 8.9 KB
Line 
1// -*- C++ -*-
2// ---------------------------------------------------------------------------
3//
4// This file is a part of the CLHEP - a Class Library for High Energy Physics.
5//
6// This is the definitions of the inline member functions of the
7// HepBoost class
8//
9
10#include <cmath>
11
12namespace CLHEP {
13
14// ---------- Constructors and Assignment:
15
16inline HepBoost::HepBoost() : rep_() {}
17
18inline HepBoost::HepBoost(const HepBoost & m) : rep_(m.rep_) {}
19
20inline HepBoost & HepBoost::operator = (const HepBoost & m) {
21 rep_ = m.rep_;
22 return *this;
23}
24
25inline HepBoost::HepBoost(double betaX, double betaY, double betaZ)
26{
27 set(betaX, betaY, betaZ);
28}
29
30inline HepBoost::HepBoost(const HepRep4x4Symmetric & m) : rep_(m) {}
31
32inline HepBoost::HepBoost(Hep3Vector direction, double beta)
33{
34 double length = direction.mag();
35 if (length==0) {
36 ZMthrowC ( ZMxpvZeroVector("HepBoost constructed using a zero vector as direction") );
37 set(0,0,0);
38 }
39 set(beta*direction.x()/length,
40 beta*direction.y()/length,
41 beta*direction.z()/length);
42}
43
44inline HepBoost::HepBoost(const Hep3Vector & boost)
45{
46 set(boost.x(), boost.y(), boost.z());
47}
48
49inline HepBoost::HepBoost(const HepBoostX & boost) {set(boost.boostVector());}
50inline HepBoost::HepBoost(const HepBoostY & boost) {set(boost.boostVector());}
51inline HepBoost::HepBoost(const HepBoostZ & boost) {set(boost.boostVector());}
52inline HepBoost & HepBoost::set(const HepBoostX & boost)
53 {return set(boost.boostVector());}
54inline HepBoost & HepBoost::set(const HepBoostY & boost)
55 {return set(boost.boostVector());}
56inline HepBoost & HepBoost::set(const HepBoostZ & boost)
57 {return set(boost.boostVector());}
58
59// - Protected method:
60inline HepBoost::HepBoost (
61 double xx, double xy, double xz, double xt,
62 double yy, double yz, double yt,
63 double zz, double zt,
64 double tt) :
65 rep_ ( xx, xy, xz, xt, yy, yz, yt, zz, zt, tt ) {}
66
67// ---------- Accessors:
68
69inline double HepBoost::beta() const {
70 return std::sqrt( 1.0 - 1.0 / (rep_.tt_ * rep_.tt_) );
71}
72
73inline double HepBoost::gamma() const {
74 return rep_.tt_;
75}
76
77inline Hep3Vector HepBoost::boostVector() const {
78 return (1.0/rep_.tt_) * Hep3Vector( rep_.xt_, rep_.yt_, rep_.zt_ );
79}
80
81inline Hep3Vector HepBoost::getDirection() const {
82 double norm = 1.0/beta();
83 return (norm*boostVector());
84}
85
86inline Hep3Vector HepBoost::direction() const {
87 return getDirection();
88}
89
90inline double HepBoost::xx() const { return rep_.xx_; }
91inline double HepBoost::xy() const { return rep_.xy_; }
92inline double HepBoost::xz() const { return rep_.xz_; }
93inline double HepBoost::xt() const { return rep_.xt_; }
94inline double HepBoost::yx() const { return rep_.xy_; }
95inline double HepBoost::yy() const { return rep_.yy_; }
96inline double HepBoost::yz() const { return rep_.yz_; }
97inline double HepBoost::yt() const { return rep_.yt_; }
98inline double HepBoost::zx() const { return rep_.xz_; }
99inline double HepBoost::zy() const { return rep_.yz_; }
100inline double HepBoost::zz() const { return rep_.zz_; }
101inline double HepBoost::zt() const { return rep_.zt_; }
102inline double HepBoost::tx() const { return rep_.xt_; }
103inline double HepBoost::ty() const { return rep_.yt_; }
104inline double HepBoost::tz() const { return rep_.zt_; }
105inline double HepBoost::tt() const { return rep_.tt_; }
106
107inline HepLorentzVector HepBoost::col1() const {
108 return HepLorentzVector ( xx(), yx(), zx(), tx() );
109}
110inline HepLorentzVector HepBoost::col2() const {
111 return HepLorentzVector ( xy(), yy(), zy(), ty() );
112}
113inline HepLorentzVector HepBoost::col3() const {
114 return HepLorentzVector ( xz(), yz(), zz(), tz() );
115}
116inline HepLorentzVector HepBoost::col4() const {
117 return HepLorentzVector ( xt(), yt(), zt(), tt() );
118}
119
120inline HepLorentzVector HepBoost::row1() const {
121 return HepLorentzVector ( col1() );
122}
123inline HepLorentzVector HepBoost::row2() const {
124 return HepLorentzVector ( col2() );
125}
126inline HepLorentzVector HepBoost::row3() const {
127 return HepLorentzVector ( col3() );
128}
129inline HepLorentzVector HepBoost::row4() const {
130 return HepLorentzVector ( col4() );
131}
132
133inline HepRep4x4 HepBoost::rep4x4() const {
134 return HepRep4x4( rep_ );
135}
136
137inline HepRep4x4Symmetric HepBoost::rep4x4Symmetric() const {
138 return rep_;
139}
140
141
142inline void HepBoost::setBoost(double bx, double by, double bz) {
143 set(bx, by, bz);
144}
145
146
147// ---------- Comparisons:
148
149int HepBoost::compare ( const HepBoost & b ) const {
150 const HepRep4x4Symmetric & s = b.rep4x4Symmetric();
151 if (rep_.tt_ < s.tt_) return -1; else if (rep_.tt_ > s.tt_) return 1;
152 else if (rep_.zt_ < s.zt_) return -1; else if (rep_.zt_ > s.zt_) return 1;
153 else if (rep_.zz_ < s.zz_) return -1; else if (rep_.zz_ > s.zz_) return 1;
154 else if (rep_.yt_ < s.yt_) return -1; else if (rep_.yt_ > s.yt_) return 1;
155 else if (rep_.yz_ < s.yz_) return -1; else if (rep_.yz_ > s.yz_) return 1;
156 else if (rep_.yy_ < s.yy_) return -1; else if (rep_.yy_ > s.yy_) return 1;
157 else if (rep_.xt_ < s.xt_) return -1; else if (rep_.xt_ > s.xt_) return 1;
158 else if (rep_.xz_ < s.xz_) return -1; else if (rep_.xz_ > s.xz_) return 1;
159 else if (rep_.xy_ < s.xy_) return -1; else if (rep_.xy_ > s.xy_) return 1;
160 else if (rep_.xx_ < s.xx_) return -1; else if (rep_.xx_ > s.xx_) return 1;
161 else return 0;
162}
163
164inline bool
165HepBoost::operator == (const HepBoost & b) const {
166 const HepRep4x4Symmetric & s = b.rep4x4Symmetric();
167 return (
168 rep_.xx_==s.xx_ && rep_.xy_==s.xy_ && rep_.xz_==s.xz_ && rep_.xt_==s.xt_
169 && rep_.yy_==s.yy_ && rep_.yz_==s.yz_ && rep_.yt_==s.yt_
170 && rep_.zz_==s.zz_ && rep_.zt_==s.zt_
171 && rep_.tt_==s.tt_
172 );
173}
174
175inline bool
176HepBoost::operator != (const HepBoost & r) const {
177 return ( !(operator==(r)) );
178}
179inline bool HepBoost::operator <= ( const HepBoost & b ) const
180 { return compare(b)<= 0; }
181inline bool HepBoost::operator >= ( const HepBoost & b ) const
182 { return compare(b)>= 0; }
183inline bool HepBoost::operator < ( const HepBoost & b ) const
184 { return compare(b)< 0; }
185inline bool HepBoost::operator > ( const HepBoost & b ) const
186 { return compare(b)> 0; }
187
188inline bool HepBoost::isIdentity() const {
189 return (xx() == 1.0 && xy() == 0.0 && xz() == 0.0 && xt() == 0.0
190 && yy() == 1.0 && yz() == 0.0 && yt() == 0.0
191 && zz() == 1.0 && zt() == 0.0
192 && tt() == 1.0);
193}
194
195inline double HepBoost::distance2( const HepBoost & b ) const {
196 double bgx = rep_.xt_ - b.rep_.xt_;
197 double bgy = rep_.yt_ - b.rep_.yt_;
198 double bgz = rep_.zt_ - b.rep_.zt_;
199 return bgx*bgx+bgy*bgy+bgz*bgz;
200}
201
202inline double HepBoost::distance2( const HepBoostX & bx ) const {
203 double bgx = rep_.xt_ - bx.beta()*bx.gamma();
204 double bgy = rep_.yt_;
205 double bgz = rep_.zt_;
206 return bgx*bgx+bgy*bgy+bgz*bgz;
207}
208
209inline double HepBoost::distance2( const HepBoostY & by ) const {
210 double bgy = rep_.xt_;
211 double bgx = rep_.yt_ - by.beta()*by.gamma();
212 double bgz = rep_.zt_;
213 return bgx*bgx+bgy*bgy+bgz*bgz;
214}
215
216inline double HepBoost::distance2( const HepBoostZ & bz ) const {
217 double bgz = rep_.xt_;
218 double bgy = rep_.yt_;
219 double bgx = rep_.zt_ - bz.beta()*bz.gamma();
220 return bgx*bgx+bgy*bgy+bgz*bgz;
221}
222
223inline double HepBoost::howNear ( const HepBoost & b ) const {
224 return std::sqrt(distance2(b));
225}
226
227inline bool HepBoost::isNear(const HepBoost & b, double epsilon) const{
228 return (distance2(b) <= epsilon*epsilon);
229}
230
231// ---------- Application:
232
233// - Protected method:
234inline HepLorentzVector
235HepBoost::vectorMultiplication(const HepLorentzVector & p) const {
236 register double x = p.x();
237 register double y = p.y();
238 register double z = p.z();
239 register double t = p.t();
240 return HepLorentzVector( rep_.xx_*x + rep_.xy_*y + rep_.xz_*z + rep_.xt_*t,
241 rep_.xy_*x + rep_.yy_*y + rep_.yz_*z + rep_.yt_*t,
242 rep_.xz_*x + rep_.yz_*y + rep_.zz_*z + rep_.zt_*t,
243 rep_.xt_*x + rep_.yt_*y + rep_.zt_*z + rep_.tt_*t);
244}
245
246inline HepLorentzVector
247HepBoost::operator () (const HepLorentzVector & p) const {
248 return vectorMultiplication(p);
249}
250
251inline HepLorentzVector
252HepBoost::operator * (const HepLorentzVector & p) const {
253 return vectorMultiplication(p);
254}
255
256
257// ---------- Operations in the group of 4-Rotations
258
259inline HepBoost HepBoost::inverse() const {
260 return HepBoost( xx(), yx(), zx(), -tx(),
261 yy(), zy(), -ty(),
262 zz(), -tz(),
263 tt());
264}
265
266inline HepBoost inverseOf ( const HepBoost & lt ) {
267 return HepBoost( lt.xx(), lt.yx(), lt.zx(), -lt.tx(),
268 lt.yy(), lt.zy(), -lt.ty(),
269 lt.zz(), -lt.tz(),
270 lt.tt());
271}
272
273inline HepBoost & HepBoost::invert() {
274 rep_.xt_ = -rep_.xt_;
275 rep_.yt_ = -rep_.yt_;
276 rep_.zt_ = -rep_.zt_;
277 return *this;
278}
279
280// ---------- Tolerance:
281
282inline double HepBoost::getTolerance() {
283 return Hep4RotationInterface::tolerance;
284}
285inline double HepBoost::setTolerance(double tol) {
286 return Hep4RotationInterface::setTolerance(tol);
287}
288
289} // namespace CLHEP
Note: See TracBrowser for help on using the repository browser.