FEDRA emulsion software from the OPERA Collaboration
Fitter Class Reference

#include <fitter.h>

Public Member Functions

void addPoint (double x, double y)
 
bool evaluateLinearFit ()
 
 Fitter ()
 
double getChi2 ()
 
double getIntercept ()
 
double getPearsonCoefficent ()
 
double getSlope ()
 
void printStatistics ()
 
void setErrXY (double errx, double erry)
 
 ~Fitter ()
 

Private Attributes

double _chi2
 
double _errx
 
double _erry
 
double _m
 
unsigned short _nPoints
 
double _q
 
double _r
 
std::vector< double > _x
 
std::vector< double > _y
 

Constructor & Destructor Documentation

◆ Fitter()

Fitter::Fitter ( )
4{
5 _x.clear();
6 _y.clear();
7 _errx = _erry = _chi2 = _m = _q = _r = 0;
8 _nPoints = 0;
9}
double _q
Definition: fitter.h:12
std::vector< double > _y
Definition: fitter.h:16
double _chi2
Definition: fitter.h:14
double _errx
Definition: fitter.h:17
unsigned short _nPoints
Definition: fitter.h:18
double _m
Definition: fitter.h:11
double _r
Definition: fitter.h:13
std::vector< double > _x
Definition: fitter.h:15
double _erry
Definition: fitter.h:17

◆ ~Fitter()

Fitter::~Fitter ( )
12{
13}

Member Function Documentation

◆ addPoint()

void Fitter::addPoint ( double  x,
double  y 
)
16{
17 _x.push_back(x);
18 _y.push_back(y);
19 _nPoints++;
20}

◆ evaluateLinearFit()

bool Fitter::evaluateLinearFit ( )
29{
30 if (_nPoints == 0 || _erry == 0)
31 return false;
32 double s = 0, sx = 0, sy = 0, sxx = 0, syy = 0, sxy = 0;
33 double d = _errx / _erry;
34 //unsigned int nPoints = static_cast<unsigned int>(_x.size());
35 for (unsigned short i = 0; i < _nPoints; i++)
36 {
37 double x = _x.at(i);
38 double y = _y.at(i);
39 s += 1;
40 sx += x;
41 sy += y;
42 sxx += x*x;
43 syy += y*y;
44 sxy += x*y;
45 }
46
47 _r = (s*sxy-sx*sy)/(sqrt(s*sxx-sx*sx)*sqrt(s*syy-sy*sy));
48 s/=_errx;
49 sx/=_errx;
50 sy/=_errx;
51 sxx/=_errx;
52 syy/=_errx;
53 sxy/=_errx;
54
55 double den = 1./(s*sxx - sx*sx);
56 _m = (s*sxy - sx*sy)*den;
57 //_r = (s*sxy-sx*sy)/(sqrt(s*sxx-sx*sx)*sqrt(s*syy-sy*sy));
58 double r2 = _r*_r;
59 _m = 1./(2*d)*(-1./(d*_m)+d*_m/r2+1./(d*_m)*sqrt((1-d*d*_m*_m/r2)*(1-d*d*_m*_m/r2)+4*d*d*_m*_m));
60 _q = (sy-sx*_m)/s;
61
62 for (unsigned short i = 0; i < _nPoints; i++)
63 {
64 double x = _x.at(i);
65 double y = _y.at(i);
66 _chi2 += ((y-_q-_m*x)*(y-_q-_m*x))/((_erry*_erry)+_m*(_errx*_errx));
67 }
68
69 //_chi2/=(1+d*d*_m*_m);
70
71 return true;
72}
void d()
Definition: RecDispEX.C:381
s
Definition: check_shower.C:55

◆ getChi2()

double Fitter::getChi2 ( )
inline
26{return _chi2;};

◆ getIntercept()

double Fitter::getIntercept ( )
inline
24{return _q;};

◆ getPearsonCoefficent()

double Fitter::getPearsonCoefficent ( )
inline
25{return _r;};

◆ getSlope()

double Fitter::getSlope ( )
inline
23{return _m;};

◆ printStatistics()

void Fitter::printStatistics ( )
75{
76 std::cout << "nPoints: " << _nPoints
77 << "\n y = " << _m << " * x + " << _q
78 << "\n r = " << _r << "\nchi2 = " << _chi2 << std::endl;
79}

◆ setErrXY()

void Fitter::setErrXY ( double  errx,
double  erry 
)
23{
24 _errx = errx;
25 _erry = erry;
26}

Member Data Documentation

◆ _chi2

double Fitter::_chi2
private

◆ _errx

double Fitter::_errx
private

◆ _erry

double Fitter::_erry
private

◆ _m

double Fitter::_m
private

◆ _nPoints

unsigned short Fitter::_nPoints
private

◆ _q

double Fitter::_q
private

◆ _r

double Fitter::_r
private

◆ _x

std::vector<double> Fitter::_x
private

◆ _y

std::vector<double> Fitter::_y
private

The documentation for this class was generated from the following files: