Geant4 Cross Reference |
1 // -*- C++ -*- 1 2 // ------------------------------------------- 3 // 4 // This file is a part of the CLHEP - a Class 5 // 6 // This is the implementation of that part of 7 // which is concerned with setting or construc 8 // on 4 supplied columns or rows. 9 10 #include "CLHEP/Vector/LorentzRotation.h" 11 #include "CLHEP/Vector/LorentzVector.h" 12 13 #include <cmath> 14 #include <iostream> 15 16 namespace CLHEP { 17 18 // ---------- Constructors and Assignment: 19 20 HepLorentzRotation & HepLorentzRotation::set ( 21 const HepLor 22 const HepLorentzVe 23 const HepLorentzVe 24 // First, test that the four cols do represe 25 // true LT: 26 27 ZMpvMetric_t savedMetric = HepLorentzVector: 28 29 if ( ccol4.getT() < 0 ) { 30 std::cerr << "HepLorentzRotation::set() - 31 << "column 4 supplied to define transfor 32 << std::endl; 33 *this = HepLorentzRotation(); 34 return *this; 35 } 36 /* 37 double u1u1 = ccol1.dot(ccol1); 38 double f11 = std::fabs(u1u1 + 1.0); 39 if ( f11 > Hep4RotationInterface::tolerance 40 std::cerr << "HepLorentzRotation::set() - 41 << "column 1 supplied for HepLorentzRota 42 } 43 double u2u2 = ccol2.dot(ccol2); 44 double f22 = std::fabs(u2u2 + 1.0); 45 if ( f22 > Hep4RotationInterface::tolerance 46 std::cerr << "HepLorentzRotation::set() - 47 << "column 2 supplied for HepLorentzRota 48 } 49 double u3u3 = ccol3.dot(ccol3); 50 double f33 = std::fabs(u3u3 + 1.0); 51 if ( f33 > Hep4RotationInterface::tolerance 52 std::cerr << "HepLorentzRotation::set() - 53 << "column 3 supplied for HepLorentzRota 54 } 55 double u4u4 = ccol4.dot(ccol4); 56 double f44 = std::fabs(u4u4 - 1.0); 57 if ( f44 > Hep4RotationInterface::tolerance 58 std::cerr << "HepLorentzRotation::set() - 59 << "column 4 supplied for HepLorentzRota 60 } 61 62 double u1u2 = ccol1.dot(ccol2); 63 double f12 = std::fabs(u1u2); 64 if ( f12 > Hep4RotationInterface::tolerance 65 std::cerr << "HepLorentzRotation::set() - 66 << "columns 1 and 2 supplied for HepLore 67 } 68 double u1u3 = ccol1.dot(ccol3); 69 double f13 = std::fabs(u1u3); 70 71 if ( f13 > Hep4RotationInterface::tolerance 72 std::cerr << "HepLorentzRotation::set() - 73 << "columns 1 and 3 supplied for HepLore 74 } 75 double u1u4 = ccol1.dot(ccol4); 76 double f14 = std::fabs(u1u4); 77 if ( f14 > Hep4RotationInterface::tolerance 78 std::cerr << "HepLorentzRotation::set() - 79 << "columns 1 and 4 supplied for HepLore 80 } 81 double u2u3 = ccol2.dot(ccol3); 82 double f23 = std::fabs(u2u3); 83 if ( f23 > Hep4RotationInterface::tolerance 84 std::cerr << "HepLorentzRotation::set() - 85 << "columns 2 and 3 supplied for HepLore 86 } 87 double u2u4 = ccol2.dot(ccol4); 88 double f24 = std::fabs(u2u4); 89 if ( f24 > Hep4RotationInterface::tolerance 90 std::cerr << "HepLorentzRotation::set() - 91 << "columns 2 and 4 supplied for HepLore 92 } 93 double u3u4 = ccol3.dot(ccol4); 94 double f34 = std::fabs(u3u4); 95 if ( f34 > Hep4RotationInterface::tolerance 96 std::cerr << "HepLorentzRotation::set() - 97 << "columns 3 and 4 supplied for HepLore 98 } 99 */ 100 // Our strategy will be to order the cols, t 101 // (that is, remove the components of col d 102 // col c, normalize that, then remove the co 103 // non-orthogonal to d and to c, normalize t 104 105 // Because col4, the time col, is most likel 106 // will start from there and work left-ward. 107 108 HepLorentzVector a, b, c, d; 109 bool isLorentzTransformation = true; 110 double norm; 111 112 d = ccol4; 113 norm = d.dot(d); 114 if (norm <= 0.0) { 115 isLorentzTransformation = false; 116 if (norm == 0.0) { 117 d = T_HAT4; // Moot, but let's kee 118 norm = 1.0; 119 } 120 } 121 d /= norm; 122 123 c = ccol3 - ccol3.dot(d) * d; 124 norm = -c.dot(c); 125 if (norm <= 0.0) { 126 isLorentzTransformation = false; 127 if (norm == 0.0) { 128 c = Z_HAT4; // Moot 129 norm = 1.0; 130 } 131 } 132 c /= norm; 133 134 b = ccol2 + ccol2.dot(c) * c - ccol2.dot(d) 135 norm = -b.dot(b); 136 if (norm <= 0.0) { 137 isLorentzTransformation = false; 138 if (norm == 0.0) { 139 b = Y_HAT4; // Moot 140 norm = 1.0; 141 } 142 } 143 b /= norm; 144 145 a = ccol1 + ccol1.dot(b) * b + ccol1.dot(c) 146 norm = -a.dot(a); 147 if (norm <= 0.0) { 148 isLorentzTransformation = false; 149 if (norm == 0.0) { 150 a = X_HAT4; // Moot 151 norm = 1.0; 152 } 153 } 154 a /= norm; 155 156 if ( !isLorentzTransformation ) { 157 std::cerr << "HepLorentzRotation::set() 158 << "cols 1-4 supplied to define transf 159 << " a boosted reflection or a t 160 << " transformation will be set 161 162 *this = HepLorentzRotation(); 163 } 164 165 if ( isLorentzTransformation ) { 166 mxx = a.x(); myx = a.y(); mzx = a.z(); mtx 167 mxy = b.x(); myy = b.y(); mzy = b.z(); mty 168 mxz = c.x(); myz = c.y(); mzz = c.z(); mtz 169 mxt = d.x(); myt = d.y(); mzt = d.z(); mtt 170 } 171 172 HepLorentzVector::setMetric (savedMetric); 173 return *this; 174 175 } // set ( col1, col2, col3, col4 ) 176 177 HepLorentzRotation & HepLorentzRotation::setRo 178 (const HepLorentzVector & rrow1, 179 const HepLorentzVector & rrow2, 180 const HepLorentzVector & rrow3, 181 const HepLorentzVector & rrow4) { 182 // Set based on using those rows as columns: 183 set (rrow1, rrow2, rrow3, rrow4); 184 // Now transpose in place: 185 double q1, q2, q3; 186 q1 = mxy; q2 = mxz; q3 = mxt; 187 mxy = myx; mxz = mzx; mxt = mtx; 188 myx = q1; mzx = q2; mtx = q3; 189 q1 = myz; q2 = myt; q3 = mzt; 190 myz = mzy; myt = mty; mzt = mtz; 191 mzy = q1; mty = q2; mtz = q3; 192 return *this; 193 } // LorentzTransformation::setRows(row1 ... r 194 195 HepLorentzRotation::HepLorentzRotation ( const 196 const HepLorentzV 197 const HepLorentzV 198 const HepLorentzV 199 { 200 set ( ccol1, ccol2, ccol3, ccol4 ); 201 } 202 203 } // namespace CLHEP 204 205