Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:52

0001 #define EDM_ML_DEBUG 1
0002 
0003 #include "FWCore/Framework/interface/MakerMacros.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_0x10010033.h"
0012 
0013 namespace l1t {
0014   namespace stage2 {
0015     bool MPUnpacker_0x10010033::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       unsigned int tmt = block.amc().getBoardID() - l1t::stage2::layer2::mp::offsetBoardId + 1;
0021       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       int unsigned fet = 0;
0039       int unsigned fht = 2;
0040       int unsigned feg = 4;
0041       int unsigned ftau = 6;
0042       int unsigned fjet = 8;
0043       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       // ET EM
0126       if (block.header().getID() == 123 || block.header().getID() == 125) {
0127         l1t::EtSum etEm{l1t::EtSum::kTotalEtEm};
0128         etEm.setHwPt(static_cast<int32_t>(uint32_t((raw_data >> 16) & 0xFFFF)));
0129         res2_->push_back(0, etEm);
0130       }
0131 
0132       // HT / MHT(x)/ MHT (y) with HF
0133 
0134       raw_data = block.payload()[fht];
0135 
0136       l1t::EtSum hthf = l1t::EtSum();
0137 
0138       switch (block.header().getID()) {
0139         case 123:  // 61
0140           hthf.setType(l1t::EtSum::kTotalHtHF);
0141           hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
0142           break;
0143         case 121:  // 60
0144           hthf.setType(l1t::EtSum::kTotalHtxHF);
0145           hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0146           break;
0147         case 127:  // 63
0148           hthf.setType(l1t::EtSum::kTotalHtyHF);
0149           hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0150           break;
0151         case 125:  // 62
0152           hthf.setType(l1t::EtSum::kTotalHtHF);
0153           hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
0154           break;
0155         case 131:  // 65
0156           hthf.setType(l1t::EtSum::kTotalHtxHF);
0157           hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0158           break;
0159         case 129:  // 64
0160           hthf.setType(l1t::EtSum::kTotalHtyHF);
0161           hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0162           break;
0163         default:
0164           break;
0165       }
0166 
0167       LogDebug("L1T") << "HTHF/MHTHFx/MHTHFy: pT " << hthf.hwPt();
0168 
0169       res2_->push_back(0, hthf);
0170 
0171       // HT / MHT(x)/ MHT (y) no HF
0172 
0173       raw_data = block.payload()[fht + 1];
0174 
0175       l1t::EtSum htNoHF = l1t::EtSum();
0176 
0177       switch (block.header().getID()) {
0178         case 123:  // 61
0179           htNoHF.setType(l1t::EtSum::kTotalHt);
0180           htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
0181           break;
0182         case 121:  // 60
0183           htNoHF.setType(l1t::EtSum::kTotalHtx);
0184           htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0185           break;
0186         case 127:  // 63
0187           htNoHF.setType(l1t::EtSum::kTotalHty);
0188           htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0189           break;
0190         case 125:  // 62
0191           htNoHF.setType(l1t::EtSum::kTotalHt);
0192           htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
0193           break;
0194         case 131:  // 65
0195           htNoHF.setType(l1t::EtSum::kTotalHtx);
0196           htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0197           break;
0198         case 129:  // 64
0199           htNoHF.setType(l1t::EtSum::kTotalHty);
0200           htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
0201           break;
0202         default:
0203           break;
0204       }
0205 
0206       LogDebug("L1T") << "HTNOHF/MHTNOHFx/MHTNOHFy: pT " << htNoHF.hwPt();
0207 
0208       res2_->push_back(0, htNoHF);
0209 
0210       // Two jets
0211       for (unsigned nJet = 0; nJet < 2; nJet++) {
0212         raw_data = block.payload()[fjet + nJet];
0213 
0214         if (raw_data == 0)
0215           continue;
0216 
0217         l1t::Jet jet = l1t::Jet();
0218 
0219         int etasign = 1;
0220         if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
0221           etasign = -1;
0222         }
0223 
0224         LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
0225 
0226         int mpEta = etasign * (raw_data & 0x3F);
0227         jet.setHwEta(CaloTools::caloEta(mpEta));
0228         jet.setHwPhi((raw_data >> 6) & 0x7F);
0229         jet.setHwPt((raw_data >> 13) & 0xFFFF);
0230         jet.setHwQual((raw_data >> 30) & 0x1);
0231 
0232         if (jet.hwPt() == 0)
0233           continue;
0234 
0235         LogDebug("L1T") << "Jet: eta " << jet.hwEta() << " phi " << jet.hwPhi() << " pT " << jet.hwPt() << " qual "
0236                         << jet.hwQual();
0237 
0238         jet.setP4(l1t::CaloTools::p4MP(&jet));
0239         res1_->push_back(0, jet);
0240       }
0241 
0242       //      ===== EGammas =====
0243 
0244       // Two EGammas
0245 
0246       for (unsigned nEG = 0; nEG < 2; nEG++) {
0247         raw_data = block.payload()[feg + nEG];
0248 
0249         if (raw_data == 0)
0250           continue;
0251 
0252         l1t::EGamma eg = l1t::EGamma();
0253 
0254         int etasign = 1;
0255         if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
0256           etasign = -1;
0257         }
0258 
0259         LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
0260 
0261         eg.setHwEta(etasign * ((raw_data >> 3) & 0x3F));
0262         eg.setHwPhi((raw_data >> 9) & 0x7F);
0263         eg.setHwPt((raw_data >> 20) & 0xFFF);
0264         eg.setHwIso((raw_data >> 1) & 0x3);
0265         eg.setHwQual((raw_data >> 16) & 0xf);
0266 
0267         if (eg.hwPt() == 0)
0268           continue;
0269 
0270         LogDebug("L1T") << "Egamma: eta " << eg.hwEta() << " phi " << eg.hwPhi() << " pT " << eg.hwPt() << " qual "
0271                         << eg.hwQual();
0272 
0273         eg.setP4(l1t::CaloTools::p4MP(&eg));
0274         res3_->push_back(0, eg);
0275       }
0276 
0277       //      ===== Taus =====
0278 
0279       // Two taus
0280 
0281       for (unsigned nTau = 0; nTau < 2; nTau++) {
0282         raw_data = block.payload()[ftau + nTau];
0283 
0284         if (raw_data == 0)
0285           continue;
0286 
0287         l1t::Tau tau = l1t::Tau();
0288 
0289         int etasign = 1;
0290         if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
0291           etasign = -1;
0292         }
0293 
0294         LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
0295 
0296         tau.setHwEta(etasign * ((raw_data >> 3) & 0x3F));
0297         tau.setHwPhi((raw_data >> 9) & 0x7F);
0298         tau.setHwPt((raw_data >> 20) & 0xFFF);
0299         tau.setHwIso((raw_data >> 1) & 0x3);
0300         tau.setHwQual((raw_data >> 16) & 0xf);
0301 
0302         if (tau.hwPt() == 0)
0303           continue;
0304 
0305         LogDebug("L1T") << "Tau: eta " << tau.hwEta() << " phi " << tau.hwPhi() << " pT " << tau.hwPt() << " qual "
0306                         << tau.hwQual();
0307 
0308         tau.setP4(l1t::CaloTools::p4MP(&tau));
0309         res4_->push_back(0, tau);
0310       }
0311 
0312       //      ===== Aux =====
0313       raw_data = block.payload()[faux];
0314 
0315       // create a sum object for each type of HF sum
0316 
0317       // readout the sums only if the correct block is  being processed (first frame of AUX)
0318       switch (block.header().getID()) {
0319         case 121:  // this should correspond to the first link
0320         {
0321           // read 4 bits starting at position 24 (24 -> 28)
0322           l1t::EtSum mbp0{l1t::EtSum::kMinBiasHFP0};
0323           mbp0.setHwPt((raw_data >> 24) & 0xF);
0324 
0325           // read 4 bits starting at position 16 (16 -> 20)
0326           l1t::EtSum mbm0{l1t::EtSum::kMinBiasHFM0};
0327           mbm0.setHwPt((raw_data >> 16) & 0xF);
0328 
0329           // read 4 bits starting at position 8 (8 -> 12)
0330           l1t::EtSum mbp1{l1t::EtSum::kMinBiasHFP1};
0331           mbp1.setHwPt((raw_data >> 8) & 0xF);
0332 
0333           // read the first 4 bits by masking with 0xF
0334           l1t::EtSum mbm1{l1t::EtSum::kMinBiasHFM1};
0335           mbm1.setHwPt(raw_data & 0xF);
0336 
0337           LogDebug("L1T") << "mbp0 HF sum: " << mbp0.hwPt();
0338           LogDebug("L1T") << "mbm0 HF sum: " << mbm0.hwPt();
0339           LogDebug("L1T") << "mbp1 HF sum: " << mbp1.hwPt();
0340           LogDebug("L1T") << "mbm1 HF sum: " << mbm1.hwPt();
0341 
0342           res2_->push_back(0, mbp0);
0343           res2_->push_back(0, mbm0);
0344           res2_->push_back(0, mbp1);
0345           res2_->push_back(0, mbm1);
0346           break;
0347         }
0348         case 127: {
0349           l1t::EtSum towCount{l1t::EtSum::kTowerCount};
0350           towCount.setHwPt(raw_data & 0x1FFF);
0351           res2_->push_back(0, towCount);
0352           break;
0353         }
0354         default:
0355           break;
0356       }
0357 
0358       return true;
0359     }
0360   }  // namespace stage2
0361 }  // namespace l1t
0362 
0363 DEFINE_L1T_UNPACKER(l1t::stage2::MPUnpacker_0x10010033);