File indexing completed on 2024-09-07 04:38:05
0001 #include "RecoVertex/PixelVertexFinding/interface/DivisiveVertexFinder.h"
0002 #include "RecoVertex/PixelVertexFinding/interface/PVPositionBuilder.h"
0003 #include "RecoVertex/PixelVertexFinding/interface/PVCluster.h"
0004 #include "DataFormats/GeometryCommonDetAlgo/interface/Measurement1D.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/Utilities/interface/isFinite.h"
0007 #include <utility>
0008 #include <vector>
0009 #include <map>
0010 #include <algorithm>
0011 #include <cmath>
0012
0013 DivisiveVertexFinder::DivisiveVertexFinder(double track_pt_min,
0014 double track_pt_max,
0015 double track_chi2_max,
0016 double track_prob_min,
0017 double zOffset,
0018 int ntrkMin,
0019 bool useError,
0020 double zSeparation,
0021 bool wtAverage,
0022 int verbosity)
0023 : zOffset_(zOffset),
0024 zSeparation_(zSeparation),
0025 ntrkMin_(ntrkMin),
0026 useError_(useError),
0027 wtAverage_(wtAverage),
0028 divmeth_(zOffset, ntrkMin, useError, zSeparation, wtAverage),
0029 verbose_(verbosity) {
0030 pvComparer_ = new PVClusterComparer(track_pt_min, track_pt_max, track_chi2_max, track_prob_min);
0031 }
0032
0033 DivisiveVertexFinder::~DivisiveVertexFinder() {}
0034
0035 bool DivisiveVertexFinder::findVertexes(const reco::TrackRefVector &trks,
0036 reco::VertexCollection &vertexes) {
0037 PVPositionBuilder pos;
0038 Measurement1D vz;
0039 if (wtAverage_) {
0040 vz = pos.wtAverage(trks);
0041 } else {
0042 vz = pos.average(trks);
0043 }
0044 reco::Vertex::Error err;
0045 err(2, 2) = vz.error() * vz.error();
0046
0047 reco::Vertex v(reco::Vertex::Point(0, 0, vz.value()), err, 0, 1, trks.size());
0048 for (unsigned int i = 0; i < trks.size(); i++) {
0049 double vz = trks[i]->vz();
0050 if (edm::isNotFinite(vz))
0051 continue;
0052 v.add(reco::TrackBaseRef(trks[i]));
0053 }
0054
0055 vertexes.push_back(v);
0056
0057 return true;
0058 }
0059
0060 bool DivisiveVertexFinder::findVertexesAlt(const reco::TrackRefVector &trks,
0061 reco::VertexCollection &vertexes,
0062 const math::XYZPoint &bs) {
0063 std::vector<PVCluster> in;
0064 std::pair<std::vector<PVCluster>, std::vector<const reco::Track *> > out;
0065
0066
0067
0068 std::map<const reco::Track *, reco::TrackRef> mapa;
0069
0070 for (unsigned int i = 0; i < trks.size(); ++i) {
0071 double vz = trks[i]->vz();
0072 if (edm::isNotFinite(vz))
0073 continue;
0074 std::vector<const reco::Track *> temp;
0075 temp.clear();
0076 temp.push_back(&(*trks[i]));
0077
0078 in.push_back(PVCluster(Measurement1D(trks[i]->dz(bs), trks[i]->dzError()), temp));
0079 mapa[temp[0]] = trks[i];
0080 }
0081
0082 if (verbose_ > 0) {
0083 edm::LogInfo("DivisiveVertexFinder") << "size of input vector of clusters " << in.size();
0084 for (unsigned int i = 0; i < in.size(); ++i) {
0085 edm::LogInfo("DivisiveVertexFinder")
0086 << "Track " << i << " addr " << in[i].tracks()[0] << " dz " << in[i].tracks()[0]->dz(bs) << " +- "
0087 << in[i].tracks()[0]->dzError() << " prodID " << mapa[in[i].tracks()[0]].id() << " dz from RefTrack "
0088 << mapa[in[i].tracks()[0]]->dz(bs) << " +- " << mapa[in[i].tracks()[0]]->dzError();
0089 }
0090 }
0091
0092
0093 divmeth_.setBeamSpot(bs);
0094 out = divmeth_(in);
0095
0096 if (verbose_ > 0)
0097 edm::LogInfo("DivisiveVertexFinder") << " DivisiveClusterizer1D found " << out.first.size() << " vertexes";
0098
0099
0100 for (unsigned int iv = 0; iv < out.first.size(); ++iv) {
0101 reco::Vertex::Error err;
0102 err(2, 2) = out.first[iv].position().error() * out.first[iv].position().error();
0103
0104 reco::Vertex v(reco::Vertex::Point(0, 0, out.first[iv].position().value()), err, 0, 1, out.second.size());
0105 if (verbose_ > 0)
0106 edm::LogInfo("DivisiveVertexFinder")
0107 << " DivisiveClusterizer1D vertex " << iv << " has " << out.first[iv].tracks().size()
0108 << " tracks and a position of " << v.z() << " +- " << std::sqrt(v.covariance(2, 2));
0109 for (unsigned int itrk = 0; itrk < out.first[iv].tracks().size(); ++itrk) {
0110 v.add(reco::TrackBaseRef(mapa[out.first[iv].tracks()[itrk]]));
0111 }
0112 vertexes.push_back(v);
0113 }
0114
0115
0116
0117 std::sort(vertexes.begin(), vertexes.end(), *pvComparer_);
0118
0119 return true;
0120 }