ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LorentzVector.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file LorentzVector.cc
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 that portion of the HepLorentzVector class
7 // which was in the original CLHEP and which does not force loading of either
8 // Rotation.cc or LorentzRotation.cc
9 //
10 
11 #ifdef GNUPRAGMA
12 #pragma implementation
13 #endif
14 
16 
17 #include <iostream>
18 
19 namespace CLHEP {
20 
22  Hep3Vector::ToleranceTicks * 2.22045e-16;
23 double HepLorentzVector::metric = 1.0;
24 
25 double HepLorentzVector::operator () (int i) const {
26  switch(i) {
27  case X:
28  case Y:
29  case Z:
30  return pp(i);
31  case T:
32  return e();
33  default:
34  std::cerr << "HepLorentzVector subscripting: bad index (" << i << ")"
35  << std::endl;
36  }
37  return 0.;
38 }
39 
41  static double dummy;
42  switch(i) {
43  case X:
44  case Y:
45  case Z:
46  return pp(i);
47  case T:
48  return ee;
49  default:
50  std::cerr
51  << "HepLorentzVector subscripting: bad index (" << i << ")"
52  << std::endl;
53  return dummy;
54  }
55 }
56 
58  (double bx, double by, double bz){
59  double b2 = bx*bx + by*by + bz*bz;
60  double ggamma = 1.0 / std::sqrt(1.0 - b2);
61  double bp = bx*x() + by*y() + bz*z();
62  double gamma2 = b2 > 0 ? (ggamma - 1.0)/b2 : 0.0;
63 
64  setX(x() + gamma2*bp*bx + ggamma*bx*t());
65  setY(y() + gamma2*bp*by + ggamma*by*t());
66  setZ(z() + gamma2*bp*bz + ggamma*bz*t());
67  setT(ggamma*(t() + bp));
68  return *this;
69 }
70 
72  pp.rotateX(a);
73  return *this;
74 }
76  pp.rotateY(a);
77  return *this;
78 }
80  pp.rotateZ(a);
81  return *this;
82 }
83 
85  pp.rotateUz(v1);
86  return *this;
87 }
88 
89 std::ostream & operator<< (std::ostream & os, const HepLorentzVector & v1)
90 {
91  return os << "(" << v1.x() << "," << v1.y() << "," << v1.z()
92  << ";" << v1.t() << ")";
93 }
94 
95 std::istream & operator>> (std::istream & is, HepLorentzVector & v1) {
96 
97 // Required format is ( a, b, c; d ) that is, four numbers, preceded by
98 // (, followed by ), components of the spatial vector separated by commas,
99 // time component separated by semicolon. The four numbers are taken
100 // as x, y, z, t.
101 
102  double x, y, z, t;
103  char c;
104 
105  is >> std::ws >> c;
106  // ws is defined to invoke eatwhite(istream & )
107  // see (Stroustrup gray book) page 333 and 345.
108  if (is.fail() || c != '(' ) {
109  std::cerr << "Could not find required opening parenthesis "
110  << "in input of a HepLorentzVector" << std::endl;
111  return is;
112  }
113 
114  is >> x >> std::ws >> c;
115  if (is.fail() || c != ',' ) {
116  std::cerr << "Could not find x value and required trailing comma "
117  << "in input of a HepLorentzVector" << std::endl;
118  return is;
119  }
120 
121  is >> y >> std::ws >> c;
122  if (is.fail() || c != ',' ) {
123  std::cerr << "Could not find y value and required trailing comma "
124  << "in input of a HepLorentzVector" << std::endl;
125  return is;
126  }
127 
128  is >> z >> std::ws >> c;
129  if (is.fail() || c != ';' ) {
130  std::cerr << "Could not find z value and required trailing semicolon "
131  << "in input of a HepLorentzVector" << std::endl;
132  return is;
133  }
134 
135  is >> t >> std::ws >> c;
136  if (is.fail() || c != ')' ) {
137  std::cerr << "Could not find t value and required close parenthesis "
138  << "in input of a HepLorentzVector" << std::endl;
139  return is;
140  }
141 
142  v1.setX(x);
143  v1.setY(y);
144  v1.setZ(z);
145  v1.setT(t);
146  return is;
147 }
148 
149 // The following were added when ZOOM classes were merged in:
150 
152 // if (c == 0) {
153 // std::cerr << "HepLorentzVector::operator /=() - "
154 // << "Attempt to do LorentzVector /= 0 -- \n"
155 // << "division by zero would produce infinite or NAN components"
156 // << std::endl;
157 // }
158  double oneOverC = 1.0/c;
159  pp *= oneOverC;
160  ee *= oneOverC;
161  return *this;
162 } /* w /= c */
163 
165 // if (c == 0) {
166 // std::cerr << "HepLorentzVector::operator /() - "
167 // << "Attempt to do LorentzVector / 0 -- \n"
168 // << "division by zero would produce infinite or NAN components"
169 // << std::endl;
170 // }
171  double oneOverC = 1.0/c;
172  return HepLorentzVector (w.getV() * oneOverC,
173  w.getT() * oneOverC);
174 } /* LV = w / c */
175 
177  if (ee == 0) {
178  if (pp.mag2() == 0) {
179  return Hep3Vector(0,0,0);
180  } else {
181  std::cerr << "HepLorentzVector::boostVector() - "
182  << "boostVector computed for LorentzVector with t=0 -- infinite result"
183  << std::endl;
184  return pp/ee;
185  }
186  }
187  if (restMass2() <= 0) {
188  std::cerr << "HepLorentzVector::boostVector() - "
189  << "boostVector computed for a non-timelike LorentzVector " << std::endl;
190  // result will make analytic sense but is physically meaningless
191  }
192  return pp * (1./ee);
193 } /* boostVector */
194 
195 
197  double b2 = bbeta*bbeta;
198  if (b2 >= 1) {
199  std::cerr << "HepLorentzVector::boostX() - "
200  << "boost along X with beta >= 1 (speed of light) -- \n"
201  << "no boost done" << std::endl;
202  } else {
203  double ggamma = std::sqrt(1./(1-b2));
204  double tt = ee;
205  ee = ggamma*(ee + bbeta*pp.getX());
206  pp.setX(ggamma*(pp.getX() + bbeta*tt));
207  }
208  return *this;
209 } /* boostX */
210 
212  double b2 = bbeta*bbeta;
213  if (b2 >= 1) {
214  std::cerr << "HepLorentzVector::boostY() - "
215  << "boost along Y with beta >= 1 (speed of light) -- \n"
216  << "no boost done" << std::endl;
217  } else {
218  double ggamma = std::sqrt(1./(1-b2));
219  double tt = ee;
220  ee = ggamma*(ee + bbeta*pp.getY());
221  pp.setY(ggamma*(pp.getY() + bbeta*tt));
222  }
223  return *this;
224 } /* boostY */
225 
227  double b2 = bbeta*bbeta;
228  if (b2 >= 1) {
229  std::cerr << "HepLorentzVector::boostZ() - "
230  << "boost along Z with beta >= 1 (speed of light) -- \n"
231  << "no boost done" << std::endl;
232  } else {
233  double ggamma = std::sqrt(1./(1-b2));
234  double tt = ee;
235  ee = ggamma*(ee + bbeta*pp.getZ());
236  pp.setZ(ggamma*(pp.getZ() + bbeta*tt));
237  }
238  return *this;
239 } /* boostZ */
240 
241 double HepLorentzVector::setTolerance ( double tol ) {
242 // Set the tolerance for two LorentzVectors to be considered near each other
243  double oldTolerance (tolerance);
244  tolerance = tol;
245  return oldTolerance;
246 }
247 
249 // Get the tolerance for two LorentzVectors to be considered near each other
250  return tolerance;
251 }
252 
253 } // namespace CLHEP