Go to the documentation of this file.00001 #include "RecoPixelVertexing/PixelVertexFinding/interface/DivisiveVertexFinder.h"
00002 #include "RecoPixelVertexing/PixelVertexFinding/interface/PVPositionBuilder.h"
00003 #include "RecoPixelVertexing/PixelVertexFinding/interface/PVCluster.h"
00004 #include "DataFormats/GeometryCommonDetAlgo/interface/Measurement1D.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "RecoPixelVertexing/PixelVertexFinding/interface/PVClusterComparer.h"
00007 #include "FWCore/Utilities/interface/isFinite.h"
00008 #include <utility>
00009 #include <vector>
00010 #include <map>
00011 #include <algorithm>
00012 #include <cmath>
00013
00014 DivisiveVertexFinder::DivisiveVertexFinder(double zOffset, int ntrkMin,
00015 bool useError, double zSeparation, bool wtAverage,
00016 int verbosity)
00017 : zOffset_(zOffset), zSeparation_(zSeparation), ntrkMin_(ntrkMin), useError_(useError),
00018 wtAverage_(wtAverage),
00019 divmeth_(zOffset, ntrkMin, useError, zSeparation, wtAverage),
00020 verbose_(verbosity)
00021 {
00022
00023 }
00024
00025 DivisiveVertexFinder::~DivisiveVertexFinder(){}
00026
00027 bool DivisiveVertexFinder::findVertexes(const reco::TrackRefVector &trks,
00028 reco::VertexCollection &vertexes){
00029 PVPositionBuilder pos;
00030 Measurement1D vz;
00031 if (wtAverage_) {
00032 vz = pos.wtAverage(trks);
00033 }
00034 else {
00035 vz = pos.average(trks);
00036 }
00037 reco::Vertex::Error err;
00038 err(2,2) = vz.error()*vz.error();
00039
00040 reco::Vertex v( reco::Vertex::Point(0,0,vz.value()), err, 0, 1, trks.size() );
00041 for (unsigned int i=0; i<trks.size(); i++) {
00042 double vz = trks[i]->vz();
00043 if(edm::isNotFinite(vz)) continue;
00044 v.add(reco::TrackBaseRef(trks[i]));
00045 }
00046
00047 vertexes.push_back(v);
00048
00049 return true;
00050 }
00051
00052 bool DivisiveVertexFinder::findVertexesAlt(const reco::TrackRefVector &trks,
00053 reco::VertexCollection &vertexes, const math::XYZPoint & bs){
00054 std::vector< PVCluster > in;
00055 std::pair< std::vector< PVCluster >, std::vector< const reco::Track* > > out;
00056
00057
00058
00059 std::map< const reco::Track*, reco::TrackRef > mapa;
00060
00061 for (unsigned int i=0; i<trks.size(); ++i) {
00062 double vz = trks[i]->vz();
00063 if(edm::isNotFinite(vz)) continue;
00064 std::vector< const reco::Track* > temp;
00065 temp.clear();
00066 temp.push_back( &(*trks[i]) );
00067
00068 in.push_back( PVCluster( Measurement1D(trks[i]->dz(bs), trks[i]->dzError() ), temp ) );
00069 mapa[temp[0]] = trks[i];
00070 }
00071
00072 if (verbose_ > 0 ) {
00073 edm::LogInfo("DivisiveVertexFinder") << "size of input vector of clusters " << in.size();
00074 for (unsigned int i=0; i<in.size(); ++i) {
00075 edm::LogInfo("DivisiveVertexFinder") << "Track " << i << " addr " << in[i].tracks()[0]
00076 << " dz " << in[i].tracks()[0]->dz(bs)
00077 << " +- " << in[i].tracks()[0]->dzError()
00078 << " prodID " << mapa[in[i].tracks()[0]].id()
00079 << " dz from RefTrack " << mapa[in[i].tracks()[0]]->dz(bs)
00080 << " +- " << mapa[in[i].tracks()[0]]->dzError();
00081 }
00082 }
00083
00084
00085 divmeth_.setBeamSpot(bs);
00086 out = divmeth_(in);
00087
00088 if (verbose_ > 0) edm::LogInfo("DivisiveVertexFinder") << " DivisiveClusterizer1D found "
00089 << out.first.size() << " vertexes";
00090
00091
00092 for (unsigned int iv=0; iv<out.first.size(); ++iv) {
00093 reco::Vertex::Error err;
00094 err(2,2) = out.first[iv].position().error()*out.first[iv].position().error();
00095
00096 reco::Vertex v( reco::Vertex::Point(0,0,out.first[iv].position().value()), err, 0, 1, out.second.size() );
00097 if (verbose_ > 0 ) edm::LogInfo("DivisiveVertexFinder") << " DivisiveClusterizer1D vertex " << iv
00098 << " has " << out.first[iv].tracks().size()
00099 << " tracks and a position of " << v.z()
00100 << " +- " << std::sqrt(v.covariance(2,2));
00101 for (unsigned int itrk=0; itrk<out.first[iv].tracks().size(); ++itrk) {
00102 v.add( reco::TrackBaseRef(mapa[out.first[iv].tracks()[itrk]] ) );
00103 }
00104 vertexes.push_back(v);
00105 }
00106
00107
00108 std::sort(vertexes.begin(), vertexes.end(), PVClusterComparer());
00109
00110 return true;
00111 }