3
<title>Four-Vectors</title>
4
<link rel="stylesheet" type="text/css" href="pythia.css"/>
5
<link rel="shortcut icon" href="pythia32.gif"/>
9
<script language=javascript type=text/javascript>
10
function stopRKey(evt) {
11
var evt = (evt) ? evt : ((event) ? event : null);
12
var node = (evt.target) ? evt.target :((evt.srcElement) ? evt.srcElement : null);
13
if ((evt.keyCode == 13) && (node.type=="text"))
17
document.onkeypress = stopRKey;
20
if($_POST['saved'] == 1) {
21
if($_POST['filepath'] != "files/") {
22
echo "<font color='red'>SETTINGS SAVED TO FILE</font><br/><br/>"; }
24
echo "<font color='red'>NO FILE SELECTED YET.. PLEASE DO SO </font><a href='SaveSettings.php'>HERE</a><br/><br/>"; }
28
<form method='post' action='FourVectors.php'>
32
The <code>Vec4</code> class gives a simple implementation of four-vectors.
33
The member function names are based on the assumption that these
34
represent four-momentum vectors. Thus one can get or set
35
<i>p_x, p_y, p_z</i> and <i>e</i>, but not <i>x, y, z</i>
36
or <i>t</i>. This is only a matter of naming, however; a
37
<code>Vec4</code> can equally well be used to store a space-time
41
The <code>Particle</code> object contains a <code>Vec4 p</code> that
42
stores the particle four-momentum, and another <code>Vec4 vProd</code>
43
for the production vertex. For the latter the input/output method
44
names are adapted to the space-time character rather than the normal
45
energy-momentum one. Thus a user would not normally access the
46
<code>Vec4</code> classes directly, but only via the methods of the
47
<code>Particle</code> class,
48
see <?php $filepath = $_GET["filepath"];
49
echo "<a href='ParticleProperties.php?filepath=".$filepath."' target='page'>";?>Particle Properties</a>.
52
Nevertheless you are free to use the PYTHIA four-vectors, e.g. as
53
part of some simple analysis code based directly on the PYTHIA output,
54
say to define the four-vector sum of a set of particles. But note that
55
this class was never set up to allow complete generality, only to
56
provide the operations that are of use inside PYTHIA. There is no
57
separate class for three-vectors, since such can easily be represented
58
by four-vectors where the fourth component is not used.
61
Four-vectors have the expected functionality: they can be created,
62
copied, added, multiplied, rotated, boosted, and manipulated in other
63
ways. Operator overloading is implemented where reasonable. Properties
64
can be read out, not only the components themselves but also for derived
65
quantities such as absolute momentum and direction angles.
67
<h3>Constructors and basic operators</h3>
69
A few methods are available to create or copy a four-vector:
71
<a name="method1"></a>
72
<p/><strong>Vec4::Vec4() </strong> <br/>
73
creates a four-vector with all components set to 0.
76
<a name="method2"></a>
77
<p/><strong>Vec4::Vec4(const Vec4& v) </strong> <br/>
78
creates a four-vector copy of the input four-vector.
81
<a name="method3"></a>
82
<p/><strong>Vec4& Vec4::operator=(const Vec4& v) </strong> <br/>
83
copies the input four-vector.
86
<a name="method4"></a>
87
<p/><strong>Vec4& Vec4::operator=(double value) </strong> <br/>
88
gives a four-vector with all components set to <i>value</i>.
91
<h3>Member methods for input</h3>
93
The values stored in a four-vector can be modified in a few different
96
<a name="method5"></a>
97
<p/><strong>void Vec4::reset() </strong> <br/>
98
sets all components to 0.
101
<a name="method6"></a>
102
<p/><strong>void Vec4::p(double pxIn, double pyIn, double pzIn, double eIn) </strong> <br/>
103
sets all components to their input values.
106
<a name="method7"></a>
107
<p/><strong>void Vec4::p(Vec4 pIn) </strong> <br/>
108
sets all components equal to those of the input four-vector.
111
<a name="method8"></a>
112
<p/><strong>void Vec4::px(double pxIn) </strong> <br/>
114
<strong>void Vec4::py(double pyIn) </strong> <br/>
116
<strong>void Vec4::pz(double pzIn) </strong> <br/>
118
<strong>void Vec4::e(double eIn) </strong> <br/>
119
sets the respective component to the input value.
122
<h3>Member methods for output</h3>
124
A number of methods provides output of basic or derived quantities:
126
<a name="method9"></a>
127
<p/><strong>double Vec4::px() </strong> <br/>
129
<strong>double Vec4::py() </strong> <br/>
131
<strong>double Vec4::pz() </strong> <br/>
133
<strong>double Vec4::e() </strong> <br/>
134
gets the respective component.
137
<a name="method10"></a>
138
<p/><strong>double Vec4::mCalc() </strong> <br/>
140
<strong>double Vec4::m2Calc() </strong> <br/>
141
the (squared) mass, calculated from the four-vectors.
142
If <i>m^2 < 0</i> the mass is given with a minus sign,
143
<i>-sqrt(-m^2)</i>. Note the possible loss of precision
144
in the calculation of <i>E^2 - p^2</i>; for particles the
145
correct mass is stored separately to avoid such problems.
148
<a name="method11"></a>
149
<p/><strong>double Vec4::pT() </strong> <br/>
151
<strong>double Vec4::pT2() </strong> <br/>
152
the (squared) transverse momentum.
155
<a name="method12"></a>
156
<p/><strong>double Vec4::pAbs() </strong> <br/>
158
<strong>double Vec4::pAbs2() </strong> <br/>
159
the (squared) absolute momentum.
162
<a name="method13"></a>
163
<p/><strong>double Vec4::eT() </strong> <br/>
165
<strong>double Vec4::eT2() </strong> <br/>
166
the (squared) transverse energy,
167
<i>eT = e * sin(theta) = e * pT / pAbs</i>.
170
<a name="method14"></a>
171
<p/><strong>double Vec4::theta() </strong> <br/>
172
the polar angle, in the range 0 through
176
<a name="method15"></a>
177
<p/><strong>double Vec4::phi() </strong> <br/>
178
the azimuthal angle, in the range <i>-pi</i> through <i>pi</i>.
181
<a name="method16"></a>
182
<p/><strong>double Vec4::thetaXZ() </strong> <br/>
183
the angle in the <i>xz</i> plane, in the range <i>-pi</i> through
184
<i>pi</i>, with 0 along the <i>+z</i> axis.
187
<a name="method17"></a>
188
<p/><strong>double Vec4::pPos() </strong> <br/>
190
<strong>double Vec4::pNeg() </strong> <br/>
191
the combinations <i>E+-p_z</i>.
193
<h3>Friend methods for output</h3>
195
There are also some <code>friend</code> methods that take one, two
196
or three four-vectors as argument. Several of them only use the
197
three-vector part of the four-vector.
199
<a name="method18"></a>
200
<p/><strong>friend ostream& operator<<(ostream&, const Vec4& v) </strong> <br/>
201
writes out the values of the four components of a <code>Vec4</code> and,
202
within brackets, a fifth component being the invariant length of the
203
four-vector, as provided by <code>mCalc()</code> above, and it all
204
ended with a newline.
207
<a name="method19"></a>
208
<p/><strong>friend double m(const Vec4& v1, const Vec4& v2) </strong> <br/>
210
<strong>friend double m2(const Vec4& v1, const Vec4& v2) </strong> <br/>
211
the (squared) invariant mass.
214
<a name="method20"></a>
215
<p/><strong>friend double dot3(const Vec4& v1, const Vec4& v2) </strong> <br/>
219
<a name="method21"></a>
220
<p/><strong>friend double cross3(const Vec4& v1, const Vec4& v2) </strong> <br/>
224
<a name="method22"></a>
225
<p/><strong>friend double theta(const Vec4& v1, const Vec4& v2) </strong> <br/>
227
<strong>friend double costheta(const Vec4& v1, const Vec4& v2) </strong> <br/>
228
the (cosine) of the opening angle between the vectors,
229
in the range 0 through <i>pi</i>.
232
<a name="method23"></a>
233
<p/><strong>friend double phi(const Vec4& v1, const Vec4& v2) </strong> <br/>
235
<strong>friend double cosphi(const Vec4& v1, const Vec4& v2) </strong> <br/>
236
the (cosine) of the azimuthal angle between the vectors around the
237
<i>z</i> axis, in the range 0 through <i>pi</i>.
240
<a name="method24"></a>
241
<p/><strong>friend double phi(const Vec4& v1, const Vec4& v2, const Vec4& v3) </strong> <br/>
243
<strong>friend double cosphi(const Vec4& v1, const Vec4& v2, const Vec4& v3) </strong> <br/>
244
the (cosine) of the azimuthal angle between the first two vectors
245
around the direction of the third, in the range 0 through <i>pi</i>.
248
<h3>Operations with four-vectors</h3>
250
Of course one should be able to add, subtract and scale four-vectors,
253
<a name="method25"></a>
254
<p/><strong>Vec4 Vec4::operator-() </strong> <br/>
255
return a vector with flipped sign for all components, while leaving
256
the original vector unchanged.
259
<a name="method26"></a>
260
<p/><strong>Vec4& Vec4::operator+=(const Vec4& v) </strong> <br/>
261
add a four-vector to an existing one.
264
<a name="method27"></a>
265
<p/><strong>Vec4& Vec4::operator-=(const Vec4& v) </strong> <br/>
266
subtract a four-vector from an existing one.
269
<a name="method28"></a>
270
<p/><strong>Vec4& Vec4::operator*=(double f) </strong> <br/>
271
multiply all four-vector components by a real number.
274
<a name="method29"></a>
275
<p/><strong>Vec4& Vec4::operator/=(double f) </strong> <br/>
276
divide all four-vector components by a real number.
279
<a name="method30"></a>
280
<p/><strong>friend Vec4 operator+(const Vec4& v1, const Vec4& v2) </strong> <br/>
281
add two four-vectors.
284
<a name="method31"></a>
285
<p/><strong>friend Vec4 operator-(const Vec4& v1, const Vec4& v2) </strong> <br/>
286
subtract two four-vectors.
289
<a name="method32"></a>
290
<p/><strong>friend Vec4 operator*(double f, const Vec4& v) </strong> <br/>
292
<strong>friend Vec4 operator*(const Vec4& v, double f) </strong> <br/>
293
multiply a four-vector by a real number.
296
<a name="method33"></a>
297
<p/><strong>friend Vec4 operator/(const Vec4& v, double f) </strong> <br/>
298
divide a four-vector by a real number.
301
<a name="method34"></a>
302
<p/><strong>friend double operator*(const Vec4& v1, const Vec4 v2) </strong> <br/>
307
There are also a few related operations that are normal member methods:
309
<a name="method35"></a>
310
<p/><strong>void Vec4::rescale3(double f) </strong> <br/>
311
multiply the three-vector components by <i>f</i>, but keep the
312
fourth component unchanged.
315
<a name="method36"></a>
316
<p/><strong>void Vec4::rescale4(double f) </strong> <br/>
317
multiply all four-vector components by <i>f</i>.
320
<a name="method37"></a>
321
<p/><strong>void Vec4::flip3() </strong> <br/>
322
flip the sign of the three-vector components, but keep the
323
fourth component unchanged.
326
<a name="method38"></a>
327
<p/><strong>void Vec4::flip4() </strong> <br/>
328
flip the sign of all four-vector components.
331
<h3>Rotations and boosts</h3>
333
A common task is to rotate or boost four-vectors. In case only one
334
four-vector is affected the operation may be performed directly on it.
335
However, in case many particles are affected, the helper class
336
<code>RotBstMatrix</code> can be used to speed up operations.
338
<a name="method39"></a>
339
<p/><strong>void Vec4::rot(double theta, double phi) </strong> <br/>
340
rotate the three-momentum with the polar angle <i>theta</i>
341
and the azimuthal angle <i>phi</i>.
344
<a name="method40"></a>
345
<p/><strong>void Vec4::rotaxis(double phi, double nx, double ny, double nz) </strong> <br/>
346
rotate the three-momentum with the azimuthal angle <i>phi</i>
347
around the direction defined by the <i>(n_x, n_y, n_z)</i>
351
<a name="method41"></a>
352
<p/><strong>void Vec4::rotaxis(double phi, Vec4& n) </strong> <br/>
353
rotate the three-momentum with the azimuthal angle <i>phi</i>
354
around the direction defined by the three-vector part of <i>n</i>.
357
<a name="method42"></a>
358
<p/><strong>void Vec4::bst(double betaX, double betaY, double betaZ) </strong> <br/>
359
boost the four-momentum by <i>beta = (beta_x, beta_y, beta_z)</i>.
362
<a name="method43"></a>
363
<p/><strong>void Vec4::bst(double betaX, double betaY, double betaZ,double gamma) </strong> <br/>
364
boost the four-momentum by <i>beta = (beta_x, beta_y, beta_z)</i>,
365
where the <i>gamma = 1/sqrt(1 - beta^2)</i> is also input to allow
366
better precision when <i>beta</i> is close to unity.
369
<a name="method44"></a>
370
<p/><strong>void Vec4::bst(const Vec4& p) </strong> <br/>
371
boost the four-momentum by <i>beta = (p_x/E, p_y/E, p_z/E)</i>.
374
<a name="method45"></a>
375
<p/><strong>void Vec4::bst(const Vec4& p, double m) </strong> <br/>
376
boost the four-momentum by <i>beta = (p_x/E, p_y/E, p_z/E)</i>,
377
where the <i>gamma = E/m</i> is also calculated from input to allow
378
better precision when <i>beta</i> is close to unity.
381
<a name="method46"></a>
382
<p/><strong>void Vec4::bstback(const Vec4& p) </strong> <br/>
383
boost the four-momentum by <i>beta = (-p_x/E, -p_y/E, -p_z/E)</i>.
386
<a name="method47"></a>
387
<p/><strong>void Vec4::bstback(const Vec4& p, double m) </strong> <br/>
388
boost the four-momentum by <i>beta = (-p_x/E, -p_y/E, -p_z/E)</i>,
389
where the <i>gamma = E/m</i> is also calculated from input to allow
390
better precision when <i>beta</i> is close to unity.
393
<a name="method48"></a>
394
<p/><strong>void Vec4::rotbst(const RotBstMatrix& M) </strong> <br/>
395
perform a combined rotation and boost; see below for a description
396
of the <code>RotBstMatrix</code>.
400
For a longer sequence of rotations and boosts, and where several
401
<code>Vec4</code> are to be rotated and boosted in the same way,
402
a more efficient approach is to define a <code>RotBstMatrix</code>,
403
which forms a separate auxiliary class. You can build up this
404
4-by-4 matrix by successive calls to the methods of the class,
405
such that the matrix encodes the full sequence of operations.
406
The order in which you do these calls must agree with the imagined
407
order in which the rotations/boosts should be applied to a
408
four-momentum, since in general the operations do not commute.
410
<a name="method49"></a>
411
<p/><strong>RotBstMatrix::RotBstMatrix() </strong> <br/>
412
creates a diagonal unit matrix, i.e. one that leaves a four-vector
416
<a name="method50"></a>
417
<p/><strong>RotBstMatrix::RotBstMatrix(const RotBstMatrix& Min) </strong> <br/>
418
creates a copy of the input matrix.
421
<a name="method51"></a>
422
<p/><strong>RotBstMatrix& RotBstMatrix::operator=(const RotBstMatrix4& Min) </strong> <br/>
423
copies the input matrix.
426
<a name="method52"></a>
427
<p/><strong>void RotBstMatrix::rot(double theta = 0., double phi = 0.) </strong> <br/>
428
rotate by this polar and azimuthal angle.
431
<a name="method53"></a>
432
<p/><strong>void RotBstMatrix::rot(const Vec4& p) </strong> <br/>
433
rotate so that a vector originally along the <i>+z</i> axis becomes
434
parallel with <i>p</i>. More specifically, rotate by <i>-phi</i>,
435
<i>theta</i> and <i>phi</i>, with angles defined by <i>p</i>.
438
<a name="method54"></a>
439
<p/><strong>void RotBstMatrix::bst(double betaX = 0., double betaY = 0., double betaZ = 0.) </strong> <br/>
440
boost by this <i>beta</i> vector.
443
<a name="method55"></a>
444
<p/><strong>void RotBstMatrix::bst(const Vec4&) </strong> <br/>
446
<strong>void RotBstMatrix::bstback(const Vec4&) </strong> <br/>
447
boost with a <i>beta = p/E</i> or <i>beta = -p/E</i>, respectively.
450
<a name="method56"></a>
451
<p/><strong>void RotBstMatrix::bst(const Vec4& p1, const Vec4& p2) </strong> <br/>
452
boost so that <i>p_1</i> is transformed to <i>p_2</i>. It is assumed
453
that the two vectors obey <i>p_1^2 = p_2^2</i>.
456
<a name="method57"></a>
457
<p/><strong>void RotBstMatrix::toCMframe(const Vec4& p1, const Vec4& p2) </strong> <br/>
458
boost and rotate to 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.
462
<a name="method58"></a>
463
<p/><strong>void RotBstMatrix::fromCMframe(const Vec4& p1, const Vec4& p2) </strong> <br/>
464
rotate and boost from the rest frame of <i>p_1</i> and <i>p_2</i>,
465
with <i>p_1</i> along the <i>+z</i> axis, to the actual frame of
466
<i>p_1</i> and <i>p_2</i>, i.e. the inverse of the above.
469
<a name="method59"></a>
470
<p/><strong>void RotBstMatrix::rotbst(const RotBstMatrix& Min); </strong> <br/>
471
combine the current matrix with another one.
474
<a name="method60"></a>
475
<p/><strong>void RotBstMatrix::invert() </strong> <br/>
476
invert the matrix, which corresponds to an opposite sequence and sign
477
of rotations and boosts.
480
<a name="method61"></a>
481
<p/><strong>void RotBstMatrix::reset() </strong> <br/>
482
reset to no rotation/boost; i.e. the default at creation.
485
<a name="method62"></a>
486
<p/><strong>double RotBstMatrix::deviation() </strong> <br/>
487
crude estimate how much a matrix deviates from the unit matrix:
488
the sum of the absolute values of all non-diagonal matrix elements
489
plus the sum of the absolute deviation of the diagonal matrix
493
<a name="method63"></a>
494
<p/><strong>friend ostream& operator<<(ostream&, const RotBstMatrix& M) </strong> <br/>
495
writes out the values of the sixteen components of a
496
<code>RotBstMatrix</code>, on four consecutive lines and
497
ended with a newline.
503
<!-- Copyright (C) 2012 Torbjorn Sjostrand -->