CMS 3D CMS Logo

L1TrackVertexAssociationProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/L1TTrackMatch
4 // Class: L1TrackVertexAssociationProducer
5 //
18 //
19 // Original Author: Alexx Perloff
20 // Created: Thu, 16 Dec 2021 19:02:50 GMT
21 // Derivative Author: Nick Manganelli
22 // Created: Thu, 14 Oct 2023 16:32:32 GMT
23 //
24 //
25 
26 // system include files
27 #include <algorithm>
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 // Xilinx HLS includes
33 #include <ap_fixed.h>
34 #include <ap_int.h>
35 
36 // user include files
68 
69 //
70 // class declaration
71 //
72 
74 public:
77 
78  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
79 
80 private:
81  // ----------constants, enums and typedefs ---------
82  // Relevant constants for the converted track word
84  kPtSize = TTTrack_TrackWord::TrackBitWidths::kRinvSize - 1, // Width of pt
85  kPtMagSize = 9, // Width of pt magnitude (unsigned)
86  kEtaSize = TTTrack_TrackWord::TrackBitWidths::kTanlSize, // Width of eta
87  kEtaMagSize = 3, // Width of eta magnitude (signed)
88  };
89 
91  typedef std::vector<TTTrackType> TTTrackCollectionType;
94  typedef std::unique_ptr<TTTrackRefCollectionType> TTTrackRefCollectionUPtr;
95 
96  // ----------member functions ----------------------
97  void printDebugInfo(const edm::Handle<TTTrackRefCollectionType>& l1SelectedTracksHandle,
98  const edm::Handle<TTTrackRefCollectionType>& l1SelectedTracksEmulationHandle,
99  const TTTrackRefCollectionUPtr& vTTTrackAssociatedOutput,
100  const TTTrackRefCollectionUPtr& vTTTrackAssociatedEmulationOutput) const;
101  void printTrackInfo(edm::LogInfo& log, const TTTrackType& track, bool printEmulation = false) const;
102  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
103 
104  // ----------selectors -----------------------------
105  // Based on recommendations from https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideGenericSelectors
107  TTTrackDeltaZMaxSelector(const std::vector<double>& deltaZMaxEtaBounds, const std::vector<double>& deltaZMax)
110  : deltaZMaxEtaBounds_(cfg.template getParameter<double>("deltaZMaxEtaBounds")),
111  deltaZMax_(cfg.template getParameter<double>("deltaZMax")) {}
112  bool operator()(const TTTrackType& t, const l1t::Vertex& v) const {
113  size_t etaIndex =
114  std::upper_bound(deltaZMaxEtaBounds_.begin(), deltaZMaxEtaBounds_.end(), std::abs(t.momentum().eta())) -
115  deltaZMaxEtaBounds_.begin() - 1;
116  if (etaIndex > deltaZMax_.size() - 1)
117  etaIndex = deltaZMax_.size() - 1;
118  return std::abs(v.z0() - t.z0()) <= deltaZMax_[etaIndex];
119  }
120 
121  private:
122  std::vector<double> deltaZMaxEtaBounds_;
123  std::vector<double> deltaZMax_;
124  };
126  TTTrackWordDeltaZMaxSelector(const std::vector<double>& deltaZMaxEtaBounds, const std::vector<double>& deltaZMax)
129  : deltaZMaxEtaBounds_(cfg.template getParameter<double>("deltaZMaxEtaBounds")),
130  deltaZMax_(cfg.template getParameter<double>("deltaZMax")) {}
131  bool operator()(const TTTrackType& t, const l1t::VertexWord& v) const {
132  TTTrack_TrackWord::tanl_t etaEmulationBits = t.getTanlWord();
133  ap_fixed<TrackBitWidths::kEtaSize, TrackBitWidths::kEtaMagSize> etaEmulation;
134  etaEmulation.V = etaEmulationBits.range();
135  size_t etaIndex =
136  std::upper_bound(deltaZMaxEtaBounds_.begin(), deltaZMaxEtaBounds_.end(), std::abs(etaEmulation.to_double())) -
137  deltaZMaxEtaBounds_.begin() - 1;
138  if (etaIndex > deltaZMax_.size() - 1)
139  etaIndex = deltaZMax_.size() - 1;
140  l1t::VertexWord::vtxz0_t fixedTkZ0 = t.undigitizeSignedValue(
141  t.getZ0Bits(), TTTrack_TrackWord::TrackBitWidths::kZ0Size, TTTrack_TrackWord::stepZ0, 0.0);
142 
143  ap_uint<TrackBitWidths::kPtSize> ptEmulationBits = t.getTrackWord()(
144  TTTrack_TrackWord::TrackBitLocations::kRinvMSB - 1, TTTrack_TrackWord::TrackBitLocations::kRinvLSB);
145  ap_ufixed<TrackBitWidths::kPtSize, TrackBitWidths::kPtMagSize> ptEmulation;
146  ptEmulation.V = ptEmulationBits.range();
147  return std::abs(v.z0() - fixedTkZ0.to_double()) <= deltaZMax_[etaIndex];
148  }
149 
150  private:
151  std::vector<double> deltaZMaxEtaBounds_;
152  std::vector<double> deltaZMax_;
153  };
154 
156  NNTrackWordSelector(tensorflow::Session* AssociationSesh,
157  const double AssociationThreshold,
158  const std::vector<double>& AssociationNetworkZ0binning,
159  const std::vector<double>& AssociationNetworkEtaBounds,
160  const std::vector<double>& AssociationNetworkZ0ResBins)
161  : AssociationSesh_(AssociationSesh),
162  AssociationThreshold_(AssociationThreshold),
163  z0_binning_(AssociationNetworkZ0binning),
164  eta_bins_(AssociationNetworkEtaBounds),
165  res_bins_(AssociationNetworkZ0ResBins) {}
166 
167  bool operator()(const TTTrackType& t, const l1t::VertexWord& v) const {
168  tensorflow::Tensor inputAssoc(tensorflow::DT_FLOAT, {1, 4});
169  std::vector<tensorflow::Tensor> outputAssoc;
170 
171  TTTrack_TrackWord::tanl_t etaEmulationBits = t.getTanlWord();
172  ap_fixed<16, 3> etaEmulation;
173  etaEmulation.V = (etaEmulationBits.range());
174 
175  auto lower = std::lower_bound(eta_bins_.begin(), eta_bins_.end(), etaEmulation.to_double());
176 
177  int resbin = std::distance(eta_bins_.begin(), lower);
178  float binWidth = z0_binning_[2];
179  // Calculate integer dZ from track z0 and vertex z0 (use floating point version and convert internally allowing use of both emulator and simulator vertex and track)
180  float dZ =
181  abs(floor(((t.getZ0() + z0_binning_[1]) / (binWidth))) - floor(((v.z0() + z0_binning_[1]) / (binWidth))));
182 
183  // The following constants <14, 9>, <22, 9> are defined by the quantisation of the Neural Network
184  ap_uint<14> ptEmulationBits = t.getTrackWord()(TTTrack_TrackWord::TrackBitLocations::kRinvMSB - 1,
185  TTTrack_TrackWord::TrackBitLocations::kRinvLSB);
186  ap_ufixed<14, 9> ptEmulation;
187  ptEmulation.V = (ptEmulationBits.range());
188 
189  ap_ufixed<22, 9> ptEmulation_rescale;
190  ptEmulation_rescale = ptEmulation.to_double();
191 
192  ap_ufixed<22, 9> resBinEmulation_rescale;
193  resBinEmulation_rescale = res_bins_[resbin];
194 
195  ap_ufixed<22, 9> MVAEmulation_rescale;
196  MVAEmulation_rescale = t.getMVAQualityBits();
197 
198  ap_ufixed<22, 9> dZEmulation_rescale;
199  dZEmulation_rescale = dZ;
200 
201  inputAssoc.tensor<float, 2>()(0, 0) = ptEmulation_rescale.to_double();
202  inputAssoc.tensor<float, 2>()(0, 1) = MVAEmulation_rescale.to_double();
203  inputAssoc.tensor<float, 2>()(0, 2) = resBinEmulation_rescale.to_double() / 16.0;
204  inputAssoc.tensor<float, 2>()(0, 3) = dZEmulation_rescale.to_double();
205 
206  // Run Association Network:
207  tensorflow::run(AssociationSesh_, {{"assoc:0", inputAssoc}}, {"Identity:0"}, &outputAssoc);
208 
209  double NNOutput = (double)outputAssoc[0].tensor<float, 2>()(0, 0);
210 
211  double NNOutput_exp = 1.0 / (1.0 + exp(-1.0 * (NNOutput)));
212 
213  return NNOutput_exp >= AssociationThreshold_;
214  }
215 
216  private:
217  tensorflow::Session* AssociationSesh_;
219  std::vector<double> z0_binning_;
220  std::vector<double> eta_bins_;
221  std::vector<double> res_bins_;
222  };
223 
226  //create a counter for all 18 GTT input links, 2 per phiSector of the TrackFindingProcessors
227  for (int idx = 0; idx < 18; idx++) {
228  processedTracksPerLink_.push_back(0);
229  truncatedTracksPerLink_.push_back(0);
230  }
231  }
233  : fwNTrackSetsTVA_(cfg.template getParameter<unsigned int>("fwNTrackSetsTVA")) {
234  for (int idx = 0; idx < 18; idx++) {
235  processedTracksPerLink_.push_back(0);
236  }
237  }
238  bool operator()(const TTTrackType& t) {
239  unsigned int gttLinkID = l1t::demo::codecs::gttLinkID(t);
240  //increment the counter of processed tracks
242  //fwNTrackSetsTVA_ tracks may be processed in firmware, no more (<= used intentionally to match the off-by-one indexing versus LibHLS)
243  if ((processedTracksPerLink_[gttLinkID] > fwNTrackSetsTVA_) && (t.getValidWord()))
246  }
247  void log() {
248  edm::LogInfo log("L1TrackVertexAssociationProducer");
249  log << "Processed track link counters:\t[";
250  for (int idx = 0; idx < 18; idx++) {
251  if (idx > 0)
252  log << ", ";
254  }
255  log << "]\n";
256  log << "Truncated track link counters:\t[";
257  for (int idx = 0; idx < 18; idx++) {
258  if (idx > 0)
259  log << ", ";
261  }
262  log << "]\n";
263  }
264 
265  private:
266  unsigned int fwNTrackSetsTVA_;
267  std::vector<unsigned int> processedTracksPerLink_;
268  std::vector<unsigned int> truncatedTracksPerLink_;
269  };
270 
271  // ----------member data ---------------------------
280  std::vector<double> deltaZMaxEtaBounds_, deltaZMax_;
282  // corresponds to N_TRACK_SETS_TVA in LibHLS https://gitlab.cern.ch/GTT/LibHLS/-/blob/master/DataFormats/Track/interface/TrackConstants.h
283  const unsigned int fwNTrackSetsTVA_;
284 
285  //NNVtx:
287  const double associationThreshold_;
289  tensorflow::GraphDef* associationGraph_;
290  tensorflow::Session* associationSesh_;
292 
293  int debug_;
294 };
295 
296 //
297 // constructors and destructor
298 //
300  : processSimulatedTracks_(iConfig.getParameter<bool>("processSimulatedTracks")),
301  processEmulatedTracks_(iConfig.getParameter<bool>("processEmulatedTracks")),
302  l1TracksToken_(consumes<TTTrackCollectionType>(iConfig.getParameter<edm::InputTag>("l1TracksInputTag"))),
303  l1VerticesToken_(processSimulatedTracks_
304  ? consumes<l1t::VertexCollection>(iConfig.getParameter<edm::InputTag>("l1VerticesInputTag"))
305  : edm::EDGetTokenT<l1t::VertexCollection>()),
306  l1SelectedTracksToken_(
307  processSimulatedTracks_
308  ? consumes<TTTrackRefCollectionType>(iConfig.getParameter<edm::InputTag>("l1SelectedTracksInputTag"))
309  : edm::EDGetTokenT<TTTrackRefCollectionType>()),
310  l1VerticesEmulationToken_(
311  processEmulatedTracks_
312  ? consumes<l1t::VertexWordCollection>(iConfig.getParameter<edm::InputTag>("l1VerticesEmulationInputTag"))
313  : edm::EDGetTokenT<l1t::VertexWordCollection>()),
314  l1SelectedTracksEmulationToken_(processEmulatedTracks_
315  ? consumes<TTTrackRefCollectionType>(iConfig.getParameter<edm::InputTag>(
316  "l1SelectedTracksEmulationInputTag"))
317  : edm::EDGetTokenT<TTTrackRefCollectionType>()),
318  outputCollectionName_(iConfig.getParameter<std::string>("outputCollectionName")),
319  cutSet_(iConfig.getParameter<edm::ParameterSet>("cutSet")),
320 
321  deltaZMaxEtaBounds_(cutSet_.getParameter<std::vector<double>>("deltaZMaxEtaBounds")),
322  deltaZMax_(cutSet_.getParameter<std::vector<double>>("deltaZMax")),
323  useDisplacedTracksDeltaZOverride_(iConfig.getParameter<double>("useDisplacedTracksDeltaZOverride")),
324  fwNTrackSetsTVA_(iConfig.getParameter<unsigned int>("fwNTrackSetsTVA")),
325  associationThreshold_(iConfig.getParameter<double>("associationThreshold")),
326  useAssociationNetwork_(iConfig.getParameter<bool>("useAssociationNetwork")),
327  associationNetworkZ0binning_(iConfig.getParameter<std::vector<double>>("associationNetworkZ0binning")),
328  associationNetworkEtaBounds_(iConfig.getParameter<std::vector<double>>("associationNetworkEtaBounds")),
329  associationNetworkZ0ResBins_(iConfig.getParameter<std::vector<double>>("associationNetworkZ0ResBins")),
330  debug_(iConfig.getParameter<int>("debug")) {
332  associationGraphPath_ = iConfig.getParameter<edm::FileInPath>("associationGraph");
335  }
336  // Confirm the the configuration makes sense
338  throw cms::Exception("You must process at least one of the track collections (simulated or emulated).");
339  }
340 
341  if (deltaZMax_.size() != deltaZMaxEtaBounds_.size() - 1) {
342  throw cms::Exception("The number of deltaZ cuts does not match the number of eta bins!");
343  }
344 
346  deltaZMax_ = std::vector<double>(deltaZMax_.size(), useDisplacedTracksDeltaZOverride_);
347  }
348 
349  // Get additional input tags and define the EDM output based on the previous configuration parameters
351  produces<TTTrackRefCollectionType>(outputCollectionName_);
353  produces<TTTrackRefCollectionType>(outputCollectionName_ + "Emulation");
354 }
355 
357 
358 //
359 // member functions
360 //
361 
363  const edm::Handle<TTTrackRefCollectionType>& l1SelectedTracksHandle,
364  const edm::Handle<TTTrackRefCollectionType>& l1SelectedTracksEmulationHandle,
365  const TTTrackRefCollectionUPtr& vTTTrackAssociatedOutput,
366  const TTTrackRefCollectionUPtr& vTTTrackAssociatedEmulationOutput) const {
367  edm::LogInfo log("L1TrackVertexAssociationProducer");
369  log << "The original selected track collection (pt, eta, phi, nstub, bendchi2, chi2rz, chi2rphi, z0) values are "
370  "... \n";
371  for (const auto& track : *l1SelectedTracksHandle) {
372  printTrackInfo(log, *track, debug_ >= 4);
373  }
374  log << "\t---\n\tNumber of tracks in this selection = " << l1SelectedTracksHandle->size() << "\n\n";
375  }
377  log << "The original selected emulated track collection (pt, eta, phi, nstub, bendchi2, chi2rz, chi2rphi, z0) "
378  "values are ... \n";
379  for (const auto& track : *l1SelectedTracksEmulationHandle) {
380  printTrackInfo(log, *track, debug_ >= 4);
381  }
382  log << "\t---\n\tNumber of tracks in this selection = " << l1SelectedTracksEmulationHandle->size() << "\n\n";
383  }
385  TTTrackRefCollectionType inSimButNotEmu;
386  TTTrackRefCollectionType inEmuButNotSim;
387  std::set_difference(l1SelectedTracksHandle->begin(),
388  l1SelectedTracksHandle->end(),
389  l1SelectedTracksEmulationHandle->begin(),
390  l1SelectedTracksEmulationHandle->end(),
391  std::back_inserter(inSimButNotEmu));
392  std::set_difference(l1SelectedTracksEmulationHandle->begin(),
393  l1SelectedTracksEmulationHandle->end(),
394  l1SelectedTracksHandle->begin(),
395  l1SelectedTracksHandle->end(),
396  std::back_inserter(inEmuButNotSim));
397  log << "The set of tracks selected via cuts on the simulated values which are not in the set of tracks selected "
398  "by cutting on the emulated values ... \n";
399  for (const auto& track : inSimButNotEmu) {
400  printTrackInfo(log, *track, debug_ >= 3);
401  }
402  log << "\t---\n\tNumber of tracks in this selection = " << inSimButNotEmu.size() << "\n\n"
403  << "The set of tracks selected via cuts on the emulated values which are not in the set of tracks selected "
404  "by cutting on the simulated values ... \n";
405  for (const auto& track : inEmuButNotSim) {
406  printTrackInfo(log, *track, debug_ >= 3);
407  }
408  log << "\t---\n\tNumber of tracks in this selection = " << inEmuButNotSim.size() << "\n\n";
409  }
411  log << "The selected and leading vertex associated track collection (pt, eta, phi, nstub, bendchi2, chi2rz, "
412  "chi2rphi, z0) values are ... \n";
413  for (const auto& track : *vTTTrackAssociatedOutput) {
414  printTrackInfo(log, *track, debug_ >= 4);
415  }
416  log << "\t---\n\tNumber of tracks in this selection = " << vTTTrackAssociatedOutput->size() << "\n\n";
417  }
419  log << "The emulation selected and leading vertex associated track collection (pt, eta, phi, nstub, bendchi2, "
420  "chi2rz, chi2rphi, z0) values are "
421  "... \n";
422  for (const auto& track : *vTTTrackAssociatedEmulationOutput) {
423  printTrackInfo(log, *track, debug_ >= 4);
424  }
425  log << "\t---\n\tNumber of tracks in this selection = " << vTTTrackAssociatedEmulationOutput->size() << "\n\n";
426  }
428  TTTrackRefCollectionType inSimButNotEmu;
429  TTTrackRefCollectionType inEmuButNotSim;
430  std::set_difference(vTTTrackAssociatedOutput->begin(),
431  vTTTrackAssociatedOutput->end(),
432  vTTTrackAssociatedEmulationOutput->begin(),
433  vTTTrackAssociatedEmulationOutput->end(),
434  std::back_inserter(inSimButNotEmu));
435  std::set_difference(vTTTrackAssociatedEmulationOutput->begin(),
436  vTTTrackAssociatedEmulationOutput->end(),
437  vTTTrackAssociatedOutput->begin(),
438  vTTTrackAssociatedOutput->end(),
439  std::back_inserter(inEmuButNotSim));
440  log << "The set of vertex associated tracks selected via cuts on the simulated values which are not in the set of "
441  "tracks selected "
442  "by cutting on the emulated values ... \n";
443  for (const auto& track : inSimButNotEmu) {
444  printTrackInfo(log, *track, debug_ >= 3);
445  }
446  log << "\t---\n\tNumber of tracks in this selection = " << inSimButNotEmu.size() << "\n\n"
447  << "The set of vertex associated tracks selected via cuts on the emulated values which are not in the set of "
448  "tracks selected "
449  "by cutting on the simulated values ... \n";
450  for (const auto& track : inEmuButNotSim) {
451  printTrackInfo(log, *track, debug_ >= 3);
452  }
453  log << "\t---\n\tNumber of tracks in this selection = " << inEmuButNotSim.size() << "\n\n";
454  }
455 }
456 
458  const TTTrackType& track,
459  bool printEmulation) const {
460  log << "\t(" << track.momentum().perp() << ", " << track.momentum().eta() << ", " << track.momentum().phi() << ", "
461  << track.getStubRefs().size() << ", " << track.stubPtConsistency() << ", " << track.chi2ZRed() << ", "
462  << track.chi2XYRed() << ", " << track.z0() << ")\n";
463 
464  if (printEmulation) {
465  ap_uint<TrackBitWidths::kPtSize> ptEmulationBits = track.getTrackWord()(
466  TTTrack_TrackWord::TrackBitLocations::kRinvMSB - 1, TTTrack_TrackWord::TrackBitLocations::kRinvLSB);
467  ap_ufixed<TrackBitWidths::kPtSize, TrackBitWidths::kPtMagSize> ptEmulation;
468  ptEmulation.V = ptEmulationBits.range();
469  TTTrack_TrackWord::tanl_t etaEmulationBits = track.getTanlWord();
470  ap_fixed<TrackBitWidths::kEtaSize, TrackBitWidths::kEtaMagSize> etaEmulation;
471  etaEmulation.V = etaEmulationBits.range();
472  double floatTkZ0 = track.undigitizeSignedValue(
473  track.getZ0Bits(), TTTrack_TrackWord::TrackBitWidths::kZ0Size, TTTrack_TrackWord::stepZ0, 0.0);
474  double floatTkPhi = track.undigitizeSignedValue(
475  track.getPhiBits(), TTTrack_TrackWord::TrackBitWidths::kPhiSize, TTTrack_TrackWord::stepPhi0, 0.0);
476  log << "\t\t(" << ptEmulation.to_double() << ", " << etaEmulation.to_double() << ", " << floatTkPhi << ", "
477  << track.getNStubs() << ", " << track.getBendChi2() << ", " << track.getChi2RZ() << ", " << track.getChi2RPhi()
478  << ", " << floatTkZ0 << ")\n";
479  }
480 }
481 
482 // ------------ method called to produce the data ------------
484  auto vTTTrackAssociatedOutput = std::make_unique<TTTrackRefCollectionType>();
485  auto vTTTrackAssociatedEmulationOutput = std::make_unique<TTTrackRefCollectionType>();
486 
487  TTTrackCollectionHandle l1TracksHandle;
488  edm::Handle<TTTrackRefCollectionType> l1SelectedTracksHandle;
489  edm::Handle<TTTrackRefCollectionType> l1SelectedTracksEmulationHandle;
490  edm::Handle<l1t::VertexCollection> l1VerticesHandle;
491  edm::Handle<l1t::VertexWordCollection> l1VerticesEmulationHandle;
492 
493  l1t::Vertex leadingVertex;
494  l1t::VertexWord leadingEmulationVertex;
495 
496  TTTrackWordLinkLimitSelector linkLimitSel(fwNTrackSetsTVA_); //stateful functor for simulated tracks
497  TTTrackWordLinkLimitSelector linkLimitSelEmu(fwNTrackSetsTVA_); //stateful functor for emulated tracks
498 
501 
502  NNTrackWordSelector TTTrackNetworkSelector(associationSesh_,
507 
508  iEvent.getByToken(l1TracksToken_, l1TracksHandle);
509  size_t nOutputApproximate = l1TracksHandle->size();
510 
512  iEvent.getByToken(l1SelectedTracksToken_, l1SelectedTracksHandle);
513  iEvent.getByToken(l1VerticesToken_, l1VerticesHandle);
514  leadingVertex = l1VerticesHandle->at(0);
515  if (debug_ >= 2) {
516  edm::LogInfo("L1TrackVertexAssociationProducer") << "leading vertex z0 = " << leadingVertex.z0();
517  }
518  vTTTrackAssociatedOutput->reserve(nOutputApproximate);
519  }
521  iEvent.getByToken(l1SelectedTracksEmulationToken_, l1SelectedTracksEmulationHandle);
522  iEvent.getByToken(l1VerticesEmulationToken_, l1VerticesEmulationHandle);
523  leadingEmulationVertex = l1VerticesEmulationHandle->at(0);
524  if (debug_ >= 2) {
525  edm::LogInfo("L1TrackVertexAssociationProducer")
526  << "leading emulation vertex z0 = " << leadingEmulationVertex.z0();
527  }
528  vTTTrackAssociatedEmulationOutput->reserve(nOutputApproximate);
529  }
530  for (size_t i = 0; i < nOutputApproximate; i++) {
531  const auto& track = l1TracksHandle->at(i);
533  // Limit the number of processed tracks according to the firmware capability: must be run on non-selected tracks (i.e. GTTConverted tracks)
534  bool passLinkLimit = linkLimitSel(track);
535  // Only match Selected tracks, by testing that the track is in the SelectedTracks collection
536  auto itr = std::find_if(l1SelectedTracksHandle->begin(), l1SelectedTracksHandle->end(), [track](const auto& ref) {
537  return (*ref).getTrackWord() == track.getTrackWord();
538  });
539  bool passSelection = (itr != l1SelectedTracksHandle->end());
540  // Associate tracks based on the simulation delta Z
541  if (passLinkLimit && passSelection && deltaZSel(track, leadingVertex)) {
542  vTTTrackAssociatedOutput->push_back(TTTrackRef(l1TracksHandle, i));
543  }
544  } //end if (processSimulatedTracks_)
546  // Limit the number of processed tracks according to the firmware capability: must be run on non-selected tracks (i.e. GTTConverted tracks)
547  bool passLinkLimitEmu = linkLimitSelEmu(track);
548  // Only match Selected tracks, by testing that the track is in the SelectedTracks collection
549  auto itrEmu = std::find_if(l1SelectedTracksEmulationHandle->begin(),
550  l1SelectedTracksEmulationHandle->end(),
551  [track](const auto& ref) { return (*ref).getTrackWord() == track.getTrackWord(); });
552  bool passSelectionEmu = (itrEmu != l1SelectedTracksEmulationHandle->end());
553  // Associated tracks based on the bitwise accurate TTTrack_TrackWord
555  if (passLinkLimitEmu && passSelectionEmu && TTTrackNetworkSelector(track, l1VerticesEmulationHandle->at(0))) {
556  vTTTrackAssociatedEmulationOutput->push_back(TTTrackRef(l1TracksHandle, i));
557  }
558  } else {
559  if (passLinkLimitEmu && passSelectionEmu && deltaZSelEmu(track, l1VerticesEmulationHandle->at(0))) {
560  vTTTrackAssociatedEmulationOutput->push_back(TTTrackRef(l1TracksHandle, i));
561  } //end block for satisfying LinkLimitEmu and SelectionEmu criteria
562  } //end if use track association NN
563  } //end if (processEmulatedTracks_)
564  } //end loop over input converted tracks
565 
567  printDebugInfo(l1SelectedTracksHandle,
568  l1SelectedTracksEmulationHandle,
569  vTTTrackAssociatedOutput,
570  vTTTrackAssociatedEmulationOutput);
571  }
572 
574  iEvent.put(std::move(vTTTrackAssociatedOutput), outputCollectionName_);
575  }
576 
578  iEvent.put(std::move(vTTTrackAssociatedEmulationOutput), outputCollectionName_ + "Emulation");
579  if (debug_ >= 2)
580  linkLimitSelEmu.log();
581  }
582 }
583 
584 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
587  desc.add<edm::InputTag>("l1TracksInputTag", edm::InputTag("l1tGTTInputProducer", "Level1TTTracksConverted"));
588  desc.add<edm::InputTag>("l1SelectedTracksInputTag",
589  edm::InputTag("l1tTrackSelectionProducer", "Level1TTTracksSelected"));
590  desc.add<edm::InputTag>("l1SelectedTracksEmulationInputTag",
591  edm::InputTag("l1tTrackSelectionProducer", "Level1TTTracksSelectedEmulation"));
592  desc.add<edm::InputTag>("l1VerticesInputTag", edm::InputTag("l1tVertexFinder", "L1Vertices"));
593  desc.add<edm::InputTag>("l1VerticesEmulationInputTag",
594  edm::InputTag("l1tVertexFinderEmulator", "L1VerticesEmulation"));
595  desc.add<std::string>("outputCollectionName", "Level1TTTracksSelectedAssociated");
596  {
597  edm::ParameterSetDescription descCutSet;
598  descCutSet.add<std::vector<double>>("deltaZMaxEtaBounds", {0.0, 0.7, 1.0, 1.2, 1.6, 2.0, 2.4})
599  ->setComment("these values define the bin boundaries in |eta|");
600  descCutSet.add<std::vector<double>>("deltaZMax", {0.37, 0.50, 0.60, 0.75, 1.00, 1.60})
601  ->setComment(
602  "delta z must be less than these values, there will be one less value here than in deltaZMaxEtaBounds, "
603  "[cm]");
604  desc.add<edm::ParameterSetDescription>("cutSet", descCutSet);
605  }
606  desc.add<double>("useDisplacedTracksDeltaZOverride", -1.0)
607  ->setComment("override the deltaZ cut value for displaced tracks");
608  desc.add<bool>("processSimulatedTracks", true)
609  ->setComment("return selected tracks after cutting on the floating point values");
610  desc.add<bool>("processEmulatedTracks", true)
611  ->setComment("return selected tracks after cutting on the bitwise emulated values");
612  desc.add<unsigned int>("fwNTrackSetsTVA", 94)->setComment("firmware limit on processed tracks per GTT input link");
613  desc.add<bool>("useAssociationNetwork", false)->setComment("Enable Association Network");
614  desc.add<double>("associationThreshold", 0)->setComment("Association Network threshold for PV tracks");
615  desc.addOptional<edm::FileInPath>("associationGraph")->setComment("Location of Association Network model file");
616  desc.add<std::vector<double>>("associationNetworkZ0binning", {})
617  ->setComment("z0 binning used for setting the input feature digitisation");
618  desc.add<std::vector<double>>("associationNetworkEtaBounds", {})
619  ->setComment("Eta bounds used to set z0 resolution input feature");
620  desc.add<std::vector<double>>("associationNetworkZ0ResBins", {})->setComment("z0 resolution input feature bins");
621 
622  desc.add<int>("debug", 0)->setComment("Verbosity levels: 0, 1, 2, 3");
623  descriptions.addWithDefaultLabel(desc);
624 }
625 
626 //define this as a plug-in
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const edm::EDGetTokenT< TTTrackCollectionType > l1TracksToken_
void printTrackInfo(edm::LogInfo &log, const TTTrackType &track, bool printEmulation=false) const
bool operator()(const TTTrackType &t, const l1t::VertexWord &v) const
L1TrackVertexAssociationProducer(const edm::ParameterSet &)
std::string fullPath() const
Definition: FileInPath.cc:161
TTTrackDeltaZMaxSelector(const std::vector< double > &deltaZMaxEtaBounds, const std::vector< double > &deltaZMax)
GraphDef * loadGraphDef(const std::string &pbFile)
Definition: TensorFlow.cc:129
bool operator()(const TTTrackType &t, const l1t::Vertex &v) const
delete x;
Definition: CaloConfig.h:22
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
const edm::EDGetTokenT< l1t::VertexCollection > l1VerticesToken_
const edm::EDGetTokenT< TTTrackRefCollectionType > l1SelectedTracksToken_
TTTrackWordDeltaZMaxSelector(const std::vector< double > &deltaZMaxEtaBounds, const std::vector< double > &deltaZMax)
int iEvent
Definition: GenABIO.cc:224
ap_fixed< VertexBitWidths::kZ0Size, VertexBitWidths::kZ0MagSize, AP_RND_CONV, AP_SAT > vtxz0_t
Definition: VertexWord.h:65
edm::Handle< TTTrackCollectionType > TTTrackCollectionHandle
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
unsigned int gttLinkID(T track)
Definition: tracks.h:20
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Definition: TensorFlow.cc:281
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< VertexWord > VertexWordCollection
Definition: VertexWord.h:197
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Session * createSession()
Definition: TensorFlow.cc:146
Log< level::Info, false > LogInfo
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
void printDebugInfo(const edm::Handle< TTTrackRefCollectionType > &l1SelectedTracksHandle, const edm::Handle< TTTrackRefCollectionType > &l1SelectedTracksEmulationHandle, const TTTrackRefCollectionUPtr &vTTTrackAssociatedOutput, const TTTrackRefCollectionUPtr &vTTTrackAssociatedEmulationOutput) const
static constexpr double stepPhi0
bool operator()(const TTTrackType &t, const l1t::VertexWord &v) const
double z0() const
Definition: VertexWord.h:158
std::unique_ptr< TTTrackRefCollectionType > TTTrackRefCollectionUPtr
HLT enums.
ap_uint< TrackBitWidths::kTanlSize > tanl_t
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< l1t::VertexWordCollection > l1VerticesEmulationToken_
float z0() const
Definition: Vertex.h:21
edm::Ref< std::vector< TTTrack< Ref_Phase2TrackerDigi_ > >, TTTrack< Ref_Phase2TrackerDigi_ > > TTTrackRef
Definition: TTTypes.h:51
edm::RefVector< TTTrackCollectionType > TTTrackRefCollectionType
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
TTTrack< Ref_Phase2TrackerDigi_ > TTTrackType
static constexpr double stepZ0
const edm::EDGetTokenT< TTTrackRefCollectionType > l1SelectedTracksEmulationToken_
std::vector< std::string > set_difference(std::vector< std::string > const &v1, std::vector< std::string > const &v2)
def move(src, dest)
Definition: eostools.py:511
NNTrackWordSelector(tensorflow::Session *AssociationSesh, const double AssociationThreshold, const std::vector< double > &AssociationNetworkZ0binning, const std::vector< double > &AssociationNetworkEtaBounds, const std::vector< double > &AssociationNetworkZ0ResBins)