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