Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"
0003 
0004 #include "L1Trigger/L1TCalorimeter/interface/CaloTools.h"
0005 
0006 #include "L1TObjectCollections.h"
0007 
0008 #include "L1TStage2Layer2Constants.h"
0009 #include "EGammaUnpacker.h"
0010 
0011 namespace l1t {
0012   namespace stage2 {
0013     EGammaUnpacker::EGammaUnpacker() : EGammaCopy_(0) {}
0014 
0015     bool EGammaUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
0016       using namespace l1t::stage2::layer2;
0017 
0018       LogDebug("L1T") << "Block ID  = " << block.header().getID() << " size = " << block.header().getSize();
0019 
0020       int nBX = int(ceil(block.header().getSize() / (double)demux::nOutputFramePerBX));  // 6 link frames per BX
0021 
0022       // Find the central, first and last BXs
0023       int firstBX = -(ceil((double)nBX / 2.) - 1);
0024       int lastBX;
0025       if (nBX % 2 == 0) {
0026         lastBX = ceil((double)nBX / 2.);
0027       } else {
0028         lastBX = ceil((double)nBX / 2.) - 1;
0029       }
0030 
0031       auto res_ = static_cast<L1TObjectCollections*>(coll)->getEGammas(EGammaCopy_);
0032       res_->setBXRange(firstBX, lastBX);
0033 
0034       LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;
0035 
0036       // Loop over multiple BX and then number of EG cands filling collection
0037       for (int bx = firstBX; bx <= lastBX; bx++) {
0038         for (unsigned iEG = 0; iEG < demux::nEGPerLink && iEG < block.header().getSize(); iEG++) {
0039           int iFrame = (bx - firstBX) * demux::nOutputFramePerBX + iEG;
0040           uint32_t raw_data = block.payload().at(iFrame);
0041 
0042           // skip padding to bring EG candidates up to 12 pre BX
0043           if (raw_data == 0)
0044             continue;
0045 
0046           l1t::EGamma eg = l1t::EGamma();
0047 
0048           eg.setHwPt(raw_data & 0x1FF);
0049 
0050           if (eg.hwPt() == 0)
0051             continue;
0052 
0053           int abs_eta = (raw_data >> 9) & 0x7F;
0054           if ((raw_data >> 16) & 0x1) {
0055             eg.setHwEta(-1 * (128 - abs_eta));
0056           } else {
0057             eg.setHwEta(abs_eta);
0058           }
0059 
0060           eg.setHwPhi((raw_data >> 17) & 0xFF);
0061           eg.setHwIso((raw_data >> 25) & 0x3);
0062           eg.setHwQual((raw_data >> 27) & 0x7);  // Assume 3 bits for now? leaves 2 spare bits
0063 
0064           LogDebug("L1T") << "EG: eta " << eg.hwEta() << " phi " << eg.hwPhi() << " pT " << eg.hwPt() << " iso "
0065                           << eg.hwIso() << " qual " << eg.hwQual();
0066 
0067           eg.setP4(l1t::CaloTools::p4Demux(&eg));
0068 
0069           res_->push_back(bx, eg);
0070         }
0071       }
0072 
0073       return true;
0074     }
0075   }  // namespace stage2
0076 }  // namespace l1t
0077 
0078 DEFINE_L1T_UNPACKER(l1t::stage2::EGammaUnpacker);