00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifdef GNUPRAGMA
00010 #pragma implementation
00011 #endif
00012
00013 #include "CLHEP/Vector/LorentzRotation.h"
00014
00015 namespace CLHEP {
00016
00017
00018
00019 void HepLorentzRotation::decompose
00020 (HepBoost & bboost, HepRotation & rotation) const {
00021
00022
00023
00024
00025
00026
00027 Hep3Vector betaVec ( xt(), yt(), zt() );
00028 betaVec *= 1.0 / tt();
00029 bboost.set( betaVec );
00030
00031
00032
00033 HepBoost B( -betaVec );
00034 HepLorentzRotation R( B * *this );
00035
00036 HepRep3x3 m1 ( R.xx(), R.xy(), R.xz(),
00037 R.yx(), R.yy(), R.yz(),
00038 R.zx(), R.zy(), R.zz() );
00039 rotation.set( m1 );
00040 rotation.rectify();
00041
00042 return;
00043
00044 }
00045
00046 void HepLorentzRotation::decompose
00047 (Hep3Vector & bboost, HepAxisAngle & rotation) const {
00048 HepRotation r;
00049 HepBoost b;
00050 decompose(b,r);
00051 bboost = b.boostVector();
00052 rotation = r.axisAngle();
00053 return;
00054 }
00055
00056 void HepLorentzRotation::decompose
00057 (HepRotation & rotation, HepBoost & bboost) const {
00058
00059
00060
00061 Hep3Vector betaVec( tx(), ty(), tz() );
00062 betaVec *= 1.0 / tt();
00063 bboost.set( betaVec );
00064
00065
00066
00067 HepBoost B( -betaVec );
00068 HepLorentzRotation R( *this * B );
00069
00070 HepRep3x3 m1 ( R.xx(), R.xy(), R.xz(),
00071 R.yx(), R.yy(), R.yz(),
00072 R.zx(), R.zy(), R.zz() );
00073 rotation.set( m1 );
00074 rotation.rectify();
00075 return;
00076
00077 }
00078
00079 void HepLorentzRotation::decompose
00080 (HepAxisAngle & rotation, Hep3Vector & bboost) const {
00081 HepRotation r;
00082 HepBoost b;
00083 decompose(r,b);
00084 rotation = r.axisAngle();
00085 bboost = b.boostVector();
00086 return;
00087 }
00088
00089 double HepLorentzRotation::distance2( const HepBoost & b ) const {
00090 HepBoost b1;
00091 HepRotation r1;
00092 decompose( b1, r1 );
00093 double db2 = b1.distance2( b );
00094 double dr2 = r1.norm2();
00095 return ( db2 + dr2 );
00096 }
00097
00098 double HepLorentzRotation::distance2( const HepRotation & r ) const {
00099 HepBoost b1;
00100 HepRotation r1;
00101 decompose( b1, r1 );
00102 double db2 = b1.norm2( );
00103 double dr2 = r1.distance2( r );
00104 return ( db2 + dr2 );
00105 }
00106
00107 double HepLorentzRotation::distance2(
00108 const HepLorentzRotation & lt ) const {
00109 HepBoost b1;
00110 HepRotation r1;
00111 decompose( b1, r1 );
00112 HepBoost b2;
00113 HepRotation r2;
00114 lt.decompose (b2, r2);
00115 double db2 = b1.distance2( b2 );
00116 double dr2 = r1.distance2( r2 );
00117 return ( db2 + dr2 );
00118 }
00119
00120 double HepLorentzRotation::howNear( const HepBoost & b ) const {
00121 return std::sqrt( distance2( b ) );
00122 }
00123 double HepLorentzRotation::howNear( const HepRotation & r ) const {
00124 return std::sqrt( distance2( r ) );
00125 }
00126 double HepLorentzRotation::howNear( const HepLorentzRotation & lt )const {
00127 return std::sqrt( distance2( lt ) );
00128 }
00129
00130 bool HepLorentzRotation::isNear(
00131 const HepBoost & b, double epsilon ) const {
00132 HepBoost b1;
00133 HepRotation r1;
00134 decompose( b1, r1 );
00135 double db2 = b1.distance2(b);
00136 if ( db2 > epsilon*epsilon ) {
00137 return false;
00138 }
00139 double dr2 = r1.norm2();
00140 return ( (db2 + dr2) <= epsilon*epsilon );
00141 }
00142
00143 bool HepLorentzRotation::isNear(
00144 const HepRotation & r, double epsilon ) const {
00145 HepBoost b1;
00146 HepRotation r1;
00147 decompose( b1, r1 );
00148 double db2 = b1.norm2();
00149 if ( db2 > epsilon*epsilon ) {
00150 return false;
00151 }
00152 double dr2 = r1.distance2(r);
00153 return ( (db2 + dr2) <= epsilon*epsilon );
00154 }
00155
00156 bool HepLorentzRotation::isNear(
00157 const HepLorentzRotation & lt, double epsilon ) const {
00158 HepBoost b1;
00159 HepRotation r1;
00160 decompose( b1, r1 );
00161 HepBoost b2;
00162 HepRotation r2;
00163 lt.decompose (b2, r2);
00164 double db2 = b1.distance2(b2);
00165 if ( db2 > epsilon*epsilon ) {
00166 return false;
00167 }
00168 double dr2 = r1.distance2(r2);
00169 return ( (db2 + dr2) <= epsilon*epsilon );
00170 }
00171
00172 double HepLorentzRotation::norm2() const {
00173 HepBoost b;
00174 HepRotation r;
00175 decompose( b, r );
00176 return b.norm2() + r.norm2();
00177 }
00178
00179 void HepLorentzRotation::rectify() {
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 Hep3Vector beta (tx(), ty(), tz());
00192 double gam = tt();
00193 if ( gam <= 0 ) {
00194 std::cerr << "HepLorentzRotation::rectify() - "
00195 << "rectify() on a transformation with tt() <= 0 - will not help!"
00196 << std::endl;
00197 gam = 1;
00198 }
00199 beta *= 1.0/gam;
00200 HepLorentzRotation R = (*this) * HepBoost(-beta);
00201
00202 HepRep3x3 m1 ( R.xx(), R.xy(), R.xz(),
00203 R.yx(), R.yy(), R.yz(),
00204 R.zx(), R.zy(), R.zz() );
00205
00206 HepRotation Rgood (m1);
00207 Rgood.rectify();
00208
00209 set ( Rgood, HepBoost(beta) );
00210 }
00211
00212 }