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_MathX_GenVectorX_PtEtaPhiE4D
20#define ROOT_MathX_GenVectorX_PtEtaPhiE4D 1
21
22#include "Math/Math.h"
23
25
27
29
31
32using namespace ROOT::ROOT_MATH_ARCH;
33
34// #define TRACE_CE
35#ifdef TRACE_CE
36#include <iostream>
37#endif
38
39#include <cmath>
40
41namespace ROOT {
42
43namespace ROOT_MATH_ARCH {
44
45//__________________________________________________________________________________________
46/**
47 Class describing a 4D cylindrical coordinate system
48 using Pt , Phi, Eta and E (or rho, phi, eta , T)
49 The metric used is (-,-,-,+).
50 Phi is restricted to be in the range [-PI,PI)
51
52 @ingroup GenVectorX
53
54 @see GenVectorX
55*/
56
57template <class ScalarType>
59
60public:
61 typedef ScalarType Scalar;
62
63 // --------- Constructors ---------------
64
65 /**
66 Default constructor gives zero 4-vector
67 */
69
70 /**
71 Constructor from pt, eta, phi, e values
72 */
74 {
75 Restrict();
76 }
77
78 /**
79 Generic constructor from any 4D coordinate system implementing
80 Pt(), Eta(), Phi() and E()
81 */
82 template <class CoordSystem>
83 explicit PtEtaPhiE4D(const CoordSystem &c) : fPt(c.Pt()), fEta(c.Eta()), fPhi(c.Phi()), fE(c.E())
84 {
85 }
86
87 /**
88 Set internal data based on an array of 4 Scalar numbers
89 */
91 {
92 fPt = src[0];
93 fEta = src[1];
94 fPhi = src[2];
95 fE = src[3];
96 Restrict();
97 }
98
99 /**
100 get internal data into an array of 4 Scalar numbers
101 */
103 {
104 dest[0] = fPt;
105 dest[1] = fEta;
106 dest[2] = fPhi;
107 dest[3] = fE;
108 }
109
110 /**
111 Set internal data based on 4 Scalar numbers
112 */
114 {
115 fPt = pt;
116 fEta = eta;
117 fPhi = phi;
118 fE = e;
119 Restrict();
120 }
121
122 /**
123 get internal data into 4 Scalar numbers
124 */
125 void GetCoordinates(Scalar &pt, Scalar &eta, Scalar &phi, Scalar &e) const
126 {
127 pt = fPt;
128 eta = fEta;
129 phi = fPhi;
130 e = fE;
131 }
132
133 // --------- Coordinates and Coordinate-like Scalar properties -------------
134
135 // 4-D Cylindrical eta coordinate accessors
136
137 Scalar Pt() const { return fPt; }
138 Scalar Eta() const { return fEta; }
139 Scalar Phi() const { return fPhi; }
140 Scalar E() const { return fE; }
141
142 Scalar Perp() const { return Pt(); }
143 Scalar Rho() const { return Pt(); }
144 Scalar T() const { return E(); }
145
146 // other coordinate representation
147
148 Scalar Px() const { return fPt * math_cos(fPhi); }
149 Scalar X() const { return Px(); }
150 Scalar Py() const { return fPt * math_sin(fPhi); }
151 Scalar Y() const { return Py(); }
152 Scalar Pz() const
153 {
154 return fPt > 0 ? fPt * math_sinh(fEta)
155 : fEta == 0 ? 0
156 : fEta > 0 ? fEta - etaMax<Scalar>()
157 : fEta + etaMax<Scalar>();
158 }
159 Scalar Z() const { return Pz(); }
160
161 /**
162 magnitude of momentum
163 */
164 Scalar P() const
165 {
166 return fPt > 0 ? fPt * math_cosh(fEta)
169 : 0;
170 }
171 Scalar R() const { return P(); }
172
173 /**
174 squared magnitude of spatial components (momentum squared)
175 */
176 Scalar P2() const
177 {
178 const Scalar p = P();
179 return p * p;
180 }
181
182 /**
183 vector magnitude squared (or mass squared)
184 */
185 Scalar M2() const
186 {
187 const Scalar p = P();
188 return fE * fE - p * p;
189 }
190 Scalar Mag2() const { return M2(); }
191
192 /**
193 invariant mass
194 */
195 Scalar M() const
196 {
197 const Scalar mm = M2();
198 if (mm >= 0) {
199 return math_sqrt(mm);
200 } else {
201#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
202 GenVector_Throw("PtEtaPhiE4D::M() - Tachyonic:\n"
203 " Pt and Eta give P such that P^2 > E^2, so the mass would be imaginary");
204#endif
205 return -math_sqrt(-mm);
206 }
207 }
208 Scalar Mag() const { return M(); }
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
220 {
221 Scalar pz = Pz();
222 return fE * fE - pz * pz;
223 }
224
225 /**
226 transverse mass
227 */
228 Scalar Mt() const
229 {
230 const Scalar mm = Mt2();
231 if (mm >= 0) {
232 return math_sqrt(mm);
233 } else {
234#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
235 GenVector_Throw("PtEtaPhiE4D::Mt() - Tachyonic:\n"
236 " Pt and Eta give Pz such that Pz^2 > E^2, so the mass would be imaginary");
237#endif
238 return -math_sqrt(-mm);
239 }
240 }
241
242 /**
243 transverse energy
244 */
245 /**
246 transverse energy
247 */
248 Scalar Et() const
249 {
250 return fE / math_cosh(fEta); // faster using eta
251 }
252
253 /**
254 transverse energy squared
255 */
256 Scalar Et2() const
257 {
258 const Scalar et = Et();
259 return et * et;
260 }
261
262private:
263 inline static Scalar pi() { return M_PI; }
264 inline void Restrict()
265 {
266 if (fPhi <= -pi() || fPhi > pi())
267 fPhi = fPhi - math_floor(fPhi / (2 * pi()) + .5) * 2 * pi();
268 }
269
270public:
271 /**
272 polar angle
273 */
274 Scalar Theta() const { return (fPt > 0 ? Scalar(2) * math_atan(math_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) { fPt = pt; }
282 /**
283 set eta value
284 */
285 void SetEta(Scalar eta) { fEta = eta; }
286 /**
287 set phi value
288 */
289 void SetPhi(Scalar phi)
290 {
291 fPhi = phi;
292 Restrict();
293 }
294 /**
295 set E value
296 */
297 void SetE(Scalar e) { fE = e; }
298
299 /**
300 set values using cartesian coordinate system
301 */
302 void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e);
303
304 // ------ Manipulations -------------
305
306 /**
307 negate the 4-vector
308 */
309 void Negate()
310 {
311 fPhi = (fPhi > 0 ? fPhi - pi() : fPhi + pi());
312 fEta = -fEta;
313 fE = -fE;
314 }
315
316 /**
317 Scale coordinate values by a scalar quantity a
318 */
320 {
321 if (a < 0) {
322 Negate();
323 a = -a;
324 }
325 fPt *= a;
326 fE *= a;
327 }
328
329 /**
330 Assignment from a generic coordinate system implementing
331 Pt(), Eta(), Phi() and E()
332 */
333 template <class CoordSystem>
334 PtEtaPhiE4D &operator=(const CoordSystem &c)
335 {
336 fPt = c.Pt();
337 fEta = c.Eta();
338 fPhi = c.Phi();
339 fE = c.E();
340 return *this;
341 }
342
343 /**
344 Exact equality
345 */
346 bool operator==(const PtEtaPhiE4D &rhs) const
347 {
348 return fPt == rhs.fPt && fEta == rhs.fEta && fPhi == rhs.fPhi && fE == rhs.fE;
349 }
350 bool operator!=(const PtEtaPhiE4D &rhs) const { return !(operator==(rhs)); }
351
352 // ============= Compatibility section ==================
353
354 // The following make this coordinate system look enough like a CLHEP
355 // vector that an assignment member template can work with either
356 Scalar x() const { return X(); }
357 Scalar y() const { return Y(); }
358 Scalar z() const { return Z(); }
359 Scalar t() const { return E(); }
360
361#if defined(__MAKECINT__) || defined(G__DICTIONARY)
362
363 // ====== Set member functions for coordinates in other systems =======
364
365 void SetPx(Scalar px);
366
367 void SetPy(Scalar py);
368
369 void SetPz(Scalar pz);
370
371 void SetM(Scalar m);
372
373#endif
374
375private:
376 ScalarType fPt = 0.;
377 ScalarType fEta = 0.;
378 ScalarType fPhi = 0.;
379 ScalarType fE = 0.;
380};
381
382} // end namespace ROOT_MATH_ARCH
383} // end namespace ROOT
384
385// move implementations here to avoid circle dependencies
387#if defined(__MAKECINT__) || defined(G__DICTIONARY)
389#endif
390
391namespace ROOT {
392
393namespace ROOT_MATH_ARCH {
394
395template <class ScalarType>
397{
398 *this = PxPyPzE4D<Scalar>(px, py, pz, e);
399}
400
401#if defined(__MAKECINT__) || defined(G__DICTIONARY)
402#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
403
404// ====== Set member functions for coordinates in other systems =======
405
406template <class ScalarType>
408{
409 GenVector_exception e("PtEtaPhiE4D::SetPx() is not supposed to be called");
410 throw e;
411 PxPyPzE4D<Scalar> v(*this);
412 v.SetPx(px);
413 *this = PtEtaPhiE4D<Scalar>(v);
414}
415template <class ScalarType>
416inline void PtEtaPhiE4D<ScalarType>::SetPy(Scalar py)
417{
418 GenVector_exception e("PtEtaPhiE4D::SetPx() is not supposed to be called");
419 throw e;
420 PxPyPzE4D<Scalar> v(*this);
421 v.SetPy(py);
422 *this = PtEtaPhiE4D<Scalar>(v);
423}
424template <class ScalarType>
426{
427 GenVector_exception e("PtEtaPhiE4D::SetPx() is not supposed to be called");
428 throw e;
429 PxPyPzE4D<Scalar> v(*this);
430 v.SetPz(pz);
431 *this = PtEtaPhiE4D<Scalar>(v);
432}
433template <class ScalarType>
435{
436 GenVector_exception e("PtEtaPhiE4D::SetM() is not supposed to be called");
437 throw e;
438 PtEtaPhiM4D<Scalar> v(*this);
439 v.SetM(m);
440 *this = PtEtaPhiE4D<Scalar>(v);
441}
442
443#endif // endif __MAKE__CINT || G__DICTIONARY
444#endif
445
446} // end namespace ROOT_MATH_ARCH
447
448} // end namespace ROOT
449
450#endif // ROOT_MathX_GenVectorX_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:58
Scalar P() const
magnitude of momentum
void SetE(Scalar e)
set E value
Scalar Mt2() const
transverse mass squared
constexpr PtEtaPhiE4D() noexcept=default
Default constructor gives zero 4-vector.
PtEtaPhiE4D(const CoordSystem &c)
Generic constructor from any 4D coordinate system implementing Pt(), Eta(), Phi() and E()
Definition PtEtaPhiE4D.h:83
bool operator!=(const PtEtaPhiE4D &rhs) const
void Negate()
negate the 4-vector
Scalar Et() const
transverse energy
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 4 Scalar numbers.
Definition PtEtaPhiE4D.h:90
Scalar M() const
invariant mass
void SetCoordinates(Scalar pt, Scalar eta, Scalar phi, Scalar e)
Set internal data based on 4 Scalar numbers.
void GetCoordinates(Scalar &pt, Scalar &eta, Scalar &phi, Scalar &e) const
get internal data into 4 Scalar numbers
void SetEta(Scalar eta)
set eta value
PtEtaPhiE4D & operator=(const CoordSystem &c)
Assignment from a generic coordinate system implementing Pt(), Eta(), Phi() and E()
Scalar Et2() const
transverse energy squared
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 4 Scalar numbers
Scalar Theta() const
polar angle
void Scale(Scalar a)
Scale coordinate values by a scalar quantity a.
Scalar P2() const
squared magnitude of spatial components (momentum squared)
void SetPhi(Scalar phi)
set phi value
Scalar M2() const
vector magnitude squared (or mass squared)
void SetPt(Scalar pt)
set Pt value
Scalar Pt2() const
transverse spatial component squared
bool operator==(const PtEtaPhiE4D &rhs) const
Exact equality.
Scalar Mt() const
transverse mass
void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e)
set values using cartesian coordinate system
TPaveText * pt
Scalar math_floor(Scalar x)
Scalar math_cos(Scalar x)
Scalar math_atan(Scalar x)
void GenVector_Throw(const char *)
function throwing exception, by creating internally a GenVector_exception only when needed
Scalar math_sqrt(Scalar x)
Scalar math_sinh(Scalar x)
Scalar math_exp(Scalar x)
Scalar math_cosh(Scalar x)
Scalar math_sin(Scalar x)
TMarker m
Definition textangle.C:8