Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion math/genvector/inc/Math/GenVector/VectorUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ 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 <class Vector1, class Vector2>
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
Expand All @@ -96,7 +111,18 @@ namespace ROOT {
return std::sqrt( DeltaR2(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 <class Vector1, class Vector2>
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
Expand Down
22 changes: 17 additions & 5 deletions math/physics/inc/TLorentzVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down