diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f8220f9a15b0e00fe5f22c3ec7860fc86d5feca2..4015bdd5ecb8ba8ab091bdfaecb60c1e385a8f07 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,3 +17,22 @@ build: - cmake .. - cmake --build . - ctest -V + +code_quality: + image: docker:stable + variables: + DOCKER_DRIVER: overlay2 + allow_failure: true + services: + - docker:stable-dind + script: + - export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') + - docker run + --env SOURCE_CODE="$PWD" + --volume "$PWD":/code + --volume /var/run/docker.sock:/var/run/docker.sock + "registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code + artifacts: + reports: + codequality: gl-code-quality-report.json + \ No newline at end of file diff --git a/Framework/Cascade/testCascade.cc b/Framework/Cascade/testCascade.cc index ad4daa2e4df0a554727f1a0584cc88a3af3cff72..6d0244555d7c9e66de6121e4f3d2a2e31bb4dda3 100644 --- a/Framework/Cascade/testCascade.cc +++ b/Framework/Cascade/testCascade.cc @@ -73,7 +73,6 @@ public: private: }; - TEST_CASE("Cascade", "[Cascade]") { tracking_line::TrackingLine<setup::Stack> tracking; @@ -92,8 +91,8 @@ TEST_CASE("Cascade", "[Cascade]") { EnergyType E0 = 100_GeV; particle.SetEnergy(E0); particle.SetPosition(Point(rootCS, {0_m, 0_m, 10_km})); - particle.SetMomentum( - corsika::stack::super_stupid::MomentumVector(rootCS, {0*newton*second, 0*newton*second, -1*newton*second})); + particle.SetMomentum(corsika::stack::super_stupid::MomentumVector( + rootCS, {0 * newton * second, 0 * newton * second, -1 * newton * second})); EAS.Init(); EAS.Run(); diff --git a/Framework/Particles/ParticleProperties.h b/Framework/Particles/ParticleProperties.h index 4bb3cda140f4b5c986d004a3c8c48fc3533deb53..e7d48547f87779c8da84ea2c318de55ee8b163a8 100644 --- a/Framework/Particles/ParticleProperties.h +++ b/Framework/Particles/ParticleProperties.h @@ -26,7 +26,6 @@ #include <corsika/units/PhysicalConstants.h> #include <corsika/units/PhysicalUnits.h> - /** * @namespace particle * @@ -47,7 +46,7 @@ namespace corsika::particles { // forward declarations to be used in GeneratedParticleProperties int16_t constexpr GetElectricChargeNumber(Code const); corsika::units::si::ElectricChargeType constexpr GetElectricCharge(Code const); - corsika::units::si::MassType constexpr GetMass(Code const); + corsika::units::hep::MassType constexpr GetMass(Code const); PDGCodeType constexpr GetPDG(Code const); constexpr std::string const& GetName(Code const); corsika::units::si::TimeType constexpr GetLifetime(Code const); @@ -57,7 +56,7 @@ namespace corsika::particles { /*! * returns mass of particle */ - corsika::units::si::MassType constexpr GetMass(Code const p) { + corsika::units::hep::MassType constexpr GetMass(Code const p) { return masses[static_cast<CodeIntType const>(p)]; } diff --git a/Framework/Particles/pdxml_reader.py b/Framework/Particles/pdxml_reader.py index 39aaddd310dfeb51969660a7c17bcabdf9c6eb87..aa77d0c5a4e954f713c4cac0aeb938bcf00d8bff 100755 --- a/Framework/Particles/pdxml_reader.py +++ b/Framework/Particles/pdxml_reader.py @@ -231,9 +231,9 @@ def gen_properties(pythia_db): string += "\n" # particle masses table - string += "static constexpr std::array<corsika::units::si::MassType const, size> masses = {\n" + string += "static constexpr std::array<corsika::units::hep::MassType const, size> masses = {\n" for p in pythia_db.values(): - string += " {mass:f} * (1e9 * corsika::units::si::constants::eV / corsika::units::si::constants::cSquared), // {name:s}\n".format(mass = p['mass'], name = p['name']) + string += " {mass:f} * (1e9 * corsika::units::si::constants::eV), // {name:s}\n".format(mass = p['mass'], name = p['name']) string += "};\n\n" # PDG code table @@ -295,7 +295,7 @@ def gen_classes(pythia_db): string += "/** @class " + cname + "\n\n" string += " * Particle properties are taken from the PYTHIA8 ParticleData.xml file:<br>\n" string += " * - pdg=" + str(pythia_db[cname]['pdg']) +"\n" - string += " * - mass=" + str(pythia_db[cname]['mass']) + " GeV/c2 \n" + string += " * - mass=" + str(pythia_db[cname]['mass']) + " GeV \n" string += " * - charge= " + str(pythia_db[cname]['electric_charge']/3) + " \n" string += " * - name=" + str(cname) + "\n" string += " * - anti=" + str(antiP) + "\n" @@ -303,7 +303,7 @@ def gen_classes(pythia_db): string += "class " + cname + " {\n" string += " public:\n" string += " static constexpr Code GetCode() { return Type; }\n" - string += " static constexpr corsika::units::si::MassType GetMass() { return corsika::particles::GetMass(Type); }\n" + string += " static constexpr corsika::units::hep::MassType GetMass() { return corsika::particles::GetMass(Type); }\n" string += " static constexpr corsika::units::si::ElectricChargeType GetCharge() { return corsika::particles::GetElectricCharge(Type); }\n" string += " static constexpr int16_t GetChargeNumber() { return corsika::particles::GetElectricChargeNumber(Type); }\n" string += " static std::string const& GetName() { return corsika::particles::GetName(Type); }\n" diff --git a/Framework/Particles/testParticles.cc b/Framework/Particles/testParticles.cc index 283bb48c9dfe38db8225d5f8944c1fe7eeaec04c..78f34d0beb262166e51839bbedf3b83521355d6a 100644 --- a/Framework/Particles/testParticles.cc +++ b/Framework/Particles/testParticles.cc @@ -31,7 +31,7 @@ TEST_CASE("ParticleProperties", "[Particles]") { } SECTION("Masses") { - REQUIRE(Electron::GetMass() / (511_keV / constants::cSquared) == Approx(1)); + REQUIRE(Electron::GetMass() / (511_keV) == Approx(1)); REQUIRE(Electron::GetMass() / GetMass(Code::Electron) == Approx(1)); } @@ -55,10 +55,14 @@ TEST_CASE("ParticleProperties", "[Particles]") { } SECTION("Lifetimes") { - REQUIRE(GetLifetime(Code::Electron) == std::numeric_limits<double>::infinity() * corsika::units::si::second); - REQUIRE(GetLifetime(Code::DPlus) < GetLifetime(Code::Gamma)); - //REQUIRE(GetLifetime(Code::RhoPlus)/corsika::units::si::second == (Approx(4.414566727909413e-24).epsilon(1e-3))); - //REQUIRE(GetLifetime(Code::SigmaMinusBar)/corsika::units::si::second == (Approx(8.018880848563575e-11).epsilon(1e-5))); - //REQUIRE(GetLifetime(Code::MuPlus)/corsika::units::si::second == (Approx(2.1970332555864364e-06).epsilon(1e-5))); + REQUIRE(GetLifetime(Code::Electron) == + std::numeric_limits<double>::infinity() * corsika::units::si::second); + REQUIRE(GetLifetime(Code::DPlus) < GetLifetime(Code::Gamma)); + // REQUIRE(GetLifetime(Code::RhoPlus)/corsika::units::si::second == + // (Approx(4.414566727909413e-24).epsilon(1e-3))); + // REQUIRE(GetLifetime(Code::SigmaMinusBar)/corsika::units::si::second == + // (Approx(8.018880848563575e-11).epsilon(1e-5))); + // REQUIRE(GetLifetime(Code::MuPlus)/corsika::units::si::second == + // (Approx(2.1970332555864364e-06).epsilon(1e-5))); } } diff --git a/Framework/Units/PhysicalUnits.h b/Framework/Units/PhysicalUnits.h index e97003eee0a0e649021e20c420776afd6e586e59..8975a6e9994cb316cf4c633c3ba6a0715c1d90c0 100644 --- a/Framework/Units/PhysicalUnits.h +++ b/Framework/Units/PhysicalUnits.h @@ -9,9 +9,24 @@ /** * @file PhysicalUnits * - * Define new units and unit-types + * Add new units and types we need + * + * Define _XeV literals, etc., allowing 10_GeV in the code. */ +namespace corsika::units::hep { + using namespace phys::units; + using namespace phys::units::literals; + + /// defining HEP energy, mass, momentum + using energy_hep_d = phys::units::energy_d; + + 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>; + +} // namespace corsika::units::hep + namespace corsika::units::si { using namespace phys::units; using namespace phys::units::literals; @@ -59,8 +74,6 @@ namespace phys { QUANTITY_DEFINE_SCALING_LITERALS(barn, corsika::units::si::sigma_d, magnitude(corsika::units::si::constants::barn)) - // phys::units::quantity<energy_d/mass_d> Joule2Kg = c2; // 1_Joule / 1_kg; - QUANTITY_DEFINE_SCALING_LITERALS(meter, length_d, magnitude(corsika::units::si::constants::meter)) diff --git a/Framework/Units/testUnits.cc b/Framework/Units/testUnits.cc index 5785cc4aef1b285c3ac0676e692bbeaecdfa8d17..4990cd62462af914744aefe76be86528333a978e 100644 --- a/Framework/Units/testUnits.cc +++ b/Framework/Units/testUnits.cc @@ -17,6 +17,7 @@ #include <array> +using namespace corsika; using namespace corsika::units::si; TEST_CASE("PhysicalUnits", "[Units]") { @@ -91,6 +92,19 @@ TEST_CASE("PhysicalUnits", "[Units]") { 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); + } + SECTION("Special") { const LengthType farAway = std::numeric_limits<double>::infinity() * meter; diff --git a/Processes/StackInspector/StackInspector.h b/Processes/StackInspector/StackInspector.h index e40517499d7c07b984c5d9b30caac469269cf649..7b68d92d3fa6f5527de8bc42b76059017a79221f 100644 --- a/Processes/StackInspector/StackInspector.h +++ b/Processes/StackInspector/StackInspector.h @@ -16,7 +16,6 @@ #include <corsika/setup/SetupTrajectory.h> - namespace corsika::process { namespace stack_inspector { diff --git a/Processes/TrackingLine/TrackingLine.h b/Processes/TrackingLine/TrackingLine.h index 602d5473269c8e15561967fe9adc8b16ff4dfa0c..e750342a1add1bff5e32bd270710e995d60ce4b0 100644 --- a/Processes/TrackingLine/TrackingLine.h +++ b/Processes/TrackingLine/TrackingLine.h @@ -1,8 +1,8 @@ #ifndef _include_corsika_processes_TrackinLine_h_ #define _include_corsika_processes_TrackinLine_h_ -#include <corsika/geometry/Vector.h> #include <corsika/geometry/Point.h> +#include <corsika/geometry/Vector.h> #include <corsika/units/PhysicalUnits.h> @@ -28,7 +28,7 @@ namespace corsika::process { } }; - } // namespace stack_inspector + } // namespace tracking_line } // namespace corsika::process