Jpp
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
JTOOLS::JWeight::getCount
long long int getCount() const
Get total count.
Definition: JWeight.hh:68
JTOOLS::w
data_type w[N+1][M+1]
Definition: JPolint.hh:708
JTOOLS::JWeight
Weight calculator.
Definition: JWeight.hh:23
JTOOLS::JWeight::reset
void reset()
Reset.
Definition: JWeight.hh:42
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JLANG::JTitle
Auxiliary class for title.
Definition: JTitle.hh:19
JTitle.hh
JTOOLS::JWeight::err
double err
Definition: JWeight.hh:97
JTOOLS::JWeight::getTotal
double getTotal() const
Get total weight.
Definition: JWeight.hh:79
JTOOLS::JWeight::num
long long int num
Definition: JWeight.hh:98
JTOOLS::JWeight::put
void put(const double w)
Put weight.
Definition: JWeight.hh:55
JTOOLS
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Definition: JAbstractCollection.hh:9
JTOOLS::JWeight::getError
double getError() const
Get total error.
Definition: JWeight.hh:90
JTOOLS::JWeight::tot
double tot
Definition: JWeight.hh:96
JLANG::JTitle::title
std::string title
Definition: JTitle.hh:73
JTOOLS::JWeight::JWeight
JWeight(const JTitle &title="")
Constructor.
Definition: JWeight.hh:32