1 <chapter name="Four-Vectors">
5 The <code>Vec4</code> class gives a simple implementation of four-vectors.
6 The member function names are based on the assumption that these
7 represent four-momentum vectors. Thus one can get or set
8 <ei>p_x, p_y, p_z</ei> and <ei>e</ei>, but not <ei>x, y, z</ei>
9 or <ei>t</ei>. This is only a matter of naming, however; a
10 <code>Vec4</code> can equally well be used to store a space-time
14 The <code>Particle</code> object contains a <code>Vec4 p</code> that
15 stores the particle four-momentum, and another <code>Vec4 vProd</code>
16 for the production vertex. For the latter the input/output method
17 names are adapted to the space-time character rather than the normal
18 energy-momentum one. Thus a user would not normally access the
19 <code>Vec4</code> classes directly, but only via the methods of the
20 <code>Particle</code> class,
21 see <aloc href="ParticleProperties">Particle Properties</aloc>.
24 Nevertheless you are free to use the PYTHIA four-vectors, e.g. as
25 part of some simple analysis code based directly on the PYTHIA output,
26 say to define the four-vector sum of a set of particles. But note that
27 this class was never set up to allow complete generality, only to
28 provide the operations that are of use inside PYTHIA. There is no
29 separate class for three-vectors, since such can easily be represented
30 by four-vectors where the fourth component is not used.
33 Four-vectors have the expected functionality: they can be created,
34 copied, added, multiplied, rotated, boosted, and manipulated in other
35 ways. Operator overloading is implemented where reasonable. Properties
36 can be read out, not only the components themselves but also for derived
37 quantities such as absolute momentum and direction angles.
39 <h3>Constructors and basic operators</h3>
41 A few methods are available to create or copy a four-vector:
43 <method name="Vec4::Vec4()">
44 creates a four-vector with all components set to 0.
47 <method name="Vec4::Vec4(const Vec4& v)">
48 creates a four-vector copy of the input four-vector.
51 <method name="Vec4& Vec4::operator=(const Vec4& v)">
52 copies the input four-vector.
55 <method name="Vec4& Vec4::operator=(double value)">
56 gives a four-vector with all components set to <ei>value</ei>.
59 <h3>Member methods for input</h3>
61 The values stored in a four-vector can be modified in a few different
64 <method name="void Vec4::reset()">
65 sets all components to 0.
68 <method name="void Vec4::p(double pxIn, double pyIn, double pzIn,
70 sets all components to their input values.
73 <method name="void Vec4::p(Vec4 pIn)">
74 sets all components equal to those of the input four-vector.
77 <method name="void Vec4::px(double pxIn)">
79 <methodmore name="void Vec4::py(double pyIn)">
81 <methodmore name="void Vec4::pz(double pzIn)">
83 <methodmore name="void Vec4::e(double eIn)">
84 sets the respective component to the input value.
87 <h3>Member methods for output</h3>
89 A number of methods provides output of basic or derived quantities:
91 <method name="double Vec4::px()">
93 <methodmore name="double Vec4::py()">
95 <methodmore name="double Vec4::pz()">
97 <methodmore name="double Vec4::e()">
98 gets the respective component.
101 <method name="double Vec4::mCalc()">
103 <methodmore name="double Vec4::m2Calc()">
104 the (squared) mass, calculated from the four-vectors.
105 If <ei>m^2 < 0</ei> the mass is given with a minus sign,
106 <ei>-sqrt(-m^2)</ei>. Note the possible loss of precision
107 in the calculation of <ei>E^2 - p^2</ei>; for particles the
108 correct mass is stored separately to avoid such problems.
111 <method name="double Vec4::pT()">
113 <methodmore name="double Vec4::pT2()">
114 the (squared) transverse momentum.
117 <method name="double Vec4::pAbs()">
119 <methodmore name="double Vec4::pAbs2()">
120 the (squared) absolute momentum.
123 <method name="double Vec4::eT()">
125 <methodmore name="double Vec4::eT2()">
126 the (squared) transverse energy,
127 <ei>eT = e * sin(theta) = e * pT / pAbs</ei>.
130 <method name="double Vec4::theta()">
131 the polar angle, in the range 0 through
135 <method name="double Vec4::phi()">
136 the azimuthal angle, in the range <ei>-pi</ei> through <ei>pi</ei>.
139 <method name="double Vec4::thetaXZ()">
140 the angle in the <ei>xz</ei> plane, in the range <ei>-pi</ei> through
141 <ei>pi</ei>, with 0 along the <ei>+z</ei> axis.
144 <method name="double Vec4::pPos()">
146 <methodmore name="double Vec4::pNeg()">
147 the combinations <ei>E+-p_z</ei>.</methodmore>
149 <h3>Friend methods for output</h3>
151 There are also some <code>friend</code> methods that take one, two
152 or three four-vectors as argument. Several of them only use the
153 three-vector part of the four-vector.
155 <method name="friend ostream& operator<<(ostream&, const Vec4& v)">
156 writes out the values of the four components of a <code>Vec4</code> and,
157 within brackets, a fifth component being the invariant length of the
158 four-vector, as provided by <code>mCalc()</code> above, and it all
159 ended with a newline.
162 <method name="friend double m(const Vec4& v1, const Vec4& v2)">
164 <methodmore name="friend double m2(const Vec4& v1, const Vec4& v2)">
165 the (squared) invariant mass.
168 <method name="friend double dot3(const Vec4& v1, const Vec4& v2)">
172 <method name="friend double cross3(const Vec4& v1, const Vec4& v2)">
176 <method name="friend double theta(const Vec4& v1, const Vec4& v2)">
178 <methodmore name="friend double costheta(const Vec4& v1, const Vec4& v2)">
179 the (cosine) of the opening angle between the vectors,
180 in the range 0 through <ei>pi</ei>.
183 <method name="friend double phi(const Vec4& v1, const Vec4& v2)">
185 <methodmore name="friend double cosphi(const Vec4& v1, const Vec4& v2)">
186 the (cosine) of the azimuthal angle between the vectors around the
187 <ei>z</ei> axis, in the range 0 through <ei>pi</ei>.
190 <method name="friend double phi(const Vec4& v1, const Vec4& v2,
193 <methodmore name="friend double cosphi(const Vec4& v1, const Vec4& v2,
195 the (cosine) of the azimuthal angle between the first two vectors
196 around the direction of the third, in the range 0 through <ei>pi</ei>.
199 <h3>Operations with four-vectors</h3>
201 Of course one should be able to add, subtract and scale four-vectors,
204 <method name="Vec4 Vec4::operator-()">
205 return a vector with flipped sign for all components, while leaving
206 the original vector unchanged.
209 <method name="Vec4& Vec4::operator+=(const Vec4& v)">
210 add a four-vector to an existing one.
213 <method name="Vec4& Vec4::operator-=(const Vec4& v)">
214 subtract a four-vector from an existing one.
217 <method name="Vec4& Vec4::operator*=(double f)">
218 multiply all four-vector components by a real number.
221 <method name="Vec4& Vec4::operator/=(double f)">
222 divide all four-vector components by a real number.
225 <method name="friend Vec4 operator+(const Vec4& v1, const Vec4& v2)">
226 add two four-vectors.
229 <method name="friend Vec4 operator-(const Vec4& v1, const Vec4& v2)">
230 subtract two four-vectors.
233 <method name="friend Vec4 operator*(double f, const Vec4& v)">
235 <methodmore name="friend Vec4 operator*(const Vec4& v, double f)">
236 multiply a four-vector by a real number.
239 <method name="friend Vec4 operator/(const Vec4& v, double f)">
240 divide a four-vector by a real number.
243 <method name="friend double operator*(const Vec4& v1, const Vec4 v2)">
248 There are also a few related operations that are normal member methods:
250 <method name="void Vec4::rescale3(double f)">
251 multiply the three-vector components by <ei>f</ei>, but keep the
252 fourth component unchanged.
255 <method name="void Vec4::rescale4(double f)">
256 multiply all four-vector components by <ei>f</ei>.
259 <method name="void Vec4::flip3()">
260 flip the sign of the three-vector components, but keep the
261 fourth component unchanged.
264 <method name="void Vec4::flip4()">
265 flip the sign of all four-vector components.
268 <h3>Rotations and boosts</h3>
270 A common task is to rotate or boost four-vectors. In case only one
271 four-vector is affected the operation may be performed directly on it.
272 However, in case many particles are affected, the helper class
273 <code>RotBstMatrix</code> can be used to speed up operations.
275 <method name="void Vec4::rot(double theta, double phi)">
276 rotate the three-momentum with the polar angle <ei>theta</ei>
277 and the azimuthal angle <ei>phi</ei>.
280 <method name="void Vec4::rotaxis(double phi, double nx, double ny,
282 rotate the three-momentum with the azimuthal angle <ei>phi</ei>
283 around the direction defined by the <ei>(n_x, n_y, n_z)</ei>
287 <method name="void Vec4::rotaxis(double phi, Vec4& n)">
288 rotate the three-momentum with the azimuthal angle <ei>phi</ei>
289 around the direction defined by the three-vector part of <ei>n</ei>.
292 <method name="void Vec4::bst(double betaX, double betaY, double betaZ)">
293 boost the four-momentum by <ei>beta = (beta_x, beta_y, beta_z)</ei>.
296 <method name="void Vec4::bst(double betaX, double betaY, double betaZ,
298 boost the four-momentum by <ei>beta = (beta_x, beta_y, beta_z)</ei>,
299 where the <ei>gamma = 1/sqrt(1 - beta^2)</ei> is also input to allow
300 better precision when <ei>beta</ei> is close to unity.
303 <method name="void Vec4::bst(const Vec4& p)">
304 boost the four-momentum by <ei>beta = (p_x/E, p_y/E, p_z/E)</ei>.
307 <method name="void Vec4::bst(const Vec4& p, double m)">
308 boost the four-momentum by <ei>beta = (p_x/E, p_y/E, p_z/E)</ei>,
309 where the <ei>gamma = E/m</ei> is also calculated from input to allow
310 better precision when <ei>beta</ei> is close to unity.
313 <method name="void Vec4::bstback(const Vec4& p)">
314 boost the four-momentum by <ei>beta = (-p_x/E, -p_y/E, -p_z/E)</ei>.
317 <method name="void Vec4::bstback(const Vec4& p, double m)">
318 boost the four-momentum by <ei>beta = (-p_x/E, -p_y/E, -p_z/E)</ei>,
319 where the <ei>gamma = E/m</ei> is also calculated from input to allow
320 better precision when <ei>beta</ei> is close to unity.
323 <method name="void Vec4::rotbst(const RotBstMatrix& M)">
324 perform a combined rotation and boost; see below for a description
325 of the <code>RotBstMatrix</code>.
329 For a longer sequence of rotations and boosts, and where several
330 <code>Vec4</code> are to be rotated and boosted in the same way,
331 a more efficient approach is to define a <code>RotBstMatrix</code>,
332 which forms a separate auxiliary class. You can build up this
333 4-by-4 matrix by successive calls to the methods of the class,
334 such that the matrix encodes the full sequence of operations.
335 The order in which you do these calls must agree with the imagined
336 order in which the rotations/boosts should be applied to a
337 four-momentum, since in general the operations do not commute.
339 <method name="RotBstMatrix::RotBstMatrix()">
340 creates a diagonal unit matrix, i.e. one that leaves a four-vector
344 <method name="RotBstMatrix::RotBstMatrix(const RotBstMatrix& Min)">
345 creates a copy of the input matrix.
348 <method name="RotBstMatrix& RotBstMatrix::operator=(const RotBstMatrix4& Min)">
349 copies the input matrix.
352 <method name="void RotBstMatrix::rot(double theta = 0., double phi = 0.)">
353 rotate by this polar and azimuthal angle.
356 <method name="void RotBstMatrix::rot(const Vec4& p)">
357 rotate so that a vector originally along the <ei>+z</ei> axis becomes
358 parallel with <ei>p</ei>. More specifically, rotate by <ei>-phi</ei>,
359 <ei>theta</ei> and <ei>phi</ei>, with angles defined by <ei>p</ei>.
362 <method name="void RotBstMatrix::bst(double betaX = 0., double betaY = 0.,
364 boost by this <ei>beta</ei> vector.
367 <method name="void RotBstMatrix::bst(const Vec4&)">
369 <methodmore name="void RotBstMatrix::bstback(const Vec4&)">
370 boost with a <ei>beta = p/E</ei> or <ei>beta = -p/E</ei>, respectively.
373 <method name="void RotBstMatrix::bst(const Vec4& p1, const Vec4& p2)">
374 boost so that <ei>p_1</ei> is transformed to <ei>p_2</ei>. It is assumed
375 that the two vectors obey <ei>p_1^2 = p_2^2</ei>.
378 <method name="void RotBstMatrix::toCMframe(const Vec4& p1, const Vec4& p2)">
379 boost and rotate to the rest frame of <ei>p_1</ei> and <ei>p_2</ei>,
380 with <ei>p_1</ei> along the <ei>+z</ei> axis.
383 <method name="void RotBstMatrix::fromCMframe(const Vec4& p1, const Vec4& p2)">
384 rotate and boost from the rest frame of <ei>p_1</ei> and <ei>p_2</ei>,
385 with <ei>p_1</ei> along the <ei>+z</ei> axis, to the actual frame of
386 <ei>p_1</ei> and <ei>p_2</ei>, i.e. the inverse of the above.
389 <method name="void RotBstMatrix::rotbst(const RotBstMatrix& Min);">
390 combine the current matrix with another one.
393 <method name="void RotBstMatrix::invert()">
394 invert the matrix, which corresponds to an opposite sequence and sign
395 of rotations and boosts.
398 <method name="void RotBstMatrix::reset()">
399 reset to no rotation/boost; i.e. the default at creation.
402 <method name="double RotBstMatrix::deviation()">
403 crude estimate how much a matrix deviates from the unit matrix:
404 the sum of the absolute values of all non-diagonal matrix elements
405 plus the sum of the absolute deviation of the diagonal matrix
409 <method name="friend ostream& operator<<(ostream&,
410 const RotBstMatrix& M)">
411 writes out the values of the sixteen components of a
412 <code>RotBstMatrix</code>, on four consecutive lines and
413 ended with a newline.
418 <!-- Copyright (C) 2012 Torbjorn Sjostrand -->