File indexing completed on 2024-04-06 12:19:39
0001 #include "L1Trigger/DemonstratorTools/interface/codecs/etsums.h"
0002 #include "DataFormats/Math/interface/LorentzVector.h"
0003
0004 namespace l1t::demo::codecs {
0005
0006 ap_uint<64> encodeEtSum(const l1t::EtSum& etSum) {
0007 l1tmetemu::EtMiss etMiss;
0008 etMiss.Et.V = etSum.hwPt();
0009 etMiss.Phi = etSum.hwPhi();
0010 ap_uint<1> valid = (etSum.hwQual() > 0);
0011 ap_uint<64 - (l1tmetemu::kMETSize + l1tmetemu::kMETPhiSize + 1)> unassigned = 0;
0012 ap_uint<64> etSumWord = (unassigned, etMiss.Phi, etMiss.Et.range(), valid);
0013 return etSumWord;
0014 }
0015
0016
0017 std::array<std::vector<ap_uint<64>>, 1> encodeEtSums(const edm::View<l1t::EtSum>& etSums) {
0018 std::vector<ap_uint<64>> etSumWords;
0019
0020 for (const auto& etSum : etSums)
0021 etSumWords.push_back(encodeEtSum(etSum));
0022
0023 std::array<std::vector<ap_uint<64>>, 1> linkData;
0024
0025 for (size_t i = 0; i < linkData.size(); i++) {
0026
0027 etSumWords.resize(1, 0);
0028 linkData.at(i) = etSumWords;
0029 }
0030
0031 return linkData;
0032 }
0033
0034 std::vector<l1t::EtSum> decodeEtSums(const std::vector<ap_uint<64>>& frames) {
0035 std::vector<l1t::EtSum> etSums;
0036
0037 for (const auto& x : frames) {
0038 if (not x.test(0))
0039 break;
0040
0041 math::XYZTLorentzVector v(0, 0, 0, 0);
0042 l1t::EtSum s(
0043 v,
0044 l1t::EtSum::EtSumType::kMissingEt,
0045 l1tmetemu::METWord_t(x(l1tmetemu::kMETSize, 1)),
0046 0,
0047 l1tmetemu::METWordphi_t(x(l1tmetemu::kMETSize + l1tmetemu::kMETPhiSize, 1 + l1tmetemu::kMETSize)).to_int(),
0048 0);
0049 etSums.push_back(s);
0050 }
0051
0052 return etSums;
0053 }
0054
0055 }