CMS 3D CMS Logo

codecs_tracks.cc
Go to the documentation of this file.
3 
4 namespace l1t::demo::codecs {
5 
6  ap_uint<96> encodeTrack(const TTTrack_TrackWord& t) { return t.getTrackWord(); }
7 
8  // Encodes track collection onto 18 output links (2x9 eta-phi sectors; first 9 negative eta)
9  std::array<std::vector<ap_uint<64>>, 18> encodeTracks(const edm::View<TTTrack<Ref_Phase2TrackerDigi_>>& tracks,
10  int debug) {
11  std::array<std::vector<ap_uint<96>>, 18> trackWords;
12  if (debug > 0) {
13  edm::LogInfo("l1t::demo::codecs") << "encodeTrack::Encoding " << tracks.size() << " tracks";
14  }
15  for (const auto& track : tracks)
16  trackWords.at((track.eta() >= 0 ? 9 : 0) + track.phiSector()).push_back(encodeTrack(track));
17 
18  std::array<std::vector<ap_uint<64>>, 18> linkData;
19 
20  size_t counter = 0;
21  for (size_t i = 0; i < linkData.size(); i++) {
22  // Pad track vectors -> full packet length (156 frames = 104 tracks)
23  trackWords.at(i).resize(104, 0);
24  linkData.at(i).resize(156, {0});
25 
26  for (size_t j = 0; (j < trackWords.at(i).size()); j += 2) {
27  linkData.at(i).at(3 * j / 2) = trackWords.at(i).at(j)(63, 0);
28  linkData.at(i).at(3 * j / 2 + 1) =
29  (ap_uint<32>(trackWords.at(i).at(j + 1)(31, 0)), ap_uint<32>(trackWords.at(i).at(j)(95, 64)));
30  linkData.at(i).at(3 * j / 2 + 2) = trackWords.at(i).at(j + 1)(95, 32);
31  counter += trackWords.at(i).at(j)(95, 95) + trackWords.at(i).at(j + 1)(95, 95);
32  }
33  }
34  if (debug > 0) {
35  edm::LogInfo("l1t::demo::codecs") << "encodeTrack::Encoded " << counter << " tracks";
36  }
37 
38  return linkData;
39  }
40 
41  std::vector<TTTrack_TrackWord> decodeTracks(const std::vector<ap_uint<64>>& frames) {
42  std::vector<TTTrack_TrackWord> tracks;
43 
44  if ((frames.size() % 3) != 0) {
45  std::stringstream message;
46  message << "The number of track frames (" << frames.size() << ") is not evenly divisible by 3";
47  throw std::runtime_error(message.str());
48  }
49 
50  for (size_t i = 0; i < frames.size(); i += 3) {
51  TTTrack_TrackWord::tkword_t combination1 = (ap_uint<32>(frames.at(i + 1)(31, 0)), frames.at(i)(63, 0));
52  TTTrack_TrackWord::tkword_t combination2 = (frames.at(i + 2)(63, 0), ap_uint<32>(frames.at(i + 1)(63, 32)));
53  TTTrack_TrackWord track1, track2;
54  track1.setTrackWord(
69  track2.setTrackWord(
84  tracks.push_back(track1);
85  tracks.push_back(track2);
86  }
87 
88  return tracks;
89  }
90 
91  std::array<std::vector<TTTrack_TrackWord>, 18> decodeTracks(const std::array<std::vector<ap_uint<64>>, 18>& frames) {
92  std::array<std::vector<TTTrack_TrackWord>, 18> tracks;
93 
94  for (size_t i = 0; i < tracks.size(); i++) {
95  tracks.at(i) = decodeTracks(frames.at(i));
96  }
97 
98  return tracks;
99  }
100 
101 } // namespace l1t::demo::codecs
ap_uint< TrackBitWidths::kTrackWordSize > tkword_t
ap_uint< 96 > encodeTrack(const TTTrack_TrackWord &t)
Definition: codecs_tracks.cc:6
ap_uint< TrackBitWidths::kMVAQualitySize > qualityMVA_t
std::array< std::vector< ap_uint< 64 > >, 18 > encodeTracks(const edm::View< TTTrack< Ref_Phase2TrackerDigi_ >> &, int debug=0)
Definition: codecs_tracks.cc:9
ap_uint< TrackBitWidths::kZ0Size > z0_t
void setTrackWord(unsigned int valid, const GlobalVector &momentum, const GlobalPoint &POCA, double rInv, double chi2RPhi, double chi2RZ, double bendChi2, unsigned int hitPattern, unsigned int mvaQuality, unsigned int mvaOther, unsigned int sector)
ap_uint< TrackBitWidths::kMVAOtherSize > otherMVA_t
std::vector< TTTrack_TrackWord > decodeTracks(const std::vector< ap_uint< 64 >> &frames)
ap_uint< TrackBitWidths::kValidSize > valid_t
ap_uint< TrackBitWidths::kRinvSize > rinv_t
ap_uint< TrackBitWidths::kHitPatternSize > hit_t
ap_uint< TrackBitWidths::kChi2RZSize > chi2rz_t
Log< level::Info, false > LogInfo
#define debug
Definition: HDRShower.cc:19
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
ap_uint< TrackBitWidths::kTanlSize > tanl_t
ap_uint< TrackBitWidths::kD0Size > d0_t
ap_uint< TrackBitWidths::kChi2RPhiSize > chi2rphi_t
ap_uint< TrackBitWidths::kBendChi2Size > bendChi2_t
ap_uint< TrackBitWidths::kPhiSize > phi_t