CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoVertex/KinematicFit/src/PointingKinematicConstraint.cc

Go to the documentation of this file.
00001 #include "RecoVertex/KinematicFit/interface/PointingKinematicConstraint.h"
00002 #include "RecoVertex/VertexPrimitives/interface/VertexException.h"
00003 
00004 std::pair<AlgebraicVector, AlgebraicVector> PointingKinematicConstraint::value(const AlgebraicVector& exPoint) const
00005 {
00006  if(exPoint.num_row() ==0 ) throw VertexException("PointingKinematicConstraint::value requested for zero Linearization point");
00007 
00008 //security check for extended cartesian parametrization 
00009  int inSize = exPoint.num_row(); 
00010  if((inSize%7) !=0) throw VertexException("PointingKinematicConstraint::linearization point has a wrong dimension");
00011  int nStates = inSize/7;
00012  if(nStates != 1) throw VertexException("PointingKinematicConstraint::Current version does not support the multistate refit");
00013  
00014  AlgebraicVector lPar = exPoint;
00015  AlgebraicVector vl(2,0);
00016  
00017 //vector of values 1x2  for given particle
00018  AlgebraicVector lValue = makeValue(lPar).first;
00019  vl(1) =lValue(1);
00020  vl(2) =lValue(2);
00021  return std::pair<AlgebraicVector,AlgebraicVector>(vl,lPar); 
00022 }
00023 
00024 std::pair<AlgebraicMatrix, AlgebraicVector> PointingKinematicConstraint::derivative(const AlgebraicVector& exPoint) const
00025 {
00026  if(exPoint.num_row() ==0 ) throw VertexException("PointingKinematicConstraint::value requested for zero Linearization point");
00027 
00028 //security check for extended cartesian parametrization 
00029  int inSize = exPoint.num_row(); 
00030  if((inSize%7) !=0) throw VertexException("PointingKinematicConstraint::linearization point has a wrong dimension");
00031  int nStates = inSize/7;
00032  if(nStates != 1) throw VertexException("PointingKinematicConstraint::Current version does not support the multistate refit");
00033  AlgebraicVector lPar = exPoint;
00034 
00035 //2x7 derivative matrix for given particle
00036  AlgebraicMatrix lDeriv = makeDerivative(lPar).first;
00037  AlgebraicMatrix dr(2,7,0);
00038  dr.sub(1,1,lDeriv);
00039  return std::pair<AlgebraicMatrix,AlgebraicVector>(dr,lPar);
00040 }
00041 
00042 std::pair<AlgebraicMatrix, AlgebraicVector> PointingKinematicConstraint::derivative(const std::vector<RefCountedKinematicParticle> par) const
00043 {
00044  int nStates = par.size();
00045  if(nStates == 0) throw VertexException("PointingKinematicConstraint::Empty vector of particles passed");
00046  if(nStates != 1) throw VertexException("PointingKinematicConstraint::Current version does not support the multistate refit");
00047  
00048  AlgebraicMatrix dr(2,7,0);
00049  AlgebraicVector lPoint = asHepVector<7>(par.front()->currentState().kinematicParameters().vector());
00050 
00051 //2x7 derivative matrix for given state  
00052  AlgebraicMatrix lDeriv = makeDerivative(lPoint).first;
00053  dr.sub(1,1,lDeriv);
00054  return std::pair<AlgebraicMatrix,AlgebraicVector>(dr,lPoint);
00055 }
00056 
00057 std::pair<AlgebraicVector, AlgebraicVector> PointingKinematicConstraint::value(const std::vector<RefCountedKinematicParticle> par) const
00058 {
00059  int nStates = par.size();
00060  if(nStates == 0) throw VertexException("PointingKinematicConstraint::Empty vector of particles passed");
00061  if(nStates != 1) throw VertexException("PointingKinematicConstraint::Current version does not support the multistate refit");
00062  AlgebraicVector vl(2,0);
00063  AlgebraicVector lPoint = asHepVector<7>(par.front()->currentState().kinematicParameters().vector());
00064  vl(1) = makeValue(lPoint).first(1);
00065  vl(2) = makeValue(lPoint).first(2);
00066  return std::pair<AlgebraicVector,AlgebraicVector>(vl,lPoint); 
00067 }
00068 
00069 std::pair<AlgebraicVector,AlgebraicVector> PointingKinematicConstraint::makeValue(const AlgebraicVector& exPoint)const
00070 {
00071  AlgebraicVector vl(2,0);
00072  AlgebraicVector point = exPoint;
00073  double dx = point(1) - refPoint.x();
00074  double dy = point(2) - refPoint.y();
00075  double dz = point(3) - refPoint.z();
00076  double px = point(4);
00077  double py = point(5); 
00078  double pz = point(6);
00079 
00080 // tangent solution
00081 // vl(1) = dy/dx - py/px;
00082 // vl(2) = dz/sqrt(dx*dx + dy*dy) - pz/sqrt(px*px + py*py); 
00083 
00084 
00085 //half angle solution
00086  double sin_p = py/sqrt(px*px + py*py);
00087  double cos_p = px/sqrt(px*px + py*py);
00088  double sin_x = dy/sqrt(dx*dx + dy*dy);
00089  double cos_x = dx/sqrt(dx*dx + dy*dy);
00090  
00091  double sin_pt = pz/sqrt(px*px + py*py + pz*pz); 
00092  double cos_pt = sqrt(px*px + py*py)/sqrt(px*px + py*py + pz*pz);
00093  double sin_xt = dz/sqrt(dx*dx + dy*dy + dz*dz); 
00094  double cos_xt = sqrt(dx*dx + dy*dy)/sqrt(dx*dx + dy*dy + dz*dz);
00095  
00096  vl(1) = (1-cos_x)/sin_x - (1-cos_p)/sin_p;
00097  vl(2) = (1-cos_xt)/sin_xt - (1-cos_pt)/sin_pt;
00098 
00099 //half angle corrected
00100 // vl(1) = (sin_x/(1+cos_x)) - (sin_p/(1+cos_p));
00101 // vl(2) = (sin_xt/(1+cos_xt)) - (sin_pt/(1+cos_pt));
00102  return std::pair<AlgebraicVector,AlgebraicVector>(vl,point);
00103 }
00104 
00105 
00106 std::pair<AlgebraicMatrix, AlgebraicVector> PointingKinematicConstraint:: makeDerivative(const AlgebraicVector& exPoint) const
00107 {
00108  AlgebraicMatrix dr(2,7,0);
00109  AlgebraicVector point = exPoint;
00110  double dx = point(1) - refPoint.x();
00111  double dy = point(2) - refPoint.y();
00112  double dz = point(3) - refPoint.z();
00113  double px = point(4);
00114  double py = point(5); 
00115  double pz = point(6);
00116                   
00117 // double tr = px*px + py*py;
00118 // double trd = dx*dx + dy*dy;
00119 // double pr =1.5;
00120 // double p_factor = pow(tr,pr);
00121 // double x_factor = pow(trd,pr);
00122   
00123 //tangent solution
00124 /*
00125  dr(1,1) = -dy/(dx*dx);
00126  dr(1,2) = 1/dx;
00127  dr(1,3) = 0;
00128  dr(1,4) = py/(px*px);
00129  dr(1,5) = -1/px;
00130  dr(1,6) = 0;
00131  dr(1,7) = 0;
00132  
00133  dr(2,1) = -(dx*dz)/x_factor;
00134  dr(2,2) = -(dy*dz)/x_factor;
00135  dr(2,3) = 1/sqrt(dx*dx + dy*dy);
00136  dr(2,4) = (px*pz)/p_factor;
00137  dr(2,5) = (py*pz)/p_factor;
00138  dr(2,6) = -1/sqrt(px*px + py*py);
00139  dr(2,7) = 0.;
00140 */
00141 //half angle solution corrected   
00142 /*
00143  dr(1,1) = - dy/(dx*dx+dy*dy+dx*sqrt(dx*dx+dy*dy));
00144  dr(1,2) =   dx/(dx*dx+dy*dy+dx*sqrt(dx*dx+dy*dy));
00145  dr(1,3) = 0; 
00146  dr(1,4) = py/(px*px+py*py+px*sqrt(px*px+py*py));
00147  dr(1,5) = -px/(px*px+py*py+px*sqrt(px*px+py*py));
00148  dr(1,6) = 0;
00149  dr(1,7) = 0; 
00150 */
00151 
00152 //half angle solution
00153  dr(1,1) = dx/(dy*sqrt(dx*dx + dy*dy)) - 1/dy;
00154  dr(1,2) = 1/sqrt(dx*dx+dy*dy) - sqrt(dx*dx+dy*dy)/(dy*dy)+ dx/(dy*dy);
00155  dr(1,3) = 0; 
00156  dr(1,4) = -(px/(py*sqrt(px*px + py*py)) - 1/py);
00157  dr(1,5) = -(1/sqrt(px*px+py*py) - sqrt(px*px+py*py)/(py*py)+ px/(py*py));
00158  dr(1,6) = 0;
00159  dr(1,7) = 0; 
00160 
00161 
00162 //half angle solution
00163  dr(2,1) = (dx/dz)*(1/sqrt(dx*dx + dy*dy + dz*dz) - 1/sqrt(dx*dx + dy*dy));
00164  dr(2,2) = (dy/dz)*(1/sqrt(dx*dx + dy*dy + dz*dz) - 1/sqrt(dx*dx + dy*dy));
00165  dr(2,3) = (1/(dz*dz))*(sqrt(dx*dx + dy*dy) - sqrt(dx*dx+dy*dy+dz*dz)) + 1/sqrt(dx*dx+dy*dy+dz*dz);
00166  dr(2,4) = -(px/pz)*(1/sqrt(px*px + py*py + pz*pz) - 1/sqrt(px*px + py*py));
00167  dr(2,5) = -(py/pz)*(1/sqrt(px*px + py*py + pz*pz) - 1/sqrt(px*px + py*py));
00168  dr(2,6) = -((1/(pz*pz))*(sqrt(px*px + py*py) - sqrt(px*px+py*py+pz*pz)) + 1/sqrt(px*px+py*py+pz*pz));
00169  dr(2,7) = 0;
00170  
00171  return std::pair<AlgebraicMatrix,AlgebraicVector>(dr,point);
00172 }
00173 
00174 AlgebraicVector PointingKinematicConstraint::deviations(int nStates) const
00175 {return AlgebraicVector(7*nStates,0);}
00176 
00177 int PointingKinematicConstraint::numberOfEquations() const
00178 {return 2;}