Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
PxPyPzM4D.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id: 464c29f33a8bbd8462a3e15b7e4c30c6f5b74a30 $
2// Authors: W. Brown, M. Fischler, L. Moneta 2005
3
4/**********************************************************************
5* *
6* Copyright (c) 2005 , LCG ROOT MathLib Team *
7* *
8* *
9**********************************************************************/
10
11// Header file for class PxPyPzM4D
12//
13// Created by: fischler at Wed Jul 20 2005
14// (starting from PxPyPzM4D by moneta)
15//
16// Last update: $Id: 464c29f33a8bbd8462a3e15b7e4c30c6f5b74a30 $
17//
18#ifndef ROOT_Math_GenVector_PxPyPzM4D
19#define ROOT_Math_GenVector_PxPyPzM4D 1
20
21#include "Math/GenVector/eta.h"
22
24
25
26#include <cmath>
27
28namespace ROOT {
29
30namespace Math {
31
32//__________________________________________________________________________________________
33/**
34 Class describing a 4D coordinate system
35 or momentum-energy vectors stored as (Px, Py, Pz, M).
36 This system is useful to describe ultra-relativistic particles
37 (like electrons at LHC) to avoid numerical errors evaluating the mass
38 when E >>> m
39 The metric used is (-,-,-,+)
40 Spacelike particles (M2 < 0) are described with negative mass values,
41 but in this case m2 must always be less than P2 to preserve a positive value of E2
42
43 @ingroup GenVector
44
45 @sa Overview of the @ref GenVector "physics vector library"
46*/
47
48template <class ScalarType = double>
49class PxPyPzM4D {
50
51public :
52
53 typedef ScalarType Scalar;
54 static constexpr unsigned int Dimension = 4U;
55
56 // --------- Constructors ---------------
57
58 /**
59 Default constructor with x=y=z=m=0
60 */
61 PxPyPzM4D() : fX(0.0), fY(0.0), fZ(0.0), fM(0.0) { }
62
63
64 /**
65 Constructor from x, y , z , m values
66 */
68 fX(px), fY(py), fZ(pz), fM(m) {
69
70 if (fM < 0) RestrictNegMass();
71 }
72
73 /**
74 construct from any 4D coordinate system class
75 implementing X(), Y(), X() and M()
76 */
77 template <class CoordSystem>
78 explicit constexpr PxPyPzM4D(const CoordSystem & v) :
79 fX( v.X() ), fY( v.Y() ), fZ( v.Z() ), fM( v.M() )
80 { }
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 copy constructor
86 */
88 fX(v.fX), fY(v.fY), fZ(v.fZ), fM(v.fM) { }
89
90 /**
91 assignment operator
92 */
94 fX = v.fX;
95 fY = v.fY;
96 fZ = v.fZ;
97 fM = v.fM;
98 return *this;
99 }
100
101
102 /**
103 construct from any 4D coordinate system class
104 implementing X(), Y(), X() and M()
105 */
106 template <class AnyCoordSystem>
107 PxPyPzM4D & operator = (const AnyCoordSystem & v) {
108 fX = v.X();
109 fY = v.Y();
110 fZ = v.Z();
111 fM = v.M();
112 return *this;
113 }
114
115 /**
116 Set internal data based on an array of 4 Scalar numbers
117 */
118 void SetCoordinates( const Scalar src[] ) {
119 fX=src[0]; fY=src[1]; fZ=src[2]; fM=src[3];
120 if (fM < 0) RestrictNegMass();
121 }
122
123 /**
124 get internal data into an array of 4 Scalar numbers
125 */
126 void GetCoordinates( Scalar dest[] ) const
127 { dest[0] = fX; dest[1] = fY; dest[2] = fZ; dest[3] = fM; }
128
129 /**
130 Set internal data based on 4 Scalar numbers
131 */
133 fX=px; fY=py; fZ=pz; fM=m;
134 if (fM < 0) RestrictNegMass();
135 }
136
137 /**
138 get internal data into 4 Scalar numbers
139 */
140 void GetCoordinates(Scalar& px, Scalar& py, Scalar& pz, Scalar& m) const
141 { px=fX; py=fY; pz=fZ; m=fM;}
142
143 // --------- Coordinates and Coordinate-like Scalar properties -------------
144
145 // cartesian (Minkowski)coordinate accessors
146
147 Scalar Px() const { return fX;}
148 Scalar Py() const { return fY;}
149 Scalar Pz() const { return fZ;}
150 Scalar M() const { return fM; }
151
152 Scalar X() const { return fX;}
153 Scalar Y() const { return fY;}
154 Scalar Z() const { return fZ;}
155
156 // other coordinate representation
157 /**
158 Energy
159 */
160 Scalar E() const { using std::sqrt; return sqrt(E2()); }
161
162 Scalar T() const { return E();}
163
164 /**
165 squared magnitude of spatial components
166 */
167 Scalar P2() const { return fX*fX + fY*fY + fZ*fZ; }
168
169 /**
170 magnitude of spatial components (magnitude of 3-momentum)
171 */
172 Scalar P() const { using std::sqrt; return sqrt(P2()); }
173 Scalar R() const { return P(); }
174
175 /**
176 vector magnitude squared (or mass squared)
177 In case of negative mass (spacelike particles return negative values)
178 */
179 Scalar M2() const {
180 return ( fM >= 0 ) ? fM*fM : -fM*fM;
181 }
182 Scalar Mag2() const { return M2(); }
183
184 Scalar Mag() const { return M(); }
185
186 /**
187 energy squared
188 */
189 Scalar E2() const {
190 Scalar e2 = P2() + M2();
191 // protect against numerical errors when M2() is negative
192 return e2 > 0 ? e2 : 0;
193 }
194
195 /**
196 transverse spatial component squared
197 */
198 Scalar Pt2() const { return fX*fX + fY*fY;}
199 Scalar Perp2() const { return Pt2();}
200
201 /**
202 Transverse spatial component (P_perp or rho)
203 */
204 Scalar Pt() const { using std::sqrt; return sqrt(Perp2()); }
205 Scalar Perp() const { return Pt();}
206 Scalar Rho() const { return Pt();}
207
208 /**
209 transverse mass squared
210 */
211 Scalar Mt2() const { return E2() - fZ*fZ; }
212
213 /**
214 transverse mass
215 */
216 Scalar Mt() const {
217 const Scalar mm = Mt2();
218 if (mm >= 0) {
219 using std::sqrt;
220 return sqrt(mm);
221 } else {
222 GenVector::Throw ("PxPyPzM4D::Mt() - Tachyonic:\n"
223 " Pz^2 > E^2 so the transverse mass would be imaginary");
224 using std::sqrt;
225 return -sqrt(-mm);
226 }
227 }
228
229 /**
230 transverse energy squared
231 */
232 Scalar Et2() const { // is (E^2 * pt ^2) / p^2
233 // but it is faster to form p^2 from pt^2
234 Scalar pt2 = Pt2();
235 return pt2 == 0 ? 0 : E2() * pt2/( pt2 + fZ*fZ );
236 }
237
238 /**
239 transverse energy
240 */
241 Scalar Et() const {
242 const Scalar etet = Et2();
243 using std::sqrt;
244 return sqrt(etet);
245 }
246
247 /**
248 azimuthal angle
249 */
250 Scalar Phi() const { using std::atan2; return (fX == 0.0 && fY == 0.0) ? 0.0 : atan2(fY, fX); }
251
252 /**
253 polar angle
254 */
255 Scalar Theta() const { using std::atan2; return (fX == 0.0 && fY == 0.0 && fZ == 0.0) ? 0 : atan2(Pt(), fZ); }
256
257 /**
258 pseudorapidity
259 */
260 Scalar Eta() const {
261 return Impl::Eta_FromRhoZ ( Pt(), fZ);
262 }
263
264 // --------- Set Coordinates of this system ---------------
265
266
267 /**
268 set X value
269 */
270 void SetPx( Scalar px) {
271 fX = px;
272 }
273 /**
274 set Y value
275 */
276 void SetPy( Scalar py) {
277 fY = py;
278 }
279 /**
280 set Z value
281 */
282 void SetPz( Scalar pz) {
283 fZ = pz;
284 }
285 /**
286 set T value
287 */
288 void SetM( Scalar m) {
289 fM = m;
290 if (fM < 0) RestrictNegMass();
291 }
292
293 /**
294 set all values
295 */
296 void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e);
297
298 // ------ Manipulations -------------
299
300 /**
301 negate the 4-vector - Note that the energy cannot be negate (would need an additional data member)
302 therefore negate will work only on the spatial components.
303 One would need to use negate only with vectors having the energy as data members
304 */
305 void Negate( ) {
306 fX = -fX;
307 fY = -fY;
308 fZ = -fZ;
309 GenVector::Throw ("PxPyPzM4D::Negate - cannot negate the energy - can negate only the spatial components");
310 }
311
312 /**
313 scale coordinate values by a scalar quantity a
314 */
315 void Scale( const Scalar & a) {
316 fX *= a;
317 fY *= a;
318 fZ *= a;
319 fM *= a;
320 }
321
322
323 /**
324 Exact equality
325 */
326 bool operator == (const PxPyPzM4D & rhs) const {
327 return fX == rhs.fX && fY == rhs.fY && fZ == rhs.fZ && fM == rhs.fM;
328 }
329 bool operator != (const PxPyPzM4D & rhs) const {return !(operator==(rhs));}
330
331
332 // ============= Compatibility section ==================
333
334 // The following make this coordinate system look enough like a CLHEP
335 // vector that an assignment member template can work with either
336 Scalar x() const { return X(); }
337 Scalar y() const { return Y(); }
338 Scalar z() const { return Z(); }
339 Scalar t() const { return E(); }
340
341
342
343#if defined(__MAKECINT__) || defined(G__DICTIONARY)
344
345 // ====== Set member functions for coordinates in other systems =======
346
347 void SetPt(Scalar pt);
348
349 void SetEta(Scalar eta);
350
351 void SetPhi(Scalar phi);
352
353 void SetE(Scalar t);
354
355#endif
356
357private:
358
359 // restrict the value of negative mass to avoid unphysical negative E2 values
360 // M2 must be less than P2 for the tachionic particles - otherwise use positive values
361 inline void RestrictNegMass() {
362 if ( fM >=0 ) return;
363 if ( P2() - fM*fM < 0 ) {
364 GenVector::Throw("PxPyPzM4D::unphysical value of mass, set to closest physical value");
365 fM = - P();
366 }
367 return;
368 }
369
370
371 /**
372 (contiguous) data containing the coordinate values x,y,z,t
373 */
374
375 ScalarType fX;
376 ScalarType fY;
377 ScalarType fZ;
378 ScalarType fM;
379
380};
381
382} // end namespace Math
383} // end namespace ROOT
384
385
386// move implementations here to avoid circle dependencies
387
390
391namespace ROOT {
392
393namespace Math {
394
395template <class ScalarType>
397 *this = PxPyPzE4D<Scalar> (px, py, pz, e);
398}
399
400
401#if defined(__MAKECINT__) || defined(G__DICTIONARY)
402
403 // ====== Set member functions for coordinates in other systems =======
404
405 // ====== Set member functions for coordinates in other systems =======
406
407template <class ScalarType>
408inline void PxPyPzM4D<ScalarType>::SetPt(ScalarType pt) {
409 GenVector_exception e("PxPyPzM4D::SetPt() is not supposed to be called");
410 throw e;
411 PtEtaPhiE4D<ScalarType> v(*this); v.SetPt(pt); *this = PxPyPzM4D<ScalarType>(v);
412}
413template <class ScalarType>
414inline void PxPyPzM4D<ScalarType>::SetEta(ScalarType eta) {
415 GenVector_exception e("PxPyPzM4D::SetEta() is not supposed to be called");
416 throw e;
417 PtEtaPhiE4D<ScalarType> v(*this); v.SetEta(eta); *this = PxPyPzM4D<ScalarType>(v);
418}
419template <class ScalarType>
420inline void PxPyPzM4D<ScalarType>::SetPhi(ScalarType phi) {
421 GenVector_exception e("PxPyPzM4D::SetPhi() is not supposed to be called");
422 throw e;
423 PtEtaPhiE4D<ScalarType> v(*this); v.SetPhi(phi); *this = PxPyPzM4D<ScalarType>(v);
424}
425template <class ScalarType>
426inline void PxPyPzM4D<ScalarType>::SetE(ScalarType energy) {
427 GenVector_exception e("PxPyPzM4D::SetE() is not supposed to be called");
428 throw e;
429 PxPyPzE4D<ScalarType> v(*this); v.SetE(energy);
430 *this = PxPyPzM4D<ScalarType>(v);
431}
432
433
434#endif // endif __MAKE__CINT || G__DICTIONARY
435
436} // end namespace Math
437
438} // end namespace ROOT
439
440
441
442#endif // ROOT_Math_GenVector_PxPyPzM4D
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
#define X(type, name)
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
Class describing a 4D cartesian coordinate system (x, y, z, t coordinates) or momentum-energy vectors...
Definition PxPyPzE4D.h:44
Class describing a 4D coordinate system or momentum-energy vectors stored as (Px, Py,...
Definition PxPyPzM4D.h:49
Scalar x() const
Definition PxPyPzM4D.h:336
Scalar Pz() const
Definition PxPyPzM4D.h:149
Scalar Theta() const
polar angle
Definition PxPyPzM4D.h:255
Scalar Py() const
Definition PxPyPzM4D.h:148
Scalar z() const
Definition PxPyPzM4D.h:338
PxPyPzM4D(const PxPyPzM4D &v)
copy constructor
Definition PxPyPzM4D.h:87
Scalar Px() const
Definition PxPyPzM4D.h:147
Scalar y() const
Definition PxPyPzM4D.h:337
Scalar Z() const
Definition PxPyPzM4D.h:154
Scalar Et() const
transverse energy
Definition PxPyPzM4D.h:241
PxPyPzM4D & operator=(const PxPyPzM4D &v)
assignment operator
Definition PxPyPzM4D.h:93
Scalar E2() const
energy squared
Definition PxPyPzM4D.h:189
void Scale(const Scalar &a)
scale coordinate values by a scalar quantity a
Definition PxPyPzM4D.h:315
Scalar Perp() const
Definition PxPyPzM4D.h:205
constexpr PxPyPzM4D(const CoordSystem &v)
construct from any 4D coordinate system class implementing X(), Y(), X() and M()
Definition PxPyPzM4D.h:78
ScalarType fX
(contiguous) data containing the coordinate values x,y,z,t
Definition PxPyPzM4D.h:375
Scalar Mag() const
Definition PxPyPzM4D.h:184
void GetCoordinates(Scalar &px, Scalar &py, Scalar &pz, Scalar &m) const
get internal data into 4 Scalar numbers
Definition PxPyPzM4D.h:140
void SetPx(Scalar px)
set X value
Definition PxPyPzM4D.h:270
PxPyPzM4D(Scalar px, Scalar py, Scalar pz, Scalar m)
Constructor from x, y , z , m values.
Definition PxPyPzM4D.h:67
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 4 Scalar numbers.
Definition PxPyPzM4D.h:118
void Negate()
negate the 4-vector - Note that the energy cannot be negate (would need an additional data member) th...
Definition PxPyPzM4D.h:305
Scalar M2() const
vector magnitude squared (or mass squared) In case of negative mass (spacelike particles return negat...
Definition PxPyPzM4D.h:179
Scalar Mag2() const
Definition PxPyPzM4D.h:182
Scalar P() const
magnitude of spatial components (magnitude of 3-momentum)
Definition PxPyPzM4D.h:172
Scalar R() const
Definition PxPyPzM4D.h:173
void SetPz(Scalar pz)
set Z value
Definition PxPyPzM4D.h:282
Scalar Mt2() const
transverse mass squared
Definition PxPyPzM4D.h:211
void SetCoordinates(Scalar px, Scalar py, Scalar pz, Scalar m)
Set internal data based on 4 Scalar numbers.
Definition PxPyPzM4D.h:132
Scalar X() const
Definition PxPyPzM4D.h:152
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 4 Scalar numbers
Definition PxPyPzM4D.h:126
Scalar M() const
Definition PxPyPzM4D.h:150
Scalar Pt() const
Transverse spatial component (P_perp or rho)
Definition PxPyPzM4D.h:204
bool operator==(const PxPyPzM4D &rhs) const
Exact equality.
Definition PxPyPzM4D.h:326
Scalar E() const
Energy.
Definition PxPyPzM4D.h:160
void SetPy(Scalar py)
set Y value
Definition PxPyPzM4D.h:276
Scalar Mt() const
transverse mass
Definition PxPyPzM4D.h:216
static constexpr unsigned int Dimension
Definition PxPyPzM4D.h:54
Scalar Y() const
Definition PxPyPzM4D.h:153
Scalar Phi() const
azimuthal angle
Definition PxPyPzM4D.h:250
Scalar P2() const
squared magnitude of spatial components
Definition PxPyPzM4D.h:167
Scalar Pt2() const
transverse spatial component squared
Definition PxPyPzM4D.h:198
bool operator!=(const PxPyPzM4D &rhs) const
Definition PxPyPzM4D.h:329
Scalar Perp2() const
Definition PxPyPzM4D.h:199
Scalar Et2() const
transverse energy squared
Definition PxPyPzM4D.h:232
Scalar Rho() const
Definition PxPyPzM4D.h:206
PxPyPzM4D()
Default constructor with x=y=z=m=0.
Definition PxPyPzM4D.h:61
Scalar t() const
Definition PxPyPzM4D.h:339
void SetM(Scalar m)
set T value
Definition PxPyPzM4D.h:288
Scalar T() const
Definition PxPyPzM4D.h:162
void SetPxPyPzE(Scalar px, Scalar py, Scalar pz, Scalar e)
set all values
Definition PxPyPzM4D.h:396
Scalar Eta() const
pseudorapidity
Definition PxPyPzM4D.h:260
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
Scalar Eta_FromRhoZ(Scalar rho, Scalar z)
Calculate eta given rho and zeta.
Definition eta.h:48
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