File indexing completed on 2025-12-15 10:30:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TLorentzVector
0013 #define ROOT_TLorentzVector
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include "TMath.h"
0025 #include "TVector3.h"
0026 #include "TRotation.h"
0027 #include "Math/Vector4D.h"
0028
0029 class TLorentzRotation;
0030
0031 class TLorentzVector : public TObject {
0032
0033 private:
0034
0035 TVector3 fP;
0036 Double_t fE;
0037
0038 public:
0039
0040 typedef Double_t Scalar;
0041
0042 enum { kX=0, kY=1, kZ=2, kT=3, kNUM_COORDINATES=4, kSIZE=kNUM_COORDINATES };
0043
0044
0045 TLorentzVector();
0046
0047 TLorentzVector(Double_t x, Double_t y, Double_t z, Double_t t);
0048
0049
0050 TLorentzVector(const Double_t * carray);
0051 TLorentzVector(const Float_t * carray);
0052
0053
0054 TLorentzVector(const TVector3 & vector3, Double_t t);
0055
0056
0057 TLorentzVector(const TLorentzVector & lorentzvector) noexcept;
0058
0059
0060 ~TLorentzVector() override = default;
0061
0062
0063
0064
0065
0066
0067 inline Double_t X() const;
0068 inline Double_t Y() const;
0069 inline Double_t Z() const;
0070 inline Double_t T() const;
0071
0072
0073 inline void SetX(Double_t a);
0074 inline void SetY(Double_t a);
0075 inline void SetZ(Double_t a);
0076 inline void SetT(Double_t a);
0077
0078
0079 inline Double_t Px() const;
0080 inline Double_t Py() const;
0081 inline Double_t Pz() const;
0082 inline Double_t P() const;
0083 inline Double_t E() const;
0084 inline Double_t Energy() const;
0085
0086
0087 inline void SetPx(Double_t a);
0088 inline void SetPy(Double_t a);
0089 inline void SetPz(Double_t a);
0090 inline void SetE(Double_t a);
0091
0092
0093 inline TVector3 Vect() const ;
0094
0095
0096 inline void SetVect(const TVector3 & vect3);
0097
0098
0099 inline Double_t Theta() const;
0100 inline Double_t CosTheta() const;
0101 inline Double_t Phi() const;
0102 inline Double_t Rho() const;
0103
0104
0105 inline void SetTheta(Double_t theta);
0106 inline void SetPhi(Double_t phi);
0107 inline void SetRho(Double_t rho);
0108
0109
0110 inline void SetPxPyPzE(Double_t px, Double_t py, Double_t pz, Double_t e);
0111 inline void SetXYZT(Double_t x, Double_t y, Double_t z, Double_t t);
0112 inline void SetXYZM(Double_t x, Double_t y, Double_t z, Double_t m);
0113 inline void SetPtEtaPhiM(Double_t pt, Double_t eta, Double_t phi, Double_t m);
0114 inline void SetPtEtaPhiE(Double_t pt, Double_t eta, Double_t phi, Double_t e);
0115
0116
0117
0118 inline void GetXYZT(Double_t *carray) const;
0119 inline void GetXYZT(Float_t *carray) const;
0120
0121
0122
0123 Double_t operator () (int i) const;
0124 inline Double_t operator [] (int i) const;
0125
0126
0127 Double_t & operator () (int i);
0128 inline Double_t & operator [] (int i);
0129
0130
0131 inline TLorentzVector & operator = (const TLorentzVector &) noexcept;
0132
0133
0134 inline TLorentzVector operator + (const TLorentzVector &) const;
0135 inline TLorentzVector & operator += (const TLorentzVector &);
0136
0137
0138 inline TLorentzVector operator - (const TLorentzVector &) const;
0139 inline TLorentzVector & operator -= (const TLorentzVector &);
0140
0141
0142 inline TLorentzVector operator - () const;
0143
0144
0145 inline TLorentzVector operator * (Double_t a) const;
0146 inline TLorentzVector & operator *= (Double_t a);
0147
0148
0149 inline Bool_t operator == (const TLorentzVector &) const;
0150 inline Bool_t operator != (const TLorentzVector &) const;
0151
0152
0153 inline Double_t Perp2() const;
0154
0155
0156 inline Double_t Pt() const;
0157 inline Double_t Perp() const;
0158
0159
0160 inline void SetPerp(Double_t);
0161
0162
0163 inline Double_t Perp2(const TVector3 & v) const;
0164
0165
0166 inline Double_t Pt(const TVector3 & v) const;
0167 inline Double_t Perp(const TVector3 & v) const;
0168
0169
0170 inline Double_t Et2() const;
0171
0172
0173 inline Double_t Et() const;
0174
0175
0176 inline Double_t Et2(const TVector3 &) const;
0177
0178
0179 inline Double_t Et(const TVector3 &) const;
0180
0181
0182 inline Double_t DeltaPhi(const TLorentzVector &) const;
0183 inline Double_t DeltaR(const TLorentzVector &, Bool_t useRapidity=kFALSE) const;
0184 inline Double_t DrEtaPhi(const TLorentzVector &) const;
0185 inline Double_t DrRapidityPhi(const TLorentzVector &) const;
0186 inline TVector2 EtaPhiVector();
0187
0188 inline Double_t Angle(const TVector3 & v) const;
0189
0190
0191 inline Double_t Mag2() const;
0192 inline Double_t M2() const;
0193
0194
0195 inline Double_t Mag() const;
0196 inline Double_t M() const;
0197
0198
0199 inline Double_t Mt2() const;
0200
0201
0202 inline Double_t Mt() const;
0203
0204
0205 inline Double_t Beta() const;
0206 inline Double_t Gamma() const;
0207
0208 inline Double_t Dot(const TLorentzVector &) const;
0209 inline Double_t operator * (const TLorentzVector &) const;
0210
0211
0212 inline void SetVectMag(const TVector3 & spatial, Double_t magnitude);
0213 inline void SetVectM(const TVector3 & spatial, Double_t mass);
0214
0215
0216 inline Double_t Plus() const;
0217 inline Double_t Minus() const;
0218
0219
0220
0221
0222 inline TVector3 BoostVector() const ;
0223
0224
0225 void Boost(Double_t, Double_t, Double_t);
0226 inline void Boost(const TVector3 &);
0227
0228
0229 Double_t Rapidity() const;
0230
0231
0232 inline Double_t Eta() const;
0233 inline Double_t PseudoRapidity() const;
0234
0235
0236 inline void RotateX(Double_t angle);
0237
0238
0239 inline void RotateY(Double_t angle);
0240
0241
0242 inline void RotateZ(Double_t angle);
0243
0244
0245 inline void RotateUz(const TVector3 & newUzVector);
0246
0247
0248 inline void Rotate(Double_t, const TVector3 &);
0249
0250
0251 inline TLorentzVector & operator *= (const TRotation &);
0252 inline TLorentzVector & Transform(const TRotation &);
0253
0254
0255 TLorentzVector & operator *= (const TLorentzRotation &);
0256 TLorentzVector & Transform(const TLorentzRotation &);
0257
0258
0259 operator ROOT::Math::PxPyPzEVector() const {
0260 return {Px(), Py(), Pz(), E()};
0261 }
0262
0263 void Print(Option_t *option="") const override;
0264
0265 ClassDefOverride(TLorentzVector,4)
0266 };
0267
0268
0269
0270
0271 inline TLorentzVector operator * (Double_t a, const TLorentzVector &);
0272
0273
0274
0275 inline Double_t TLorentzVector::X() const { return fP.X(); }
0276 inline Double_t TLorentzVector::Y() const { return fP.Y(); }
0277 inline Double_t TLorentzVector::Z() const { return fP.Z(); }
0278 inline Double_t TLorentzVector::T() const { return fE; }
0279
0280 inline void TLorentzVector::SetX(Double_t a) { fP.SetX(a); }
0281 inline void TLorentzVector::SetY(Double_t a) { fP.SetY(a); }
0282 inline void TLorentzVector::SetZ(Double_t a) { fP.SetZ(a); }
0283 inline void TLorentzVector::SetT(Double_t a) { fE = a; }
0284
0285 inline Double_t TLorentzVector::Px() const { return X(); }
0286 inline Double_t TLorentzVector::Py() const { return Y(); }
0287 inline Double_t TLorentzVector::Pz() const { return Z(); }
0288 inline Double_t TLorentzVector::P() const { return fP.Mag(); }
0289 inline Double_t TLorentzVector::E() const { return T(); }
0290 inline Double_t TLorentzVector::Energy() const { return T(); }
0291
0292 inline void TLorentzVector::SetPx(Double_t a) { SetX(a); }
0293 inline void TLorentzVector::SetPy(Double_t a) { SetY(a); }
0294 inline void TLorentzVector::SetPz(Double_t a) { SetZ(a); }
0295 inline void TLorentzVector::SetE(Double_t a) { SetT(a); }
0296
0297 inline TVector3 TLorentzVector::Vect() const { return fP; }
0298
0299 inline void TLorentzVector::SetVect(const TVector3 &p) { fP = p; }
0300
0301 inline Double_t TLorentzVector::Phi() const {
0302 return fP.Phi();
0303 }
0304
0305 inline Double_t TLorentzVector::Theta() const {
0306 return fP.Theta();
0307 }
0308
0309 inline Double_t TLorentzVector::CosTheta() const {
0310 return fP.CosTheta();
0311 }
0312
0313
0314 inline Double_t TLorentzVector::Rho() const {
0315 return fP.Mag();
0316 }
0317
0318 inline void TLorentzVector::SetTheta(Double_t th) {
0319 fP.SetTheta(th);
0320 }
0321
0322 inline void TLorentzVector::SetPhi(Double_t phi) {
0323 fP.SetPhi(phi);
0324 }
0325
0326 inline void TLorentzVector::SetRho(Double_t rho) {
0327 fP.SetMag(rho);
0328 }
0329
0330 inline void TLorentzVector::SetXYZT(Double_t x, Double_t y, Double_t z, Double_t t) {
0331 fP.SetXYZ(x, y, z);
0332 SetT(t);
0333 }
0334
0335 inline void TLorentzVector::SetPxPyPzE(Double_t px, Double_t py, Double_t pz, Double_t e) {
0336 SetXYZT(px, py, pz, e);
0337 }
0338
0339 inline void TLorentzVector::SetXYZM(Double_t x, Double_t y, Double_t z, Double_t m) {
0340 if ( m >= 0 )
0341 SetXYZT( x, y, z, TMath::Sqrt(x*x+y*y+z*z+m*m) );
0342 else
0343 SetXYZT( x, y, z, TMath::Sqrt( TMath::Max((x*x+y*y+z*z-m*m), 0. ) ) );
0344 }
0345
0346 inline void TLorentzVector::SetPtEtaPhiM(Double_t pt, Double_t eta, Double_t phi, Double_t m) {
0347 pt = TMath::Abs(pt);
0348 SetXYZM(pt*TMath::Cos(phi), pt*TMath::Sin(phi), pt*sinh(eta) ,m);
0349 }
0350
0351 inline void TLorentzVector::SetPtEtaPhiE(Double_t pt, Double_t eta, Double_t phi, Double_t e) {
0352 pt = TMath::Abs(pt);
0353 SetXYZT(pt*TMath::Cos(phi), pt*TMath::Sin(phi), pt*sinh(eta) ,e);
0354 }
0355
0356 inline void TLorentzVector::GetXYZT(Double_t *carray) const {
0357 fP.GetXYZ(carray);
0358 carray[3] = fE;
0359 }
0360
0361 inline void TLorentzVector::GetXYZT(Float_t *carray) const{
0362 fP.GetXYZ(carray);
0363 carray[3] = fE;
0364 }
0365
0366 inline Double_t & TLorentzVector::operator [] (int i) { return (*this)(i); }
0367 inline Double_t TLorentzVector::operator [] (int i) const { return (*this)(i); }
0368
0369 inline TLorentzVector &TLorentzVector::operator = (const TLorentzVector & q) noexcept {
0370 fP = q.Vect();
0371 fE = q.T();
0372 return *this;
0373 }
0374
0375 inline TLorentzVector TLorentzVector::operator + (const TLorentzVector & q) const {
0376 return TLorentzVector(fP+q.Vect(), fE+q.T());
0377 }
0378
0379 inline TLorentzVector &TLorentzVector::operator += (const TLorentzVector & q) {
0380 fP += q.Vect();
0381 fE += q.T();
0382 return *this;
0383 }
0384
0385 inline TLorentzVector TLorentzVector::operator - (const TLorentzVector & q) const {
0386 return TLorentzVector(fP-q.Vect(), fE-q.T());
0387 }
0388
0389 inline TLorentzVector &TLorentzVector::operator -= (const TLorentzVector & q) {
0390 fP -= q.Vect();
0391 fE -= q.T();
0392 return *this;
0393 }
0394
0395 inline TLorentzVector TLorentzVector::operator - () const {
0396 return TLorentzVector(-X(), -Y(), -Z(), -T());
0397 }
0398
0399 inline TLorentzVector& TLorentzVector::operator *= (Double_t a) {
0400 fP *= a;
0401 fE *= a;
0402 return *this;
0403 }
0404
0405 inline TLorentzVector TLorentzVector::operator * (Double_t a) const {
0406 return TLorentzVector(a*X(), a*Y(), a*Z(), a*T());
0407 }
0408
0409 inline Bool_t TLorentzVector::operator == (const TLorentzVector & q) const {
0410 return (Vect() == q.Vect() && T() == q.T());
0411 }
0412
0413 inline Bool_t TLorentzVector::operator != (const TLorentzVector & q) const {
0414 return (Vect() != q.Vect() || T() != q.T());
0415 }
0416
0417 inline Double_t TLorentzVector::Perp2() const { return fP.Perp2(); }
0418
0419 inline Double_t TLorentzVector::Perp() const { return fP.Perp(); }
0420
0421 inline Double_t TLorentzVector::Pt() const { return Perp(); }
0422
0423 inline void TLorentzVector::SetPerp(Double_t r) {
0424 fP.SetPerp(r);
0425 }
0426
0427 inline Double_t TLorentzVector::Perp2(const TVector3 &v) const {
0428 return fP.Perp2(v);
0429 }
0430
0431 inline Double_t TLorentzVector::Perp(const TVector3 &v) const {
0432 return fP.Perp(v);
0433 }
0434
0435 inline Double_t TLorentzVector::Pt(const TVector3 &v) const {
0436 return Perp(v);
0437 }
0438
0439 inline Double_t TLorentzVector::Et2() const {
0440 Double_t pt2 = fP.Perp2();
0441 return pt2 == 0 ? 0 : E()*E() * pt2/(pt2+Z()*Z());
0442 }
0443
0444 inline Double_t TLorentzVector::Et() const {
0445 Double_t etet = Et2();
0446 return E() < 0.0 ? -sqrt(etet) : sqrt(etet);
0447 }
0448
0449 inline Double_t TLorentzVector::Et2(const TVector3 & v) const {
0450 Double_t pt2 = fP.Perp2(v);
0451 Double_t pv = fP.Dot(v.Unit());
0452 return pt2 == 0 ? 0 : E()*E() * pt2/(pt2+pv*pv);
0453 }
0454
0455 inline Double_t TLorentzVector::Et(const TVector3 & v) const {
0456 Double_t etet = Et2(v);
0457 return E() < 0.0 ? -sqrt(etet) : sqrt(etet);
0458 }
0459
0460 inline Double_t TLorentzVector::DeltaPhi(const TLorentzVector & v) const {
0461 return TVector2::Phi_mpi_pi(Phi()-v.Phi());
0462 }
0463
0464 inline Double_t TLorentzVector::Eta() const {
0465 return PseudoRapidity();
0466 }
0467
0468 inline Double_t TLorentzVector::DeltaR(const TLorentzVector & v, const Bool_t useRapidity) const {
0469 if(useRapidity){
0470 Double_t drap = Rapidity()-v.Rapidity();
0471 Double_t dphi = TVector2::Phi_mpi_pi(Phi()-v.Phi());
0472 return TMath::Sqrt( drap*drap+dphi*dphi );
0473 } else {
0474 Double_t deta = Eta()-v.Eta();
0475 Double_t dphi = TVector2::Phi_mpi_pi(Phi()-v.Phi());
0476 return TMath::Sqrt( deta*deta+dphi*dphi );
0477 }
0478 }
0479
0480 inline Double_t TLorentzVector::DrEtaPhi(const TLorentzVector & v) const{
0481 return DeltaR(v);
0482 }
0483
0484 inline Double_t TLorentzVector::DrRapidityPhi(const TLorentzVector & v) const{
0485 return DeltaR(v, kTRUE);
0486 }
0487
0488 inline TVector2 TLorentzVector::EtaPhiVector() {
0489 return TVector2 (Eta(),Phi());
0490 }
0491
0492
0493 inline Double_t TLorentzVector::Angle(const TVector3 &v) const {
0494 return fP.Angle(v);
0495 }
0496
0497 inline Double_t TLorentzVector::Mag2() const {
0498 return T()*T() - fP.Mag2();
0499 }
0500
0501 inline Double_t TLorentzVector::Mag() const {
0502 Double_t mm = Mag2();
0503 return mm < 0.0 ? -TMath::Sqrt(-mm) : TMath::Sqrt(mm);
0504 }
0505
0506 inline Double_t TLorentzVector::M2() const { return Mag2(); }
0507 inline Double_t TLorentzVector::M() const { return Mag(); }
0508
0509 inline Double_t TLorentzVector::Mt2() const {
0510 return E()*E() - Z()*Z();
0511 }
0512
0513 inline Double_t TLorentzVector::Mt() const {
0514 Double_t mm = Mt2();
0515 return mm < 0.0 ? -TMath::Sqrt(-mm) : TMath::Sqrt(mm);
0516 }
0517
0518 inline Double_t TLorentzVector::Beta() const {
0519 return fP.Mag() / fE;
0520 }
0521
0522 inline Double_t TLorentzVector::Gamma() const {
0523 Double_t b = Beta();
0524 return 1.0/TMath::Sqrt(1- b*b);
0525 }
0526
0527 inline void TLorentzVector::SetVectMag(const TVector3 & spatial, Double_t magnitude) {
0528 SetXYZM(spatial.X(), spatial.Y(), spatial.Z(), magnitude);
0529 }
0530
0531 inline void TLorentzVector::SetVectM(const TVector3 & spatial, Double_t mass) {
0532 SetVectMag(spatial, mass);
0533 }
0534
0535 inline Double_t TLorentzVector::Dot(const TLorentzVector & q) const {
0536 return T()*q.T() - Z()*q.Z() - Y()*q.Y() - X()*q.X();
0537 }
0538
0539 inline Double_t TLorentzVector::operator * (const TLorentzVector & q) const {
0540 return Dot(q);
0541 }
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551
0552
0553
0554 inline Double_t TLorentzVector::Plus() const {
0555 return T() + Z();
0556 }
0557
0558 inline Double_t TLorentzVector::Minus() const {
0559 return T() - Z();
0560 }
0561
0562 inline TVector3 TLorentzVector::BoostVector() const {
0563 return TVector3(X()/T(), Y()/T(), Z()/T());
0564 }
0565
0566 inline void TLorentzVector::Boost(const TVector3 & b) {
0567 Boost(b.X(), b.Y(), b.Z());
0568 }
0569
0570 inline Double_t TLorentzVector::PseudoRapidity() const {
0571 return fP.PseudoRapidity();
0572 }
0573
0574 inline void TLorentzVector::RotateX(Double_t angle) {
0575 fP.RotateX(angle);
0576 }
0577
0578 inline void TLorentzVector::RotateY(Double_t angle) {
0579 fP.RotateY(angle);
0580 }
0581
0582 inline void TLorentzVector::RotateZ(Double_t angle) {
0583 fP.RotateZ(angle);
0584 }
0585
0586 inline void TLorentzVector::RotateUz(const TVector3 &newUzVector) {
0587 fP.RotateUz(newUzVector);
0588 }
0589
0590 inline void TLorentzVector::Rotate(Double_t a, const TVector3 &v) {
0591 fP.Rotate(a,v);
0592 }
0593
0594 inline TLorentzVector &TLorentzVector::operator *= (const TRotation & m) {
0595 fP *= m;
0596 return *this;
0597 }
0598
0599 inline TLorentzVector &TLorentzVector::Transform(const TRotation & m) {
0600 fP.Transform(m);
0601 return *this;
0602 }
0603
0604 inline TLorentzVector operator * (Double_t a, const TLorentzVector & p) {
0605 return TLorentzVector(a*p.X(), a*p.Y(), a*p.Z(), a*p.T());
0606 }
0607
0608 inline TLorentzVector::TLorentzVector()
0609 : fP(), fE(0.0) {}
0610
0611 inline TLorentzVector::TLorentzVector(Double_t x, Double_t y, Double_t z, Double_t t)
0612 : fP(x,y,z), fE(t) {}
0613
0614 inline TLorentzVector::TLorentzVector(const Double_t * x0)
0615 : fP(x0), fE(x0[3]) {}
0616
0617 inline TLorentzVector::TLorentzVector(const Float_t * x0)
0618 : fP(x0), fE(x0[3]) {}
0619
0620 inline TLorentzVector::TLorentzVector(const TVector3 & p, Double_t e)
0621 : fP(p), fE(e) {}
0622
0623 inline TLorentzVector::TLorentzVector(const TLorentzVector & p) noexcept : TObject(p)
0624 , fP(p.Vect()), fE(p.T()) {}
0625
0626
0627
0628 inline Double_t TLorentzVector::operator () (int i) const
0629 {
0630
0631 switch(i) {
0632 case kX:
0633 return fP.X();
0634 case kY:
0635 return fP.Y();
0636 case kZ:
0637 return fP.Z();
0638 case kT:
0639 return fE;
0640 default:
0641 Error("operator()()", "bad index (%d) returning 0",i);
0642 }
0643 return 0.;
0644 }
0645
0646 inline Double_t & TLorentzVector::operator () (int i)
0647 {
0648
0649 switch(i) {
0650 case kX:
0651 return fP.fX;
0652 case kY:
0653 return fP.fY;
0654 case kZ:
0655 return fP.fZ;
0656 case kT:
0657 return fE;
0658 default:
0659 Error("operator()()", "bad index (%d) returning &fE",i);
0660 }
0661 return fE;
0662 }
0663
0664 #endif