Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L1T vertex finder phase2 developments #37382

Merged
merged 5 commits into from Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions L1Trigger/VertexFinder/BuildFile.xml
@@ -1,3 +1,4 @@
<use name="CommonTools/UtilAlgos"/>
<use name="DataFormats/Common"/>
<use name="DataFormats/L1TrackTrigger"/>
<use name="DataFormats/L1Trigger"/>
Expand Down
31 changes: 20 additions & 11 deletions L1Trigger/VertexFinder/interface/AlgoSettings.h
Expand Up @@ -10,17 +10,20 @@
namespace l1tVertexFinder {

enum class Algorithm {
FastHisto,
FastHistoLooseAssociation,
fastHisto,
fastHistoEmulation,
fastHistoLooseAssociation,
GapClustering,
AgglomerativeHierarchical,
agglomerativeHierarchical,
DBSCAN,
PVR,
AdaptiveVertexReconstruction,
adaptiveVertexReconstruction,
HPV,
Kmeans
};

enum class Precision { Simulation, Emulation };

class AlgoSettings {
public:
AlgoSettings(const edm::ParameterSet& iConfig);
Expand All @@ -29,7 +32,8 @@ namespace l1tVertexFinder {
//=== Vertex Reconstruction configuration
// Vertex Reconstruction algo
Algorithm vx_algo() const { return vx_algo_; }
/// For Agglomerative cluster algorithm, select a definition of distance between clusters
Precision vx_precision() const { return vx_precision_; }
// For agglomerative cluster algorithm, select a definition of distance between clusters
unsigned int vx_distanceType() const { return vx_distanceType_; }
// Assumed Vertex Distance
float vx_distance() const { return vx_distance_; }
Expand All @@ -39,21 +43,23 @@ namespace l1tVertexFinder {
unsigned int vx_minTracks() const { return vx_minTracks_; }
// Compute the z0 position of the vertex with a mean weighted with track momenta
unsigned int vx_weightedmean() const { return vx_weightedmean_; }
/// Chi2 cut for the Adaptive Vertex Recostruction Algorithm
// Chi2 cut for the adaptive Vertex Recostruction Algorithm
float vx_chi2cut() const { return vx_chi2cut_; }
/// Window size of the sliding window
// Do track quality cuts in emulation algorithms
bool vx_DoQualityCuts() const { return vx_DoQualityCuts_; }
// Window size of the sliding window
unsigned int vx_windowSize() const { return vx_windowSize_; }
/// FastHisto histogram parameters (min, max, width)
// fastHisto histogram parameters (min, max, width)
std::vector<double> vx_histogram_parameters() const { return vx_histogram_parameters_; }
double vx_histogram_min() const { return vx_histogram_parameters_.at(0); }
double vx_histogram_max() const { return vx_histogram_parameters_.at(1); }
double vx_histogram_binwidth() const { return vx_histogram_parameters_.at(2); }
/// FastHisto assumed vertex width
// fastHisto assumed vertex width
float vx_width() const { return vx_width_; }
/// FastHisto track selection control
// fastHisto track selection control
bool vx_DoPtComp() const { return vx_DoPtComp_; }
bool vx_DoTightChi2() const { return vx_DoTightChi2_; }
/// Number of vertices to return for FastHisto
// Number of vertices to return for fastHisto
unsigned int vx_nvtx() const { return vx_nvtx_; }
float vx_dbscan_pt() const { return vx_dbscan_pt_; }
unsigned int vx_dbscan_mintracks() const { return vx_dbscan_mintracks_; }
Expand Down Expand Up @@ -82,18 +88,21 @@ namespace l1tVertexFinder {

private:
static const std::map<std::string, Algorithm> algoNameMap;
static const std::map<Algorithm, Precision> algoPrecisionMap;

// Parameter sets for differents types of configuration parameter.
edm::ParameterSet vertex_;

// Vertex Reconstruction configuration
Algorithm vx_algo_;
Precision vx_precision_;
float vx_distance_;
float vx_resolution_;
unsigned int vx_distanceType_;
unsigned int vx_minTracks_;
unsigned int vx_weightedmean_;
float vx_chi2cut_;
bool vx_DoQualityCuts_;
bool vx_DoPtComp_;
bool vx_DoTightChi2_;
std::vector<double> vx_histogram_parameters_;
Expand Down
12 changes: 12 additions & 0 deletions L1Trigger/VertexFinder/interface/RecoVertex.h
Expand Up @@ -69,6 +69,8 @@ namespace l1tVertexFinder {
unsigned int nHighPt = -999,
double highestPt = -999.,
bool pv = false);
/// Get the equivalent l1t::Vertex
l1t::Vertex vertex() const;
/// Vertex z0 position [cm]
double z0() const { return z0_; }
/// Vertex z0 width [cm]
Expand Down Expand Up @@ -151,6 +153,16 @@ namespace l1tVertexFinder {
pv_ = pv;
}

template <typename T>
l1t::Vertex RecoVertex<T>::vertex() const {
std::vector<edm::Ptr<l1t::Vertex::Track_t>> tracks;
tracks.reserve(tracks_.size());
for (const auto& t : tracks_) {
tracks.push_back(t->getTTTrackPtr());
}
return l1t::Vertex(pT_, z0_, tracks);
}

// Template specializations
template <>
RecoVertexWithTP& RecoVertexWithTP::operator+=(const RecoVertexWithTP& rhs);
Expand Down
76 changes: 36 additions & 40 deletions L1Trigger/VertexFinder/interface/VertexFinder.h
Expand Up @@ -2,9 +2,9 @@
#define __L1Trigger_VertexFinder_VertexFinder_h__

#include "DataFormats/Common/interface/Ptr.h"
#include "DataFormats/L1Trigger/interface/VertexWord.h"
#include "DataFormats/Math/interface/deltaPhi.h"
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "L1Trigger/VertexFinder/interface/AlgoSettings.h"
#include "L1Trigger/VertexFinder/interface/RecoVertex.h"
Expand All @@ -15,6 +15,9 @@

namespace l1tVertexFinder {

// Returns the number of bits needed to represent and integer decimal
static constexpr unsigned BitsToRepresent(unsigned x) { return x < 2 ? 1 : 1 + BitsToRepresent(x >> 1); }

typedef std::vector<L1Track> FitTrackCollection;
typedef std::vector<RecoVertex<>> RecoVertexCollection;

Expand All @@ -40,29 +43,36 @@ namespace l1tVertexFinder {

/// Accessors

/// Storage for tracks out of the L1 Track finder
const FitTrackCollection& fitTracks() const { return fitTracks_; }
/// Number of iterations
unsigned int IterationsPerTrack() const { return double(iterations_) / double(fitTracks_.size()); }
unsigned int iterationsPerTrack() const { return double(iterations_) / double(fitTracks_.size()); }
/// Storage for tracks out of the L1 Track finder
unsigned int numInputTracks() const { return fitTracks_.size(); }
/// Number of iterations
unsigned int NumIterations() const { return iterations_; }
unsigned int numIterations() const { return iterations_; }
/// Number of reconstructed vertices
unsigned int numVertices() const { return vertices_.size(); }
/// Reconstructed Primary Vertex
RecoVertex<> primaryVertex() const {
if (pv_index_ < vertices_.size())
/// Number of emulation vertices
unsigned int numVerticesEmulation() const { return verticesEmulation_.size(); }
/// Reconstructed primary vertex
template <typename T>
T PrimaryVertex() const {
if ((settings_->vx_precision() == Precision::Simulation) && (pv_index_ < vertices_.size()))
return vertices_[pv_index_];
else if ((settings_->vx_precision() == Precision::Emulation) && (pv_index_ < vertices_.size()))
return verticesEmulation_[pv_index_];
else {
edm::LogWarning("VertexFinder") << "PrimaryVertex::No Primary Vertex has been found.";
edm::LogWarning("VertexFinder") << "PrimaryVertex::No primary vertex has been found.";
return RecoVertex<>();
}
}
/// Reconstructed Primary Vertex Id
unsigned int primaryVertexId() const { return pv_index_; }
/// Returns the z positions of the reconstructed primary vertices
const std::vector<RecoVertex<>>& vertices() const { return vertices_; }
/// Storage for tracks out of the L1 Track finder
const FitTrackCollection& fitTracks() const { return fitTracks_; }
/// Returns the emulation primary vertices
const l1t::VertexWordCollection& verticesEmulation() const { return verticesEmulation_; }

/// Find the primary vertex
void findPrimaryVertex();
Expand All @@ -86,22 +96,23 @@ namespace l1tVertexFinder {
void fastHistoLooseAssociation();
/// Histogramming algorithm
void fastHisto(const TrackerTopology* tTopo);
/// Histogramming algorithm (emulation)
void fastHistoEmulation();

/// Sort vertices in pT
void SortVerticesInPt() {
std::sort(vertices_.begin(), vertices_.end(), [](const RecoVertex<>& vertex0, const RecoVertex<>& vertex1) {
return (vertex0.pt() > vertex1.pt());
});
}
void sortVerticesInPt();
/// Sort vertices in z
void SortVerticesInZ0() {
std::sort(vertices_.begin(), vertices_.end(), [](const RecoVertex<>& vertex0, const RecoVertex<>& vertex1) {
return (vertex0.z0() < vertex1.z0());
});
}
/// Number of iterations
unsigned int numIterations() const { return iterations_; }
/// Number of iterations
unsigned int iterationsPerTrack() const { return double(iterations_) / double(fitTracks_.size()); }
void sortVerticesInZ0();

/// Print an ASCII histogram
template <class data_type, typename stream_type = std::ostream>
void printHistogram(stream_type& stream,
std::vector<data_type> data,
int width = 80,
int minimum = 0,
int maximum = -1,
std::string title = "",
std::string color = "");

template <typename ForwardIterator, typename T>
void strided_iota(ForwardIterator first, ForwardIterator last, T value, T stride) {
Expand All @@ -113,38 +124,23 @@ namespace l1tVertexFinder {

/// Vertexing algorithms

/// Adaptive Vertex Reconstruction algorithm
void AdaptiveVertexReconstruction();
/// Simple Merge Algorithm
void AgglomerativeHierarchicalClustering();
/// Find distance between centres of two clusters
float CentralDistance(RecoVertex<> cluster0, RecoVertex<> cluster1);
/// Compute the vertex parameters
void computeAndSetVertexParameters(RecoVertex<>& vertex,
const std::vector<float>& bin_centers,
const std::vector<unsigned int>& counts);
/// DBSCAN algorithm
void DBSCAN();
/// TDR histogramming algorithmn
void FastHistoLooseAssociation();
/// Histogramming algorithm
void FastHisto(const TrackerTopology* tTopo);
/// High pT Vertex Algorithm
void HPV();
/// Kmeans Algorithm
void Kmeans();
/// Find maximum distance in two clusters of tracks
float MaxDistance(RecoVertex<> cluster0, RecoVertex<> cluster1);
/// Find minimum distance in two clusters of tracks
float MinDistance(RecoVertex<> cluster0, RecoVertex<> cluster1);
/// Find average distance in two clusters of tracks
float MeanDistance(RecoVertex<> cluster0, RecoVertex<> cluster1);
/// Principal Vertex Reconstructor algorithm
void PVR();

private:
const AlgoSettings* settings_;
std::vector<RecoVertex<>> vertices_;
RecoVertexCollection vertices_;
l1t::VertexWordCollection verticesEmulation_;
unsigned int numMatchedVertices_;
FitTrackCollection fitTracks_;
unsigned int pv_index_;
Expand Down
5 changes: 4 additions & 1 deletion L1Trigger/VertexFinder/interface/VertexProducer.h
Expand Up @@ -3,6 +3,8 @@

#include "DataFormats/L1Trigger/interface/Vertex.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
#include "DataFormats/L1Trigger/interface/VertexWord.h"
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
Expand All @@ -13,6 +15,7 @@
#include "Geometry/Records/interface/TrackerTopologyRcd.h"
#include "L1Trigger/VertexFinder/interface/AlgoSettings.h"
#include "L1Trigger/VertexFinder/interface/RecoVertex.h"
#include "L1Trigger/VertexFinder/interface/VertexFinder.h"

#include <iostream>
#include <map>
Expand All @@ -36,7 +39,7 @@ class VertexProducer : public edm::global::EDProducer<> {

private:
const edm::EDGetTokenT<TTTrackCollectionView> l1TracksToken_;
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> trackerTopologyToken_;
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken;
const std::string outputCollectionName_;

l1tVertexFinder::AlgoSettings settings_;
Expand Down
1 change: 0 additions & 1 deletion L1Trigger/VertexFinder/plugins/TPStubValueMapProducer.cc
Expand Up @@ -77,7 +77,6 @@ class TPStubValueMapProducer : public edm::global::EDProducer<> {
const edm::EDGetTokenT<DetSetVec> stubToken_;
const edm::EDGetTokenT<TTStubAssMap> stubTruthToken_;
const edm::EDGetTokenT<TTClusterAssMap> clusterTruthToken_;

edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tGeomToken_;
};
Expand Down