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