CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoVertex/KinematicFit/src/KinematicParticleVertexFitter.cc

Go to the documentation of this file.
00001 #include "RecoVertex/KinematicFit/interface/KinematicParticleVertexFitter.h"
00002 // #include "Vertex/LinearizationPointFinders/interface/LMSLinearizationPointFinder.h"
00003 #include "RecoVertex/KinematicFit/interface/FinalTreeBuilder.h"
00004 #include "RecoVertex/VertexTools/interface/SequentialVertexSmoother.h"
00005 #include "RecoVertex/KalmanVertexFit/interface/KalmanVertexUpdator.h"
00006 #include "RecoVertex/KalmanVertexFit/interface/KalmanVertexTrackUpdator.h"
00007 #include "RecoVertex/KalmanVertexFit/interface/KalmanSmoothedVertexChi2Estimator.h"
00008 #include "RecoVertex/KalmanVertexFit/interface/KalmanTrackToTrackCovCalculator.h"
00009 #include "RecoVertex/VertexPrimitives/interface/VertexException.h"
00010 #include "RecoVertex/LinearizationPointFinders/interface/DefaultLinearizationPointFinder.h"
00011 #include "RecoVertex/VertexTools/interface/SequentialVertexFitter.h"
00012 #include "DataFormats/CLHEP/interface/Migration.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 
00015 KinematicParticleVertexFitter::KinematicParticleVertexFitter()
00016 {
00017   edm::ParameterSet pSet = defaultParameters();
00018   setup(pSet);
00019 }
00020 
00021 KinematicParticleVertexFitter::KinematicParticleVertexFitter(const edm::ParameterSet pSet)
00022 {
00023   setup(pSet);
00024 }
00025 
00026 void
00027 KinematicParticleVertexFitter::setup(const edm::ParameterSet pSet)
00028 { 
00029 
00030   pointFinder =  new DefaultLinearizationPointFinder();
00031   vFactory = new VertexTrackFactory<6>();
00032 
00033   KalmanVertexTrackUpdator<6> vtu;
00034   KalmanSmoothedVertexChi2Estimator<6> vse;
00035   KalmanTrackToTrackCovCalculator<6> covCalc;
00036   SequentialVertexSmoother<6> smoother(vtu, vse, covCalc);
00037   fitter 
00038     = new SequentialVertexFitter<6>(pSet, *pointFinder, KalmanVertexUpdator<6>(),
00039                                  smoother, ParticleKinematicLinearizedTrackStateFactory());
00040 }
00041 
00042 KinematicParticleVertexFitter::~KinematicParticleVertexFitter()
00043 {
00044  delete vFactory;
00045  delete pointFinder;
00046  delete fitter;
00047 }
00048 
00049 edm::ParameterSet KinematicParticleVertexFitter::defaultParameters() const 
00050 {
00051   edm::ParameterSet pSet;
00052   pSet.addParameter<double>("maxDistance", 0.01);
00053   pSet.addParameter<int>("maxNbrOfIterations", 100); //10
00054   return pSet;
00055 }
00056  
00057 RefCountedKinematicTree KinematicParticleVertexFitter::fit(std::vector<RefCountedKinematicParticle> particles) const
00058 {
00059  typedef ReferenceCountingPointer<VertexTrack<6> > RefCountedVertexTrack;
00060 //sorting the input 
00061  if(particles.size()<2) throw VertexException("KinematicParticleVertexFitter::input states are less than 2"); 
00062  InputSort iSort;
00063  std::pair<std::vector<RefCountedKinematicParticle>, std::vector<FreeTrajectoryState> > input = iSort.sort(particles);
00064  std::vector<RefCountedKinematicParticle> & newPart = input.first;
00065  std::vector<FreeTrajectoryState> & freeStates = input.second;
00066 
00067  GlobalPoint linPoint = pointFinder->getLinearizationPoint(freeStates);
00068   
00069 // cout<<"Linearization point found"<<endl; 
00070  
00071 //making initial veretx seed with lin point as position and a fake error
00072  AlgebraicSymMatrix33 we;
00073  we(0,0)=we(1,1)=we(2,2) = 10000.;
00074  GlobalError error(we);
00075  VertexState state(linPoint, error);
00076  
00077 //vector of Vertex Tracks to fit
00078  std::vector<RefCountedVertexTrack> ttf; 
00079  for(std::vector<RefCountedKinematicParticle>::const_iterator i = newPart.begin();i != newPart.end();i++)
00080  {ttf.push_back(vFactory->vertexTrack((*i)->particleLinearizedTrackState(linPoint),state,1.));}
00081 
00082 // //debugging code to check neutrals: 
00083 //  for(std::vector<RefCountedVertexTrack>::const_iterator i = ttf.begin(); i!=ttf.end(); i++)
00084 //  {
00085 // //   cout<<"predicted state momentum error"<<(*i)->linearizedTrack()->predictedStateMomentumError()<<endl;
00086 // //  cout<<"Momentum jacobian"<<(*i)->linearizedTrack()->momentumJacobian() <<endl;
00087 //  //  cout<<"predicted state momentum "<<(*i)->linearizedTrack()->predictedStateMomentum()<<endl;
00088 // //   cout<<"constant term"<<(*i)->linearizedTrack()->constantTerm()<<endl;
00089 // 
00090 //  }
00091 
00092  CachingVertex<6> vtx = fitter->vertex(ttf); 
00093  if (!vtx.isValid()) {
00094      LogDebug("RecoVertex/KinematicParticleVertexFitter") 
00095        << "Fitted position is invalid. Returned Tree is invalid\n";
00096     return ReferenceCountingPointer<KinematicTree>(new KinematicTree()); // return invalid vertex
00097  }
00098  FinalTreeBuilder tBuilder;
00099  return tBuilder.buildTree(vtx, newPart); 
00100 }