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