Go to the documentation of this file.00001 #include "RecoHI/HiTracking/interface/HIBestVertexProducer.h"
00002
00003 #include "FWCore/Framework/interface/MakerMacros.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "FWCore/Framework/interface/Frameworkfwd.h"
00006 #include "FWCore/Framework/interface/Event.h"
00007
00008 #include "DataFormats/VertexReco/interface/Vertex.h"
00009 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00010 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012
00013 #include <algorithm>
00014 #include <iostream>
00015 using namespace std;
00016 using namespace edm;
00017
00018
00019 HIBestVertexProducer::HIBestVertexProducer
00020 (const edm::ParameterSet& ps) : theConfig(ps),
00021 theBeamSpotTag(ps.getParameter<edm::InputTag>("beamSpotLabel")),
00022 theMedianVertexCollection(ps.getParameter<edm::InputTag>("medianVertexCollection")),
00023 theAdaptiveVertexCollection(ps.getParameter<edm::InputTag>("adaptiveVertexCollection"))
00024 {
00025 produces<reco::VertexCollection>();
00026 }
00027
00028
00029
00030 HIBestVertexProducer::~HIBestVertexProducer()
00031 {
00032 }
00033
00034
00035 void HIBestVertexProducer::beginJob()
00036 {
00037 }
00038
00039
00040 void HIBestVertexProducer::produce
00041 (edm::Event& ev, const edm::EventSetup& es)
00042 {
00043
00044
00045
00046
00047
00048
00049 std::auto_ptr<reco::VertexCollection> newVertexCollection(new reco::VertexCollection);
00050
00051
00052 edm::Handle<reco::VertexCollection> vc1;
00053 ev.getByLabel(theAdaptiveVertexCollection, vc1);
00054 const reco::VertexCollection *vertices1 = vc1.product();
00055
00056 if(vertices1->size()==0)
00057 LogError("HeavyIonVertexing") << "adaptive vertex collection is empty!" << endl;
00058
00059 if(vertices1->begin()->zError()<3) {
00060
00061 reco::VertexCollection::const_iterator vertex1 = vertices1->begin();
00062 newVertexCollection->push_back(*vertex1);
00063
00064 LogInfo("HeavyIonVertexing") << "adaptive vertex:\n vz = ("
00065 << vertex1->x() << ", " << vertex1->y() << ", " << vertex1->z() << ")"
00066 << "\n error = ("
00067 << vertex1->xError() << ", " << vertex1->yError() << ", "
00068 << vertex1->zError() << ")" << endl;
00069 } else {
00070
00071
00072 edm::Handle<reco::VertexCollection> vc2;
00073 ev.getByLabel(theMedianVertexCollection, vc2);
00074 const reco::VertexCollection * vertices2 = vc2.product();
00075
00076
00077 reco::BeamSpot beamSpot;
00078 edm::Handle<reco::BeamSpot> beamSpotHandle;
00079 ev.getByLabel(theBeamSpotTag, beamSpotHandle);
00080
00081 if( beamSpotHandle.isValid() )
00082 beamSpot = *beamSpotHandle;
00083 else
00084 LogError("HeavyIonVertexing") << "no beamspot with name: '" << theBeamSpotTag << "'" << endl;
00085
00086 if(vertices2->size() > 0) {
00087
00088 reco::VertexCollection::const_iterator vertex2 = vertices2->begin();
00089 reco::Vertex::Error err;
00090 err(0,0)=pow(beamSpot.BeamWidthX(),2);
00091 err(1,1)=pow(beamSpot.BeamWidthY(),2);
00092 err(2,2)=pow(vertex2->zError(),2);
00093 reco::Vertex newVertex(reco::Vertex::Point(beamSpot.x0(),beamSpot.y0(),vertex2->z()),
00094 err, 0, 1, 1);
00095 newVertexCollection->push_back(newVertex);
00096
00097 LogInfo("HeavyIonVertexing") << "median vertex + beamspot: \n position = ("
00098 << newVertex.x() << ", " << newVertex.y() << ", " << newVertex.z() << ")"
00099 << "\n error = ("
00100 << newVertex.xError() << ", " << newVertex.yError() << ", "
00101 << newVertex.zError() << ")" << endl;
00102
00103 } else {
00104
00105 reco::Vertex::Error err;
00106 err(0,0)=pow(beamSpot.BeamWidthX(),2);
00107 err(1,1)=pow(beamSpot.BeamWidthY(),2);
00108 err(2,2)=pow(beamSpot.sigmaZ(),2);
00109 reco::Vertex newVertex(beamSpot.position(),
00110 err, 0, 0, 1);
00111 newVertexCollection->push_back(newVertex);
00112
00113 LogInfo("HeavyIonVertexing") << "beam spot: \n position = ("
00114 << newVertex.x() << ", " << newVertex.y() << ", " << newVertex.z() << ")"
00115 << "\n error = ("
00116 << newVertex.xError() << ", " << newVertex.yError() << ", "
00117 << newVertex.zError() << ")" << endl;
00118
00119 }
00120
00121 }
00122
00123
00124 ev.put(newVertexCollection);
00125
00126 }
00127