go-hep.org/x/hep@v0.38.1/fmom/utils.go (about) 1 // Copyright ©2017 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package fmom 6 7 import ( 8 "math" 9 10 "gonum.org/v1/gonum/spatial/r3" 11 ) 12 13 const ( 14 twopi = 2 * math.Pi 15 ) 16 17 // DeltaPhi returns the delta Phi in range [-pi,pi[ from two P4 18 func DeltaPhi(p1, p2 P4) float64 { 19 // FIXME: do something more efficient when p1&p2 are PxPyPzE 20 dphi := p1.Phi() - p2.Phi() 21 return -math.Remainder(dphi, twopi) 22 } 23 24 // DeltaEta returns the delta Eta between two P4 25 func DeltaEta(p1, p2 P4) float64 { 26 // FIXME: do something more efficient when p1&p2 are PxPyPzE 27 return p1.Eta() - p2.Eta() 28 } 29 30 // DeltaR returns the delta R between two P4 31 func DeltaR(p1, p2 P4) float64 { 32 deta := DeltaEta(p1, p2) 33 dphi := DeltaPhi(p1, p2) 34 return math.Sqrt(deta*deta + dphi*dphi) 35 } 36 37 // Dot returns the dot product p1·p2. 38 func Dot(p1, p2 P4) float64 { 39 return p1.E()*p2.E() - p1.Px()*p2.Px() - p1.Py()*p2.Py() - p1.Pz()*p2.Pz() 40 } 41 42 // CosTheta returns the cosine of the angle between the momentum of two 4-vectors. 43 func CosTheta(p1, p2 P4) float64 { 44 mag1 := p1.P2() 45 mag2 := p2.P2() 46 dot := r3.Dot(VecOf(p1), VecOf(p2)) 47 cosTh := dot / math.Sqrt(mag1*mag2) 48 return cosTh 49 }