Geant4  10.00.p03
BoostX.cc
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 implementation of the HepBoostX class.
7 //
8 
9 #ifdef GNUPRAGMA
10 #pragma implementation
11 #endif
12 
13 #include "CLHEP/Vector/BoostX.h"
14 #include "CLHEP/Vector/Boost.h"
15 #include "CLHEP/Vector/Rotation.h"
16 #include "CLHEP/Vector/LorentzRotation.h"
17 
18 namespace CLHEP {
19 
20 
21 // ---------- Constructors and Assignment:
22 
23 HepBoostX & HepBoostX::set (double bbeta) {
24  double b2 = bbeta*bbeta;
25  if (b2 >= 1) {
26  std::cerr << "HepBoostX::set() - "
27  << "Beta supplied to set HepBoostX represents speed >= c." << std::endl;
28  beta_ = 1.0 - 1.0E-8; // NaN-proofing
29  gamma_ = 1.0 / std::sqrt(1.0 - b2);
30  return *this;
31  }
32  beta_ = bbeta;
33  gamma_ = 1.0 / std::sqrt(1.0 - b2);
34  return *this;
35 }
36 
37 // ---------- Accessors:
38 
39 HepRep4x4 HepBoostX::rep4x4() const {
40  double bg = beta_*gamma_;
41  return HepRep4x4( gamma_, 0, 0, bg,
42  0, 1, 0, 0,
43  0, 0, 1, 0,
44  bg, 0, 0, gamma_ );
45 }
46 
47 HepRep4x4Symmetric HepBoostX::rep4x4Symmetric() const {
48  double bg = beta_*gamma_;
49  return HepRep4x4Symmetric( gamma_, 0, 0, bg,
50  1, 0, 0,
51  1, 0,
52  gamma_ );
53 }
54 
55 // ---------- Decomposition:
56 
57 void HepBoostX::decompose (HepRotation & rotation, HepBoost & boost) const {
58  HepAxisAngle vdelta = HepAxisAngle();
59  rotation = HepRotation(vdelta);
60  Hep3Vector bbeta = boostVector();
61  boost = HepBoost(bbeta);
62 }
63 
64 void HepBoostX::decompose (HepAxisAngle & rotation, Hep3Vector & boost) const {
65  rotation = HepAxisAngle();
66  boost = boostVector();
67 }
68 
69 void HepBoostX::decompose (HepBoost & boost, HepRotation & rotation) const {
70  HepAxisAngle vdelta = HepAxisAngle();
71  rotation = HepRotation(vdelta);
72  Hep3Vector bbeta = boostVector();
73  boost = HepBoost(bbeta);
74 }
75 
76 void HepBoostX::decompose (Hep3Vector & boost, HepAxisAngle & rotation) const {
77  rotation = HepAxisAngle();
78  boost = boostVector();
79 }
80 
81 // ---------- Comparisons:
82 
83 double HepBoostX::distance2( const HepBoost & b ) const {
84  return b.distance2(*this);
85 }
86 
87 double HepBoostX::distance2( const HepRotation & r ) const {
88  double db2 = norm2();
89  double dr2 = r.norm2();
90  return (db2 + dr2);
91 }
92 
93 double HepBoostX::distance2( const HepLorentzRotation & lt ) const {
94  HepBoost b1;
95  HepRotation r1;
96  lt.decompose(b1,r1);
97  double db2 = distance2(b1);
98  double dr2 = r1.norm2();
99  return (db2 + dr2);
100 }
101 
102 bool HepBoostX::isNear (const HepRotation & r, double epsilon) const {
103  double db2 = norm2();
104  if (db2 > epsilon*epsilon) return false;
105  double dr2 = r.norm2();
106  return (db2+dr2 <= epsilon*epsilon);
107 }
108 
109 bool HepBoostX::isNear ( const HepLorentzRotation & lt,
110  double epsilon) const {
111  HepBoost b1;
112  HepRotation r1;
113  double db2 = distance2(b1);
114  lt.decompose(b1,r1);
115  if (db2 > epsilon*epsilon) return false;
116  double dr2 = r1.norm2();
117  return (db2 + dr2);
118 }
119 
120 // ---------- Properties:
121 
122 void HepBoostX::rectify() {
123  // Assuming the representation of this is close to a true pure boost,
124  // but may have drifted due to round-off error from many operations,
125  // this forms an "exact" pure boostX matrix for again.
126 
127  double b2 = beta_*beta_;
128  if (b2 >= 1) {
129  beta_ = 1.0 - 1.0e-8; // NaN-proofing
130  b2 = beta_*beta_;
131  }
132  gamma_ = 1.0 / std::sqrt(1.0 - b2);
133 }
134 
135 // ---------- Application:
136 
137 // ---------- Operations in the group of 4-Rotations
138 
139 HepBoostX HepBoostX::operator * (const HepBoostX & b) const {
140  return HepBoostX ( (beta()+b.beta()) / (1+beta()*b.beta()) );
141 }
142 HepLorentzRotation HepBoostX::operator * (const HepBoost & b) const {
143  HepLorentzRotation me (*this);
144  return me*b;
145 }
146 HepLorentzRotation HepBoostX::operator * (const HepRotation & r) const {
147  HepLorentzRotation me (*this);
148  return me*r;
149 }
150 HepLorentzRotation HepBoostX::operator * (const HepLorentzRotation & lt) const {
151  HepLorentzRotation me (*this);
152  return me*lt;
153 }
154 
155 // ---------- I/O:
156 
157 std::ostream & HepBoostX::print( std::ostream & os ) const {
158  os << "Boost in X direction (beta = " << beta_
159  << ", gamma = " << gamma_ << ") ";
160  return os;
161 }
162 
163 } // namespace CLHEP
G4ErrorMatrix operator*(const G4ErrorMatrix &m1, const G4ErrorMatrix &m2)
static const G4double b2
static const G4double b1
void print(const std::vector< T > &data)
Definition: DicomRun.hh:111