6#include "gsl/gsl_statistics.h"
7#include "gsl/gsl_fit.h"
21 const std::string& name,
22 const IInterface* parent):
31 unsigned MIN_WIRE_POINTS,
32 unsigned MIN_STRIP_POINTS)
56 double *
y =
new double[points.size()];
57 double *w =
new double[points.size()];
82 double fMaxChi2 = 0.0;
84 for (
unsigned iPt = 0; iPt < points.size(); iPt++)
86 if (!points[iPt].bOutlier)
88 double fDiff = points[iPt].fY - stats.fMean;
89 points[iPt].fChi2 = points[iPt].fW * fDiff * fDiff;
90 stats.fChi2 += points[iPt].fChi2;
91 if (fMaxChi2 < points[iPt].fChi2)
93 fMaxChi2 = points[iPt].fChi2;
100 <<
" n=" << stats.n <<
" Mean=" << stats.fMean
101 <<
" Std=" << stats.fStd <<
" Chi2=" << stats.fChi2);
105 points[iPtMax].bOutlier =
true;
116 double *
x =
new double[points.size()];
117 double *
y =
new double[points.size()];
118 double *w =
new double[points.size()];
140 &stats.fIntercept, &stats.fSlope,
141 &stats.fCov00, &stats.fCov01, &stats.fCov11,
143 ATH_MSG_DEBUG(
"Y=" << stats.fIntercept <<
"+X*" << stats.fSlope
144 <<
", N=" << stats.n <<
", Chi2=" << stats.fChi2);
146 double fMaxChi2 = 0.0;
148 for (
unsigned iPt = 0; iPt < points.size(); iPt++)
150 if (!points[iPt].bOutlier)
152 double fDiff = points[iPt].fY - stats.eval(points[iPt].fX);
153 points[iPt].fChi2 = points[iPt].fW * fDiff * fDiff;
154 if (fMaxChi2 < points[iPt].fChi2)
156 fMaxChi2 = points[iPt].fChi2;
161 if (iPtMax == -1 || fMaxChi2 <
m_CHI2_TEST || stats.n <= 2)
163 points[iPtMax].bOutlier =
true;
179 <<
", Y=" << stats.eval(Pt.fX)
180 <<
", chi2=" << Pt.fChi2);
189 std::vector<int> Stations;
190 Stations.reserve(array.size());
193 Stations.push_back(wirePt.nStation);
195 std::sort(Stations.begin(), Stations.end());
196 Stations.erase(
std::unique( Stations.begin(), Stations.end() ), Stations.end() );
197 return Stations.size();
204 ATH_MSG_DEBUG(
"TrigL2MuonSA::TgcFit::runTgcMiddle stripPoints=" << stripPoints.size()
205 <<
" wirePoints=" << wirePoints.size());
210 if (stripPoints.empty() || wirePoints.empty())
227 wireStats.
n = stats.n;
228 wireStats.
fChi2 = stats.fChi2;
233 stripStats.
n = stats.n;
234 stripStats.
fChi2 = stats.fChi2;
240 linReg(wirePoints, wireStats);
247 stripStats.
n = stats.n;
248 stripStats.
fChi2 = stats.fChi2;
253 linReg(stripPoints, stripStats);
261 double lowZ = 30000.0, highZ = 0.0;
262 int iLow = -1, iHigh = -1;
263 for (
unsigned iPt = 0; iPt < wirePoints.size(); iPt++)
265 if (!wirePoints[iPt].bOutlier)
267 if (lowZ > std::abs(wirePoints[iPt].fX))
269 lowZ = std::abs(wirePoints[iPt].fX);
272 if (highZ < std::abs(wirePoints[iPt].fX))
274 highZ = std::abs(wirePoints[iPt].fX);
279 if (iLow > -1 && iLow < (
int)wirePoints.size()) lowZ = wirePoints[iLow].fX;
280 if (iHigh > -1 && iHigh < (
int)wirePoints.size()) highZ = wirePoints[iHigh].fX;
282 double phi = stripStats.
eval(lowZ);
293 <<
",phi=" << p1.phi() <<
",perp=" << p1.perp() <<
",z=" << p1.z());
297 <<
",phi=" << p2.phi() <<
",perp=" << p2.perp() <<
",z=" << p2.z());
299 tgcFitResult.
tgcMid1[0] = p1.eta();
300 tgcFitResult.
tgcMid1[1] = p1.phi();
301 tgcFitResult.
tgcMid1[2] = p1.perp();
302 tgcFitResult.
tgcMid1[3] = p1.z();
303 tgcFitResult.
tgcMid2[0] = p2.eta();
304 tgcFitResult.
tgcMid2[1] = p2.phi();
305 tgcFitResult.
tgcMid2[2] = p2.perp();
306 tgcFitResult.
tgcMid2[3] = p2.z();
329 ATH_MSG_DEBUG(
"runTgcInner: stripPoints.size()=" << stripPoints.size()
330 <<
", wirePoints.size()=" << wirePoints.size());
332 if (stripPoints.size() > 1 && wirePoints.size() > 1)
348 <<
",phi=" << p.phi() <<
",perp=" << p.perp() <<
",z=" << p.z());
350 tgcFitResult.
tgcInn[0] = p.eta();
351 tgcFitResult.
tgcInn[1] = p.phi();
352 tgcFitResult.
tgcInn[2] = p.perp();
353 tgcFitResult.
tgcInn[3] = p.z();
Scalar phi() const
phi method
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
void SimpleStatistics(PointArray &points, SimpleStats &stats) const
TgcFit(const std::string &type, const std::string &name, const IInterface *parent)
void linReg(PointArray &points, LinStats &stats) const
unsigned m_MIN_WIRE_POINTS
Test for outliers: w * (value - mean)^2 > CHI2_TEST.
std::vector< Point > PointArray
void printDebug(const std::string &str) const
Status runTgcMiddle(PointArray &stripPoints, PointArray &wirePoints, TgcFitResult &fitResult) const
Status runTgcInner(PointArray &stripPoints, PointArray &wirePoints, TgcFitResult &fitResult) const
size_t countUniqueStations(const TrigL2MuonSA::TgcFit::PointArray &) const
unsigned m_MIN_STRIP_POINTS
Minimum number of strip points for linear fit.
void setFitParameters(double CHI2_TEST, unsigned MIN_WIRE_POINTS, unsigned MIN_STRIP_POINTS)
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Amg::RotationMatrix3D setPhi(Amg::RotationMatrix3D mat, double angle, int convention=0)
Eigen::Matrix< double, 3, 1 > Vector3D
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
double fIntercept
Intercept of the fit line.
double fSlope
Slope of the fit line.
double eval(double fX) const
A structure to hold simple statisitcs.
int n
Number of valid points.
double fStd
Standard deviation.