ATLAS Offline Software
Loading...
Searching...
No Matches
LinFitSglPass.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
6// //
7// Header file for class LinFitSglPass //
8// //
9// Description: Little helper class for single-pass linear //
10// fits of data points. //
11// //
12// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
13// Initial version: February 2011 //
14// //
16
17#ifndef LINFITSGLPASS_H
18#define LINFITSGLPASS_H
19
20namespace PerfMon {
21
23public:
24
27
28 void addPoint(const double&,const double&);
29 void getFit(double&offset,double&slope) const;//Fitted line parametrised as: y(x) = offset + x*slope
30 void reset();
31 unsigned nPoints() const { return m_n; }
32 double slope() const;
33private:
34 unsigned m_n;
35 double m_sumx;
36 double m_sumy;
37 double m_sumxy;
38 double m_sumxx;
39};
40
42// Implementation //
44
46 : m_n(0),m_sumx(0),m_sumy(0),m_sumxy(0),m_sumxx(0)
47{
48}
49
51{
52 m_n=0;
54}
55
56inline void LinFitSglPass::addPoint(const double&x,const double&y)
57{
58 ++m_n;
59 m_sumx += x;
60 m_sumy += y;
61 m_sumxy += x*y;
62 m_sumxx += x*x;
63}
64
65inline void LinFitSglPass::getFit(double&offset,double&slope) const
66{
67 if (m_n<2) {
68 offset=slope=0;
69 } else {
71 offset = (m_sumy-slope*m_sumx)/m_n;
72 }
73}
74
75inline double LinFitSglPass::slope() const
76{
77 double offset,slope;
78 getFit(offset,slope);
79 return slope;
80}
81
82} //> namespace PerfMon
83
84#endif
#define y
#define x
void getFit(double &offset, double &slope) const
unsigned nPoints() const
void addPoint(const double &, const double &)