CMS 3D CMS Logo

PrimaryVertexProducerAlgorithm.cc

Go to the documentation of this file.
00001 #include "RecoVertex/PrimaryVertexProducer/interface/PrimaryVertexProducerAlgorithm.h"
00002 #include "RecoVertex/PrimaryVertexProducer/interface/VertexHigherPtSquared.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00006 #include "RecoVertex/VertexPrimitives/interface/ConvertError.h"
00007 #include "RecoVertex/KalmanVertexFit/interface/KalmanVertexFitter.h"
00008 #include "RecoVertex/AdaptiveVertexFit/interface/AdaptiveVertexFitter.h"
00009 #include "RecoVertex/VertexTools/interface/VertexDistanceXY.h"
00010 #include "RecoVertex/VertexPrimitives/interface/VertexException.h"
00011 #include <algorithm>
00012 
00013 using namespace reco;
00014 
00015 //
00016 // constants, enums and typedefs
00017 //
00018 
00019 //
00020 // static data member definitions
00021 //
00022 
00023 //
00024 // constructors and destructor
00025 //
00026 PrimaryVertexProducerAlgorithm::PrimaryVertexProducerAlgorithm(const edm::ParameterSet& conf)
00027   // extract relevant parts of config for components
00028   : theConfig(conf), 
00029     theTrackFilter(conf.getParameter<edm::ParameterSet>("TkFilterParameters")), 
00030     theTrackClusterizer(conf.getParameter<edm::ParameterSet>("TkClusParameters")), 
00031     theVertexSelector(VertexDistanceXY(), 
00032                       conf.getParameter<edm::ParameterSet>("PVSelParameters").getParameter<double>("maxDistanceToBeam"))
00033 {
00034   edm::LogInfo("RecoVertex/PrimaryVertexProducerAlgorithm") 
00035     << "Initializing PV producer algorithm" << "\n";
00036   edm::LogInfo("RecoVertex/PrimaryVertexProducerAlgorithm") 
00037     << "PVSelParameters::maxDistanceToBeam = " 
00038     << conf.getParameter<edm::ParameterSet>("PVSelParameters").getParameter<double>("maxDistanceToBeam") << "\n";
00039 
00040   fUseBeamConstraint = conf.getParameter<bool>("useBeamConstraint");
00041   fVerbose           = conf.getUntrackedParameter<bool>("verbose", false);
00042   std::string algorithm = conf.getParameter<std::string>("algorithm");
00043   fapply_finder = false;
00044   if (algorithm == "TrimmedKalmanFinder") {
00045     fapply_finder = true;
00046   } else if (algorithm=="KalmanVertexFitter") {
00047     theFitter=new KalmanVertexFitter();
00048   } else if( algorithm=="AdaptiveVertexFitter") {
00049     theFitter=new AdaptiveVertexFitter();
00050   } else {
00051     throw VertexException("PrimaryVertexProducerAlgorithm: unknown algorithm: " + algorithm);  
00052   }
00053 
00054   edm::LogInfo("RecoVertex/PrimaryVertexProducerAlgorithm") 
00055     << "Using " << algorithm << "\n";
00056   edm::LogInfo("RecoVertex/PrimaryVertexProducerAlgorithm") 
00057     << "beam-constraint  " << fUseBeamConstraint << "\n"; 
00058 
00059   // FIXME move vertex chi2 cut in theVertexSelector
00060   // theFinder should not perform the final vertex cleanup
00061   float minVertexFitProb 
00062     = conf.getParameter<edm::ParameterSet>("PVSelParameters").getParameter<double>("minVertexFitProb");
00063   edm::LogInfo("RecoVertex/PrimaryVertexProducerAlgorithm") 
00064     << "PVSelParameters::minVertexFitProb = " 
00065     << conf.getParameter<edm::ParameterSet>("PVSelParameters").getParameter<double>("minVertexFitProb") << endl;
00066 
00067   theFinder.setVertexFitProbabilityCut(minVertexFitProb);
00068 
00069   // initialization of vertex finder algorithm
00070   // theFinder should not perform any track selection
00071   // theTrackFilter does it
00072   theFinder.setPtCut(conf.getParameter<edm::ParameterSet>("TkFilterParameters").getParameter<double>("minPt"));
00073   float minTrackCompatibilityToMainVertex 
00074     = conf.getParameter<edm::ParameterSet>("VtxFinderParameters").getParameter<double>("minTrackCompatibilityToMainVertex");
00075   edm::LogInfo("RecoVertex/PrimaryVertexProducerAlgorithm") 
00076     << "VtxFinderParameters::minTrackCompatibilityToMainVertex = " 
00077     << conf.getParameter<edm::ParameterSet>("VtxFinderParameters").getParameter<double>("minTrackCompatibilityToMainVertex") << endl;
00078   theFinder.setTrackCompatibilityCut(minTrackCompatibilityToMainVertex);
00079   float minTrackCompatibilityToOtherVertex 
00080     = conf.getParameter<edm::ParameterSet>("VtxFinderParameters").getParameter<double>("minTrackCompatibilityToOtherVertex");
00081   edm::LogInfo("RecoVertex/PrimaryVertexProducerAlgorithm") 
00082     << "VtxFinderParameters::minTrackCompatibilityToOtherVertex = " 
00083     << conf.getParameter<edm::ParameterSet>("VtxFinderParameters").getParameter<double>("minTrackCompatibilityToOtherVertex") << endl;
00084   theFinder.setTrackCompatibilityToSV(minTrackCompatibilityToOtherVertex);
00085   int maxNbVertices 
00086     = conf.getParameter<edm::ParameterSet>("VtxFinderParameters").getParameter<int>("maxNbVertices");
00087   edm::LogInfo("RecoVertex/PrimaryVertexProducerAlgorithm") 
00088     << "VtxFinderParameters::maxNbVertices = " 
00089     << conf.getParameter<edm::ParameterSet>("VtxFinderParameters").getParameter<int>("maxNbVertices") << endl;
00090   theFinder.setMaxNbOfVertices(maxNbVertices);
00091 
00092   edm::LogInfo("RecoVertex/PrimaryVertexProducerAlgorithm") 
00093     << "PV producer algorithm initialization: done" << "\n";
00094 
00095 }
00096 
00097 
00098 PrimaryVertexProducerAlgorithm::~PrimaryVertexProducerAlgorithm() 
00099 {
00100   if (theFitter) delete theFitter;
00101 }
00102 
00103 
00104 //
00105 // member functions
00106 //
00107 vector<TransientVertex> 
00108 PrimaryVertexProducerAlgorithm::vertices(const vector<reco::TransientTrack> & tracks) const
00109 {
00110   std::cout<< "PrimaryVertexProducer::vertices> Obsolete function, using dummy beamspot " << std::endl;
00111     reco::BeamSpot dummyBeamSpot;
00112     dummyBeamSpot.dummy();
00113     return vertices(tracks,dummyBeamSpot); 
00114 }
00115 
00116 
00117 vector<TransientVertex> 
00118 PrimaryVertexProducerAlgorithm::vertices(const vector<reco::TransientTrack> & tracks,
00119                                          const reco::BeamSpot & beamSpot) const
00120 {
00121   
00122   VertexState beamVertexState(beamSpot);
00123 
00124   if ( fapply_finder) {
00125         return theFinder.vertices( tracks );
00126   }
00127   vector<TransientVertex> pvs;
00128 
00129 
00130   // select tracks
00131   vector<TransientTrack> seltks;
00132 
00133   for (vector<reco::TransientTrack>::const_iterator itk = tracks.begin();
00134        itk != tracks.end(); itk++) {
00135     if (theTrackFilter(*itk)) seltks.push_back(*itk);
00136   }
00137 
00138   if(fVerbose){
00139     cout << "PrimaryVertexProducerAlgorithm::vertices  selected tracks=" << seltks.size() << endl;
00140   }
00141 
00142   // clusterize tracks in Z
00143   vector< vector<reco::TransientTrack> > clusters = 
00144     theTrackClusterizer.clusterize(seltks);
00145 
00146 
00147   // look for primary vertices in each cluster
00148   vector<TransientVertex> pvCand;
00149   int nclu=0;
00150   for (vector< vector<reco::TransientTrack> >::const_iterator iclus
00151          = clusters.begin(); iclus != clusters.end(); iclus++) {
00152 
00153     if(fVerbose){
00154       cout << "PrimaryVertexProducerAlgorithm::vertices  cluster =" 
00155            << nclu << "  tracks" << (*iclus).size() << endl;
00156 
00157       std::cout << "cluster tracks " << std::endl;
00158     }
00159 
00160     if( fUseBeamConstraint &&((*iclus).size()>1) ){
00161       if (fVerbose){cout <<  "constrained fit with "<< (*iclus).size() << " tracks"  << endl;}
00162       TransientVertex v = theFitter->vertex(*iclus, beamSpot);
00163       if (v.isValid()) pvCand.push_back(v);
00164 
00165       if (fVerbose){
00166         cout << "beamspot   x="<< beamVertexState.position().x() 
00167              << " y=" << beamVertexState.position().y()
00168              << " z=" << beamVertexState.position().z()
00169              << " dx=" << sqrt(beamVertexState.error().cxx())
00170              << " dy=" << sqrt(beamVertexState.error().cyy())
00171              << " dz=" << sqrt(beamVertexState.error().czz())
00172              << std::endl;
00173         if (v.isValid()) cout << "x,y,z=" << v.position().x() <<" " << v.position().y() << " " <<  v.position().z() << endl;
00174         else cout <<"Invalid fitted vertex\n";
00175       }
00176 
00177     }else if((*iclus).size()>1){
00178       if (fVerbose){cout <<  "unconstrained fit with "<< (*iclus).size() << " tracks"  << endl;}
00179 
00180       TransientVertex v = theFitter->vertex(*iclus); 
00181       if (v.isValid()) pvCand.push_back(v);
00182 
00183       if (fVerbose){
00184         if (v.isValid()) cout << "x,y,z=" << v.position().x() <<" " << v.position().y() << " " <<  v.position().z() << endl;
00185         else cout <<"Invalid fitted vertex\n";
00186       }
00187 
00188     }else if (fVerbose){
00189       cout <<  "cluster dropped" << endl;
00190     }
00191 
00192 
00193     nclu++;
00194   }// end of cluster loop
00195 
00196 
00197   if(fVerbose){
00198     cout << "PrimaryVertexProducerAlgorithm::vertices  candidates =" << pvCand.size() << endl;
00199   }
00200 
00201   // select vertices compatible with beam
00202   int npv=0;
00203   for (vector<TransientVertex>::const_iterator ipv = pvCand.begin();
00204        ipv != pvCand.end(); ipv++) {
00205     if(fVerbose){
00206       cout << "PrimaryVertexProducerAlgorithm::vertices cand " << npv++ << " sel=" <<
00207         theVertexSelector(*ipv,beamVertexState) << "   z="  << ipv->position().z() << endl;
00208     }
00209     if (theVertexSelector(*ipv,beamVertexState)) pvs.push_back(*ipv);
00210   }
00211 
00212   // sort vertices by pt**2  vertex (aka signal vertex tagging)
00213   sort(pvs.begin(), pvs.end(), VertexHigherPtSquared());
00214   
00215 
00216   return pvs;
00217   
00218 }

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