CMS 3D CMS Logo

ParabolaFit Class Reference

The parabola fit y = parA + parB * x + parC * x*x see: R.L. More...

#include <RecoPixelVertexing/PixelTrackFitting/src/ParabolaFit.h>

List of all members.

Public Member Functions

void addPoint (double x, double y, double weight)
void addPoint (double x, double y)
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

Classes

struct  Column
struct  Point
struct  Result


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.

00016                 : 
00017       doErr(true), hasFixedParC(false), hasValues(false), hasErrors(false), hasWeights(true) { }


Member Function Documentation

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

Definition at line 12 of file ParabolaFit.cc.

References hasErrors, hasValues, p, and points.

00013 {
00014   hasValues = false;
00015   hasErrors = false;
00016   Point p = {x,y,w};
00017   points.push_back(p);
00018 }

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

Definition at line 6 of file ParabolaFit.cc.

References hasWeights.

Referenced by ConformalMappingFit::ConformalMappingFit().

00007 {
00008   hasWeights = false;
00009   addPoint(x,y,1.);
00010 }

double ParabolaFit::chi2 ( void   )  const

Definition at line 104 of file ParabolaFit.cc.

References fun(), points, and sqr().

Referenced by ConformalMappingFit::chi2(), and result().

00105 {
00106   double mychi2 = 0.;
00107   for ( vector<Point>::const_iterator 
00108       ip = points.begin(); ip != points.end(); ip++) {
00109      mychi2 += ip->w * sqr(ip->y - fun(ip->x)); 
00110   }
00111   return mychi2;
00112 }

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.

00138 {
00139   return c1.r1*c2.r2 - c1.r2*c2.r1;
00140 }

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.

Referenced by result().

00128 {
00129   return   c1.r1 * c2.r2 * c3.r3
00130          + c2.r1 * c3.r2 * c1.r3
00131          + c3.r1 * c1.r2 * c2.r3
00132          - c1.r3 * c2.r2 * c3.r1
00133          - c2.r3 * c3.r2 * c1.r1
00134          - c3.r3 * c1.r2 * c2.r1;
00135 }

int ParabolaFit::dof (  )  const

Definition at line 119 of file ParabolaFit.cc.

References hasFixedParC, and points.

Referenced by result().

00120 {
00121   int nPar = 3; if (hasFixedParC) nPar--;
00122   int nDof = points.size() - nPar;
00123   return (nDof > 0) ? nDof : 0;
00124 }

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

00023 { hasFixedParC = true; theResult.parC = val; }

double ParabolaFit::fun ( double  x  )  const [private]

Definition at line 114 of file ParabolaFit.cc.

References ParabolaFit::Result::parA, ParabolaFit::Result::parB, ParabolaFit::Result::parC, and theResult.

Referenced by chi2().

00115 {
00116    return theResult.parA + theResult.parB*x + theResult.parC*x*x;
00117 }

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

00027 { if(!hasValues) result(doErr); return theResult.parA; }

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

00028 { if(!hasValues) result(doErr); return theResult.parB; }

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

00029 { if(!hasValues) result(doErr); return theResult.parC; }

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

Definition at line 20 of file ParabolaFit.cc.

References chi2(), det(), dof(), hasErrors, hasFixedParC, hasValues, hasWeights, ParabolaFit::Result::parA, ParabolaFit::Result::parB, ParabolaFit::Result::parC, points, funct::pow(), sqr(), theResult, ParabolaFit::Result::varAA, ParabolaFit::Result::varAB, ParabolaFit::Result::varAC, ParabolaFit::Result::varBB, ParabolaFit::Result::varBC, ParabolaFit::Result::varCC, w, x, and y.

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

00021 {
00022   if (hasErrors)  return theResult;
00023   if (hasValues && !doErrors) return theResult;
00024 
00025   double F0,  F1,  F2,  F3,  F4,  F0y,  F1y,  F2y;
00026          F0 = F1 = F2 = F3 = F4 = F0y = F1y = F2y = 0.;
00027 
00028   typedef vector<Point>::const_iterator IT;
00029   for (IT ip = points.begin(); ip != points.end(); ip++) {
00030  
00031     double pow;
00032     double x = ip->x;
00033     double y = ip->y;
00034     double w = ip->w;
00035 
00036                 F0 += w;         F0y += w*y;   
00037                 F1 += w*x;       F1y += w*x*y;
00038     pow = x*x;  F2 += w*pow;     F2y += w*pow*y;    // x^2
00039     pow *= x;   F3 += w*pow;                        // x^3
00040     pow *= x;   F4 += w*pow;                        // x^4
00041   }
00042 
00043   Column cA = { F0, F1, F2 };
00044   Column cB = { F1, F2, F3 };
00045   Column cC = { F2, F3, F4 };
00046   Column cY = { F0y, F1y, F2y };
00047 
00048   double det0 = det(cA, cB, cC);
00049 
00050   if ( !hasFixedParC) {
00051   theResult.parA = det(cY, cB, cC) / det0;
00052   theResult.parB = det(cA, cY, cC) / det0;
00053   theResult.parC = det(cA, cB, cY) / det0;
00054   } else {
00055     Column cCY = {F0y-theResult.parC*F2, F1y-theResult.parC*F3, F2y-theResult.parC*F4};
00056     double det0C   = det(cA, cB);
00057     theResult.parA = det(cCY, cB) / det0C;
00058     theResult.parB = det(cA, cCY) / det0C;
00059   } 
00060 
00061 //  std::cout <<" result: A="<<theResult.parA<<" B="<<theResult.parB<<" C="<<theResult.parC<<endl; 
00062   double vAA,  vBB,  vCC,  vAB,  vAC,  vBC;
00063          vAA = vBB = vCC = vAB = vAC = vBC = 0.;
00064 
00065   hasValues = true;
00066   if (!doErrors) return theResult;
00067 
00068   if( !hasWeights &&  dof() > 0) {
00069 //     cout <<" CHI2: " << chi2() <<" DOF: " << dof() << endl;
00070      double scale_w = 1./chi2()/dof();
00071      for (IT ip = points.begin(); ip != points.end(); ip++) ip->w *= scale_w; 
00072 //     cout <<" CHI2: " << chi2() <<" DOF: " << dof() << endl;
00073   }
00074   
00075   for (IT ip = points.begin(); ip != points.end(); ip++) {
00076 
00077     double w = ip->w;
00078     Column cX = {1., ip->x, sqr(ip->x) };
00079 
00080     double dXBC = det(cX, cB, cC);
00081     double dAXC = det(cA, cX, cC);
00082     double dABX = det(cA, cB, cX);
00083 
00084     vAA += w * sqr(dXBC);
00085     vBB += w * sqr(dAXC);
00086     vCC += w * sqr(dABX);
00087     vAB += w * dXBC * dAXC;
00088     vAC += w * dXBC * dABX;
00089     vBC += w * dAXC * dABX;
00090   }
00091    
00092   theResult.varAA = vAA/sqr(det0);
00093   theResult.varBB = vBB/sqr(det0);
00094   theResult.varCC = vCC/sqr(det0);
00095   theResult.varAB = vAB/sqr(det0);
00096   theResult.varAC = vAC/sqr(det0);
00097   theResult.varBC = vBC/sqr(det0);
00098 
00099   hasErrors = true;
00100   return theResult;
00101 }

void ParabolaFit::skipErrorCalculationByDefault (  )  [inline]

Definition at line 22 of file ParabolaFit.h.

References doErr.

Referenced by ConformalMappingFit::skipErrorCalculation().

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

00030 { if(!hasErrors) result(true); return theResult.varAA; }

double ParabolaFit::varAB (  )  const [inline]

Definition at line 33 of file ParabolaFit.h.

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

00033 { if(!hasErrors) result(true); return theResult.varAB; }

double ParabolaFit::varAC (  )  const [inline]

Definition at line 34 of file ParabolaFit.h.

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

00034 { if(!hasErrors) result(true); return theResult.varAC; }

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

00031 { if(!hasErrors) result(true); return theResult.varBB; }

double ParabolaFit::varBC (  )  const [inline]

Definition at line 35 of file ParabolaFit.h.

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

00035 { if(!hasErrors) result(true); return theResult.varBC; }

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

00032 { if(!hasErrors) result(true); return theResult.varCC; }


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 [mutable, private]

Definition at line 51 of file ParabolaFit.h.

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

bool ParabolaFit::hasFixedParC [private]

Definition at line 50 of file ParabolaFit.h.

Referenced by dof(), fixParC(), and result().

bool ParabolaFit::hasValues [mutable, private]

Definition at line 51 of file ParabolaFit.h.

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

bool ParabolaFit::hasWeights [private]

Definition at line 52 of file ParabolaFit.h.

Referenced by addPoint(), and result().

std::vector<Point> ParabolaFit::points [mutable, private]

Definition at line 49 of file ParabolaFit.h.

Referenced by addPoint(), chi2(), dof(), and result().

Result ParabolaFit::theResult [mutable, private]

Definition at line 53 of file ParabolaFit.h.

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


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:29:26 2009 for CMSSW by  doxygen 1.5.4