Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ShipSoft/FairShip/llms.txt

Use this file to discover all available pages before exploring further.

The shipunit module defines the physical unit system used throughout FairShip. It is derived from CLHEP’s SystemOfUnits.h and adapted for use with FairROOT. All quantities in FairShip geometry, energy, time, and momentum are expressed in these units. The two fundamental base units are centimeter (1.0, for length) and GeV (1.0, for energy); all other units are defined as dimensionless scale factors relative to those bases. To convert a value stored internally to a desired unit, divide by the unit constant — for example, length_cm = pos / u.cm.
import shipunit as u

# Construct physical quantities
mass    = 1.0 * u.GeV          # 1 GeV (internal: 1.0)
length  = 50.0 * u.cm          # 50 cm (internal: 50.0)
time    = 100.0 * u.ns         # 100 ns (internal: 100.0)
angle   = 30.0 * u.degree      # 30° in radians

# Convert back to human units by dividing
print(f"Mass in MeV:    {mass / u.MeV:.1f}")    # 1000.0
print(f"Length in mm:   {length / u.mm:.1f}")   # 500.0
print(f"Time in μs:     {time / u.microsecond:.4f}")
print(f"Angle in mrad:  {angle / u.mrad:.2f}")

# Speed of light and particle β·γ kinematics
p   = 10.0 * u.GeV
m0  = 0.938 * u.GeV
E   = (p**2 + m0**2) ** 0.5
print(f"c_light = {u.c_light / (u.m / u.s):.6e} m/s")

Length units

All length units are defined relative to the millimeter (millimeter = 0.1), making the centimeter the true internal base unit (centimeter = 1.0).
SymbolFull nameValue in internal units (cm)
mmmillimeter0.1
cmcentimeter1.0
mmeter1 000
kmkilometer100 000
ummicrometer1 × 10⁻⁴
nmnanometer1 × 10⁻⁷
angstromangstrom1 × 10⁻⁸
fermifermi1 × 10⁻¹³
pcparsec3.0856775807 × 10¹⁸
Area and volume powers are also defined: mm2, mm3, cm2, cm3, m2, m3, km2, km3. Cross-section units (area):
SymbolFull nameValue
barnbarn1 × 10⁻²⁴ cm²
millibarnmillibarn1 × 10⁻²⁷ cm²
microbarnmicrobarn1 × 10⁻³⁰ cm²
nanobarnnanobarn1 × 10⁻³³ cm²
picobarnpicobarn1 × 10⁻³⁶ cm²

Energy units

The base energy unit is the gigaelectronvolt (GeV = 1.0). The megaelectronvolt is defined as MeV = 1/1000.
SymbolFull nameValue in internal units (GeV)
eVelectronvolt1 × 10⁻⁹
keVkiloelectronvolt1 × 10⁻⁶
MeVmegaelectronvolt1 × 10⁻³
GeVgigaelectronvolt1.0
TeVteraelectronvolt1 × 10³
PeVpetaelectronvolt1 × 10⁶
joulejouleeV / e_SI ≈ 6.2415 × 10¹² MeV

Time units

The base time unit is the nanosecond (nanosecond = 1.0).
SymbolFull nameValue in internal units (ns)
nsnanosecond1.0
msmillisecond1 × 10⁶
ssecond1 × 10⁹
microsecondmicrosecond1 × 10³
picosecondpicosecond1 × 10⁻³
hertzhertz1 / second
kilohertzkilohertz1 × 10³ Hz
megahertzmegahertz1 × 10⁶ Hz

Angle units

SymbolFull nameValue
radradian1.0
mradmilliradian1 × 10⁻³
degdegreeπ / 180
srsteradian1.0

Mass units

Mass is a derived unit: kilogram = joule · s² / m².
SymbolFull nameValue
kgkilogramjoule * second² / meter²
ggram1 × 10⁻³ kg
mgmilligram1 × 10⁻⁶ kg

Magnetic field units

FairROOT and Geant3 use kilogauss as the internal field unit (kilogauss = 1.0).
SymbolFull nameValue in internal units (kG)
kilogausskilogauss1.0
teslatesla10.0
gaussgauss1 × 10⁻⁴

Electric charge and potential

SymbolFull nameNotes
epluspositron charge1.0 (internal)
e_SIpositron charge in Coulombs1.60217733 × 10⁻¹⁹ C
coulombcoulombeplus / e_SI
voltvolt1 × 10⁻⁶ MV
kilovoltkilovolt1 × 10⁻³ MV
megavoltmegavoltMeV / eplus

Pressure units

SymbolFull nameNotes
pascalpascalnewton / m²
barbar1 × 10⁵ Pa
atmosphereatmosphere101 325 Pa

Physical constants

The module also exports fundamental constants derived from the unit system.
ConstantDescriptionValue
piπ3.14159265358979
twopi6.28318…
halfpiπ/21.5707…
c_lightSpeed of light2.99792458 × 10⁸ m/s
c_squaredc_light²
h_PlanckPlanck constant6.6260755 × 10⁻³⁴ J·s
hbar_Planckh_Planck / 2π
hbarcℏ·c197.32705 × 10⁻¹² MeV·mm
electron_mass_c2Electron mass0.51099906 MeV
proton_mass_c2Proton mass938.27231 MeV
neutron_mass_c2Neutron mass939.56563 MeV
amu_c2Atomic mass unit931.49432 MeV
AvogadroAvogadro number6.0221367 × 10²³ /mol
k_BoltzmannBoltzmann constant8.617385 × 10⁻¹¹ MeV/K
fine_structure_constFine structure constant αelm_coupling / hbarc
classic_electr_radiusClassical electron radiuselm_coupling / electron_mass_c2
speedOfLightSpeed of light (alias)299792458 m/s
STP_TemperatureStandard temperature273.15 K
STP_PressureStandard pressure1 atm
universe_mean_densityMean cosmic density1 × 10⁻²⁵ g/cm³

Miscellaneous fractional constants

import shipunit as u

u.perCent      # 0.01
u.perThousand  # 0.001
u.perMillion   # 0.000001

Common patterns

import shipunit as u

# Detector geometry: magnet aperture
aperture = 2.5 * u.m           # store in cm internally

# Momentum threshold cut
p_min = 1.0 * u.GeV            # store in GeV internally

# Cross-section: express in pb
xs = 3.7e-8 * u.picobarn

# Density threshold for gas volumes
kGasThreshold = 10.0 * u.mg / u.cm3

# Convert: divide by the target unit
print(f"aperture = {aperture / u.cm:.1f} cm")
print(f"p_min    = {p_min / u.MeV:.0f} MeV")

Build docs developers (and LLMs) love