CMS 3D CMS Logo

MuonPacker.cc
Go to the documentation of this file.
2 
3 #include "GMTTokens.h"
4 #include "MuonPacker.h"
5 
6 namespace l1t {
7  namespace stage2 {
9  GMTOutputObjectMap gmtObjMap;
10  std::pair<int, int> muonBx = getMuons(gmtObjMap, event, static_cast<const CommonTokens*>(toks)->getMuonToken());
11  std::pair<int, int> muonShowerBx{0, 0};
13  muonShowerBx = getMuonShowers(gmtObjMap, event, static_cast<const CommonTokens*>(toks)->getMuonShowerToken());
14  }
15 
16  PayloadMap payloadMap;
17 
18  packBx(gmtObjMap, muonBx.first, muonBx.second, muonShowerBx.first, muonShowerBx.second, payloadMap);
19 
20  Blocks blocks;
21  // push everything in the blocks vector
22  for (auto& kv : payloadMap) {
23  blocks.push_back(Block(kv.first, kv.second));
24  }
25  return blocks;
26  }
27 
28  std::pair<int, int> MuonPacker::getMuonShowers(GMTOutputObjectMap& objMap,
29  const edm::Event& event,
30  const edm::EDGetTokenT<MuonShowerBxCollection>& showerToken) {
32  event.getByToken(showerToken, muonShowers);
33  for (int bx = muonShowers->getFirstBX(); bx <= muonShowers->getLastBX(); ++bx) {
34  if (muonShowers->size(bx) > 0) {
35  objMap[bx].shower = muonShowers->at(bx, 0); // At most one shower per BX.
36  }
37  }
38  return std::make_pair(muonShowers->getFirstBX(), muonShowers->getLastBX());
39  }
40 
41  std::pair<int, int> MuonPacker::getMuons(GMTOutputObjectMap& objMap,
42  const edm::Event& event,
45  event.getByToken(muonToken, muons);
46  for (int bx = muons->getFirstBX(); bx <= muons->getLastBX(); ++bx) {
47  objMap[bx] = GMTObjects();
48  for (auto mu = muons->begin(bx); mu != muons->end(bx); ++mu) {
49  objMap[bx].mus.push_back(*mu);
50  }
51  }
52  return std::make_pair(muons->getFirstBX(), muons->getLastBX());
53  }
54 
56  const int firstMuonBx,
57  const int lastMuonBx,
58  const int firstMuonShowerBx,
59  const int lastMuonShowerBx,
60  PayloadMap& payloadMap) {
61  const auto firstBx{std::min(firstMuonShowerBx, firstMuonBx)};
62  const auto lastBx{std::max(lastMuonShowerBx, lastMuonBx)};
63 
64  for (int bx{firstBx}; bx < lastBx + 1; ++bx) {
65  // the first word in every BX and every block id is 0
66  for (unsigned int blkId = b1_; blkId < b1_ + 7; blkId += 2) {
67  payloadMap[blkId].push_back(0);
68  }
69 
70  unsigned int blkId = b1_;
71  uint32_t mu1_shared_word{0};
72  uint32_t mu2_shared_word{0};
73  uint32_t mu1_msw{0};
74  uint32_t mu2_msw{0};
75  uint32_t mu1_lsw{0};
76  uint32_t mu2_lsw{0};
77  auto mu{objMap.at(bx).mus.begin()}; // Need to get the first muon of that bx from the object map
78  std::array<std::array<uint32_t, 4>, 2> const showerWords{
80  // Slightly convoluted logic to account for the Run-3 muon readout record:
81  // To make space for displacement information we moved the raw
82  // (i.e. non-extrapolated) eta value to the second "spare" word
83  // in the block which we call "shared word". So the logic below
84  // needs to be aware if it is operating on the first or second
85  // muon in the block in order to place the eta value in the right
86  // place in the shared word. Additionally the logic needs to
87  // wait for the second muon in the block before filling the
88  // payload map because the shared word goes in first.
89  for (int muCtr = 1; muCtr <= 8; ++muCtr) {
90  if (mu != objMap.at(bx).mus.end()) {
92  *mu, mu2_shared_word, mu2_lsw, mu2_msw, fedId_, fwId_, 2 - (muCtr % 2));
93  ++mu;
94  }
95 
96  // If we're remaining in the current block the muon we just packed is the first one in the block.
97  // If not we add both muons to the payload map and go to the next block.
98  if (muCtr % 2 == 1) {
99  mu1_shared_word = mu2_shared_word;
100  mu1_lsw = mu2_lsw;
101  mu1_msw = mu2_msw;
102  mu1_msw |= showerWords.at(0).at(muCtr / 2);
103  } else {
104  mu2_msw |= showerWords.at(1).at(muCtr / 2 - 1);
105  payloadMap[blkId].push_back(mu1_shared_word | mu2_shared_word);
106  payloadMap[blkId].push_back(mu1_lsw);
107  payloadMap[blkId].push_back(mu1_msw);
108  payloadMap[blkId].push_back(mu2_lsw);
109  payloadMap[blkId].push_back(mu2_msw);
110 
111  blkId += 2;
112 
113  mu1_shared_word = 0;
114  mu1_lsw = 0;
115  mu1_msw = 0;
116  }
117  mu2_shared_word = 0;
118  mu2_lsw = 0;
119  mu2_msw = 0;
120  }
121  }
122  }
123  } // namespace stage2
124 } // namespace l1t
125 
std::pair< int, int > getMuons(GMTOutputObjectMap &objMap, const edm::Event &event, const edm::EDGetTokenT< MuonBxCollection > &muonToken)
Definition: MuonPacker.cc:41
std::map< size_t, GMTObjects > GMTOutputObjectMap
Definition: MuonPacker.h:25
static std::array< std::array< uint32_t, 4 >, 2 > getPackedShowerDataWords(const MuonShower &shower, int fedId, int fwId)
std::map< unsigned int, std::vector< uint32_t > > PayloadMap
Definition: MuonPacker.h:26
delete x;
Definition: CaloConfig.h:22
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 packBx(const GMTOutputObjectMap &objMap, int firstMuonBx, int lastMuonBx, int firstMuonShowerBx, int lastMuonShowerBx, PayloadMap &payloadMap)
Definition: MuonPacker.cc:55
Blocks pack(const edm::Event &, const PackerTokens *) override
Definition: MuonPacker.cc:8
static bool isFwVersionWithShowers(int fedId, int fwId)
std::vector< Block > Blocks
Definition: Block.h:99
static void generatePackedMuonDataWords(const Muon &mu, uint32_t &raw_data_spare, uint32_t &raw_data_00_31, uint32_t &raw_data_32_63, int fedId, int fwId, int muInBx)
#define DEFINE_L1T_PACKER(type)
Definition: PackerFactory.h:23
std::pair< int, int > getMuonShowers(GMTOutputObjectMap &objMap, const edm::Event &event, const edm::EDGetTokenT< MuonShowerBxCollection > &showerToken)
Definition: MuonPacker.cc:28
Definition: event.py:1