File indexing completed on 2024-04-06 12:20:39
0001 #include "L1Trigger/L1THGCal/interface/HGCalAlgoWrapperBase.h"
0002
0003 #include "DataFormats/L1THGCal/interface/HGCalTriggerCell.h"
0004 #include "L1Trigger/L1THGCal/interface/backend/HGCalTriggerCell_SA.h"
0005 #include "L1Trigger/L1THGCal/interface/backend/HGCalStage1TruncationImpl_SA.h"
0006 #include "L1Trigger/L1THGCal/interface/backend/HGCalStage1TruncationConfig_SA.h"
0007
0008 #include "L1Trigger/L1THGCal/interface/HGCalTriggerTools.h"
0009
0010 class HGCalStage1TruncationWrapper : public HGCalStage1TruncationWrapperBase {
0011 public:
0012 HGCalStage1TruncationWrapper(const edm::ParameterSet& conf);
0013 ~HGCalStage1TruncationWrapper() override = default;
0014
0015 void configure(
0016 const std::tuple<const HGCalTriggerGeometryBase* const, const unsigned&, const uint32_t&>& configuration) override;
0017
0018 void process(const std::vector<edm::Ptr<l1t::HGCalTriggerCell>>& fpga_tcs,
0019 std::vector<edm::Ptr<l1t::HGCalTriggerCell>>& tcs_out) const override;
0020
0021 private:
0022 void convertCMSSWInputs(const std::vector<edm::Ptr<l1t::HGCalTriggerCell>>& fpga_tcs,
0023 l1thgcfirmware::HGCalTriggerCellSACollection& fpga_tcs_SA) const;
0024
0025 void convertAlgorithmOutputs(const l1thgcfirmware::HGCalTriggerCellSACollection& fpga_tcs_out,
0026 const std::vector<edm::Ptr<l1t::HGCalTriggerCell>>& fpga_tcs_original,
0027 std::vector<edm::Ptr<l1t::HGCalTriggerCell>>& fpga_tcs_trunc) const;
0028
0029 void setGeometry(const HGCalTriggerGeometryBase* const geom) { triggerTools_.setGeometry(geom); }
0030
0031 HGCalTriggerTools triggerTools_;
0032 HGCalStage1TruncationImplSA theAlgo_;
0033 l1thgcfirmware::Stage1TruncationConfig theConfiguration_;
0034 };
0035
0036 HGCalStage1TruncationWrapper::HGCalStage1TruncationWrapper(const edm::ParameterSet& conf)
0037 : HGCalStage1TruncationWrapperBase(conf),
0038 theAlgo_(),
0039 theConfiguration_(conf.getParameter<bool>("doTruncation"),
0040 conf.getParameter<double>("rozMin"),
0041 conf.getParameter<double>("rozMax"),
0042 conf.getParameter<unsigned>("rozBins"),
0043 conf.getParameter<std::vector<unsigned>>("maxTcsPerBin"),
0044 conf.getParameter<std::vector<double>>("phiSectorEdges")) {}
0045
0046 void HGCalStage1TruncationWrapper::convertCMSSWInputs(const std::vector<edm::Ptr<l1t::HGCalTriggerCell>>& fpga_tcs,
0047 l1thgcfirmware::HGCalTriggerCellSACollection& fpga_tcs_SA) const {
0048 fpga_tcs_SA.clear();
0049 fpga_tcs_SA.reserve(fpga_tcs.size());
0050 unsigned int itc = 0;
0051 for (auto& tc : fpga_tcs) {
0052 fpga_tcs_SA.emplace_back(tc->position().x(),
0053 tc->position().y(),
0054 tc->position().z(),
0055 triggerTools_.zside(tc->detId()),
0056 triggerTools_.layerWithOffset(tc->detId()),
0057 tc->eta(),
0058 tc->phi(),
0059 tc->pt(),
0060 tc->mipPt(),
0061 itc);
0062 ++itc;
0063 }
0064 }
0065
0066 void HGCalStage1TruncationWrapper::convertAlgorithmOutputs(
0067 const l1thgcfirmware::HGCalTriggerCellSACollection& fpga_tcs_out,
0068 const std::vector<edm::Ptr<l1t::HGCalTriggerCell>>& fpga_tcs_original,
0069 std::vector<edm::Ptr<l1t::HGCalTriggerCell>>& fpga_tcs_trunc) const {
0070 for (auto& tc : fpga_tcs_out) {
0071 unsigned tc_cmssw_id = tc.index_cmssw();
0072 fpga_tcs_trunc.push_back(fpga_tcs_original[tc_cmssw_id]);
0073 }
0074 }
0075
0076 void HGCalStage1TruncationWrapper::process(const std::vector<edm::Ptr<l1t::HGCalTriggerCell>>& fpga_tcs,
0077 std::vector<edm::Ptr<l1t::HGCalTriggerCell>>& tcs_out) const {
0078 l1thgcfirmware::HGCalTriggerCellSACollection fpga_tcs_SA;
0079 convertCMSSWInputs(fpga_tcs, fpga_tcs_SA);
0080
0081 l1thgcfirmware::HGCalTriggerCellSACollection tcs_out_SA;
0082 unsigned error_code = theAlgo_.run(fpga_tcs_SA, theConfiguration_, tcs_out_SA);
0083
0084 if (error_code == 1)
0085 throw cms::Exception("HGCalStage1TruncationImpl::OutOfRange") << "roverzbin index out of range";
0086
0087 convertAlgorithmOutputs(tcs_out_SA, fpga_tcs, tcs_out);
0088 }
0089
0090 void HGCalStage1TruncationWrapper::configure(
0091 const std::tuple<const HGCalTriggerGeometryBase* const, const unsigned&, const uint32_t&>& configuration) {
0092 setGeometry(std::get<0>(configuration));
0093
0094 theConfiguration_.setSector120(std::get<1>(configuration));
0095 theConfiguration_.setFPGAID(std::get<2>(configuration));
0096 };
0097
0098 DEFINE_EDM_PLUGIN(HGCalStage1TruncationWrapperBaseFactory,
0099 HGCalStage1TruncationWrapper,
0100 "HGCalStage1TruncationWrapper");