CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/RecoEgamma/EgammaPhotonAlgos/src/ConversionVertexFinder.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <vector>
00003 #include <memory>
00004 #include "RecoEgamma/EgammaPhotonAlgos/interface/ConversionVertexFinder.h"
00005 // Framework
00006 #include "FWCore/Framework/interface/Event.h"
00007 #include "FWCore/Framework/interface/EventSetup.h"
00008 #include "DataFormats/Common/interface/Handle.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include "FWCore/Utilities/interface/Exception.h"
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 //
00014 //Kinematic constraint vertex fitter
00015 #include "RecoVertex/KinematicFitPrimitives/interface/ParticleMass.h"
00016 #include "RecoVertex/KinematicFitPrimitives/interface/MultiTrackKinematicConstraint.h"
00017 #include <RecoVertex/KinematicFitPrimitives/interface/KinematicParticleFactoryFromTransientTrack.h>
00018 
00019 #include "RecoVertex/KinematicFit/interface/TwoTrackMassKinematicConstraint.h"
00020 #include "RecoVertex/KinematicFit/interface/KinematicParticleVertexFitter.h"
00021 #include "RecoVertex/KinematicFit/interface/KinematicParticleFitter.h"
00022 #include "RecoVertex/KinematicFit/interface/MassKinematicConstraint.h"
00023 #include "RecoVertex/KinematicFit/interface/ColinearityKinematicConstraint.h"
00024 #include "CommonTools/Statistics/interface/ChiSquaredProbability.h"
00025 
00026 // new templated one
00027 #include "RecoVertex/KinematicFit/interface/KinematicConstrainedVertexFitterT.h"
00028 #include "RecoVertex/KinematicFit/interface/ColinearityKinematicConstraintT.h"
00029 
00030 
00031 
00032 //
00033 #include "CLHEP/Units/GlobalPhysicalConstants.h"
00034 #include <TMath.h>
00035 
00036 
00037 
00038 
00039 
00040 ConversionVertexFinder::ConversionVertexFinder(const edm::ParameterSet& config ):
00041   conf_(config)
00042 { 
00043   LogDebug("ConversionVertexFinder") << "ConversionVertexFinder CTOR  " <<  "\n";  
00044   maxDelta_ = conf_.getParameter<double>("maxDelta");
00045   maxReducedChiSq_ = conf_.getParameter<double>("maxReducedChiSq");
00046   minChiSqImprovement_  = conf_.getParameter<double>("minChiSqImprovement");
00047   maxNbrOfIterations_ = conf_.getParameter<int>("maxNbrOfIterations");
00048   kcvFitter_ = new KinematicConstrainedVertexFitter();
00049   kcvFitter_->setParameters(conf_);
00050 
00051 }
00052 
00053 ConversionVertexFinder::~ConversionVertexFinder() {
00054 
00055   LogDebug("ConversionVertexFinder") << "ConversionVertexFinder DTOR " <<  "\n";  
00056   delete   kcvFitter_;
00057  
00058 }
00059 
00060 bool  ConversionVertexFinder::run(std::vector<reco::TransientTrack>  pair, reco::Vertex& the_vertex) {
00061   bool found= false;
00062 
00063   if ( pair.size() < 2) return found;
00064   
00065   float sigma = 0.00000001;
00066   float chi = 0.;
00067   float ndf = 0.;
00068   float mass = 0.000511;
00069   
00070 
00071   KinematicParticleFactoryFromTransientTrack pFactory;
00072   
00073   std::vector<RefCountedKinematicParticle> particles;
00074   
00075   particles.push_back(pFactory.particle (pair[0],mass,chi,ndf,sigma,*pair[0].innermostMeasurementState().freeState()));
00076   particles.push_back(pFactory.particle (pair[1],mass,chi,ndf,sigma,*pair[1].innermostMeasurementState().freeState()));
00077   
00078 
00079 #ifdef OldKineFit
00080   ColinearityKinematicConstraint constr(ColinearityKinematicConstraint::PhiTheta);
00081   
00082   RefCountedKinematicTree myTree = kcvFitter_->fit(particles, &constr);
00083 #else
00084 
00085   // bizzare way to the get the field...
00086   const MagneticField* mf = pair[0].field();
00087 
00088   ColinearityKinematicConstraintT<colinearityKinematic::PhiTheta> constr;
00089   KinematicConstrainedVertexFitterT<2,2> kcvFitter(mf);
00090   kcvFitter.setParameters(conf_);
00091   RefCountedKinematicTree myTree =  kcvFitter.fit(particles, &constr);
00092 
00093 #ifdef KineFitDebug
00094 
00095   ColinearityKinematicConstraint oldconstr(ColinearityKinematicConstraint::PhiTheta);
00096   
00097   RefCountedKinematicTree oldTree = kcvFitter_->fit(particles, &oldconstr);
00098 
00099 
00100   if( oldTree->isValid() ) {
00101     std::cout << "old " << kcvFitter_->getNit() << std::endl;
00102     RefCountedKinematicVertex gamma_dec_vertex = oldTree->currentDecayVertex();                                                          
00103     if( gamma_dec_vertex->vertexIsValid())
00104       std::cout << gamma_dec_vertex->chiSquared() <<  " " << gamma_dec_vertex->degreesOfFreedom() << std::endl;
00105     std::cout <<  oldTree->currentParticle()->currentState().globalMomentum() <<
00106       oldTree->currentParticle()->currentState().globalPosition()<< std::endl;
00107     std::vector<RefCountedKinematicParticle> fStates=oldTree->finalStateParticles();
00108     for (unsigned int kk=0; kk<fStates.size(); kk++) {
00109       std::cout <<  fStates[kk]->currentState().globalMomentum() << 
00110         fStates[kk]->currentState().globalPosition() << std::endl;
00111     }
00112   } else       std::cout << "old invalid " << kcvFitter_->getNit() << std::endl;
00113   
00114   if( myTree->isValid() ) {
00115     std::cout << "new " << kcvFitter.getNit() << std::endl;
00116     RefCountedKinematicVertex gamma_dec_vertex = myTree->currentDecayVertex();                                                          
00117     if( gamma_dec_vertex->vertexIsValid())
00118       std::cout << gamma_dec_vertex->chiSquared() <<  " " << gamma_dec_vertex->degreesOfFreedom() << std::endl;
00119     std::cout <<  myTree->currentParticle()->currentState().globalMomentum() <<
00120       myTree->currentParticle()->currentState().globalPosition()<< std::endl;
00121     std::vector<RefCountedKinematicParticle> fStates=myTree->finalStateParticles();
00122     for (unsigned int kk=0; kk<fStates.size(); kk++) {
00123       std::cout <<  fStates[kk]->currentState().globalMomentum() << 
00124         fStates[kk]->currentState().globalPosition() << std::endl;
00125     }
00126   } else       std::cout << "new invalid " << kcvFitter.getNit() << std::endl;
00127 
00128 #endif // TemplateKineFitDebug
00129 
00130 #endif
00131 
00132   if( myTree->isValid() ) {
00133     myTree->movePointerToTheTop();                                                                                
00134     RefCountedKinematicParticle the_photon = myTree->currentParticle();                                           
00135     if (the_photon->currentState().isValid()){                                                                    
00136       //const ParticleMass photon_mass = the_photon->currentState().mass();                                       
00137       RefCountedKinematicVertex gamma_dec_vertex;                                                               
00138       gamma_dec_vertex = myTree->currentDecayVertex();                                                          
00139       if( gamma_dec_vertex->vertexIsValid() ){                                                                  
00140         const float chi2Prob = ChiSquaredProbability(gamma_dec_vertex->chiSquared(), gamma_dec_vertex->degreesOfFreedom());
00141         if (chi2Prob>0.){// no longer cut here, only ask positive probability here 
00142           //const math::XYZPoint vtxPos(gamma_dec_vertex->position());                                           
00143           the_vertex = *gamma_dec_vertex;
00144           found = true;
00145         }
00146       }
00147     }
00148   }
00149  
00150   return found;
00151 }
00152 
00153 
00154 TransientVertex  ConversionVertexFinder::run(std::vector<reco::TransientTrack>  pair) {
00155   LogDebug("ConversionVertexFinder") << "ConversionVertexFinder run pair size " << pair.size() <<  "\n";  
00156   
00157   //for ( std::vector<reco::TransientTrack>::const_iterator iTk=pair.begin(); iTk!=pair.end(); ++iTk) {
00158   // LogDebug("ConversionVertexFinder") << "  ConversionVertexFinder  Tracks in the pair  charge " << iTk->charge() << " Num of RecHits " << iTk->recHitsSize() << " inner momentum " << iTk->track().innerMomentum() << "\n";  
00159   //}
00160 
00161 
00162   reco::Vertex theVertex;  
00163   KalmanVertexFitter fitter(true);
00164   TransientVertex transientVtx;
00165 
00166   const std::string metname =  "ConversionVertexFinder| ConversionVertexFinder";
00167   try{
00168 
00169     transientVtx = fitter.vertex(pair); 
00170 
00171   }  catch ( cms::Exception& e ) {
00172 
00173 
00174     edm::LogWarning(metname) << "cms::Exception caught in ConversionVertexFinder::run\n"
00175                              << e.explainSelf();
00176     
00177   }
00178   
00179 
00180   return transientVtx;
00181 
00182     
00183     
00184 }
00185