Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:42

0001 #include "L1Trigger/L1THGCal/interface/concentrator/HGCalConcentratorBestChoiceImpl.h"
0002 
0003 constexpr unsigned HGCalConcentratorBestChoiceImpl::kNDataSize_;
0004 constexpr uint32_t HGCalConcentratorBestChoiceImpl::kWaferOffset_;
0005 constexpr uint32_t HGCalConcentratorBestChoiceImpl::kWaferMask_;
0006 constexpr uint32_t HGCalConcentratorBestChoiceImpl::kLinkMask_;
0007 
0008 HGCalConcentratorBestChoiceImpl::HGCalConcentratorBestChoiceImpl(const edm::ParameterSet& conf)
0009     : nData_(conf.getParameter<std::vector<unsigned>>("NData")) {
0010   if (nData_.size() != kNDataSize_) {
0011     throw cms::Exception("BadInitialization") << "NData vector must be of size " << kNDataSize_;
0012   }
0013 }
0014 
0015 void HGCalConcentratorBestChoiceImpl::select(unsigned nLinks,
0016                                              unsigned nWafers,
0017                                              const std::vector<l1t::HGCalTriggerCell>& trigCellVecInput,
0018                                              std::vector<l1t::HGCalTriggerCell>& trigCellVecOutput,
0019                                              std::vector<l1t::HGCalTriggerCell>& trigCellVecNotSelected) {
0020   trigCellVecOutput = trigCellVecInput;
0021   trigCellVecNotSelected.resize(0);
0022   // sort, reverse order
0023   std::sort(
0024       trigCellVecOutput.begin(),
0025       trigCellVecOutput.end(),
0026       [](const l1t::HGCalTriggerCell& a, const l1t::HGCalTriggerCell& b) -> bool { return a.mipPt() > b.mipPt(); });
0027 
0028   uint32_t nLinksIndex = 0;
0029   if (nLinks > kLinkMask_) {
0030     throw cms::Exception("BadConfig") << "BestChoice: Nlinks=" << nLinks
0031                                       << " larger then the max supported number of links " << kLinkMask_;
0032   }
0033   nLinksIndex |= ((nLinks - 1) & kLinkMask_);
0034   nLinksIndex |= (((nWafers - 1) & kWaferMask_) << kWaferOffset_);
0035   unsigned nData = nData_.at(nLinksIndex);
0036   if (nData == 0) {
0037     throw cms::Exception("BadConfig") << "BestChoice: NData=0 for "
0038                                       << " NWafers=" << nWafers << " and NLinks=" << nLinks;
0039   }
0040   // keep only N trigger cells
0041   if (trigCellVecOutput.size() > nData) {
0042     // store the last cells (not selected)
0043     std::move(trigCellVecOutput.begin() + nData, trigCellVecOutput.end(), std::back_inserter(trigCellVecNotSelected));
0044     // keep only N trigger cells
0045     trigCellVecOutput.resize(nData);
0046   }
0047 }