Back to home page

Project CMSSW displayed by LXR

 
 

    


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   // Returns the number of bits needed to represent and integer decimal
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     /// Constructor and destructor
0030     VertexFinder(FitTrackCollection& fitTracks, const AlgoSettings& settings) {
0031       fitTracks_ = fitTracks;
0032       settings_ = &settings;
0033     }
0034     ~VertexFinder() {}
0035 
0036     /// Helper structs/classes
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     /// Accessors
0048 
0049     /// Storage for tracks out of the L1 Track finder
0050     const FitTrackCollection& fitTracks() const { return fitTracks_; }
0051     /// Number of iterations
0052     unsigned int iterationsPerTrack() const { return double(iterations_) / double(fitTracks_.size()); }
0053     /// Storage for tracks out of the L1 Track finder
0054     unsigned int numInputTracks() const { return fitTracks_.size(); }
0055     /// Number of iterations
0056     unsigned int numIterations() const { return iterations_; }
0057     /// Number of reconstructed vertices
0058     unsigned int numVertices() const { return vertices_.size(); }
0059     /// Number of emulation vertices
0060     unsigned int numVerticesEmulation() const { return verticesEmulation_.size(); }
0061     /// Reconstructed primary vertex
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     /// Reconstructed Primary Vertex Id
0074     unsigned int primaryVertexId() const { return pv_index_; }
0075     /// Returns the z positions of the reconstructed primary vertices
0076     const std::vector<RecoVertex<>>& vertices() const { return vertices_; }
0077     /// Returns the emulation primary vertices
0078     const l1t::VertexWordCollection& verticesEmulation() const { return verticesEmulation_; }
0079 
0080     /// Find the primary vertex
0081     void findPrimaryVertex();
0082     /// Associate the primary vertex with the real one
0083     void associatePrimaryVertex(double trueZ0);
0084     /// Gap Clustering Algorithm
0085     void GapClustering();
0086     /// Find maximum distance in two clusters of tracks
0087     float maxDistance(RecoVertex<> cluster0, RecoVertex<> cluster1);
0088     /// Find minimum distance in two clusters of tracks
0089     float minDistance(RecoVertex<> cluster0, RecoVertex<> cluster1);
0090     /// Find average distance in two clusters of tracks
0091     float meanDistance(RecoVertex<> cluster0, RecoVertex<> cluster1);
0092     /// Find distance between centres of two clusters
0093     float centralDistance(RecoVertex<> cluster0, RecoVertex<> cluster1);
0094     /// Simple Merge Algorithm
0095     void agglomerativeHierarchicalClustering();
0096     /// Adaptive Vertex Reconstruction algorithm
0097     void adaptiveVertexReconstruction();
0098     /// High pT Vertex Algorithm
0099     void fastHistoLooseAssociation();
0100     /// Histogramming algorithm
0101     void fastHisto(const TrackerTopology* tTopo);
0102     /// Histogramming algorithm (emulation)
0103     void fastHistoEmulation();
0104     /// NNVtx algorithm
0105     void NNVtxEmulation(tensorflow::Session* TrackWeightSesh = nullptr,
0106                         tensorflow::Session* PatternRecSesh = nullptr,
0107                         tensorflow::Session* AssociationSesh = nullptr);
0108 
0109     /// Sort vertices in pT
0110     void sortVerticesInPt();
0111     /// Sort vertices in z
0112     void sortVerticesInZ0();
0113 
0114     /// Print an ASCII histogram
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     /// Vertexing algorithms
0133 
0134     /// Compute the vertex parameters
0135     void computeAndSetVertexParameters(RecoVertex<>& vertex,
0136                                        const std::vector<float>& bin_centers,
0137                                        const std::vector<unsigned int>& counts);
0138     /// DBSCAN algorithm
0139     void DBSCAN();
0140     /// High pT Vertex Algorithm
0141     void HPV();
0142     /// Kmeans Algorithm
0143     void Kmeans();
0144     /// Find maximum distance in two clusters of tracks
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 }  // end namespace l1tVertexFinder
0158 
0159 #endif