3 <title>Four-Vectors</title>
4 <link rel="stylesheet" type="text/css" href="pythia.css"/>
5 <link rel="shortcut icon" href="pythia32.gif"/>
11 The <code>Vec4</code> class gives a simple implementation of four-vectors.
12 The member function names are based on the assumption that these
13 represent four-momentum vectors. Thus one can get or set
14 <i>p_x, p_y, p_z</i> and <i>e</i>, but not <i>x, y, z</i>
15 or <i>t</i>. This is only a matter of naming, however; a
16 <code>Vec4</code> can equally well be used to store a space-time
20 The <code>Particle</code> object contains a <code>Vec4 p</code> that
21 stores the particle four-momentum, and another <code>Vec4 vProd</code>
22 for the production vertex. For the latter the input/output method
23 names are adapted to the space-time character rather than the normal
24 energy-momentum one. Thus a user would not normally access the
25 <code>Vec4</code> classes directly, but only via the methods of the
26 <code>Particle</code> class,
27 see <a href="ParticleProperties.html" target="page">Particle Properties</a>.
30 Nevertheless you are free to use the PYTHIA four-vectors, e.g. as
31 part of some simple analysis code based directly on the PYTHIA output,
32 say to define the four-vector sum of a set of particles. But note that
33 this class was never set up to allow complete generality, only to
34 provide the operations that are of use inside PYTHIA. There is no
35 separate class for three-vectors, since such can easily be represented
36 by four-vectors where the fourth component is not used.
39 Four-vectors have the expected functionality: they can be created,
40 copied, added, multiplied, rotated, boosted, and manipulated in other
41 ways. Operator overloading is implemented where reasonable. Properties
42 can be read out, not only the components themselves but also for derived
43 quantities such as absolute momentum and direction angles.
45 <h3>Constructors and basic operators</h3>
47 A few methods are available to create or copy a four-vector:
49 <a name="method1"></a>
50 <p/><strong>Vec4::Vec4(double x = 0., double y = 0., double z = 0., double t = 0.) </strong> <br/>
51 creates a four-vector, by default with all components set to 0.
54 <a name="method2"></a>
55 <p/><strong>Vec4::Vec4(const Vec4& v) </strong> <br/>
56 creates a four-vector copy of the input four-vector.
59 <a name="method3"></a>
60 <p/><strong>Vec4& Vec4::operator=(const Vec4& v) </strong> <br/>
61 copies the input four-vector.
64 <a name="method4"></a>
65 <p/><strong>Vec4& Vec4::operator=(double value) </strong> <br/>
66 gives a four-vector with all components set to <i>value</i>.
69 <h3>Member methods for input</h3>
71 The values stored in a four-vector can be modified in a few different
74 <a name="method5"></a>
75 <p/><strong>void Vec4::reset() </strong> <br/>
76 sets all components to 0.
79 <a name="method6"></a>
80 <p/><strong>void Vec4::p(double pxIn, double pyIn, double pzIn, double eIn) </strong> <br/>
81 sets all components to their input values.
84 <a name="method7"></a>
85 <p/><strong>void Vec4::p(Vec4 pIn) </strong> <br/>
86 sets all components equal to those of the input four-vector.
89 <a name="method8"></a>
90 <p/><strong>void Vec4::px(double pxIn) </strong> <br/>
92 <strong>void Vec4::py(double pyIn) </strong> <br/>
94 <strong>void Vec4::pz(double pzIn) </strong> <br/>
96 <strong>void Vec4::e(double eIn) </strong> <br/>
97 sets the respective component to the input value.
100 <h3>Member methods for output</h3>
102 A number of methods provides output of basic or derived quantities:
104 <a name="method9"></a>
105 <p/><strong>double Vec4::px() </strong> <br/>
107 <strong>double Vec4::py() </strong> <br/>
109 <strong>double Vec4::pz() </strong> <br/>
111 <strong>double Vec4::e() </strong> <br/>
112 gets the respective component.
115 <a name="method10"></a>
116 <p/><strong>double Vec4::mCalc() </strong> <br/>
118 <strong>double Vec4::m2Calc() </strong> <br/>
119 the (squared) mass, calculated from the four-vectors.
120 If <i>m^2 < 0</i> the mass is given with a minus sign,
121 <i>-sqrt(-m^2)</i>. Note the possible loss of precision
122 in the calculation of <i>E^2 - p^2</i>; for particles the
123 correct mass is stored separately to avoid such problems.
126 <a name="method11"></a>
127 <p/><strong>double Vec4::pT() </strong> <br/>
129 <strong>double Vec4::pT2() </strong> <br/>
130 the (squared) transverse momentum.
133 <a name="method12"></a>
134 <p/><strong>double Vec4::pAbs() </strong> <br/>
136 <strong>double Vec4::pAbs2() </strong> <br/>
137 the (squared) absolute momentum.
140 <a name="method13"></a>
141 <p/><strong>double Vec4::eT() </strong> <br/>
143 <strong>double Vec4::eT2() </strong> <br/>
144 the (squared) transverse energy,
145 <i>eT = e * sin(theta) = e * pT / pAbs</i>.
148 <a name="method14"></a>
149 <p/><strong>double Vec4::theta() </strong> <br/>
150 the polar angle, in the range 0 through
154 <a name="method15"></a>
155 <p/><strong>double Vec4::phi() </strong> <br/>
156 the azimuthal angle, in the range <i>-pi</i> through <i>pi</i>.
159 <a name="method16"></a>
160 <p/><strong>double Vec4::thetaXZ() </strong> <br/>
161 the angle in the <i>xz</i> plane, in the range <i>-pi</i> through
162 <i>pi</i>, with 0 along the <i>+z</i> axis.
165 <a name="method17"></a>
166 <p/><strong>double Vec4::pPos() </strong> <br/>
168 <strong>double Vec4::pNeg() </strong> <br/>
169 the combinations <i>E+-p_z</i>.
171 <a name="method18"></a>
172 <p/><strong>double Vec4::rap() </strong> <br/>
174 <strong>double Vec4::eta() </strong> <br/>
175 true rapidity <i>y</i> and pseudorapidity <i>eta</i>.
178 <h3>Friend methods for output</h3>
180 There are also some <code>friend</code> methods that take one, two
181 or three four-vectors as argument. Several of them only use the
182 three-vector part of the four-vector.
184 <a name="method19"></a>
185 <p/><strong>friend ostream& operator<<(ostream&, const Vec4& v) </strong> <br/>
186 writes out the values of the four components of a <code>Vec4</code> and,
187 within brackets, a fifth component being the invariant length of the
188 four-vector, as provided by <code>mCalc()</code> above, and it all
189 ended with a newline.
192 <a name="method20"></a>
193 <p/><strong>friend double m(const Vec4& v1, const Vec4& v2) </strong> <br/>
195 <strong>friend double m2(const Vec4& v1, const Vec4& v2) </strong> <br/>
196 the (squared) invariant mass.
199 <a name="method21"></a>
200 <p/><strong>friend double dot3(const Vec4& v1, const Vec4& v2) </strong> <br/>
204 <a name="method22"></a>
205 <p/><strong>friend double cross3(const Vec4& v1, const Vec4& v2) </strong> <br/>
209 <a name="method23"></a>
210 <p/><strong>friend double theta(const Vec4& v1, const Vec4& v2) </strong> <br/>
212 <strong>friend double costheta(const Vec4& v1, const Vec4& v2) </strong> <br/>
213 the (cosine) of the opening angle between the vectors,
214 in the range 0 through <i>pi</i>.
217 <a name="method24"></a>
218 <p/><strong>friend double phi(const Vec4& v1, const Vec4& v2) </strong> <br/>
220 <strong>friend double cosphi(const Vec4& v1, const Vec4& v2) </strong> <br/>
221 the (cosine) of the azimuthal angle between the vectors around the
222 <i>z</i> axis, in the range 0 through <i>pi</i>.
225 <a name="method25"></a>
226 <p/><strong>friend double phi(const Vec4& v1, const Vec4& v2, const Vec4& v3) </strong> <br/>
228 <strong>friend double cosphi(const Vec4& v1, const Vec4& v2, const Vec4& v3) </strong> <br/>
229 the (cosine) of the azimuthal angle between the first two vectors
230 around the direction of the third, in the range 0 through <i>pi</i>.
233 <a name="method26"></a>
234 <p/><strong>friend double RRapPhi(const Vec4& v1, const Vec4& v2) </strong> <br/>
236 <strong>friend double REtaPhi(const Vec4& v1, const Vec4& v2) </strong> <br/>
237 the <i>R</i> distance measure, in <i>(y, phi)</i> or
238 <i>(eta, phi)</i> cylindrical coordinates, i.e.
239 <i>R^2 = (y_1 - y_2)^2 + (phi_1 - phi_2)^2</i> and equivalent.
242 <h3>Operations with four-vectors</h3>
244 Of course one should be able to add, subtract and scale four-vectors,
247 <a name="method27"></a>
248 <p/><strong>Vec4 Vec4::operator-() </strong> <br/>
249 return a vector with flipped sign for all components, while leaving
250 the original vector unchanged.
253 <a name="method28"></a>
254 <p/><strong>Vec4& Vec4::operator+=(const Vec4& v) </strong> <br/>
255 add a four-vector to an existing one.
258 <a name="method29"></a>
259 <p/><strong>Vec4& Vec4::operator-=(const Vec4& v) </strong> <br/>
260 subtract a four-vector from an existing one.
263 <a name="method30"></a>
264 <p/><strong>Vec4& Vec4::operator*=(double f) </strong> <br/>
265 multiply all four-vector components by a real number.
268 <a name="method31"></a>
269 <p/><strong>Vec4& Vec4::operator/=(double f) </strong> <br/>
270 divide all four-vector components by a real number.
273 <a name="method32"></a>
274 <p/><strong>friend Vec4 operator+(const Vec4& v1, const Vec4& v2) </strong> <br/>
275 add two four-vectors.
278 <a name="method33"></a>
279 <p/><strong>friend Vec4 operator-(const Vec4& v1, const Vec4& v2) </strong> <br/>
280 subtract two four-vectors.
283 <a name="method34"></a>
284 <p/><strong>friend Vec4 operator*(double f, const Vec4& v) </strong> <br/>
286 <strong>friend Vec4 operator*(const Vec4& v, double f) </strong> <br/>
287 multiply a four-vector by a real number.
290 <a name="method35"></a>
291 <p/><strong>friend Vec4 operator/(const Vec4& v, double f) </strong> <br/>
292 divide a four-vector by a real number.
295 <a name="method36"></a>
296 <p/><strong>friend double operator*(const Vec4& v1, const Vec4 v2) </strong> <br/>
301 There are also a few related operations that are normal member methods:
303 <a name="method37"></a>
304 <p/><strong>void Vec4::rescale3(double f) </strong> <br/>
305 multiply the three-vector components by <i>f</i>, but keep the
306 fourth component unchanged.
309 <a name="method38"></a>
310 <p/><strong>void Vec4::rescale4(double f) </strong> <br/>
311 multiply all four-vector components by <i>f</i>.
314 <a name="method39"></a>
315 <p/><strong>void Vec4::flip3() </strong> <br/>
316 flip the sign of the three-vector components, but keep the
317 fourth component unchanged.
320 <a name="method40"></a>
321 <p/><strong>void Vec4::flip4() </strong> <br/>
322 flip the sign of all four-vector components.
325 <h3>Rotations and boosts</h3>
327 A common task is to rotate or boost four-vectors. In case only one
328 four-vector is affected the operation may be performed directly on it.
329 However, in case many particles are affected, the helper class
330 <code>RotBstMatrix</code> can be used to speed up operations.
332 <a name="method41"></a>
333 <p/><strong>void Vec4::rot(double theta, double phi) </strong> <br/>
334 rotate the three-momentum with the polar angle <i>theta</i>
335 and the azimuthal angle <i>phi</i>.
338 <a name="method42"></a>
339 <p/><strong>void Vec4::rotaxis(double phi, double nx, double ny, double nz) </strong> <br/>
340 rotate the three-momentum with the azimuthal angle <i>phi</i>
341 around the direction defined by the <i>(n_x, n_y, n_z)</i>
345 <a name="method43"></a>
346 <p/><strong>void Vec4::rotaxis(double phi, Vec4& n) </strong> <br/>
347 rotate the three-momentum with the azimuthal angle <i>phi</i>
348 around the direction defined by the three-vector part of <i>n</i>.
351 <a name="method44"></a>
352 <p/><strong>void Vec4::bst(double betaX, double betaY, double betaZ) </strong> <br/>
353 boost the four-momentum by <i>beta = (beta_x, beta_y, beta_z)</i>.
356 <a name="method45"></a>
357 <p/><strong>void Vec4::bst(double betaX, double betaY, double betaZ,double gamma) </strong> <br/>
358 boost the four-momentum by <i>beta = (beta_x, beta_y, beta_z)</i>,
359 where the <i>gamma = 1/sqrt(1 - beta^2)</i> is also input to allow
360 better precision when <i>beta</i> is close to unity.
363 <a name="method46"></a>
364 <p/><strong>void Vec4::bst(const Vec4& p) </strong> <br/>
365 boost the four-momentum by <i>beta = (p_x/E, p_y/E, p_z/E)</i>.
368 <a name="method47"></a>
369 <p/><strong>void Vec4::bst(const Vec4& p, double m) </strong> <br/>
370 boost the four-momentum by <i>beta = (p_x/E, p_y/E, p_z/E)</i>,
371 where the <i>gamma = E/m</i> is also calculated from input to allow
372 better precision when <i>beta</i> is close to unity.
375 <a name="method48"></a>
376 <p/><strong>void Vec4::bstback(const Vec4& p) </strong> <br/>
377 boost the four-momentum by <i>beta = (-p_x/E, -p_y/E, -p_z/E)</i>.
380 <a name="method49"></a>
381 <p/><strong>void Vec4::bstback(const Vec4& p, double m) </strong> <br/>
382 boost the four-momentum by <i>beta = (-p_x/E, -p_y/E, -p_z/E)</i>,
383 where the <i>gamma = E/m</i> is also calculated from input to allow
384 better precision when <i>beta</i> is close to unity.
387 <a name="method50"></a>
388 <p/><strong>void Vec4::rotbst(const RotBstMatrix& M) </strong> <br/>
389 perform a combined rotation and boost; see below for a description
390 of the <code>RotBstMatrix</code>.
394 For a longer sequence of rotations and boosts, and where several
395 <code>Vec4</code> are to be rotated and boosted in the same way,
396 a more efficient approach is to define a <code>RotBstMatrix</code>,
397 which forms a separate auxiliary class. You can build up this
398 4-by-4 matrix by successive calls to the methods of the class,
399 such that the matrix encodes the full sequence of operations.
400 The order in which you do these calls must agree with the imagined
401 order in which the rotations/boosts should be applied to a
402 four-momentum, since in general the operations do not commute.
404 <a name="method51"></a>
405 <p/><strong>RotBstMatrix::RotBstMatrix() </strong> <br/>
406 creates a diagonal unit matrix, i.e. one that leaves a four-vector
410 <a name="method52"></a>
411 <p/><strong>RotBstMatrix::RotBstMatrix(const RotBstMatrix& Min) </strong> <br/>
412 creates a copy of the input matrix.
415 <a name="method53"></a>
416 <p/><strong>RotBstMatrix& RotBstMatrix::operator=(const RotBstMatrix4& Min) </strong> <br/>
417 copies the input matrix.
420 <a name="method54"></a>
421 <p/><strong>void RotBstMatrix::rot(double theta = 0., double phi = 0.) </strong> <br/>
422 rotate by this polar and azimuthal angle.
425 <a name="method55"></a>
426 <p/><strong>void RotBstMatrix::rot(const Vec4& p) </strong> <br/>
427 rotate so that a vector originally along the <i>+z</i> axis becomes
428 parallel with <i>p</i>. More specifically, rotate by <i>-phi</i>,
429 <i>theta</i> and <i>phi</i>, with angles defined by <i>p</i>.
432 <a name="method56"></a>
433 <p/><strong>void RotBstMatrix::bst(double betaX = 0., double betaY = 0., double betaZ = 0.) </strong> <br/>
434 boost by this <i>beta</i> vector.
437 <a name="method57"></a>
438 <p/><strong>void RotBstMatrix::bst(const Vec4&) </strong> <br/>
440 <strong>void RotBstMatrix::bstback(const Vec4&) </strong> <br/>
441 boost with a <i>beta = p/E</i> or <i>beta = -p/E</i>, respectively.
444 <a name="method58"></a>
445 <p/><strong>void RotBstMatrix::bst(const Vec4& p1, const Vec4& p2) </strong> <br/>
446 boost so that <i>p_1</i> is transformed to <i>p_2</i>. It is assumed
447 that the two vectors obey <i>p_1^2 = p_2^2</i>.
450 <a name="method59"></a>
451 <p/><strong>void RotBstMatrix::toCMframe(const Vec4& p1, const Vec4& p2) </strong> <br/>
452 boost and rotate to the rest frame of <i>p_1</i> and <i>p_2</i>,
453 with <i>p_1</i> along the <i>+z</i> axis.
456 <a name="method60"></a>
457 <p/><strong>void RotBstMatrix::fromCMframe(const Vec4& p1, const Vec4& p2) </strong> <br/>
458 rotate and boost from the rest frame of <i>p_1</i> and <i>p_2</i>,
459 with <i>p_1</i> along the <i>+z</i> axis, to the actual frame of
460 <i>p_1</i> and <i>p_2</i>, i.e. the inverse of the above.
463 <a name="method61"></a>
464 <p/><strong>void RotBstMatrix::rotbst(const RotBstMatrix& Min); </strong> <br/>
465 combine the current matrix with another one.
468 <a name="method62"></a>
469 <p/><strong>void RotBstMatrix::invert() </strong> <br/>
470 invert the matrix, which corresponds to an opposite sequence and sign
471 of rotations and boosts.
474 <a name="method63"></a>
475 <p/><strong>void RotBstMatrix::reset() </strong> <br/>
476 reset to no rotation/boost; i.e. the default at creation.
479 <a name="method64"></a>
480 <p/><strong>double RotBstMatrix::deviation() </strong> <br/>
481 crude estimate how much a matrix deviates from the unit matrix:
482 the sum of the absolute values of all non-diagonal matrix elements
483 plus the sum of the absolute deviation of the diagonal matrix
487 <a name="method65"></a>
488 <p/><strong>friend ostream& operator<<(ostream&, const RotBstMatrix& M) </strong> <br/>
489 writes out the values of the sixteen components of a
490 <code>RotBstMatrix</code>, on four consecutive lines and
491 ended with a newline.
497 <!-- Copyright (C) 2013 Torbjorn Sjostrand -->