CMS 3D CMS Logo

MuonUnpacker.cc
Go to the documentation of this file.
4 
6 
7 #include "MuonUnpacker.h"
8 
9 namespace l1t {
10  namespace stage2 {
11  MuonUnpacker::MuonUnpacker() : muonCollection_(nullptr), muonShowerCollection_(nullptr), muonCopy_(0) {}
12 
14  LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize();
15  // process only if there is a payload
16  // If all BX block were zero suppressed the block header size is 0.
17  if (block.header().getSize() < 1) {
18  return true;
19  }
20 
21  auto payload = block.payload();
22 
23  int nBX, firstBX, lastBX;
24  // Check if per BX zero suppression was enabled
25  bool bxZsEnabled = ((block.header().getFlags() >> bxzs_enable_shift_) & 0x1) == 1;
26  // Calculate the total number of BXs
27  if (bxZsEnabled) {
28  BxBlockHeader bxHeader(payload.at(0));
29  nBX = bxHeader.getTotalBx();
30  } else {
31  nBX = int(ceil(block.header().getSize() / nWords_));
32  }
33  getBXRange(nBX, firstBX, lastBX);
34 
35  // Set the muon collection and the BX range
36  muonCollection_ = static_cast<L1TObjectCollections*>(coll)->getMuons(muonCopy_);
38  // Set the muon shower collection and the BX range
39  muonShowerCollection_ = static_cast<L1TObjectCollections*>(coll)->getMuonShowers(muonCopy_);
41 
42  LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;
43 
44  // Get the BX blocks and unpack them
45  auto bxBlocks = block.getBxBlocks(nWords_, bxZsEnabled);
46  for (const auto& bxBlock : bxBlocks) {
47  // Throw an exception if finding a corrupt BX header with out of range BX numbers
48  const auto bx = bxBlock.header().getBx();
49  if (bx < firstBX || bx > lastBX) {
50  throw cms::Exception("CorruptData")
51  << "Corrupt RAW data from FED " << fed_ << ", AMC " << block.amc().getAMCNumber() << ". BX number " << bx
52  << " in BX header is outside of the BX range [" << firstBX << "," << lastBX
53  << "] defined in the block header.";
54  }
55  unpackBx(bx, bxBlock.payload(), block.header().getID());
56  }
57  return true;
58  }
59 
61  const std::vector<uint32_t>& payload,
62  unsigned int blockID,
63  unsigned int startIdx) {
64  unsigned int i = startIdx + 2; // Only words 2-5 are "standard" muon words.
65  // Check if there are enough words left in the payload
66  if (startIdx + nWords_ <= payload.size()) {
67  // Unpacking showers.
68  // The shower from uGMT is transmitted via four links, each link
69  // carrying one of the bits of the shower. We therefore have to
70  // determine which link we're looking at and act accordingly.
71  // Output links are odd and input links are even.
72  int link_offset{0}; // This is correct for the uGT unpacker
73  if (fed_ == 1402) { // For uGMT we have to adjust the block/link ID
74  link_offset = 1;
75  }
76  unsigned linkID{(blockID - link_offset) / 2};
77 
78  // Try to get the shower for this BX and if it doesn't exist create an
79  // empty one and push it in.
80  // Note: We can't just create it for the first linkID, because in
81  // prinicple there could be a case where that is removed by the ZS.
82  MuonShower shower;
84  shower = muonShowerCollection_->at(bx, 0);
86  }
87  if (linkID == 0) { // OneNominal shower
89  } else if (linkID == 1) { // OneTight shower
91  }
92 
93  if (shower.isValid()) {
95  }
96 
97  for (unsigned nWord = 2; nWord < nWords_; nWord += 2) { // Only words 2-5 are "standard" muon words.
98  uint32_t raw_data_spare = payload[startIdx + 1];
99  uint32_t raw_data_00_31 = payload[i++];
100  uint32_t raw_data_32_63 = payload[i++];
101  LogDebug("L1T") << "raw_data_spare = 0x" << hex << raw_data_spare << " raw_data_00_31 = 0x" << raw_data_00_31
102  << " raw_data_32_63 = 0x" << raw_data_32_63;
103  // skip empty muons (hwPt == 0)
105  LogDebug("L1T") << "Muon hwPt zero. Skip.";
106  continue;
107  }
108 
109  Muon mu;
110 
112  mu, raw_data_spare, raw_data_00_31, raw_data_32_63, fed_, getAlgoVersion(), nWord / 2);
113 
114  LogDebug("L1T") << "Mu" << nWord / 2 << ": eta " << mu.hwEta() << " phi " << mu.hwPhi() << " pT " << mu.hwPt()
115  << " iso " << mu.hwIso() << " qual " << mu.hwQual() << " charge " << mu.hwCharge()
116  << " charge valid " << mu.hwChargeValid();
117 
119  }
120  } else {
121  edm::LogWarning("L1T") << "Only " << payload.size() - i << " 32 bit words in this BX but " << nWords_
122  << " are required. Not unpacking the data for BX " << bx << ".";
123  }
124  }
125  } // namespace stage2
126 } // namespace l1t
127 
constexpr int32_t ceil(float num)
unsigned int getAlgoVersion()
Definition: Unpacker.h:18
void unpackBx(int bx, const std::vector< uint32_t > &payload, unsigned int blockID, unsigned int startIdx=0)
Definition: MuonUnpacker.cc:60
void getBXRange(int nbx, int &first, int &last)
static constexpr unsigned bxzs_enable_shift_
Definition: MuonUnpacker.h:25
static constexpr unsigned nWords_
Definition: MuonUnpacker.h:24
delete x;
Definition: CaloConfig.h:22
bool isEmpty(int bx) const
void setOneTightInTime(const bool bit)
Definition: MuonShower.h:58
void setOneNominalInTime(const bool bit)
Definition: MuonShower.h:57
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: MuonUnpacker.cc:13
MuonShowerBxCollection * muonShowerCollection_
Definition: MuonUnpacker.h:28
Definition: Muon.py:1
bool isValid() const
Definition: MuonShower.cc:19
const T & at(int bx, unsigned i) const
unsigned int getTotalBx() const
Definition: BxBlock.h:27
static constexpr unsigned ptShift_
MuonBxCollection * muonCollection_
Definition: MuonUnpacker.h:27
void setBXRange(int bxFirst, int bxLast)
void erase(int bx, unsigned i)
static void fillMuon(Muon &mu, uint32_t raw_data_spare, uint32_t raw_data_00_31, uint32_t raw_data_32_63, int fed, unsigned int fw, int muInBx)
#define DEFINE_L1T_UNPACKER(type)
Log< level::Warning, false > LogWarning
static bool showerFired(uint32_t shower_word, int fedId, unsigned int fwId)
static constexpr unsigned ptMask_
void push_back(int bx, T object)
#define LogDebug(id)