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