File indexing completed on 2023-03-17 10:59:59
0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "EventFilter/L1TRawToDigi/plugins/PackerFactory.h"
0003
0004 #include "CaloTokens.h"
0005 #include "HFRingPacker.h"
0006
0007 namespace l1t {
0008 namespace stage1 {
0009 Blocks HFRingPacker::pack(const edm::Event& event, const PackerTokens* toks) {
0010 edm::Handle<EtSumBxCollection> etSums;
0011 event.getByToken(static_cast<const CaloTokens*>(toks)->getEtSumToken(), etSums);
0012
0013 edm::Handle<CaloSpareBxCollection> calosparesHFBitCounts;
0014 event.getByToken(static_cast<const CaloTokens*>(toks)->getCaloSpareHFBitCountsToken(), calosparesHFBitCounts);
0015
0016 edm::Handle<CaloSpareBxCollection> calosparesHFRingSums;
0017 event.getByToken(static_cast<const CaloTokens*>(toks)->getCaloSpareHFRingSumsToken(), calosparesHFRingSums);
0018
0019 std::vector<uint32_t> load;
0020
0021 for (int i = etSums->getFirstBX(); i <= etSums->getLastBX(); ++i) {
0022 int n = 0;
0023
0024 int hfbitcount = 0;
0025 int hfringsum = 0;
0026 int htmissphi = 0;
0027 int htmiss = 0;
0028
0029 int flaghtmiss = 0;
0030
0031 for (auto j = etSums->begin(i); j != etSums->end(i) && n < 4; ++j, ++n) {
0032 if (j->getType() == l1t::EtSum::kMissingHt) {
0033 flaghtmiss = j->hwQual() & 0x1;
0034 htmiss = std::min(j->hwPt(), 0x7F);
0035 htmissphi = std::min(j->hwPhi(), 0x1F);
0036 }
0037 }
0038
0039 n = 0;
0040
0041 for (auto j = calosparesHFBitCounts->begin(i); j != calosparesHFBitCounts->end(i) && n < 2; ++j, ++n) {
0042 hfbitcount = std::min(j->hwPt(), 0xFFF);
0043 }
0044
0045 n = 0;
0046
0047 for (auto j = calosparesHFRingSums->begin(i); j != calosparesHFRingSums->end(i) && n < 2; ++j, ++n) {
0048 hfringsum = std::min(j->hwPt(), 0xFFF);
0049 }
0050
0051 uint16_t object[4] = {0, 0, 0, 0};
0052
0053 object[0] = hfbitcount | ((hfringsum & 0x7) << 12);
0054 object[1] = htmissphi | ((htmiss & 0x7F) << 5) | (flaghtmiss << 12) | (0x1 << 14);
0055 object[2] = ((hfringsum >> 3) & 0x1FF) | (0x1) << 10 | (0x1) << 12 | (0x1) << 14;
0056 object[3] = 0x1 | (0x1 << 2) | (0x1 << 4) | (0x1 << 6) | (0x1 << 8) | (0x1 << 10) | (0x1 << 12) | (0x1 << 14);
0057
0058 uint32_t word0 = (object[0] & 0xFFFF) | ((object[1] & 0xFFFF) << 16);
0059 uint32_t word1 = (object[2] & 0xFFFF) | ((object[3] & 0xFFFF) << 16);
0060
0061 word0 |= (1 << 31) | (1 << 15);
0062 word1 |= ((i == 0) << 31) | ((i == 0) << 15);
0063
0064 load.push_back(word0);
0065 load.push_back(word1);
0066 }
0067
0068 return {Block(7, load)};
0069 }
0070 }
0071 }
0072
0073 DEFINE_L1T_PACKER(l1t::stage1::HFRingPacker);