CMS 3D CMS Logo

codecs_tracks.cc
Go to the documentation of this file.
3 
4 namespace l1t::demo::codecs {
5 
6  // Return true if a track is contained within a collection
10  auto it = std::find_if(
11  trackRefCollection->begin(),
12  trackRefCollection->end(),
13  [&trackRef](edm::Ref<std::vector<TTTrack<Ref_Phase2TrackerDigi_>>> const& obj) { return obj == trackRef; });
14  if (it != trackRefCollection->end())
15  return true;
16  else
17  return false;
18  }
19 
20  // Encodes a single track into a 96-bit track word
21  ap_uint<96> encodeTrack(const TTTrack_TrackWord& t) { return t.getTrackWord(); }
22 
23  // Return the 96-bit track words from a given track collection and place them on the appropriate 18 'logical' links
24  std::array<std::vector<ap_uint<96>>, 18> getTrackWords(const edm::View<TTTrack<Ref_Phase2TrackerDigi_>>& tracks) {
25  std::array<std::vector<ap_uint<96>>, 18> trackWords;
26  for (const auto& track : tracks) {
27  trackWords.at((track.eta() >= 0 ? 1 : 0) + (2 * track.phiSector())).push_back(encodeTrack(track));
28  }
29  return trackWords;
30  }
31 
32  // Return the 96-bit track words from a given track collection and place them on the appropriate 18 'logical' links
33  std::array<std::vector<ap_uint<96>>, 18> getTrackWords(
36  std::array<std::vector<ap_uint<96>>, 18> trackWords;
37  for (unsigned int itrack = 0; itrack < referenceTracks->size(); itrack++) {
38  const auto& referenceTrack = referenceTracks->at(itrack);
39  edm::Ref<std::vector<TTTrack<Ref_Phase2TrackerDigi_>>> referenceTrackRef(referenceTracks, itrack);
40 
41  if (trackInCollection(referenceTrackRef, tracks)) {
42  trackWords.at((referenceTrack.eta() >= 0 ? 1 : 0) + (2 * referenceTrack.phiSector()))
43  .push_back(encodeTrack(referenceTrack));
44  } else {
45  trackWords.at((referenceTrack.eta() >= 0 ? 1 : 0) + (2 * referenceTrack.phiSector())).push_back(ap_uint<96>(0));
46  }
47  }
48  return trackWords;
49  }
50 
51  // Encodes a set of tracks onto a set of links
52  size_t encodeLinks(std::array<std::vector<ap_uint<96>>, 18>& trackWords,
53  std::array<std::vector<ap_uint<64>>, 18>& linkData) {
54  size_t counter = 0;
55  for (size_t i = 0; i < linkData.size(); i++) {
56  // Pad track vectors -> full packet length (156 frames = 104 tracks)
57  trackWords.at(i).resize(104, 0);
58  linkData.at(i).resize(156, {0});
59 
60  for (size_t j = 0; (j < trackWords.at(i).size()); j += 2) {
61  linkData.at(i).at(3 * j / 2) = trackWords.at(i).at(j)(63, 0);
62  linkData.at(i).at(3 * j / 2 + 1) =
63  (ap_uint<32>(trackWords.at(i).at(j + 1)(31, 0)), ap_uint<32>(trackWords.at(i).at(j)(95, 64)));
64  linkData.at(i).at(3 * j / 2 + 2) = trackWords.at(i).at(j + 1)(95, 32);
65  counter += trackWords.at(i).at(j)(95, 95) + trackWords.at(i).at(j + 1)(95, 95);
66  }
67  }
68  return counter;
69  }
70 
71  // Encodes track collection onto 18 output links (2x9 eta-phi sectors; , -/+ eta pairs)
72  std::array<std::vector<ap_uint<64>>, 18> encodeTracks(const edm::View<TTTrack<Ref_Phase2TrackerDigi_>>& tracks,
73  int debug) {
74  if (debug > 0) {
75  edm::LogInfo("l1t::demo::codecs") << "encodeTrack::Encoding " << tracks.size() << " tracks";
76  }
77 
78  std::array<std::vector<ap_uint<96>>, 18> trackWords = getTrackWords(tracks);
79  std::array<std::vector<ap_uint<64>>, 18> linkData;
80  size_t counter = encodeLinks(trackWords, linkData);
81 
82  if (debug > 0) {
83  edm::LogInfo("l1t::demo::codecs") << "encodeTrack::Encoded " << counter << " tracks";
84  }
85 
86  return linkData;
87  }
88 
89  // Encodes a track collection based off the ordering of another track collection
90  // Requirement: The second collection must be a subset of the first
91  std::array<std::vector<ap_uint<64>>, 18> encodeTracks(
94  int debug) {
95  if (debug > 0) {
96  edm::LogInfo("l1t::demo::codecs") << "encodeTrack::Encoding " << tracks->size() << " tracks";
97  }
98 
99  std::array<std::vector<ap_uint<96>>, 18> trackWords = getTrackWords(referenceTracks, tracks);
100  std::array<std::vector<ap_uint<64>>, 18> linkData;
101  size_t counter = encodeLinks(trackWords, linkData);
102 
103  if (debug > 0) {
104  edm::LogInfo("l1t::demo::codecs") << "encodeTrack::Encoded " << counter << " tracks";
105  }
106 
107  return linkData;
108  }
109 
110  std::vector<TTTrack_TrackWord> decodeTracks(const std::vector<ap_uint<64>>& frames) {
111  std::vector<TTTrack_TrackWord> tracks;
112 
113  if ((frames.size() % 3) != 0) {
114  std::stringstream message;
115  message << "The number of track frames (" << frames.size() << ") is not evenly divisible by 3";
116  throw std::runtime_error(message.str());
117  }
118 
119  for (size_t i = 0; i < frames.size(); i += 3) {
120  TTTrack_TrackWord::tkword_t combination1 = (ap_uint<32>(frames.at(i + 1)(31, 0)), frames.at(i)(63, 0));
121  TTTrack_TrackWord::tkword_t combination2 = (frames.at(i + 2)(63, 0), ap_uint<32>(frames.at(i + 1)(63, 32)));
122  TTTrack_TrackWord track1, track2;
123  track1.setTrackWord(
138  track2.setTrackWord(
153  tracks.push_back(track1);
154  tracks.push_back(track2);
155  }
156 
157  return tracks;
158  }
159 
160  // Decodes the tracks from 18 'logical' output links (2x9 eta-phi sectors; , -/+ eta pairs)
161  std::array<std::vector<TTTrack_TrackWord>, 18> decodeTracks(const std::array<std::vector<ap_uint<64>>, 18>& frames) {
162  std::array<std::vector<TTTrack_TrackWord>, 18> tracks;
163 
164  for (size_t i = 0; i < tracks.size(); i++) {
165  tracks.at(i) = decodeTracks(frames.at(i));
166  }
167 
168  return tracks;
169  }
170 
171 } // namespace l1t::demo::codecs
ap_uint< TrackBitWidths::kTrackWordSize > tkword_t
ap_uint< 96 > encodeTrack(const TTTrack_TrackWord &t)
ap_uint< TrackBitWidths::kMVAQualitySize > qualityMVA_t
size_t encodeLinks(std::array< std::vector< ap_uint< 96 >>, 18 > &trackWords, std::array< std::vector< ap_uint< 64 >>, 18 > &linkData)
std::array< std::vector< ap_uint< 64 > >, 18 > encodeTracks(const edm::View< TTTrack< Ref_Phase2TrackerDigi_ >> &, int debug=0)
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
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
std::array< std::vector< ap_uint< 96 > >, 18 > getTrackWords(const edm::View< TTTrack< Ref_Phase2TrackerDigi_ >> &)
bool trackInCollection(const edm::Ref< std::vector< TTTrack< Ref_Phase2TrackerDigi_ >>> &, const edm::Handle< edm::RefVector< std::vector< TTTrack< Ref_Phase2TrackerDigi_ >>>> &)
Definition: codecs_tracks.cc:7
ap_uint< TrackBitWidths::kTanlSize > tanl_t
static std::atomic< unsigned int > counter
ap_uint< TrackBitWidths::kD0Size > d0_t
ap_uint< TrackBitWidths::kChi2RPhiSize > chi2rphi_t
std::vector< TTTrack_TrackWord > decodeTracks(const std::vector< ap_uint< 64 >> &)
ap_uint< TrackBitWidths::kBendChi2Size > bendChi2_t
ap_uint< TrackBitWidths::kPhiSize > phi_t