IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 75074e41 authored by ralfulrich's avatar ralfulrich
Browse files

added units::hep

parent 219e5bd9
No related branches found
No related tags found
1 merge request!22Resolve "Define best unit for mass: "eV" or "kg""
...@@ -9,20 +9,25 @@ ...@@ -9,20 +9,25 @@
/** /**
* @file PhysicalUnits * @file PhysicalUnits
* *
* Define _XeV literals, alowing 10_GeV in the code. * Add units and types we need
*
* Define _XeV literals, etc., allowing 10_GeV in the code.
*/ */
namespace phys { namespace corsika::units::hep {
namespace units { using namespace phys::units;
namespace literals { using namespace phys::units::literals;
QUANTITY_DEFINE_SCALING_LITERALS(eV, energy_d,
magnitude(corsika::units::si::constants::eV)) /// defining cross section
using energy_hep_d = phys::units::energy_d; //dimensions<2, 0, 0>;
// constexpr phys::units::quantity<energy_hep_d> energy{Rep(1.e-28L) * meter * meter};
using MassType = phys::units::quantity<energy_hep_d, double>;
using MomentumType = phys::units::quantity<energy_hep_d, double>;
using EnergyType = phys::units::quantity<energy_hep_d, double>;
// phys::units::quantity<energy_d/mass_d> Joule2Kg = c2; // 1_Joule / 1_kg; } // end namespace corsika::units::si
} // namespace literals
} // namespace units
} // namespace phys
namespace corsika::units::si { namespace corsika::units::si {
using namespace phys::units; using namespace phys::units;
...@@ -40,6 +45,16 @@ namespace corsika::units::si { ...@@ -40,6 +45,16 @@ namespace corsika::units::si {
} // end namespace corsika::units::si } // end namespace corsika::units::si
namespace phys {
namespace units {
namespace literals {
QUANTITY_DEFINE_SCALING_LITERALS(eV, energy_d,
magnitude(corsika::units::si::constants::eV))
} // namespace literals
} // namespace units
} // namespace phys
// we want to call the operator<< without namespace... I think // we want to call the operator<< without namespace... I think
using namespace phys::units::io; using namespace phys::units::io;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <array> #include <array>
using namespace corsika;
using namespace corsika::units::si; using namespace corsika::units::si;
TEST_CASE("PhysicalUnits", "[Units]") { TEST_CASE("PhysicalUnits", "[Units]") {
...@@ -70,4 +71,20 @@ TEST_CASE("PhysicalUnits", "[Units]") { ...@@ -70,4 +71,20 @@ TEST_CASE("PhysicalUnits", "[Units]") {
const auto E3 = E2 + 100_GeV + pow(10, lgE) * 1_GeV; const auto E3 = E2 + 100_GeV + pow(10, lgE) * 1_GeV;
REQUIRE(E3 == 180_GeV); REQUIRE(E3 == 180_GeV);
} }
SECTION("Unit system conversion") {
const units::hep::MassType m_hep = 3_GeV;
REQUIRE(m_hep == 3_GeV); // hep::mass identical to si::energy
auto type_check = m_hep / units::si::constants::cSquared;
REQUIRE(dynamic_cast<units::si::MassType*>(&type_check)); // hep::mass*c2 is mass unit
const units::hep::EnergyType e_hep = 4_GeV;
REQUIRE(sqrt(m_hep*m_hep + e_hep*e_hep) == 5_GeV);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment