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