Commit a0faa86e by Alejandro Homs Puron Committed by operator for beamline

### Add XYStat for Linear Regression calculation

parent f7250456
 ... ... @@ -408,8 +408,35 @@ private: static bool DoHist; }; struct XYStat { double xacc, xacc2, yacc, xyacc; int xn; double factor; mutable Mutex lock; XYStat(double f = 1); void reset(); void add(double x, double y); XYStat& operator =(const XYStat& o); XYStat& operator += (const XYStat& o); // Linear Regression struct LinRegress { int n; double slope; double offset; LinRegress() : n(0), slope(0), offset(0) {} }; int n() const; LinRegress calcLinRegress() const; }; std::ostream& operator <<(std::ostream& os, const SimpleStat::Histogram& s); std::ostream& operator <<(std::ostream& os, const SimpleStat& s); std::ostream& operator <<(std::ostream& os, const XYStat::LinRegress& r); class Camera; ... ...
 ... ... @@ -475,6 +475,76 @@ double SimpleStat::std() const return xn ? sqrt(xacc2 / xn - pow(ave(), 2)) : 0; } XYStat::XYStat(double f) : factor(f) { reset(); } void XYStat::reset() { AutoMutex l(lock); xacc = xacc2 = yacc = xyacc = 0; xn = 0; } void XYStat::add(double x, double y) { AutoMutex l(lock); y *= factor; xacc += x; xacc2 += pow(x, 2); yacc += y; xyacc += x * y; ++xn; } XYStat& XYStat::operator =(const XYStat& o) { if (&o == this) return *this; AutoMutex l(o.lock); xacc = o.xacc; xacc2 = o.xacc2; yacc = o.yacc; xyacc = o.xyacc; xn = o.xn; factor = o.factor; return *this; } XYStat& XYStat::operator +=(const XYStat& o) { if (o.factor != factor) throw LIMA_HW_EXC(Error, "Cannot add different XYStats"); AutoMutex l(o.lock); xacc += o.xacc; xacc2 += o.xacc2; yacc += o.yacc; xyacc += o.xyacc; xn += o.xn; return *this; } int XYStat::n() const { AutoMutex l(lock); return xn; } XYStat::LinRegress XYStat::calcLinRegress() const { AutoMutex l(lock); LinRegress r; if (!xn) return r; r.n = xn; r.slope = (xn * xyacc - xacc * yacc) / (xn * xacc2 - xacc * xacc); r.offset = (yacc - r.slope * xacc) / xn; return r; } FrameType lima::SlsDetector::getLatestFrame(const FrameArray& l) { DEB_STATIC_FUNCT(); ... ... @@ -569,6 +639,16 @@ ostream& lima::SlsDetector::operator <<(ostream& os, const SimpleStat& s) return os << ">"; } ostream& lima::SlsDetector::operator <<(ostream& os, const XYStat::LinRegress& r) { os << "<"; os << "slope=" << r.slope << ", " << "offset=" << r.offset << ", " << "n=" << r.n; return os << ">"; } TimeRangesChangedCallback::TimeRangesChangedCallback() : m_cam(NULL) { ... ...
 ... ... @@ -23,7 +23,8 @@ set(test_src test_slsdetector test_slsdetector_control test_thread_cpu_affinity test_expand_4) test_expand_4 test_stat) limatools_run_camera_tests("\${test_src}" \${PROJECT_NAME})