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