Logo ROOT   6.08/07
Reference Guide
PxPyPzM4D.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id: 464c29f33a8bbd8462a3e15b7e4c30c6f5b74a30 $
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 PxPyPzM4D
12 //
13 // Created by: fischler at Wed Jul 20 2005
14 // (starting from PxPyPzM4D by moneta)
15 //
16 // Last update: $Id: 464c29f33a8bbd8462a3e15b7e4c30c6f5b74a30 $
17 //
18 #ifndef ROOT_Math_GenVector_PxPyPzM4D
19 #define ROOT_Math_GenVector_PxPyPzM4D 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 coordinate system
39  or momentum-energy vectors stored as (Px, Py, Pz, M).
40  This system is useful to describe ultra-relativistic particles
41  (like electrons at LHC) to avoid numerical errors evaluating the mass
42  when E >>> m
43  The metric used is (-,-,-,+)
44  Spacelike particles (M2 < 0) are described with negative mass values,
45  but in this case m2 must alwasy be less than P2 to preserve a positive value of E2
46 
47  @ingroup GenVector
48 */
49 
50 template <class ScalarType = double>
51 class PxPyPzM4D {
52 
53 public :
54 
55  typedef ScalarType Scalar;
56 
57  // --------- Constructors ---------------
58 
59  /**
60  Default constructor with x=y=z=m=0
61  */
62  PxPyPzM4D() : fX(0.0), fY(0.0), fZ(0.0), fM(0.0) { }
63 
64 
65  /**
66  Constructor from x, y , z , m values
67  */
68  PxPyPzM4D(Scalar px, Scalar py, Scalar pz, Scalar m) :
69  fX(px), fY(py), fZ(pz), fM(m) {
70 
71  if (fM < 0) RestrictNegMass();
72  }
73 
74  /**
75  construct from any 4D coordinate system class
76  implementing X(), Y(), X() and M()
77  */
78  template <class CoordSystem>
79  explicit PxPyPzM4D(const CoordSystem & v) :
80  fX( v.X() ), fY( v.Y() ), fZ( v.Z() ), fM( v.M() )
81  { }
82 
83  // for g++ 3.2 and 3.4 on 32 bits found that the compiler generated copy ctor and assignment are much slower
84  // so we decided to re-implement them ( there is no no need to have them with g++4)
85  /**
86  copy constructor
87  */
88  PxPyPzM4D(const PxPyPzM4D & v) :
89  fX(v.fX), fY(v.fY), fZ(v.fZ), fM(v.fM) { }
90 
91  /**
92  assignment operator
93  */
95  fX = v.fX;
96  fY = v.fY;
97  fZ = v.fZ;
98  fM = v.fM;
99  return *this;
100  }
101 
102 
103  /**
104  construct from any 4D coordinate system class
105  implementing X(), Y(), X() and M()
106  */
107  template <class AnyCoordSystem>
108  PxPyPzM4D & operator = (const AnyCoordSystem & v) {
109  fX = v.X();
110  fY = v.Y();
111  fZ = v.Z();
112  fM = v.M();
113  return *this;
114  }
115 
116  /**
117  Set internal data based on an array of 4 Scalar numbers
118  */
119  void SetCoordinates( const Scalar src[] ) {
120  fX=src[0]; fY=src[1]; fZ=src[2]; fM=src[3];
121  if (fM < 0) RestrictNegMass();
122  }
123 
124  /**
125  get internal data into an array of 4 Scalar numbers
126  */
127  void GetCoordinates( Scalar dest[] ) const
128  { dest[0] = fX; dest[1] = fY; dest[2] = fZ; dest[3] = fM; }
129 
130  /**
131  Set internal data based on 4 Scalar numbers
132  */
133  void SetCoordinates(Scalar px, Scalar py, Scalar pz, Scalar m) {
134  fX=px; fY=py; fZ=pz; fM=m;
135  if (fM < 0) RestrictNegMass();
136  }
137 
138  /**
139  get internal data into 4 Scalar numbers
140  */
141  void GetCoordinates(Scalar& px, Scalar& py, Scalar& pz, Scalar& m) const
142  { px=fX; py=fY; pz=fZ; m=fM;}
143 
144  // --------- Coordinates and Coordinate-like Scalar properties -------------
145 
146  // cartesian (Minkowski)coordinate accessors
147 
148  Scalar Px() const { return fX;}
149  Scalar Py() const { return fY;}
150  Scalar Pz() const { return fZ;}
151  Scalar M() const { return fM; }
152 
153  Scalar X() const { return fX;}
154  Scalar Y() const { return fY;}
155  Scalar Z() const { return fZ;}
156 
157  // other coordinate representation
158  /**
159  Energy
160  */
161  Scalar E() const { return std::sqrt(E2() ); }
162 
163  Scalar T() const { return E();}
164 
165  /**
166  squared magnitude of spatial components
167  */
168  Scalar P2() const { return fX*fX + fY*fY + fZ*fZ; }
169 
170  /**
171  magnitude of spatial components (magnitude of 3-momentum)
172  */
173  Scalar P() const { return std::sqrt(P2()); }
174  Scalar R() const { return P(); }
175 
176  /**
177  vector magnitude squared (or mass squared)
178  In case of negative mass (spacelike particles return negative values)
179  */
180  Scalar M2() const {
181  return ( fM >= 0 ) ? fM*fM : -fM*fM;
182  }
183  Scalar Mag2() const { return M2(); }
184 
185  Scalar Mag() const { return M(); }
186 
187  /**
188  energy squared
189  */
190  Scalar E2() const {
191  Scalar e2 = P2() + M2();
192  // protect against numerical errors when M2() is negative
193  return e2 > 0 ? e2 : 0;
194  }
195 
196  /**
197  transverse spatial component squared
198  */
199  Scalar Pt2() const { return fX*fX + fY*fY;}
200  Scalar Perp2() const { return Pt2();}
201 
202  /**
203  Transverse spatial component (P_perp or rho)
204  */
205  Scalar Pt() const { return std::sqrt(Perp2());}
206  Scalar Perp() const { return Pt();}
207  Scalar Rho() const { return Pt();}
208 
209  /**
210  transverse mass squared
211  */
212  Scalar Mt2() const { return E2() - fZ*fZ; }
213 
214  /**
215  transverse mass
216  */
217  Scalar Mt() const {
218  Scalar mm = Mt2();
219  if (mm >= 0) {
220  return std::sqrt(mm);
221  } else {
222  GenVector::Throw ("PxPyPzM4D::Mt() - Tachyonic:\n"
223  " Pz^2 > E^2 so the transverse mass would be imaginary");
224  return -std::sqrt(-mm);
225  }
226  }
227 
228  /**
229  transverse energy squared
230  */
231  Scalar Et2() const { // is (E^2 * pt ^2) / p^2
232  // but it is faster to form p^2 from pt^2
233  Scalar pt2 = Pt2();
234  return pt2 == 0 ? 0 : E2() * pt2/( pt2 + fZ*fZ );
235  }
236 
237  /**
238  transverse energy
239  */
240  Scalar Et() const {
241  Scalar etet = Et2();
242  return std::sqrt(etet);
243  }
244 
245  /**
246  azimuthal angle
247  */
248  Scalar Phi() const {
249  return (fX == 0.0 && fY == 0.0) ? 0.0 : std::atan2(fY,fX);
250  }
251 
252  /**
253  polar angle
254  */
255  Scalar Theta() const {
256  return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : std::atan2(Pt(),fZ);
257  }
258 
259  /**
260  pseudorapidity
261  */
262  Scalar Eta() const {
263  return Impl::Eta_FromRhoZ ( Pt(), fZ);
264  }
265 
266  // --------- Set Coordinates of this system ---------------
267 
268 
269  /**
270  set X value
271  */
272  void SetPx( Scalar px) {
273  fX = px;
274  }
275  /**
276  set Y value
277  */
278  void SetPy( Scalar py) {
279  fY = py;
280  }
281  /**
282  set Z value
283  */
284  void SetPz( Scalar pz) {
285  fZ = pz;
286  }
287  /**
288  set T value
289  */
290  void SetM( Scalar m) {
291  fM = m;
292  if (fM < 0) RestrictNegMass();
293  }
294 
295  /**
296  set all values
297  */
298  void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e);
299 
300  // ------ Manipulations -------------
301 
302  /**
303  negate the 4-vector - Note that the energy cannot be negate (would need an additional data member)
304  therefore negate will work only on the spatial components.
305  One would need to use negate only with vectors having the energy as data members
306  */
307  void Negate( ) {
308  fX = -fX;
309  fY = -fY;
310  fZ = -fZ;
311  GenVector::Throw ("PxPyPzM4D::Negate - cannot negate the energy - can negate only the spatial components");
312  }
313 
314  /**
315  scale coordinate values by a scalar quantity a
316  */
317  void Scale( const Scalar & a) {
318  fX *= a;
319  fY *= a;
320  fZ *= a;
321  fM *= a;
322  }
323 
324 
325  /**
326  Exact equality
327  */
328  bool operator == (const PxPyPzM4D & rhs) const {
329  return fX == rhs.fX && fY == rhs.fY && fZ == rhs.fZ && fM == rhs.fM;
330  }
331  bool operator != (const PxPyPzM4D & rhs) const {return !(operator==(rhs));}
332 
333 
334  // ============= Compatibility section ==================
335 
336  // The following make this coordinate system look enough like a CLHEP
337  // vector that an assignment member template can work with either
338  Scalar x() const { return X(); }
339  Scalar y() const { return Y(); }
340  Scalar z() const { return Z(); }
341  Scalar t() const { return E(); }
342 
343 
344 
345 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
346 
347  // ====== Set member functions for coordinates in other systems =======
348 
349  void SetPt(Scalar pt);
350 
351  void SetEta(Scalar eta);
352 
353  void SetPhi(Scalar phi);
354 
355  void SetE(Scalar t);
356 
357 #endif
358 
359 private:
360 
361  // restrict the value of negative mass to avoid unphysical negative E2 values
362  // M2 must be less than P2 for the tachionic particles - otherwise use positive values
363  inline void RestrictNegMass() {
364  if ( fM >=0 ) return;
365  if ( P2() - fM*fM < 0 ) {
366  GenVector::Throw("PxPyPzM4D::unphysical value of mass, set to closest physical value");
367  fM = - P();
368  }
369  return;
370  }
371 
372 
373  /**
374  (contigous) data containing the coordinate values x,y,z,t
375  */
376 
377  ScalarType fX;
378  ScalarType fY;
379  ScalarType fZ;
380  ScalarType fM;
381 
382 };
383 
384 } // end namespace Math
385 } // end namespace ROOT
386 
387 
388 // move implementations here to avoid circle dependencies
389 
390 #ifndef ROOT_Math_GenVector_PxPyPzE4D
392 #endif
393 #ifndef ROOT_Math_GenVector_PtEtaPhiM4D
395 #endif
396 
397 namespace ROOT {
398 
399 namespace Math {
400 
401 template <class ScalarType>
403  *this = PxPyPzE4D<Scalar> (px, py, pz, e);
404 }
405 
406 
407 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
408 
409  // ====== Set member functions for coordinates in other systems =======
410 
411  // ====== Set member functions for coordinates in other systems =======
412 
413 template <class ScalarType>
414 inline void PxPyPzM4D<ScalarType>::SetPt(ScalarType pt) {
415  GenVector_exception e("PxPyPzM4D::SetPt() is not supposed to be called");
416  throw e;
417  PtEtaPhiE4D<ScalarType> v(*this); v.SetPt(pt); *this = PxPyPzM4D<ScalarType>(v);
418 }
419 template <class ScalarType>
420 inline void PxPyPzM4D<ScalarType>::SetEta(ScalarType eta) {
421  GenVector_exception e("PxPyPzM4D::SetEta() is not supposed to be called");
422  throw e;
423  PtEtaPhiE4D<ScalarType> v(*this); v.SetEta(eta); *this = PxPyPzM4D<ScalarType>(v);
424 }
425 template <class ScalarType>
426 inline void PxPyPzM4D<ScalarType>::SetPhi(ScalarType phi) {
427  GenVector_exception e("PxPyPzM4D::SetPhi() is not supposed to be called");
428  throw e;
429  PtEtaPhiE4D<ScalarType> v(*this); v.SetPhi(phi); *this = PxPyPzM4D<ScalarType>(v);
430 }
431 template <class ScalarType>
432 inline void PxPyPzM4D<ScalarType>::SetE(ScalarType energy) {
433  GenVector_exception e("PxPyPzM4D::SetE() is not supposed to be called");
434  throw e;
435  PxPyPzE4D<ScalarType> v(*this); v.SetE(energy);
436  *this = PxPyPzM4D<ScalarType>(v);
437 }
438 
439 
440 #endif // endif __MAKE__CINT || G__DICTIONARY
441 
442 } // end namespace Math
443 
444 } // end namespace ROOT
445 
446 
447 
448 #endif // ROOT_Math_GenVector_PxPyPzM4D
Class describing a 4D cylindrical coordinate system using Pt , Phi, Eta and E (or rho...
Definition: PtEtaPhiE4D.h:58
void SetPhi(Scalar phi)
set phi value
Definition: PtEtaPhiE4D.h:271
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 4 Scalar numbers
Definition: PxPyPzM4D.h:127
Scalar Theta() const
polar angle
Definition: PxPyPzM4D.h:255
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
void GetCoordinates(Scalar &px, Scalar &py, Scalar &pz, Scalar &m) const
get internal data into 4 Scalar numbers
Definition: PxPyPzM4D.h:141
Scalar Px() const
Definition: PxPyPzM4D.h:148
Scalar z() const
Definition: PxPyPzM4D.h:340
Scalar Mt2() const
transverse mass squared
Definition: PxPyPzM4D.h:212
void Scale(const Scalar &a)
scale coordinate values by a scalar quantity a
Definition: PxPyPzM4D.h:317
Scalar Mt() const
transverse mass
Definition: PxPyPzM4D.h:217
TArc * a
Definition: textangle.C:12
void Negate()
negate the 4-vector - Note that the energy cannot be negate (would need an additional data member) th...
Definition: PxPyPzM4D.h:307
PxPyPzM4D(const CoordSystem &v)
construct from any 4D coordinate system class implementing X(), Y(), X() and M()
Definition: PxPyPzM4D.h:79
void SetPy(Scalar py)
set Y value
Definition: PxPyPzM4D.h:278
Scalar Rho() const
Definition: PxPyPzM4D.h:207
void SetM(Scalar m)
set T value
Definition: PxPyPzM4D.h:290
Scalar Y() const
Definition: PxPyPzM4D.h:154
Scalar Pz() const
Definition: PxPyPzM4D.h:150
Scalar T() const
Definition: PxPyPzM4D.h:163
double sqrt(double)
Class describing a 4D cartesian coordinate system (x, y, z, t coordinates) or momentum-energy vectors...
Definition: PxPyPzE4D.h:46
Class describing a 4D coordinate system or momentum-energy vectors stored as (Px, Py...
Definition: PxPyPzM4D.h:51
ScalarType fX
(contigous) data containing the coordinate values x,y,z,t
Definition: PxPyPzM4D.h:377
Scalar E() const
Energy.
Definition: PxPyPzM4D.h:161
Scalar x() const
Definition: PxPyPzM4D.h:338
Scalar Et() const
transverse energy
Definition: PxPyPzM4D.h:240
Scalar M2() const
vector magnitude squared (or mass squared) In case of negative mass (spacelike particles return negat...
Definition: PxPyPzM4D.h:180
bool operator==(const PxPyPzM4D &rhs) const
Exact equality.
Definition: PxPyPzM4D.h:328
PxPyPzM4D()
Default constructor with x=y=z=m=0.
Definition: PxPyPzM4D.h:62
Scalar Eta() const
pseudorapidity
Definition: PxPyPzM4D.h:262
Scalar E2() const
energy squared
Definition: PxPyPzM4D.h:190
bool operator!=(const PxPyPzM4D &rhs) const
Definition: PxPyPzM4D.h:331
Scalar t() const
Definition: PxPyPzM4D.h:341
PxPyPzM4D(const PxPyPzM4D &v)
copy constructor
Definition: PxPyPzM4D.h:88
Scalar Pt2() const
transverse spatial component squared
Definition: PxPyPzM4D.h:199
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 4 Scalar numbers.
Definition: PxPyPzM4D.h:119
void SetPt(Scalar pt)
set Pt value
Definition: PtEtaPhiE4D.h:259
TPaveText * pt
Scalar Et2() const
transverse energy squared
Definition: PxPyPzM4D.h:231
void Throw(const char *)
function throwing exception, by creating internally a GenVector_exception only when needed ...
SVector< double, 2 > v
Definition: Dict.h:5
Scalar y() const
Definition: PxPyPzM4D.h:339
Scalar P() const
magnitude of spatial components (magnitude of 3-momentum)
Definition: PxPyPzM4D.h:173
void SetEta(Scalar eta)
set eta value
Definition: PtEtaPhiE4D.h:265
TMarker * m
Definition: textangle.C:8
Scalar Phi() const
azimuthal angle
Definition: PxPyPzM4D.h:248
Scalar Py() const
Definition: PxPyPzM4D.h:149
Scalar Eta_FromRhoZ(Scalar rho, Scalar z)
Calculate eta given rho and zeta.
Definition: eta.h:50
void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e)
set all values
Definition: PxPyPzM4D.h:402
Scalar P2() const
squared magnitude of spatial components
Definition: PxPyPzM4D.h:168
Scalar R() const
Definition: PxPyPzM4D.h:174
Scalar Perp() const
Definition: PxPyPzM4D.h:206
double atan2(double, double)
ScalarType Scalar
Definition: PxPyPzM4D.h:55
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
Namespace for new Math classes and functions.
Scalar Pt() const
Transverse spatial component (P_perp or rho)
Definition: PxPyPzM4D.h:205
Scalar Perp2() const
Definition: PxPyPzM4D.h:200
void SetCoordinates(Scalar px, Scalar py, Scalar pz, Scalar m)
Set internal data based on 4 Scalar numbers.
Definition: PxPyPzM4D.h:133
Scalar X() const
Definition: PxPyPzM4D.h:153
PxPyPzM4D & operator=(const PxPyPzM4D &v)
assignment operator
Definition: PxPyPzM4D.h:94
#define dest(otri, vertexptr)
Definition: triangle.c:1040
void SetPz(Scalar pz)
set Z value
Definition: PxPyPzM4D.h:284
Scalar Mag2() const
Definition: PxPyPzM4D.h:183
void SetPx(Scalar px)
set X value
Definition: PxPyPzM4D.h:272
Scalar M() const
Definition: PxPyPzM4D.h:151
PxPyPzM4D(Scalar px, Scalar py, Scalar pz, Scalar m)
Constructor from x, y , z , m values.
Definition: PxPyPzM4D.h:68
Scalar Z() const
Definition: PxPyPzM4D.h:155
void SetE(Scalar e)
set T value
Definition: PxPyPzE4D.h:260
Scalar Mag() const
Definition: PxPyPzM4D.h:185