Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:13

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(block, res, [](const l1t::EGamma& eg) { return eg; }, true, false, false);
0091     }
0092 
0093     bool CentralJetUnpackerLeft::unpack(const Block& block, UnpackerCollections* coll) {
0094       auto res = static_cast<CaloCollections*>(coll)->getJets();
0095       return process(block, res, [](const l1t::Jet& j) { return j; }, true, true, false);
0096     }
0097 
0098     bool ForwardJetUnpackerLeft::unpack(const Block& block, UnpackerCollections* coll) {
0099       auto res = static_cast<CaloCollections*>(coll)->getJets();
0100       return process(
0101           block,
0102           res,
0103           [](l1t::Jet j) {
0104             j.setHwQual(j.hwQual() | 2);
0105             return j;
0106           },
0107           true,
0108           false,
0109           false);
0110     }
0111 
0112     bool TauUnpackerLeft::unpack(const Block& block, UnpackerCollections* coll) {
0113       auto res = static_cast<CaloCollections*>(coll)->getTaus();
0114       return process(block, res, [](const l1t::Tau& t) { return t; }, true, true, true);
0115     }
0116 
0117     bool IsoTauUnpackerLeft::unpack(const Block& block, UnpackerCollections* coll) {
0118       auto res = static_cast<CaloCollections*>(coll)->getIsoTaus();
0119       return process(block, res, [](const l1t::Tau& t) { return t; }, true, true, true);
0120     }
0121 
0122     bool IsoEGammaUnpackerRight::unpack(const Block& block, UnpackerCollections* coll) {
0123       auto res = static_cast<CaloCollections*>(coll)->getEGammas();
0124       return process(
0125           block,
0126           res,
0127           [](l1t::EGamma eg) {
0128             eg.setHwIso(1);
0129             return eg;
0130           },
0131           false,
0132           true,
0133           false);
0134     }
0135 
0136     bool NonIsoEGammaUnpackerRight::unpack(const Block& block, UnpackerCollections* coll) {
0137       auto res = static_cast<CaloCollections*>(coll)->getEGammas();
0138       return process(block, res, [](const l1t::EGamma& eg) { return eg; }, false, false, false);
0139     }
0140 
0141     bool CentralJetUnpackerRight::unpack(const Block& block, UnpackerCollections* coll) {
0142       auto res = static_cast<CaloCollections*>(coll)->getJets();
0143       return process(block, res, [](const l1t::Jet& j) { return j; }, false, true, false);
0144     }
0145 
0146     bool ForwardJetUnpackerRight::unpack(const Block& block, UnpackerCollections* coll) {
0147       auto res = static_cast<CaloCollections*>(coll)->getJets();
0148       return process(
0149           block,
0150           res,
0151           [](l1t::Jet j) {
0152             j.setHwQual(j.hwQual() | 2);
0153             return j;
0154           },
0155           false,
0156           false,
0157           false);
0158     }
0159 
0160     bool TauUnpackerRight::unpack(const Block& block, UnpackerCollections* coll) {
0161       auto res = static_cast<CaloCollections*>(coll)->getTaus();
0162       return process(block, res, [](const l1t::Tau& t) { return t; }, false, true, true);
0163     }
0164 
0165     bool IsoTauUnpackerRight::unpack(const Block& block, UnpackerCollections* coll) {
0166       auto res = static_cast<CaloCollections*>(coll)->getIsoTaus();
0167       return process(block, res, [](const l1t::Tau& t) { return t; }, false, true, true);
0168     }
0169   }  // namespace stage1
0170 }  // namespace l1t
0171 
0172 DEFINE_L1T_UNPACKER(l1t::stage1::IsoEGammaUnpackerLeft);
0173 DEFINE_L1T_UNPACKER(l1t::stage1::NonIsoEGammaUnpackerLeft);
0174 DEFINE_L1T_UNPACKER(l1t::stage1::CentralJetUnpackerLeft);
0175 DEFINE_L1T_UNPACKER(l1t::stage1::ForwardJetUnpackerLeft);
0176 DEFINE_L1T_UNPACKER(l1t::stage1::TauUnpackerLeft);
0177 DEFINE_L1T_UNPACKER(l1t::stage1::IsoTauUnpackerLeft);
0178 DEFINE_L1T_UNPACKER(l1t::stage1::IsoEGammaUnpackerRight);
0179 DEFINE_L1T_UNPACKER(l1t::stage1::NonIsoEGammaUnpackerRight);
0180 DEFINE_L1T_UNPACKER(l1t::stage1::CentralJetUnpackerRight);
0181 DEFINE_L1T_UNPACKER(l1t::stage1::ForwardJetUnpackerRight);
0182 DEFINE_L1T_UNPACKER(l1t::stage1::TauUnpackerRight);
0183 DEFINE_L1T_UNPACKER(l1t::stage1::IsoTauUnpackerRight);