diff --git a/Documentation/Examples/geometry_example.cc b/Documentation/Examples/geometry_example.cc index 528c0d4436a2ccf00f226642fc5eda20ce8afd55..a8ae9c51bbdfe0dfb1d398fd6c4d980e2e918603 100644 --- a/Documentation/Examples/geometry_example.cc +++ b/Documentation/Examples/geometry_example.cc @@ -8,11 +8,8 @@ #include <typeinfo> #include <cstdlib> -using namespace phys::units; -using namespace phys::units::io; // support stream << unit -using namespace phys::units::literals; // support unit literals like 5_m; - using namespace fwk; +using namespace fwk::literals; // support unit literals like 5_m; int main() { @@ -29,7 +26,7 @@ int main() Point const p1(root, {0_m, 0_m, 0_m}); // the origin of the root CS Point const p2(cs2, {0_m, 0_m, 0_m}); // the origin of cs2 - Vector<length_d> const diff = p2 - p1; // the distance between the points, basically the translation vector given above + Vector<fwk::length_d> const diff = p2 - p1; // the distance between the points, basically the translation vector given above auto const norm = diff.squaredNorm(); // squared length with the right dimension // print the components of the vector as given in the different CS @@ -46,8 +43,8 @@ int main() // let's try parallel projections: - auto const v1 = Vector<length_d>(root, {1_m, 1_m, 0_m}); - auto const v2 = Vector<length_d>(root, {1_m, 0_m, 0_m}); + auto const v1 = Vector<fwk::length_d>(root, {1_m, 1_m, 0_m}); + auto const v2 = Vector<fwk::length_d>(root, {1_m, 0_m, 0_m}); auto const v3 = v1.parallelProjectionOnto(v2); diff --git a/Documentation/Examples/helix_example.cc b/Documentation/Examples/helix_example.cc index c365c83b0fd300b3fac3fa23040031fc8883a7b0..4d6ccfe8c93612e8765d9caf4163f068afd11132 100644 --- a/Documentation/Examples/helix_example.cc +++ b/Documentation/Examples/helix_example.cc @@ -8,9 +8,8 @@ #include <cstdlib> #include <iostream> -using namespace phys::units; -using namespace phys::units::io; // support stream << unit -using namespace phys::units::literals; // support unit literals like 5_m; +using namespace fwk; +using namespace fwk::literals; // support unit literals like 5_m; int main() { fwk::CoordinateSystem root; diff --git a/Framework/Particles/ParticleProperties.h b/Framework/Particles/ParticleProperties.h index 7f2f433d925b5febe49909fcf1269eba8db1d8bb..c9acdb44cbac3f0457adeb8daf067d1f9defddb9 100644 --- a/Framework/Particles/ParticleProperties.h +++ b/Framework/Particles/ParticleProperties.h @@ -43,7 +43,7 @@ namespace fwk { } auto constexpr GetElectricCharge(Code const p) { - return GetElectricChargeNumber(p) * (phys::units::e); + return GetElectricChargeNumber(p) * (fwk::constants::e); } auto const GetName(Code const p) { diff --git a/Framework/Particles/pdxml_reader.py b/Framework/Particles/pdxml_reader.py index 6c1fc3bd95339c0d6366452705d57d0bc7aabefc..9a5e5220f621c21b324601f900e7144a584625c1 100755 --- a/Framework/Particles/pdxml_reader.py +++ b/Framework/Particles/pdxml_reader.py @@ -278,7 +278,7 @@ def gen_classes(pythia_db): string += " public:\n" string += " static Code GetCode() { return Type; }\n" string += " static quantity<energy_d> GetMass() { return masses[TypeIndex]; }\n" - string += " static quantity<electric_charge_d> GetCharge() { return phys::units::e*electric_charge[TypeIndex]/3; }\n" + string += " static quantity<electric_charge_d> GetCharge() { return fwk::constants::e*electric_charge[TypeIndex]/3; }\n" string += " static int GetChargeNumber() { return electric_charge[TypeIndex]/3; }\n" string += " static std::string GetName() { return names[TypeIndex]; }\n" string += " static Code GetAntiParticle() { return AntiType; }\n" @@ -303,9 +303,8 @@ def inc_start(): string += "#include <array>\n" string += "#include <cstdint>\n" # string += "#include <iostream>\n\n" - string += "using namespace phys::units;\n" - string += "using namespace phys::units::literals;\n\n" string += "namespace fwk { \n\n" + string += "using namespace literals; \n" string += "namespace particle { \n\n" string += "typedef int16_t PDGCode;\n\n" return string diff --git a/Framework/Particles/testParticles.cc b/Framework/Particles/testParticles.cc index 8b219a3eded171c52a0df47b09de7821b9b128e0..a48858b991f01e9623ee2884819c6706c98011af 100644 --- a/Framework/Particles/testParticles.cc +++ b/Framework/Particles/testParticles.cc @@ -6,9 +6,7 @@ #include <fwk/ParticleProperties.h> -// using namespace phys::units; -// using namespace phys::units::literals; - +using namespace fwk::literals; using namespace fwk::particle; TEST_CASE("Particles", "[Particles]") { @@ -18,9 +16,9 @@ TEST_CASE("Particles", "[Particles]") { SECTION("Data") { REQUIRE(Electron::GetMass() / 0.511_MeV == Approx(1)); REQUIRE(Electron::GetMass() / GetMass(Code::Electron) == Approx(1)); - REQUIRE(Electron::GetCharge() / phys::units::e == Approx(-1)); - REQUIRE(Positron::GetCharge() / phys::units::e == Approx(+1)); - REQUIRE(GetElectricCharge(Positron::GetAntiParticle()) / phys::units::e == + REQUIRE(Electron::GetCharge() / fwk::constants::e == Approx(-1)); + REQUIRE(Positron::GetCharge() / fwk::constants::e == Approx(+1)); + REQUIRE(GetElectricCharge(Positron::GetAntiParticle()) / fwk::constants::e == Approx(-1)); REQUIRE(Electron::GetName() == "e-"); } diff --git a/Framework/Units/PhysicalConstants.h b/Framework/Units/PhysicalConstants.h index 7935c3962e83b14fe27dd0f60176faac75b6eedf..a4e8b0ce6e644734a3dbeb627c568a458d6ffdfb 100644 --- a/Framework/Units/PhysicalConstants.h +++ b/Framework/Units/PhysicalConstants.h @@ -64,13 +64,12 @@ namespace phys { namespace fwk { - using namespace phys; + // using namespace phys; using namespace phys::units; + namespace constants = phys::units::constants; + } // namespace fwk #endif // PHYS_UNITS_PHYSICAL_CONSTANTS_HPP_INCLUDED -/* - * end of file - */ diff --git a/Framework/Units/PhysicalUnits.h b/Framework/Units/PhysicalUnits.h index b5ee98bff29baf44223e0aa02aded7e7fb7cc091..3403cafac6765c630ea3a7d64041a59d6f0c3fd4 100644 --- a/Framework/Units/PhysicalUnits.h +++ b/Framework/Units/PhysicalUnits.h @@ -1,8 +1,9 @@ #ifndef _include_PhysicalUnits_h_ #define _include_PhysicalUnits_h_ +#include <fwk/PhysicalConstants.h> + #include <phys/units/io.hpp> -#include <phys/units/physical_constants.hpp> #include <phys/units/quantity.hpp> /** @@ -11,29 +12,27 @@ * Define _XeV literals, alowing 10_GeV in the code. */ -/*using namespace phys::units::io; -using namespace phys::units::literals;*/ - namespace phys { namespace units { namespace literals { - QUANTITY_DEFINE_SCALING_LITERALS(eV, energy_d, magnitude(eV)) + QUANTITY_DEFINE_SCALING_LITERALS(eV, energy_d, magnitude(constants::eV)) } } // namespace units } // namespace phys namespace fwk { - using namespace phys; using namespace phys::units; - // using namespace phys::units::literals; + //namespace literals = phys::units::literals; - using Length = phys::units::quantity<phys::units::length_d, double>; - using Time = phys::units::quantity<phys::units::time_interval_d, double>; - using Speed = phys::units::quantity<phys::units::speed_d, double>; - using Frequency = phys::units::quantity<phys::units::frequency_d, double>; - using ElectricCharge = phys::units::quantity<phys::units::electric_charge_d, double>; - using Energy = phys::units::quantity<phys::units::energy_d, double>; + //namespace quantity { + using Length = phys::units::quantity<phys::units::length_d, double>; + using Time = phys::units::quantity<phys::units::time_interval_d, double>; + using Speed = phys::units::quantity<phys::units::speed_d, double>; + using Frequency = phys::units::quantity<phys::units::frequency_d, double>; + using ElectricCharge = phys::units::quantity<phys::units::electric_charge_d, double>; + using Energy = phys::units::quantity<phys::units::energy_d, double>; + //} // namespace quantity } // end namespace fwk diff --git a/Framework/Units/testUnits.cc b/Framework/Units/testUnits.cc index e963c6796ee5d746abc0c29bd006c5d07c394d0e..a1f52e15d39ee493fe16732deb01352caf32d1bb 100644 --- a/Framework/Units/testUnits.cc +++ b/Framework/Units/testUnits.cc @@ -1,73 +1,73 @@ -#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one + // cpp file #include <catch2/catch.hpp> #include <fwk/PhysicalUnits.h> #include <array> -using namespace phys::units; -using namespace phys::units::literals; +using namespace fwk; +using namespace fwk::literals; -TEST_CASE( "PhysicalUnits", "[Units]" ) { +TEST_CASE("PhysicalUnits", "[Units]") { SECTION("Consistency") { - REQUIRE( 1_m/1_m == Approx(1) ); - //REQUIRE_FALSE( 1_m/1_s == 1 ); // static assert + REQUIRE(1_m / 1_m == Approx(1)); + // REQUIRE_FALSE( 1_m/1_s == 1 ); // static assert } SECTION("Constructors") { auto E1 = 10_GeV; - REQUIRE( E1==10_GeV ); + REQUIRE(E1 == 10_GeV); - quantity<phys::units::length_d> l1 = 10_nm; - - quantity<phys::units::length_d> arr0[5]; + fwk::Length l1 = 10_nm; + + fwk::Length arr0[5]; arr0[0] = 5_m; - - quantity<phys::units::length_d> arr1[2] = { {1_mm}, {2_cm} }; - std::array<quantity<phys::units::energy_d>, 4> arr2; // empty array - - std::array<quantity<phys::units::energy_d>, 4> arr3 = { 1_GeV, 1_eV, 5_MeV }; + fwk::Length arr1[2] = {{1_mm}, {2_cm}}; + + std::array<fwk::Energy, 4> arr2; // empty array + + std::array<fwk::Energy, 4> arr3 = {1_GeV, 1_eV, 5_MeV}; } - + SECTION("Powers in literal units") { - REQUIRE( 1_s/1_ds == Approx(1e1) ); - REQUIRE( 1_m/1_cm == Approx(1e2) ); - REQUIRE( 1_m/1_mm == Approx(1e3) ); - REQUIRE( 1_V/1_uV == Approx(1e6) ); - REQUIRE( 1_s/1_ns == Approx(1e9) ); - REQUIRE( 1_eV/1_peV == Approx(1e12) ); - REQUIRE( 1_A/1_fA == Approx(1e15) ); - REQUIRE( 1_mol/1_amol == Approx(1e18) ); - REQUIRE( 1_K/1_zK == Approx(1e21) ); - REQUIRE( 1_K/1_yK == Approx(1e24) ); - - REQUIRE( 1_A/1_hA == Approx(1e-2) ); - REQUIRE( 1_m/1_km == Approx(1e-3) ); - REQUIRE( 1_m/1_Mm == Approx(1e-6) ); - REQUIRE( 1_V/1_GV == Approx(1e-9) ); - REQUIRE( 1_s/1_Ts == Approx(1e-12) ); - REQUIRE( 1_eV/1_PeV == Approx(1e-15) ); - REQUIRE( 1_A/1_EA == Approx(1e-18) ); - REQUIRE( 1_K/1_ZK == Approx(1e-21) ); - REQUIRE( 1_mol/1_Ymol == Approx(1e-24) ); + REQUIRE(1_s / 1_ds == Approx(1e1)); + REQUIRE(1_m / 1_cm == Approx(1e2)); + REQUIRE(1_m / 1_mm == Approx(1e3)); + REQUIRE(1_V / 1_uV == Approx(1e6)); + REQUIRE(1_s / 1_ns == Approx(1e9)); + REQUIRE(1_eV / 1_peV == Approx(1e12)); + REQUIRE(1_A / 1_fA == Approx(1e15)); + REQUIRE(1_mol / 1_amol == Approx(1e18)); + REQUIRE(1_K / 1_zK == Approx(1e21)); + REQUIRE(1_K / 1_yK == Approx(1e24)); + + REQUIRE(1_A / 1_hA == Approx(1e-2)); + REQUIRE(1_m / 1_km == Approx(1e-3)); + REQUIRE(1_m / 1_Mm == Approx(1e-6)); + REQUIRE(1_V / 1_GV == Approx(1e-9)); + REQUIRE(1_s / 1_Ts == Approx(1e-12)); + REQUIRE(1_eV / 1_PeV == Approx(1e-15)); + REQUIRE(1_A / 1_EA == Approx(1e-18)); + REQUIRE(1_K / 1_ZK == Approx(1e-21)); + REQUIRE(1_mol / 1_Ymol == Approx(1e-24)); } SECTION("Powers and units") { - REQUIRE( 1 * ampere / 1_A == Approx(1e0) ); - REQUIRE( mega * bar / bar == Approx(1e6) ); + REQUIRE(1 * ampere / 1_A == Approx(1e0)); + REQUIRE(mega * bar / bar == Approx(1e6)); } SECTION("Formulas") { - const quantity<phys::units::energy_d> E2 = 20_GeV * 2; - REQUIRE( E2==40_GeV ); - - const double lgE = log10(E2/1_GeV); - REQUIRE( lgE==Approx(log10(40.)) ); + const fwk::Energy E2 = 20_GeV * 2; + REQUIRE(E2 == 40_GeV); + + const double lgE = log10(E2 / 1_GeV); + REQUIRE(lgE == Approx(log10(40.))); const auto E3 = E2 + 100_GeV + pow(10, lgE) * 1_GeV; - REQUIRE( E3==180_GeV ); + REQUIRE(E3 == 180_GeV); } - }