ATLAS Offline Software
Fit2D.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef MUONLINEARSEGMENTMAKERUTILITIES_FIT2D_H
6 #define MUONLINEARSEGMENTMAKERUTILITIES_FIT2D_H
7 
8 #include "GaudiKernel/MsgStream.h"
9 #include <vector>
10 #include <cstring>
11 #include <string>
12 
13 namespace Muon
14 {
15 
28  class Fit2D
29  {
30  public:
34  struct Point
35  {
36  int nIdx;
37  double fX;
38  double fY;
39  double fW;
40  double fChi2;
41  bool bExclude;
42  const void* pData;
47  Point();
48 
56  Point(int nIdx, double fX, double fY, double fW = 1.0, const void* pData = nullptr);
57  };
58 
59  typedef std::vector<Point*> PointArray;
61  struct SimpleStats
62  {
63  int n;
64  double fMean;
65  double fStd;
66  double fChi2;
67 
68  SimpleStats();
69  void clear();
70  std::string toString() const;
71  };
72 
76  struct LinStats
77  {
78  int n;
79  double fIntercept;
80  double fSlope;
81  double fCov[2][2];
82  double fChi2;
87  LinStats();
88 
92  void clear();
93 
100  void eval(double fX, double& fY, double& fYerr) const;
101 
105  std::string toString() const;
106  };
107 
111  Fit2D();
112 
118  static void SimpleStatistics(const PointArray& points, SimpleStats& stats);
119 
127  static void fitLine(PointArray& points, double fExclChi2, bool bDump, LinStats& stats);
128 
136  static void fitPoint(PointArray& points, double fExclChi2, bool bDump, SimpleStats& stats);
137  };
138 
140  nIdx(0), fX(0.0), fY(0.0), fW(1.0), fChi2(0.0), bExclude(false), pData(NULL)
141  {
142  }
143 
144  inline Fit2D::Point::Point(int nIdx, double fX, double fY, double fW, const void* pData) :
145  nIdx(nIdx), fX(fX), fY(fY), fW(fW), fChi2(0.0), bExclude(false), pData(pData)
146  {
147  }
148 
150  n(0),
151  fMean(0.0),
152  fStd(0.0),
153  fChi2(0.0)
154  {
155  }
156 
158  {
159  n = 0;
160  fMean = fStd = fChi2 = 0.0;
161  }
162 
164  n(0),
165  fIntercept(0.0),
166  fSlope(0.0),
167  fChi2(0.0)
168  {
169  memset(fCov, 0, sizeof(fCov));
170  }
171 
173  {
174  n = 0;
175  fIntercept = fSlope = fChi2 = 0.0;
176  memset(fCov, 0, sizeof(fCov));
177  }
178 
179  inline Fit2D::Fit2D()
180  {
181  }
182 
183 }
184 
185 #endif //MUONLINEARSEGMENTMAKERUTILITIES_FIT2D_H
Muon::Fit2D::LinStats::LinStats
LinStats()
Constructor.
Definition: Fit2D.h:163
Muon::Fit2D::fitLine
static void fitLine(PointArray &points, double fExclChi2, bool bDump, LinStats &stats)
Fit a straight line through the given points.
Muon::Fit2D
A 2D linear regression calculator.
Definition: Fit2D.h:29
Muon::Fit2D::Point::fW
double fW
Weight.
Definition: Fit2D.h:39
Muon::Fit2D::LinStats::n
int n
Number of points.
Definition: Fit2D.h:78
Muon::Fit2D::LinStats::clear
void clear()
Clear the statistics before a new fit.
Definition: Fit2D.h:172
Muon::Fit2D::SimpleStats::SimpleStats
SimpleStats()
Definition: Fit2D.h:149
Muon
This class provides conversion from CSC RDO data to CSC Digits.
Definition: TrackSystemController.h:49
trigbs_dumpHLTContentInBS.stats
stats
Definition: trigbs_dumpHLTContentInBS.py:91
Muon::Fit2D::Point::Point
Point()
Default constructor.
Definition: Fit2D.h:139
Muon::Fit2D::LinStats::fSlope
double fSlope
Slope of the fit line.
Definition: Fit2D.h:80
Muon::Fit2D::Point::nIdx
int nIdx
Index of the point in the original list.
Definition: Fit2D.h:36
Muon::Fit2D::Fit2D
Fit2D()
Constructor.
Definition: Fit2D.h:179
Muon::Fit2D::Point::fY
double fY
The Y coordinate.
Definition: Fit2D.h:38
beamspotman.n
n
Definition: beamspotman.py:731
Muon::Fit2D::SimpleStats::n
int n
Definition: Fit2D.h:63
Muon::Fit2D::LinStats
A structure to hold linear fit statistics.
Definition: Fit2D.h:77
Muon::Fit2D::LinStats::fCov
double fCov[2][2]
The parameter covariance matrix.
Definition: Fit2D.h:81
Muon::Fit2D::LinStats::eval
void eval(double fX, double &fY, double &fYerr) const
Evaluate a point along the fitted line.
Definition: Fit2D.cxx:26
Muon::Fit2D::Point
A 2D point used in statistics and fit.
Definition: Fit2D.h:35
Muon::Fit2D::fitPoint
static void fitPoint(PointArray &points, double fExclChi2, bool bDump, SimpleStats &stats)
Estimate a new point from the given points.
Muon::Fit2D::SimpleStats::fStd
double fStd
Definition: Fit2D.h:65
Muon::Fit2D::Point::fChi2
double fChi2
Contribution to the Chi2.
Definition: Fit2D.h:40
Muon::Fit2D::Point::pData
const void * pData
Any external data provided by the caller.
Definition: Fit2D.h:42
Muon::Fit2D::Point::bExclude
bool bExclude
If set, exclude the point from all calculations.
Definition: Fit2D.h:41
Muon::Fit2D::PointArray
std::vector< Point * > PointArray
A vector of points.
Definition: Fit2D.h:59
Muon::Fit2D::LinStats::toString
std::string toString() const
Get a string representation of the fit parameters.
Definition: Fit2D.cxx:31
Muon::Fit2D::SimpleStatistics
static void SimpleStatistics(const PointArray &points, SimpleStats &stats)
Calculate simple statistics for the Y values of a set of points.
Muon::Fit2D::SimpleStats::fChi2
double fChi2
Definition: Fit2D.h:66
Muon::Fit2D::SimpleStats::clear
void clear()
Definition: Fit2D.h:157
Muon::Fit2D::SimpleStats::toString
std::string toString() const
Definition: Fit2D.cxx:15
Muon::Fit2D::SimpleStats::fMean
double fMean
Definition: Fit2D.h:64
Muon::Fit2D::LinStats::fChi2
double fChi2
Chi-squared of the fit.
Definition: Fit2D.h:82
Muon::Fit2D::SimpleStats
Definition: Fit2D.h:62
Muon::Fit2D::LinStats::fIntercept
double fIntercept
Intercept of the fit line.
Definition: Fit2D.h:79
Muon::Fit2D::Point::fX
double fX
The X coordinate.
Definition: Fit2D.h:37