File indexing completed on 2024-04-06 12:29:17
0001
0002 #include "RecoVertex/PrimaryVertexProducer/interface/PrimaryVertexProducerAlgorithm.h"
0003
0004 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0005 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0006 #include "DataFormats/Common/interface/Handle.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009
0010 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0011 #include "RecoVertex/VertexPrimitives/interface/TransientVertex.h"
0012 #include "RecoVertex/VertexTools/interface/VertexDistanceXY.h"
0013
0014 #include "FWCore/Framework/interface/ESHandle.h"
0015 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
0016 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
0017 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0018
0019 PrimaryVertexProducerAlgorithm::PrimaryVertexProducerAlgorithm(const edm::ParameterSet& conf) : theConfig(conf) {
0020 fVerbose = conf.getUntrackedParameter<bool>("verbose", false);
0021 trackLabel = conf.getParameter<edm::InputTag>("TrackLabel");
0022 beamSpotLabel = conf.getParameter<edm::InputTag>("beamSpotLabel");
0023
0024
0025 std::string trackSelectionAlgorithm =
0026 conf.getParameter<edm::ParameterSet>("TkFilterParameters").getParameter<std::string>("algorithm");
0027 if (trackSelectionAlgorithm == "filter") {
0028 theTrackFilter = new TrackFilterForPVFinding(conf.getParameter<edm::ParameterSet>("TkFilterParameters"));
0029 } else if (trackSelectionAlgorithm == "filterWithThreshold") {
0030 theTrackFilter = new HITrackFilterForPVFinding(conf.getParameter<edm::ParameterSet>("TkFilterParameters"));
0031 } else {
0032 throw VertexException("PrimaryVertexProducerAlgorithm: unknown track selection algorithm: " +
0033 trackSelectionAlgorithm);
0034 }
0035
0036
0037 std::string clusteringAlgorithm =
0038 conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<std::string>("algorithm");
0039 if (clusteringAlgorithm == "gap") {
0040 theTrackClusterizer = new GapClusterizerInZ(
0041 conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkGapClusParameters"));
0042 }
0043
0044 else if (clusteringAlgorithm == "DA_vect") {
0045 theTrackClusterizer = new DAClusterizerInZ_vect(
0046 conf.getParameter<edm::ParameterSet>("TkClusParameters").getParameter<edm::ParameterSet>("TkDAClusParameters"));
0047 }
0048
0049 else {
0050 throw VertexException("PrimaryVertexProducerAlgorithm: unknown clustering algorithm: " + clusteringAlgorithm);
0051 }
0052
0053
0054 std::vector<edm::ParameterSet> vertexCollections =
0055 conf.getParameter<std::vector<edm::ParameterSet> >("vertexCollections");
0056
0057 for (std::vector<edm::ParameterSet>::const_iterator algoconf = vertexCollections.begin();
0058 algoconf != vertexCollections.end();
0059 algoconf++) {
0060 algo algorithm;
0061 std::string fitterAlgorithm = algoconf->getParameter<std::string>("algorithm");
0062 if (fitterAlgorithm == "KalmanVertexFitter") {
0063 algorithm.fitter = new KalmanVertexFitter();
0064 } else if (fitterAlgorithm == "AdaptiveVertexFitter") {
0065 algorithm.fitter = new AdaptiveVertexFitter();
0066 } else {
0067 throw VertexException("PrimaryVertexProducerAlgorithm: unknown algorithm: " + fitterAlgorithm);
0068 }
0069 algorithm.label = algoconf->getParameter<std::string>("label");
0070 algorithm.minNdof = algoconf->getParameter<double>("minNdof");
0071 algorithm.useBeamConstraint = algoconf->getParameter<bool>("useBeamConstraint");
0072 algorithm.vertexSelector =
0073 new VertexCompatibleWithBeam(VertexDistanceXY(), algoconf->getParameter<double>("maxDistanceToBeam"));
0074 algorithms.push_back(algorithm);
0075 }
0076 }
0077
0078 PrimaryVertexProducerAlgorithm::~PrimaryVertexProducerAlgorithm() {
0079 if (theTrackFilter)
0080 delete theTrackFilter;
0081 if (theTrackClusterizer)
0082 delete theTrackClusterizer;
0083 for (std::vector<algo>::const_iterator algorithm = algorithms.begin(); algorithm != algorithms.end(); algorithm++) {
0084 if (algorithm->fitter)
0085 delete algorithm->fitter;
0086 if (algorithm->vertexSelector)
0087 delete algorithm->vertexSelector;
0088 }
0089 }
0090
0091
0092
0093
0094
0095
0096 std::vector<TransientVertex> PrimaryVertexProducerAlgorithm::vertices(
0097 const std::vector<reco::TransientTrack>& tracks) const {
0098 throw VertexException("PrimaryVertexProducerAlgorithm: cannot make a Primary Vertex without a beam spot");
0099
0100 return std::vector<TransientVertex>();
0101 }
0102
0103 std::vector<TransientVertex> PrimaryVertexProducerAlgorithm::vertices(const std::vector<reco::TransientTrack>& t_tks,
0104 const reco::BeamSpot& beamSpot,
0105 const std::string& label) const {
0106 bool validBS = true;
0107 VertexState beamVertexState(beamSpot);
0108 if ((beamVertexState.error().cxx() <= 0.) || (beamVertexState.error().cyy() <= 0.) ||
0109 (beamVertexState.error().czz() <= 0.)) {
0110 validBS = false;
0111 edm::LogError("UnusableBeamSpot") << "Beamspot with invalid errors " << beamVertexState.error().matrix();
0112 }
0113
0114
0115
0116
0117
0118
0119
0120 std::vector<reco::TransientTrack> seltks = theTrackFilter->select(t_tks);
0121
0122
0123 std::vector<std::vector<reco::TransientTrack> > clusters = theTrackClusterizer->clusterize(seltks);
0124 if (fVerbose) {
0125 std::cout << " clustering returned " << clusters.size() << " clusters from " << seltks.size()
0126 << " selected tracks" << std::endl;
0127 }
0128
0129
0130 for (std::vector<algo>::const_iterator algorithm = algorithms.begin(); algorithm != algorithms.end(); algorithm++) {
0131 if (!(algorithm->label == label))
0132 continue;
0133
0134
0135
0136
0137 std::vector<TransientVertex> pvs;
0138 for (std::vector<std::vector<reco::TransientTrack> >::const_iterator iclus = clusters.begin();
0139 iclus != clusters.end();
0140 iclus++) {
0141 TransientVertex v;
0142 if (algorithm->useBeamConstraint && validBS && ((*iclus).size() > 1)) {
0143 v = algorithm->fitter->vertex(*iclus, beamSpot);
0144
0145 } else if (!(algorithm->useBeamConstraint) && ((*iclus).size() > 1)) {
0146 v = algorithm->fitter->vertex(*iclus);
0147
0148 }
0149
0150 if (fVerbose) {
0151 if (v.isValid())
0152 std::cout << "x,y,z=" << v.position().x() << " " << v.position().y() << " " << v.position().z() << std::endl;
0153 else
0154 std::cout << "Invalid fitted vertex\n";
0155 }
0156
0157 if (v.isValid() && (v.degreesOfFreedom() >= algorithm->minNdof) &&
0158 (!validBS || (*(algorithm->vertexSelector))(v, beamVertexState)))
0159 pvs.push_back(v);
0160 }
0161
0162 if (fVerbose) {
0163 std::cout << "PrimaryVertexProducerAlgorithm::vertices candidates =" << pvs.size() << std::endl;
0164 }
0165
0166
0167 if (pvs.size() > 1) {
0168 sort(pvs.begin(), pvs.end(), VertexHigherPtSquared());
0169 }
0170
0171 return pvs;
0172 }
0173
0174 std::vector<TransientVertex> dummy;
0175 return dummy;
0176 }