From eb0e38e6e8dacb569bc9c1fa5900176e01478fd9 Mon Sep 17 00:00:00 2001 From: Matt LeBlanc Date: Fri, 22 Jan 2021 14:35:02 +0100 Subject: [PATCH 1/4] Implement rapidity-based DeltaR calculations in TLorentzVector --- math/physics/inc/TLorentzVector.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/math/physics/inc/TLorentzVector.h b/math/physics/inc/TLorentzVector.h index 0eab6083d356a..7a1c6da25f39b 100644 --- a/math/physics/inc/TLorentzVector.h +++ b/math/physics/inc/TLorentzVector.h @@ -181,8 +181,9 @@ class TLorentzVector : public TObject { // Transverse energy w.r.t. given axis. inline Double_t DeltaPhi(const TLorentzVector &) const; - inline Double_t DeltaR(const TLorentzVector &) const; + inline Double_t DeltaR(const TLorentzVector &, Bool_t useRapidity=kFALSE) const; inline Double_t DrEtaPhi(const TLorentzVector &) const; + inline Double_t DrRapidityPhi(const TLorentzVector &) const; inline TVector2 EtaPhiVector(); inline Double_t Angle(const TVector3 & v) const; @@ -460,16 +461,27 @@ inline Double_t TLorentzVector::DeltaPhi(const TLorentzVector & v) const { inline Double_t TLorentzVector::Eta() const { return PseudoRapidity(); } -inline Double_t TLorentzVector::DeltaR(const TLorentzVector & v) const { - Double_t deta = Eta()-v.Eta(); - Double_t dphi = TVector2::Phi_mpi_pi(Phi()-v.Phi()); - return TMath::Sqrt( deta*deta+dphi*dphi ); + +inline Double_t TLorentzVector::DeltaR(const TLorentzVector & v, const Bool_t useRapidity) const { + if(useRapidity){ + Double_t drap = Rapidity()-v.Rapidity(); + Double_t dphi = TVector2::Phi_mpi_pi(Phi()-v.Phi()); + return TMath::Sqrt( drap*drap+dphi*dphi ); + } else { + Double_t deta = Eta()-v.Eta(); + Double_t dphi = TVector2::Phi_mpi_pi(Phi()-v.Phi()); + return TMath::Sqrt( deta*deta+dphi*dphi ); + } } inline Double_t TLorentzVector::DrEtaPhi(const TLorentzVector & v) const{ return DeltaR(v); } +inline Double_t TLorentzVector::DrRapidityPhi(const TLorentzVector & v) const{ + return DeltaR(v, kTRUE); +} + inline TVector2 TLorentzVector::EtaPhiVector() { return TVector2 (Eta(),Phi()); } From 6436285b607e3cbe963ef460b595b844d1b77ca9 Mon Sep 17 00:00:00 2001 From: Matt LeBlanc Date: Tue, 26 Jan 2021 11:54:58 +0100 Subject: [PATCH 2/4] Implement rapidity-based DeltaR calculation option in GenVector --- .../genvector/inc/Math/GenVector/VectorUtil.h | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/VectorUtil.h b/math/genvector/inc/Math/GenVector/VectorUtil.h index 07a2f6c99d516..f245cbb350803 100644 --- a/math/genvector/inc/Math/GenVector/VectorUtil.h +++ b/math/genvector/inc/Math/GenVector/VectorUtil.h @@ -83,17 +83,41 @@ namespace ROOT { return dphi*dphi + deta*deta; } + /** + Find square of the difference in true rapidity (y) and Phi betwen two generic vectors + The only requirements on the Vector classes is that they implement the Phi() and Rapidity() method + \param v1 Vector 1 + \param v2 Vector 2 + \return Angle between the two vectors + \f[ \Delta R2 = ( \Delta \phi )^2 + ( \Delta \y )^2 \f], + */ + template + inline typename Vector1::Scalar DeltaR2RapidityPhi( const Vector1 & v1, const Vector2 & v2) { + typename Vector1::Scalar dphi = DeltaPhi(v1,v2); + typename Vector1::Scalar drap = v2.Rapidity() - v1.Rapidity(); + return dphi*dphi + drap*drap; + } + /** Find difference in pseudorapidity (Eta) and Phi betwen two generic vectors The only requirements on the Vector classes is that they implement the Phi() and Eta() method + An option to use the rapidity instead of Eta is included, for use with massive vectors. \param v1 Vector 1 \param v2 Vector 2 + \param useRapidity use rapidity instead of pseudorapidity? \return Angle between the two vectors - \f[ \Delta R = \sqrt{ ( \Delta \phi )^2 + ( \Delta \eta )^2 } \f] + \f[ \Delta R = \sqrt{ ( \Delta \phi )^2 + ( \Delta \eta )^2 } \f], + or + \f[ \Delta R2 = ( \Delta \phi )^2 + ( \Delta \y )^2 \f] + if useRapidity is true. */ template - inline typename Vector1::Scalar DeltaR( const Vector1 & v1, const Vector2 & v2) { - return std::sqrt( DeltaR2(v1,v2) ); + inline typename Vector1::Scalar DeltaR( const Vector1 & v1, const Vector2 & v2, const bool useRapidity=false) { + if(useRapidity==false){ + return std::sqrt( DeltaR2(v1,v2) ); + } else { + return std::sqrt( DeltaR2RapidityPhi(v1,v2) ); + } } From b3c92e7d89f94dd11bf1ade1661ed43a8441f1ba Mon Sep 17 00:00:00 2001 From: Matt LeBlanc Date: Tue, 2 Feb 2021 13:16:56 +0100 Subject: [PATCH 3/4] Implement separate DeltaRapidityPhi function for VectorUtil --- .../genvector/inc/Math/GenVector/VectorUtil.h | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/VectorUtil.h b/math/genvector/inc/Math/GenVector/VectorUtil.h index f245cbb350803..f822273ec1e4b 100644 --- a/math/genvector/inc/Math/GenVector/VectorUtil.h +++ b/math/genvector/inc/Math/GenVector/VectorUtil.h @@ -101,26 +101,28 @@ namespace ROOT { /** Find difference in pseudorapidity (Eta) and Phi betwen two generic vectors The only requirements on the Vector classes is that they implement the Phi() and Eta() method - An option to use the rapidity instead of Eta is included, for use with massive vectors. \param v1 Vector 1 \param v2 Vector 2 - \param useRapidity use rapidity instead of pseudorapidity? \return Angle between the two vectors \f[ \Delta R = \sqrt{ ( \Delta \phi )^2 + ( \Delta \eta )^2 } \f], - or - \f[ \Delta R2 = ( \Delta \phi )^2 + ( \Delta \y )^2 \f] - if useRapidity is true. */ template - inline typename Vector1::Scalar DeltaR( const Vector1 & v1, const Vector2 & v2, const bool useRapidity=false) { - if(useRapidity==false){ + inline typename Vector1::Scalar DeltaR( const Vector1 & v1, const Vector2 & v2 ) { return std::sqrt( DeltaR2(v1,v2) ); - } else { - return std::sqrt( DeltaR2RapidityPhi(v1,v2) ); - } } - + /** + Find difference in Rapidity (y) and Phi betwen two generic vectors + The only requirements on the Vector classes is that they implement the Phi() and Rapidity() method + \param v1 Vector 1 + \param v2 Vector 2 + \return Angle between the two vectors + \f[ \Delta R = \sqrt{ ( \Delta \phi )^2 + ( \Delta y )^2 } \f], + */ + template + inline typename Vector1::Scalar DeltaRapidityPhi( const Vector1 & v1, const Vector2 & v2 ) { + return std::sqrt( DeltaR2RapidityPhi(v1,v2) ); + } /** Find CosTheta Angle between two generic 3D vectors From e13f3f1960a69c09c79ebfb16b5ca6a77794196a Mon Sep 17 00:00:00 2001 From: Matt LeBlanc Date: Tue, 2 Feb 2021 13:18:43 +0100 Subject: [PATCH 4/4] Fixing whitespace in VectorUtil.h --- math/genvector/inc/Math/GenVector/VectorUtil.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/VectorUtil.h b/math/genvector/inc/Math/GenVector/VectorUtil.h index f822273ec1e4b..90bfff81d0652 100644 --- a/math/genvector/inc/Math/GenVector/VectorUtil.h +++ b/math/genvector/inc/Math/GenVector/VectorUtil.h @@ -89,7 +89,7 @@ namespace ROOT { \param v1 Vector 1 \param v2 Vector 2 \return Angle between the two vectors - \f[ \Delta R2 = ( \Delta \phi )^2 + ( \Delta \y )^2 \f], + \f[ \Delta R2 = ( \Delta \phi )^2 + ( \Delta \y )^2 \f] */ template inline typename Vector1::Scalar DeltaR2RapidityPhi( const Vector1 & v1, const Vector2 & v2) { @@ -104,11 +104,11 @@ namespace ROOT { \param v1 Vector 1 \param v2 Vector 2 \return Angle between the two vectors - \f[ \Delta R = \sqrt{ ( \Delta \phi )^2 + ( \Delta \eta )^2 } \f], + \f[ \Delta R = \sqrt{ ( \Delta \phi )^2 + ( \Delta \eta )^2 } \f] */ template - inline typename Vector1::Scalar DeltaR( const Vector1 & v1, const Vector2 & v2 ) { - return std::sqrt( DeltaR2(v1,v2) ); + inline typename Vector1::Scalar DeltaR( const Vector1 & v1, const Vector2 & v2) { + return std::sqrt( DeltaR2(v1,v2) ); } /** @@ -120,7 +120,7 @@ namespace ROOT { \f[ \Delta R = \sqrt{ ( \Delta \phi )^2 + ( \Delta y )^2 } \f], */ template - inline typename Vector1::Scalar DeltaRapidityPhi( const Vector1 & v1, const Vector2 & v2 ) { + inline typename Vector1::Scalar DeltaRapidityPhi( const Vector1 & v1, const Vector2 & v2) { return std::sqrt( DeltaR2RapidityPhi(v1,v2) ); }