File indexing completed on 2023-03-17 11:14:07
0001 #ifndef __L1Trigger_VertexFinder_VertexFinder_h__
0002 #define __L1Trigger_VertexFinder_VertexFinder_h__
0003
0004 #include "DataFormats/Common/interface/Ptr.h"
0005 #include "DataFormats/L1TrackTrigger/interface/TTTrack.h"
0006 #include "DataFormats/L1Trigger/interface/VertexWord.h"
0007 #include "DataFormats/Math/interface/deltaPhi.h"
0008 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "L1Trigger/VertexFinder/interface/AlgoSettings.h"
0011 #include "L1Trigger/VertexFinder/interface/RecoVertex.h"
0012
0013 #include <algorithm>
0014 #include <cmath>
0015 #include <iterator>
0016 #include <vector>
0017
0018 namespace l1tVertexFinder {
0019
0020
0021 static constexpr unsigned BitsToRepresent(unsigned x) { return x < 2 ? 1 : 1 + BitsToRepresent(x >> 1); }
0022
0023 typedef std::vector<L1Track> FitTrackCollection;
0024 typedef std::vector<RecoVertex<>> RecoVertexCollection;
0025
0026 class VertexFinder {
0027 public:
0028
0029 VertexFinder(FitTrackCollection& fitTracks, const AlgoSettings& settings) {
0030 fitTracks_ = fitTracks;
0031 settings_ = &settings;
0032 }
0033 ~VertexFinder() {}
0034
0035
0036 struct SortTracksByZ0 {
0037 inline bool operator()(const L1Track track0, const L1Track track1) { return (track0.z0() < track1.z0()); }
0038 };
0039
0040 struct SortTracksByPt {
0041 inline bool operator()(const L1Track track0, const L1Track track1) {
0042 return (std::abs(track0.pt()) > std::abs(track1.pt()));
0043 }
0044 };
0045
0046
0047
0048
0049 const FitTrackCollection& fitTracks() const { return fitTracks_; }
0050
0051 unsigned int iterationsPerTrack() const { return double(iterations_) / double(fitTracks_.size()); }
0052
0053 unsigned int numInputTracks() const { return fitTracks_.size(); }
0054
0055 unsigned int numIterations() const { return iterations_; }
0056
0057 unsigned int numVertices() const { return vertices_.size(); }
0058
0059 unsigned int numVerticesEmulation() const { return verticesEmulation_.size(); }
0060
0061 template <typename T>
0062 T PrimaryVertex() const {
0063 if ((settings_->vx_precision() == Precision::Simulation) && (pv_index_ < vertices_.size()))
0064 return vertices_[pv_index_];
0065 else if ((settings_->vx_precision() == Precision::Emulation) && (pv_index_ < vertices_.size()))
0066 return verticesEmulation_[pv_index_];
0067 else {
0068 edm::LogWarning("VertexFinder") << "PrimaryVertex::No primary vertex has been found.";
0069 return RecoVertex<>();
0070 }
0071 }
0072
0073 unsigned int primaryVertexId() const { return pv_index_; }
0074
0075 const std::vector<RecoVertex<>>& vertices() const { return vertices_; }
0076
0077 const l1t::VertexWordCollection& verticesEmulation() const { return verticesEmulation_; }
0078
0079
0080 void findPrimaryVertex();
0081
0082 void associatePrimaryVertex(double trueZ0);
0083
0084 void GapClustering();
0085
0086 float maxDistance(RecoVertex<> cluster0, RecoVertex<> cluster1);
0087
0088 float minDistance(RecoVertex<> cluster0, RecoVertex<> cluster1);
0089
0090 float meanDistance(RecoVertex<> cluster0, RecoVertex<> cluster1);
0091
0092 float centralDistance(RecoVertex<> cluster0, RecoVertex<> cluster1);
0093
0094 void agglomerativeHierarchicalClustering();
0095
0096 void adaptiveVertexReconstruction();
0097
0098 void fastHistoLooseAssociation();
0099
0100 void fastHisto(const TrackerTopology* tTopo);
0101
0102 void fastHistoEmulation();
0103
0104
0105 void sortVerticesInPt();
0106
0107 void sortVerticesInZ0();
0108
0109
0110 template <class data_type, typename stream_type = std::ostream>
0111 void printHistogram(stream_type& stream,
0112 std::vector<data_type> data,
0113 int width = 80,
0114 int minimum = 0,
0115 int maximum = -1,
0116 std::string title = "",
0117 std::string color = "");
0118
0119 template <typename ForwardIterator, typename T>
0120 void strided_iota(ForwardIterator first, ForwardIterator last, T value, T stride) {
0121 while (first != last) {
0122 *first++ = value;
0123 value += stride;
0124 }
0125 }
0126
0127
0128
0129
0130 void computeAndSetVertexParameters(RecoVertex<>& vertex,
0131 const std::vector<float>& bin_centers,
0132 const std::vector<unsigned int>& counts);
0133
0134 void DBSCAN();
0135
0136 void HPV();
0137
0138 void Kmeans();
0139
0140 void PVR();
0141
0142 private:
0143 const AlgoSettings* settings_;
0144 RecoVertexCollection vertices_;
0145 l1t::VertexWordCollection verticesEmulation_;
0146 unsigned int numMatchedVertices_;
0147 FitTrackCollection fitTracks_;
0148 unsigned int pv_index_;
0149 unsigned int iterations_;
0150 };
0151
0152 }
0153
0154 #endif