diff --git a/corsika/detail/modules/OnShellCheck.inl b/corsika/detail/modules/OnShellCheck.inl index c479ff66ed21a13cc05b8fafa9bb35d1882c38ca..aa6b0453fb24400246c96de206fa415dd0ade7cb 100644 --- a/corsika/detail/modules/OnShellCheck.inl +++ b/corsika/detail/modules/OnShellCheck.inl @@ -10,6 +10,7 @@ #include <corsika/framework/geometry/FourVector.hpp> #include <corsika/modules/OnShellCheck.hpp> +#include <corsika/framework/core/Logging.hpp> namespace corsika { @@ -18,26 +19,26 @@ namespace corsika { : mass_tolerance_(vMassTolerance) , energy_tolerance_(vEnergyTolerance) , throw_error_(vError) { - std::cout << "OnShellCheck: mass tolerance is set to " << mass_tolerance_ * 100 << "%" - << std::endl - << " energy tolerance is set to " << energy_tolerance_ * 100 - << "%" << std::endl; + CORSIKA_LOGGER_DEBUG(logger_, "mass tolerance is set to {:3.2f}%", + mass_tolerance_ * 100); + CORSIKA_LOGGER_DEBUG(logger_, "energy tolerance is set to {:3.2f}%", + energy_tolerance_ * 100); } OnShellCheck::~OnShellCheck() { - std::cout << "OnShellCheck: summary" << std::endl - << " particles shifted: " << int(count_) << std::endl; - if (count_) - std::cout << " average energy shift (%): " << average_shift_ / count_ * 100. - << std::endl - << " max. energy shift (%): " << max_shift_ * 100. << std::endl; + logger_->info( + " summary \n" + " particles shifted: {} \n" + " average energy shift (%): {} \n" + " max. energy shift (%): {} ", + int(count_), (count_ ? average_shift_ / count_ * 100 : 0), max_shift_ * 100.); } template <typename TView> void OnShellCheck::doSecondaries(TView& vS) { for (auto& p : vS) { auto const pid = p.getPID(); - if (!is_hadron(pid) || is_nucleus(pid)) continue; + if (is_nucleus(pid)) continue; auto const e_original = p.getEnergy(); auto const p_original = p.getMomentum(); auto const Plab = FourVector(e_original, p_original); @@ -51,23 +52,24 @@ namespace corsika { count_ = count_ + 1; average_shift_ += abs(e_shift_relative); if (abs(e_shift_relative) > max_shift_) max_shift_ = abs(e_shift_relative); - std::cout << "OnShellCheck: shift particle mass for " << pid << std::endl - << std::setw(40) << std::setfill(' ') - << "corsika mass (GeV): " << m_corsika / 1_GeV << std::endl - << std::setw(40) << std::setfill(' ') - << "kinetic mass (GeV): " << m_kinetic / 1_GeV << std::endl - << std::setw(40) << std::setfill(' ') - << "m_kin-m_cor (GeV): " << m_err_abs / 1_GeV << std::endl - << std::setw(40) << std::setfill(' ') - << "mass tolerance (GeV): " << (m_corsika * mass_tolerance_) / 1_GeV - << std::endl; + CORSIKA_LOGGER_TRACE( + logger_, + "shift particle mass for {} \n" + "{:>45} {:7.5f} \n" + "{:>45} {:7.5f} \n" + "{:>45} {:7.5f} \n" + "{:>45} {:7.5f} \n", + pid, "corsika mass (GeV):", m_corsika / 1_GeV, + "kinetic mass (GeV): ", m_kinetic / 1_GeV, + "m_kin-m_cor (GeV): ", m_err_abs / 1_GeV, + "mass tolerance (GeV): ", (m_corsika * mass_tolerance_) / 1_GeV); /* For now we warn if the necessary shift is larger than 1%. we could promote this to an error. */ if (abs(e_shift_relative) > energy_tolerance_) { - std::cout << "OnShellCheck: warning! shifted particle energy by " - << e_shift_relative * 100 << " %" << std::endl; + logger_->warn("warning! shifted particle energy by {} %", + e_shift_relative * 100); if (throw_error_) throw std::runtime_error( "OnShellCheck: error! shifted energy by large amount!"); @@ -76,7 +78,7 @@ namespace corsika { // reset energy p.setEnergy(e_shifted); } else - std::cout << "OnShellCheck: particle mass for " << pid << " OK" << std::endl; + CORSIKA_LOGGER_DEBUG(logger_, "particle mass for {} OK", pid); } } diff --git a/corsika/modules/OnShellCheck.hpp b/corsika/modules/OnShellCheck.hpp index a7efa4e26241fee9c0036137a38c6f73c02f3e6a..b51f55adac5b8b85aeafdde2db711e26c06ab61d 100644 --- a/corsika/modules/OnShellCheck.hpp +++ b/corsika/modules/OnShellCheck.hpp @@ -31,7 +31,7 @@ namespace corsika { double average_shift_ = 0; double max_shift_ = 0; double count_ = 0; - + std::shared_ptr<spdlog::logger> logger_ = get_logger("corsika_OnShellCheck"); double mass_tolerance_; double energy_tolerance_; bool throw_error_; diff --git a/tests/modules/testOnShellCheck.cpp b/tests/modules/testOnShellCheck.cpp index f7577569c8188afd5d79fd90490d703911ba4943..eccf73f287e9b07642ba5ed65e807d15d524f935 100644 --- a/tests/modules/testOnShellCheck.cpp +++ b/tests/modules/testOnShellCheck.cpp @@ -24,7 +24,7 @@ using namespace corsika; TEST_CASE("OnShellCheck", "[processes]") { - logging::set_level(logging::level::info); + logging::set_level(logging::level::debug); corsika_logger->set_pattern("[%n:%^%-8l%$] custom pattern: %v"); feenableexcept(FE_INVALID); @@ -38,9 +38,10 @@ TEST_CASE("OnShellCheck", "[processes]") { // two energies const HEPEnergyType E = 10_GeV; // list of arbitrary particles - std::array const particleList{Code::PiPlus, Code::PiMinus, Code::Helium, Code::Gamma}; + std::array const particleList{Code::PiPlus, Code::PiMinus, Code::Helium, + Code::Gamma, Code::Electron, Code::MuPlus}; - std::array const mass_shifts{1.1, 1.001, 1.0, 1.0}; + std::array const mass_shifts{1.1, 1.001, 1.0, 1.0, 1.01, 1.0}; SECTION("check particle masses") {