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 "L1Trigger/L1TCalorimeter/interface/CaloTools.h"
0005 
0006 #include "CaloTokens.h"
0007 #include "CaloTowerPacker.h"
0008 
0009 namespace l1t {
0010   namespace stage2 {
0011     Blocks CaloTowerPacker::pack(const edm::Event& event, const PackerTokens* toks) {
0012       edm::Handle<CaloTowerBxCollection> towers;
0013       event.getByToken(static_cast<const CaloTokens*>(toks)->getCaloTowerToken(), towers);
0014 
0015       Blocks res;
0016 
0017       for (int i = towers->getFirstBX(); i <= towers->getLastBX(); ++i) {
0018         for (int phi = 1; phi <= 72; phi = phi + 2) {  // Two phi values per link
0019 
0020           unsigned int id = 2 * phi - 2;  // Block IDs start at zero and span even numbers up to 142
0021           std::vector<uint32_t> load;
0022 
0023           for (int eta = 1; eta <= 41; eta++) {  // This is abs(eta) since +/- eta are interleaved in time
0024 
0025             if (eta == CaloTools::kHFBegin)
0026               continue;
0027 
0028             // Get four towers +/- eta and phi and phi+1 to all be packed in this loop
0029             l1t::CaloTower t1 = towers->at(i, l1t::CaloTools::caloTowerHash(eta, phi));
0030             l1t::CaloTower t2 = towers->at(i, l1t::CaloTools::caloTowerHash(eta, phi + 1));
0031             l1t::CaloTower t3 = towers->at(i, l1t::CaloTools::caloTowerHash(-1 * eta, phi));
0032             l1t::CaloTower t4 = towers->at(i, l1t::CaloTools::caloTowerHash(-1 * eta, phi + 1));
0033 
0034             // Merge phi and phi+1 into one block (phi is LSW, phi+1 is MSW)
0035             uint32_t word1 = std::min(t1.hwPt(), 0x1FF) | (t1.hwEtRatio() & 0x7) << 9 | (t1.hwQual() & 0xF) << 12;
0036 
0037             word1 = word1 | std::min(t2.hwPt(), 0x1FF) << 16 | (t2.hwEtRatio() & 0x7) << 25 | (t2.hwQual() & 0xF) << 28;
0038 
0039             load.push_back(word1);
0040 
0041             // Do it all again for -eta
0042 
0043             uint32_t word2 = std::min(t3.hwPt(), 0x1FF) | (t3.hwEtRatio() & 0x7) << 9 | (t3.hwQual() & 0xF) << 12;
0044 
0045             word2 = word2 | std::min(t4.hwPt(), 0x1FF) << 16 | (t4.hwEtRatio() & 0x7) << 25 | (t4.hwQual() & 0xF) << 28;
0046 
0047             load.push_back(word2);
0048           }
0049 
0050           res.push_back(Block(id, load));
0051         }
0052       }
0053       return res;
0054     }
0055   }  // namespace stage2
0056 }  // namespace l1t
0057 
0058 DEFINE_L1T_PACKER(l1t::stage2::CaloTowerPacker);