Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
PxPyPzE4D.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id: 04c6d98020d7178ed5f0884f9466bca32b031565 $
2// Authors: W. Brown, M. Fischler, L. Moneta 2005
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 , LCG ROOT MathLib Team *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for class PxPyPzE4D
12//
13// Created by: fischler at Wed Jul 20 2005
14// (starting from PxPyPzE4D by moneta)
15//
16// Last update: $Id: 04c6d98020d7178ed5f0884f9466bca32b031565 $
17//
18#ifndef ROOT_MathX_GenVectorX_PxPyPzE4D
19#define ROOT_MathX_GenVectorX_PxPyPzE4D 1
20
22
24
26
27using namespace ROOT::ROOT_MATH_ARCH;
28
30
31#include <cmath>
32
33namespace ROOT {
34
35namespace ROOT_MATH_ARCH {
36
37//__________________________________________________________________________________________
38/**
39 Class describing a 4D cartesian coordinate system (x, y, z, t coordinates)
40 or momentum-energy vectors stored as (Px, Py, Pz, E).
41 The metric used is (-,-,-,+)
42
43 @ingroup GenVectorX
44
45 @see GenVectorX
46*/
47
48template <class ScalarType = double>
49class PxPyPzE4D {
50
51public:
52 typedef ScalarType Scalar;
53
54 // --------- Constructors ---------------
55
56 /**
57 Default constructor with x=y=z=t=0
58 */
59 constexpr PxPyPzE4D() noexcept = default;
60
61 /**
62 Constructor from x, y , z , t values
63 */
64 constexpr PxPyPzE4D(Scalar px, Scalar py, Scalar pz, Scalar e) noexcept : fX(px), fY(py), fZ(pz), fT(e) {}
65
66 /**
67 construct from any vector or coordinate system class
68 implementing x(), y() and z() and t()
69 */
70 template <class CoordSystem>
71 explicit PxPyPzE4D(const CoordSystem &v) : fX(v.x()), fY(v.y()), fZ(v.z()), fT(v.t())
72 {
73 }
74
75 /**
76 Set internal data based on an array of 4 Scalar numbers
77 */
79 {
80 fX = src[0];
81 fY = src[1];
82 fZ = src[2];
83 fT = src[3];
84 }
85
86 /**
87 get internal data into an array of 4 Scalar numbers
88 */
90 {
91 dest[0] = fX;
92 dest[1] = fY;
93 dest[2] = fZ;
94 dest[3] = fT;
95 }
96
97 /**
98 Set internal data based on 4 Scalar numbers
99 */
101 {
102 fX = px;
103 fY = py;
104 fZ = pz;
105 fT = e;
106 }
107
108 /**
109 get internal data into 4 Scalar numbers
110 */
111 void GetCoordinates(Scalar &px, Scalar &py, Scalar &pz, Scalar &e) const
112 {
113 px = fX;
114 py = fY;
115 pz = fZ;
116 e = fT;
117 }
118
119 // --------- Coordinates and Coordinate-like Scalar properties -------------
120
121 // cartesian (Minkowski)coordinate accessors
122
123 Scalar Px() const { return fX; }
124 Scalar Py() const { return fY; }
125 Scalar Pz() const { return fZ; }
126 Scalar E() const { return fT; }
127
128 Scalar X() const { return fX; }
129 Scalar Y() const { return fY; }
130 Scalar Z() const { return fZ; }
131 Scalar T() const { return fT; }
132
133 // other coordinate representation
134
135 /**
136 squared magnitude of spatial components
137 */
138 Scalar P2() const { return fX * fX + fY * fY + fZ * fZ; }
139
140 /**
141 magnitude of spatial components (magnitude of 3-momentum)
142 */
143 Scalar P() const { return math_sqrt(P2()); }
144 Scalar R() const { return P(); }
145
146 /**
147 vector magnitude squared (or mass squared)
148 */
149 Scalar M2() const { return fT * fT - fX * fX - fY * fY - fZ * fZ; }
150 Scalar Mag2() const { return M2(); }
151
152 /**
153 invariant mass
154 */
155 Scalar M() const
156 {
157 const Scalar mm = M2();
158 if (mm >= 0) {
159 return math_sqrt(mm);
160 } else {
161#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
162 GenVector_Throw("PxPyPzE4D::M() - Tachyonic:\n"
163 " P^2 > E^2 so the mass would be imaginary");
164#endif
165 return -math_sqrt(-mm);
166 }
167 }
168 Scalar Mag() const { return M(); }
169
170 /**
171 transverse spatial component squared
172 */
173 Scalar Pt2() const { return fX * fX + fY * fY; }
174 Scalar Perp2() const { return Pt2(); }
175
176 /**
177 Transverse spatial component (P_perp or rho)
178 */
179 Scalar Pt() const { return math_sqrt(Perp2()); }
180 Scalar Perp() const { return Pt(); }
181 Scalar Rho() const { return Pt(); }
182
183 /**
184 transverse mass squared
185 */
186 Scalar Mt2() const { return fT * fT - fZ * fZ; }
187
188 /**
189 transverse mass
190 */
191 Scalar Mt() const
192 {
193 const Scalar mm = Mt2();
194 if (mm >= 0) {
195 return math_sqrt(mm);
196 } else {
197#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
198 GenVector_Throw("PxPyPzE4D::Mt() - Tachyonic:\n"
199 " Pz^2 > E^2 so the transverse mass would be imaginary");
200#endif
201 return -math_sqrt(-mm);
202 }
203 }
204
205 /**
206 transverse energy squared
207 */
208 Scalar Et2() const
209 { // is (E^2 * pt ^2) / p^2
210 // but it is faster to form p^2 from pt^2
211 Scalar pt2 = Pt2();
212 return pt2 == 0 ? 0 : fT * fT * pt2 / (pt2 + fZ * fZ);
213 }
214
215 /**
216 transverse energy
217 */
218 Scalar Et() const
219 {
220 const Scalar etet = Et2();
221 return fT < 0.0 ? -math_sqrt(etet) : math_sqrt(etet);
222 }
223
224 /**
225 azimuthal angle
226 */
227 Scalar Phi() const { return (fX == 0.0 && fY == 0.0) ? 0 : math_atan2(fY, fX); }
228
229 /**
230 polar angle
231 */
232 Scalar Theta() const { return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : math_atan2(Pt(), fZ); }
233
234 /**
235 pseudorapidity
236 */
237 Scalar Eta() const { return Impl::Eta_FromRhoZ(Pt(), fZ); }
238
239 // --------- Set Coordinates of this system ---------------
240
241 /**
242 set X value
243 */
244 void SetPx(Scalar px) { fX = px; }
245 /**
246 set Y value
247 */
248 void SetPy(Scalar py) { fY = py; }
249 /**
250 set Z value
251 */
252 void SetPz(Scalar pz) { fZ = pz; }
253 /**
254 set T value
255 */
256 void SetE(Scalar e) { fT = e; }
257
258 /**
259 set all values using cartesian coordinates
260 */
262 {
263 fX = px;
264 fY = py;
265 fZ = pz;
266 fT = e;
267 }
268
269 // ------ Manipulations -------------
270
271 /**
272 negate the 4-vector
273 */
274 void Negate()
275 {
276 fX = -fX;
277 fY = -fY;
278 fZ = -fZ;
279 fT = -fT;
280 }
281
282 /**
283 scale coordinate values by a scalar quantity a
284 */
285 void Scale(const Scalar &a)
286 {
287 fX *= a;
288 fY *= a;
289 fZ *= a;
290 fT *= a;
291 }
292
293 /**
294 Assignment from a generic coordinate system implementing
295 x(), y(), z() and t()
296 */
297 template <class AnyCoordSystem>
299 {
300 fX = v.x();
301 fY = v.y();
302 fZ = v.z();
303 fT = v.t();
304 return *this;
305 }
306
307 /**
308 Exact equality
309 */
310 bool operator==(const PxPyPzE4D &rhs) const { return fX == rhs.fX && fY == rhs.fY && fZ == rhs.fZ && fT == rhs.fT; }
311 bool operator!=(const PxPyPzE4D &rhs) const { return !(operator==(rhs)); }
312
313 // ============= Compatibility section ==================
314
315 // The following make this coordinate system look enough like a CLHEP
316 // vector that an assignment member template can work with either
317 Scalar x() const { return fX; }
318 Scalar y() const { return fY; }
319 Scalar z() const { return fZ; }
320 Scalar t() const { return fT; }
321
322#if defined(__MAKECINT__) || defined(G__DICTIONARY)
323
324 // ====== Set member functions for coordinates in other systems =======
325
326 void SetPt(Scalar pt);
327
328 void SetEta(Scalar eta);
329
330 void SetPhi(Scalar phi);
331
332 void SetM(Scalar m);
333
334#endif
335
336private:
337 /**
338 (contiguous) data containing the coordinate values x,y,z,t
339 */
340
341 ScalarType fX = 0;
342 ScalarType fY = 0;
343 ScalarType fZ = 0;
344 ScalarType fT = 0;
345};
346
347} // end namespace ROOT_MATH_ARCH
348} // end namespace ROOT
349
350#if defined(__MAKECINT__) || defined(G__DICTIONARY)
351#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
352// move implementations here to avoid circle dependencies
353
356
357namespace ROOT {
358
359namespace ROOT_MATH_ARCH {
360
361// ====== Set member functions for coordinates in other systems =======
362// throw always exceptions in this case
363
364template <class ScalarType>
366{
367 GenVector_exception e("PxPyPzE4D::SetPt() is not supposed to be called");
368 throw e;
369 PtEtaPhiE4D<Scalar> v(*this);
370 v.SetPt(pt);
371 *this = PxPyPzE4D<Scalar>(v);
372}
373template <class ScalarType>
375{
376 GenVector_exception e("PxPyPzE4D::SetEta() is not supposed to be called");
377 throw e;
378 PtEtaPhiE4D<Scalar> v(*this);
379 v.SetEta(eta);
380 *this = PxPyPzE4D<Scalar>(v);
381}
382template <class ScalarType>
384{
385 GenVector_exception e("PxPyPzE4D::SetPhi() is not supposed to be called");
386 throw e;
387 PtEtaPhiE4D<Scalar> v(*this);
388 v.SetPhi(phi);
389 *this = PxPyPzE4D<Scalar>(v);
390}
391
392template <class ScalarType>
394{
395 GenVector_exception e("PxPyPzE4D::SetM() is not supposed to be called");
396 throw e;
397 PtEtaPhiM4D<Scalar> v(*this);
398 v.SetM(m);
399 *this = PxPyPzE4D<Scalar>(v);
400}
401
402} // end namespace ROOT_MATH_ARCH
403
404} // end namespace ROOT
405
406#endif // endif __MAKE__CINT || G__DICTIONARY
407#endif
408
409#endif // ROOT_MathX_GenVectorX_PxPyPzE4D
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t dest
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
Class describing a 4D cartesian coordinate system (x, y, z, t coordinates) or momentum-energy vectors...
Definition PxPyPzE4D.h:49
ScalarType fX
(contiguous) data containing the coordinate values x,y,z,t
Definition PxPyPzE4D.h:341
constexpr PxPyPzE4D() noexcept=default
Default constructor with x=y=z=t=0.
Scalar M() const
invariant mass
Definition PxPyPzE4D.h:155
Scalar Pt() const
Transverse spatial component (P_perp or rho)
Definition PxPyPzE4D.h:179
bool operator==(const PxPyPzE4D &rhs) const
Exact equality.
Definition PxPyPzE4D.h:310
PxPyPzE4D & operator=(const AnyCoordSystem &v)
Assignment from a generic coordinate system implementing x(), y(), z() and t()
Definition PxPyPzE4D.h:298
Scalar Et() const
transverse energy
Definition PxPyPzE4D.h:218
void SetCoordinates(Scalar px, Scalar py, Scalar pz, Scalar e)
Set internal data based on 4 Scalar numbers.
Definition PxPyPzE4D.h:100
void SetPx(Scalar px)
set X value
Definition PxPyPzE4D.h:244
PxPyPzE4D(const CoordSystem &v)
construct from any vector or coordinate system class implementing x(), y() and z() and t()
Definition PxPyPzE4D.h:71
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 4 Scalar numbers.
Definition PxPyPzE4D.h:78
Scalar Mt2() const
transverse mass squared
Definition PxPyPzE4D.h:186
void SetPy(Scalar py)
set Y value
Definition PxPyPzE4D.h:248
Scalar Theta() const
polar angle
Definition PxPyPzE4D.h:232
Scalar Pt2() const
transverse spatial component squared
Definition PxPyPzE4D.h:173
bool operator!=(const PxPyPzE4D &rhs) const
Definition PxPyPzE4D.h:311
Scalar Mt() const
transverse mass
Definition PxPyPzE4D.h:191
Scalar Phi() const
azimuthal angle
Definition PxPyPzE4D.h:227
Scalar Eta() const
pseudorapidity
Definition PxPyPzE4D.h:237
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 4 Scalar numbers
Definition PxPyPzE4D.h:89
Scalar Et2() const
transverse energy squared
Definition PxPyPzE4D.h:208
void GetCoordinates(Scalar &px, Scalar &py, Scalar &pz, Scalar &e) const
get internal data into 4 Scalar numbers
Definition PxPyPzE4D.h:111
Scalar M2() const
vector magnitude squared (or mass squared)
Definition PxPyPzE4D.h:149
void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e)
set all values using cartesian coordinates
Definition PxPyPzE4D.h:261
Scalar P() const
magnitude of spatial components (magnitude of 3-momentum)
Definition PxPyPzE4D.h:143
void SetE(Scalar e)
set T value
Definition PxPyPzE4D.h:256
void SetPz(Scalar pz)
set Z value
Definition PxPyPzE4D.h:252
void Scale(const Scalar &a)
scale coordinate values by a scalar quantity a
Definition PxPyPzE4D.h:285
Scalar P2() const
squared magnitude of spatial components
Definition PxPyPzE4D.h:138
void Negate()
negate the 4-vector
Definition PxPyPzE4D.h:274
TPaveText * pt
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Scalar Eta_FromRhoZ(Scalar rho, Scalar z)
Calculate eta given rho and zeta.
Definition eta.h:50
void GenVector_Throw(const char *)
function throwing exception, by creating internally a GenVector_exception only when needed
Scalar math_sqrt(Scalar x)
Scalar math_atan2(Scalar x, Scalar y)
TMarker m
Definition textangle.C:8