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
 
double det (const Column &c1, const Column &c2, const Column &c3) 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) {}

Member Function Documentation

◆ addPoint() [1/2]

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

Definition at line 9 of file ParabolaFit.cc.

9  {
10  hasWeights = false;
11  addPoint(x, y, 1.);
12 }

Referenced by ConformalMappingFit::ConformalMappingFit().

◆ addPoint() [2/2]

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

Definition at line 14 of file ParabolaFit.cc.

14  {
15  hasValues = false;
16  hasErrors = false;
17  Point p = {x, y, w};
18  points.push_back(p);
19 }

References AlCaHLTBitMon_ParallelJobs::p, HLT_FULL_cff::points, and w.

◆ chi2()

double ParabolaFit::chi2 ( void  ) const

Definition at line 111 of file ParabolaFit.cc.

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 }

References HLT_FULL_cff::points, and sqr().

Referenced by ConformalMappingFit::chi2().

◆ det() [1/2]

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

Definition at line 134 of file ParabolaFit.cc.

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

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

◆ det() [2/2]

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

Definition at line 129 of file ParabolaFit.cc.

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 }

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

◆ dof()

int ParabolaFit::dof ( ) const

Definition at line 121 of file ParabolaFit.cc.

121  {
122  int nPar = 3;
123  if (hasFixedParC)
124  nPar--;
125  int nDof = points.size() - nPar;
126  return (nDof > 0) ? nDof : 0;
127 }

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

◆ fixParC()

void ParabolaFit::fixParC ( double  val)
inline

Definition at line 23 of file ParabolaFit.h.

23  {
24  hasFixedParC = true;
25  theResult.parC = val;
26  }

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

Referenced by ConformalMappingFit::fixImpactParmaeter().

◆ fun()

double ParabolaFit::fun ( double  x) const
private

Definition at line 119 of file ParabolaFit.cc.

119 { return theResult.parA + theResult.parB * x + theResult.parC * x * x; }

◆ parA()

double ParabolaFit::parA ( ) const
inline

Definition at line 30 of file ParabolaFit.h.

30  {
31  if (!hasValues)
32  result(doErr);
33  return theResult.parA;
34  }

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

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

◆ parB()

double ParabolaFit::parB ( ) const
inline

Definition at line 35 of file ParabolaFit.h.

35  {
36  if (!hasValues)
37  result(doErr);
38  return theResult.parB;
39  }

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

Referenced by ConformalMappingFit::directionPhi().

◆ parC()

double ParabolaFit::parC ( ) const
inline

Definition at line 40 of file ParabolaFit.h.

40  {
41  if (!hasValues)
42  result(doErr);
43  return theResult.parC;
44  }

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

Referenced by ConformalMappingFit::impactParameter().

◆ result()

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

Definition at line 21 of file ParabolaFit.cc.

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 }

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

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

◆ skipErrorCalculationByDefault()

void ParabolaFit::skipErrorCalculationByDefault ( )
inline

Definition at line 22 of file ParabolaFit.h.

22 { doErr = false; }

References doErr.

Referenced by ConformalMappingFit::skipErrorCalculation().

◆ varAA()

double ParabolaFit::varAA ( ) const
inline

Definition at line 45 of file ParabolaFit.h.

45  {
46  if (!hasErrors)
47  result(true);
48  return theResult.varAA;
49  }

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

Referenced by ConformalMappingFit::curvature().

◆ varAB()

double ParabolaFit::varAB ( ) const
inline

Definition at line 60 of file ParabolaFit.h.

60  {
61  if (!hasErrors)
62  result(true);
63  return theResult.varAB;
64  }

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

◆ varAC()

double ParabolaFit::varAC ( ) const
inline

Definition at line 65 of file ParabolaFit.h.

65  {
66  if (!hasErrors)
67  result(true);
68  return theResult.varAC;
69  }

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

◆ varBB()

double ParabolaFit::varBB ( ) const
inline

Definition at line 50 of file ParabolaFit.h.

50  {
51  if (!hasErrors)
52  result(true);
53  return theResult.varBB;
54  }

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

Referenced by ConformalMappingFit::directionPhi().

◆ varBC()

double ParabolaFit::varBC ( ) const
inline

Definition at line 70 of file ParabolaFit.h.

70  {
71  if (!hasErrors)
72  result(true);
73  return theResult.varBC;
74  }

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

◆ varCC()

double ParabolaFit::varCC ( ) const
inline

Definition at line 55 of file ParabolaFit.h.

55  {
56  if (!hasErrors)
57  result(true);
58  return theResult.varCC;
59  }

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

Referenced by ConformalMappingFit::impactParameter().

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().

DDAxes::y
ParabolaFit::theResult
Result theResult
Definition: ParabolaFit.h:100
ParabolaFit::doErr
bool doErr
Definition: ParabolaFit.h:97
fftjetvertexadder_cfi.nDof
nDof
Definition: fftjetvertexadder_cfi.py:35
ParabolaFit::Result::varAC
double varAC
Definition: ParabolaFit.h:15
ParabolaFit::hasFixedParC
bool hasFixedParC
Definition: ParabolaFit.h:97
ParabolaFit::dof
int dof() const
Definition: ParabolaFit.cc:121
ParabolaFit::Result::varBB
double varBB
Definition: ParabolaFit.h:15
ParabolaFit::fun
double fun(double x) const
Definition: ParabolaFit.cc:119
ParabolaFit::points
std::vector< Point > points
Definition: ParabolaFit.h:96
DDAxes::x
ParabolaFit::Result::varAB
double varAB
Definition: ParabolaFit.h:15
HcalResponse_cfi.nPar
nPar
Definition: HcalResponse_cfi.py:33
ParabolaFit::Result::parB
double parB
Definition: ParabolaFit.h:14
ParabolaFit::Result::varCC
double varCC
Definition: ParabolaFit.h:15
ParabolaFit::hasErrors
bool hasErrors
Definition: ParabolaFit.h:98
w
const double w
Definition: UKUtility.cc:23
Point
Structure Point Contains parameters of Gaussian fits to DMRs.
Definition: DMRtrends.cc:57
ParabolaFit::Result::parA
double parA
Definition: ParabolaFit.h:14
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
ParabolaFit::addPoint
void addPoint(double x, double y)
Definition: ParabolaFit.cc:9
alignmentValidation.c1
c1
do drawing
Definition: alignmentValidation.py:1025
sqr
T sqr(T t)
Definition: ParabolaFit.cc:5
IT
std::vector< LinkConnSpec >::const_iterator IT
Definition: TriggerBoardSpec.cc:5
ParabolaFit::det
double det(const Column &c1, const Column &c2, const Column &c3) const
Definition: ParabolaFit.cc:129
heppy_batch.val
val
Definition: heppy_batch.py:351
ParabolaFit::Result::varBC
double varBC
Definition: ParabolaFit.h:15
ParabolaFit::hasWeights
bool hasWeights
Definition: ParabolaFit.h:99
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
ParabolaFit::Result::parC
double parC
Definition: ParabolaFit.h:14
ParabolaFit::result
const Result & result(bool doErrors) const
Definition: ParabolaFit.cc:21
ParabolaFit::chi2
double chi2() const
Definition: ParabolaFit.cc:111
ParabolaFit::hasValues
bool hasValues
Definition: ParabolaFit.h:98
ParabolaFit::Result::varAA
double varAA
Definition: ParabolaFit.h:15