CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoEgamma/EgammaPhotonAlgos/src/ConversionVertexFinder.cc

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