IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 518ae25f authored by Ralf Ulrich's avatar Ralf Ulrich
Browse files

Merge branch '27-define-best-unit-for-mass-ev-or-kg' into 'master'

Resolve "Define best unit for mass: "eV" or "kg""

Closes #27

See merge request !22
parents 9295cee0 5e23ab21
No related branches found
No related tags found
No related merge requests found
...@@ -17,3 +17,22 @@ build: ...@@ -17,3 +17,22 @@ build:
- cmake .. - cmake ..
- cmake --build . - cmake --build .
- ctest -V - 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
...@@ -73,7 +73,6 @@ public: ...@@ -73,7 +73,6 @@ public:
private: private:
}; };
TEST_CASE("Cascade", "[Cascade]") { TEST_CASE("Cascade", "[Cascade]") {
tracking_line::TrackingLine<setup::Stack> tracking; tracking_line::TrackingLine<setup::Stack> tracking;
...@@ -92,8 +91,8 @@ TEST_CASE("Cascade", "[Cascade]") { ...@@ -92,8 +91,8 @@ TEST_CASE("Cascade", "[Cascade]") {
EnergyType E0 = 100_GeV; EnergyType E0 = 100_GeV;
particle.SetEnergy(E0); particle.SetEnergy(E0);
particle.SetPosition(Point(rootCS, {0_m, 0_m, 10_km})); particle.SetPosition(Point(rootCS, {0_m, 0_m, 10_km}));
particle.SetMomentum( particle.SetMomentum(corsika::stack::super_stupid::MomentumVector(
corsika::stack::super_stupid::MomentumVector(rootCS, {0*newton*second, 0*newton*second, -1*newton*second})); rootCS, {0 * newton * second, 0 * newton * second, -1 * newton * second}));
EAS.Init(); EAS.Init();
EAS.Run(); EAS.Run();
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include <corsika/units/PhysicalConstants.h> #include <corsika/units/PhysicalConstants.h>
#include <corsika/units/PhysicalUnits.h> #include <corsika/units/PhysicalUnits.h>
/** /**
* @namespace particle * @namespace particle
* *
...@@ -47,7 +46,7 @@ namespace corsika::particles { ...@@ -47,7 +46,7 @@ namespace corsika::particles {
// forward declarations to be used in GeneratedParticleProperties // forward declarations to be used in GeneratedParticleProperties
int16_t constexpr GetElectricChargeNumber(Code const); int16_t constexpr GetElectricChargeNumber(Code const);
corsika::units::si::ElectricChargeType constexpr GetElectricCharge(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); PDGCodeType constexpr GetPDG(Code const);
constexpr std::string const& GetName(Code const); constexpr std::string const& GetName(Code const);
corsika::units::si::TimeType constexpr GetLifetime(Code const); corsika::units::si::TimeType constexpr GetLifetime(Code const);
...@@ -57,7 +56,7 @@ namespace corsika::particles { ...@@ -57,7 +56,7 @@ namespace corsika::particles {
/*! /*!
* returns mass of particle * 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)]; return masses[static_cast<CodeIntType const>(p)];
} }
......
...@@ -231,9 +231,9 @@ def gen_properties(pythia_db): ...@@ -231,9 +231,9 @@ def gen_properties(pythia_db):
string += "\n" string += "\n"
# particle masses table # 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(): 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" string += "};\n\n"
# PDG code table # PDG code table
...@@ -295,7 +295,7 @@ def gen_classes(pythia_db): ...@@ -295,7 +295,7 @@ def gen_classes(pythia_db):
string += "/** @class " + cname + "\n\n" string += "/** @class " + cname + "\n\n"
string += " * Particle properties are taken from the PYTHIA8 ParticleData.xml file:<br>\n" string += " * Particle properties are taken from the PYTHIA8 ParticleData.xml file:<br>\n"
string += " * - pdg=" + str(pythia_db[cname]['pdg']) +"\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 += " * - charge= " + str(pythia_db[cname]['electric_charge']/3) + " \n"
string += " * - name=" + str(cname) + "\n" string += " * - name=" + str(cname) + "\n"
string += " * - anti=" + str(antiP) + "\n" string += " * - anti=" + str(antiP) + "\n"
...@@ -303,7 +303,7 @@ def gen_classes(pythia_db): ...@@ -303,7 +303,7 @@ def gen_classes(pythia_db):
string += "class " + cname + " {\n" string += "class " + cname + " {\n"
string += " public:\n" string += " public:\n"
string += " static constexpr Code GetCode() { return Type; }\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 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 constexpr int16_t GetChargeNumber() { return corsika::particles::GetElectricChargeNumber(Type); }\n"
string += " static std::string const& GetName() { return corsika::particles::GetName(Type); }\n" string += " static std::string const& GetName() { return corsika::particles::GetName(Type); }\n"
......
...@@ -31,7 +31,7 @@ TEST_CASE("ParticleProperties", "[Particles]") { ...@@ -31,7 +31,7 @@ TEST_CASE("ParticleProperties", "[Particles]") {
} }
SECTION("Masses") { 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)); REQUIRE(Electron::GetMass() / GetMass(Code::Electron) == Approx(1));
} }
...@@ -55,10 +55,14 @@ TEST_CASE("ParticleProperties", "[Particles]") { ...@@ -55,10 +55,14 @@ TEST_CASE("ParticleProperties", "[Particles]") {
} }
SECTION("Lifetimes") { SECTION("Lifetimes") {
REQUIRE(GetLifetime(Code::Electron) == std::numeric_limits<double>::infinity() * corsika::units::si::second); REQUIRE(GetLifetime(Code::Electron) ==
REQUIRE(GetLifetime(Code::DPlus) < GetLifetime(Code::Gamma)); std::numeric_limits<double>::infinity() * corsika::units::si::second);
//REQUIRE(GetLifetime(Code::RhoPlus)/corsika::units::si::second == (Approx(4.414566727909413e-24).epsilon(1e-3))); REQUIRE(GetLifetime(Code::DPlus) < GetLifetime(Code::Gamma));
//REQUIRE(GetLifetime(Code::SigmaMinusBar)/corsika::units::si::second == (Approx(8.018880848563575e-11).epsilon(1e-5))); // REQUIRE(GetLifetime(Code::RhoPlus)/corsika::units::si::second ==
//REQUIRE(GetLifetime(Code::MuPlus)/corsika::units::si::second == (Approx(2.1970332555864364e-06).epsilon(1e-5))); // (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)));
} }
} }
...@@ -9,9 +9,24 @@ ...@@ -9,9 +9,24 @@
/** /**
* @file PhysicalUnits * @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 { namespace corsika::units::si {
using namespace phys::units; using namespace phys::units;
using namespace phys::units::literals; using namespace phys::units::literals;
...@@ -59,8 +74,6 @@ namespace phys { ...@@ -59,8 +74,6 @@ namespace phys {
QUANTITY_DEFINE_SCALING_LITERALS(barn, corsika::units::si::sigma_d, QUANTITY_DEFINE_SCALING_LITERALS(barn, corsika::units::si::sigma_d,
magnitude(corsika::units::si::constants::barn)) 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, QUANTITY_DEFINE_SCALING_LITERALS(meter, length_d,
magnitude(corsika::units::si::constants::meter)) magnitude(corsika::units::si::constants::meter))
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,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]") {
...@@ -91,6 +92,19 @@ TEST_CASE("PhysicalUnits", "[Units]") { ...@@ -91,6 +92,19 @@ TEST_CASE("PhysicalUnits", "[Units]") {
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);
}
SECTION("Special") { SECTION("Special") {
const LengthType farAway = std::numeric_limits<double>::infinity() * meter; const LengthType farAway = std::numeric_limits<double>::infinity() * meter;
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include <corsika/setup/SetupTrajectory.h> #include <corsika/setup/SetupTrajectory.h>
namespace corsika::process { namespace corsika::process {
namespace stack_inspector { namespace stack_inspector {
......
#ifndef _include_corsika_processes_TrackinLine_h_ #ifndef _include_corsika_processes_TrackinLine_h_
#define _include_corsika_processes_TrackinLine_h_ #define _include_corsika_processes_TrackinLine_h_
#include <corsika/geometry/Vector.h>
#include <corsika/geometry/Point.h> #include <corsika/geometry/Point.h>
#include <corsika/geometry/Vector.h>
#include <corsika/units/PhysicalUnits.h> #include <corsika/units/PhysicalUnits.h>
...@@ -28,7 +28,7 @@ namespace corsika::process { ...@@ -28,7 +28,7 @@ namespace corsika::process {
} }
}; };
} // namespace stack_inspector } // namespace tracking_line
} // namespace corsika::process } // namespace corsika::process
......
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