#ifndef __JTOOLS__JWEIGHT__ #define __JTOOLS__JWEIGHT__ #include #include "JLang/JTitle.hh" /** * \author mdejong */ namespace JTOOLS {} namespace JPP { using namespace JTOOLS; } namespace JTOOLS { using JLANG::JTitle; /** * Weight calculator. */ class JWeight : public JTitle { public: /** * Constructor. * * \param title title */ JWeight(const JTitle& title = "") : JTitle(title) { reset(); } /** * Reset. */ void reset() { tot = 0.0; err = 0.0; num = 0; } /** * Put weight. * * \param w weight */ void put(const double w) { tot += w; err += w*w; num += 1; } /** * Get total count. * * \return count */ long long int getCount() const { return num; } /** * Get total weight. * * \return weight */ double getTotal() const { return tot; } /** * Get total error. * * \return error */ double getError() const { return sqrt(err); } protected: double tot; double err; long long int num; }; } #endif