Skip to content
Merged
25 changes: 25 additions & 0 deletions math/genvector/inc/Math/GenVector/LorentzVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "Math/GenVector/GenVectorIO.h"

#include "TMath.h"

#include <cmath>
#include <string>

Expand Down Expand Up @@ -364,6 +366,29 @@ ROOT provides specialisations and aliases to them of the ROOT::Math::LorentzVect
*/
Scalar Eta() const { return fCoordinates.Eta(); }

/**
deltaRapidity between this and vector v
\f[ \Delta R = \sqrt { \Delta \eta ^2 + \Delta \phi ^2 } \f]
\param useRapidity true to use Rapidity(), false to use Eta()
*/
template <class OtherLorentzVector>
Scalar DeltaR(const OtherLorentzVector &v, const bool useRapidity = false) const
{
const double delta = useRapidity ? Rapidity() - v.Rapidity() : Eta() - v.Eta();
double dphi = Phi() - v.Phi();
// convert dphi angle to the interval (-PI,PI]
if (dphi > TMath::Pi() || dphi <= -TMath::Pi()) {
if (dphi > 0) {
int n = static_cast<int>(dphi / TMath::TwoPi() + 0.5);
dphi -= TMath::TwoPi() * n;
} else {
int n = static_cast<int>(0.5 - dphi / TMath::TwoPi());
dphi += TMath::TwoPi() * n;
}
}
return std::sqrt(delta * delta + dphi * dphi);
}

/**
get the spatial components of the Vector in a
DisplacementVector based on Cartesian Coordinates
Expand Down
22 changes: 21 additions & 1 deletion math/genvector/test/testGenVector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "Math/RotationZYX.h"

#include "Math/LorentzRotation.h"
#include "Math/PtEtaPhiM4D.h"
#include "Math/LorentzVector.h"

#include "Math/VectorUtil.h"
#ifndef NO_SMATRIX
Expand Down Expand Up @@ -794,6 +796,24 @@ int testVectorUtil() {

}

int testLorentzVector()
{
std::cout << "testing LorentzVector \t:\t";
int iret = 0;
LorentzVector<PtEtaPhiM4D<float>> v1(1,2,3,4);
LorentzVector<PtEtaPhiM4D<float>> v2(5,6,7,8);
iret |= compare(v1.DeltaR(v2), 4.60575f);
// Result cross-validated using:
// TLorentzVector t1, t2;
// t1.SetPtEtaPhiE(1,2,3,4); t2.SetPtEtaPhiE(5,6,7,8);
// t1.DeltaR(t2)
if (iret == 0)
std::cout << "\t\t\tOK\n";
else
std::cout << "\t\t\t\t\t\tFAILED\n";
return iret;
}

int testGenVector() {

int iret = 0;
Expand All @@ -808,7 +828,7 @@ int testGenVector() {
iret |= testTransform3D();

iret |= testVectorUtil();

iret |= testLorentzVector();

if (iret !=0) std::cout << "\nTest GenVector FAILED!!!!!!!!!\n";
return iret;
Expand Down
Loading