Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Framework/interface/MakerMacros.h"
0002 #include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"
0003 
0004 #include "CaloCollections.h"
0005 #include "PhysCandUnpacker.h"
0006 
0007 template <typename T, typename F>
0008 bool process(const l1t::Block& block, BXVector<T>* coll, F modify, bool isleft, bool isfirst, bool istau) {
0009   LogDebug("L1T") << "Block ID  = " << block.header().getID() << " size = " << block.header().getSize();
0010 
0011   int nBX, firstBX, lastBX;
0012   nBX = int(ceil(block.header().getSize() / 2.));
0013   l1t::getBXRange(nBX, firstBX, lastBX);
0014 
0015   coll->setBXRange(firstBX, lastBX);
0016 
0017   LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;
0018 
0019   // Initialise index
0020   int unsigned i = 0;
0021 
0022   // Loop over multiple BX and then number of jets filling jet collection
0023   for (int bx = firstBX; bx <= lastBX; bx++) {
0024     if (!istau)
0025       coll->resize(bx, 8);
0026     else
0027       coll->resize(bx, 4);
0028 
0029     uint32_t raw_data0 = block.payload()[i++];
0030     uint32_t raw_data1 = block.payload()[i++];
0031 
0032     uint16_t candbit[2];
0033     candbit[0] = raw_data0 & 0xFFFF;
0034     candbit[1] = raw_data1 & 0xFFFF;
0035 
0036     for (int icand = 0; icand < 2; icand++) {
0037       int candPt = candbit[icand] & 0x3F;
0038       int candEta = (candbit[icand] >> 6) & 0x7;
0039       int candEtasign = (candbit[icand] >> 9) & 0x1;
0040       int candPhi = (candbit[icand] >> 10) & 0x1F;
0041 
0042       T cand;
0043       cand.setHwPt(candPt);
0044       cand.setHwEta((candEtasign << 3) | candEta);
0045       cand.setHwPhi(candPhi);
0046       //int qualflag=cand.hwQual();
0047       //qualflag|= (candPt == 0x3F);
0048       //cand.setHwQual(qualflag);
0049 
0050       /* std::cout << "cand: eta " << cand.hwEta() << " phi " << cand.hwPhi() << " pT " << cand.hwPt() << " qual " << cand.hwQual() << std::endl; */
0051       //std::cout << cand.hwPt() << " @ " << cand.hwEta() << ", " << cand.hwPhi() << " > " << cand.hwQual() << " > " << cand.hwIso() << std::endl;
0052 
0053       if (isfirst) {
0054         if (isleft) {
0055           coll->set(bx, 2 * icand, modify(cand));
0056         } else if (!isleft) {
0057           coll->set(bx, 2 * icand + 1, modify(cand));
0058         }
0059       } else if (!isfirst) {
0060         if (isleft) {
0061           coll->set(bx, 2 * icand + 4, modify(cand));
0062         } else if (!isleft) {
0063           coll->set(bx, 2 * icand + 5, modify(cand));
0064         }
0065       }
0066     }
0067   }
0068 
0069   return true;
0070 }
0071 
0072 namespace l1t {
0073   namespace stage1 {
0074     bool IsoEGammaUnpackerLeft::unpack(const Block& block, UnpackerCollections* coll) {
0075       auto res = static_cast<CaloCollections*>(coll)->getEGammas();
0076       return process(
0077           block,
0078           res,
0079           [](l1t::EGamma eg) {
0080             eg.setHwIso(1);
0081             return eg;
0082           },
0083           true,
0084           true,
0085           false);
0086     }
0087 
0088     bool NonIsoEGammaUnpackerLeft::unpack(const Block& block, UnpackerCollections* coll) {
0089       auto res = static_cast<CaloCollections*>(coll)->getEGammas();
0090       return process(
0091           block, res, [](const l1t::EGamma& eg) { return eg; }, true, false, false);
0092     }
0093 
0094     bool CentralJetUnpackerLeft::unpack(const Block& block, UnpackerCollections* coll) {
0095       auto res = static_cast<CaloCollections*>(coll)->getJets();
0096       return process(
0097           block, res, [](const l1t::Jet& j) { return j; }, true, true, false);
0098     }
0099 
0100     bool ForwardJetUnpackerLeft::unpack(const Block& block, UnpackerCollections* coll) {
0101       auto res = static_cast<CaloCollections*>(coll)->getJets();
0102       return process(
0103           block,
0104           res,
0105           [](l1t::Jet j) {
0106             j.setHwQual(j.hwQual() | 2);
0107             return j;
0108           },
0109           true,
0110           false,
0111           false);
0112     }
0113 
0114     bool TauUnpackerLeft::unpack(const Block& block, UnpackerCollections* coll) {
0115       auto res = static_cast<CaloCollections*>(coll)->getTaus();
0116       return process(
0117           block, res, [](const l1t::Tau& t) { return t; }, true, true, true);
0118     }
0119 
0120     bool IsoTauUnpackerLeft::unpack(const Block& block, UnpackerCollections* coll) {
0121       auto res = static_cast<CaloCollections*>(coll)->getIsoTaus();
0122       return process(
0123           block, res, [](const l1t::Tau& t) { return t; }, true, true, true);
0124     }
0125 
0126     bool IsoEGammaUnpackerRight::unpack(const Block& block, UnpackerCollections* coll) {
0127       auto res = static_cast<CaloCollections*>(coll)->getEGammas();
0128       return process(
0129           block,
0130           res,
0131           [](l1t::EGamma eg) {
0132             eg.setHwIso(1);
0133             return eg;
0134           },
0135           false,
0136           true,
0137           false);
0138     }
0139 
0140     bool NonIsoEGammaUnpackerRight::unpack(const Block& block, UnpackerCollections* coll) {
0141       auto res = static_cast<CaloCollections*>(coll)->getEGammas();
0142       return process(
0143           block, res, [](const l1t::EGamma& eg) { return eg; }, false, false, false);
0144     }
0145 
0146     bool CentralJetUnpackerRight::unpack(const Block& block, UnpackerCollections* coll) {
0147       auto res = static_cast<CaloCollections*>(coll)->getJets();
0148       return process(
0149           block, res, [](const l1t::Jet& j) { return j; }, false, true, false);
0150     }
0151 
0152     bool ForwardJetUnpackerRight::unpack(const Block& block, UnpackerCollections* coll) {
0153       auto res = static_cast<CaloCollections*>(coll)->getJets();
0154       return process(
0155           block,
0156           res,
0157           [](l1t::Jet j) {
0158             j.setHwQual(j.hwQual() | 2);
0159             return j;
0160           },
0161           false,
0162           false,
0163           false);
0164     }
0165 
0166     bool TauUnpackerRight::unpack(const Block& block, UnpackerCollections* coll) {
0167       auto res = static_cast<CaloCollections*>(coll)->getTaus();
0168       return process(
0169           block, res, [](const l1t::Tau& t) { return t; }, false, true, true);
0170     }
0171 
0172     bool IsoTauUnpackerRight::unpack(const Block& block, UnpackerCollections* coll) {
0173       auto res = static_cast<CaloCollections*>(coll)->getIsoTaus();
0174       return process(
0175           block, res, [](const l1t::Tau& t) { return t; }, false, true, true);
0176     }
0177   }  // namespace stage1
0178 }  // namespace l1t
0179 
0180 DEFINE_L1T_UNPACKER(l1t::stage1::IsoEGammaUnpackerLeft);
0181 DEFINE_L1T_UNPACKER(l1t::stage1::NonIsoEGammaUnpackerLeft);
0182 DEFINE_L1T_UNPACKER(l1t::stage1::CentralJetUnpackerLeft);
0183 DEFINE_L1T_UNPACKER(l1t::stage1::ForwardJetUnpackerLeft);
0184 DEFINE_L1T_UNPACKER(l1t::stage1::TauUnpackerLeft);
0185 DEFINE_L1T_UNPACKER(l1t::stage1::IsoTauUnpackerLeft);
0186 DEFINE_L1T_UNPACKER(l1t::stage1::IsoEGammaUnpackerRight);
0187 DEFINE_L1T_UNPACKER(l1t::stage1::NonIsoEGammaUnpackerRight);
0188 DEFINE_L1T_UNPACKER(l1t::stage1::CentralJetUnpackerRight);
0189 DEFINE_L1T_UNPACKER(l1t::stage1::ForwardJetUnpackerRight);
0190 DEFINE_L1T_UNPACKER(l1t::stage1::TauUnpackerRight);
0191 DEFINE_L1T_UNPACKER(l1t::stage1::IsoTauUnpackerRight);