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