Geant4 Cross Reference |
1 // -*- C++ -*- 1 2 // ------------------------------------------- 3 // 4 // This file is a part of the CLHEP - a Class 5 // 6 // This is part of the implementation of the H 7 // Those methods which originated from ZOOM an 8 // kinematic properties. 9 // 10 11 #include "CLHEP/Vector/LorentzVector.h" 12 13 #include <cmath> 14 #include <iostream> 15 16 namespace CLHEP { 17 18 //-****************** 19 // Metric flexibility 20 //-****************** 21 22 ZMpvMetric_t HepLorentzVector::setMetric( ZMpv 23 ZMpvMetric_t oldMetric = (metric > 0) ? Time 24 if ( a1 == TimeNegative ) { 25 metric = -1.0; 26 } else { 27 metric = 1.0; 28 } 29 return oldMetric; 30 } 31 32 ZMpvMetric_t HepLorentzVector::getMetric() { 33 return ( (metric > 0) ? TimePositive : TimeN 34 } 35 36 //-******** 37 // plus 38 // minus 39 //-******** 40 41 double HepLorentzVector::plus (const Hep3Vecto 42 double r = ref.mag(); 43 if (r == 0) { 44 std::cerr << "HepLorentzVector::plus() - " 45 << "A zero vector used as reference to L 46 << std::endl; 47 return ee; 48 } 49 return ee + pp.dot(ref)/r; 50 } /* plus */ 51 52 double HepLorentzVector::minus (const Hep3Vect 53 double r = ref.mag(); 54 if (r == 0) { 55 std::cerr << "HepLorentzVector::minus() - 56 << "A zero vector used as reference to L 57 << std::endl; 58 return ee; 59 } 60 return ee - pp.dot(ref)/r; 61 } /* plus */ 62 63 HepLorentzVector HepLorentzVector::rest4Vector 64 return HepLorentzVector (0, 0, 0, (t() < 0.0 65 } 66 67 //-******** 68 // beta 69 // gamma 70 //-******** 71 72 double HepLorentzVector::beta() const { 73 if (ee == 0) { 74 if (pp.mag2() == 0) { 75 return 0; 76 } else { 77 std::cerr << "HepLorentzVector::beta() - 78 << "beta computed for HepLorentzVector 79 << std::endl; 80 return 1./ee; 81 } 82 } 83 // if (restMass2() <= 0) { 84 // std::cerr << "HepLorentzVector::beta() - 85 // << "beta computed for a non-timelike H 86 // // result will make analytic sense b 87 // } 88 return std::sqrt (pp.mag2() / (ee*ee)) ; 89 } /* beta */ 90 91 double HepLorentzVector::gamma() const { 92 double v2 = pp.mag2(); 93 double t2 = ee*ee; 94 if (ee == 0) { 95 if (pp.mag2() == 0) { 96 return 1; 97 } else { 98 std::cerr << "HepLorentzVector::gamma() 99 << "gamma computed for HepLorentzVecto 100 << std::endl; 101 return 0; 102 } 103 } 104 if (t2 < v2) { 105 std::cerr << "HepLorentzVector::gamma() - 106 << "gamma computed for a spacelike HepLo 107 << std::endl; 108 // analytic result would be imaginary. 109 return 0; 110 // } else if ( t2 == v2 ) { 111 // std::cerr << "HepLorentzVector::gamma() 112 // << "gamma computed for a lightlike Hep 113 // << std::endl; 114 } 115 return 1./std::sqrt(1. - v2/t2 ); 116 } /* gamma */ 117 118 119 //-*************** 120 // rapidity 121 // pseudorapidity 122 // eta 123 //-*************** 124 125 double HepLorentzVector::rapidity() const { 126 double z1 = pp.getZ(); 127 // if (std::fabs(ee) == std::fabs(z1)) { 128 // std::cerr << "HepLorentzVector::rapidity 129 // << "rapidity for 4-vector with |E| = | 130 // << std::endl; 131 // } 132 if (std::fabs(ee) < std::fabs(z1)) { 133 std::cerr << "HepLorentzVector::rapidity() 134 << "rapidity for spacelike 4-vector with 135 << std::endl; 136 return 0; 137 } 138 double q = (ee + z1) / (ee - z1); 139 //-| This cannot be negative now, sinc 140 //-| and denominator have the same sig 141 return .5 * std::log(q); 142 } /* rapidity */ 143 144 double HepLorentzVector::rapidity(const Hep3Ve 145 double r = ref.mag2(); 146 if (r == 0) { 147 std::cerr << "HepLorentzVector::rapidity() 148 << "A zero vector used as reference to L 149 << std::endl; 150 return 0; 151 } 152 double vdotu = pp.dot(ref)/std::sqrt(r); 153 // if (std::fabs(ee) == std::fabs(vdotu)) { 154 // std::cerr << "HepLorentzVector::rapidity 155 // << "rapidity for 4-vector with |E| = | 156 // << std::endl; 157 // } 158 if (std::fabs(ee) < std::fabs(vdotu)) { 159 std::cerr << "HepLorentzVector::rapidity() 160 << "rapidity for spacelike 4-vector with 161 << std::endl; 162 return 0; 163 } 164 double q = (ee + vdotu) / (ee - vdotu); 165 return .5 * std::log(q); 166 } /* rapidity(ref) */ 167 168 double HepLorentzVector::coLinearRapidity() co 169 double v1 = pp.mag(); 170 // if (std::fabs(ee) == std::fabs(v1)) { 171 // std::cerr << "HepLorentzVector::coLinear 172 // << "co-Linear rapidity for 4-vector wi 173 // << std::endl; 174 // } 175 if (std::fabs(ee) < std::fabs(v1)) { 176 std::cerr << "HepLorentzVector::coLinearRa 177 << "co-linear rapidity for spacelike 4-v 178 << std::endl; 179 return 0; 180 } 181 double q = (ee + v1) / (ee - v1); 182 return .5 * std::log(q); 183 } /* rapidity */ 184 185 //-************* 186 // invariantMass 187 //-************* 188 189 double HepLorentzVector::invariantMass(const H 190 double m1 = invariantMass2(w); 191 if (m1 < 0) { 192 // We should find out why: 193 if ( ee * w.ee < 0 ) { 194 std::cerr << "HepLorentzVector::invarian 195 << "invariant mass meaningless: \n" 196 << "a negative-mass input led to space 197 return 0; 198 } else if ( (isSpacelike() && !isLightlike 199 (w.isSpacelike() && !w.isLight 200 std::cerr << "HepLorentzVector::invari 201 << "invariant mass meaningless becau 202 << std::endl; 203 return 0; 204 } else { 205 // Invariant mass squared for a pair of 206 // mathematically cannot be negative. I 207 // tolerance of being lightlike or timel 208 // or current roundoffs have caused the 209 // without comment. 210 return 0; 211 } 212 } 213 return (ee+w.ee >=0 ) ? std::sqrt(m1) : - st 214 } /* invariantMass */ 215 216 //-*************** 217 // findBoostToCM 218 //-*************** 219 220 Hep3Vector HepLorentzVector::findBoostToCM() c 221 return -boostVector(); 222 } /* boostToCM() */ 223 224 Hep3Vector HepLorentzVector::findBoostToCM (co 225 double t1 = ee + w.ee; 226 Hep3Vector v1 = pp + w.pp; 227 if (t1 == 0) { 228 if (v1.mag2() == 0) { 229 return Hep3Vector(0,0,0); 230 } else { 231 std::cerr << "HepLorentzVector::findBoos 232 << "boostToCM computed for two 4-vecto 233 << "infinite result" << std::endl; 234 return Hep3Vector(v1*(1./t1)); // Yup, 1 235 } 236 } 237 // if (t1*t1 - v1.mag2() <= 0) { 238 // std::cerr << "HepLorentzVector::findBoos 239 // << "boostToCM computed for pair of He 240 // << std::endl; 241 // // result will make analytic sense b 242 // } 243 return Hep3Vector(v1 * (-1./t1)); 244 } /* boostToCM(w) */ 245 246 } // namespace CLHEP 247 248