Go to the documentation of this file.00001 #include "RecoVertex/KinematicFit/interface/LagrangeParentParticleFitter.h"
00002 #include "RecoVertex/KinematicFitPrimitives/interface/KinematicVertexFactory.h"
00003 #include "RecoVertex/KinematicFit/interface/InputSort.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005
00006 LagrangeParentParticleFitter::LagrangeParentParticleFitter()
00007 {defaultParameters();}
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 std::vector<RefCountedKinematicTree> LagrangeParentParticleFitter::fit(std::vector<RefCountedKinematicTree> trees,
00122 KinematicConstraint * cs)const
00123 {
00124
00125 InputSort iSort;
00126 std::vector<RefCountedKinematicParticle> prt = iSort.sort(trees);
00127 int nStates = prt.size();
00128
00129
00130 AlgebraicVector part(7*nStates,0);
00131 AlgebraicSymMatrix cov(7*nStates,0);
00132
00133 AlgebraicVector chi_in(nStates,0);
00134 AlgebraicVector ndf_in(nStates,0);
00135 int l_c=0;
00136 for(std::vector<RefCountedKinematicParticle>::const_iterator i = prt.begin(); i != prt.end(); i++)
00137 {
00138 AlgebraicVector7 lp = (*i)->currentState().kinematicParameters().vector();
00139 for(int j = 1; j != 8; j++){part(7*l_c + j) = lp(j-1);}
00140 AlgebraicSymMatrix lc= asHepMatrix<7>((*i)->currentState().kinematicParametersError().matrix());
00141 cov.sub(7*l_c+1,lc);
00142 chi_in(l_c+1) = (*i)->chiSquared();
00143 ndf_in(l_c+1) = (*i)->degreesOfFreedom();
00144 l_c++;
00145 }
00146
00147
00148 AlgebraicVector refPar;
00149 AlgebraicSymMatrix refCovS;
00150
00151
00152 AlgebraicVector vl;
00153 AlgebraicMatrix dr;
00154 AlgebraicVector dev;
00155 int nstep = 0;
00156 double df = 0.;
00157 AlgebraicVector exPoint = part;
00158
00159
00160
00161
00162
00163 AlgebraicVector chi;
00164 AlgebraicVector ndf;
00165
00166 do{
00167 df = 0.;
00168 chi = chi_in;
00169 ndf = ndf_in;
00170
00171 vl = cs->value(exPoint).first;
00172 dr = cs->derivative(exPoint).first;
00173 dev = cs->deviations(nStates);
00174
00175
00176
00177
00178
00179
00180
00181
00182 AlgebraicVector delta_alpha = part - exPoint;
00183
00184
00185
00186 AlgebraicMatrix drt = dr.T();
00187 AlgebraicMatrix v_d = dr * cov * drt;
00188 int ifail = 0;
00189 v_d.invert(ifail);
00190 if(ifail != 0) {
00191 LogDebug("KinematicConstrainedVertexFitter")
00192 << "Fit failed: unable to invert covariance matrix\n";
00193 return std::vector<RefCountedKinematicTree>();
00194 }
00195
00196
00197
00198 AlgebraicVector lambda = v_d * (dr*delta_alpha + vl);
00199
00200
00201 refPar = part - (cov * drt * lambda);
00202
00203
00204 refCovS = cov;
00205 AlgebraicMatrix sPart = drt * v_d * dr;
00206 AlgebraicMatrix covF = cov * sPart * cov;
00207
00208
00209 AlgebraicSymMatrix sCovF(nStates*7,0);
00210 for(int i = 1; i< nStates*7 +1; ++i)
00211 {
00212 for(int j = 1; j< nStates*7 +1; j++)
00213 {if(i<=j) sCovF(i,j) = covF(i,j);}
00214 }
00215
00216 refCovS -= sCovF;
00217
00218
00219 for(int i = 1; i < nStates+1; i++)
00220 {for(int j = 1; j<8; j++){refCovS((i-1)+j,(i-1)+j) += dev(j);}}
00221
00222
00223 for(int k =1; k<nStates+1; k++)
00224 {
00225 chi(k) += (lambda.T() * (dr*delta_alpha + vl))(1);
00226 ndf(k) += cs->numberOfEquations();
00227 }
00228
00229 exPoint = refPar;
00230 AlgebraicVector vlp = cs->value(exPoint).first;
00231 for(int i = 1; i< vl.num_row();i++)
00232 {df += std::abs(vlp(i));}
00233 nstep++;
00234 }while(df>theMaxDiff && nstep<theMaxStep);
00235
00236
00237
00238
00239 std::vector<RefCountedKinematicParticle> refPart;
00240 std::vector<RefCountedKinematicTree> refTrees = trees;
00241
00242 int j=1;
00243 std::vector<RefCountedKinematicTree>::const_iterator tr = refTrees.begin();
00244 for(std::vector<RefCountedKinematicParticle>::const_iterator i = prt.begin(); i!= prt.end(); i++)
00245 {
00246 AlgebraicVector7 lRefPar;
00247 for(int k = 1; k<8 ; k++)
00248 {lRefPar(k-1) = refPar((j-1)*7+k);}
00249 AlgebraicSymMatrix77 lRefCovS = asSMatrix<7>(refCovS.sub((j-1)*7 +1,(j-1)*7+7));
00250
00251
00252 KinematicParameters param(lRefPar);
00253 KinematicParametersError er(lRefCovS);
00254 KinematicState kState(param,er,(*i)->initialState().particleCharge(), (**i).magneticField());
00255 RefCountedKinematicParticle refParticle = (*i)->refittedParticle(kState,chi(j),ndf(j),cs->clone());
00256
00257
00258 (*tr)->findParticle(*i);
00259 RefCountedKinematicVertex inVertex = (*tr)->currentDecayVertex();
00260 (*tr)->replaceCurrentParticle(refParticle);
00261
00262
00263 GlobalPoint nvPos(param.position());
00264 AlgebraicSymMatrix nvMatrix = asHepMatrix<7>(er.matrix()).sub(1,3);
00265 GlobalError nvError(asSMatrix<3>(nvMatrix));
00266 VertexState vState(nvPos, nvError, 1.0);
00267 KinematicVertexFactory vFactory;
00268 RefCountedKinematicVertex nVertex = vFactory.vertex(vState,inVertex,chi(j),ndf(j));
00269 (*tr)->replaceCurrentVertex(nVertex);
00270 tr++;
00271 j++;
00272 }
00273 return refTrees;
00274 }
00275
00276 void LagrangeParentParticleFitter::setParameters(const edm::ParameterSet& pSet)
00277 {
00278 theMaxDiff = pSet.getParameter<double>("maxDistance");
00279 theMaxStep = pSet.getParameter<int>("maxNbrOfIterations");;
00280 }
00281
00282 void LagrangeParentParticleFitter::defaultParameters()
00283 {
00284 theMaxDiff = 0.001;
00285 theMaxStep = 100;
00286 }