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