00001 #include "RecoVertex/PrimaryVertexProducer/interface/PrimaryVertexProducer.h"
00002
00003 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00004 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00005 #include "DataFormats/Common/interface/EDProduct.h"
00006 #include "DataFormats/Common/interface/Handle.h"
00007 #include "FWCore/Framework/interface/MakerMacros.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009
00010 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00011 #include "RecoVertex/VertexPrimitives/interface/TransientVertex.h"
00012
00013 #include "FWCore/Framework/interface/ESHandle.h"
00014 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
00015 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
00016 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 PrimaryVertexProducer::PrimaryVertexProducer(const edm::ParameterSet& conf)
00032 : theAlgo(conf), theConfig(conf)
00033 {
00034 edm::LogInfo("RecoVertex/PrimaryVertexProducer")
00035 << "Initializing PV producer " << "\n";
00036 fVerbose=conf.getUntrackedParameter<bool>("verbose", false);
00037
00038 trackLabel = conf.getParameter<edm::InputTag>("TrackLabel");
00039 beamSpotLabel = conf.getParameter<edm::InputTag>("beamSpotLabel");
00040
00041
00042 produces<reco::VertexCollection>();
00043
00044 }
00045
00046
00047 PrimaryVertexProducer::~PrimaryVertexProducer() {}
00048
00049
00050
00051
00052
00053
00054 void
00055 PrimaryVertexProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00056 {
00057 using namespace edm;
00058
00059 std::auto_ptr<reco::VertexCollection> result(new reco::VertexCollection);
00060 reco::VertexCollection vColl;
00061
00062
00063 edm::LogInfo("RecoVertex/PrimaryVertexProducer")
00064 << "Reconstructing event number: " << iEvent.id() << "\n";
00065
00066
00067 reco::BeamSpot vertexBeamSpot;
00068 edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00069 iEvent.getByLabel(beamSpotLabel,recoBeamSpotHandle);
00070 if (recoBeamSpotHandle.isValid()){
00071 vertexBeamSpot = *recoBeamSpotHandle;
00072 edm::LogInfo("RecoVertex/PrimaryVertexProducer")
00073 << " found BeamSpot"
00074 << *recoBeamSpotHandle << "\n";
00075 }else{
00076 vertexBeamSpot.dummy();
00077 edm::LogInfo("RecoVertex/PrimaryVertexProducer")
00078 << "No beam spot available from EventSetup \n"
00079 << "continue using default BeamSpot\n" ;
00080 }
00081
00082
00083
00084
00085
00086 edm::Handle<reco::TrackCollection> tks;
00087 iEvent.getByLabel(trackLabel, tks);
00088
00089
00090
00091 edm::LogInfo("RecoVertex/PrimaryVertexProducer")
00092 << "Found: " << (*tks).size() << " reconstructed tracks" << "\n";
00093 edm::ESHandle<TransientTrackBuilder> theB;
00094 iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theB);
00095 vector<reco::TransientTrack> t_tks = (*theB).build(tks, vertexBeamSpot);
00096 edm::LogInfo("RecoVertex/PrimaryVertexProducer")
00097 << "Found: " << t_tks.size() << " reconstructed tracks" << "\n";
00098 if(fVerbose) {cout << "RecoVertex/PrimaryVertexProducer"
00099 << "Found: " << t_tks.size() << " reconstructed tracks" << "\n";
00100 }
00101
00102
00103
00104 vector<TransientVertex> t_vts = theAlgo.vertices(t_tks, vertexBeamSpot);
00105 if(fVerbose){
00106 std::cout <<"RecoVertex/PrimaryVertexProducer: "
00107 << " found " << t_vts.size() << " reconstructed vertices" << "\n";
00108 }
00109
00110
00111 for (vector<TransientVertex>::const_iterator iv = t_vts.begin();
00112 iv != t_vts.end(); iv++) {
00113 reco::Vertex v = *iv;
00114 vColl.push_back(v);
00115 }
00116
00117 if (vColl.empty()) {
00118 vColl.push_back(reco::Vertex(vertexBeamSpot.position(),
00119 vertexBeamSpot.rotatedCovariance3D(),0.,0.,0));
00120 if(fVerbose){
00121 std::cout <<"RecoVertex/PrimaryVertexProducer: "
00122 << " will put Vertex derived from BeamSpot into Event.\n";
00123 }
00124 }
00125
00126 if(fVerbose){
00127 cout << "RecoVertex/PrimaryVertexProducer: nv=" <<vColl.size()<< endl;
00128 int ivtx=0;
00129 for(reco::VertexCollection::const_iterator v=vColl.begin();
00130 v!=vColl.end(); ++v){
00131 std::cout << "recvtx "<< ivtx++
00132 << "#trk " << std::setw(3) << v->tracksSize()
00133 << " chi2 " << std::setw(4) << v->chi2()
00134 << " ndof " << std::setw(3) << v->ndof()
00135 << " x " << std::setw(6) << v->position().x()
00136 << " dx " << std::setw(6) << v->xError()
00137 << " y " << std::setw(6) << v->position().y()
00138 << " dy " << std::setw(6) << v->yError()
00139 << " z " << std::setw(6) << v->position().z()
00140 << " dz " << std::setw(6) << v->zError()
00141 << std::endl;
00142 }
00143 }
00144
00145
00146 *result = vColl;
00147
00148 iEvent.put(result);
00149
00150 }
00151
00152
00153
00154 DEFINE_FWK_MODULE(PrimaryVertexProducer);