diff --git a/include/HEJ/CrossSectionAccumulator.hh b/include/HEJ/CrossSectionAccumulator.hh index 86ac501..013ffa5 100644 --- a/include/HEJ/CrossSectionAccumulator.hh +++ b/include/HEJ/CrossSectionAccumulator.hh @@ -1,69 +1,69 @@ #pragma once #include <map> #include <ostream> #include <iomanip> #include <string> #include "HEJ/Event.hh" #include "HEJ/event_types.hh" namespace HEJ { template<typename T> struct XSWithError { T value = T{}; T error = T{}; }; /** * @brief Sum of Cross Section for different subproccess */ class CrossSectionAccumulator { public: void fill(HEJ::Event const & ev) { const double wt = ev.central().weight; auto & entry = xs_[ev.type()]; entry.value += wt; entry.error += wt*wt; total_.value += wt; total_.error += wt*wt; } auto begin() const { return std::begin(xs_); } auto end() const { return std::end(xs_); } //! total Cross Section and error XSWithError<double> total() const { return total_; } private: std::map<HEJ::event_type::EventType, XSWithError<double>> xs_; XSWithError<double> total_; }; std::ostream& operator<<(std::ostream& os, const CrossSectionAccumulator& xs){ const std::streamsize orig_prec = os.precision(); os << std::scientific << std::setprecision(3) << " " << std::left << std::setw(25) << "Cross section: " << xs.total().value << " +- " << std::sqrt(xs.total().error) << " (pb)\n"; for(auto const & xs_type: xs) { os << " " << std::left << std::scientific <<std::setw(25) << (HEJ::event_type::names[xs_type.first] + std::string(": ")); os << xs_type.second.value << " +- " << std::sqrt(xs_type.second.error) << " (pb) " << std::fixed << std::setprecision(3) - << "[" << ((xs_type.second.value)/xs.total().value)*100 << "%]" + << "[" <<std::setw(6) <<std::right<< ((xs_type.second.value)/xs.total().value)*100 << "%]" << std::endl; } os << std::defaultfloat; os.precision(orig_prec); return os; } }