From abcf569cc675b58724564ce48208e4342e26d617 Mon Sep 17 00:00:00 2001 From: Maximilian Reininghaus <maximilian.reininghaus@tu-dortmund.de> Date: Fri, 22 Jan 2021 00:32:32 +0100 Subject: [PATCH] improved testInteractionCounter --- tests/framework/testInteractionCounter.cpp | 72 ++++------ .../testInteractionCounter_file1_REF.npz | Bin 2378 -> 4760 bytes .../testInteractionCounter_file2_REF.npz | Bin 1898 -> 3960 bytes tests/modules/testInteractionCounter.cpp | 134 ------------------ 4 files changed, 30 insertions(+), 176 deletions(-) delete mode 100644 tests/modules/testInteractionCounter.cpp diff --git a/tests/framework/testInteractionCounter.cpp b/tests/framework/testInteractionCounter.cpp index b9cb8b013..d4ba7df8a 100644 --- a/tests/framework/testInteractionCounter.cpp +++ b/tests/framework/testInteractionCounter.cpp @@ -21,6 +21,11 @@ #include <catch2/catch.hpp> #include <numeric> +#include <algorithm> +#include <iterator> +#include <string> +#include <fstream> +#include <cstdio> using namespace corsika; @@ -69,10 +74,31 @@ TEST_CASE("InteractionCounter", "[process]") { CHECK(h2.at(h2.axis(0).index(1'000'070'140), h2.axis(1).index(1.6e12)) == 1); CHECK(std::accumulate(h2.cbegin(), h2.cend(), 0) == 1); - countedProcess.getHistogram().saveLab("testInteractionCounter_file1.npz", - SaveMode::overwrite); - countedProcess.getHistogram().saveCMS("testInteractionCounter_file2.npz", - SaveMode::overwrite); + std::remove("testInteractionCounter_file1.npz"); + std::remove("testInteractionCounter_file2.npz"); + countedProcess.getHistogram().saveLab("testInteractionCounter_file1.npz"); + countedProcess.getHistogram().saveCMS("testInteractionCounter_file2.npz"); + + SECTION("output validation") { + auto const file = GENERATE(as<std::string>{}, "testInteractionCounter_file1", + "testInteractionCounter_file2"); + + std::cout << file + ".npz vs " << refDataDir + "/" + file + "_REF.npz" << std::endl; + + // compare to binary reference data + // note that this currenly compares the whole files byte by byte. If the new + // or the reference file are compressed this would be a false-negative outcome + // of this test + std::ifstream file1(file + ".npz"); + std::ifstream file1ref(refDataDir + "/" + file + "_REF.npz"); + + std::istreambuf_iterator<char> begin1(file1); + std::istreambuf_iterator<char> begin1ref(file1ref); + + std::istreambuf_iterator<char> end; + + CHECK(std::equal(begin1, end, begin1ref)); + } } SECTION("DoInteraction Lambda") { @@ -93,41 +119,3 @@ TEST_CASE("InteractionCounter", "[process]") { CHECK(std::accumulate(h2.cbegin(), h2.cend(), 0) == 1); } } - -#include <algorithm> -#include <iterator> -#include <string> -#include <fstream> - -TEST_CASE("InteractionCounterOutput", "[output validation]") { - - logging::set_level(logging::level::info); - corsika_logger->set_pattern("[%n:%^%-8l%$] custom pattern: %v"); - - auto file = GENERATE(as<std::string>{}, "testInteractionCounter_file1", - "testInteractionCounter_file2"); - - SECTION(std::string("check saved data, ") + file + ".npz") { - - std::cout << file + ".npz vs " << refDataDir + "/" + file + "_REF.npz" << std::endl; - - // compare to binary reference data - std::ifstream file1(file + ".npz"); - std::ifstream file1ref(refDataDir + "/" + file + "_REF.npz"); - - std::istreambuf_iterator<char> begin1(file1); - std::istreambuf_iterator<char> begin1ref(file1ref); - - std::istreambuf_iterator<char> end; - - while (begin1 != end && begin1ref != end) { - CHECK(*begin1 == *begin1ref); - ++begin1; - ++begin1ref; - } - CHECK(begin1 == end); - CHECK(begin1ref == end); - file1.close(); - file1ref.close(); - } -} diff --git a/tests/framework/testInteractionCounter_file1_REF.npz b/tests/framework/testInteractionCounter_file1_REF.npz index 13e2d5d49e16b6a2e7eb6b95dc1a26bccab18ae8..ca75c99e4df0292da9db9f05f5a7b3319c482653 100644 GIT binary patch literal 4760 zcmeI$c}x^n90%~XB48<MQR_j`j4irUSIP>uTUK$_gHjPhtT)H3>~bgqvQ#iu9kGh0 zUIhgjwG3XZL8^EZQ)wI^)oO)CY(?Y2AZkroO{sXrqn+>18e|h1)5IoCb~cmGet&P@ zzBlim_c9ToP91x&r&r*LD<cxsfZI*IXC<ZBV*Pwm(iY@}PY#Qiu3^D!q1Ixx#ieTl zIqmQygI33B<5SZ!(#<Kcsp%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VC{=$8S^K zHTMBj8b)iz;CJIHoT1<v{W262-t{28_Pk2<)bX!TzU|u|a(9XcP`%MO7%Hp0^-!+g zFpTQagN;!1_B2th%o$6$$uo3J+daZ9qR}r>{VDFw>TS+SvSlntv)bC<B9ipawQUWx z+aNg3%@Wska6hKpc{;eeI(X`QYkGWgYG(Um&-&M6Gfn$r<H0{nQMcd!YVgw=k4tCO zy&E^SaEm#^-2Owy2Rzq;`|CKpVd%4G1?<U=%drBE6>zM8V+9;5;8=kdx&q?J7y9@A z<3EoG)pY2=+J95h_R(73o7nfWf1}abZ@v0e?f1<44g0?KC*9V*2VCsVz4l%0&#A3l z^{#DCt^d>$r_9!?RPEX3%xT}%{*2h#b&z^we0pMx2z6Fx&zOt)nW16K#{=mvWWIQq delta 48 ucmbQCdP-=s76%{a<QO3-B?cf!Ni0d!%PXi1@MdKL@fm^83`qau0Pz3~RS4Dq diff --git a/tests/framework/testInteractionCounter_file2_REF.npz b/tests/framework/testInteractionCounter_file2_REF.npz index 8509b27e4d690a386c2710a24ceda6a1143bf757..2aaa26ed6240a2de96ae24cc566d695d7f4467b1 100644 GIT binary patch literal 3960 zcmeI#e@s<n7zgl|-;6-g7$r+~s_8{{Wn8!xLy&{C8xE0+<PT7~=fb_$i}A~Q2(ZE( zO$9f@gn~vHCrrx;6=*_+>j=xj1vzYiE90m{&6S1`*wpHLUt<@}b{p%Dwi@T|-RC~f zvuE!)?;q#9uQA!fGl)!FF}sK2>`H*)r;O~}0^Sr6UQo2PX4RS$V}=_skmocOE1%=g z#4wuJ+-QxK(bx(d#SU|UsnB7uB5yF~@m3|z+s#E*B@T<yF4QvR%%scjE#JFyvVVE| z>(`bdW1Mn7yDRPW?Vf~S%({C&R?8+UZ_>HGC)@PyNvGGT?g|gg5_TV}C>=XmL#^(5 z70UjL8z4E;a1e4;$KQcue#m=J7_2!4NzI{lC?@%Q3|Ugy1tqceGbomh_ChA?`SUbx zs~Dhh>!oiYyRPU86#C14fbw|nH5$KY`2})h^G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xhuF8IYD^2k`(sU<o4t diff --git a/tests/modules/testInteractionCounter.cpp b/tests/modules/testInteractionCounter.cpp deleted file mode 100644 index ba0ea2ce6..000000000 --- a/tests/modules/testInteractionCounter.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* - * (c) Copyright 2021 CORSIKA Project, corsika-project@lists.kit.edu - * - * This software is distributed under the terms of the GNU General Public - * Licence version 3 (GPL Version 3). See file LICENSE for a full version of - * the license. - */ - -#include <corsika/modules/InteractionCounter.hpp> - -#include <corsika/media/Environment.hpp> -#include <corsika/media/HomogeneousMedium.hpp> -#include <corsika/media/NuclearComposition.hpp> -#include <corsika/framework/geometry/Point.hpp> -#include <corsika/framework/geometry/RootCoordinateSystem.hpp> -#include <corsika/framework/geometry/Vector.hpp> -#include <corsika/framework/core/PhysicalUnits.hpp> - -#include <corsika/setup/SetupStack.hpp> - -#include <catch2/catch.hpp> - -#include <numeric> - -using namespace corsika; - -const std::string refDataDir = std::string(REFDATADIR); // from cmake - -struct DummyProcess { - template <typename TParticle> - GrammageType GetInteractionLength([[maybe_unused]] TParticle const& particle) { - return 100_g / 1_cm / 1_cm; - } - - template <typename TParticle> - auto DoInteraction([[maybe_unused]] TParticle& projectile) { - return nullptr; - } -}; - -TEST_CASE("InteractionCounter", "[process]") { - - logging::set_level(logging::level::info); - corsika_logger->set_pattern("[%n:%^%-8l%$] custom pattern: %v"); - - DummyProcess d; - InteractionCounter countedProcess(d); - - SECTION("GetInteractionLength") { - CHECK(countedProcess.GetInteractionLength(nullptr) == 100_g / 1_cm / 1_cm); - } - - auto [env, csPtr, nodePtr] = setup::testing::setupEnvironment(particles::Code::Oxygen); - [[maybe_unused]] auto& env_dummy = env; - - SECTION("DoInteraction nucleus") { - unsigned short constexpr A = 14, Z = 7; - auto [stackPtr, secViewPtr] = setup::testing::setupStack(particles::Code::Nucleus, A, - Z, 105_TeV, nodePtr, *csPtr); - CHECK(stackPtr->getEntries() == 1); - CHECK(secViewPtr->getEntries() == 0); - - auto const ret = countedProcess.DoInteraction(*secViewPtr); - CHECK(ret == nullptr); - - auto const& h = countedProcess.GetHistogram().labHist(); - CHECK(h.at(h.axis(0).index(1'000'070'140), h.axis(1).index(1.05e14)) == 1); - CHECK(std::accumulate(h.cbegin(), h.cend(), 0) == 1); - - auto const& h2 = countedProcess.GetHistogram().CMSHist(); - CHECK(h2.at(h2.axis(0).index(1'000'070'140), h2.axis(1).index(1.6e12)) == 1); - CHECK(std::accumulate(h2.cbegin(), h2.cend(), 0) == 1); - - countedProcess.GetHistogram().saveLab("testInteractionCounter_file1.npz"); - countedProcess.GetHistogram().saveCMS("testInteractionCounter_file2.npz"); - } - - SECTION("DoInteraction Lambda") { - auto constexpr code = particles::Code::Lambda0; - auto [stackPtr, secViewPtr] = - setup::testing::setupStack(code, 0, 0, 105_TeV, nodePtr, *csPtr); - CHECK(stackPtr->getEntries() == 1); - CHECK(secViewPtr->getEntries() == 0); - - auto const ret = countedProcess.DoInteraction(*secViewPtr); - CHECK(ret == nullptr); - - auto const& h = countedProcess.GetHistogram().labHist(); - CHECK(h.at(h.axis(0).index(3122), h.axis(1).index(1.05e14)) == 1); - CHECK(std::accumulate(h.cbegin(), h.cend(), 0) == 1); - - auto const& h2 = countedProcess.GetHistogram().CMSHist(); - CHECK(h2.at(h2.axis(0).index(3122), h2.axis(1).index(1.6e12)) == 1); - CHECK(std::accumulate(h2.cbegin(), h2.cend(), 0) == 1); - } -} - -#include <algorithm> -#include <iterator> -#include <string> -#include <fstream> - -TEST_CASE("InteractionCounterOutput", "[output validation]") { - - logging::set_level(logging::level::info); - corsika_logger->set_pattern("[%n:%^%-8l%$] custom pattern: %v"); - - auto file = GENERATE(as<std::string>{}, "testInteractionCounter_file1", - "testInteractionCounter_file2"); - - SECTION(std::string("check saved data, ") + file + ".npz") { - - std::cout << file + ".npz vs " << refDataDir + "/" + file + "_REF.npz" << std::endl; - - // compare to binary reference data - std::ifstream file1(file + ".npz"); - std::ifstream file1ref(refDataDir + "/" + file + "_REF.npz"); - - std::istreambuf_iterator<char> begin1(file1); - std::istreambuf_iterator<char> begin1ref(file1ref); - - std::istreambuf_iterator<char> end; - - while (begin1 != end && begin1ref != end) { - CHECK(*begin1 == *begin1ref); - ++begin1; - ++begin1ref; - } - CHECK(begin1 == end); - CHECK(begin1ref == end); - file1.close(); - file1ref.close(); - } -} -- GitLab