Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "L1Trigger/L1THGCal/interface/concentrator/HGCalConcentratorProcessorSelection.h"
0002 #include <limits>
0003 
0004 #include "DataFormats/HGCDigi/interface/HGCDigiCollections.h"
0005 
0006 DEFINE_EDM_PLUGIN(HGCalConcentratorFactory, HGCalConcentratorProcessorSelection, "HGCalConcentratorProcessorSelection");
0007 
0008 HGCalConcentratorProcessorSelection::HGCalConcentratorProcessorSelection(const edm::ParameterSet& conf)
0009     : HGCalConcentratorProcessorBase(conf),
0010       fixedDataSizePerHGCROC_(conf.getParameter<bool>("fixedDataSizePerHGCROC")),
0011       allTrigCellsInTrigSums_(conf.getParameter<bool>("allTrigCellsInTrigSums")),
0012       coarsenTriggerCells_(conf.getParameter<std::vector<unsigned>>("coarsenTriggerCells")),
0013       selectionType_(kNSubDetectors_) {
0014   std::vector<std::string> selectionType(conf.getParameter<std::vector<std::string>>("Method"));
0015   if (selectionType.size() != kNSubDetectors_ || coarsenTriggerCells_.size() != kNSubDetectors_) {
0016     throw cms::Exception("HGCTriggerParameterError")
0017         << "Inconsistent number of sub-detectors (should be " << kNSubDetectors_ << ")";
0018   }
0019 
0020   for (int subdet = 0; subdet < kNSubDetectors_; subdet++) {
0021     if (selectionType[subdet] == "thresholdSelect") {
0022       selectionType_[subdet] = thresholdSelect;
0023       if (!thresholdImpl_)
0024         thresholdImpl_ = std::make_unique<HGCalConcentratorThresholdImpl>(conf);
0025       if (!trigSumImpl_)
0026         trigSumImpl_ = std::make_unique<HGCalConcentratorTrigSumImpl>(conf);
0027     } else if (selectionType[subdet] == "bestChoiceSelect") {
0028       selectionType_[subdet] = bestChoiceSelect;
0029       if (!bestChoiceImpl_)
0030         bestChoiceImpl_ = std::make_unique<HGCalConcentratorBestChoiceImpl>(conf);
0031       if (!trigSumImpl_)
0032         trigSumImpl_ = std::make_unique<HGCalConcentratorTrigSumImpl>(conf);
0033     } else if (selectionType[subdet] == "superTriggerCellSelect") {
0034       selectionType_[subdet] = superTriggerCellSelect;
0035       if (!superTriggerCellImpl_)
0036         superTriggerCellImpl_ = std::make_unique<HGCalConcentratorSuperTriggerCellImpl>(conf);
0037     } else if (selectionType[subdet] == "autoEncoder") {
0038       selectionType_[subdet] = autoEncoderSelect;
0039       if (!autoEncoderImpl_)
0040         autoEncoderImpl_ = std::make_unique<HGCalConcentratorAutoEncoderImpl>(conf);
0041     } else if (selectionType[subdet] == "noSelection") {
0042       selectionType_[subdet] = noSelection;
0043     } else {
0044       throw cms::Exception("HGCTriggerParameterError")
0045           << "Unknown type of concentrator selection '" << selectionType[subdet] << "'";
0046     }
0047   }
0048 
0049   if (std::find(coarsenTriggerCells_.begin(), coarsenTriggerCells_.end(), true) != coarsenTriggerCells_.end() ||
0050       fixedDataSizePerHGCROC_) {
0051     coarsenerImpl_ = std::make_unique<HGCalConcentratorCoarsenerImpl>(conf);
0052   }
0053 }
0054 
0055 void HGCalConcentratorProcessorSelection::run(const edm::Handle<l1t::HGCalTriggerCellBxCollection>& triggerCellCollInput,
0056                                               std::tuple<l1t::HGCalTriggerCellBxCollection,
0057                                                          l1t::HGCalTriggerSumsBxCollection,
0058                                                          l1t::HGCalConcentratorDataBxCollection>& triggerCollOutput) {
0059   if (thresholdImpl_)
0060     thresholdImpl_->setGeometry(geometry());
0061   if (bestChoiceImpl_)
0062     bestChoiceImpl_->setGeometry(geometry());
0063   if (superTriggerCellImpl_)
0064     superTriggerCellImpl_->setGeometry(geometry());
0065   if (autoEncoderImpl_)
0066     autoEncoderImpl_->setGeometry(geometry());
0067   if (coarsenerImpl_)
0068     coarsenerImpl_->setGeometry(geometry());
0069   if (trigSumImpl_)
0070     trigSumImpl_->setGeometry(geometry());
0071   triggerTools_.setGeometry(geometry());
0072 
0073   auto& triggerCellCollOutput = std::get<0>(triggerCollOutput);
0074   auto& triggerSumCollOutput = std::get<1>(triggerCollOutput);
0075   auto& autoEncoderCollOutput = std::get<2>(triggerCollOutput);
0076 
0077   const l1t::HGCalTriggerCellBxCollection& collInput = *triggerCellCollInput;
0078 
0079   std::unordered_map<uint32_t, std::vector<l1t::HGCalTriggerCell>> tc_modules;
0080   for (const auto& trigCell : collInput) {
0081     uint32_t module = geometry()->getModuleFromTriggerCell(trigCell.detId());
0082     tc_modules[module].push_back(trigCell);
0083   }
0084 
0085   for (const auto& module_trigcell : tc_modules) {
0086     std::vector<l1t::HGCalTriggerCell> trigCellVecOutput;
0087     std::vector<l1t::HGCalTriggerCell> trigCellVecCoarsened;
0088     std::vector<l1t::HGCalTriggerCell> trigCellVecNotSelected;
0089     std::vector<l1t::HGCalTriggerSums> trigSumsVecOutput;
0090     std::vector<l1t::HGCalConcentratorData> ae_EncodedLayerOutput;
0091 
0092     int thickness = triggerTools_.thicknessIndex(module_trigcell.second.at(0).detId());
0093 
0094     HGCalTriggerTools::SubDetectorType subdet = triggerTools_.getSubDetectorType(module_trigcell.second.at(0).detId());
0095 
0096     if (coarsenTriggerCells_[subdet] || (fixedDataSizePerHGCROC_ && thickness > kHighDensityThickness_)) {
0097       coarsenerImpl_->coarsen(module_trigcell.second, trigCellVecCoarsened);
0098 
0099       switch (selectionType_[subdet]) {
0100         case thresholdSelect:
0101           thresholdImpl_->select(trigCellVecCoarsened, trigCellVecOutput, trigCellVecNotSelected);
0102           break;
0103         case bestChoiceSelect:
0104           if (triggerTools_.isEm(module_trigcell.first)) {
0105             bestChoiceImpl_->select(geometry()->getLinksInModule(module_trigcell.first),
0106                                     geometry()->getModuleSize(module_trigcell.first),
0107                                     module_trigcell.second,
0108                                     trigCellVecOutput,
0109                                     trigCellVecNotSelected);
0110           } else {
0111             bestChoiceImpl_->select(geometry()->getLinksInModule(module_trigcell.first),
0112                                     geometry()->getModuleSize(module_trigcell.first),
0113                                     trigCellVecCoarsened,
0114                                     trigCellVecOutput,
0115                                     trigCellVecNotSelected);
0116           }
0117           break;
0118         case superTriggerCellSelect:
0119           superTriggerCellImpl_->select(trigCellVecCoarsened, trigCellVecOutput);
0120           break;
0121         case autoEncoderSelect:
0122           autoEncoderImpl_->select(geometry()->getLinksInModule(module_trigcell.first),
0123                                    trigCellVecCoarsened,
0124                                    trigCellVecOutput,
0125                                    ae_EncodedLayerOutput);
0126           break;
0127         case noSelection:
0128           trigCellVecOutput = trigCellVecCoarsened;
0129           break;
0130         default:
0131           // Should not happen, selection type checked in constructor
0132           break;
0133       }
0134 
0135     } else {
0136       switch (selectionType_[subdet]) {
0137         case thresholdSelect:
0138           thresholdImpl_->select(module_trigcell.second, trigCellVecOutput, trigCellVecNotSelected);
0139           break;
0140         case bestChoiceSelect:
0141           bestChoiceImpl_->select(geometry()->getLinksInModule(module_trigcell.first),
0142                                   geometry()->getModuleSize(module_trigcell.first),
0143                                   module_trigcell.second,
0144                                   trigCellVecOutput,
0145                                   trigCellVecNotSelected);
0146           break;
0147         case superTriggerCellSelect:
0148           superTriggerCellImpl_->select(module_trigcell.second, trigCellVecOutput);
0149           break;
0150         case autoEncoderSelect:
0151           autoEncoderImpl_->select(geometry()->getLinksInModule(module_trigcell.first),
0152                                    module_trigcell.second,
0153                                    trigCellVecOutput,
0154                                    ae_EncodedLayerOutput);
0155           break;
0156         case noSelection:
0157           trigCellVecOutput = module_trigcell.second;
0158           break;
0159         default:
0160           // Should not happen, selection type checked in constructor
0161           break;
0162       }
0163     }
0164 
0165     // trigger sum
0166     if (trigSumImpl_) {
0167       if (allTrigCellsInTrigSums_) {  // using all TCs
0168         trigSumImpl_->doSum(module_trigcell.first, module_trigcell.second, trigSumsVecOutput);
0169       } else {  // using only unselected TCs
0170         trigSumImpl_->doSum(module_trigcell.first, trigCellVecNotSelected, trigSumsVecOutput);
0171       }
0172     }
0173 
0174     for (const auto& trigCell : trigCellVecOutput) {
0175       triggerCellCollOutput.push_back(0, trigCell);
0176     }
0177     for (const auto& trigSums : trigSumsVecOutput) {
0178       triggerSumCollOutput.push_back(0, trigSums);
0179     }
0180     for (const auto& aeVal : ae_EncodedLayerOutput) {
0181       autoEncoderCollOutput.push_back(0, aeVal);
0182     }
0183   }
0184 }