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