Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"
0003 
0004 #include "L1Trigger/L1TCalorimeter/interface/CaloTools.h"
0005 
0006 #include "L1TObjectCollections.h"
0007 
0008 #include "L1TStage2Layer2Constants.h"
0009 #include "EtSumUnpacker.h"
0010 
0011 namespace l1t {
0012   namespace stage2 {
0013     EtSumUnpacker::EtSumUnpacker() : EtSumCopy_(0) {}
0014 
0015     bool EtSumUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
0016       using namespace l1t::stage2::layer2;
0017 
0018       LogDebug("L1T") << "Block ID  = " << block.header().getID() << " size = " << block.header().getSize();
0019 
0020       int nBX = int(
0021           ceil(block.header().getSize() / demux::nOutputFramePerBX));  // Since there 6 frames per demux output event
0022       // expect the first four frames to be the first 4 EtSum objects reported per event (see CMS IN-2013/005)
0023 
0024       // Find the central, first and last BXs
0025       int firstBX = -(ceil((double)nBX / 2.) - 1);
0026       int lastBX;
0027       if (nBX % 2 == 0) {
0028         lastBX = ceil((double)nBX / 2.);
0029       } else {
0030         lastBX = ceil((double)nBX / 2.) - 1;
0031       }
0032 
0033       auto res_ = static_cast<L1TObjectCollections*>(coll)->getEtSums(EtSumCopy_);
0034       res_->setBXRange(firstBX, lastBX);
0035 
0036       LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;
0037 
0038       // Loop over multiple BX and fill EtSums collection
0039       for (int bx = firstBX; bx <= lastBX; bx++) {
0040         // ET
0041         int iFrame = (bx - firstBX) * demux::nOutputFramePerBX;
0042 
0043         uint32_t raw_data = block.payload().at(iFrame);
0044 
0045         l1t::EtSum et{l1t::EtSum::kTotalEt};
0046         et.setHwPt(raw_data & 0xFFF);
0047         et.setP4(l1t::CaloTools::p4Demux(&et));
0048 
0049         LogDebug("L1T") << "ET: pT " << et.hwPt() << " bx " << bx;
0050 
0051         res_->push_back(bx, et);
0052 
0053         // ET EM
0054 
0055         l1t::EtSum etem{l1t::EtSum::kTotalEtEm};
0056 
0057         etem.setHwPt((raw_data >> 12) & 0xFFF);
0058         etem.setP4(l1t::CaloTools::p4Demux(&etem));
0059 
0060         LogDebug("L1T") << "ETEM: pT " << etem.hwPt() << " bx " << bx;
0061 
0062         res_->push_back(bx, etem);
0063 
0064         // MBHFPT0
0065 
0066         l1t::EtSum mbp0{l1t::EtSum::kMinBiasHFP0};
0067         mbp0.setHwPt((raw_data >> 28) & 0xf);
0068 
0069         res_->push_back(bx, mbp0);
0070 
0071         // HT
0072 
0073         raw_data = block.payload()[iFrame + 1];
0074 
0075         l1t::EtSum ht{l1t::EtSum::kTotalHt};
0076         ht.setHwPt(raw_data & 0xFFF);
0077         ht.setP4(l1t::CaloTools::p4Demux(&ht));
0078 
0079         LogDebug("L1T") << "HT: pT " << ht.hwPt();
0080 
0081         res_->push_back(bx, ht);
0082 
0083         //MBHFMT0
0084 
0085         l1t::EtSum mbm0{l1t::EtSum::kMinBiasHFM0};
0086         mbm0.setHwPt((raw_data >> 28) & 0xf);
0087 
0088         res_->push_back(bx, mbm0);
0089 
0090         //  MET (no HF)
0091 
0092         raw_data = block.payload()[iFrame + 2];
0093 
0094         l1t::EtSum met{l1t::EtSum::kMissingEt};
0095 
0096         met.setHwPt(raw_data & 0xFFF);
0097         met.setHwPhi((raw_data >> 12) & 0xFF);
0098         met.setP4(l1t::CaloTools::p4Demux(&met));
0099 
0100         LogDebug("L1T") << "MET: phi " << met.hwPhi() << " pT " << met.hwPt() << " bx " << bx;
0101 
0102         res_->push_back(bx, met);
0103 
0104         // MBHFPT1
0105 
0106         l1t::EtSum mbp1{l1t::EtSum::kMinBiasHFP1};
0107         mbp1.setHwPt((raw_data >> 28) & 0xf);
0108 
0109         res_->push_back(bx, mbp1);
0110 
0111         // MHT
0112 
0113         raw_data = block.payload()[iFrame + 3];
0114 
0115         l1t::EtSum mht{l1t::EtSum::kMissingHt};
0116 
0117         mht.setHwPt(raw_data & 0xFFF);
0118         mht.setHwPhi((raw_data >> 12) & 0xFF);
0119         mht.setP4(l1t::CaloTools::p4Demux(&mht));
0120 
0121         LogDebug("L1T") << "MHT: phi " << mht.hwPhi() << " pT " << mht.hwPt() << " bx " << bx;
0122 
0123         res_->push_back(bx, mht);
0124 
0125         // MBHFMT1
0126 
0127         l1t::EtSum mbm1{l1t::EtSum::kMinBiasHFM1};
0128         mbm1.setHwPt((raw_data >> 28) & 0xf);
0129 
0130         res_->push_back(bx, mbm1);
0131 
0132         //  MET (with HF)
0133 
0134         raw_data = block.payload()[iFrame + 4];
0135 
0136         l1t::EtSum methf{l1t::EtSum::kMissingEtHF};
0137 
0138         methf.setHwPt(raw_data & 0xFFF);
0139         methf.setHwPhi((raw_data >> 12) & 0xFF);
0140         methf.setP4(l1t::CaloTools::p4Demux(&methf));
0141 
0142         LogDebug("L1T") << "METHF: phi " << methf.hwPhi() << " pT " << methf.hwPt() << " bx " << bx;
0143 
0144         res_->push_back(bx, methf);
0145 
0146         // MHT with HF
0147 
0148         raw_data = block.payload()[iFrame + 5];
0149 
0150         l1t::EtSum mhthf{l1t::EtSum::kMissingHtHF};
0151         mhthf.setHwPt(raw_data & 0xFFF);
0152         mhthf.setHwPhi((raw_data >> 12) & 0xFF);
0153         mhthf.setP4(l1t::CaloTools::p4Demux(&mhthf));
0154 
0155         LogDebug("L1T") << "MHThf: phi " << mhthf.hwPhi() << " pT " << mhthf.hwPt() << " bx " << bx;
0156 
0157         res_->push_back(bx, mhthf);
0158 
0159         //HI-SUM
0160 
0161         raw_data = block.payload()[iFrame + 1];
0162 
0163         l1t::EtSum towCount{l1t::EtSum::kTowerCount};
0164         towCount.setHwPt((raw_data >> 12) & 0x1FFF);
0165         towCount.setP4(l1t::CaloTools::p4Demux(&towCount));
0166 
0167         res_->push_back(bx, towCount);
0168       }
0169 
0170       return true;
0171     }
0172   }  // namespace stage2
0173 }  // namespace l1t
0174 
0175 DEFINE_L1T_UNPACKER(l1t::stage2::EtSumUnpacker);