HEPJo is a high-performance library for numerical computations in particle physics, written in Mojo 🔥 similar to Scikit-HEP in Python.
Table of Contents
HEPJo is a high-performance library for numerical computations in particle physics, written in Mojo. Inspired by Scikit-HEP, it aims to provide fast and efficient implementations of common particle physics operations. The library currently includes implementations of LorentzVector, Vector3D, and Vector2D classes with plans to expand further.
- Clone the repository.
- Build the package using
mojo package hepjo - Move the hepjo.mojopkg into the directory containing the your code.
- High Performance: Written in Mojo for maximum speed and efficiency
- Vector Operations: Complete implementation of 2D, 3D, and 4D (Lorentz) vectors
- Physics Operations: Common particle physics calculations including boosts and transformations
- Type Safety: Strong typing and compile-time checks
- Scikit-HEP like Interface: Familiar API for physics computations
HEPJo is currently under development and does not yet have comprehensive documentation. Please refer to the tests and example code to explore the full range of functionalities available.
import hepjo as hj
from hepjo import Vector3D, LorentzVector
# Create and manipulate 3D vectors
var vec = hj.Vector3D(1.0, 2.0, 3.0)
var vec1 = hj.Vector3D(1.0, 2.0, 3.0)
print(vec.dot(vec1), vec @ vec1) # Both computes dot product
# Work with Lorentz vectors
var lvec = LorentzVector(1.0, 2.0, 3.0, 10.0) # px, py, pz, e
var restframe_lvec = lvec.torestframe() # Transform to rest frame
# Create Lorentz vector with given mass
var lvec1 = LorentzVector.setpxpypzm(3.0, 4.0, 5.0, 10.0)
var boosted_lvec = lvec.boost(lvec1.boostvector()) # Apply boost transformationThe Vector2D[dtype] class represents a two-dimensional vector.
__init__(x: Scalar[dtype], y: Scalar[dtype]): Initialize a 3D vectordot(other: Vector2D) -> Float64: Compute dot productcross(other: Vector2D) -> Vector3D: Compute cross productmag() -> Scalar[dtype]: Get vector magnitudemag2() -> Scalar[dtype]: Get squared magnitudeunit() -> Vector2D: Get unit vector
The Vector3D[dtype] class represents a three-dimensional vector with operations commonly used in particle physics.
__init__(x: Scalar[dtype], y: Scalar[dtype], z: Scalar[dtype]): Initialize a 3D vectordot(other: Vector3D) -> Float64: Compute dot productcross(other: Vector3D) -> Vector3D: Compute cross productmag() -> Scalar[dtype]: Get vector magnitudemag2() -> Scalar[dtype]: Get squared magnitudeunit() -> Vector3D: Get unit vector
The LorentzVector[dtype] class represents a four-momentum vector with operations for relativistic calculations.
__init__(px: Scalar[dtype], py: Scalar[dtype], pz: Scalar[dtype], e: Scalar[dtype]): Initialize with momentum components and energysetpxpypzm(px: Scalar[dtype], py: Scalar[dtype], pz: Scalar[dtype], m: Scalar[dtype]) -> LorentzVector: Create from momentum and masstorestframe() -> LorentzVector: Transform to rest frameboost(beta: Vector3D) -> LorentzVector: Apply Lorentz boostmass() -> Scalar[dtype]: Get invariant massmass2() -> Scalar[dtype]: Get squared invariant masspt() -> Scalar[dtype]: Get transverse momentumeta() -> Scalar[dtype]: Get pseudorapidityphi() -> Scalar[dtype]: Get azimuthal angleboostvector() -> Vector3D: Get boost vector
from hepjo import LorentzVector
# Create two particles
var particle1 = LorentzVector.setpxpypzm(10.0, 20.0, 30.0, 0.139) # pion
var particle2 = LorentzVector.setpxpypzm(-5.0, 15.0, 25.0, 0.139) # pion
# Compute invariant mass of the system
var system = particle1 + particle2
print(system.mass()) # Print invariant massfrom hepjo import LorentzVector
# Create a particle system
var particle = LorentzVector(5.0, 0.0, 0.0, 10.0) # px, py, pz, e
var lab_frame = LorentzVector(0.0, 0.0, 8.0, 12.0)
# Boost to center of mass frame
var cm_frame = particle.boost(lab_frame.boostvector())
print(cm_frame.p()) # Print momentum in CM frameContributions are welcome! Please feel free to report issues and submit a Pull Request.
Distributed under the Apache 2.0 License with LLVM Exceptions. See LICENSE and the LLVM License for more information.
- Integration with PDG particle data.
- Implement a System of Units similar to GEANT4.
- Integration with common HEP analysis frameworks.
- GPU support for large array computations.
- Add more Mojo backends such as NuMojo.
If you find HEPJo useful in your research adventures, consider giving it a shout-out in your citations!
@software{hepjo,
author = {ShivaSankar K.A},
title = {HEPJo: High Performance Particle Physics in Mojo},
year = {2024},
url = {https://github.com/shivasankarka/hepjo}
}