From 83114daf717d5da72112d8d3961edbbd9f678eff Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Tue, 12 Aug 2025 16:54:54 +0200 Subject: [PATCH 1/6] [nfc] clarify GenVector abbreviations --- math/genvector/inc/Math/GenVector/LorentzVector.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/LorentzVector.h b/math/genvector/inc/Math/GenVector/LorentzVector.h index 11f0f495d2698..791992cf28a67 100644 --- a/math/genvector/inc/Math/GenVector/LorentzVector.h +++ b/math/genvector/inc/Math/GenVector/LorentzVector.h @@ -43,16 +43,17 @@ In the case of LorentzVector we don't distinguish the concepts of points and displacement vectors as in the 3D case, since the main use case for 4D Vectors is to describe the kinematics of relativistic particles. A LorentzVector behaves like a -DisplacementVector in 4D. The Minkowski components could be viewed as +DisplacementVector in 4D. The Minkowski components could be viewed as v and t, or for kinematic 4-vectors, as p and E. -ROOT provides specialisations and aliases to them of the ROOT::Math::LorentzVector template: +ROOT provides specialisations (and aliases to them) of the ROOT::Math::LorentzVector template: - ROOT::Math::PtEtaPhiMVector based on pt (rho),eta,phi and M (t) coordinates in double precision - ROOT::Math::PtEtaPhiEVector based on pt (rho),eta,phi and E (t) coordinates in double precision -- ROOT::Math::PxPyPzMVector based on px,py,pz and M (mass) coordinates in double precision -- ROOT::Math::PxPyPzEVector based on px,py,pz and E (energy) coordinates in double precision +- ROOT::Math::PxPyPzMVector based on px,py,pz and M coordinates in double precision +- ROOT::Math::PxPyPzEVector based on px,py,pz and E coordinates in double precision - ROOT::Math::XYZTVector based on x,y,z,t coordinates (cartesian) in double precision (same as PxPyPzEVector) - ROOT::Math::XYZTVectorF based on x,y,z,t coordinates (cartesian) in float precision (same as PxPyPzEVector but float) +Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. M is mass, E is energy, p is momentum. @see GenVector */ From 940a7c9d7d4f9134be4abed157eeadb4a25fe1ec Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Tue, 12 Aug 2025 17:53:17 +0200 Subject: [PATCH 2/6] [math] Implement acoplanarity and asymmetry functions Fixes https://github.com/root-project/root/issues/19338 --- .../inc/Math/GenVector/LorentzVector.h | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/LorentzVector.h b/math/genvector/inc/Math/GenVector/LorentzVector.h index 791992cf28a67..ba69607de2fc0 100644 --- a/math/genvector/inc/Math/GenVector/LorentzVector.h +++ b/math/genvector/inc/Math/GenVector/LorentzVector.h @@ -19,10 +19,9 @@ #define ROOT_Math_GenVector_LorentzVector 1 #include "Math/GenVector/PxPyPzE4D.h" - #include "Math/GenVector/DisplacementVector3D.h" - #include "Math/GenVector/GenVectorIO.h" +#include "Math/Vector2D.h" #include "TMath.h" @@ -732,6 +731,66 @@ Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. return tmp; } + /** + pair (p+ p-) acoplanarity `alpha = 1 - |phi+ - phi-|/pi`. + \param pp p+, mathcore::LorentzVector based on any coordinate system + \param pm p-, mathcore::LorentzVector based on any coordinate system + \return a scalar + \see http://doi.org/10.1103/PhysRevLett.121.212301 + */ + template< class CoordSystem > + Scalar Acoplanarity(LorentzVector pp, LorentzVector pm) + { + double dphi = pp.Phi() - pm.Phi(); + // convert dphi angle to the interval (-PI,PI] + if (dphi > TMath::Pi() || dphi <= -TMath::Pi()) { + if (dphi > 0) { + int n = static_cast(dphi / TMath::TwoPi() + 0.5); + dphi -= TMath::TwoPi() * n; + } else { + int n = static_cast(0.5 - dphi / TMath::TwoPi()); + dphi += TMath::TwoPi() * n; + } + } + return 1 - std::abs(phi)/TMath::Pi(); + } + + /** + pair (p+ p-) vectorial asymmetry `Av = |Pt+ - Pt-|/|Pt+ + Pt-|`. + In an experimental setting, it reflects a convolution of the experimental resolutions + of particle energy and azimuthal angle measurement. + \param pp p+, mathcore::LorentzVector based on any coordinate system + \param pm p-, mathcore::LorentzVector based on any coordinate system + \return a scalar + \see http://doi.org/10.1103/PhysRevLett.121.212301, https://doi.org/10.1103/PhysRevD.99.093013 + */ + template< class CoordSystem > + Scalar AsymmetryVectorial(LorentzVector pp, LorentzVector pm) + { + ROOT::Math::XYVector vp(pp.Px(), pp.Py()); + ROOT::Math::XYVector vm(pm.Px(), pm.Py()); + return (vp - vm).R() / (vp + vm).R(); + } + + /** + pair (p+ p-) scalar asymmetry `As = ||Pt+| - |Pt-|/||Pt+| + |Pt-||`. + Measures the relative difference in transverse momentum of the pair, e.g. two photons, + and would be ideally zero for two back-to-back photons. + \param pp p+, mathcore::LorentzVector based on any coordinate system + \param pm p-, mathcore::LorentzVector based on any coordinate system + \return a scalar. Returns 0 if both transverse momenta are zero + \see http://doi.org/10.1103/PhysRevLett.121.212301, https://doi.org/10.1103/PhysRevD.99.093013 + */ + template< class CoordSystem > + Scalar AsymmetryScalar(LorentzVector pp, LorentzVector pm) + { + auto ptp = pp.Pt(); + auto ptm = pm.Pt(); + if (ptp == 0 && ptm == 0) + return 0; + return std::abs(ptp - ptm) / (ptp + ptm); + } + // ------------- I/O to/from streams ------------- template< class char_t, class traits_t, class Coords > From 3a1a61b05e7cfb5c4a146c69be28690d930ae269 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Tue, 12 Aug 2025 18:01:17 +0200 Subject: [PATCH 3/6] [math] fix compiler errors --- math/genvector/inc/Math/GenVector/LorentzVector.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/LorentzVector.h b/math/genvector/inc/Math/GenVector/LorentzVector.h index ba69607de2fc0..972f6f3f47db1 100644 --- a/math/genvector/inc/Math/GenVector/LorentzVector.h +++ b/math/genvector/inc/Math/GenVector/LorentzVector.h @@ -739,9 +739,9 @@ Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. \see http://doi.org/10.1103/PhysRevLett.121.212301 */ template< class CoordSystem > - Scalar Acoplanarity(LorentzVector pp, LorentzVector pm) + LorentzVector::Scalar Acoplanarity(LorentzVector pp, LorentzVector pm) { - double dphi = pp.Phi() - pm.Phi(); + auto dphi = pp.Phi() - pm.Phi(); // convert dphi angle to the interval (-PI,PI] if (dphi > TMath::Pi() || dphi <= -TMath::Pi()) { if (dphi > 0) { @@ -752,7 +752,7 @@ Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. dphi += TMath::TwoPi() * n; } } - return 1 - std::abs(phi)/TMath::Pi(); + return 1 - std::abs(dphi)/TMath::Pi(); } /** @@ -765,7 +765,7 @@ Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. \see http://doi.org/10.1103/PhysRevLett.121.212301, https://doi.org/10.1103/PhysRevD.99.093013 */ template< class CoordSystem > - Scalar AsymmetryVectorial(LorentzVector pp, LorentzVector pm) + LorentzVector::Scalar AsymmetryVectorial(LorentzVector pp, LorentzVector pm) { ROOT::Math::XYVector vp(pp.Px(), pp.Py()); ROOT::Math::XYVector vm(pm.Px(), pm.Py()); @@ -782,7 +782,7 @@ Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. \see http://doi.org/10.1103/PhysRevLett.121.212301, https://doi.org/10.1103/PhysRevD.99.093013 */ template< class CoordSystem > - Scalar AsymmetryScalar(LorentzVector pp, LorentzVector pm) + LorentzVector::Scalar AsymmetryScalar(LorentzVector pp, LorentzVector pm) { auto ptp = pp.Pt(); auto ptm = pm.Pt(); From 941c1995d8a92c51891ebb0fdcc629c3d6f6d94f Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Tue, 12 Aug 2025 18:08:26 +0200 Subject: [PATCH 4/6] [math] fix compile error and deal with zeroes --- math/genvector/inc/Math/GenVector/LorentzVector.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/LorentzVector.h b/math/genvector/inc/Math/GenVector/LorentzVector.h index 972f6f3f47db1..27a3feb7929b5 100644 --- a/math/genvector/inc/Math/GenVector/LorentzVector.h +++ b/math/genvector/inc/Math/GenVector/LorentzVector.h @@ -739,7 +739,7 @@ Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. \see http://doi.org/10.1103/PhysRevLett.121.212301 */ template< class CoordSystem > - LorentzVector::Scalar Acoplanarity(LorentzVector pp, LorentzVector pm) + typename LorentzVector::Scalar Acoplanarity(LorentzVector pp, LorentzVector pm) { auto dphi = pp.Phi() - pm.Phi(); // convert dphi angle to the interval (-PI,PI] @@ -761,15 +761,18 @@ Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. of particle energy and azimuthal angle measurement. \param pp p+, mathcore::LorentzVector based on any coordinate system \param pm p-, mathcore::LorentzVector based on any coordinate system - \return a scalar + \return a scalar. Returns -1 if both momenta are exactly mirrored. \see http://doi.org/10.1103/PhysRevLett.121.212301, https://doi.org/10.1103/PhysRevD.99.093013 */ template< class CoordSystem > - LorentzVector::Scalar AsymmetryVectorial(LorentzVector pp, LorentzVector pm) + typename LorentzVector::Scalar AsymmetryVectorial(LorentzVector pp, LorentzVector pm) { ROOT::Math::XYVector vp(pp.Px(), pp.Py()); ROOT::Math::XYVector vm(pm.Px(), pm.Py()); - return (vp - vm).R() / (vp + vm).R(); + auto denom = (vp + vm).R(); + if (denom == 0.) + return -1; + return (vp - vm).R() / denom; } /** @@ -782,7 +785,7 @@ Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. \see http://doi.org/10.1103/PhysRevLett.121.212301, https://doi.org/10.1103/PhysRevD.99.093013 */ template< class CoordSystem > - LorentzVector::Scalar AsymmetryScalar(LorentzVector pp, LorentzVector pm) + typename LorentzVector::Scalar AsymmetryScalar(LorentzVector pp, LorentzVector pm) { auto ptp = pp.Pt(); auto ptm = pm.Pt(); From 36ad477d104fa42f643bf4d13d8ce66231e4af6c Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Wed, 13 Aug 2025 16:15:06 +0200 Subject: [PATCH 5/6] [nfc] Add free functions to GenVector doxygen group as suggested by Stephan Co-authored-by: Stephan Hageboeck --- math/genvector/inc/Math/GenVector/LorentzVector.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/math/genvector/inc/Math/GenVector/LorentzVector.h b/math/genvector/inc/Math/GenVector/LorentzVector.h index 27a3feb7929b5..589ffb5d748a4 100644 --- a/math/genvector/inc/Math/GenVector/LorentzVector.h +++ b/math/genvector/inc/Math/GenVector/LorentzVector.h @@ -736,6 +736,7 @@ Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. \param pp p+, mathcore::LorentzVector based on any coordinate system \param pm p-, mathcore::LorentzVector based on any coordinate system \return a scalar + \ingroup GenVector \see http://doi.org/10.1103/PhysRevLett.121.212301 */ template< class CoordSystem > @@ -762,6 +763,7 @@ Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. \param pp p+, mathcore::LorentzVector based on any coordinate system \param pm p-, mathcore::LorentzVector based on any coordinate system \return a scalar. Returns -1 if both momenta are exactly mirrored. + \ingroup GenVector \see http://doi.org/10.1103/PhysRevLett.121.212301, https://doi.org/10.1103/PhysRevD.99.093013 */ template< class CoordSystem > @@ -782,6 +784,7 @@ Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. \param pp p+, mathcore::LorentzVector based on any coordinate system \param pm p-, mathcore::LorentzVector based on any coordinate system \return a scalar. Returns 0 if both transverse momenta are zero + \ingroup GenVector \see http://doi.org/10.1103/PhysRevLett.121.212301, https://doi.org/10.1103/PhysRevD.99.093013 */ template< class CoordSystem > From 09e74417fab13a853eb0572a9bff63f6e3e70194 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Wed, 13 Aug 2025 16:16:14 +0200 Subject: [PATCH 6/6] [math] use const-ref for arguments to avoid non-trivial copies as suggested by Stephan Co-authored-by: Stephan Hageboeck --- math/genvector/inc/Math/GenVector/LorentzVector.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/math/genvector/inc/Math/GenVector/LorentzVector.h b/math/genvector/inc/Math/GenVector/LorentzVector.h index 589ffb5d748a4..158e475ca1bac 100644 --- a/math/genvector/inc/Math/GenVector/LorentzVector.h +++ b/math/genvector/inc/Math/GenVector/LorentzVector.h @@ -740,7 +740,7 @@ Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. \see http://doi.org/10.1103/PhysRevLett.121.212301 */ template< class CoordSystem > - typename LorentzVector::Scalar Acoplanarity(LorentzVector pp, LorentzVector pm) + typename LorentzVector::Scalar Acoplanarity(LorentzVector const &pp, LorentzVector const &pm) { auto dphi = pp.Phi() - pm.Phi(); // convert dphi angle to the interval (-PI,PI] @@ -767,7 +767,7 @@ Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. \see http://doi.org/10.1103/PhysRevLett.121.212301, https://doi.org/10.1103/PhysRevD.99.093013 */ template< class CoordSystem > - typename LorentzVector::Scalar AsymmetryVectorial(LorentzVector pp, LorentzVector pm) + typename LorentzVector::Scalar AsymmetryVectorial(LorentzVector const &pp, LorentzVector const &pm) { ROOT::Math::XYVector vp(pp.Px(), pp.Py()); ROOT::Math::XYVector vm(pm.Px(), pm.Py()); @@ -788,7 +788,7 @@ Pt (or rho) refers to transverse momentum, whereas eta refers to pseudorapidity. \see http://doi.org/10.1103/PhysRevLett.121.212301, https://doi.org/10.1103/PhysRevD.99.093013 */ template< class CoordSystem > - typename LorentzVector::Scalar AsymmetryScalar(LorentzVector pp, LorentzVector pm) + typename LorentzVector::Scalar AsymmetryScalar(LorentzVector const &pp, LorentzVector const &pm) { auto ptp = pp.Pt(); auto ptm = pm.Pt();