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 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 @sa Overview of the @ref GenVector "physics vector library"
51*/
52
53template <class ScalarType>
55
56public :
57
58 typedef ScalarType Scalar;
59
60 // --------- Constructors ---------------
61
62 /**
63 Default constructor gives zero 4-vector (with zero mass)
64 */
65 PtEtaPhiM4D() : fPt(0), fEta(0), fPhi(0), fM(0) { }
66
67 /**
68 Constructor from pt, eta, phi, mass values
69 */
71 fPt(pt), fEta(eta), fPhi(phi), fM(mass) {
73 if (fM < 0) RestrictNegMass();
74 }
75
76 /**
77 Generic constructor from any 4D coordinate system implementing
78 Pt(), Eta(), Phi() and M()
79 */
80 template <class CoordSystem >
81 explicit PtEtaPhiM4D(const CoordSystem & c) :
82 fPt(c.Pt()), fEta(c.Eta()), fPhi(c.Phi()), fM(c.M()) { RestrictPhi(); }
83
84 // for g++ 3.2 and 3.4 on 32 bits found that the compiler generated copy ctor and assignment are much slower
85 // so we decided to re-implement them ( there is no no need to have them with g++4)
86
87 /**
88 copy constructor
89 */
91 fPt(v.fPt), fEta(v.fEta), fPhi(v.fPhi), fM(v.fM) { }
92
93 /**
94 assignment operator
95 */
97 fPt = v.fPt;
98 fEta = v.fEta;
99 fPhi = v.fPhi;
100 fM = v.fM;
101 return *this;
102 }
103
104
105 /**
106 Set internal data based on an array of 4 Scalar numbers
107 */
108 void SetCoordinates( const Scalar src[] ) {
109 fPt=src[0]; fEta=src[1]; fPhi=src[2]; fM=src[3];
110 RestrictPhi();
111 if (fM <0) RestrictNegMass();
112 }
113
114 /**
115 get internal data into an array of 4 Scalar numbers
116 */
117 void GetCoordinates( Scalar dest[] ) const
118 { dest[0] = fPt; dest[1] = fEta; dest[2] = fPhi; dest[3] = fM; }
119
120 /**
121 Set internal data based on 4 Scalar numbers
122 */
123 void SetCoordinates(Scalar pt, Scalar eta, Scalar phi, Scalar mass) {
124 fPt=pt; fEta = eta; fPhi = phi; fM = mass;
125 RestrictPhi();
126 if (fM <0) RestrictNegMass();
127 }
128
129 /**
130 get internal data into 4 Scalar numbers
131 */
132 void
133 GetCoordinates(Scalar& pt, Scalar & eta, Scalar & phi, Scalar& mass) const
134 { pt=fPt; eta=fEta; phi = fPhi; mass = fM; }
135
136 // --------- Coordinates and Coordinate-like Scalar properties -------------
137
138 // 4-D Cylindrical eta coordinate accessors
139
140 Scalar Pt() const { return fPt; }
141 Scalar Eta() const { return fEta; }
142 Scalar Phi() const { return fPhi; }
143 /**
144 M() is the invariant mass;
145 in this coordinate system it can be negagative if set that way.
146 */
147 Scalar M() const { return fM; }
148 Scalar Mag() const { return M(); }
149
150 Scalar Perp()const { return Pt(); }
151 Scalar Rho() const { return Pt(); }
152
153 // other coordinate representation
154
155 Scalar Px() const { using std::cos; return fPt * cos(fPhi); }
156 Scalar X () const { return Px(); }
157 Scalar Py() const { using std::sin; return fPt * sin(fPhi); }
158 Scalar Y () const { return Py(); }
159 Scalar Pz() const {
160 using std::sinh;
161 return fPt > 0 ? fPt * sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax<Scalar>() : fEta + etaMax<Scalar>();
162 }
163 Scalar Z () const { return Pz(); }
164
165 /**
166 magnitude of momentum
167 */
168 Scalar P() const {
169 using std::cosh;
170 return fPt > 0 ? fPt * cosh(fEta)
171 : fEta > etaMax<Scalar>() ? fEta - etaMax<Scalar>()
172 : fEta < -etaMax<Scalar>() ? -fEta - etaMax<Scalar>() : 0;
173 }
174 Scalar R() const { return P(); }
175
176 /**
177 squared magnitude of spatial components (momentum squared)
178 */
179 Scalar P2() const
180 {
181 const Scalar p = P();
182 return p * p;
183 }
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 { using std::sqrt; return 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 const Scalar mm = Mt2();
226 if (mm >= 0) {
227 using std::sqrt;
228 return sqrt(mm);
229 } else {
230 GenVector::Throw ("PtEtaPhiM4D::Mt() - Tachyonic:\n"
231 " Pz^2 > E^2 so the transverse mass would be imaginary");
232 using std::sqrt;
233 return -sqrt(-mm);
234 }
235 }
236
237 /**
238 transverse energy squared
239 */
240 Scalar Et2() const {
241 // a bit faster than et * et
242 using std::cosh;
243 return 2. * E2() / (cosh(2 * fEta) + 1);
244 }
245
246 /**
247 transverse energy
248 */
249 Scalar Et() const { using std::cosh; return E() / cosh(fEta); }
250
251private:
252 inline static Scalar pi() { return M_PI; }
253 inline void RestrictPhi() {
254 using std::floor;
255 if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi();
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) {
261 if (P2() - fM * fM < 0) {
262 GenVector::Throw("PtEtaPhiM4D::unphysical value of mass, set to closest physical value");
263 fM = -P();
264 }
265 }
266 }
267
268public:
269
270 /**
271 polar angle
272 */
273 Scalar Theta() const { using std::atan; return (fPt > 0 ? Scalar(2) * atan(exp(-fEta)) : fEta >= 0 ? 0 : pi()); }
274
275 // --------- Set Coordinates of this system ---------------
276
277 /**
278 set Pt value
279 */
280 void SetPt( Scalar pt) {
281 fPt = pt;
282 }
283 /**
284 set eta value
285 */
286 void SetEta( Scalar eta) {
287 fEta = eta;
288 }
289 /**
290 set phi value
291 */
292 void SetPhi( Scalar phi) {
293 fPhi = phi;
294 RestrictPhi();
295 }
296 /**
297 set M value
298 */
299 void SetM( Scalar mass) {
300 fM = mass;
301 if (fM <0) RestrictNegMass();
302 }
303
304 /**
305 set values using cartesian coordinate system
306 */
307 void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e);
308
309
310 // ------ Manipulations -------------
311
312 /**
313 negate the 4-vector -- Note that the energy cannot be negate (would need an additional data member)
314 therefore negate will work only on the spatial components
315 One would need to use negate only with vectors having the energy as data members
316 */
317 void Negate( ) {
318 fPhi = ( (fPhi > 0) ? fPhi - pi() : fPhi + pi() );
319 fEta = - fEta;
320 GenVector::Throw ("PtEtaPhiM4D::Negate - cannot negate the energy - can negate only the spatial components");
321 }
322
323 /**
324 Scale coordinate values by a scalar quantity a
325 */
326 void Scale( Scalar a) {
327 if (a < 0) {
328 Negate(); a = -a;
329 }
330 fPt *= a;
331 fM *= a;
332 }
333
334 /**
335 Assignment from a generic coordinate system implementing
336 Pt(), Eta(), Phi() and M()
337 */
338 template <class CoordSystem >
339 PtEtaPhiM4D & operator = (const CoordSystem & c) {
340 fPt = c.Pt();
341 fEta = c.Eta();
342 fPhi = c.Phi();
343 fM = c.M();
344 return *this;
345 }
346
347 /**
348 Exact equality
349 */
350 bool operator == (const PtEtaPhiM4D & rhs) const {
351 return fPt == rhs.fPt && fEta == rhs.fEta
352 && fPhi == rhs.fPhi && fM == rhs.fM;
353 }
354 bool operator != (const PtEtaPhiM4D & rhs) const {return !(operator==(rhs));}
355
356 // ============= Compatibility section ==================
357
358 // The following make this coordinate system look enough like a CLHEP
359 // vector that an assignment member template can work with either
360 Scalar x() const { return X(); }
361 Scalar y() const { return Y(); }
362 Scalar z() const { return Z(); }
363 Scalar t() const { return E(); }
364
365
366#if defined(__MAKECINT__) || defined(G__DICTIONARY)
367
368 // ====== Set member functions for coordinates in other systems =======
369
370 void SetPx(Scalar px);
371
372 void SetPy(Scalar py);
373
374 void SetPz(Scalar pz);
375
376 void SetE(Scalar t);
377
378#endif
379
380private:
381
382 ScalarType fPt;
383 ScalarType fEta;
384 ScalarType fPhi;
385 ScalarType fM;
386
387};
388
389
390} // end namespace Math
391} // end namespace ROOT
392
393
394// move implementations here to avoid circle dependencies
396
397
398
399namespace ROOT {
400
401namespace Math {
402
403
404template <class ScalarType>
406 *this = PxPyPzE4D<Scalar> (px, py, pz, e);
407}
408
409
410#if defined(__MAKECINT__) || defined(G__DICTIONARY)
411
412 // ====== Set member functions for coordinates in other systems =======
413
414template <class ScalarType>
416 GenVector_exception e("PtEtaPhiM4D::SetPx() is not supposed to be called");
417 throw e;
418 PxPyPzE4D<Scalar> v(*this); v.SetPx(px); *this = PtEtaPhiM4D<Scalar>(v);
419}
420template <class ScalarType>
421void PtEtaPhiM4D<ScalarType>::SetPy(Scalar py) {
422 GenVector_exception e("PtEtaPhiM4D::SetPx() is not supposed to be called");
423 throw e;
424 PxPyPzE4D<Scalar> v(*this); v.SetPy(py); *this = PtEtaPhiM4D<Scalar>(v);
425}
426template <class ScalarType>
427void PtEtaPhiM4D<ScalarType>::SetPz(Scalar pz) {
428 GenVector_exception e("PtEtaPhiM4D::SetPx() is not supposed to be called");
429 throw e;
430 PxPyPzE4D<Scalar> v(*this); v.SetPz(pz); *this = PtEtaPhiM4D<Scalar>(v);
431}
432template <class ScalarType>
433void PtEtaPhiM4D<ScalarType>::SetE(Scalar energy) {
434 GenVector_exception e("PtEtaPhiM4D::SetE() is not supposed to be called");
435 throw e;
436 PxPyPzE4D<Scalar> v(*this); v.SetE(energy); *this = PtEtaPhiM4D<Scalar>(v);
437}
438
439#endif // endif __MAKE__CINT || G__DICTIONARY
440
441} // end namespace Math
442
443} // end namespace ROOT
444
445
446
447#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 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:90
PtEtaPhiM4D & operator=(const PtEtaPhiM4D &v)
assignment operator
Definition PtEtaPhiM4D.h:96
void SetPt(Scalar pt)
set Pt value
PtEtaPhiM4D()
Default constructor gives zero 4-vector (with zero mass)
Definition PtEtaPhiM4D.h:65
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.
PtEtaPhiM4D(const CoordSystem &c)
Generic constructor from any 4D coordinate system implementing Pt(), Eta(), Phi() and M()
Definition PtEtaPhiM4D.h:81
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.
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...
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:70
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.
#define dest(otri, vertexptr)
Definition triangle.c:1041