Jpp  18.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JWeight.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JWEIGHT__
2 #define __JTOOLS__JWEIGHT__
3 
4 #include <cmath>
5 
6 #include "JLang/JTitle.hh"
7 
8 
9 /**
10  * \author mdejong
11  */
12 
13 namespace JTOOLS {}
14 namespace JPP { using namespace JTOOLS; }
15 
16 namespace JTOOLS {
17 
18  using JLANG::JTitle;
19 
20  /**
21  * Weight calculator.
22  */
23  class JWeight :
24  public JTitle
25  {
26  public:
27  /**
28  * Constructor.
29  *
30  * \param title title
31  */
32  JWeight(const JTitle& title = "") :
33  JTitle(title)
34  {
35  reset();
36  }
37 
38 
39  /**
40  * Reset.
41  */
42  void reset()
43  {
44  tot = 0.0;
45  err = 0.0;
46  num = 0;
47  }
48 
49 
50  /**
51  * Put weight.
52  *
53  * \param w weight
54  */
55  void put(const double w)
56  {
57  tot += w;
58  err += w*w;
59  num += 1;
60  }
61 
62 
63  /**
64  * Get total count.
65  *
66  * \return count
67  */
68  long long int getCount() const
69  {
70  return num;
71  }
72 
73 
74  /**
75  * Get total weight.
76  *
77  * \return weight
78  */
79  double getTotal() const
80  {
81  return tot;
82  }
83 
84 
85  /**
86  * Get total error.
87  *
88  * \return error
89  */
90  double getError() const
91  {
92  return sqrt(err);
93  }
94 
95  protected:
96  double tot;
97  double err;
98  long long int num;
99  };
100 }
101 
102 #endif
data_type w[N+1][M+1]
Definition: JPolint.hh:867
double getTotal() const
Get total weight.
Definition: JWeight.hh:79
double err
Definition: JWeight.hh:97
void reset()
Reset.
Definition: JWeight.hh:42
double getError() const
Get total error.
Definition: JWeight.hh:90
void put(const double w)
Put weight.
Definition: JWeight.hh:55
Auxiliary class for title.
Definition: JTitle.hh:19
long long int getCount() const
Get total count.
Definition: JWeight.hh:68
Weight calculator.
Definition: JWeight.hh:23
double tot
Definition: JWeight.hh:96
long long int num
Definition: JWeight.hh:98
std::string title
Definition: JTitle.hh:73
JWeight(const JTitle &title="")
Constructor.
Definition: JWeight.hh:32