CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
VertexProducer.cc
Go to the documentation of this file.
14 
15 using namespace l1tVertexFinder;
16 using namespace std;
17 
19  : l1TracksToken_(consumes<TTTrackRefCollectionType>(iConfig.getParameter<edm::InputTag>("l1TracksInputTag"))),
21  outputCollectionName_(iConfig.getParameter<std::string>("l1VertexCollectionName")),
22  settings_(AlgoSettings(iConfig)) {
23  // Get configuration parameters
24 
25  switch (settings_.vx_algo()) {
26  case Algorithm::fastHisto:
27  edm::LogInfo("VertexProducer") << "VertexProducer::Finding vertices using the fastHisto binning algorithm";
28  break;
29  case Algorithm::fastHistoEmulation:
30  edm::LogInfo("VertexProducer")
31  << "VertexProducer::Finding vertices using the emulation version of the fastHisto binning algorithm";
32  break;
33  case Algorithm::fastHistoLooseAssociation:
34  edm::LogInfo("VertexProducer")
35  << "VertexProducer::Finding vertices using the fastHistoLooseAssociation binning algorithm";
36  break;
37  case Algorithm::GapClustering:
38  edm::LogInfo("VertexProducer") << "VertexProducer::Finding vertices using a gap clustering algorithm";
39  break;
40  case Algorithm::agglomerativeHierarchical:
41  edm::LogInfo("VertexProducer") << "VertexProducer::Finding vertices using a Simple Merge Clustering algorithm";
42  break;
43  case Algorithm::DBSCAN:
44  edm::LogInfo("VertexProducer") << "VertexProducer::Finding vertices using a DBSCAN algorithm";
45  break;
46  case Algorithm::PVR:
47  edm::LogInfo("VertexProducer") << "VertexProducer::Finding vertices using a PVR algorithm";
48  break;
49  case Algorithm::adaptiveVertexReconstruction:
50  edm::LogInfo("VertexProducer")
51  << "VertexProducer::Finding vertices using an AdaptiveVertexReconstruction algorithm";
52  break;
53  case Algorithm::HPV:
54  edm::LogInfo("VertexProducer") << "VertexProducer::Finding vertices using a Highest Pt Vertex algorithm";
55  break;
56  case Algorithm::Kmeans:
57  edm::LogInfo("VertexProducer") << "VertexProducer::Finding vertices using a kmeans algorithm";
58  break;
59  case Algorithm::NNEmulation:
60  edm::LogInfo("VertexProducer") << "VertexProducer::Finding vertices using the Neural Network Emulation";
61  break;
62  }
63 
64  //--- Define EDM output to be written to file (if required)
65  if (settings_.vx_algo() == Algorithm::fastHistoEmulation || settings_.vx_algo() == Algorithm::NNEmulation) {
66  produces<l1t::VertexWordCollection>(outputCollectionName_ + "Emulation");
67  } else {
68  produces<l1t::VertexCollection>(outputCollectionName_);
69  }
70 
71  if (settings_.vx_algo() == Algorithm::NNEmulation) {
72  // load graphs, create a new session and add the graphDef
73  if (settings_.debug() > 1) {
74  edm::LogInfo("VertexProducer") << "loading TrkWeight graph from " << settings_.vx_trkw_graph() << std::endl;
75  edm::LogInfo("VertexProducer") << "loading PatternRec graph from " << settings_.vx_pattrec_graph() << std::endl;
76  }
81  }
82 }
83 
86  iEvent.getByToken(l1TracksToken_, l1TracksHandle);
87 
88  std::vector<l1tVertexFinder::L1Track> l1Tracks;
89  l1Tracks.reserve(l1TracksHandle->size());
90  if (settings_.debug() > 1) {
91  edm::LogInfo("VertexProducer") << "produce::Processing " << l1TracksHandle->size() << " tracks";
92  }
93  for (const auto& track : *l1TracksHandle) {
94  auto l1track = L1Track(edm::refToPtr(track));
95  if (l1track.pt() >= settings_.vx_TrackMinPt()) {
96  l1Tracks.push_back(l1track);
97  } else {
98  if (settings_.debug() > 2) {
99  edm::LogInfo("VertexProducer") << "produce::Removing track with too low of a pt (" << l1track.pt() << ")\n"
100  << " word = " << l1track.getTTTrackPtr()->getTrackWord().to_string(2);
101  }
102  }
103  }
104 
105  if (settings_.debug() > 1) {
106  edm::LogInfo("VertexProducer") << "produce::Processing " << l1Tracks.size() << " tracks after minimum pt cut of"
107  << settings_.vx_TrackMinPt() << " GeV";
108  }
109 
111 
112  switch (settings_.vx_algo()) {
113  case Algorithm::fastHisto: {
114  const TrackerTopology& tTopo = iSetup.getData(tTopoToken);
115  vf.fastHisto(&tTopo);
116  break;
117  }
118  case Algorithm::fastHistoEmulation:
119  vf.fastHistoEmulation();
120  break;
121  case Algorithm::fastHistoLooseAssociation:
123  break;
124  case Algorithm::GapClustering:
125  vf.GapClustering();
126  break;
127  case Algorithm::agglomerativeHierarchical:
129  break;
130  case Algorithm::DBSCAN:
131  vf.DBSCAN();
132  break;
133  case Algorithm::PVR:
134  vf.PVR();
135  break;
136  case Algorithm::adaptiveVertexReconstruction:
138  break;
139  case Algorithm::HPV:
140  vf.HPV();
141  break;
142  case Algorithm::Kmeans:
143  vf.Kmeans();
144  break;
145  case Algorithm::NNEmulation:
147  break;
148  }
149 
150  vf.sortVerticesInPt();
151  vf.findPrimaryVertex();
152 
153  // //=== Store output EDM track and hardware stub collections.
154  if (settings_.vx_algo() == Algorithm::fastHistoEmulation || settings_.vx_algo() == Algorithm::NNEmulation) {
155  std::unique_ptr<l1t::VertexWordCollection> product_emulation =
156  std::make_unique<l1t::VertexWordCollection>(vf.verticesEmulation().begin(), vf.verticesEmulation().end());
157  iEvent.put(std::move(product_emulation), outputCollectionName_ + "Emulation");
158  } else {
159  std::unique_ptr<l1t::VertexCollection> product(new std::vector<l1t::Vertex>());
160  for (const auto& vtx : vf.vertices()) {
161  product->emplace_back(vtx.vertex());
162  }
163  iEvent.put(std::move(product), outputCollectionName_);
164  }
165 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
tensorflow::GraphDef * TrkWGraph_
void fastHistoLooseAssociation()
High pT Vertex Algorithm.
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
void GapClustering()
Gap Clustering Algorithm.
Definition: VertexFinder.cc:65
GraphDef * loadGraphDef(const std::string &pbFile)
Definition: TensorFlow.cc:119
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken
void NNVtxEmulation(tensorflow::Session *TrackWeightSesh=nullptr, tensorflow::Session *PatternRecSesh=nullptr, tensorflow::Session *AssociationSesh=nullptr)
NNVtx algorithm.
tensorflow::Session * TrkWSesh_
void agglomerativeHierarchicalClustering()
Simple Merge Algorithm.
const edm::EDGetTokenT< TTTrackRefCollectionType > l1TracksToken_
const std::string outputCollectionName_
unsigned int debug() const
Definition: AlgoSettings.h:86
void adaptiveVertexReconstruction()
Adaptive Vertex Reconstruction algorithm.
int iEvent
Definition: GenABIO.cc:224
void findPrimaryVertex()
Find the primary vertex.
void fastHisto(const TrackerTopology *tTopo)
Histogramming algorithm.
const std::vector< RecoVertex<> > & vertices() const
Returns the z positions of the reconstructed primary vertices.
Definition: VertexFinder.h:76
std::string vx_trkw_graph() const
Definition: AlgoSettings.h:82
std::string vx_pattrec_graph() const
Definition: AlgoSettings.h:83
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void sortVerticesInPt()
Sort vertices in pT.
VertexProducer(const edm::ParameterSet &)
tensorflow::GraphDef * PattRecGraph_
Session * createSession()
Definition: TensorFlow.cc:136
Log< level::Info, false > LogInfo
void PVR()
Find maximum distance in two clusters of tracks.
tensorflow::Session * PattRecSesh_
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
void fastHistoEmulation()
Histogramming algorithm (emulation)
void HPV()
High pT Vertex Algorithm.
TTTrack< Ref_Phase2TrackerDigi_ > L1Track
Definition: L1Track.h:8
HLT enums.
void Kmeans()
Kmeans Algorithm.
const l1t::VertexWordCollection & verticesEmulation() const
Returns the emulation primary vertices.
Definition: VertexFinder.h:78
Algorithm vx_algo() const
Definition: AlgoSettings.h:36
void DBSCAN()
DBSCAN algorithm.
def move(src, dest)
Definition: eostools.py:511
l1tVertexFinder::AlgoSettings settings_