Back to home page

Project CMSSW displayed by LXR

 
 

    


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