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