CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // -*- C++ -*- 00002 // $Id: LorentzVector.cc,v 1.2 2003/08/13 20:00:14 garren Exp $ 00003 // --------------------------------------------------------------------------- 00004 // 00005 // This file is a part of the CLHEP - a Class Library for High Energy Physics. 00006 // 00007 // This is the implementation of that portion of the HepLorentzVector class 00008 // which was in the original CLHEP and which does not force loading of either 00009 // Rotation.cc or LorentzRotation.cc 00010 // 00011 00012 #ifdef GNUPRAGMA 00013 #pragma implementation 00014 #endif 00015 00016 #include "CLHEP/Vector/defs.h" 00017 #include "CLHEP/Vector/LorentzVector.h" 00018 #include "CLHEP/Vector/ZMxpv.h" 00019 00020 #include <iostream> 00021 00022 namespace CLHEP { 00023 00024 double HepLorentzVector::operator () (int i) const { 00025 switch(i) { 00026 case X: 00027 case Y: 00028 case Z: 00029 return pp(i); 00030 case T: 00031 return e(); 00032 default: 00033 std::cerr << "HepLorentzVector subscripting: bad index (" << i << ")" 00034 << std::endl; 00035 } 00036 return 0.; 00037 } 00038 00039 double & HepLorentzVector::operator () (int i) { 00040 static double dummy; 00041 switch(i) { 00042 case X: 00043 case Y: 00044 case Z: 00045 return pp(i); 00046 case T: 00047 return ee; 00048 default: 00049 std::cerr 00050 << "HepLorentzVector subscripting: bad index (" << i << ")" 00051 << std::endl; 00052 return dummy; 00053 } 00054 } 00055 00056 HepLorentzVector & HepLorentzVector::boost 00057 (double bx, double by, double bz){ 00058 double b2 = bx*bx + by*by + bz*bz; 00059 register double gamma = 1.0 / sqrt(1.0 - b2); 00060 register double bp = bx*x() + by*y() + bz*z(); 00061 register double gamma2 = b2 > 0 ? (gamma - 1.0)/b2 : 0.0; 00062 00063 setX(x() + gamma2*bp*bx + gamma*bx*t()); 00064 setY(y() + gamma2*bp*by + gamma*by*t()); 00065 setZ(z() + gamma2*bp*bz + gamma*bz*t()); 00066 setT(gamma*(t() + bp)); 00067 return *this; 00068 } 00069 00070 HepLorentzVector & HepLorentzVector::rotateX(double a) { 00071 pp.rotateX(a); 00072 return *this; 00073 } 00074 HepLorentzVector & HepLorentzVector::rotateY(double a) { 00075 pp.rotateY(a); 00076 return *this; 00077 } 00078 HepLorentzVector & HepLorentzVector::rotateZ(double a) { 00079 pp.rotateZ(a); 00080 return *this; 00081 } 00082 00083 HepLorentzVector & HepLorentzVector::rotateUz(const Hep3Vector &v) { 00084 pp.rotateUz(v); 00085 return *this; 00086 } 00087 00088 std::ostream & operator<< (std::ostream & os, const HepLorentzVector & v) 00089 { 00090 return os << "(" << v.x() << "," << v.y() << "," << v.z() 00091 << ";" << v.t() << ")"; 00092 } 00093 00094 std::istream & operator>> (std::istream & is, HepLorentzVector & v) { 00095 00096 // Required format is ( a, b, c; d ) that is, four numbers, preceded by 00097 // (, followed by ), components of the spatial vector separated by commas, 00098 // time component separated by semicolon. The four numbers are taken 00099 // as x, y, z, t. 00100 00101 double x, y, z, t; 00102 char c; 00103 00104 is >> std::ws >> c; 00105 // ws is defined to invoke eatwhite(istream & ) 00106 // see (Stroustrup gray book) page 333 and 345. 00107 if (is.fail() || c != '(' ) { 00108 std::cerr << "Could not find required opening parenthesis " 00109 << "in input of a HepLorentzVector" << std::endl; 00110 return is; 00111 } 00112 00113 is >> x >> std::ws >> c; 00114 if (is.fail() || c != ',' ) { 00115 std::cerr << "Could not find x value and required trailing comma " 00116 << "in input of a HepLorentzVector" << std::endl; 00117 return is; 00118 } 00119 00120 is >> y >> std::ws >> c; 00121 if (is.fail() || c != ',' ) { 00122 std::cerr << "Could not find y value and required trailing comma " 00123 << "in input of a HepLorentzVector" << std::endl; 00124 return is; 00125 } 00126 00127 is >> z >> std::ws >> c; 00128 if (is.fail() || c != ';' ) { 00129 std::cerr << "Could not find z value and required trailing semicolon " 00130 << "in input of a HepLorentzVector" << std::endl; 00131 return is; 00132 } 00133 00134 is >> t >> std::ws >> c; 00135 if (is.fail() || c != ')' ) { 00136 std::cerr << "Could not find t value and required close parenthesis " 00137 << "in input of a HepLorentzVector" << std::endl; 00138 return is; 00139 } 00140 00141 v.setX(x); 00142 v.setY(y); 00143 v.setZ(z); 00144 v.setT(t); 00145 return is; 00146 } 00147 00148 // The following were added when ZOOM classes were merged in: 00149 00150 HepLorentzVector & HepLorentzVector::operator /= (double c) { 00151 if (c == 0) { 00152 ZMthrowA (ZMxpvInfiniteVector( 00153 "Attempt to do LorentzVector /= 0 -- \n" 00154 "division by zero would produce infinite or NAN components")); 00155 } 00156 double oneOverC = 1.0/c; 00157 pp *= oneOverC; 00158 ee *= oneOverC; 00159 return *this; 00160 } /* w /= c */ 00161 00162 HepLorentzVector operator / (const HepLorentzVector & w, double c) { 00163 if (c == 0) { 00164 ZMthrowA (ZMxpvInfiniteVector( 00165 "Attempt to do LorentzVector / 0 -- \n" 00166 "division by zero would produce infinite or NAN components")); 00167 } 00168 double oneOverC = 1.0/c; 00169 return HepLorentzVector (w.getV() * oneOverC, 00170 w.getT() * oneOverC); 00171 } /* LV = w / c */ 00172 00173 Hep3Vector HepLorentzVector::boostVector() const { 00174 if (ee == 0) { 00175 if (pp.mag2() == 0) { 00176 return Hep3Vector(0,0,0); 00177 } else { 00178 ZMthrowA (ZMxpvInfiniteVector( 00179 "boostVector computed for LorentzVector with t=0 -- infinite result")); 00180 return pp/ee; 00181 } 00182 } 00183 if (restMass2() <= 0) { 00184 ZMthrowC (ZMxpvTachyonic( 00185 "boostVector computed for a non-timelike LorentzVector ")); 00186 // result will make analytic sense but is physically meaningless 00187 } 00188 return pp * (1./ee); 00189 } /* boostVector */ 00190 00191 00192 HepLorentzVector & HepLorentzVector::boostX (double beta){ 00193 register double b2 = beta*beta; 00194 if (b2 >= 1) { 00195 ZMthrowA (ZMxpvTachyonic( 00196 "boost along X with beta >= 1 (speed of light) -- no boost done")); 00197 } else { 00198 register double gamma = sqrt(1./(1-b2)); 00199 register double tt = ee; 00200 ee = gamma*(ee + beta*pp.getX()); 00201 pp.setX(gamma*(pp.getX() + beta*tt)); 00202 } 00203 return *this; 00204 } /* boostX */ 00205 00206 HepLorentzVector & HepLorentzVector::boostY (double beta){ 00207 register double b2 = beta*beta; 00208 if (b2 >= 1) { 00209 ZMthrowA (ZMxpvTachyonic( 00210 "boost along Y with beta >= 1 (speed of light) -- \nno boost done")); 00211 } else { 00212 register double gamma = sqrt(1./(1-b2)); 00213 register double tt = ee; 00214 ee = gamma*(ee + beta*pp.getY()); 00215 pp.setY(gamma*(pp.getY() + beta*tt)); 00216 } 00217 return *this; 00218 } /* boostY */ 00219 00220 HepLorentzVector & HepLorentzVector::boostZ (double beta){ 00221 register double b2 = beta*beta; 00222 if (b2 >= 1) { 00223 ZMthrowA (ZMxpvTachyonic( 00224 "boost along Z with beta >= 1 (speed of light) -- \nno boost done")); 00225 } else { 00226 register double gamma = sqrt(1./(1-b2)); 00227 register double tt = ee; 00228 ee = gamma*(ee + beta*pp.getZ()); 00229 pp.setZ(gamma*(pp.getZ() + beta*tt)); 00230 } 00231 return *this; 00232 } /* boostZ */ 00233 00234 double HepLorentzVector::setTolerance ( double tol ) { 00235 // Set the tolerance for two LorentzVectors to be considered near each other 00236 double oldTolerance (tolerance); 00237 tolerance = tol; 00238 return oldTolerance; 00239 } 00240 00241 double HepLorentzVector::getTolerance ( ) { 00242 // Get the tolerance for two LorentzVectors to be considered near each other 00243 return tolerance; 00244 } 00245 00246 double HepLorentzVector::tolerance = 00247 Hep3Vector::ToleranceTicks * 2.22045e-16; 00248 double HepLorentzVector::metric = 1.0; 00249 00250 00251 } // namespace CLHEP