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
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
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
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
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
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
00081
00082
00083
00084
00085
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
00100
00101
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
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
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
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;}