aegir
Phlex-based simulation framework for the SHiP experiment.
Loading...
Searching...
No Matches
clhep_bridge.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 CERN for the benefit of the SHiP Collaboration
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5// clhep_bridge.hpp — the one place aegir touches CLHEP unit constants
6//
7// Geant4 works in CLHEP internal units (mm/ns/MeV); the framework works in
8// the canonical ShipSoft quantities (SHiP/Units.hpp: mm/ns/GeV, GeV/c). Raw
9// Geant4 doubles must acquire their unit here on ingest and only leave a
10// quantity via g4() on egress. Do not include G4SystemOfUnits.hh anywhere in
11// aegir: it injects unqualified globals (mm, GeV, tesla, ...) that collide
12// with the mp-units vocabulary.
13
14#pragma once
15
16#include <CLHEP/Units/SystemOfUnits.h>
17
18#include <G4ThreeVector.hh>
19#include <G4Types.hh>
20#include <SHiP/Units.hpp>
21
22namespace aegir::clhep {
23
24namespace su = ship::units;
25
26// --- ingest: Geant4 internal double -> canonical quantity -------------------
27
28[[nodiscard]] inline ship::Length length(G4double v) {
29 return (v / CLHEP::mm) * su::mm;
30}
31[[nodiscard]] inline ship::Time time(G4double v) {
32 return (v / CLHEP::ns) * su::ns;
33}
34[[nodiscard]] inline ship::Energy energy(G4double v) {
35 return (v / CLHEP::GeV) * su::GeV;
36}
37// Geant4 momenta are energy-scaled (p*c, internal MeV).
38[[nodiscard]] inline ship::Momentum momentum(G4double v) {
39 return (v / CLHEP::GeV) * su::GeV_per_c;
40}
41[[nodiscard]] inline ship::Vec3<ship::Length> position(G4ThreeVector const& v) {
42 return {length(v.x()), length(v.y()), length(v.z())};
43}
44[[nodiscard]] inline ship::Vec3<ship::Momentum> momentum(
45 G4ThreeVector const& v) {
46 return {momentum(v.x()), momentum(v.y()), momentum(v.z())};
47}
48
49// --- egress: canonical quantity -> Geant4 internal double -------------------
50
51[[nodiscard]] inline G4double g4(ship::Length l) {
52 return l.numerical_value_in(su::mm) * CLHEP::mm;
53}
54[[nodiscard]] inline G4double g4(ship::Time t) {
55 return t.numerical_value_in(su::ns) * CLHEP::ns;
56}
57[[nodiscard]] inline G4double g4(ship::Energy e) {
58 return e.numerical_value_in(su::GeV) * CLHEP::GeV;
59}
60// The one consciously-bridged c convention: a GeV/c quantity becomes the
61// numeric GeV value Geant4 expects for momenta.
62[[nodiscard]] inline G4double g4(ship::Momentum p) {
63 return p.numerical_value_in(su::GeV_per_c) * CLHEP::GeV;
64}
65
66} // namespace aegir::clhep
Definition clhep_bridge.hpp:22
ship::Energy energy(G4double v)
Definition clhep_bridge.hpp:34
ship::Length length(G4double v)
Definition clhep_bridge.hpp:28
ship::Vec3< ship::Length > position(G4ThreeVector const &v)
Definition clhep_bridge.hpp:41
ship::Momentum momentum(G4double v)
Definition clhep_bridge.hpp:38
G4double g4(ship::Length l)
Definition clhep_bridge.hpp:51
ship::Time time(G4double v)
Definition clhep_bridge.hpp:31