CMS 3D CMS Logo

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 11 of file ParabolaFit.h.

Constructor & Destructor Documentation

◆ ParabolaFit()

ParabolaFit::ParabolaFit ( )
inline

Definition at line 17 of file ParabolaFit.h.

17 : doErr(true), hasFixedParC(false), hasValues(false), hasErrors(false), hasWeights(true) {}
bool hasValues
Definition: ParabolaFit.h:98
bool hasFixedParC
Definition: ParabolaFit.h:97
bool hasErrors
Definition: ParabolaFit.h:98
bool hasWeights
Definition: ParabolaFit.h:99

Member Function Documentation

◆ addPoint() [1/2]

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

Definition at line 9 of file ParabolaFit.cc.

References x.

Referenced by ConformalMappingFit::ConformalMappingFit().

9  {
10  hasWeights = false;
11  addPoint(x, y, 1.);
12 }
void addPoint(double x, double y)
Definition: ParabolaFit.cc:9
bool hasWeights
Definition: ParabolaFit.h:99

◆ addPoint() [2/2]

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

Definition at line 14 of file ParabolaFit.cc.

References AlCaHLTBitMon_ParallelJobs::p, hiPixelPairStep_cff::points, w(), and x.

14  {
15  hasValues = false;
16  hasErrors = false;
17  Point p = {x, y, w};
18  points.push_back(p);
19 }
bool hasValues
Definition: ParabolaFit.h:98
T w() const
std::vector< Point > points
Definition: ParabolaFit.h:96
bool hasErrors
Definition: ParabolaFit.h:98
Structure Point Contains parameters of Gaussian fits to DMRs.

◆ chi2()

double ParabolaFit::chi2 ( void  ) const

Definition at line 111 of file ParabolaFit.cc.

References hiPixelPairStep_cff::points, and sqr().

Referenced by ConformalMappingFit::chi2().

111  {
112  double mychi2 = 0.;
113  for (vector<Point>::const_iterator ip = points.begin(); ip != points.end(); ip++) {
114  mychi2 += ip->w * sqr(ip->y - fun(ip->x));
115  }
116  return mychi2;
117 }
double fun(double x) const
Definition: ParabolaFit.cc:119
std::vector< Point > points
Definition: ParabolaFit.h:96
T sqr(T t)
Definition: ParabolaFit.cc:5

◆ det() [1/2]

double ParabolaFit::det ( const Column c1,
const Column c2,
const Column c3 
) const
private

Definition at line 129 of file ParabolaFit.cc.

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

129  {
130  return c1.r1 * c2.r2 * c3.r3 + c2.r1 * c3.r2 * c1.r3 + c3.r1 * c1.r2 * c2.r3 - c1.r3 * c2.r2 * c3.r1 -
131  c2.r3 * c3.r2 * c1.r1 - c3.r3 * c1.r2 * c2.r1;
132 }

◆ det() [2/2]

double ParabolaFit::det ( const Column c1,
const Column c2 
) const
private

Definition at line 134 of file ParabolaFit.cc.

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

134 { return c1.r1 * c2.r2 - c1.r2 * c2.r1; }

◆ dof()

int ParabolaFit::dof ( ) const

Definition at line 121 of file ParabolaFit.cc.

References fftjetvertexadder_cfi::nDof, HcalResponse_cfi::nPar, and hiPixelPairStep_cff::points.

121  {
122  int nPar = 3;
123  if (hasFixedParC)
124  nPar--;
125  int nDof = points.size() - nPar;
126  return (nDof > 0) ? nDof : 0;
127 }
bool hasFixedParC
Definition: ParabolaFit.h:97
std::vector< Point > points
Definition: ParabolaFit.h:96

◆ fixParC()

void ParabolaFit::fixParC ( double  val)
inline

Definition at line 23 of file ParabolaFit.h.

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

Referenced by ConformalMappingFit::fixImpactParmaeter().

23  {
24  hasFixedParC = true;
25  theResult.parC = val;
26  }
bool hasFixedParC
Definition: ParabolaFit.h:97
Result theResult
Definition: ParabolaFit.h:100

◆ fun()

double ParabolaFit::fun ( double  x) const
private

Definition at line 119 of file ParabolaFit.cc.

References x.

◆ parA()

double ParabolaFit::parA ( ) const
inline

Definition at line 30 of file ParabolaFit.h.

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

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

30  {
31  if (!hasValues)
32  result(doErr);
33  return theResult.parA;
34  }
bool hasValues
Definition: ParabolaFit.h:98
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:21
Result theResult
Definition: ParabolaFit.h:100

◆ parB()

double ParabolaFit::parB ( ) const
inline

Definition at line 35 of file ParabolaFit.h.

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

Referenced by ConformalMappingFit::directionPhi().

35  {
36  if (!hasValues)
37  result(doErr);
38  return theResult.parB;
39  }
bool hasValues
Definition: ParabolaFit.h:98
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:21
Result theResult
Definition: ParabolaFit.h:100

◆ parC()

double ParabolaFit::parC ( ) const
inline

Definition at line 40 of file ParabolaFit.h.

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

Referenced by ConformalMappingFit::impactParameter().

40  {
41  if (!hasValues)
42  result(doErr);
43  return theResult.parC;
44  }
bool hasValues
Definition: ParabolaFit.h:98
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:21
Result theResult
Definition: ParabolaFit.h:100

◆ result()

const ParabolaFit::Result & ParabolaFit::result ( bool  doErrors) const

Definition at line 21 of file ParabolaFit.cc.

References hltPixelTracks_cff::chi2, hiPixelPairStep_cff::points, funct::pow(), sqr(), w(), and x.

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

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

◆ skipErrorCalculationByDefault()

void ParabolaFit::skipErrorCalculationByDefault ( )
inline

Definition at line 22 of file ParabolaFit.h.

References doErr.

Referenced by ConformalMappingFit::skipErrorCalculation().

22 { doErr = false; }

◆ varAA()

double ParabolaFit::varAA ( ) const
inline

Definition at line 45 of file ParabolaFit.h.

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

Referenced by ConformalMappingFit::curvature().

45  {
46  if (!hasErrors)
47  result(true);
48  return theResult.varAA;
49  }
bool hasErrors
Definition: ParabolaFit.h:98
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:21
Result theResult
Definition: ParabolaFit.h:100

◆ varAB()

double ParabolaFit::varAB ( ) const
inline

Definition at line 60 of file ParabolaFit.h.

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

60  {
61  if (!hasErrors)
62  result(true);
63  return theResult.varAB;
64  }
bool hasErrors
Definition: ParabolaFit.h:98
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:21
Result theResult
Definition: ParabolaFit.h:100

◆ varAC()

double ParabolaFit::varAC ( ) const
inline

Definition at line 65 of file ParabolaFit.h.

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

65  {
66  if (!hasErrors)
67  result(true);
68  return theResult.varAC;
69  }
bool hasErrors
Definition: ParabolaFit.h:98
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:21
Result theResult
Definition: ParabolaFit.h:100

◆ varBB()

double ParabolaFit::varBB ( ) const
inline

Definition at line 50 of file ParabolaFit.h.

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

Referenced by ConformalMappingFit::directionPhi().

50  {
51  if (!hasErrors)
52  result(true);
53  return theResult.varBB;
54  }
bool hasErrors
Definition: ParabolaFit.h:98
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:21
Result theResult
Definition: ParabolaFit.h:100

◆ varBC()

double ParabolaFit::varBC ( ) const
inline

Definition at line 70 of file ParabolaFit.h.

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

70  {
71  if (!hasErrors)
72  result(true);
73  return theResult.varBC;
74  }
bool hasErrors
Definition: ParabolaFit.h:98
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:21
Result theResult
Definition: ParabolaFit.h:100

◆ varCC()

double ParabolaFit::varCC ( ) const
inline

Definition at line 55 of file ParabolaFit.h.

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

Referenced by ConformalMappingFit::impactParameter().

55  {
56  if (!hasErrors)
57  result(true);
58  return theResult.varCC;
59  }
bool hasErrors
Definition: ParabolaFit.h:98
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:21
Result theResult
Definition: ParabolaFit.h:100

Member Data Documentation

◆ doErr

bool ParabolaFit::doErr
private

Definition at line 97 of file ParabolaFit.h.

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

◆ hasErrors

bool ParabolaFit::hasErrors
mutableprivate

Definition at line 98 of file ParabolaFit.h.

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

◆ hasFixedParC

bool ParabolaFit::hasFixedParC
private

Definition at line 97 of file ParabolaFit.h.

Referenced by fixParC().

◆ hasValues

bool ParabolaFit::hasValues
mutableprivate

Definition at line 98 of file ParabolaFit.h.

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

◆ hasWeights

bool ParabolaFit::hasWeights
private

Definition at line 99 of file ParabolaFit.h.

◆ points

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

Definition at line 96 of file ParabolaFit.h.

◆ theResult

Result ParabolaFit::theResult
mutableprivate

Definition at line 100 of file ParabolaFit.h.

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