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