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