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