Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #define EDM_ML_DEBUG 1
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"
0006 
0007 #include "L1Trigger/L1TCalorimeter/interface/CaloTools.h"
0008 
0009 #include "CaloCollections.h"
0010 #include "MPUnpacker.h"
0011 
0012 namespace l1t {
0013   namespace stage2 {
0014     bool MPUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
0015       LogDebug("L1T") << "Block ID  = " << block.header().getID() << " size = " << block.header().getSize()
0016                       << " AMC = " << block.amc().getAMCNumber();
0017 
0018       // check this is the correct MP
0019       unsigned int amc = block.amc().getAMCNumber();
0020       unsigned int bxid = block.amc().getBX();
0021       LogDebug("L1T") << "Unpacking AMC " << amc << " for BX " << bxid;
0022 
0023       auto res1_ = static_cast<CaloCollections*>(coll)->getMPJets();
0024       auto res2_ = static_cast<CaloCollections*>(coll)->getMPEtSums();
0025       auto res3_ = static_cast<CaloCollections*>(coll)->getMPEGammas();
0026       auto res4_ = static_cast<CaloCollections*>(coll)->getMPTaus();
0027 
0028       res1_->setBXRange(0, 0);
0029       res2_->setBXRange(0, 0);
0030       res3_->setBXRange(0, 0);
0031       res4_->setBXRange(0, 0);
0032 
0033       // Initialise frame indices for each data type
0034       int unsigned fet = 0;
0035       int unsigned fht = 1;
0036       int unsigned fjet = 6;
0037       int unsigned feg = 2;
0038       int unsigned ftau = 4;
0039 
0040       //      ===== Jets and Sums =====
0041 
0042       // ET / MET(x) / MET (y)
0043 
0044       uint32_t raw_data = block.payload()[fet];
0045 
0046       l1t::EtSum et = l1t::EtSum();
0047 
0048       et.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFFFF) << 16) >> 16);
0049       //et.setHwPt(raw_data & 0xFFFFF);
0050       switch (block.header().getID()) {
0051         case 123:
0052           et.setType(l1t::EtSum::kTotalEt);
0053           break;
0054         case 121:
0055           et.setType(l1t::EtSum::kTotalEtx);
0056           break;
0057         case 127:
0058           et.setType(l1t::EtSum::kTotalEty);
0059           break;
0060         case 125:
0061           et.setType(l1t::EtSum::kTotalEt);
0062           break;
0063         case 131:
0064           et.setType(l1t::EtSum::kTotalEtx);
0065           break;
0066         case 129:
0067           et.setType(l1t::EtSum::kTotalEty);
0068           break;
0069         default:
0070           break;
0071       }
0072 
0073       LogDebug("L1T") << "ET/METx/METy: pT " << et.hwPt();
0074 
0075       res2_->push_back(0, et);
0076 
0077       // HT / MHT(x)/ MHT (y)
0078 
0079       raw_data = block.payload()[fht];
0080 
0081       l1t::EtSum ht = l1t::EtSum();
0082 
0083       //ht.setHwPt(raw_data & 0xFFFFF);
0084       ht.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFFFF) << 16) >> 16);
0085       switch (block.header().getID()) {
0086         case 123:
0087           ht.setType(l1t::EtSum::kTotalHt);
0088           break;
0089         case 121:
0090           ht.setType(l1t::EtSum::kTotalHtx);
0091           break;
0092         case 127:
0093           ht.setType(l1t::EtSum::kTotalHty);
0094           break;
0095         case 125:
0096           ht.setType(l1t::EtSum::kTotalHt);
0097           break;
0098         case 131:
0099           ht.setType(l1t::EtSum::kTotalHtx);
0100           break;
0101         case 129:
0102           ht.setType(l1t::EtSum::kTotalHty);
0103           break;
0104         default:
0105           break;
0106       }
0107 
0108       LogDebug("L1T") << "HT/MHTx/MHTy: pT " << ht.hwPt();
0109 
0110       res2_->push_back(0, ht);
0111 
0112       // Two jets
0113       for (unsigned nJet = 0; nJet < 2; nJet++) {
0114         raw_data = block.payload()[fjet + nJet];
0115 
0116         if (raw_data == 0)
0117           continue;
0118 
0119         l1t::Jet jet = l1t::Jet();
0120 
0121         int etasign = 1;
0122         if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
0123           etasign = -1;
0124         }
0125 
0126         LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
0127 
0128         int mpEta = etasign * (raw_data & 0x3F);
0129         jet.setHwEta(CaloTools::caloEta(mpEta));
0130         jet.setHwPhi((raw_data >> 6) & 0x7F);
0131         jet.setHwPt((raw_data >> 13) & 0xFFFF);
0132 
0133         LogDebug("L1T") << "Jet: eta " << jet.hwEta() << " phi " << jet.hwPhi() << " pT " << jet.hwPt() << " qual "
0134                         << jet.hwQual();
0135 
0136         jet.setP4(l1t::CaloTools::p4MP(&jet));
0137         res1_->push_back(0, jet);
0138 
0139         // Push them back in the right place (for checking sorting)
0140         /*
0141        int blockID = block.header().getID();
0142        int nPos=0, nNeg=0;
0143        for (unsigned i=0; i<res1_->size(0); i++)
0144          res1_->at(0,i).hwEta()>0 ? nPos++ : nNeg++;
0145        
0146        if (nJet==1) res1_->push_back(0,jet);
0147        else if (nJet==0) {
0148          if (blockID==123) {
0149            res1_->push_back(0,jet);
0150          }
0151          if (blockID==121) {
0152            if (nPos==1) res1_->push_back(0,jet);
0153            else if (nPos==2) res1_->insert(0,1,jet);
0154          }
0155          if (blockID==127) {
0156            if (nPos==2) res1_->push_back(0,jet);
0157            else if (nPos>2) res1_->insert(0,2,jet);
0158          }
0159          if (blockID==125) {
0160            res1_->push_back(0,jet);
0161          }
0162          if (blockID==131) {
0163            if (nNeg==1) res1_->push_back(0,jet);
0164            else if (nNeg==2) res1_->insert(0,nPos+1,jet);
0165          }
0166          if (blockID==129) {
0167            if (nNeg==2) res1_->push_back(0,jet);
0168            else if (nNeg>2) res1_->insert(0,nPos+2,jet);
0169          }
0170        }
0171        */
0172       }
0173 
0174       //      ===== EGammas =====
0175 
0176       // Two EGammas
0177 
0178       for (unsigned nEG = 0; nEG < 2; nEG++) {
0179         raw_data = block.payload()[feg + nEG];
0180 
0181         if (raw_data == 0)
0182           continue;
0183 
0184         l1t::EGamma eg = l1t::EGamma();
0185 
0186         int etasign = 1;
0187         if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
0188           etasign = -1;
0189         }
0190 
0191         LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
0192 
0193         eg.setHwEta(etasign * ((raw_data >> 4) & 0x3F));
0194         eg.setHwPhi((raw_data >> 10) & 0x7F);
0195         eg.setHwPt((raw_data >> 21) & 0x3FF);
0196         eg.setHwQual(((raw_data >> 3) & 0x1) + (((raw_data >> 1) & 0x1) << 2));  //ECalFG + EGammaLikeShape
0197         eg.setHwIso(raw_data & 0x1);
0198 
0199         LogDebug("L1T") << "Egamma: eta " << eg.hwEta() << " phi " << eg.hwPhi() << " pT " << eg.hwPt() << " qual "
0200                         << eg.hwQual();
0201 
0202         eg.setP4(l1t::CaloTools::p4MP(&eg));
0203         res3_->push_back(0, eg);
0204       }
0205 
0206       //      ===== Taus =====
0207 
0208       // Two taus
0209 
0210       for (unsigned nTau = 0; nTau < 2; nTau++) {
0211         raw_data = block.payload()[ftau + nTau];
0212 
0213         if (raw_data == 0)
0214           continue;
0215 
0216         l1t::Tau tau = l1t::Tau();
0217 
0218         int etasign = 1;
0219         if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
0220           etasign = -1;
0221         }
0222 
0223         LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
0224 
0225         tau.setHwEta(etasign * ((raw_data >> 4) & 0x3F));
0226         tau.setHwPhi((raw_data >> 10) & 0x7F);
0227         tau.setHwPt((raw_data >> 21) & 0x3FF);
0228         tau.setHwQual(((raw_data >> 3) & 0x1) + (((raw_data >> 1) & 0x1) << 2));
0229         tau.setHwIso(raw_data & 0x1);
0230 
0231         // tau.setHwEta(etasign*((raw_data >> 9) & 0x7F));
0232         // tau.setHwPhi((raw_data >> 17) & 0xFF);
0233         // tau.setHwPt(raw_data & 0x1FF);
0234         // tau.setHwQual(((raw_data >> 26) & 0x1)); //ECalFG + TauLikeShape
0235         // tau.setHwIso(((raw_data >> 25) & 0x1) + ((raw_data >> 26) & 0x1) + ((raw_data >> 27) & 0x1));
0236 
0237         LogDebug("L1T") << "Tau: eta " << tau.hwEta() << " phi " << tau.hwPhi() << " pT " << tau.hwPt() << " qual "
0238                         << tau.hwQual();
0239 
0240         tau.setP4(l1t::CaloTools::p4MP(&tau));
0241         res4_->push_back(0, tau);
0242       }
0243 
0244       return true;
0245     }
0246   }  // namespace stage2
0247 }  // namespace l1t
0248 
0249 DEFINE_L1T_UNPACKER(l1t::stage2::MPUnpacker);