From baf632626a59a8ebd08aaccd683186f227f3c5c8 Mon Sep 17 00:00:00 2001 From: ralfulrich <ralf.ulrich@kit.edu> Date: Thu, 13 Dec 2018 16:46:43 +0100 Subject: [PATCH] added real but simple interface tests for all processes so far --- Documentation/Examples/cascade_example.cc | 2 +- Documentation/Examples/geometry_example.cc | 2 +- Documentation/Examples/helix_example.cc | 2 +- Environment/Environment.h | 2 +- Framework/Cascade/testCascade.cc | 2 +- Framework/Geometry/RootCoordinateSystem.h | 4 +- Framework/Geometry/testGeometry.cc | 6 +- Processes/NullModel/CMakeLists.txt | 4 ++ Processes/NullModel/NullModel.cc | 36 ++++++++++-- Processes/NullModel/NullModel.h | 13 ++++- Processes/NullModel/testNullModel.cc | 34 +++++++++++- Processes/Sibyll/CMakeLists.txt | 3 + Processes/Sibyll/Decay.h | 2 + Processes/Sibyll/Interaction.h | 12 +--- Processes/Sibyll/SibStack.h | 2 +- Processes/Sibyll/testSibyll.cc | 55 +++++++++++++++++-- Processes/StackInspector/CMakeLists.txt | 4 ++ Processes/StackInspector/StackInspector.cc | 2 +- Processes/StackInspector/StackInspector.h | 4 -- .../StackInspector/testStackInspector.cc | 38 ++++++++++++- Stack/SuperStupidStack/SuperStupidStack.h | 4 +- .../SuperStupidStack/testSuperStupidStack.cc | 2 +- 22 files changed, 190 insertions(+), 45 deletions(-) diff --git a/Documentation/Examples/cascade_example.cc b/Documentation/Examples/cascade_example.cc index 6ce55d5d..9c56a9a2 100644 --- a/Documentation/Examples/cascade_example.cc +++ b/Documentation/Examples/cascade_example.cc @@ -215,7 +215,7 @@ int main() { universe.AddChild(std::move(theMedium)); - CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCS(); + CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); tracking_line::TrackingLine<setup::Stack> tracking(env); stack_inspector::StackInspector<setup::Stack> p0(true); diff --git a/Documentation/Examples/geometry_example.cc b/Documentation/Examples/geometry_example.cc index 67f43344..cfd9fd8b 100644 --- a/Documentation/Examples/geometry_example.cc +++ b/Documentation/Examples/geometry_example.cc @@ -26,7 +26,7 @@ using namespace corsika::units::si; int main() { // define the root coordinate system geometry::CoordinateSystem& root = - geometry::RootCoordinateSystem::GetInstance().GetRootCS(); + geometry::RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); // another CS defined by a translation relative to the root CS CoordinateSystem cs2 = root.translate({0_m, 0_m, 1_m}); diff --git a/Documentation/Examples/helix_example.cc b/Documentation/Examples/helix_example.cc index 02ccc7c2..068d25f1 100644 --- a/Documentation/Examples/helix_example.cc +++ b/Documentation/Examples/helix_example.cc @@ -24,7 +24,7 @@ using namespace corsika::units::si; int main() { geometry::CoordinateSystem& root = - geometry::RootCoordinateSystem::GetInstance().GetRootCS(); + geometry::RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); Point const r0(root, {0_m, 0_m, 0_m}); auto const omegaC = 2 * M_PI * 1_Hz; diff --git a/Environment/Environment.h b/Environment/Environment.h index 335f776e..cb75b648 100644 --- a/Environment/Environment.h +++ b/Environment/Environment.h @@ -35,7 +35,7 @@ namespace corsika::environment { class Environment { public: Environment() - : fCoordinateSystem{corsika::geometry::RootCoordinateSystem::GetInstance().GetRootCS()}, + : fCoordinateSystem{corsika::geometry::RootCoordinateSystem::GetInstance().GetRootCoordinateSystem()}, fUniverse(std::make_unique<VolumeTreeNode<IEnvironmentModel>>( std::make_unique<Universe>(fCoordinateSystem))) {} diff --git a/Framework/Cascade/testCascade.cc b/Framework/Cascade/testCascade.cc index b39c3f14..875ff1df 100644 --- a/Framework/Cascade/testCascade.cc +++ b/Framework/Cascade/testCascade.cc @@ -99,7 +99,7 @@ TEST_CASE("Cascade", "[Cascade]") { setup::Stack stack; corsika::cascade::Cascade EAS(tracking, sequence, stack); - CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCS(); + CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); stack.Clear(); auto particle = stack.NewParticle(); diff --git a/Framework/Geometry/RootCoordinateSystem.h b/Framework/Geometry/RootCoordinateSystem.h index 4c3133be..a9df34ed 100644 --- a/Framework/Geometry/RootCoordinateSystem.h +++ b/Framework/Geometry/RootCoordinateSystem.h @@ -21,8 +21,8 @@ namespace corsika::geometry { RootCoordinateSystem() {} public: - corsika::geometry::CoordinateSystem& GetRootCS() { return fRootCS; } - const corsika::geometry::CoordinateSystem& GetRootCS() const { return fRootCS; } + corsika::geometry::CoordinateSystem& GetRootCoordinateSystem() { return fRootCS; } + const corsika::geometry::CoordinateSystem& GetRootCoordinateSystem() const { return fRootCS; } private: corsika::geometry::CoordinateSystem fRootCS; // THIS IS IT diff --git a/Framework/Geometry/testGeometry.cc b/Framework/Geometry/testGeometry.cc index 8130114a..bf6f8760 100644 --- a/Framework/Geometry/testGeometry.cc +++ b/Framework/Geometry/testGeometry.cc @@ -29,7 +29,7 @@ using namespace corsika::units::si; double constexpr absMargin = 1.0e-8; TEST_CASE("transformations between CoordinateSystems") { - CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCS(); + CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); REQUIRE(CoordinateSystem::GetTransformation(rootCS, rootCS) .isApprox(EigenTransform::Identity())); @@ -128,7 +128,7 @@ TEST_CASE("transformations between CoordinateSystems") { } TEST_CASE("Sphere") { - CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCS(); + CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); Point center(rootCS, {0_m, 3_m, 4_m}); Sphere sphere(center, 5_m); @@ -147,7 +147,7 @@ TEST_CASE("Sphere") { } TEST_CASE("Trajectories") { - CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCS(); + CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); Point r0(rootCS, {0_m, 0_m, 0_m}); SECTION("Line") { diff --git a/Processes/NullModel/CMakeLists.txt b/Processes/NullModel/CMakeLists.txt index ff8b026d..300e3b57 100644 --- a/Processes/NullModel/CMakeLists.txt +++ b/Processes/NullModel/CMakeLists.txt @@ -29,6 +29,8 @@ set_target_properties ( target_link_libraries ( ProcessNullModel CORSIKAunits + CORSIKAgeometry + CORSIKAsetup ) target_include_directories ( @@ -52,6 +54,8 @@ add_executable (testNullModel testNullModel.cc) target_link_libraries ( testNullModel + ProcessNullModel + CORSIKAsetup CORSIKAgeometry CORSIKAunits CORSIKAthirdparty # for catch2 diff --git a/Processes/NullModel/NullModel.cc b/Processes/NullModel/NullModel.cc index 3629d522..631891e6 100644 --- a/Processes/NullModel/NullModel.cc +++ b/Processes/NullModel/NullModel.cc @@ -11,14 +11,40 @@ #include <corsika/process/null_model/NullModel.h> + +#include <corsika/logging/Logger.h> +#include <corsika/setup/SetupTrajectory.h> + +#include <iostream> +#include <limits> +using namespace std; + +using namespace corsika; +using namespace corsika::units::si; using namespace corsika::process::null_model; -NullModel::NullModel() {} +template <typename Stack> +NullModel<Stack>::NullModel() {} + +template <typename Stack> +NullModel<Stack>::~NullModel() {} + +template <typename Stack> +process::EProcessReturn NullModel<Stack>::DoContinuous(Particle&, setup::Trajectory&, + Stack& ) const { + return EProcessReturn::eOk; +} + +template <typename Stack> +double NullModel<Stack>::MaxStepLength(Particle&, setup::Trajectory&) const { + return std::numeric_limits<double>::infinity(); +} -NullModel::~NullModel() {} +template <typename Stack> +void NullModel<Stack>::Init() { +} -void NullModel::init() {} +#include <corsika/setup/SetupStack.h> -void NullModel::run() {} +template class process::null_model::NullModel<setup::Stack>; -double NullModel::GetStepLength() { return 0; } diff --git a/Processes/NullModel/NullModel.h b/Processes/NullModel/NullModel.h index dc3bf504..e7eac1bb 100644 --- a/Processes/NullModel/NullModel.h +++ b/Processes/NullModel/NullModel.h @@ -12,19 +12,26 @@ #ifndef _Physics_NullModel_NullModel_h_ #define _Physics_NullModel_NullModel_h_ +#include <corsika/process/ContinuousProcess.h> +#include <corsika/setup/SetupTrajectory.h> + namespace corsika::process { namespace null_model { + template <typename Stack> class NullModel { + typedef typename Stack::ParticleType Particle; + public: NullModel(); ~NullModel(); - void init(); - void run(); - double GetStepLength(); + void Init(); + EProcessReturn DoContinuous(Particle&, corsika::setup::Trajectory&, Stack& s) const; + double MaxStepLength(Particle&, corsika::setup::Trajectory&) const; + }; } // namespace null_model diff --git a/Processes/NullModel/testNullModel.cc b/Processes/NullModel/testNullModel.cc index c098b025..908d7370 100644 --- a/Processes/NullModel/testNullModel.cc +++ b/Processes/NullModel/testNullModel.cc @@ -13,11 +13,41 @@ // cpp file #include <catch2/catch.hpp> +#include <corsika/process/null_model/NullModel.h> + +#include <corsika/geometry/Point.h> +#include <corsika/geometry/Vector.h> +#include <corsika/geometry/RootCoordinateSystem.h> + #include <corsika/units/PhysicalUnits.h> +#include <corsika/setup/SetupStack.h> +#include <corsika/setup/SetupTrajectory.h> + +using namespace corsika::units::si; +using namespace corsika::process::null_model; +using namespace corsika; + TEST_CASE("NullModel", "[processes]") { - SECTION("bla") {} + auto const& cs = geometry::RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); + geometry::Point const origin(cs, {0_m, 0_m, 0_m}); + geometry::Vector<corsika::units::si::SpeedType::dimension_type> v(cs, 0_m / second, + 0_m / second, 1_m / second); + geometry::Line line(origin, v); + geometry::Trajectory<geometry::Line> track(line, 10_s); + + setup::Stack stack; + auto particle = stack.NewParticle(); + + SECTION("interface") { + + NullModel<setup::Stack> model; + + model.Init(); + [[maybe_unused]] const process::EProcessReturn ret = model.DoContinuous(particle, track, stack); + [[maybe_unused]] const double length = model.MaxStepLength(particle, track); - SECTION("blubb") {} + + } } diff --git a/Processes/Sibyll/CMakeLists.txt b/Processes/Sibyll/CMakeLists.txt index 880ed76d..9224d9fe 100644 --- a/Processes/Sibyll/CMakeLists.txt +++ b/Processes/Sibyll/CMakeLists.txt @@ -94,6 +94,9 @@ add_executable (testSibyll target_link_libraries ( testSibyll + ProcessSibyll + CORSIKAsetup + CORSIKArandom CORSIKAgeometry CORSIKAunits CORSIKAthirdparty # for catch2 diff --git a/Processes/Sibyll/Decay.h b/Processes/Sibyll/Decay.h index cc13040b..fd1a8f42 100644 --- a/Processes/Sibyll/Decay.h +++ b/Processes/Sibyll/Decay.h @@ -4,7 +4,9 @@ #include <corsika/process/sibyll/SibStack.h> #include <corsika/process/sibyll/ParticleConversion.h> #include <corsika/process/DecayProcess.h> + #include <corsika/setup/SetupTrajectory.h> +#include <corsika/setup/SetupStack.h> #include <corsika/particles/ParticleProperties.h> diff --git a/Processes/Sibyll/Interaction.h b/Processes/Sibyll/Interaction.h index c0ceb87d..fa22f7fc 100644 --- a/Processes/Sibyll/Interaction.h +++ b/Processes/Sibyll/Interaction.h @@ -21,13 +21,7 @@ using namespace corsika::units::si; namespace corsika::process::sibyll { - // template <typename Stack, typename Track> - //template <typename Stack> - class Interaction : public corsika::process::InteractionProcess<Interaction> { // <Stack,Track>> { - - //typedef typename Stack::ParticleType Particle; - //typedef typename corsika::setup::Stack::ParticleType Particle; - //typedef corsika::setup::Trajectory Track; + class Interaction : public corsika::process::InteractionProcess<Interaction> { public: @@ -54,7 +48,7 @@ namespace corsika::process::sibyll { double GetInteractionLength(Particle& p, Track&) const { // coordinate system, get global frame of reference - CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCS(); + CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); const particles::Code corsikaBeamId = p.GetPID(); @@ -142,7 +136,7 @@ namespace corsika::process::sibyll { if (process::sibyll::CanInteract(p.GetPID())) { cout << "defining coordinates" << endl; // coordinate system, get global frame of reference - CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCS(); + CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); QuantityVector<length_d> const coordinates{0_m, 0_m, 0_m}; Point pOrig(rootCS, coordinates); diff --git a/Processes/Sibyll/SibStack.h b/Processes/Sibyll/SibStack.h index 4c0326a9..09e97b39 100644 --- a/Processes/Sibyll/SibStack.h +++ b/Processes/Sibyll/SibStack.h @@ -39,7 +39,7 @@ public: EnergyType GetEnergy(const int i) const { return s_plist_.p[3][i] * 1_GeV; } super_stupid::MomentumVector GetMomentum(const int i) const { - CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCS(); + CoordinateSystem& rootCS = RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); corsika::geometry::QuantityVector<momentum_d> components{ s_plist_.p[0][i] * 1_GeV / constants::c, s_plist_.p[1][i] * 1_GeV / constants::c, diff --git a/Processes/Sibyll/testSibyll.cc b/Processes/Sibyll/testSibyll.cc index 67c950e5..5d91a5b4 100644 --- a/Processes/Sibyll/testSibyll.cc +++ b/Processes/Sibyll/testSibyll.cc @@ -9,17 +9,18 @@ * the license. */ -#include <corsika/particles/ParticleProperties.h> +#include <corsika/process/sibyll/Interaction.h> +#include <corsika/process/sibyll/Decay.h> #include <corsika/process/sibyll/ParticleConversion.h> -#include <corsika/units/PhysicalUnits.h> + +#include <corsika/particles/ParticleProperties.h> #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one // cpp file #include <catch2/catch.hpp> -#include <iostream> -using namespace std; using namespace corsika; +using namespace corsika::process::sibyll; TEST_CASE("Sibyll", "[processes]") { @@ -57,5 +58,51 @@ TEST_CASE("Sibyll", "[processes]") { REQUIRE(process::sibyll::GetSibyllXSCode(corsika::particles::Code::K0Long) == 3); REQUIRE(process::sibyll::GetSibyllXSCode(corsika::particles::Code::SigmaPlus) == 1); REQUIRE(process::sibyll::GetSibyllXSCode(corsika::particles::Code::PiMinus) == 2); + } +} + +#include <corsika/geometry/Point.h> +#include <corsika/geometry/Vector.h> +#include <corsika/geometry/RootCoordinateSystem.h> + +#include <corsika/units/PhysicalUnits.h> + +#include <corsika/setup/SetupStack.h> +#include <corsika/setup/SetupTrajectory.h> + +using namespace corsika::units::si; + +TEST_CASE("SibyllInterface", "[processes]") { + + auto const& cs = geometry::RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); + geometry::Point const origin(cs, {0_m, 0_m, 0_m}); + geometry::Vector<corsika::units::si::SpeedType::dimension_type> v(cs, 0_m / second, + 0_m / second, 1_m / second); + geometry::Line line(origin, v); + geometry::Trajectory<geometry::Line> track(line, 10_s); + + setup::Stack stack; + auto particle = stack.NewParticle(); + + SECTION("InteractionInterface") { + + Interaction model; + + model.Init(); + [[maybe_unused]] const process::EProcessReturn ret = model.DoInteraction(particle, stack); + [[maybe_unused]] const double length = model.GetInteractionLength(particle, track); + + } + + SECTION("DecayInterface") { + + Decay model; + + model.Init(); + /*[[maybe_unused]] const process::EProcessReturn ret =*/ model.DoDecay(particle, stack); + [[maybe_unused]] const double length = model.GetLifetime(particle); + } + } + diff --git a/Processes/StackInspector/CMakeLists.txt b/Processes/StackInspector/CMakeLists.txt index b0b9d379..f87cc137 100644 --- a/Processes/StackInspector/CMakeLists.txt +++ b/Processes/StackInspector/CMakeLists.txt @@ -29,6 +29,7 @@ set_target_properties ( target_link_libraries ( ProcessStackInspector CORSIKAunits + CORSIKAgeometry CORSIKAsetup ) @@ -53,6 +54,9 @@ add_executable (testStackInspector testStackInspector.cc) target_link_libraries ( testStackInspector + ProcessStackInspector + CORSIKAsetup + CORSIKAgeometry CORSIKAunits CORSIKAthirdparty # for catch2 ) diff --git a/Processes/StackInspector/StackInspector.cc b/Processes/StackInspector/StackInspector.cc index ad904428..f062c6e4 100644 --- a/Processes/StackInspector/StackInspector.cc +++ b/Processes/StackInspector/StackInspector.cc @@ -45,7 +45,7 @@ process::EProcessReturn StackInspector<Stack>::DoContinuous(Particle&, setup::Tr EnergyType E = iterP.GetEnergy(); Etot += E; geometry::CoordinateSystem& rootCS = - geometry::RootCoordinateSystem::GetInstance().GetRootCS(); // for printout + geometry::RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); // for printout auto pos = iterP.GetPosition().GetCoordinates(rootCS); cout << "StackInspector: i=" << setw(5) << fixed << (i++) << ", id=" << setw(30) << iterP.GetPID() << " E=" << setw(15) << scientific << (E / 1_GeV) << " GeV, " diff --git a/Processes/StackInspector/StackInspector.h b/Processes/StackInspector/StackInspector.h index 6032beac..d4b9f1fa 100644 --- a/Processes/StackInspector/StackInspector.h +++ b/Processes/StackInspector/StackInspector.h @@ -31,11 +31,7 @@ namespace corsika::process { ~StackInspector(); void Init(); - - // template <typename Particle, typename Trajectory, typename Stack> EProcessReturn DoContinuous(Particle&, corsika::setup::Trajectory&, Stack& s) const; - - // template <typename Particle> double MaxStepLength(Particle&, corsika::setup::Trajectory&) const; private: diff --git a/Processes/StackInspector/testStackInspector.cc b/Processes/StackInspector/testStackInspector.cc index c098b025..51f796a2 100644 --- a/Processes/StackInspector/testStackInspector.cc +++ b/Processes/StackInspector/testStackInspector.cc @@ -13,11 +13,43 @@ // cpp file #include <catch2/catch.hpp> +#include <corsika/process/stack_inspector/StackInspector.h> + +#include <corsika/geometry/Point.h> +#include <corsika/geometry/Vector.h> +#include <corsika/geometry/RootCoordinateSystem.h> + #include <corsika/units/PhysicalUnits.h> -TEST_CASE("NullModel", "[processes]") { +#include <corsika/setup/SetupStack.h> +#include <corsika/setup/SetupTrajectory.h> + +using namespace corsika::units::si; +using namespace corsika::process::stack_inspector; +using namespace corsika; + + +TEST_CASE("StackInspector", "[processes]") { - SECTION("bla") {} + auto const& cs = geometry::RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); + geometry::Point const origin(cs, {0_m, 0_m, 0_m}); + geometry::Vector<corsika::units::si::SpeedType::dimension_type> v(cs, 0_m / second, + 0_m / second, 1_m / second); + geometry::Line line(origin, v); + geometry::Trajectory<geometry::Line> track(line, 10_s); - SECTION("blubb") {} + setup::Stack stack; + auto particle = stack.NewParticle(); + + SECTION("interface") { + + StackInspector<setup::Stack> model(true); + + model.Init(); + [[maybe_unused]] const process::EProcessReturn ret = model.DoContinuous(particle, track, stack); + [[maybe_unused]] const double length = model.MaxStepLength(particle, track); + + } } + + diff --git a/Stack/SuperStupidStack/SuperStupidStack.h b/Stack/SuperStupidStack/SuperStupidStack.h index a889d32a..d865c2d1 100644 --- a/Stack/SuperStupidStack/SuperStupidStack.h +++ b/Stack/SuperStupidStack/SuperStupidStack.h @@ -71,7 +71,7 @@ namespace corsika::stack { Point GetPosition() const { return GetStackData().GetPosition(GetIndex()); } TimeType GetTime() const { return GetStackData().GetTime(GetIndex()); } -#warning this does not really work, nor make sense: +#warning this does not really work, nor makes sense: Vector<SpeedType::dimension_type> GetDirection() const { auto P = GetMomentum(); return P / P.norm() * 1e10 * (units::si::meter / units::si::second); @@ -139,7 +139,7 @@ namespace corsika::stack { fDataE.push_back(0 * joule); //#TODO this here makes no sense: see issue #48 geometry::CoordinateSystem& dummyCS = - geometry::RootCoordinateSystem::GetInstance().GetRootCS(); + geometry::RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); fMomentum.push_back(MomentumVector( dummyCS, {0 * newton_second, 0 * newton_second, 0 * newton_second})); fPosition.push_back(Point(dummyCS, {0 * meter, 0 * meter, 0 * meter})); diff --git a/Stack/SuperStupidStack/testSuperStupidStack.cc b/Stack/SuperStupidStack/testSuperStupidStack.cc index 28cb891b..21f88290 100644 --- a/Stack/SuperStupidStack/testSuperStupidStack.cc +++ b/Stack/SuperStupidStack/testSuperStupidStack.cc @@ -35,7 +35,7 @@ TEST_CASE("SuperStupidStack", "[stack]") { p.SetPID(particles::Code::Electron); p.SetEnergy(1.5_GeV); geometry::CoordinateSystem& dummyCS = - geometry::RootCoordinateSystem::GetInstance().GetRootCS(); + geometry::RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); p.SetMomentum(MomentumVector( dummyCS, {1 * newton_second, 1 * newton_second, 1 * newton_second})); p.SetPosition(Point(dummyCS, {1 * meter, 1 * meter, 1 * meter})); -- GitLab