go-hep.org/x/hep@v0.38.1/fads/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 fads
     6  
     7  import (
     8  	"math"
     9  
    10  	"go-hep.org/x/hep/fmom"
    11  )
    12  
    13  type int64Slice []int64
    14  
    15  func (p int64Slice) Len() int {
    16  	return len(p)
    17  }
    18  
    19  func (p int64Slice) Less(i, j int) bool {
    20  	return p[i] < p[j]
    21  }
    22  
    23  func (p int64Slice) Swap(i, j int) {
    24  	p[i], p[j] = p[j], p[i]
    25  }
    26  
    27  // ByPt sorts candidate by descending Pt
    28  type ByPt []Candidate
    29  
    30  func (p ByPt) Len() int {
    31  	return len(p)
    32  }
    33  
    34  func (p ByPt) Less(i, j int) bool {
    35  	return p[i].Mom.Pt() > p[j].Mom.Pt()
    36  }
    37  
    38  func (p ByPt) Swap(i, j int) {
    39  	p[i], p[j] = p[j], p[i]
    40  }
    41  
    42  func newPtEtaPhiE(pt, eta, phi, ene float64) fmom.PxPyPzE {
    43  	pt = math.Abs(pt)
    44  
    45  	px := pt * math.Cos(phi)
    46  	py := pt * math.Sin(phi)
    47  	pz := pt * math.Sinh(eta)
    48  
    49  	return fmom.NewPxPyPzE(px, py, pz, ene)
    50  }