diff --git a/Framework/Units/PhysicalUnits.h b/Framework/Units/PhysicalUnits.h index 23dbbb871dc7d5b2cd2d8538c2bbe7c6197c6812..37b2007d995c7b3fb65d65fce228b06ec197a36a 100644 --- a/Framework/Units/PhysicalUnits.h +++ b/Framework/Units/PhysicalUnits.h @@ -9,20 +9,25 @@ /** * @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 units { - namespace literals { - QUANTITY_DEFINE_SCALING_LITERALS(eV, energy_d, - magnitude(corsika::units::si::constants::eV)) +namespace corsika::units::hep { + using namespace phys::units; + using namespace phys::units::literals; + + /// 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 { using namespace phys::units; @@ -40,6 +45,16 @@ 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 using namespace phys::units::io; diff --git a/Framework/Units/testUnits.cc b/Framework/Units/testUnits.cc index 6e77e4a01e62d2e5cd63e6ad286982fca6ef1766..de119e3d3c2cd7f6bad85efe6f0a7e6900fcdb7c 100644 --- a/Framework/Units/testUnits.cc +++ b/Framework/Units/testUnits.cc @@ -6,6 +6,7 @@ #include <array> +using namespace corsika; using namespace corsika::units::si; TEST_CASE("PhysicalUnits", "[Units]") { @@ -70,4 +71,20 @@ TEST_CASE("PhysicalUnits", "[Units]") { const auto E3 = E2 + 100_GeV + pow(10, lgE) * 1_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); + + } + }