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