Skip to content

all: introduce fmom.Vec4, make fmom.PxPyPzE a struct instead of [4]float64 #594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 25, 2020
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
12 changes: 6 additions & 6 deletions cmd/lhef2hepmc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,21 @@ func main() {
Barcode: -1,
}
p1 := hepmc.Particle{
Momentum: fmom.PxPyPzE{
Momentum: fmom.NewPxPyPzE(
0, 0,
dec.Run.EBMUP[0],
dec.Run.EBMUP[0],
},
),
PdgID: dec.Run.IDBMUP[0],
Status: 4,
Barcode: 1,
}
p2 := hepmc.Particle{
Momentum: fmom.PxPyPzE{
Momentum: fmom.NewPxPyPzE(
0, 0,
dec.Run.EBMUP[1],
dec.Run.EBMUP[1],
},
),
PdgID: dec.Run.IDBMUP[1],
Status: 4,
Barcode: 2,
Expand All @@ -170,12 +170,12 @@ func main() {
}
nmax += 1
vtx.AddParticleOut(&hepmc.Particle{
Momentum: fmom.PxPyPzE{
Momentum: fmom.NewPxPyPzE(
lhevt.PUP[i][0],
lhevt.PUP[i][1],
lhevt.PUP[i][2],
lhevt.PUP[i][3],
},
),
GeneratedMass: lhevt.PUP[i][4],
PdgID: lhevt.IDUP[i],
Status: 1,
Expand Down
8 changes: 5 additions & 3 deletions fads/fastjet_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ func (tsk *FastJetFinder) Process(ctx fwk.Context) error {
dphiMax := 0.0
output = make([]Candidate, 0, len(outjets))
for i := range outjets {
jet := &outjets[i]
area := fmom.PxPyPzE{0, 0, 0, 0}
var (
jet = &outjets[i]
area fmom.PxPyPzE
)
if tsk.areaDef != nil {
// FIXME
panic("not implemented")
Expand Down Expand Up @@ -187,7 +189,7 @@ func (tsk *FastJetFinder) Process(ctx fwk.Context) error {
cand.Add(cst)
}

cand.Pos[3] = time / wtime
cand.Pos.P4.T = time / wtime
cand.Area = area
cand.DEta = detaMax
cand.DPhi = dphiMax
Expand Down
2 changes: 1 addition & 1 deletion fads/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ func newPtEtaPhiE(pt, eta, phi, ene float64) fmom.PxPyPzE {
py := pt * math.Sin(phi)
pz := pt * math.Sinh(eta)

return fmom.PxPyPzE{px, py, pz, ene}
return fmom.NewPxPyPzE(px, py, pz, ene)
}
24 changes: 13 additions & 11 deletions fmom/eetaphim.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"math"
)

type EEtaPhiM [4]float64
type EEtaPhiM struct {
P4 Vec4
}

func NewEEtaPhiM(et, eta, phi, m float64) EEtaPhiM {
return EEtaPhiM([4]float64{et, eta, phi, m})
func NewEEtaPhiM(e, eta, phi, m float64) EEtaPhiM {
return EEtaPhiM{P4: Vec4{X: e, Y: eta, Z: phi, T: m}}
}

func (p4 *EEtaPhiM) Clone() P4 {
Expand All @@ -20,19 +22,19 @@ func (p4 *EEtaPhiM) Clone() P4 {
}

func (p4 *EEtaPhiM) E() float64 {
return p4[0]
return p4.P4.X
}

func (p4 *EEtaPhiM) Eta() float64 {
return p4[1]
return p4.P4.Y
}

func (p4 *EEtaPhiM) Phi() float64 {
return p4[2]
return p4.P4.Z
}

func (p4 *EEtaPhiM) M() float64 {
return p4[3]
return p4.P4.T
}

func (p4 *EEtaPhiM) M2() float64 {
Expand Down Expand Up @@ -143,8 +145,8 @@ func (p4 *EEtaPhiM) Pz() float64 {
}

func (p4 *EEtaPhiM) Set(p P4) {
p4[0] = p.E()
p4[1] = p.Eta()
p4[2] = p.Phi()
p4[3] = p.M()
p4.P4.X = p.E()
p4.P4.Y = p.Eta()
p4.P4.Z = p.Phi()
p4.P4.T = p.M()
}
22 changes: 12 additions & 10 deletions fmom/etetaphim.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"math"
)

type EtEtaPhiM [4]float64
type EtEtaPhiM struct {
P4 Vec4
}

func NewEtEtaPhiM(et, eta, phi, m float64) EtEtaPhiM {
return EtEtaPhiM([4]float64{et, eta, phi, m})
return EtEtaPhiM{P4: Vec4{X: et, Y: eta, Z: phi, T: m}}
}

func (p4 *EtEtaPhiM) Clone() P4 {
Expand All @@ -20,19 +22,19 @@ func (p4 *EtEtaPhiM) Clone() P4 {
}

func (p4 *EtEtaPhiM) Et() float64 {
return p4[0]
return p4.P4.X
}

func (p4 *EtEtaPhiM) Eta() float64 {
return p4[1]
return p4.P4.Y
}

func (p4 *EtEtaPhiM) Phi() float64 {
return p4[2]
return p4.P4.Z
}

func (p4 *EtEtaPhiM) M() float64 {
return p4[3]
return p4.P4.T
}

func (p4 *EtEtaPhiM) M2() float64 {
Expand Down Expand Up @@ -143,8 +145,8 @@ func (p4 *EtEtaPhiM) Pz() float64 {
}

func (p4 *EtEtaPhiM) Set(p P4) {
p4[0] = p.Et()
p4[1] = p.Eta()
p4[2] = p.Phi()
p4[3] = p.M()
p4.P4.X = p.Et()
p4.P4.Y = p.Eta()
p4.P4.Z = p.Phi()
p4.P4.T = p.M()
}
22 changes: 12 additions & 10 deletions fmom/iptcotthphim.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"math"
)

type IPtCotThPhiM [4]float64
type IPtCotThPhiM struct {
P4 Vec4
}

func NewIPtCotThPhiM(pt, eta, phi, m float64) IPtCotThPhiM {
return IPtCotThPhiM([4]float64{pt, eta, phi, m})
return IPtCotThPhiM{P4: Vec4{X: pt, Y: eta, Z: phi, T: m}}
}

func (p4 *IPtCotThPhiM) Clone() P4 {
Expand All @@ -20,19 +22,19 @@ func (p4 *IPtCotThPhiM) Clone() P4 {
}

func (p4 *IPtCotThPhiM) IPt() float64 {
return p4[0]
return p4.P4.X
}

func (p4 *IPtCotThPhiM) CotTh() float64 {
return p4[1]
return p4.P4.Y
}

func (p4 *IPtCotThPhiM) Phi() float64 {
return p4[2]
return p4.P4.Z
}

func (p4 *IPtCotThPhiM) M() float64 {
return p4[3]
return p4.P4.T
}

func (p4 *IPtCotThPhiM) Pt() float64 {
Expand Down Expand Up @@ -137,8 +139,8 @@ func (p4 *IPtCotThPhiM) SinPhi() float64 {
}

func (p4 *IPtCotThPhiM) Set(p P4) {
p4[0] = p.IPt()
p4[1] = p.CotTh()
p4[2] = p.Phi()
p4[3] = p.M()
p4.P4.X = p.IPt()
p4.P4.Y = p.CotTh()
p4.P4.Z = p.Phi()
p4.P4.T = p.M()
}
8 changes: 4 additions & 4 deletions fmom/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ func IAdd(dst, src P4) P4 {
default:
panic(fmt.Errorf("fmom: invalid P4 concrete value: %#v", dst))
}
p4[0] += src.Px()
p4[1] += src.Py()
p4[2] += src.Pz()
p4[3] += src.E()
p4.P4.X += src.Px()
p4.P4.Y += src.Py()
p4.P4.Z += src.Pz()
p4.P4.T += src.E()
sum.Set(p4)
return sum
}
Expand Down
5 changes: 5 additions & 0 deletions fmom/p4.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ type P4 interface {
Set(p4 P4)
Clone() P4
}

// Vec4 holds the four components of a Lorentz vector.
type Vec4 struct {
X, Y, Z, T float64
}
22 changes: 12 additions & 10 deletions fmom/ptetaphim.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"math"
)

type PtEtaPhiM [4]float64
type PtEtaPhiM struct {
P4 Vec4
}

func NewPtEtaPhiM(pt, eta, phi, m float64) PtEtaPhiM {
return PtEtaPhiM([4]float64{pt, eta, phi, m})
return PtEtaPhiM{P4: Vec4{X: pt, Y: eta, Z: phi, T: m}}
}

func (p4 *PtEtaPhiM) Clone() P4 {
Expand All @@ -20,19 +22,19 @@ func (p4 *PtEtaPhiM) Clone() P4 {
}

func (p4 *PtEtaPhiM) Pt() float64 {
return p4[0]
return p4.P4.X
}

func (p4 *PtEtaPhiM) Eta() float64 {
return p4[1]
return p4.P4.Y
}

func (p4 *PtEtaPhiM) Phi() float64 {
return p4[2]
return p4.P4.Z
}

func (p4 *PtEtaPhiM) M() float64 {
return p4[3]
return p4.P4.T
}

func (p4 *PtEtaPhiM) E() float64 {
Expand Down Expand Up @@ -150,8 +152,8 @@ func (p4 *PtEtaPhiM) Pz() float64 {
}

func (p4 *PtEtaPhiM) Set(p P4) {
p4[0] = p.Pt()
p4[1] = p.Eta()
p4[2] = p.Phi()
p4[3] = p.M()
p4.P4.X = p.Pt()
p4.P4.Y = p.Eta()
p4.P4.Z = p.Phi()
p4.P4.T = p.M()
}
52 changes: 16 additions & 36 deletions fmom/pxpypze.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,28 @@ import (
"math"
)

type PxPyPzE [4]float64
type PxPyPzE struct {
P4 Vec4
}

func NewPxPyPzE(px, py, pz, e float64) PxPyPzE {
return PxPyPzE([4]float64{px, py, pz, e})
return PxPyPzE{P4: Vec4{X: px, Y: py, Z: pz, T: e}}
}

func (p4 *PxPyPzE) Clone() P4 {
pp := *p4
return &pp
}

func (p4 *PxPyPzE) Px() float64 {
return p4[0]
}

func (p4 *PxPyPzE) Py() float64 {
return p4[1]
}

func (p4 *PxPyPzE) Pz() float64 {
return p4[2]
}

func (p4 *PxPyPzE) E() float64 {
return p4[3]
}
func (p4 *PxPyPzE) Px() float64 { return p4.P4.X }
func (p4 *PxPyPzE) Py() float64 { return p4.P4.Y }
func (p4 *PxPyPzE) Pz() float64 { return p4.P4.Z }
func (p4 *PxPyPzE) E() float64 { return p4.P4.T }

func (p4 *PxPyPzE) X() float64 {
return p4[0]
}

func (p4 *PxPyPzE) Y() float64 {
return p4[1]
}

func (p4 *PxPyPzE) Z() float64 {
return p4[2]
}

func (p4 *PxPyPzE) T() float64 {
return p4[3]
}
func (p4 *PxPyPzE) X() float64 { return p4.P4.X }
func (p4 *PxPyPzE) Y() float64 { return p4.P4.Y }
func (p4 *PxPyPzE) Z() float64 { return p4.P4.Z }
func (p4 *PxPyPzE) T() float64 { return p4.P4.T }

func (p4 *PxPyPzE) M2() float64 {
px := p4.Px()
Expand Down Expand Up @@ -206,8 +186,8 @@ func (p4 *PxPyPzE) Rapidity() float64 {
}

func (p4 *PxPyPzE) Set(p P4) {
p4[0] = p.Px()
p4[1] = p.Py()
p4[2] = p.Pz()
p4[3] = p.E()
p4.P4.X = p.Px()
p4.P4.Y = p.Py()
p4.P4.Z = p.Pz()
p4.P4.T = p.E()
}
Loading