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