IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 2d76ccc1 authored by Felix Riehn's avatar Felix Riehn Committed by Ralf Ulrich
Browse files

use logger in process OnShellCheck

parent 18f99dec
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <corsika/framework/geometry/FourVector.hpp> #include <corsika/framework/geometry/FourVector.hpp>
#include <corsika/modules/OnShellCheck.hpp> #include <corsika/modules/OnShellCheck.hpp>
#include <corsika/framework/core/Logging.hpp>
namespace corsika { namespace corsika {
...@@ -18,19 +19,19 @@ namespace corsika { ...@@ -18,19 +19,19 @@ namespace corsika {
: mass_tolerance_(vMassTolerance) : mass_tolerance_(vMassTolerance)
, energy_tolerance_(vEnergyTolerance) , energy_tolerance_(vEnergyTolerance)
, throw_error_(vError) { , throw_error_(vError) {
std::cout << "OnShellCheck: mass tolerance is set to " << mass_tolerance_ * 100 << "%" CORSIKA_LOGGER_DEBUG(logger_, "mass tolerance is set to {:3.2f}%",
<< std::endl mass_tolerance_ * 100);
<< " energy tolerance is set to " << energy_tolerance_ * 100 CORSIKA_LOGGER_DEBUG(logger_, "energy tolerance is set to {:3.2f}%",
<< "%" << std::endl; energy_tolerance_ * 100);
} }
OnShellCheck::~OnShellCheck() { OnShellCheck::~OnShellCheck() {
std::cout << "OnShellCheck: summary" << std::endl logger_->info(
<< " particles shifted: " << int(count_) << std::endl; " summary \n"
if (count_) " particles shifted: {} \n"
std::cout << " average energy shift (%): " << average_shift_ / count_ * 100. " average energy shift (%): {} \n"
<< std::endl " max. energy shift (%): {} ",
<< " max. energy shift (%): " << max_shift_ * 100. << std::endl; int(count_), (count_ ? average_shift_ / count_ * 100 : 0), max_shift_ * 100.);
} }
template <typename TView> template <typename TView>
...@@ -51,23 +52,24 @@ namespace corsika { ...@@ -51,23 +52,24 @@ namespace corsika {
count_ = count_ + 1; count_ = count_ + 1;
average_shift_ += abs(e_shift_relative); average_shift_ += abs(e_shift_relative);
if (abs(e_shift_relative) > max_shift_) max_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 CORSIKA_LOGGER_TRACE(
<< std::setw(40) << std::setfill(' ') logger_,
<< "corsika mass (GeV): " << m_corsika / 1_GeV << std::endl "shift particle mass for {} \n"
<< std::setw(40) << std::setfill(' ') "{:>45} {:7.5f} \n"
<< "kinetic mass (GeV): " << m_kinetic / 1_GeV << std::endl "{:>45} {:7.5f} \n"
<< std::setw(40) << std::setfill(' ') "{:>45} {:7.5f} \n"
<< "m_kin-m_cor (GeV): " << m_err_abs / 1_GeV << std::endl "{:>45} {:7.5f} \n",
<< std::setw(40) << std::setfill(' ') pid, "corsika mass (GeV):", m_corsika / 1_GeV,
<< "mass tolerance (GeV): " << (m_corsika * mass_tolerance_) / 1_GeV "kinetic mass (GeV): ", m_kinetic / 1_GeV,
<< std::endl; "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%. For now we warn if the necessary shift is larger than 1%.
we could promote this to an error. we could promote this to an error.
*/ */
if (abs(e_shift_relative) > energy_tolerance_) { if (abs(e_shift_relative) > energy_tolerance_) {
std::cout << "OnShellCheck: warning! shifted particle energy by " logger_->warn("warning! shifted particle energy by {} %",
<< e_shift_relative * 100 << " %" << std::endl; e_shift_relative * 100);
if (throw_error_) if (throw_error_)
throw std::runtime_error( throw std::runtime_error(
"OnShellCheck: error! shifted energy by large amount!"); "OnShellCheck: error! shifted energy by large amount!");
...@@ -76,7 +78,7 @@ namespace corsika { ...@@ -76,7 +78,7 @@ namespace corsika {
// reset energy // reset energy
p.setEnergy(e_shifted); p.setEnergy(e_shifted);
} else } else
std::cout << "OnShellCheck: particle mass for " << pid << " OK" << std::endl; CORSIKA_LOGGER_DEBUG(logger_, "OnShellCheck: particle mass for {} OK", pid);
} }
} }
......
...@@ -31,7 +31,7 @@ namespace corsika { ...@@ -31,7 +31,7 @@ namespace corsika {
double average_shift_ = 0; double average_shift_ = 0;
double max_shift_ = 0; double max_shift_ = 0;
double count_ = 0; double count_ = 0;
std::shared_ptr<spdlog::logger> logger_ = get_logger("on_shell_check");
double mass_tolerance_; double mass_tolerance_;
double energy_tolerance_; double energy_tolerance_;
bool throw_error_; bool throw_error_;
......
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