Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:01

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 
0003 #include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"
0004 
0005 #include "CaloCollections.h"
0006 #include "LegacyPhysCandUnpacker.h"
0007 
0008 template <typename T, typename F>
0009 bool process(const l1t::Block& block, BXVector<T>* coll, F modify) {
0010   LogDebug("L1T") << "Block ID  = " << block.header().getID() << " size = " << block.header().getSize();
0011 
0012   int nBX, firstBX, lastBX;
0013   nBX = int(ceil(block.header().getSize() / 2.));
0014   l1t::getBXRange(nBX, firstBX, lastBX);
0015 
0016   coll->setBXRange(firstBX, lastBX);
0017 
0018   LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;
0019 
0020   // Initialise index
0021   int unsigned i = 0;
0022 
0023   // Loop over multiple BX and then number of jets filling jet collection
0024   for (int bx = firstBX; bx <= lastBX; bx++) {
0025     uint32_t raw_data0 = block.payload()[i++];
0026     uint32_t raw_data1 = block.payload()[i++];
0027 
0028     uint16_t candbit[4];
0029     candbit[0] = raw_data0 & 0xFFFF;
0030     candbit[1] = (raw_data0 >> 16) & 0xFFFF;
0031     candbit[2] = raw_data1 & 0xFFFF;
0032     candbit[3] = (raw_data1 >> 16) & 0xFFFF;
0033 
0034     for (int icand = 0; icand < 4; icand++) {
0035       int candPt = candbit[icand] & 0x3F;
0036       int candEta = (candbit[icand] >> 6) & 0x7;
0037       int candEtasign = (candbit[icand] >> 9) & 0x1;
0038       int candPhi = (candbit[icand] >> 10) & 0x1F;
0039 
0040       T cand;
0041       cand.setHwPt(candPt);
0042       cand.setHwEta((candEtasign << 3) | candEta);
0043       cand.setHwPhi(candPhi);
0044       //int qualflag=cand.hwQual();
0045       //qualflag|= (candPt == 0x3F);
0046       //cand.setHwQual(qualflag);
0047 
0048       /* std::cout << "cand: eta " << cand.hwEta() << " phi " << cand.hwPhi() << " pT " << cand.hwPt() << " qual " << cand.hwQual() << std::endl; */
0049       //std::cout << cand.hwPt() << " @ " << cand.hwEta() << ", " << cand.hwPhi() << " > " << cand.hwQual() << " > " << cand.hwIso() << std::endl;
0050       coll->push_back(bx, modify(cand));
0051     }
0052   }
0053 
0054   return true;
0055 }
0056 
0057 namespace l1t {
0058   namespace stage1 {
0059     namespace legacy {
0060       bool IsoEGammaUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
0061         auto res = static_cast<CaloCollections*>(coll)->getEGammas();
0062         return process(block, res, [](l1t::EGamma eg) {
0063           eg.setHwIso(1);
0064           return eg;
0065         });
0066       }
0067 
0068       bool NonIsoEGammaUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
0069         auto res = static_cast<CaloCollections*>(coll)->getEGammas();
0070         return process(block, res, [](const l1t::EGamma& eg) { return eg; });
0071       }
0072 
0073       bool CentralJetUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
0074         auto res = static_cast<CaloCollections*>(coll)->getJets();
0075 
0076         if (res->size(0) != 0)
0077           edm::LogWarning("L1T") << "Need to unpack central jets before forward ones";
0078 
0079         return process(block, res, [](const l1t::Jet& j) { return j; });
0080       }
0081 
0082       bool ForwardJetUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
0083         auto res = static_cast<CaloCollections*>(coll)->getJets();
0084 
0085         if (res->size(0) != 4)
0086           edm::LogWarning("L1T") << "Need to unpack central jets before forward ones";
0087 
0088         return process(block, res, [](l1t::Jet j) {
0089           j.setHwQual(j.hwQual() | 2);
0090           return j;
0091         });
0092       }
0093 
0094       bool TauUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
0095         auto res = static_cast<CaloCollections*>(coll)->getTaus();
0096         return process(block, res, [](const l1t::Tau& t) { return t; });
0097       }
0098 
0099       bool IsoTauUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
0100         auto res = static_cast<CaloCollections*>(coll)->getIsoTaus();
0101         return process(block, res, [](const l1t::Tau& t) { return t; });
0102       }
0103     }  // namespace legacy
0104   }    // namespace stage1
0105 }  // namespace l1t
0106 
0107 DEFINE_L1T_UNPACKER(l1t::stage1::legacy::IsoEGammaUnpacker);
0108 DEFINE_L1T_UNPACKER(l1t::stage1::legacy::NonIsoEGammaUnpacker);
0109 DEFINE_L1T_UNPACKER(l1t::stage1::legacy::CentralJetUnpacker);
0110 DEFINE_L1T_UNPACKER(l1t::stage1::legacy::ForwardJetUnpacker);
0111 DEFINE_L1T_UNPACKER(l1t::stage1::legacy::TauUnpacker);
0112 DEFINE_L1T_UNPACKER(l1t::stage1::legacy::IsoTauUnpacker);