CMS 3D CMS Logo

KinematicConstrainedVertexFitter.cc

Go to the documentation of this file.
00001 #include "RecoVertex/KinematicFit/interface/KinematicConstrainedVertexFitter.h"
00002 #include "RecoVertex/KinematicFit/interface/InputSort.h"
00003 #include "RecoVertex/LinearizationPointFinders/interface/DefaultLinearizationPointFinder.h"
00004 #include "RecoVertex/KinematicFitPrimitives/interface/KinematicVertexFactory.h"
00005 // #include "Utilities/UI/interface/SimpleConfigurable.h"
00006 #include "RecoVertex/VertexPrimitives/interface/VertexException.h"
00007 
00008 
00009 
00010 KinematicConstrainedVertexFitter::KinematicConstrainedVertexFitter()
00011 {
00012  finder = new DefaultLinearizationPointFinder();
00013  vCons = new VertexKinematicConstraint();
00014  updator = new KinematicConstrainedVertexUpdator();
00015  tBuilder = new ConstrainedTreeBuilder;
00016  readParameters();
00017 }
00018 
00019 KinematicConstrainedVertexFitter:: KinematicConstrainedVertexFitter(const LinearizationPointFinder& fnd)
00020 {
00021  
00022  finder = fnd.clone();
00023  vCons = new VertexKinematicConstraint();
00024  updator = new KinematicConstrainedVertexUpdator();
00025  tBuilder = new ConstrainedTreeBuilder;
00026  readParameters();
00027 }
00028 
00029 KinematicConstrainedVertexFitter::~KinematicConstrainedVertexFitter()
00030 {
00031  delete finder;
00032  delete vCons;
00033  delete updator;
00034  delete tBuilder;
00035 }
00036 
00037 void KinematicConstrainedVertexFitter::readParameters()
00038 {
00039 //FIXME
00040 //  static SimpleConfigurable<double>
00041 //    maxEquationValueConfigurable(0.01,"KinematicConstrainedVertexFitterVertexFitter:maximumValue");
00042 //  theMaxDiff = maxEquationValueConfigurable.value();
00043 // 
00044 //  static SimpleConfigurable<int>
00045 //    maxStepConfigurable(10,"KinematicConstrainedVertexFitter:maximumNumberOfIterations");
00046 //  theMaxStep = maxStepConfigurable.value();
00047   theMaxDiff = 0.01;
00048   theMaxStep = 10;
00049 }
00050 
00051 RefCountedKinematicTree KinematicConstrainedVertexFitter::fit(vector<RefCountedKinematicParticle> part, 
00052                                                              MultiTrackKinematicConstraint * cs)const
00053 {
00054  if(part.size()<2) throw VertexException("KinematicConstrainedVertexFitter::input states are less than 2");
00055   
00056 //sorting out the input particles
00057  InputSort iSort;
00058  pair<vector<RefCountedKinematicParticle>, vector<FreeTrajectoryState> > input = iSort.sort(part);
00059  const vector<RefCountedKinematicParticle> & prt  = input.first;
00060  const vector<FreeTrajectoryState> & fStates = input.second;
00061 
00062 // linearization point: 
00063  GlobalPoint linPoint  = finder->getLinearizationPoint(fStates);
00064 
00065 //initial parameters:  
00066  int vSize = prt.size();
00067  AlgebraicVector inPar(3 + 7*vSize,0);
00068 
00069 //final parameters 
00070  AlgebraicVector finPar(3 + 7*vSize,0);
00071 
00072 //initial covariance 
00073  AlgebraicMatrix inCov(3 + 7*vSize,3 + 7*vSize,0);
00074 
00075 //making initial vector of parameters and initial particle-related covariance
00076  int nSt = 0;   
00077  vector<KinematicState> inStates;
00078  for(vector<RefCountedKinematicParticle>::const_iterator i = prt.begin(); i!=prt.end(); i++)
00079  {
00080   AlgebraicVector prPar = asHepVector<7>((*i)->stateAtPoint(linPoint).kinematicParameters().vector());
00081   for(int j = 1; j<8; j++){inPar(3 + 7*nSt + j) = prPar(j);}
00082   AlgebraicSymMatrix l_cov  = asHepMatrix<7>((*i)->stateAtPoint(linPoint).kinematicParametersError().matrix());
00083   inCov.sub(4 + 7*nSt,4 + 7*nSt ,l_cov); 
00084   inStates.push_back((*i)->stateAtPoint(linPoint));
00085   ++nSt;
00086  }
00087 
00088 //initial vertex error matrix components (huge error method)
00089 //and vertex related initial vector components
00090  double in_er = 100.;
00091  inCov(1,1) = in_er;
00092  inCov(2,2) = in_er;
00093  inCov(3,3) = in_er;
00094  
00095  inPar(1) = linPoint.x();
00096  inPar(2) = linPoint.y();
00097  inPar(3) = linPoint.z(); 
00098  
00099 //constraint equations value and number of iterations 
00100  double eq;   
00101  int nit = 0; 
00102  
00103  vector<KinematicState> lStates = inStates;
00104  GlobalPoint lPoint  = linPoint;
00105  RefCountedKinematicVertex rVtx;
00106  AlgebraicMatrix refCCov;
00107 
00108 //iterarions over the updator: each time updated parameters 
00109 //are taken as new linearization point 
00110  do{ 
00111   eq = 0.;
00112   pair< pair< vector<KinematicState>, AlgebraicMatrix >,RefCountedKinematicVertex> lRes = 
00113                                       updator->update(inPar,inCov,lStates,lPoint,cs);
00114   lStates = lRes.first.first;
00115   rVtx = lRes.second;
00116   lPoint = rVtx->position(); 
00117   AlgebraicVector vValue = vCons->value(lStates, lPoint);
00118   for(int i = 1; i<vValue.num_row();++i)
00119   {eq += abs(vValue(i));}
00120   if(cs !=0)
00121   {
00122    AlgebraicVector cVal = cs->value(lStates, lPoint);
00123    for(int i = 1; i<cVal.num_row();++i)
00124    {eq += abs(cVal(i));}
00125   }
00126   refCCov = lRes.first.second;
00127   nit++;
00128  }while(nit<theMaxStep && eq>theMaxDiff);
00129 
00130 // cout<<"number of relinearizations "<<nit<<endl;
00131 // cout<<"value obtained: "<<eq<<endl;
00132 
00133 //making refitted particles out of refitted states.
00134 //none of the operations above violates the order of particles 
00135  if(prt.size() != lStates.size()) throw VertexException("KinematicConstrainedVertexFitter::updator failure");
00136  vector<RefCountedKinematicParticle>::const_iterator i;
00137  vector<KinematicState>::const_iterator j;
00138  vector<RefCountedKinematicParticle> rParticles;
00139  for(i = prt.begin(),j = lStates.begin(); i != prt.end(),j != lStates.end(); ++i,++j)
00140  {
00141   rParticles.push_back((*i)->refittedParticle((*j),rVtx->chiSquared(),rVtx->degreesOfFreedom()));
00142  }   
00143  
00144 // cout<<"Constrained Vertex Fitter covariance: "<<refCCov <<endl;
00145  return  tBuilder->buildTree(rParticles,rVtx,refCCov); 
00146 }
00147 
00148 
00149 
00150 

Generated on Tue Jun 9 17:46:09 2009 for CMSSW by  doxygen 1.5.4