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 @sa Overview of the @ref GenVector "physics vector library"
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 PxPyPzE4D() : fX(0.0), fY(0.0), fZ(0.0), fT(0.0) { }
57
58
59 /**
60 Constructor from x, y , z , t values
61 */
63 fX(px), fY(py), fZ(pz), fT(e) { }
64
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 constexpr PxPyPzE4D(const CoordSystem & v) :
72 fX( v.x() ), fY( v.y() ), fZ( v.z() ), fT( v.t() ) { }
73
74 // for g++ 3.2 and 3.4 on 32 bits found that the compiler generated copy ctor and assignment are much slower
75 // so we decided to re-implement them ( there is no no need to have them with g++4)
76 /**
77 copy constructor
78 */
80 fX(v.fX), fY(v.fY), fZ(v.fZ), fT(v.fT) { }
81
82 /**
83 assignment operator
84 */
86 fX = v.fX;
87 fY = v.fY;
88 fZ = v.fZ;
89 fT = v.fT;
90 return *this;
91 }
92
93 /**
94 Set internal data based on an array of 4 Scalar numbers
95 */
96 void SetCoordinates( const Scalar src[] )
97 { fX=src[0]; fY=src[1]; fZ=src[2]; fT=src[3]; }
98
99 /**
100 get internal data into an array of 4 Scalar numbers
101 */
102 void GetCoordinates( Scalar dest[] ) const
103 { dest[0] = fX; dest[1] = fY; dest[2] = fZ; dest[3] = fT; }
104
105 /**
106 Set internal data based on 4 Scalar numbers
107 */
109 { fX=px; fY=py; fZ=pz; fT=e;}
110
111 /**
112 get internal data into 4 Scalar numbers
113 */
114 void GetCoordinates(Scalar& px, Scalar& py, Scalar& pz, Scalar& e) const
115 { px=fX; py=fY; pz=fZ; e=fT;}
116
117 // --------- Coordinates and Coordinate-like Scalar properties -------------
118
119 // cartesian (Minkowski)coordinate accessors
120
121 Scalar Px() const { return fX;}
122 Scalar Py() const { return fY;}
123 Scalar Pz() const { return fZ;}
124 Scalar E() const { return fT;}
125
126 Scalar X() const { return fX;}
127 Scalar Y() const { return fY;}
128 Scalar Z() const { return fZ;}
129 Scalar T() const { return fT;}
130
131 // other coordinate representation
132
133 /**
134 squared magnitude of spatial components
135 */
136 Scalar P2() const { return fX*fX + fY*fY + fZ*fZ; }
137
138 /**
139 magnitude of spatial components (magnitude of 3-momentum)
140 */
141 Scalar P() const { using std::sqrt; return sqrt(P2()); }
142 Scalar R() const { return P(); }
143
144 /**
145 vector magnitude squared (or mass squared)
146 */
147 Scalar M2() const { return fT*fT - fX*fX - fY*fY - fZ*fZ;}
148 Scalar Mag2() const { return M2(); }
149
150 /**
151 invariant mass
152 */
153 Scalar M() const
154 {
155 const Scalar mm = M2();
156 if (mm >= 0) {
157 using std::sqrt;
158 return sqrt(mm);
159 } else {
160 GenVector::Throw ("PxPyPzE4D::M() - Tachyonic:\n"
161 " P^2 > E^2 so the mass would be imaginary");
162 using std::sqrt;
163 return -sqrt(-mm);
164 }
165 }
166 Scalar Mag() const { return M(); }
167
168 /**
169 transverse spatial component squared
170 */
171 Scalar Pt2() const { return fX*fX + fY*fY;}
172 Scalar Perp2() const { return Pt2();}
173
174 /**
175 Transverse spatial component (P_perp or rho)
176 */
177 Scalar Pt() const { using std::sqrt; return sqrt(Perp2()); }
178 Scalar Perp() const { return Pt();}
179 Scalar Rho() const { return Pt();}
180
181 /**
182 transverse mass squared
183 */
184 Scalar Mt2() const { return fT*fT - fZ*fZ; }
185
186 /**
187 transverse mass
188 */
189 Scalar Mt() const {
190 const Scalar mm = Mt2();
191 if (mm >= 0) {
192 using std::sqrt;
193 return sqrt(mm);
194 } else {
195 GenVector::Throw ("PxPyPzE4D::Mt() - Tachyonic:\n"
196 " Pz^2 > E^2 so the transverse mass would be imaginary");
197 using std::sqrt;
198 return -sqrt(-mm);
199 }
200 }
201
202 /**
203 transverse energy squared
204 */
205 Scalar Et2() const { // is (E^2 * pt ^2) / p^2
206 // but it is faster to form p^2 from pt^2
207 Scalar pt2 = Pt2();
208 return pt2 == 0 ? 0 : fT*fT * pt2/( pt2 + fZ*fZ );
209 }
210
211 /**
212 transverse energy
213 */
214 Scalar Et() const {
215 const Scalar etet = Et2();
216 using std::sqrt;
217 return fT < 0.0 ? -sqrt(etet) : sqrt(etet);
218 }
219
220 /**
221 azimuthal angle
222 */
223 Scalar Phi() const { using std::atan2; return (fX == 0.0 && fY == 0.0) ? 0 : atan2(fY, fX); }
224
225 /**
226 polar angle
227 */
228 Scalar Theta() const { using std::atan2; return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : atan2(Pt(), fZ); }
229
230 /**
231 pseudorapidity
232 */
233 Scalar Eta() const {
234 return Impl::Eta_FromRhoZ ( Pt(), fZ);
235 }
236
237 // --------- Set Coordinates of this system ---------------
238
239
240 /**
241 set X value
242 */
243 void SetPx( Scalar px) {
244 fX = px;
245 }
246 /**
247 set Y value
248 */
249 void SetPy( Scalar py) {
250 fY = py;
251 }
252 /**
253 set Z value
254 */
255 void SetPz( Scalar pz) {
256 fZ = pz;
257 }
258 /**
259 set T value
260 */
261 void SetE( Scalar e) {
262 fT = e;
263 }
264
265 /**
266 set all values using cartesian coordinates
267 */
268 void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e) {
269 fX=px;
270 fY=py;
271 fZ=pz;
272 fT=e;
273 }
274
275
276
277 // ------ Manipulations -------------
278
279 /**
280 negate the 4-vector
281 */
282 void Negate( ) { fX = -fX; fY = -fY; fZ = -fZ; fT = -fT;}
283
284 /**
285 scale coordinate values by a scalar quantity a
286 */
287 void Scale( const Scalar & a) {
288 fX *= a;
289 fY *= a;
290 fZ *= a;
291 fT *= a;
292 }
293
294 /**
295 Assignment from a generic coordinate system implementing
296 x(), y(), z() and t()
297 */
298 template <class AnyCoordSystem>
299 PxPyPzE4D & operator = (const AnyCoordSystem & v) {
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 {
311 return fX == rhs.fX && fY == rhs.fY && fZ == rhs.fZ && fT == rhs.fT;
312 }
313 bool operator != (const PxPyPzE4D & rhs) const {return !(operator==(rhs));}
314
315
316 // ============= Compatibility section ==================
317
318 // The following make this coordinate system look enough like a CLHEP
319 // vector that an assignment member template can work with either
320 Scalar x() const { return fX; }
321 Scalar y() const { return fY; }
322 Scalar z() const { return fZ; }
323 Scalar t() const { return fT; }
324
325
326
327#if defined(__MAKECINT__) || defined(G__DICTIONARY)
328
329 // ====== Set member functions for coordinates in other systems =======
330
331 void SetPt(Scalar pt);
332
333 void SetEta(Scalar eta);
334
335 void SetPhi(Scalar phi);
336
337 void SetM(Scalar m);
338
339#endif
340
341private:
342
343 /**
344 (contiguous) data containing the coordinate values x,y,z,t
345 */
346
347 ScalarType fX;
348 ScalarType fY;
349 ScalarType fZ;
350 ScalarType fT;
351
352};
353
354} // end namespace Math
355} // end namespace ROOT
356
357
358
359#if defined(__MAKECINT__) || defined(G__DICTIONARY)
360// move implementations here to avoid circle dependencies
361
364
365namespace ROOT {
366
367namespace Math {
368
369
370 // ====== Set member functions for coordinates in other systems =======
371 // throw always exceptions in this case
372
373template <class ScalarType>
374void PxPyPzE4D<ScalarType>::SetPt(Scalar pt) {
375 GenVector_exception e("PxPyPzE4D::SetPt() is not supposed to be called");
376 throw e;
377 PtEtaPhiE4D<Scalar> v(*this); v.SetPt(pt); *this = PxPyPzE4D<Scalar>(v);
378}
379template <class ScalarType>
380void PxPyPzE4D<ScalarType>::SetEta(Scalar eta) {
381 GenVector_exception e("PxPyPzE4D::SetEta() is not supposed to be called");
382 throw e;
383 PtEtaPhiE4D<Scalar> v(*this); v.SetEta(eta); *this = PxPyPzE4D<Scalar>(v);
384}
385template <class ScalarType>
386void PxPyPzE4D<ScalarType>::SetPhi(Scalar phi) {
387 GenVector_exception e("PxPyPzE4D::SetPhi() is not supposed to be called");
388 throw e;
389 PtEtaPhiE4D<Scalar> v(*this); v.SetPhi(phi); *this = PxPyPzE4D<Scalar>(v);
390}
391
392template <class ScalarType>
393void PxPyPzE4D<ScalarType>::SetM(Scalar m) {
394 GenVector_exception e("PxPyPzE4D::SetM() is not supposed to be called");
395 throw e;
396 PtEtaPhiM4D<Scalar> v(*this); v.SetM(m);
397 *this = PxPyPzE4D<Scalar>(v);
398}
399
400
401} // end namespace Math
402
403} // end namespace ROOT
404
405#endif // endif __MAKE__CINT || G__DICTIONARY
406
407
408#endif // ROOT_Math_GenVector_PxPyPzE4D
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
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:320
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 4 Scalar numbers
Definition PxPyPzE4D.h:102
Scalar Pz() const
Definition PxPyPzE4D.h:123
constexpr PxPyPzE4D(const CoordSystem &v)
construct from any vector or coordinate system class implementing x(), y() and z() and t()
Definition PxPyPzE4D.h:71
void GetCoordinates(Scalar &px, Scalar &py, Scalar &pz, Scalar &e) const
get internal data into 4 Scalar numbers
Definition PxPyPzE4D.h:114
ScalarType fX
(contiguous) data containing the coordinate values x,y,z,t
Definition PxPyPzE4D.h:347
PxPyPzE4D & operator=(const PxPyPzE4D &v)
assignment operator
Definition PxPyPzE4D.h:85
void SetCoordinates(Scalar px, Scalar py, Scalar pz, Scalar e)
Set internal data based on 4 Scalar numbers.
Definition PxPyPzE4D.h:108
Scalar Y() const
Definition PxPyPzE4D.h:127
bool operator==(const PxPyPzE4D &rhs) const
Exact equality.
Definition PxPyPzE4D.h:310
Scalar z() const
Definition PxPyPzE4D.h:322
Scalar Perp2() const
Definition PxPyPzE4D.h:172
Scalar E() const
Definition PxPyPzE4D.h:124
Scalar Mt() const
transverse mass
Definition PxPyPzE4D.h:189
Scalar Pt() const
Transverse spatial component (P_perp or rho)
Definition PxPyPzE4D.h:177
Scalar Perp() const
Definition PxPyPzE4D.h:178
PxPyPzE4D()
Default constructor with x=y=z=t=0.
Definition PxPyPzE4D.h:56
Scalar Px() const
Definition PxPyPzE4D.h:121
void SetPz(Scalar pz)
set Z value
Definition PxPyPzE4D.h:255
bool operator!=(const PxPyPzE4D &rhs) const
Definition PxPyPzE4D.h:313
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 4 Scalar numbers.
Definition PxPyPzE4D.h:96
void Scale(const Scalar &a)
scale coordinate values by a scalar quantity a
Definition PxPyPzE4D.h:287
void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e)
set all values using cartesian coordinates
Definition PxPyPzE4D.h:268
void SetPx(Scalar px)
set X value
Definition PxPyPzE4D.h:243
Scalar Eta() const
pseudorapidity
Definition PxPyPzE4D.h:233
Scalar Mag2() const
Definition PxPyPzE4D.h:148
void Negate()
negate the 4-vector
Definition PxPyPzE4D.h:282
Scalar Rho() const
Definition PxPyPzE4D.h:179
Scalar Mt2() const
transverse mass squared
Definition PxPyPzE4D.h:184
Scalar Z() const
Definition PxPyPzE4D.h:128
Scalar P2() const
squared magnitude of spatial components
Definition PxPyPzE4D.h:136
PxPyPzE4D(const PxPyPzE4D &v)
copy constructor
Definition PxPyPzE4D.h:79
Scalar X() const
Definition PxPyPzE4D.h:126
Scalar M() const
invariant mass
Definition PxPyPzE4D.h:153
Scalar Et() const
transverse energy
Definition PxPyPzE4D.h:214
Scalar Et2() const
transverse energy squared
Definition PxPyPzE4D.h:205
Scalar Pt2() const
transverse spatial component squared
Definition PxPyPzE4D.h:171
Scalar Phi() const
azimuthal angle
Definition PxPyPzE4D.h:223
Scalar Theta() const
polar angle
Definition PxPyPzE4D.h:228
Scalar Py() const
Definition PxPyPzE4D.h:122
Scalar P() const
magnitude of spatial components (magnitude of 3-momentum)
Definition PxPyPzE4D.h:141
static constexpr unsigned int Dimension
Definition PxPyPzE4D.h:49
Scalar R() const
Definition PxPyPzE4D.h:142
Scalar Mag() const
Definition PxPyPzE4D.h:166
void SetE(Scalar e)
set T value
Definition PxPyPzE4D.h:261
PxPyPzE4D(Scalar px, Scalar py, Scalar pz, Scalar e)
Constructor from x, y , z , t values.
Definition PxPyPzE4D.h:62
void SetPy(Scalar py)
set Y value
Definition PxPyPzE4D.h:249
Scalar y() const
Definition PxPyPzE4D.h:321
Scalar M2() const
vector magnitude squared (or mass squared)
Definition PxPyPzE4D.h:147
Scalar t() const
Definition PxPyPzE4D.h:323
Scalar T() const
Definition PxPyPzE4D.h:129
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