Unintuitive behavior of `Math::PxPyPzMVector` in calculations
Check duplicate issues.
- [X] Checked for duplicates
Description
Depending on the mixture of 4-vector types and the order of operations the result can change, e.g. lv1 - lv2 != -lv2 + lv1 See reproducer for all combinations.
Reproducer
import ROOT
lv1 = ROOT.Math.PxPyPzEVector(0, 0, 1, 1)
lv2 = ROOT.Math.PxPyPzMVector(lv1)
print(lv1 - lv2)
# (0,0,0,0)
print(lv2 - lv1)
# (0,0,0,0)
print(-lv1 + lv2)
# (0,0,0,0)
print(-lv2 + lv1)
# (0,0,0,2)
but I am relatively sure that it will also happen in c++
ROOT version
ROOT Version: 6.33.01
Built for linuxx8664gcc on Jun 12 2024, 23:54:24
From heads/master@v6-31-01-2329-g4fe33d2d91
Installation method
LCG dev3
Operating system
Alma9
Additional context
No response
Hi, I think this is a known limitation of the design
The issue here is not a mixture of vector classes but a negation of a vector from a coordinate system using mass (so just the PxPyPzMVector part):
root [0] auto v = ROOT::Math::PxPyPzMVector(0,0,1,0)
(ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> > &) (0,0,1,0)
root [1] v-v
(ROOT::Math::LorentzVector) (0,0,0,0)
root [2] v+(-v)
(ROOT::Math::LorentzVector) (0,0,0,2)
For coordinate systems represented with mass an unary operator- doesn't model a '4-vector negation' operation, because it returns a vector with negated momentum and negated mass instead of returning a properly negated 4-vector. A negated 4-vector should have negated momentum and negated energy but the same mass, and that can't be achieved with a representation containing only momentum and mass. It could be done by introducing another member (sign of energy), but that would be intrusive into design
Hi @dpiparo, @lmoneta,
It appears this issue is closed, but wasn't yet added to a project. Please add upcoming versions that will include the fix, or 'not applicable' otherwise.
Sincerely, :robot: