ROOT  6.06/09
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 #ifndef ROOT_Math_GenVector_eta
22 #include "Math/GenVector/eta.h"
23 #endif
24 
25 #ifndef ROOT_Math_GenVector_GenVector_exception
27 #endif
28 
29 
30 #include <cmath>
31 
32 namespace ROOT {
33 
34 namespace Math {
35 
36 //__________________________________________________________________________________________
37 /**
38  Class describing a 4D cartesian coordinate system (x, y, z, t coordinates)
39  or momentum-energy vectors stored as (Px, Py, Pz, E).
40  The metric used is (-,-,-,+)
41 
42  @ingroup GenVector
43 */
44 
45 template <class ScalarType = double>
46 class PxPyPzE4D {
47 
48 public :
49 
50  typedef ScalarType Scalar;
51 
52  // --------- Constructors ---------------
53 
54  /**
55  Default constructor with x=y=z=t=0
56  */
57  PxPyPzE4D() : fX(0.0), fY(0.0), fZ(0.0), fT(0.0) { }
58 
59 
60  /**
61  Constructor from x, y , z , t values
62  */
63  PxPyPzE4D(Scalar px, Scalar py, Scalar pz, Scalar e) :
64  fX(px), fY(py), fZ(pz), fT(e) { }
65 
66 
67  /**
68  construct from any vector or coordinate system class
69  implementing x(), y() and z() and t()
70  */
71  template <class CoordSystem>
72  explicit PxPyPzE4D(const CoordSystem & v) :
73  fX( v.x() ), fY( v.y() ), fZ( v.z() ), fT( v.t() ) { }
74 
75  // for g++ 3.2 and 3.4 on 32 bits found that the compiler generated copy ctor and assignment are much slower
76  // so we decided to re-implement them ( there is no no need to have them with g++4)
77  /**
78  copy constructor
79  */
80  PxPyPzE4D(const PxPyPzE4D & v) :
81  fX(v.fX), fY(v.fY), fZ(v.fZ), fT(v.fT) { }
82 
83  /**
84  assignment operator
85  */
87  fX = v.fX;
88  fY = v.fY;
89  fZ = v.fZ;
90  fT = v.fT;
91  return *this;
92  }
93 
94  /**
95  Set internal data based on an array of 4 Scalar numbers
96  */
97  void SetCoordinates( const Scalar src[] )
98  { fX=src[0]; fY=src[1]; fZ=src[2]; fT=src[3]; }
99 
100  /**
101  get internal data into an array of 4 Scalar numbers
102  */
103  void GetCoordinates( Scalar dest[] ) const
104  { dest[0] = fX; dest[1] = fY; dest[2] = fZ; dest[3] = fT; }
105 
106  /**
107  Set internal data based on 4 Scalar numbers
108  */
109  void SetCoordinates(Scalar px, Scalar py, Scalar pz, Scalar e)
110  { fX=px; fY=py; fZ=pz; fT=e;}
111 
112  /**
113  get internal data into 4 Scalar numbers
114  */
115  void GetCoordinates(Scalar& px, Scalar& py, Scalar& pz, Scalar& e) const
116  { px=fX; py=fY; pz=fZ; e=fT;}
117 
118  // --------- Coordinates and Coordinate-like Scalar properties -------------
119 
120  // cartesian (Minkowski)coordinate accessors
121 
122  Scalar Px() const { return fX;}
123  Scalar Py() const { return fY;}
124  Scalar Pz() const { return fZ;}
125  Scalar E() const { return fT;}
126 
127  Scalar X() const { return fX;}
128  Scalar Y() const { return fY;}
129  Scalar Z() const { return fZ;}
130  Scalar T() const { return fT;}
131 
132  // other coordinate representation
133 
134  /**
135  squared magnitude of spatial components
136  */
137  Scalar P2() const { return fX*fX + fY*fY + fZ*fZ; }
138 
139  /**
140  magnitude of spatial components (magnitude of 3-momentum)
141  */
142  Scalar P() const { return std::sqrt(P2()); }
143  Scalar R() const { return P(); }
144 
145  /**
146  vector magnitude squared (or mass squared)
147  */
148  Scalar M2() const { return fT*fT - fX*fX - fY*fY - fZ*fZ;}
149  Scalar Mag2() const { return M2(); }
150 
151  /**
152  invariant mass
153  */
154  Scalar M() const {
155  Scalar mm = M2();
156  if (mm >= 0) {
157  return std::sqrt(mm);
158  } else {
159  GenVector::Throw ("PxPyPzE4D::M() - Tachyonic:\n"
160  " P^2 > E^2 so the mass would be imaginary");
161  return -std::sqrt(-mm);
162  }
163  }
164  Scalar Mag() const { return M(); }
165 
166  /**
167  transverse spatial component squared
168  */
169  Scalar Pt2() const { return fX*fX + fY*fY;}
170  Scalar Perp2() const { return Pt2();}
171 
172  /**
173  Transverse spatial component (P_perp or rho)
174  */
175  Scalar Pt() const { return std::sqrt(Perp2());}
176  Scalar Perp() const { return Pt();}
177  Scalar Rho() const { return Pt();}
178 
179  /**
180  transverse mass squared
181  */
182  Scalar Mt2() const { return fT*fT - fZ*fZ; }
183 
184  /**
185  transverse mass
186  */
187  Scalar Mt() const {
188  Scalar mm = Mt2();
189  if (mm >= 0) {
190  return std::sqrt(mm);
191  } else {
192  GenVector::Throw ("PxPyPzE4D::Mt() - Tachyonic:\n"
193  " Pz^2 > E^2 so the transverse mass would be imaginary");
194  return -std::sqrt(-mm);
195  }
196  }
197 
198  /**
199  transverse energy squared
200  */
201  Scalar Et2() const { // is (E^2 * pt ^2) / p^2
202  // but it is faster to form p^2 from pt^2
203  Scalar pt2 = Pt2();
204  return pt2 == 0 ? 0 : fT*fT * pt2/( pt2 + fZ*fZ );
205  }
206 
207  /**
208  transverse energy
209  */
210  Scalar Et() const {
211  Scalar etet = Et2();
212  return fT < 0.0 ? -std::sqrt(etet) : std::sqrt(etet);
213  }
214 
215  /**
216  azimuthal angle
217  */
218  Scalar Phi() const {
219  return (fX == 0.0 && fY == 0.0) ? 0 : std::atan2(fY,fX);
220  }
221 
222  /**
223  polar angle
224  */
225  Scalar Theta() const {
226  return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : std::atan2(Pt(),fZ);
227  }
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 
340 private:
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 
361 #ifndef ROOT_Math_GenVector_PtEtaPhiE4D
363 #endif
364 #ifndef ROOT_Math_GenVector_PtEtaPhiM4D
366 #endif
367 
368 namespace ROOT {
369 
370 namespace Math {
371 
372 
373  // ====== Set member functions for coordinates in other systems =======
374  // throw always exceptions in this case
375 
376 template <class ScalarType>
377 void PxPyPzE4D<ScalarType>::SetPt(Scalar pt) {
378  GenVector_exception e("PxPyPzE4D::SetPt() is not supposed to be called");
379  throw e;
380  PtEtaPhiE4D<Scalar> v(*this); v.SetPt(pt); *this = PxPyPzE4D<Scalar>(v);
381 }
382 template <class ScalarType>
383 void PxPyPzE4D<ScalarType>::SetEta(Scalar eta) {
384  GenVector_exception e("PxPyPzE4D::SetEta() is not supposed to be called");
385  throw e;
386  PtEtaPhiE4D<Scalar> v(*this); v.SetEta(eta); *this = PxPyPzE4D<Scalar>(v);
387 }
388 template <class ScalarType>
389 void PxPyPzE4D<ScalarType>::SetPhi(Scalar phi) {
390  GenVector_exception e("PxPyPzE4D::SetPhi() is not supposed to be called");
391  throw e;
392  PtEtaPhiE4D<Scalar> v(*this); v.SetPhi(phi); *this = PxPyPzE4D<Scalar>(v);
393 }
394 
395 template <class ScalarType>
396 void PxPyPzE4D<ScalarType>::SetM(Scalar m) {
397  GenVector_exception e("PxPyPzE4D::SetM() is not supposed to be called");
398  throw e;
399  PtEtaPhiM4D<Scalar> v(*this); v.SetM(m);
400  *this = PxPyPzE4D<Scalar>(v);
401 }
402 
403 
404 } // end namespace Math
405 
406 } // end namespace ROOT
407 
408 #endif // endif __MAKE__CINT || G__DICTIONARY
409 
410 
411 #endif // ROOT_Math_GenVector_PxPyPzE4D
void GetCoordinates(Scalar &px, Scalar &py, Scalar &pz, Scalar &e) const
get internal data into 4 Scalar numbers
Definition: PxPyPzE4D.h:115
PxPyPzE4D()
Default constructor with x=y=z=t=0.
Definition: PxPyPzE4D.h:57
Scalar X() const
Definition: PxPyPzE4D.h:127
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 4 Scalar numbers.
Definition: PxPyPzE4D.h:97
Scalar Pz() const
Definition: PxPyPzE4D.h:124
Scalar Mt() const
transverse mass
Definition: PxPyPzE4D.h:187
Scalar Eta() const
pseudorapidity
Definition: PxPyPzE4D.h:232
Scalar Mag2() const
Definition: PxPyPzE4D.h:149
ScalarType fX
(contigous) data containing the coordinate values x,y,z,t
Definition: PxPyPzE4D.h:346
Scalar Rho() const
Definition: PxPyPzE4D.h:177
TArc * a
Definition: textangle.C:12
PxPyPzE4D(const PxPyPzE4D &v)
copy constructor
Definition: PxPyPzE4D.h:80
void SetPx(Scalar px)
set X value
Definition: PxPyPzE4D.h:242
ScalarType Scalar
Definition: PxPyPzE4D.h:50
Scalar Z() const
Definition: PxPyPzE4D.h:129
Scalar R() const
Definition: PxPyPzE4D.h:143
Scalar T() const
Definition: PxPyPzE4D.h:130
double sqrt(double)
Class describing a 4D cartesian coordinate system (x, y, z, t coordinates) or momentum-energy vectors...
Definition: PxPyPzE4D.h:46
Scalar M2() const
vector magnitude squared (or mass squared)
Definition: PxPyPzE4D.h:148
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 4 Scalar numbers
Definition: PxPyPzE4D.h:103
void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e)
set all values using cartesian coordinates
Definition: PxPyPzE4D.h:267
Scalar P() const
magnitude of spatial components (magnitude of 3-momentum)
Definition: PxPyPzE4D.h:142
Scalar Pt2() const
transverse spatial component squared
Definition: PxPyPzE4D.h:169
Scalar M() const
invariant mass
Definition: PxPyPzE4D.h:154
Scalar Mt2() const
transverse mass squared
Definition: PxPyPzE4D.h:182
Scalar Perp2() const
Definition: PxPyPzE4D.h:170
PxPyPzE4D & operator=(const PxPyPzE4D &v)
assignment operator
Definition: PxPyPzE4D.h:86
PxPyPzE4D(const CoordSystem &v)
construct from any vector or coordinate system class implementing x(), y() and z() and t() ...
Definition: PxPyPzE4D.h:72
Scalar E() const
Definition: PxPyPzE4D.h:125
void Throw(const char *)
function throwing exception, by creating internally a GenVector_exception only when needed ...
SVector< double, 2 > v
Definition: Dict.h:5
void Scale(const Scalar &a)
scale coordinate values by a scalar quantity a
Definition: PxPyPzE4D.h:286
Scalar Phi() const
azimuthal angle
Definition: PxPyPzE4D.h:218
void SetPz(Scalar pz)
set Z value
Definition: PxPyPzE4D.h:254
void SetPy(Scalar py)
set Y value
Definition: PxPyPzE4D.h:248
Scalar y() const
Definition: PxPyPzE4D.h:320
TMarker * m
Definition: textangle.C:8
Scalar x() const
Definition: PxPyPzE4D.h:319
Scalar z() const
Definition: PxPyPzE4D.h:321
bool operator!=(const PxPyPzE4D &rhs) const
Definition: PxPyPzE4D.h:312
Scalar Pt() const
Transverse spatial component (P_perp or rho)
Definition: PxPyPzE4D.h:175
Scalar Eta_FromRhoZ(Scalar rho, Scalar z)
Calculate eta given rho and zeta.
Definition: eta.h:50
Scalar Perp() const
Definition: PxPyPzE4D.h:176
PxPyPzE4D(Scalar px, Scalar py, Scalar pz, Scalar e)
Constructor from x, y , z , t values.
Definition: PxPyPzE4D.h:63
bool operator==(const PxPyPzE4D &rhs) const
Exact equality.
Definition: PxPyPzE4D.h:309
double atan2(double, double)
void Negate()
negate the 4-vector
Definition: PxPyPzE4D.h:281
Scalar Y() const
Definition: PxPyPzE4D.h:128
Namespace for new Math classes and functions.
Scalar Py() const
Definition: PxPyPzE4D.h:123
Scalar Px() const
Definition: PxPyPzE4D.h:122
Scalar Theta() const
polar angle
Definition: PxPyPzE4D.h:225
Scalar Mag() const
Definition: PxPyPzE4D.h:164
#define dest(otri, vertexptr)
Definition: triangle.c:1040
Scalar Et() const
transverse energy
Definition: PxPyPzE4D.h:210
Scalar Et2() const
transverse energy squared
Definition: PxPyPzE4D.h:201
Scalar P2() const
squared magnitude of spatial components
Definition: PxPyPzE4D.h:137
Plane3D::Scalar Scalar
Definition: Plane3D.cxx:29
void SetCoordinates(Scalar px, Scalar py, Scalar pz, Scalar e)
Set internal data based on 4 Scalar numbers.
Definition: PxPyPzE4D.h:109
Scalar t() const
Definition: PxPyPzE4D.h:322
void SetE(Scalar e)
set T value
Definition: PxPyPzE4D.h:260