go-hep.org/x/hep@v0.38.1/fmom/ptetaphim_test.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_test 6 7 import ( 8 "math" 9 "testing" 10 11 "go-hep.org/x/hep/fmom" 12 ) 13 14 func TestPtEtaPhiM(t *testing.T) { 15 { 16 var p4 fmom.PtEtaPhiM 17 if got, want := p4.Pt(), 0.0; got != want { 18 t.Fatalf("p4.Pt=%v, want=%v", got, want) 19 } 20 if got, want := p4.Eta(), 0.0; got != want { 21 t.Fatalf("p4.Eta=%v, want=%v", got, want) 22 } 23 if got, want := p4.Phi(), 0.0; got != want { 24 t.Fatalf("p4.Phi=%v, want=%v", got, want) 25 } 26 if got, want := p4.M(), 0.0; got != want { 27 t.Fatalf("p4.M=%v, want=%v", got, want) 28 } 29 if got, want := p4.String(), "fmom.P4{Pt:0, Eta:0, Phi:0, M:0}"; got != want { 30 t.Fatalf("p4=%v, want=%v", got, want) 31 } 32 } 33 34 { 35 p4 := fmom.NewPtEtaPhiM(10, 11, 12, 20) 36 if got, want := p4.Pt(), 10.0; got != want { 37 t.Fatalf("p4.Pt=%v, want=%v", got, want) 38 } 39 if got, want := p4.Eta(), 11.0; got != want { 40 t.Fatalf("p4.Eta=%v, want=%v", got, want) 41 } 42 if got, want := p4.Phi(), 12.0; got != want { 43 t.Fatalf("p4.Phi=%v, want=%v", got, want) 44 } 45 if got, want := p4.M(), 20.0; got != want { 46 t.Fatalf("p4.M=%v, want=%v", got, want) 47 } 48 if got, want := p4.String(), "fmom.P4{Pt:10, Eta:11, Phi:12, M:20}"; got != want { 49 t.Fatalf("p4=%v, want=%v", got, want) 50 } 51 52 p1 := fmom.NewPtEtaPhiM(10, 11, 12, 20) 53 if p1 != p4 { 54 t.Fatalf("p4=%v, want=%v", p1, p4) 55 } 56 57 var p2 fmom.PtEtaPhiM = p1 58 if p1 != p2 { 59 t.Fatalf("p4=%v, want=%v", p1, p2) 60 } 61 } 62 63 { 64 p1 := fmom.NewPtEtaPhiM(10, 11, 12, 20) 65 var p2 fmom.PtEtaPhiM 66 p2.Set(&p1) 67 if p1 != p2 { 68 t.Fatalf("p4=%v want=%v", p2, p1) 69 } 70 } 71 72 ref := fmom.NewPxPyPzE(10, 11, 12, 20) 73 var p fmom.PtEtaPhiM 74 p.Set(&ref) 75 76 for i, v := range []float64{ 77 math.Abs(p.Pt() - ref.Pt()), 78 math.Abs(p.Eta() - ref.Eta()), 79 math.Abs(p.Phi() - ref.Phi()), 80 math.Abs(p.M() - ref.M()), 81 82 math.Abs(math.Atan2(p.SinPhi(), p.CosPhi()) - p.Phi()), 83 math.Abs(p.SinPhi()*p.SinPhi() + p.CosPhi()*p.CosPhi() - 1.0), 84 math.Abs(-math.Log(math.Tan(math.Atan(p.TanTh())*0.5)) - p.Eta()), 85 } { 86 if v > epsilon { 87 t.Fatalf("test [%d]: value out of tolerance", i) 88 } 89 90 } 91 }