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