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