CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
ParabolaFit Class Reference

#include <ParabolaFit.h>

Classes

struct  Column
 
struct  Point
 
struct  Result
 

Public Member Functions

void addPoint (double x, double y)
 
void addPoint (double x, double y, double weight)
 
double chi2 () const
 
int dof () const
 
void fixParC (double val)
 
double parA () const
 
 ParabolaFit ()
 
double parB () const
 
double parC () const
 
const Resultresult (bool doErrors) const
 
void skipErrorCalculationByDefault ()
 
double varAA () const
 
double varAB () const
 
double varAC () const
 
double varBB () const
 
double varBC () const
 
double varCC () const
 

Private Member Functions

double det (const Column &c1, const Column &c2, const Column &c3) const
 
double det (const Column &c1, const Column &c2) const
 
double fun (double x) const
 

Private Attributes

bool doErr
 
bool hasErrors
 
bool hasFixedParC
 
bool hasValues
 
bool hasWeights
 
std::vector< Pointpoints
 
Result theResult
 

Detailed Description

The parabola fit y = parA + parB * x + parC * x*x see: R.L. Gluckstern, NIM 24 (1963) 381

Definition at line 12 of file ParabolaFit.h.

Constructor & Destructor Documentation

ParabolaFit::ParabolaFit ( )
inline

Definition at line 16 of file ParabolaFit.h.

16  :
17  doErr(true), hasFixedParC(false), hasValues(false), hasErrors(false), hasWeights(true) { }
bool hasValues
Definition: ParabolaFit.h:51
bool hasFixedParC
Definition: ParabolaFit.h:50
bool hasErrors
Definition: ParabolaFit.h:51
bool hasWeights
Definition: ParabolaFit.h:52

Member Function Documentation

void ParabolaFit::addPoint ( double  x,
double  y 
)

Definition at line 6 of file ParabolaFit.cc.

Referenced by ConformalMappingFit::ConformalMappingFit().

7 {
8  hasWeights = false;
9  addPoint(x,y,1.);
10 }
void addPoint(double x, double y)
Definition: ParabolaFit.cc:6
bool hasWeights
Definition: ParabolaFit.h:52
x
Definition: VDTMath.h:216
void ParabolaFit::addPoint ( double  x,
double  y,
double  weight 
)

Definition at line 12 of file ParabolaFit.cc.

References AlCaHLTBitMon_ParallelJobs::p, vdt::x, and detailsBasic3DVector::y.

13 {
14  hasValues = false;
15  hasErrors = false;
16  Point p = {x,y,w};
17  points.push_back(p);
18 }
bool hasValues
Definition: ParabolaFit.h:51
std::vector< Point > points
Definition: ParabolaFit.h:49
bool hasErrors
Definition: ParabolaFit.h:51
math::XYZPoint Point
x
Definition: VDTMath.h:216
T w() const
double ParabolaFit::chi2 ( void  ) const

Definition at line 104 of file ParabolaFit.cc.

References funct::sqr().

Referenced by ConformalMappingFit::chi2().

105 {
106  double mychi2 = 0.;
107  for ( vector<Point>::const_iterator
108  ip = points.begin(); ip != points.end(); ip++) {
109  mychi2 += ip->w * sqr(ip->y - fun(ip->x));
110  }
111  return mychi2;
112 }
std::vector< Point > points
Definition: ParabolaFit.h:49
double fun(double x) const
Definition: ParabolaFit.cc:114
Square< F >::type sqr(const F &f)
Definition: Square.h:13
double ParabolaFit::det ( const Column c1,
const Column c2,
const Column c3 
) const
private

Definition at line 126 of file ParabolaFit.cc.

References ParabolaFit::Column::r1, ParabolaFit::Column::r2, and ParabolaFit::Column::r3.

128 {
129  return c1.r1 * c2.r2 * c3.r3
130  + c2.r1 * c3.r2 * c1.r3
131  + c3.r1 * c1.r2 * c2.r3
132  - c1.r3 * c2.r2 * c3.r1
133  - c2.r3 * c3.r2 * c1.r1
134  - c3.r3 * c1.r2 * c2.r1;
135 }
double ParabolaFit::det ( const Column c1,
const Column c2 
) const
private

Definition at line 137 of file ParabolaFit.cc.

References ParabolaFit::Column::r1, and ParabolaFit::Column::r2.

138 {
139  return c1.r1*c2.r2 - c1.r2*c2.r1;
140 }
int ParabolaFit::dof ( ) const

Definition at line 119 of file ParabolaFit.cc.

120 {
121  int nPar = 3; if (hasFixedParC) nPar--;
122  int nDof = points.size() - nPar;
123  return (nDof > 0) ? nDof : 0;
124 }
bool hasFixedParC
Definition: ParabolaFit.h:50
std::vector< Point > points
Definition: ParabolaFit.h:49
void ParabolaFit::fixParC ( double  val)
inline

Definition at line 23 of file ParabolaFit.h.

References hasFixedParC, ParabolaFit::Result::parC, and theResult.

Referenced by ConformalMappingFit::fixImpactParmaeter().

23 { hasFixedParC = true; theResult.parC = val; }
bool hasFixedParC
Definition: ParabolaFit.h:50
Result theResult
Definition: ParabolaFit.h:53
double ParabolaFit::fun ( double  x) const
private

Definition at line 114 of file ParabolaFit.cc.

References vdt::x.

115 {
117 }
x
Definition: VDTMath.h:216
Result theResult
Definition: ParabolaFit.h:53
double ParabolaFit::parA ( ) const
inline

Definition at line 27 of file ParabolaFit.h.

References doErr, hasValues, ParabolaFit::Result::parA, result(), and theResult.

Referenced by ConformalMappingFit::charge(), and ConformalMappingFit::curvature().

27 { if(!hasValues) result(doErr); return theResult.parA; }
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:20
bool hasValues
Definition: ParabolaFit.h:51
Result theResult
Definition: ParabolaFit.h:53
double ParabolaFit::parB ( ) const
inline

Definition at line 28 of file ParabolaFit.h.

References doErr, hasValues, ParabolaFit::Result::parB, result(), and theResult.

Referenced by ConformalMappingFit::directionPhi().

28 { if(!hasValues) result(doErr); return theResult.parB; }
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:20
bool hasValues
Definition: ParabolaFit.h:51
Result theResult
Definition: ParabolaFit.h:53
double ParabolaFit::parC ( ) const
inline

Definition at line 29 of file ParabolaFit.h.

References doErr, hasValues, ParabolaFit::Result::parC, result(), and theResult.

Referenced by ConformalMappingFit::impactParameter().

29 { if(!hasValues) result(doErr); return theResult.parC; }
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:20
bool hasValues
Definition: ParabolaFit.h:51
Result theResult
Definition: ParabolaFit.h:53
const ParabolaFit::Result & ParabolaFit::result ( bool  doErrors) const

Definition at line 20 of file ParabolaFit.cc.

References funct::pow(), funct::sqr(), w(), vdt::x, and detailsBasic3DVector::y.

Referenced by parA(), parB(), parC(), varAA(), varAB(), varAC(), varBB(), varBC(), and varCC().

21 {
22  if (hasErrors) return theResult;
23  if (hasValues && !doErrors) return theResult;
24 
25  double F0, F1, F2, F3, F4, F0y, F1y, F2y;
26  F0 = F1 = F2 = F3 = F4 = F0y = F1y = F2y = 0.;
27 
28  typedef vector<Point>::const_iterator IT;
29  for (IT ip = points.begin(); ip != points.end(); ip++) {
30 
31  double pow;
32  double x = ip->x;
33  double y = ip->y;
34  double w = ip->w;
35 
36  F0 += w; F0y += w*y;
37  F1 += w*x; F1y += w*x*y;
38  pow = x*x; F2 += w*pow; F2y += w*pow*y; // x^2
39  pow *= x; F3 += w*pow; // x^3
40  pow *= x; F4 += w*pow; // x^4
41  }
42 
43  Column cA = { F0, F1, F2 };
44  Column cB = { F1, F2, F3 };
45  Column cC = { F2, F3, F4 };
46  Column cY = { F0y, F1y, F2y };
47 
48  double det0 = det(cA, cB, cC);
49 
50  if ( !hasFixedParC) {
51  theResult.parA = det(cY, cB, cC) / det0;
52  theResult.parB = det(cA, cY, cC) / det0;
53  theResult.parC = det(cA, cB, cY) / det0;
54  } else {
55  Column cCY = {F0y-theResult.parC*F2, F1y-theResult.parC*F3, F2y-theResult.parC*F4};
56  double det0C = det(cA, cB);
57  theResult.parA = det(cCY, cB) / det0C;
58  theResult.parB = det(cA, cCY) / det0C;
59  }
60 
61 // std::cout <<" result: A="<<theResult.parA<<" B="<<theResult.parB<<" C="<<theResult.parC<<endl;
62  double vAA, vBB, vCC, vAB, vAC, vBC;
63  vAA = vBB = vCC = vAB = vAC = vBC = 0.;
64 
65  hasValues = true;
66  if (!doErrors) return theResult;
67 
68  if( !hasWeights && dof() > 0) {
69 // cout <<" CHI2: " << chi2() <<" DOF: " << dof() << endl;
70  double scale_w = 1./chi2()/dof();
71  for (IT ip = points.begin(); ip != points.end(); ip++) ip->w *= scale_w;
72 // cout <<" CHI2: " << chi2() <<" DOF: " << dof() << endl;
73  }
74 
75  for (IT ip = points.begin(); ip != points.end(); ip++) {
76 
77  double w = ip->w;
78  Column cX = {1., ip->x, sqr(ip->x) };
79 
80  double dXBC = det(cX, cB, cC);
81  double dAXC = det(cA, cX, cC);
82  double dABX = det(cA, cB, cX);
83 
84  vAA += w * sqr(dXBC);
85  vBB += w * sqr(dAXC);
86  vCC += w * sqr(dABX);
87  vAB += w * dXBC * dAXC;
88  vAC += w * dXBC * dABX;
89  vBC += w * dAXC * dABX;
90  }
91 
92  theResult.varAA = vAA/sqr(det0);
93  theResult.varBB = vBB/sqr(det0);
94  theResult.varCC = vCC/sqr(det0);
95  theResult.varAB = vAB/sqr(det0);
96  theResult.varAC = vAC/sqr(det0);
97  theResult.varBC = vBC/sqr(det0);
98 
99  hasErrors = true;
100  return theResult;
101 }
int dof() const
Definition: ParabolaFit.cc:119
bool hasValues
Definition: ParabolaFit.h:51
bool hasFixedParC
Definition: ParabolaFit.h:50
std::vector< Point > points
Definition: ParabolaFit.h:49
double det(const Column &c1, const Column &c2, const Column &c3) const
Definition: ParabolaFit.cc:126
bool hasErrors
Definition: ParabolaFit.h:51
double chi2() const
Definition: ParabolaFit.cc:104
std::vector< LinkConnSpec >::const_iterator IT
bool hasWeights
Definition: ParabolaFit.h:52
Square< F >::type sqr(const F &f)
Definition: Square.h:13
x
Definition: VDTMath.h:216
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
Result theResult
Definition: ParabolaFit.h:53
T w() const
void ParabolaFit::skipErrorCalculationByDefault ( )
inline

Definition at line 22 of file ParabolaFit.h.

References doErr.

Referenced by ConformalMappingFit::skipErrorCalculation().

22 { doErr = false; }
double ParabolaFit::varAA ( ) const
inline

Definition at line 30 of file ParabolaFit.h.

References hasErrors, result(), theResult, and ParabolaFit::Result::varAA.

Referenced by ConformalMappingFit::curvature().

30 { if(!hasErrors) result(true); return theResult.varAA; }
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:20
bool hasErrors
Definition: ParabolaFit.h:51
Result theResult
Definition: ParabolaFit.h:53
double ParabolaFit::varAB ( ) const
inline

Definition at line 33 of file ParabolaFit.h.

References hasErrors, result(), theResult, and ParabolaFit::Result::varAB.

33 { if(!hasErrors) result(true); return theResult.varAB; }
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:20
bool hasErrors
Definition: ParabolaFit.h:51
Result theResult
Definition: ParabolaFit.h:53
double ParabolaFit::varAC ( ) const
inline

Definition at line 34 of file ParabolaFit.h.

References hasErrors, result(), theResult, and ParabolaFit::Result::varAC.

34 { if(!hasErrors) result(true); return theResult.varAC; }
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:20
bool hasErrors
Definition: ParabolaFit.h:51
Result theResult
Definition: ParabolaFit.h:53
double ParabolaFit::varBB ( ) const
inline

Definition at line 31 of file ParabolaFit.h.

References hasErrors, result(), theResult, and ParabolaFit::Result::varBB.

Referenced by ConformalMappingFit::directionPhi().

31 { if(!hasErrors) result(true); return theResult.varBB; }
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:20
bool hasErrors
Definition: ParabolaFit.h:51
Result theResult
Definition: ParabolaFit.h:53
double ParabolaFit::varBC ( ) const
inline

Definition at line 35 of file ParabolaFit.h.

References hasErrors, result(), theResult, and ParabolaFit::Result::varBC.

35 { if(!hasErrors) result(true); return theResult.varBC; }
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:20
bool hasErrors
Definition: ParabolaFit.h:51
Result theResult
Definition: ParabolaFit.h:53
double ParabolaFit::varCC ( ) const
inline

Definition at line 32 of file ParabolaFit.h.

References hasErrors, result(), theResult, and ParabolaFit::Result::varCC.

Referenced by ConformalMappingFit::impactParameter().

32 { if(!hasErrors) result(true); return theResult.varCC; }
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:20
bool hasErrors
Definition: ParabolaFit.h:51
Result theResult
Definition: ParabolaFit.h:53

Member Data Documentation

bool ParabolaFit::doErr
private

Definition at line 50 of file ParabolaFit.h.

Referenced by parA(), parB(), parC(), and skipErrorCalculationByDefault().

bool ParabolaFit::hasErrors
mutableprivate

Definition at line 51 of file ParabolaFit.h.

Referenced by varAA(), varAB(), varAC(), varBB(), varBC(), and varCC().

bool ParabolaFit::hasFixedParC
private

Definition at line 50 of file ParabolaFit.h.

Referenced by fixParC().

bool ParabolaFit::hasValues
mutableprivate

Definition at line 51 of file ParabolaFit.h.

Referenced by parA(), parB(), and parC().

bool ParabolaFit::hasWeights
private

Definition at line 52 of file ParabolaFit.h.

std::vector<Point> ParabolaFit::points
mutableprivate

Definition at line 49 of file ParabolaFit.h.

Result ParabolaFit::theResult
mutableprivate

Definition at line 53 of file ParabolaFit.h.

Referenced by fixParC(), parA(), parB(), parC(), varAA(), varAB(), varAC(), varBB(), varBC(), and varCC().