Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
PtEtaPhiM4D.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Authors: W. Brown, M. Fischler, L. Moneta 2005
3
4/**********************************************************************
5* *
6* Copyright (c) 2005 , LCG ROOT FNAL MathLib Team *
7* *
8* *
9**********************************************************************/
10
11// Header file for class PtEtaPhiM4D
12//
13// Created by: fischler at Wed Jul 21 2005
14// Successor to PtEtaPhiMSystem by moneta
15//
16// Last update: $Id$
17//
18#ifndef ROOT_Math_GenVector_PtEtaPhiM4D
19#define ROOT_Math_GenVector_PtEtaPhiM4D 1
20
21#include "Math/Math.h"
22#include "TMath.h"
23
25
27
28
29//#define TRACE_CE
30#ifdef TRACE_CE
31#include <iostream>
32#endif
33
34#include <cmath>
35
36namespace ROOT {
37
38namespace Math {
39
40//__________________________________________________________________________________________
41/**
42 Class describing a 4D cylindrical coordinate system
43 using Pt , Phi, Eta and M (mass)
44 The metric used is (-,-,-,+).
45 Spacelike particles (M2 < 0) are described with negative mass values,
46 but in this case m2 must always be less than P2 to preserve a positive value of E2
47 Phi is restricted to be in the range [-PI,PI)
48
49 @ingroup GenVector
50
51 @see GenVector
52*/
53
54template <class ScalarType>
56
57public :
58
59 typedef ScalarType Scalar;
60 static constexpr unsigned int Dimension = 4U;
61
62 // --------- Constructors ---------------
63
64 /**
65 Default constructor gives zero 4-vector (with zero mass)
66 */
67 PtEtaPhiM4D() : fPt(0), fEta(0), fPhi(0), fM(0) { }
68
69 /**
70 Constructor from pt, eta, phi, mass values
71 */
73 fPt(pt), fEta(eta), fPhi(phi), fM(mass) {
75 if (fM < 0) RestrictNegMass();
76 }
77
78 /**
79 Generic constructor from any 4D coordinate system implementing
80 Pt(), Eta(), Phi() and M()
81 */
82 template <class CoordSystem >
83 explicit constexpr PtEtaPhiM4D(const CoordSystem & c) :
84 fPt(c.Pt()), fEta(c.Eta()), fPhi(c.Phi()), fM(c.M()) { RestrictPhi(); }
85
86
87 /**
88 Set internal data based on an array of 4 Scalar numbers
89 */
90 void SetCoordinates( const Scalar src[] ) {
91 fPt=src[0]; fEta=src[1]; fPhi=src[2]; fM=src[3];
93 if (fM <0) RestrictNegMass();
94 }
95
96 /**
97 get internal data into an array of 4 Scalar numbers
98 */
99 void GetCoordinates( Scalar dest[] ) const
100 { dest[0] = fPt; dest[1] = fEta; dest[2] = fPhi; dest[3] = fM; }
101
102 /**
103 Set internal data based on 4 Scalar numbers
104 */
105 void SetCoordinates(Scalar pt, Scalar eta, Scalar phi, Scalar mass) {
106 fPt=pt; fEta = eta; fPhi = phi; fM = mass;
107 RestrictPhi();
108 if (fM <0) RestrictNegMass();
109 }
110
111 /**
112 get internal data into 4 Scalar numbers
113 */
114 void
115 GetCoordinates(Scalar& pt, Scalar & eta, Scalar & phi, Scalar& mass) const
116 { pt=fPt; eta=fEta; phi = fPhi; mass = fM; }
117
118 // --------- Coordinates and Coordinate-like Scalar properties -------------
119
120 // 4-D Cylindrical eta coordinate accessors
121
122 Scalar Pt() const { return fPt; }
123 Scalar Eta() const { return fEta; }
124 Scalar Phi() const { return fPhi; }
125 /**
126 M() is the invariant mass;
127 in this coordinate system it can be negagative if set that way.
128 */
129 Scalar M() const { return fM; }
130 Scalar Mag() const { return M(); }
131
132 Scalar Perp()const { return Pt(); }
133 Scalar Rho() const { return Pt(); }
134
135 // other coordinate representation
136
137 Scalar Px() const { using std::cos; return fPt * cos(fPhi); }
138 Scalar X () const { return Px(); }
139 Scalar Py() const { using std::sin; return fPt * sin(fPhi); }
140 Scalar Y () const { return Py(); }
141 Scalar Pz() const {
142 using std::sinh;
143 return fPt > 0 ? fPt * sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax<Scalar>() : fEta + etaMax<Scalar>();
144 }
145 Scalar Z () const { return Pz(); }
146
147 /**
148 magnitude of momentum
149 */
150 Scalar P() const {
151 using std::cosh;
152 return fPt > 0 ? fPt * cosh(fEta)
154 : fEta < -etaMax<Scalar>() ? -fEta - etaMax<Scalar>() : 0;
155 }
156 Scalar R() const { return P(); }
157
158 /**
159 squared magnitude of spatial components (momentum squared)
160 */
161 Scalar P2() const
162 {
163 const Scalar p = P();
164 return p * p;
165 }
166
167 /**
168 energy squared
169 */
170 Scalar E2() const {
171 Scalar e2 = P2() + M2();
172 // avoid rounding error which can make E2 negative when M2 is negative
173 return e2 > 0 ? e2 : 0;
174 }
175
176 /**
177 Energy (timelike component of momentum-energy 4-vector)
178 */
179 Scalar E() const { using std::sqrt; return sqrt(E2()); }
180
181 Scalar T() const { return E(); }
182
183 /**
184 vector magnitude squared (or mass squared)
185 In case of negative mass (spacelike particles return negative values)
186 */
187 Scalar M2() const {
188 return ( fM >= 0 ) ? fM*fM : -fM*fM;
189 }
190 Scalar Mag2() const { return M2(); }
191
192 /**
193 transverse spatial component squared
194 */
195 Scalar Pt2() const { return fPt*fPt;}
196 Scalar Perp2() const { return Pt2(); }
197
198 /**
199 transverse mass squared
200 */
201 Scalar Mt2() const { return M2() + fPt*fPt; }
202
203 /**
204 transverse mass - will be negative if Mt2() is negative
205 */
206 Scalar Mt() const {
207 const Scalar mm = Mt2();
208 if (mm >= 0) {
209 using std::sqrt;
210 return sqrt(mm);
211 } else {
212 GenVector::Throw ("PtEtaPhiM4D::Mt() - Tachyonic:\n"
213 " Pz^2 > E^2 so the transverse mass would be imaginary");
214 using std::sqrt;
215 return -sqrt(-mm);
216 }
217 }
218
219 /**
220 transverse energy squared
221 */
222 Scalar Et2() const {
223 // a bit faster than et * et
224 using std::cosh;
225 return 2. * E2() / (cosh(2 * fEta) + 1);
226 }
227
228 /**
229 transverse energy
230 */
231 Scalar Et() const { using std::cosh; return E() / cosh(fEta); }
232
233private:
234 inline static Scalar pi() { return TMath::Pi(); }
235 inline void RestrictPhi() {
236 using std::floor;
237 if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi();
238 }
239 // restrict the value of negative mass to avoid unphysical negative E2 values
240 // M2 must be less than P2 for the tachionic particles - otherwise use positive values
241 inline void RestrictNegMass() {
242 if (fM < 0) {
243 if (P2() - fM * fM < 0) {
244 GenVector::Throw("PtEtaPhiM4D::unphysical value of mass, set to closest physical value");
245 fM = -P();
246 }
247 }
248 }
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 RestrictPhi();
277 }
278 /**
279 set M value
280 */
281 void SetM( Scalar mass) {
282 fM = mass;
283 if (fM <0) RestrictNegMass();
284 }
285
286 /**
287 set values using cartesian coordinate system
288 */
289 void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e);
290
291
292 // ------ Manipulations -------------
293
294 /**
295 negate the 4-vector -- Note that the energy cannot be negate (would need an additional data member)
296 therefore negate will work only on the spatial components
297 One would need to use negate only with vectors having the energy as data members
298 */
299 void Negate( ) {
300 fPhi = ( (fPhi > 0) ? fPhi - pi() : fPhi + pi() );
301 fEta = - fEta;
302 GenVector::Throw ("PtEtaPhiM4D::Negate - cannot negate the energy - can negate only the spatial components");
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 fM *= a;
314 }
315
316 /**
317 Assignment from a generic coordinate system implementing
318 Pt(), Eta(), Phi() and M()
319 */
320 template <class CoordSystem >
321 PtEtaPhiM4D & operator = (const CoordSystem & c) {
322 fPt = c.Pt();
323 fEta = c.Eta();
324 fPhi = c.Phi();
325 fM = c.M();
326 return *this;
327 }
328
329 /**
330 Exact equality
331 */
332 bool operator == (const PtEtaPhiM4D & rhs) const {
333 return fPt == rhs.fPt && fEta == rhs.fEta
334 && fPhi == rhs.fPhi && fM == rhs.fM;
335 }
336 bool operator != (const PtEtaPhiM4D & 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#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 SetE(Scalar t);
359
360#endif
361
362private:
363
364 ScalarType fPt;
365 ScalarType fEta;
366 ScalarType fPhi;
367 ScalarType fM;
368
369};
370
371
372} // end namespace Math
373} // end namespace ROOT
374
375
376// move implementations here to avoid circle dependencies
378
379
380
381namespace ROOT {
382
383namespace Math {
384
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("PtEtaPhiM4D::SetPx() is not supposed to be called");
399 throw e;
400 PxPyPzE4D<Scalar> v(*this); v.SetPx(px); *this = PtEtaPhiM4D<Scalar>(v);
401}
402template <class ScalarType>
403void PtEtaPhiM4D<ScalarType>::SetPy(Scalar py) {
404 GenVector_exception e("PtEtaPhiM4D::SetPx() is not supposed to be called");
405 throw e;
406 PxPyPzE4D<Scalar> v(*this); v.SetPy(py); *this = PtEtaPhiM4D<Scalar>(v);
407}
408template <class ScalarType>
409void PtEtaPhiM4D<ScalarType>::SetPz(Scalar pz) {
410 GenVector_exception e("PtEtaPhiM4D::SetPx() is not supposed to be called");
411 throw e;
412 PxPyPzE4D<Scalar> v(*this); v.SetPz(pz); *this = PtEtaPhiM4D<Scalar>(v);
413}
414template <class ScalarType>
415void PtEtaPhiM4D<ScalarType>::SetE(Scalar energy) {
416 GenVector_exception e("PtEtaPhiM4D::SetE() is not supposed to be called");
417 throw e;
418 PxPyPzE4D<Scalar> v(*this); v.SetE(energy); *this = PtEtaPhiM4D<Scalar>(v);
419}
420
421#endif // endif __MAKE__CINT || G__DICTIONARY
422
423} // end namespace Math
424
425} // end namespace ROOT
426
427
428
429#endif // ROOT_Math_GenVector_PtEtaPhiM4D
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
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 M (mass) The metric used ...
Definition PtEtaPhiM4D.h:55
void GetCoordinates(Scalar &pt, Scalar &eta, Scalar &phi, Scalar &mass) const
get internal data into 4 Scalar numbers
void SetPt(Scalar pt)
set Pt value
PtEtaPhiM4D()
Default constructor gives zero 4-vector (with zero mass)
Definition PtEtaPhiM4D.h:67
void SetPhi(Scalar phi)
set phi value
void Negate()
negate the 4-vector – Note that the energy cannot be negate (would need an additional data member) th...
bool operator==(const PtEtaPhiM4D &rhs) const
Exact equality.
Scalar Et() const
transverse energy
Scalar P2() const
squared magnitude of spatial components (momentum squared)
PtEtaPhiM4D & operator=(const CoordSystem &c)
Assignment from a generic coordinate system implementing Pt(), Eta(), Phi() and M()
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 4 Scalar numbers
Definition PtEtaPhiM4D.h:99
Scalar E2() const
energy squared
void SetCoordinates(Scalar pt, Scalar eta, Scalar phi, Scalar mass)
Set internal data based on 4 Scalar numbers.
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 4 Scalar numbers.
Definition PtEtaPhiM4D.h:90
static constexpr unsigned int Dimension
Definition PtEtaPhiM4D.h:60
Scalar Mt() const
transverse mass - will be negative if Mt2() is negative
void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e)
set values using cartesian coordinate system
Scalar Et2() const
transverse energy squared
bool operator!=(const PtEtaPhiM4D &rhs) const
void SetM(Scalar mass)
set M value
Scalar M() const
M() is the invariant mass; in this coordinate system it can be negagative if set that way.
Scalar Pt2() const
transverse spatial component squared
Scalar M2() const
vector magnitude squared (or mass squared) In case of negative mass (spacelike particles return negat...
constexpr PtEtaPhiM4D(const CoordSystem &c)
Generic constructor from any 4D coordinate system implementing Pt(), Eta(), Phi() and M()
Definition PtEtaPhiM4D.h:83
Scalar Mt2() const
transverse mass squared
Scalar Theta() const
polar angle
PtEtaPhiM4D(Scalar pt, Scalar eta, Scalar phi, Scalar mass)
Constructor from pt, eta, phi, mass values.
Definition PtEtaPhiM4D.h:72
void Scale(Scalar a)
Scale coordinate values by a scalar quantity a.
Scalar P() const
magnitude of momentum
Scalar E() const
Energy (timelike component of momentum-energy 4-vector)
void SetEta(Scalar eta)
set eta 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...
constexpr Double_t Pi()
Definition TMath.h:38