Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-26 22:29:26

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 "L1TStage2Layer2Constants.h"
0011 #include "MPUnpacker_0x10010010.h"
0012 
0013 namespace l1t {
0014   namespace stage2 {
0015     bool MPUnpacker_0x10010010::unpack(const Block& block, UnpackerCollections* coll) {
0016       LogDebug("L1T") << "Block ID  = " << block.header().getID() << " size = " << block.header().getSize()
0017                       << " AMC = " << block.amc().getAMCNumber();
0018 
0019       // check this is the correct MP
0020       const unsigned int tmt = block.amc().getBoardID() - l1t::stage2::layer2::mp::offsetBoardId + 1;
0021       const unsigned int bxid = block.amc().getBX();
0022 
0023       // handle offset between BC0 marker and actual BC0...
0024       //if( (tmt-1) != ((bxid-1+3)%9) ) return true;
0025       LogDebug("L1T") << "Unpacking TMT # " << tmt << " for BX " << bxid;
0026 
0027       auto res1_ = static_cast<CaloCollections*>(coll)->getMPJets();
0028       auto res2_ = static_cast<CaloCollections*>(coll)->getMPEtSums();
0029       auto res3_ = static_cast<CaloCollections*>(coll)->getMPEGammas();
0030       auto res4_ = static_cast<CaloCollections*>(coll)->getMPTaus();
0031 
0032       res1_->setBXRange(0, 0);
0033       res2_->setBXRange(0, 0);
0034       res3_->setBXRange(0, 0);
0035       res4_->setBXRange(0, 0);
0036 
0037       // Initialise frame indices for each data type
0038       const int unsigned fet = 0;
0039       const int unsigned fht = 2;
0040       const int unsigned feg = 4;
0041       const int unsigned ftau = 6;
0042       const int unsigned fjet = 8;
0043       const int unsigned faux = 10;
0044 
0045       //      ===== Jets and Sums =====
0046 
0047       // ET / MET(x) / MET (y) with HF (configurable)
0048 
0049       uint32_t raw_data = block.payload()[fet];
0050 
0051       l1t::EtSum ethf = l1t::EtSum();
0052 
0053       switch (block.header().getID()) {
0054         case 123:  // 61
0055           ethf.setType(l1t::EtSum::kTotalEtHF);
0056           ethf.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
0057           break;
0058         case 121:  // 60
0059           ethf.setType(l1t::EtSum::kTotalEtxHF);
0060           ethf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0061           break;
0062         case 127:  // 63
0063           ethf.setType(l1t::EtSum::kTotalEtyHF);
0064           ethf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0065           break;
0066         case 125:  // 62
0067           ethf.setType(l1t::EtSum::kTotalEtHF);
0068           ethf.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
0069           break;
0070         case 131:  // 65
0071           ethf.setType(l1t::EtSum::kTotalEtxHF);
0072           ethf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0073           break;
0074         case 129:  // 64
0075           ethf.setType(l1t::EtSum::kTotalEtyHF);
0076           ethf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0077           break;
0078         default:
0079           break;
0080       }
0081 
0082       LogDebug("L1T") << "ET/METx/METy: pT " << ethf.hwPt();
0083 
0084       res2_->push_back(0, ethf);
0085 
0086       // ET / MET(x) / MET (y) without HF
0087 
0088       raw_data = block.payload()[fet + 1];
0089 
0090       l1t::EtSum etNoHF = l1t::EtSum();
0091 
0092       switch (block.header().getID()) {
0093         case 123:  // 61
0094           etNoHF.setType(l1t::EtSum::kTotalEt);
0095           etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
0096           break;
0097         case 121:  // 60
0098           etNoHF.setType(l1t::EtSum::kTotalEtx);
0099           etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0100           break;
0101         case 127:  // 63
0102           etNoHF.setType(l1t::EtSum::kTotalEty);
0103           etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0104           break;
0105         case 125:  // 62
0106           etNoHF.setType(l1t::EtSum::kTotalEt);
0107           etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
0108           break;
0109         case 131:  // 65
0110           etNoHF.setType(l1t::EtSum::kTotalEtx);
0111           etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0112           break;
0113         case 129:  // 64
0114           etNoHF.setType(l1t::EtSum::kTotalEty);
0115           etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0116           break;
0117         default:
0118           break;
0119       }
0120 
0121       LogDebug("L1T") << "ET/METx/METy (no HF): pT " << etNoHF.hwPt();
0122 
0123       res2_->push_back(0, etNoHF);
0124 
0125       // HT / MHT(x)/ MHT (y) with HF
0126 
0127       raw_data = block.payload()[fht];
0128 
0129       l1t::EtSum hthf = l1t::EtSum();
0130 
0131       switch (block.header().getID()) {
0132         case 123:  // 61
0133           hthf.setType(l1t::EtSum::kTotalHtHF);
0134           hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
0135           break;
0136         case 121:  // 60
0137           hthf.setType(l1t::EtSum::kTotalHtxHF);
0138           hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0139           break;
0140         case 127:  // 63
0141           hthf.setType(l1t::EtSum::kTotalHtyHF);
0142           hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0143           break;
0144         case 125:  // 62
0145           hthf.setType(l1t::EtSum::kTotalHtHF);
0146           hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
0147           break;
0148         case 131:  // 65
0149           hthf.setType(l1t::EtSum::kTotalHtxHF);
0150           hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0151           break;
0152         case 129:  // 64
0153           hthf.setType(l1t::EtSum::kTotalHtyHF);
0154           hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0155           break;
0156         default:
0157           break;
0158       }
0159 
0160       LogDebug("L1T") << "HTHF/MHTHFx/MHTHFy: pT " << hthf.hwPt();
0161 
0162       res2_->push_back(0, hthf);
0163 
0164       // HT / MHT(x)/ MHT (y) no HF
0165 
0166       raw_data = block.payload()[fht + 1];
0167 
0168       l1t::EtSum htNoHF = l1t::EtSum();
0169 
0170       switch (block.header().getID()) {
0171         case 123:  // 61
0172           htNoHF.setType(l1t::EtSum::kTotalHt);
0173           htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
0174           break;
0175         case 121:  // 60
0176           htNoHF.setType(l1t::EtSum::kTotalHtx);
0177           htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0178           break;
0179         case 127:  // 63
0180           htNoHF.setType(l1t::EtSum::kTotalHty);
0181           htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0182           break;
0183         case 125:  // 62
0184           htNoHF.setType(l1t::EtSum::kTotalHt);
0185           htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
0186           break;
0187         case 131:  // 65
0188           htNoHF.setType(l1t::EtSum::kTotalHtx);
0189           htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0190           break;
0191         case 129:  // 64
0192           htNoHF.setType(l1t::EtSum::kTotalHty);
0193           htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0194           break;
0195         default:
0196           break;
0197       }
0198 
0199       LogDebug("L1T") << "HTNOHF/MHTNOHFx/MHTNOHFy: pT " << htNoHF.hwPt();
0200 
0201       res2_->push_back(0, htNoHF);
0202 
0203       // Two jets
0204       for (unsigned nJet = 0; nJet < 2; nJet++) {
0205         raw_data = block.payload()[fjet + nJet];
0206 
0207         if (raw_data == 0)
0208           continue;
0209 
0210         l1t::Jet jet = l1t::Jet();
0211 
0212         int etasign = 1;
0213         if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
0214           etasign = -1;
0215         }
0216 
0217         LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
0218 
0219         int mpEta = etasign * (raw_data & 0x3F);
0220         jet.setHwEta(CaloTools::caloEta(mpEta));
0221         jet.setHwPhi((raw_data >> 6) & 0x7F);
0222         jet.setHwPt((raw_data >> 13) & 0xFFFF);
0223         jet.setHwQual((raw_data >> 29) & 0x1);
0224 
0225         if (jet.hwPt() == 0)
0226           continue;
0227 
0228         LogDebug("L1T") << "Jet: eta " << jet.hwEta() << " phi " << jet.hwPhi() << " pT " << jet.hwPt() << " qual "
0229                         << jet.hwQual();
0230 
0231         jet.setP4(l1t::CaloTools::p4MP(&jet));
0232         res1_->push_back(0, jet);
0233       }
0234 
0235       //      ===== EGammas =====
0236 
0237       // Two EGammas
0238 
0239       for (unsigned nEG = 0; nEG < 2; nEG++) {
0240         raw_data = block.payload()[feg + nEG];
0241 
0242         if (raw_data == 0)
0243           continue;
0244 
0245         l1t::EGamma eg = l1t::EGamma();
0246 
0247         int etasign = 1;
0248         if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
0249           etasign = -1;
0250         }
0251 
0252         LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
0253 
0254         eg.setHwEta(etasign * ((raw_data >> 3) & 0x3F));
0255         eg.setHwPhi((raw_data >> 9) & 0x7F);
0256         eg.setHwPt((raw_data >> 20) & 0xFFF);
0257         eg.setHwIso((raw_data >> 1) & 0x3);
0258         eg.setHwQual((raw_data >> 16) & 0xf);
0259 
0260         if (eg.hwPt() == 0)
0261           continue;
0262 
0263         LogDebug("L1T") << "Egamma: eta " << eg.hwEta() << " phi " << eg.hwPhi() << " pT " << eg.hwPt() << " qual "
0264                         << eg.hwQual();
0265 
0266         eg.setP4(l1t::CaloTools::p4MP(&eg));
0267         res3_->push_back(0, eg);
0268       }
0269 
0270       //      ===== Taus =====
0271 
0272       // Two taus
0273 
0274       for (unsigned nTau = 0; nTau < 2; nTau++) {
0275         raw_data = block.payload()[ftau + nTau];
0276 
0277         if (raw_data == 0)
0278           continue;
0279 
0280         l1t::Tau tau = l1t::Tau();
0281 
0282         int etasign = 1;
0283         if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
0284           etasign = -1;
0285         }
0286 
0287         LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
0288 
0289         tau.setHwEta(etasign * ((raw_data >> 3) & 0x3F));
0290         tau.setHwPhi((raw_data >> 9) & 0x7F);
0291         tau.setHwPt((raw_data >> 20) & 0xFFF);
0292         tau.setHwIso((raw_data >> 1) & 0x3);
0293         tau.setHwQual((raw_data >> 16) & 0xf);
0294 
0295         if (tau.hwPt() == 0)
0296           continue;
0297 
0298         LogDebug("L1T") << "Tau: eta " << tau.hwEta() << " phi " << tau.hwPhi() << " pT " << tau.hwPt() << " qual "
0299                         << tau.hwQual();
0300 
0301         tau.setP4(l1t::CaloTools::p4MP(&tau));
0302         res4_->push_back(0, tau);
0303       }
0304 
0305       // check block size to avoid problems with test run 272133
0306       // which used wrong fw version and doesn't have aux output
0307 
0308       if (block.header().getSize() > faux) {
0309         //      ===== Aux =====
0310         raw_data = block.payload()[faux];
0311 
0312         // readout the sums only if the correct block is  being processed (first frame of AUX)
0313         switch (block.header().getID()) {
0314           case 121:  // this should correspond to the first link
0315           {
0316             // read 4 bits starting at position 24 (24 -> 28)
0317             l1t::EtSum mbp0{l1t::EtSum::kMinBiasHFP0};
0318             mbp0.setHwPt((raw_data >> 24) & 0xF);
0319 
0320             // read 4 bits starting at position 16 (16 -> 20)
0321             l1t::EtSum mbm0{l1t::EtSum::kMinBiasHFM0};
0322             mbm0.setHwPt((raw_data >> 16) & 0xF);
0323 
0324             // read 4 bits starting at position 8 (8 -> 12)
0325             l1t::EtSum mbp1{l1t::EtSum::kMinBiasHFP1};
0326             mbp1.setHwPt((raw_data >> 8) & 0xF);
0327 
0328             // read the first 4 bits by masking with 0xF
0329             l1t::EtSum mbm1{l1t::EtSum::kMinBiasHFM1};
0330             mbm1.setHwPt(raw_data & 0xF);
0331 
0332             LogDebug("L1T") << "mbp0 HF sum: " << mbp0.hwPt();
0333             LogDebug("L1T") << "mbm0 HF sum: " << mbm0.hwPt();
0334             LogDebug("L1T") << "mbp1 HF sum: " << mbp1.hwPt();
0335             LogDebug("L1T") << "mbm1 HF sum: " << mbm1.hwPt();
0336 
0337             res2_->push_back(0, mbp0);
0338             res2_->push_back(0, mbm0);
0339             res2_->push_back(0, mbp1);
0340             res2_->push_back(0, mbm1);
0341             break;
0342           }
0343           default:
0344             break;
0345         }
0346       }
0347 
0348       return true;
0349     }
0350   }  // namespace stage2
0351 }  // namespace l1t
0352 
0353 DEFINE_L1T_UNPACKER(l1t::stage2::MPUnpacker_0x10010010);