CMS 3D CMS Logo

RegionalMuonGMTPacker.cc
Go to the documentation of this file.
4 
6 #include "GMTTokens.h"
8 
9 namespace l1t {
10  namespace stage2 {
12  GMTObjectMap bmtfObjMap;
13  GMTObjectMap omtfObjMap;
14  GMTObjectMap emtfObjMap;
15  auto const bmtfToken = static_cast<const GMTTokens*>(toks)->getRegionalMuonCandTokenBMTF();
16  auto const omtfToken = static_cast<const GMTTokens*>(toks)->getRegionalMuonCandTokenOMTF();
17  auto const emtfToken = static_cast<const GMTTokens*>(toks)->getRegionalMuonCandTokenEMTF();
18 
19  // First we put the muons in our object map.
20  std::pair<int, int> const bmtfMuonBx = getMuons(bmtfObjMap, event, bmtfToken);
21  std::pair<int, int> const omtfMuonBx = getMuons(omtfObjMap, event, omtfToken);
22  std::pair<int, int> const emtfMuonBx = getMuons(emtfObjMap, event, emtfToken);
23 
24  // Then the showers (We don't expect to have shower data from BMTF and OMTF -- at the moment, at least)
25  std::pair<int, int> emtfMuonShowerBx{0, 0};
27  auto const emtfShowerToken = static_cast<const GMTTokens*>(toks)->getRegionalMuonShowerTokenEMTF();
28  emtfMuonShowerBx = getMuonShowers(emtfObjMap, event, emtfShowerToken);
29  }
30 
31  Blocks blocks;
32 
33  // Pack the muons and showers for each TF in blocks
34  packTF(bmtfObjMap, bmtfMuonBx.first, bmtfMuonBx.second, 0, 0, blocks);
35  packTF(omtfObjMap, omtfMuonBx.first, omtfMuonBx.second, 0, 0, blocks);
36  packTF(emtfObjMap, emtfMuonBx.first, emtfMuonBx.second, emtfMuonShowerBx.first, emtfMuonShowerBx.second, blocks);
37 
38  return blocks;
39  }
40 
42  GMTObjectMap& objMap,
43  const edm::Event& event,
46  event.getByToken(tfShowerToken, muonShowers);
47  for (int bx = muonShowers->getFirstBX(); bx <= muonShowers->getLastBX(); ++bx) {
48  for (auto muShower = muonShowers->begin(bx); muShower != muonShowers->end(bx); ++muShower) {
49  objMap[bx][muShower->link()].shower = *muShower;
50  }
51  }
52  return std::make_pair(muonShowers->getFirstBX(), muonShowers->getLastBX());
53  }
54 
55  std::pair<int, int> RegionalMuonGMTPacker::getMuons(GMTObjectMap& objMap,
56  const edm::Event& event,
59  event.getByToken(tfToken, muons);
60  for (int bx = muons->getFirstBX(); bx <= muons->getLastBX(); ++bx) {
61  for (auto mu = muons->begin(bx); mu != muons->end(bx); ++mu) {
62  objMap[bx][mu->link()].mus.push_back(*mu);
63  }
64  }
65  return std::make_pair(muons->getFirstBX(), muons->getLastBX());
66  }
67 
69  const int firstMuonBx,
70  const int lastMuonBx,
71  const int firstMuonShowerBx,
72  const int lastMuonShowerBx,
73  Blocks& blocks) {
74  const auto firstBx{std::min(firstMuonShowerBx, firstMuonBx)};
75  const auto lastBx{std::max(lastMuonShowerBx, lastMuonBx)};
76  const auto nBx{lastBx - firstBx + 1};
77 
78  PayloadMap payloadMap;
79 
80  unsigned bxCtr = 0;
81  for (int bx{firstBx}; bx < lastBx + 1; ++bx, ++bxCtr) {
82  if (objMap.count(bx) > 0) {
83  for (const auto& linkMap : objMap.at(bx)) {
84  const auto linkTimes2{linkMap.first * 2};
85  const auto gmtObjects{linkMap.second};
86 
87  // If the payload map key is new reserve the payload size.
88  if (payloadMap.count(linkTimes2) == 0) {
89  payloadMap[linkTimes2].reserve(wordsPerBx_ * nBx);
90  // If there was no muon on the link of this muon in previous
91  // BX the payload up to this BX must be filled with zeros.
92  if (bxCtr > 0) {
93  while (payloadMap[linkTimes2].size() < bxCtr * wordsPerBx_) {
94  payloadMap[linkTimes2].push_back(0);
95  }
96  }
97  }
98 
99  if (gmtObjects.mus.size() > 3) {
100  edm::LogError("L1T") << "Muon collection for link " << linkMap.first << " has " << gmtObjects.mus.size()
101  << " entries, but 3 is the maximum!";
102  }
103 
104  std::array<uint32_t, 6> buf{}; // Making sure contents of buf are initialised to 0.
105  size_t frameIdx{0};
106  for (const auto& mu : gmtObjects.mus) {
107  // Fill the muon in the payload for this link.
108  uint32_t msw{0};
109  uint32_t lsw{0};
110 
113 
114  buf.at(frameIdx++) = lsw;
115  buf.at(frameIdx++) = msw;
116  }
117  // Add shower bits to the payload buffer.
120 
121  payloadMap[linkTimes2].insert(
122  payloadMap[linkTimes2].end(), std::move_iterator(buf.begin()), std::move_iterator(buf.end()));
123  }
124  }
125  // We now loop over all channels in the payload map and make sure that they are filled up to the current BX
126  // If they are not, we fill them with zeros
127  for (auto& kv : payloadMap) {
128  while (kv.second.size() < (bxCtr + 1) * wordsPerBx_) {
129  kv.second.push_back(0);
130  }
131  }
132  }
133 
134  // push everything in the blocks vector
135  for (auto& kv : payloadMap) {
136  blocks.push_back(Block(kv.first, kv.second));
137  }
138  }
139 
140  } // namespace stage2
141 } // namespace l1t
142 
std::pair< int, int > getMuons(GMTObjectMap &objMap, const edm::Event &event, const edm::EDGetTokenT< RegionalMuonCandBxCollection > &tfToken)
std::map< unsigned int, std::vector< uint32_t > > PayloadMap
static void generatePackedDataWords(const RegionalMuonCand &mu, uint32_t &raw_data_00_31, uint32_t &raw_data_32_63, bool isKbmtf, bool useOmtfDisplacementInfo, bool useEmtfDisplacementInfo)
delete x;
Definition: CaloConfig.h:22
Log< level::Error, false > LogError
static void generatePackedShowerPayload(const RegionalMuonShower &shower, std::array< uint32_t, 6 > &payload, bool useEmtfNominalTightShowers, bool useEmtfLooseShowers)
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
void packTF(const GMTObjectMap &objMap, int firstMuonBx, int lastMuonBx, int firstMuonShowerBx, int lastMuonShowerBx, Blocks &)
std::vector< Block > Blocks
Definition: Block.h:99
std::pair< int, int > getMuonShowers(GMTObjectMap &objMap, const edm::Event &event, const edm::EDGetTokenT< RegionalMuonShowerBxCollection > &tfShowerToken)
std::map< size_t, std::map< size_t, GMTObjects > > GMTObjectMap
#define DEFINE_L1T_PACKER(type)
Definition: PackerFactory.h:23
Blocks pack(const edm::Event &, const PackerTokens *) override
Definition: event.py:1