IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 6a460fac authored by Maximilian Reininghaus's avatar Maximilian Reininghaus :vulcan: Committed by ralfulrich
Browse files

testParticles

parent 91fdc3e6
No related branches found
No related tags found
1 merge request!280Refactory 2020
......@@ -11,132 +11,133 @@
#include <catch2/catch.hpp>
using namespace corsika::units;
using namespace corsika::units::si;
using namespace corsika;
TEST_CASE("ParticleProperties", "[Particles]") {
SECTION("Types") {
CHECK(Electron::GetCode() == Code::Electron);
CHECK(Positron::GetCode() == Code::Positron);
CHECK(Proton::GetCode() == Code::Proton);
CHECK(Neutron::GetCode() == Code::Neutron);
CHECK(Gamma::GetCode() == Code::Gamma);
CHECK(PiPlus::GetCode() == Code::PiPlus);
REQUIRE(Electron::code == Code::Electron);
REQUIRE(Positron::code == Code::Positron);
REQUIRE(Proton::code == Code::Proton);
REQUIRE(Neutron::code == Code::Neutron);
REQUIRE(Gamma::code == Code::Gamma);
REQUIRE(PiPlus::code == Code::PiPlus);
}
SECTION("Masses") {
CHECK(Electron::GetMass() / (511_keV) == Approx(1));
CHECK(Electron::GetMass() / GetMass(Code::Electron) == Approx(1));
REQUIRE(Electron::mass() / (511_keV) == Approx(1));
REQUIRE(Electron::mass() / mass(Code::Electron) == Approx(1));
REQUIRE((Proton::GetMass() + Neutron::GetMass()) / constants::nucleonMass ==
Approx(2));
REQUIRE((Proton::mass() + Neutron::mass()) / constants::nucleonMass == Approx(2));
}
SECTION("Charges") {
CHECK(Electron::GetCharge() / constants::e == Approx(-1));
CHECK(Positron::GetCharge() / constants::e == Approx(+1));
CHECK(GetCharge(Positron::GetAntiParticle()) / constants::e == Approx(-1));
REQUIRE(Electron::charge() / constants::e == Approx(-1));
REQUIRE(Positron::charge() / constants::e == Approx(+1));
REQUIRE(charge(Positron::anti_code) / constants::e == Approx(-1));
}
SECTION("Names") {
CHECK(Electron::GetName() == "e-");
CHECK(PiMinus::GetName() == "pi-");
CHECK(Nucleus::GetName() == "nucleus");
CHECK(Iron::GetName() == "iron");
REQUIRE(Electron::name() == "e-");
REQUIRE(PiMinus::name() == "pi-");
REQUIRE(Nucleus::name() == "nucleus");
REQUIRE(Iron::name() == "iron");
}
SECTION("PDG") {
CHECK(GetPDG(Code::PiPlus) == PDGCode::PiPlus);
CHECK(GetPDG(Code::DPlus) == PDGCode::DPlus);
CHECK(GetPDG(Code::NuMu) == PDGCode::NuMu);
CHECK(GetPDG(Code::NuE) == PDGCode::NuE);
CHECK(GetPDG(Code::MuMinus) == PDGCode::MuMinus);
CHECK(static_cast<int>(GetPDG(Code::PiPlus)) == 211);
CHECK(static_cast<int>(GetPDG(Code::DPlus)) == 411);
CHECK(static_cast<int>(GetPDG(Code::NuMu)) == 14);
CHECK(static_cast<int>(GetPDG(Code::NuEBar)) == -12);
CHECK(static_cast<int>(GetPDG(Code::MuMinus)) == 13);
REQUIRE(PDG(Code::PiPlus) == PDGCode::PiPlus);
REQUIRE(PDG(Code::DPlus) == PDGCode::DPlus);
REQUIRE(PDG(Code::NuMu) == PDGCode::NuMu);
REQUIRE(PDG(Code::NuE) == PDGCode::NuE);
REQUIRE(PDG(Code::MuMinus) == PDGCode::MuMinus);
REQUIRE(static_cast<int>(PDG(Code::PiPlus)) == 211);
REQUIRE(static_cast<int>(PDG(Code::DPlus)) == 411);
REQUIRE(static_cast<int>(PDG(Code::NuMu)) == 14);
REQUIRE(static_cast<int>(PDG(Code::NuEBar)) == -12);
REQUIRE(static_cast<int>(PDG(Code::MuMinus)) == 13);
}
SECTION("Conversion PDG -> internal") {
CHECK(ConvertFromPDG(PDGCode::KStarMinus) == Code::KStarMinus);
CHECK(ConvertFromPDG(PDGCode::MuPlus) == Code::MuPlus);
CHECK(ConvertFromPDG(PDGCode::SigmaStarCMinusBar) == Code::SigmaStarCMinusBar);
REQUIRE(convert_from_PDG(PDGCode::KStarMinus) == Code::KStarMinus);
REQUIRE(convert_from_PDG(PDGCode::MuPlus) == Code::MuPlus);
REQUIRE(convert_from_PDG(PDGCode::SigmaStarCMinusBar) == Code::SigmaStarCMinusBar);
}
SECTION("Lifetimes") {
REQUIRE(GetLifetime(Code::Electron) ==
REQUIRE(lifetime(Code::Electron) ==
std::numeric_limits<double>::infinity() * si::second);
REQUIRE(GetLifetime(Code::DPlus) < GetLifetime(Code::Gamma));
REQUIRE(GetLifetime(Code::RhoPlus) / si::second ==
REQUIRE(lifetime(Code::DPlus) < lifetime(Code::Gamma));
REQUIRE(lifetime(Code::RhoPlus) / si::second ==
(Approx(4.414566727909413e-24).epsilon(1e-3)));
REQUIRE(GetLifetime(Code::SigmaMinusBar) / si::second ==
REQUIRE(lifetime(Code::SigmaMinusBar) / si::second ==
(Approx(8.018880848563575e-11).epsilon(1e-5)));
REQUIRE(GetLifetime(Code::MuPlus) / si::second ==
REQUIRE(lifetime(Code::MuPlus) / si::second ==
(Approx(2.1970332555864364e-06).epsilon(1e-5)));
}
SECTION("Particle groups: electromagnetic") {
CHECK(IsEM(Code::Gamma));
CHECK(IsEM(Code::Electron));
CHECK_FALSE(IsEM(Code::MuPlus));
CHECK_FALSE(IsEM(Code::NuE));
CHECK_FALSE(IsEM(Code::Proton));
CHECK_FALSE(IsEM(Code::PiPlus));
CHECK_FALSE(IsEM(Code::Oxygen));
REQUIRE(is_em(Code::Gamma));
REQUIRE(is_em(Code::Electron));
REQUIRE_FALSE(is_em(Code::MuPlus));
REQUIRE_FALSE(is_em(Code::NuE));
REQUIRE_FALSE(is_em(Code::Proton));
REQUIRE_FALSE(is_em(Code::PiPlus));
REQUIRE_FALSE(is_em(Code::Oxygen));
}
SECTION("Particle groups: hadrons") {
CHECK_FALSE(IsHadron(Code::Gamma));
CHECK_FALSE(IsHadron(Code::Electron));
CHECK_FALSE(IsHadron(Code::MuPlus));
CHECK_FALSE(IsHadron(Code::NuE));
CHECK(IsHadron(Code::Proton));
CHECK(IsHadron(Code::PiPlus));
CHECK(IsHadron(Code::Oxygen));
CHECK(IsHadron(Code::Nucleus));
REQUIRE_FALSE(is_hadron(Code::Gamma));
REQUIRE_FALSE(is_hadron(Code::Electron));
REQUIRE_FALSE(is_hadron(Code::MuPlus));
REQUIRE_FALSE(is_hadron(Code::NuE));
REQUIRE(is_hadron(Code::Proton));
REQUIRE(is_hadron(Code::PiPlus));
REQUIRE(is_hadron(Code::Oxygen));
REQUIRE(is_hadron(Code::Nucleus));
}
SECTION("Particle groups: muons") {
CHECK_FALSE(IsMuon(Code::Gamma));
CHECK_FALSE(IsMuon(Code::Electron));
CHECK(IsMuon(Code::MuPlus));
CHECK_FALSE(IsMuon(Code::NuE));
CHECK_FALSE(IsMuon(Code::Proton));
CHECK_FALSE(IsMuon(Code::PiPlus));
CHECK_FALSE(IsMuon(Code::Oxygen));
REQUIRE_FALSE(is_muon(Code::Gamma));
REQUIRE_FALSE(is_muon(Code::Electron));
REQUIRE(is_muon(Code::MuPlus));
REQUIRE(is_muon(Code::MuMinus));
REQUIRE_FALSE(is_muon(Code::NuE));
REQUIRE_FALSE(is_muon(Code::Proton));
REQUIRE_FALSE(is_muon(Code::PiPlus));
REQUIRE_FALSE(is_muon(Code::Oxygen));
}
SECTION("Particle groups: neutrinos") {
CHECK_FALSE(IsNeutrino(Code::Gamma));
CHECK_FALSE(IsNeutrino(Code::Electron));
CHECK_FALSE(IsNeutrino(Code::MuPlus));
CHECK(IsNeutrino(Code::NuE));
CHECK_FALSE(IsNeutrino(Code::Proton));
CHECK_FALSE(IsNeutrino(Code::PiPlus));
CHECK_FALSE(IsNeutrino(Code::Oxygen));
REQUIRE_FALSE(is_neutrino(Code::Gamma));
REQUIRE_FALSE(is_neutrino(Code::Electron));
REQUIRE_FALSE(is_neutrino(Code::MuPlus));
REQUIRE_FALSE(is_neutrino(Code::Proton));
REQUIRE_FALSE(is_neutrino(Code::PiPlus));
REQUIRE_FALSE(is_neutrino(Code::Oxygen));
REQUIRE(is_neutrino(Code::NuE));
REQUIRE(is_neutrino(Code::NuMu));
REQUIRE(is_neutrino(Code::NuTau));
REQUIRE(is_neutrino(Code::NuEBar));
REQUIRE(is_neutrino(Code::NuMuBar));
REQUIRE(is_neutrino(Code::NuTauBar));
}
SECTION("Nuclei") {
CHECK_FALSE(IsNucleus(Code::Gamma));
CHECK(IsNucleus(Code::Argon));
CHECK_FALSE(IsNucleus(Code::Proton));
CHECK(IsNucleus(Code::Hydrogen));
CHECK(Argon::IsNucleus());
CHECK_FALSE(EtaC::IsNucleus());
CHECK(GetNucleusA(Code::Hydrogen) == 1);
CHECK(GetNucleusA(Code::Tritium) == 3);
CHECK(Hydrogen::GetNucleusZ() == 1);
CHECK(Tritium::GetNucleusA() == 3);
// Nucleus is a generic object, it has no specific properties
CHECK_THROWS(GetNucleusA(Code::Nucleus));
CHECK_THROWS(GetNucleusZ(Code::Nucleus));
CHECK_THROWS(GetMass(Code::Nucleus));
CHECK_THROWS(GetCharge(Code::Nucleus));
REQUIRE_FALSE(is_nucleus(Code::Gamma));
REQUIRE(is_nucleus(Code::Argon));
REQUIRE_FALSE(is_nucleus(Code::Proton));
REQUIRE(is_nucleus(Code::Hydrogen));
REQUIRE(Argon::is_nucleus());
REQUIRE_FALSE(EtaC::is_nucleus());
REQUIRE(nucleus_A(Code::Hydrogen) == 1);
REQUIRE(nucleus_A(Code::Tritium) == 3);
REQUIRE(Hydrogen::nucleus_Z() == 1);
REQUIRE(Tritium::nucleus_A() == 3);
REQUIRE_THROWS(nucleus_Z(Code::Nucleus));
REQUIRE_THROWS(nucleus_A(Code::Nucleus));
}
}
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