Logo ROOT  
Reference Guide
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 
28 namespace ROOT {
29 
30 namespace 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 
41 template <class ScalarType = double>
42 class PxPyPzE4D {
43 
44 public :
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  */
76  PxPyPzE4D(const PxPyPzE4D & v) :
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 { 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  return sqrt(mm);
155  } else {
156  GenVector::Throw ("PxPyPzE4D::M() - Tachyonic:\n"
157  " P^2 > E^2 so the mass would be imaginary");
158  return -sqrt(-mm);
159  }
160  }
161  Scalar Mag() const { return M(); }
162 
163  /**
164  transverse spatial component squared
165  */
166  Scalar Pt2() const { return fX*fX + fY*fY;}
167  Scalar Perp2() const { return Pt2();}
168 
169  /**
170  Transverse spatial component (P_perp or rho)
171  */
172  Scalar Pt() const { return sqrt(Perp2()); }
173  Scalar Perp() const { return Pt();}
174  Scalar Rho() const { return Pt();}
175 
176  /**
177  transverse mass squared
178  */
179  Scalar Mt2() const { return fT*fT - fZ*fZ; }
180 
181  /**
182  transverse mass
183  */
184  Scalar Mt() const {
185  const Scalar mm = Mt2();
186  if (mm >= 0) {
187  return sqrt(mm);
188  } else {
189  GenVector::Throw ("PxPyPzE4D::Mt() - Tachyonic:\n"
190  " Pz^2 > E^2 so the transverse mass would be imaginary");
191  return -sqrt(-mm);
192  }
193  }
194 
195  /**
196  transverse energy squared
197  */
198  Scalar Et2() const { // is (E^2 * pt ^2) / p^2
199  // but it is faster to form p^2 from pt^2
200  Scalar pt2 = Pt2();
201  return pt2 == 0 ? 0 : fT*fT * pt2/( pt2 + fZ*fZ );
202  }
203 
204  /**
205  transverse energy
206  */
207  Scalar Et() const {
208  const Scalar etet = Et2();
209  return fT < 0.0 ? -sqrt(etet) : sqrt(etet);
210  }
211 
212  /**
213  azimuthal angle
214  */
215  Scalar Phi() const { return (fX == 0.0 && fY == 0.0) ? 0 : atan2(fY, fX); }
216 
217  /**
218  polar angle
219  */
220  Scalar Theta() const { return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : atan2(Pt(), fZ); }
221 
222  /**
223  pseudorapidity
224  */
225  Scalar Eta() const {
226  return Impl::Eta_FromRhoZ ( Pt(), fZ);
227  }
228 
229  // --------- Set Coordinates of this system ---------------
230 
231 
232  /**
233  set X value
234  */
235  void SetPx( Scalar px) {
236  fX = px;
237  }
238  /**
239  set Y value
240  */
241  void SetPy( Scalar py) {
242  fY = py;
243  }
244  /**
245  set Z value
246  */
247  void SetPz( Scalar pz) {
248  fZ = pz;
249  }
250  /**
251  set T value
252  */
253  void SetE( Scalar e) {
254  fT = e;
255  }
256 
257  /**
258  set all values using cartesian coordinates
259  */
260  void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e) {
261  fX=px;
262  fY=py;
263  fZ=pz;
264  fT=e;
265  }
266 
267 
268 
269  // ------ Manipulations -------------
270 
271  /**
272  negate the 4-vector
273  */
274  void Negate( ) { fX = -fX; fY = -fY; fZ = -fZ; fT = -fT;}
275 
276  /**
277  scale coordinate values by a scalar quantity a
278  */
279  void Scale( const Scalar & a) {
280  fX *= a;
281  fY *= a;
282  fZ *= a;
283  fT *= a;
284  }
285 
286  /**
287  Assignment from a generic coordinate system implementing
288  x(), y(), z() and t()
289  */
290  template <class AnyCoordSystem>
291  PxPyPzE4D & operator = (const AnyCoordSystem & v) {
292  fX = v.x();
293  fY = v.y();
294  fZ = v.z();
295  fT = v.t();
296  return *this;
297  }
298 
299  /**
300  Exact equality
301  */
302  bool operator == (const PxPyPzE4D & rhs) const {
303  return fX == rhs.fX && fY == rhs.fY && fZ == rhs.fZ && fT == rhs.fT;
304  }
305  bool operator != (const PxPyPzE4D & rhs) const {return !(operator==(rhs));}
306 
307 
308  // ============= Compatibility section ==================
309 
310  // The following make this coordinate system look enough like a CLHEP
311  // vector that an assignment member template can work with either
312  Scalar x() const { return fX; }
313  Scalar y() const { return fY; }
314  Scalar z() const { return fZ; }
315  Scalar t() const { return fT; }
316 
317 
318 
319 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
320 
321  // ====== Set member functions for coordinates in other systems =======
322 
323  void SetPt(Scalar pt);
324 
325  void SetEta(Scalar eta);
326 
327  void SetPhi(Scalar phi);
328 
329  void SetM(Scalar m);
330 
331 #endif
332 
333 private:
334 
335  /**
336  (contigous) data containing the coordinate values x,y,z,t
337  */
338 
339  ScalarType fX;
340  ScalarType fY;
341  ScalarType fZ;
342  ScalarType fT;
343 
344 };
345 
346 } // end namespace Math
347 } // end namespace ROOT
348 
349 
350 
351 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
352 // move implementations here to avoid circle dependencies
353 
356 
357 namespace ROOT {
358 
359 namespace Math {
360 
361 
362  // ====== Set member functions for coordinates in other systems =======
363  // throw always exceptions in this case
364 
365 template <class ScalarType>
366 void PxPyPzE4D<ScalarType>::SetPt(Scalar pt) {
367  GenVector_exception e("PxPyPzE4D::SetPt() is not supposed to be called");
368  throw e;
369  PtEtaPhiE4D<Scalar> v(*this); v.SetPt(pt); *this = PxPyPzE4D<Scalar>(v);
370 }
371 template <class ScalarType>
372 void PxPyPzE4D<ScalarType>::SetEta(Scalar eta) {
373  GenVector_exception e("PxPyPzE4D::SetEta() is not supposed to be called");
374  throw e;
375  PtEtaPhiE4D<Scalar> v(*this); v.SetEta(eta); *this = PxPyPzE4D<Scalar>(v);
376 }
377 template <class ScalarType>
378 void PxPyPzE4D<ScalarType>::SetPhi(Scalar phi) {
379  GenVector_exception e("PxPyPzE4D::SetPhi() is not supposed to be called");
380  throw e;
381  PtEtaPhiE4D<Scalar> v(*this); v.SetPhi(phi); *this = PxPyPzE4D<Scalar>(v);
382 }
383 
384 template <class ScalarType>
385 void PxPyPzE4D<ScalarType>::SetM(Scalar m) {
386  GenVector_exception e("PxPyPzE4D::SetM() is not supposed to be called");
387  throw e;
388  PtEtaPhiM4D<Scalar> v(*this); v.SetM(m);
389  *this = PxPyPzE4D<Scalar>(v);
390 }
391 
392 
393 } // end namespace Math
394 
395 } // end namespace ROOT
396 
397 #endif // endif __MAKE__CINT || G__DICTIONARY
398 
399 
400 #endif // ROOT_Math_GenVector_PxPyPzE4D
m
auto * m
Definition: textangle.C:8
ROOT::Math::PxPyPzE4D::Pt
Scalar Pt() const
Transverse spatial component (P_perp or rho)
Definition: PxPyPzE4D.h:172
ROOT::Math::PxPyPzE4D::GetCoordinates
void GetCoordinates(Scalar &px, Scalar &py, Scalar &pz, Scalar &e) const
get internal data into 4 Scalar numbers
Definition: PxPyPzE4D.h:111
ROOT::Math::PxPyPzE4D::Px
Scalar Px() const
Definition: PxPyPzE4D.h:118
ROOT::Math::PxPyPzE4D::Et
Scalar Et() const
transverse energy
Definition: PxPyPzE4D.h:207
ROOT::Math::PxPyPzE4D::R
Scalar R() const
Definition: PxPyPzE4D.h:139
e
#define e(i)
Definition: RSha256.hxx:103
ROOT::Math::PxPyPzE4D::PxPyPzE4D
PxPyPzE4D(const CoordSystem &v)
construct from any vector or coordinate system class implementing x(), y() and z() and t()
Definition: PxPyPzE4D.h:68
dest
#define dest(otri, vertexptr)
Definition: triangle.c:1040
ROOT::Math::PxPyPzE4D::E
Scalar E() const
Definition: PxPyPzE4D.h:121
ROOT::Math::PxPyPzE4D::Negate
void Negate()
negate the 4-vector
Definition: PxPyPzE4D.h:274
ROOT::Math::PxPyPzE4D::SetPz
void SetPz(Scalar pz)
set Z value
Definition: PxPyPzE4D.h:247
ROOT::Math::PxPyPzE4D::SetPy
void SetPy(Scalar py)
set Y value
Definition: PxPyPzE4D.h:241
ROOT::Math::PxPyPzE4D::Mt2
Scalar Mt2() const
transverse mass squared
Definition: PxPyPzE4D.h:179
ROOT::Math::PxPyPzE4D::SetCoordinates
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 4 Scalar numbers.
Definition: PxPyPzE4D.h:93
ROOT::Math::PxPyPzE4D::operator!=
bool operator!=(const PxPyPzE4D &rhs) const
Definition: PxPyPzE4D.h:305
ROOT::Math::PxPyPzE4D::Pz
Scalar Pz() const
Definition: PxPyPzE4D.h:120
ROOT::Math::PxPyPzE4D::P2
Scalar P2() const
squared magnitude of spatial components
Definition: PxPyPzE4D.h:133
ROOT::Math::PxPyPzE4D::Py
Scalar Py() const
Definition: PxPyPzE4D.h:119
ROOT::Math::PxPyPzE4D::Pt2
Scalar Pt2() const
transverse spatial component squared
Definition: PxPyPzE4D.h:166
ROOT::Math::PxPyPzE4D::Mt
Scalar Mt() const
transverse mass
Definition: PxPyPzE4D.h:184
ROOT::Math::PxPyPzE4D::SetE
void SetE(Scalar e)
set T value
Definition: PxPyPzE4D.h:253
ROOT::Math::PxPyPzE4D::Theta
Scalar Theta() const
polar angle
Definition: PxPyPzE4D.h:220
ROOT::Math::Impl::Eta_FromRhoZ
Scalar Eta_FromRhoZ(Scalar rho, Scalar z)
Calculate eta given rho and zeta.
Definition: eta.h:48
v
@ v
Definition: rootcling_impl.cxx:3635
eta.h
ROOT::Math::PxPyPzE4D::z
Scalar z() const
Definition: PxPyPzE4D.h:314
ROOT::Math::PxPyPzE4D::Phi
Scalar Phi() const
azimuthal angle
Definition: PxPyPzE4D.h:215
ROOT::Math::PxPyPzE4D::fZ
ScalarType fZ
Definition: PxPyPzE4D.h:341
ROOT::Math::PxPyPzE4D::SetCoordinates
void SetCoordinates(Scalar px, Scalar py, Scalar pz, Scalar e)
Set internal data based on 4 Scalar numbers.
Definition: PxPyPzE4D.h:105
ROOT::Math::PxPyPzE4D::Mag2
Scalar Mag2() const
Definition: PxPyPzE4D.h:145
atan2
double atan2(double, double)
ROOT::Math::GenVector::Throw
void Throw(const char *)
function throwing exception, by creating internally a GenVector_exception only when needed
Definition: GenVector_exception.h:80
ROOT::Math::sqrt
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
Definition: UnaryOperators.h:281
ROOT::Math::PxPyPzE4D::Perp
Scalar Perp() const
Definition: PxPyPzE4D.h:173
ROOT::Math::PxPyPzE4D::P
Scalar P() const
magnitude of spatial components (magnitude of 3-momentum)
Definition: PxPyPzE4D.h:138
ROOT::Math::PxPyPzE4D::fX
ScalarType fX
(contigous) data containing the coordinate values x,y,z,t
Definition: PxPyPzE4D.h:339
a
auto * a
Definition: textangle.C:12
ROOT::Math::PxPyPzE4D::X
Scalar X() const
Definition: PxPyPzE4D.h:123
ROOT::Math::PxPyPzE4D::Rho
Scalar Rho() const
Definition: PxPyPzE4D.h:174
ROOT::Math::PxPyPzE4D::M2
Scalar M2() const
vector magnitude squared (or mass squared)
Definition: PxPyPzE4D.h:144
ROOT::Math::PxPyPzE4D::Perp2
Scalar Perp2() const
Definition: PxPyPzE4D.h:167
ROOT::Math::PxPyPzE4D::Z
Scalar Z() const
Definition: PxPyPzE4D.h:125
ROOT::Math::PxPyPzE4D::T
Scalar T() const
Definition: PxPyPzE4D.h:126
ROOT::Math::PxPyPzE4D::SetPx
void SetPx(Scalar px)
set X value
Definition: PxPyPzE4D.h:235
TGeant4Unit::mm
static constexpr double mm
Definition: TGeant4SystemOfUnits.h:108
ROOT::Math::PxPyPzE4D::fY
ScalarType fY
Definition: PxPyPzE4D.h:340
ROOT::Math::PxPyPzE4D::GetCoordinates
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 4 Scalar numbers
Definition: PxPyPzE4D.h:99
ROOT::Math::PxPyPzE4D::y
Scalar y() const
Definition: PxPyPzE4D.h:313
PtEtaPhiM4D.h
ROOT::Math::PxPyPzE4D::PxPyPzE4D
PxPyPzE4D()
Default constructor with x=y=z=t=0.
Definition: PxPyPzE4D.h:53
PtEtaPhiE4D.h
ROOT::Math::PxPyPzE4D::Scalar
ScalarType Scalar
Definition: PxPyPzE4D.h:46
ROOT::Math::PxPyPzE4D::Et2
Scalar Et2() const
transverse energy squared
Definition: PxPyPzE4D.h:198
GenVector_exception.h
ROOT::Math::PxPyPzE4D::x
Scalar x() const
Definition: PxPyPzE4D.h:312
ROOT::Math::Scalar
Rotation3D::Scalar Scalar
Definition: Rotation3DxAxial.cxx:69
ROOT::Math::PxPyPzE4D::PxPyPzE4D
PxPyPzE4D(Scalar px, Scalar py, Scalar pz, Scalar e)
Constructor from x, y , z , t values.
Definition: PxPyPzE4D.h:59
ROOT::Math::PxPyPzE4D::SetPxPyPzE
void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e)
set all values using cartesian coordinates
Definition: PxPyPzE4D.h:260
ROOT::Math::PxPyPzE4D::t
Scalar t() const
Definition: PxPyPzE4D.h:315
ROOT::Math::PxPyPzE4D::Eta
Scalar Eta() const
pseudorapidity
Definition: PxPyPzE4D.h:225
ROOT::Math::PxPyPzE4D::Mag
Scalar Mag() const
Definition: PxPyPzE4D.h:161
ROOT::Math::PxPyPzE4D::operator=
PxPyPzE4D & operator=(const PxPyPzE4D &v)
assignment operator
Definition: PxPyPzE4D.h:82
ROOT::Math::PxPyPzE4D::M
Scalar M() const
invariant mass
Definition: PxPyPzE4D.h:150
ROOT::Math::PxPyPzE4D::operator==
bool operator==(const PxPyPzE4D &rhs) const
Exact equality.
Definition: PxPyPzE4D.h:302
pt
TPaveText * pt
Definition: entrylist_figure1.C:7
ROOT::Math::PxPyPzE4D::fT
ScalarType fT
Definition: PxPyPzE4D.h:342
ROOT::Math::PxPyPzE4D::Y
Scalar Y() const
Definition: PxPyPzE4D.h:124
ROOT::Math::PxPyPzE4D::Scale
void Scale(const Scalar &a)
scale coordinate values by a scalar quantity a
Definition: PxPyPzE4D.h:279
ROOT
VSD Structures.
Definition: StringConv.hxx:21
Math
Namespace for new Math classes and functions.
ROOT::Math::PxPyPzE4D
Class describing a 4D cartesian coordinate system (x, y, z, t coordinates) or momentum-energy vectors...
Definition: PxPyPzE4D.h:42
ROOT::Math::PxPyPzE4D::PxPyPzE4D
PxPyPzE4D(const PxPyPzE4D &v)
copy constructor
Definition: PxPyPzE4D.h:76