6#include "GaudiKernel/MsgStream.h"
8#include "gsl/gsl_statistics.h"
9#include "gsl/gsl_fit.h"
17 std::ostringstream oss;
18 oss <<
"Mean=" <<
fMean
21 <<
", Chi2=" <<
fChi2;
33 std::ostringstream oss;
36 <<
", Cov=[[" <<
fCov[0][0] <<
"," <<
fCov[0][1] <<
"],["
37 <<
fCov[1][0] <<
"," <<
fCov[1][1] <<
"]]"
38 <<
", Chi2=" <<
fChi2;
46 double *
y =
new double[points.size()];
47 double *w =
new double[points.size()];
48 for (
unsigned iPt = 0; iPt < points.size(); iPt++)
51 if (!points[iPt]->bExclude)
53 y[stats.n] = points[iPt]->fY;
54 w[stats.n] = points[iPt]->fW;
58 if (stats.n == 0)
goto done;
60 stats.fMean = gsl_stats_wmean(w, 1,
y, 1, stats.n);
61 if (stats.n == 1)
goto done;
62 stats.fStd = gsl_stats_wsd (w, 1,
y, 1, stats.n);
63 for (
int i = 0; i < stats.n; i++)
65 double fDiff =
y[i] - stats.fMean;
66 stats.fChi2 += w[i] * fDiff * fDiff;
76 double *
y =
new double[points.size()];
77 double *w =
new double[points.size()];
81 for (
unsigned iPt = 0; iPt < points.size(); iPt++)
84 if (!points[iPt]->bExclude)
86 y[stats.n] = points[iPt]->fY;
87 w[stats.n] = points[iPt]->fW;
92 if (stats.n == 0)
goto done;
93 stats.fMean = gsl_stats_wmean(w, 1,
y, 1, stats.n);
94 if (stats.n == 1)
goto done;
95 stats.fStd = gsl_stats_wsd(w, 1,
y, 1, stats.n);
97 int i = 0, iPtMax = 0;
98 for (
unsigned iPt = 0; iPt < points.size(); iPt++)
100 if (!points[iPt]->bExclude)
102 double fDiff =
y[i] - stats.fMean;
103 points[iPt]->fChi2 = w[i] * fDiff * fDiff;
104 stats.fChi2 += points[iPt]->fChi2;
105 if (fMaxChi2 < points[iPt]->fChi2)
107 fMaxChi2 = points[iPt]->fChi2;
110 if (bDump && log.level()<=MSG::DEBUG)
112 log << MSG::DEBUG <<
"idx=" << points[iPt]->nIdx
115 <<
", chi2=" << points[iPt]->fChi2
121 if (bDump && log.level()<=MSG::DEBUG)
122 log << MSG::DEBUG << stats.toString() <<
endmsg;
123 if (fMaxChi2 < fExclChi2 || stats.n <= 2)
125 points[iPtMax]->bExclude =
true;
135 double *
x =
new double[points.size()];
136 double *
y =
new double[points.size()];
137 double *w =
new double[points.size()];
141 for (
unsigned iPt = 0; iPt < points.size(); iPt++)
143 if (!points[iPt]->bExclude)
145 x[stats.n] = points[iPt]->fX;
146 y[stats.n] = points[iPt]->fY;
147 w[stats.n] = points[iPt]->fW;
151 if (stats.n < 2)
goto done;
153 gsl_fit_wlinear(
x, 1,
157 &stats.fIntercept, &stats.fSlope,
158 &stats.fCov[0][0], &stats.fCov[0][1], &stats.fCov[1][1],
160 stats.fCov[1][0] = stats.fCov[0][1];
161 if (bDump && log.level()<=MSG::DEBUG)
162 log << MSG::DEBUG << stats.toString() <<
endmsg;
164 double fY, fYerr, fMaxChi2 = 0;
165 int i = 0, iPtMax = 0;
166 for (
unsigned iPt = 0; iPt < points.size(); iPt++)
168 if (!points[iPt]->bExclude)
170 stats.eval(
x[i], fY, fYerr);
171 double fDiff =
y[i] - fY;
172 points[iPt]->fChi2 = w[i] * fDiff * fDiff;
173 if (fMaxChi2 < points[iPt]->fChi2)
175 fMaxChi2 = points[iPt]->fChi2;
178 if (bDump && log.level()<=MSG::DEBUG)
180 log << MSG::DEBUG <<
"idx=" << points[iPt]->nIdx
185 <<
", chi2=" << points[iPt]->fChi2
191 if (fMaxChi2 < fExclChi2 || stats.n <= 2)
193 points[iPtMax]->bExclude =
true;
static void fitPoint(PointArray &points, double fExclChi2, bool bDump, SimpleStats &stats)
Estimate a new point from the given points.
static void fitLine(PointArray &points, double fExclChi2, bool bDump, LinStats &stats)
Fit a straight line through the given points.
static void SimpleStatistics(const PointArray &points, SimpleStats &stats)
Calculate simple statistics for the Y values of a set of points.
std::vector< Point * > PointArray
A vector of points.
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
A structure to hold linear fit statistics.
void eval(double fX, double &fY, double &fYerr) const
Evaluate a point along the fitted line.
double fCov[2][2]
The parameter covariance matrix.
std::string toString() const
Get a string representation of the fit parameters.
double fIntercept
Intercept of the fit line.
double fChi2
Chi-squared of the fit.
double fSlope
Slope of the fit line.
std::string toString() const