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