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