go-hep.org/x/hep@v0.38.1/fmom/eetaphim.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  	"fmt"
     9  	"math"
    10  )
    11  
    12  type EEtaPhiM struct {
    13  	P4 Vec4
    14  }
    15  
    16  func NewEEtaPhiM(e, eta, phi, m float64) EEtaPhiM {
    17  	return EEtaPhiM{P4: Vec4{X: e, Y: eta, Z: phi, T: m}}
    18  }
    19  
    20  func (p4 EEtaPhiM) String() string {
    21  	return fmt.Sprintf(
    22  		"fmom.P4{E:%v, Eta:%v, Phi:%v, M:%v}",
    23  		p4.E(), p4.Eta(), p4.Phi(), p4.M(),
    24  	)
    25  }
    26  
    27  func (p4 *EEtaPhiM) Clone() P4 {
    28  	pp := *p4
    29  	return &pp
    30  }
    31  
    32  func (p4 *EEtaPhiM) E() float64 {
    33  	return p4.P4.X
    34  }
    35  
    36  func (p4 *EEtaPhiM) Eta() float64 {
    37  	return p4.P4.Y
    38  }
    39  
    40  func (p4 *EEtaPhiM) Phi() float64 {
    41  	return p4.P4.Z
    42  }
    43  
    44  func (p4 *EEtaPhiM) M() float64 {
    45  	return p4.P4.T
    46  }
    47  
    48  func (p4 *EEtaPhiM) M2() float64 {
    49  	m := p4.M()
    50  	return m * m
    51  }
    52  
    53  func (p4 *EEtaPhiM) P() float64 {
    54  	m := p4.M()
    55  	e := p4.E()
    56  	if m == 0 {
    57  		return e
    58  	}
    59  	sign := 1.0
    60  	if e < 0 {
    61  		sign = -1.0
    62  	}
    63  	return sign * math.Sqrt(e*e-m*m)
    64  }
    65  func (p4 *EEtaPhiM) P2() float64 {
    66  	m := p4.M()
    67  	e := p4.E()
    68  	return e*e - m*m
    69  }
    70  
    71  func (p4 *EEtaPhiM) CosPhi() float64 {
    72  	phi := p4.Phi()
    73  	return math.Cos(phi)
    74  }
    75  
    76  func (p4 *EEtaPhiM) SinPhi() float64 {
    77  	phi := p4.Phi()
    78  	return math.Sin(phi)
    79  }
    80  
    81  func (p4 *EEtaPhiM) TanTh() float64 {
    82  	eta := p4.Eta()
    83  	abseta := math.Abs(eta)
    84  	// avoid numeric overflow if very large eta
    85  	if abseta > 710 {
    86  		if eta > 0 {
    87  			eta = +710
    88  		} else {
    89  			eta = -710
    90  		}
    91  	}
    92  	return 1. / math.Sinh(eta)
    93  }
    94  
    95  func (p4 *EEtaPhiM) CotTh() float64 {
    96  	eta := p4.Eta()
    97  	return math.Sinh(eta)
    98  }
    99  
   100  func (p4 *EEtaPhiM) CosTh() float64 {
   101  	eta := p4.Eta()
   102  	return math.Tanh(eta)
   103  }
   104  
   105  func (p4 *EEtaPhiM) SinTh() float64 {
   106  	eta := p4.Eta()
   107  	abseta := min(math.Abs(eta), 710)
   108  	return 1 / math.Cosh(abseta)
   109  }
   110  
   111  func (p4 *EEtaPhiM) Pt() float64 {
   112  	p := p4.P()
   113  	sinth := p4.SinTh()
   114  	return p * sinth
   115  }
   116  
   117  func (p4 *EEtaPhiM) Et() float64 {
   118  	e := p4.E()
   119  	sinth := p4.SinTh()
   120  	return e * sinth
   121  }
   122  
   123  func (p4 *EEtaPhiM) IPt() float64 {
   124  	pt := p4.Pt()
   125  	return 1 / pt
   126  }
   127  
   128  func (p4 *EEtaPhiM) Rapidity() float64 {
   129  	e := p4.E()
   130  	pz := p4.Pz()
   131  	return 0.5 * math.Log((e+pz)/(e-pz))
   132  }
   133  
   134  func (p4 *EEtaPhiM) Px() float64 {
   135  	pt := p4.Pt()
   136  	cosphi := p4.CosPhi()
   137  	return pt * cosphi
   138  }
   139  
   140  func (p4 *EEtaPhiM) Py() float64 {
   141  	pt := p4.Pt()
   142  	sinphi := p4.SinPhi()
   143  	return pt * sinphi
   144  }
   145  
   146  func (p4 *EEtaPhiM) Pz() float64 {
   147  	p := p4.P()
   148  	costh := p4.CosTh()
   149  	return p * costh
   150  }
   151  
   152  func (p4 *EEtaPhiM) Set(p P4) {
   153  	p4.P4.X = p.E()
   154  	p4.P4.Y = p.Eta()
   155  	p4.P4.Z = p.Phi()
   156  	p4.P4.T = p.M()
   157  }
   158  
   159  var (
   160  	_ P4           = (*EEtaPhiM)(nil)
   161  	_ fmt.Stringer = (*EEtaPhiM)(nil)
   162  )