BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
CumulativeValue.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Device/Data/CumulativeValue.cpp
6 //! @brief Implements class CumulativeValue.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
16 #include <cmath>
17 
19 {
20  return std::sqrt(m_rms2);
21 }
22 
23 void CumulativeValue::add(double value, double weight)
24 {
25  m_n_entries++;
26  m_sum += value;
27  m_rms2 =
28  (m_sum_of_weights / (m_sum_of_weights + weight))
29  * (m_rms2
30  + (weight / (m_sum_of_weights + weight)) * (value - m_average) * (value - m_average));
31  m_average = m_average + (value - m_average) * weight / (m_sum_of_weights + weight);
32  m_sum_of_weights += weight;
33 }
34 
36 {
37  m_n_entries = 0;
38  m_sum = 0.0;
39  m_average = 0.0;
40  m_rms2 = 0.0;
41  m_sum_of_weights = 0.0;
42 }
43 
44 bool operator<(const CumulativeValue& lhs, const CumulativeValue& rhs)
45 {
46  return lhs.getContent() < rhs.getContent();
47 }
48 
49 bool operator>(const CumulativeValue& lhs, const CumulativeValue& rhs)
50 {
51  return rhs < lhs;
52 }
bool operator<(const CumulativeValue &lhs, const CumulativeValue &rhs)
bool operator>(const CumulativeValue &lhs, const CumulativeValue &rhs)
Defines class CumulativeValue.
The cumulative value with average and rms on-the-flight calculations.
double getContent() const
double getRMS() const
void add(double value, double weight=1.0)