Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:50

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "EventFilter/L1TRawToDigi/plugins/PackerFactory.h"
0003 
0004 #include "CaloTokens.h"
0005 
0006 #include "L1TStage2Layer2Constants.h"
0007 #include "EGammaPacker.h"
0008 
0009 namespace l1t {
0010   namespace stage2 {
0011     Blocks EGammaPacker::pack(const edm::Event& event, const PackerTokens* toks) {
0012       edm::Handle<EGammaBxCollection> egs;
0013       event.getByToken(static_cast<const CommonTokens*>(toks)->getEGammaToken(), egs);
0014 
0015       std::vector<uint32_t> load1, load2;
0016 
0017       int nBx = 0;
0018       for (int i = egs->getFirstBX(); i <= egs->getLastBX(); ++i) {
0019         for (auto j = egs->begin(i); j != egs->end(i); ++j) {
0020           uint32_t packed_eta = abs(j->hwEta()) & 0x7F;
0021           if (j->hwEta() < 0) {
0022             packed_eta = (128 - packed_eta) | 1 << 7;
0023           }
0024 
0025           uint32_t word = std::min(j->hwPt(), 0x1FF) | packed_eta << 9 | (j->hwPhi() & 0xFF) << 17 |
0026                           (j->hwIso() & 0x3) << 25 | (j->hwQual() & 0x7) << 27;
0027 
0028           //Depending on the number, push onto the appropriate link
0029           if (load1.size() - nBx * l1t::stage2::layer2::demux::nEGPerLink < l1t::stage2::layer2::demux::nEGPerLink)
0030             load1.push_back(word);
0031           else
0032             load2.push_back(word);
0033         }
0034 
0035         // push zeroes if not enough EG; must do this for each BX and each link
0036         while (load1.size() - nBx * l1t::stage2::layer2::demux::nOutputFramePerBX <
0037                l1t::stage2::layer2::demux::nOutputFramePerBX)
0038           load1.push_back(0);
0039         while (load2.size() - nBx * l1t::stage2::layer2::demux::nOutputFramePerBX <
0040                l1t::stage2::layer2::demux::nOutputFramePerBX)
0041           load2.push_back(0);
0042 
0043         nBx++;
0044       }
0045 
0046       return {Block(b1_, load1), Block(b2_, load2)};
0047     }
0048 
0049   }  // namespace stage2
0050 }  // namespace l1t
0051 
0052 DEFINE_L1T_PACKER(l1t::stage2::GTEGammaPacker);
0053 DEFINE_L1T_PACKER(l1t::stage2::CaloEGammaPacker);