mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 04:47:14 +02:00
formatted slsDetectorCalibration
This commit is contained in:
@ -1,57 +1,37 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-other
|
||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||
class RunningStat
|
||||
{
|
||||
public:
|
||||
RunningStat() : m_n(0) {}
|
||||
class RunningStat {
|
||||
public:
|
||||
RunningStat() : m_n(0) {}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
m_n = 0;
|
||||
void Clear() { m_n = 0; }
|
||||
|
||||
void Push(double x) {
|
||||
m_n++;
|
||||
|
||||
// See Knuth TAOCP vol 2, 3rd edition, page 232
|
||||
if (m_n == 1) {
|
||||
m_oldM = m_newM = x;
|
||||
m_oldS = 0.0;
|
||||
} else {
|
||||
m_newM = m_oldM + (x - m_oldM) / m_n;
|
||||
m_newS = m_oldS + (x - m_oldM) * (x - m_newM);
|
||||
|
||||
// set up for next iteration
|
||||
m_oldM = m_newM;
|
||||
m_oldS = m_newS;
|
||||
}
|
||||
}
|
||||
|
||||
void Push(double x)
|
||||
{
|
||||
m_n++;
|
||||
int NumDataValues() const { return m_n; }
|
||||
|
||||
// See Knuth TAOCP vol 2, 3rd edition, page 232
|
||||
if (m_n == 1)
|
||||
{
|
||||
m_oldM = m_newM = x;
|
||||
m_oldS = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_newM = m_oldM + (x - m_oldM)/m_n;
|
||||
m_newS = m_oldS + (x - m_oldM)*(x - m_newM);
|
||||
|
||||
// set up for next iteration
|
||||
m_oldM = m_newM;
|
||||
m_oldS = m_newS;
|
||||
}
|
||||
}
|
||||
double Mean() const { return (m_n > 0) ? m_newM : 0.0; }
|
||||
|
||||
int NumDataValues() const
|
||||
{
|
||||
return m_n;
|
||||
}
|
||||
double Variance() const { return ((m_n > 1) ? m_newS / (m_n - 1) : 0.0); }
|
||||
|
||||
double Mean() const
|
||||
{
|
||||
return (m_n > 0) ? m_newM : 0.0;
|
||||
}
|
||||
double StandardDeviation() const { return sqrt(Variance()); }
|
||||
|
||||
double Variance() const
|
||||
{
|
||||
return ( (m_n > 1) ? m_newS/(m_n - 1) : 0.0 );
|
||||
}
|
||||
|
||||
double StandardDeviation() const
|
||||
{
|
||||
return sqrt( Variance() );
|
||||
}
|
||||
|
||||
private:
|
||||
int m_n;
|
||||
double m_oldM, m_newM, m_oldS, m_newS;
|
||||
};
|
||||
private:
|
||||
int m_n;
|
||||
double m_oldM, m_newM, m_oldS, m_newS;
|
||||
};
|
||||
|
Reference in New Issue
Block a user