File indexing completed on 2024-04-06 12:10:52
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 "TauUnpacker.h"
0010
0011 namespace l1t {
0012 namespace stage2 {
0013 TauUnpacker::TauUnpacker() : TauCopy_(0) {}
0014
0015 bool TauUnpacker::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() / demux::nOutputFramePerBX));
0021
0022
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)->getTaus(TauCopy_);
0032 res_->setBXRange(firstBX, lastBX);
0033
0034 LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;
0035
0036
0037 for (int bx = firstBX; bx <= lastBX; bx++) {
0038 for (unsigned iTau = 0; iTau < demux::nTauPerLink && iTau < block.header().getSize(); iTau++) {
0039 int iFrame = (bx - firstBX) * demux::nOutputFramePerBX + iTau;
0040
0041 uint32_t raw_data = block.payload().at(iFrame);
0042
0043 if (raw_data == 0)
0044 continue;
0045
0046 l1t::Tau tau = l1t::Tau();
0047
0048 tau.setHwPt(raw_data & 0x1FF);
0049
0050 if (tau.hwPt() == 0)
0051 continue;
0052
0053 int abs_eta = (raw_data >> 9) & 0x7F;
0054 if ((raw_data >> 16) & 0x1) {
0055 tau.setHwEta(-1 * (128 - abs_eta));
0056 } else {
0057 tau.setHwEta(abs_eta);
0058 }
0059
0060 tau.setHwPhi((raw_data >> 17) & 0xFF);
0061 tau.setHwIso((raw_data >> 25) & 0x3);
0062 tau.setHwQual((raw_data >> 27) & 0x7);
0063
0064
0065 LogDebug("L1T") << "Tau: eta " << tau.hwEta() << " phi " << tau.hwPhi() << " pT " << tau.hwPt() << " iso "
0066 << tau.hwIso() << " qual " << tau.hwQual();
0067
0068 tau.setP4(l1t::CaloTools::p4Demux(&tau));
0069
0070 res_->push_back(bx, tau);
0071 }
0072 }
0073
0074 return true;
0075 }
0076 }
0077 }
0078
0079 DEFINE_L1T_UNPACKER(l1t::stage2::TauUnpacker);