aegir
Phlex-based simulation framework for the SHiP experiment.
Loading...
Searching...
No Matches
math_utils.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// math_utils.hpp — small numeric helpers shared across plugins
6
7#pragma once
8
9#include <SHiP/Units.hpp>
10#include <array>
11#include <cmath>
12
13namespace aegir {
14
15// Euclidean norm of a raw 3-vector already in storage units (momentum,
16// position, ...) — e.g. straight off a persisted struct.
17inline double magnitude(std::array<double, 3> const& v) {
18 return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
19}
20
21// Euclidean norm of a quantity 3-vector. Delegates to the double overload on
22// the bitwise-unwrapped components, so wrapping never changes the result.
23template <typename Q>
24[[nodiscard]] inline Q magnitude(ship::Vec3<Q> const& v) {
25 return ship::quantityOf<Q>(magnitude(ship::raw(v)));
26}
27
28} // namespace aegir
Definition hepmc_status.hpp:17
double magnitude(std::array< double, 3 > const &v)
Definition math_utils.hpp:17