File indexing completed on 2025-09-12 10:09:58
0001 #include "L1Trigger/L1THGCal/interface/veryfrontend/HGCalVFEProcessorSums.h"
0002
0003 DEFINE_EDM_PLUGIN(HGCalVFEProcessorBaseFactory, HGCalVFEProcessorSums, "HGCalVFEProcessorSums");
0004
0005 HGCalVFEProcessorSums::HGCalVFEProcessorSums(const edm::ParameterSet& conf) : HGCalVFEProcessorBase(conf) {
0006 vfeLinearizationSiImpl_ =
0007 std::make_unique<HGCalVFELinearizationImpl>(conf.getParameter<edm::ParameterSet>("linearizationCfg_si"));
0008 vfeLinearizationScImpl_ =
0009 std::make_unique<HGCalVFELinearizationImpl>(conf.getParameter<edm::ParameterSet>("linearizationCfg_sc"));
0010
0011 vfeSummationImpl_ = std::make_unique<HGCalVFESummationImpl>(conf.getParameter<edm::ParameterSet>("summationCfg"));
0012
0013 vfeCompressionLDMImpl_ =
0014 std::make_unique<HGCalVFECompressionImpl>(conf.getParameter<edm::ParameterSet>("compressionCfg_ldm"));
0015 vfeCompressionHDMImpl_ =
0016 std::make_unique<HGCalVFECompressionImpl>(conf.getParameter<edm::ParameterSet>("compressionCfg_hdm"));
0017
0018 calibrationEE_ =
0019 std::make_unique<HGCalTriggerCellCalibration>(conf.getParameter<edm::ParameterSet>("calibrationCfg_ee"));
0020 calibrationHEsi_ =
0021 std::make_unique<HGCalTriggerCellCalibration>(conf.getParameter<edm::ParameterSet>("calibrationCfg_hesi"));
0022 calibrationHEsc_ =
0023 std::make_unique<HGCalTriggerCellCalibration>(conf.getParameter<edm::ParameterSet>("calibrationCfg_hesc"));
0024 calibrationNose_ =
0025 std::make_unique<HGCalTriggerCellCalibration>(conf.getParameter<edm::ParameterSet>("calibrationCfg_nose"));
0026 }
0027
0028 void HGCalVFEProcessorSums::run(const HGCalDigiCollection& digiColl,
0029 l1t::HGCalTriggerCellBxCollection& triggerCellColl) {
0030 vfeSummationImpl_->setGeometry(geometry());
0031 calibrationEE_->setGeometry(geometry());
0032 calibrationHEsi_->setGeometry(geometry());
0033 calibrationHEsc_->setGeometry(geometry());
0034 calibrationNose_->setGeometry(geometry());
0035 triggerTools_.setGeometry(geometry());
0036
0037 std::vector<HGCalDataFrame> dataframes;
0038 std::vector<std::pair<DetId, uint32_t>> linearized_dataframes;
0039 std::unordered_map<uint32_t, uint32_t> tc_payload;
0040 std::unordered_map<uint32_t, std::array<uint64_t, 2>> tc_compressed_payload;
0041
0042
0043 for (const auto& digiData : digiColl) {
0044 if (!geometry()->validCell(digiData.id()))
0045 continue;
0046 uint32_t module = geometry()->getModuleFromCell(digiData.id());
0047
0048
0049 if (DetId(digiData.id()).subdetId() != ForwardSubdetector::HFNose) {
0050 if (geometry()->disconnectedModule(module))
0051 continue;
0052 }
0053
0054 dataframes.emplace_back(digiData.id());
0055 for (int i = 0; i < digiData.size(); i++) {
0056 dataframes.back().setSample(i, digiData.sample(i));
0057 }
0058 }
0059 if (dataframes.empty())
0060 return;
0061
0062 bool isSilicon = triggerTools_.isSilicon(dataframes[0].id());
0063 bool isEM = triggerTools_.isEm(dataframes[0].id());
0064 bool isNose = triggerTools_.isNose(dataframes[0].id());
0065 bool isHighDensity = triggerTools_.isSiliconHighDensity(dataframes[0].id());
0066
0067 if (isSilicon) {
0068 vfeLinearizationSiImpl_->linearize(dataframes, linearized_dataframes);
0069 } else {
0070 vfeLinearizationScImpl_->linearize(dataframes, linearized_dataframes);
0071 }
0072
0073 vfeSummationImpl_->triggerCellSums(linearized_dataframes, tc_payload);
0074
0075 if (isHighDensity) {
0076 vfeCompressionHDMImpl_->compress(tc_payload, tc_compressed_payload);
0077 } else {
0078 vfeCompressionLDMImpl_->compress(tc_payload, tc_compressed_payload);
0079 }
0080
0081
0082 for (const auto& [tc_id, tc_value] : tc_payload) {
0083 if (tc_value > 0) {
0084 const auto& [tc_compressed_code, tc_compressed_value] = tc_compressed_payload[tc_id];
0085
0086 if (tc_compressed_value > std::numeric_limits<int>::max())
0087 edm::LogWarning("CompressedValueDowncasting") << "Compressed value cannot fit into 32-bit word. Downcasting.";
0088
0089 l1t::HGCalTriggerCell triggerCell(
0090 reco::LeafCandidate::LorentzVector(), static_cast<int>(tc_compressed_value), 0, 0, 0, tc_id);
0091
0092 if (tc_compressed_code > std::numeric_limits<uint32_t>::max())
0093 edm::LogWarning("CompressedValueDowncasting") << "Compressed code cannot fit into 32-bit word. Downcasting.";
0094
0095 triggerCell.setCompressedCharge(static_cast<uint32_t>(tc_compressed_code));
0096 triggerCell.setUncompressedCharge(tc_value);
0097 GlobalPoint point = geometry()->getTriggerCellPosition(tc_id);
0098
0099
0100 math::PtEtaPhiMLorentzVector p4((double)tc_compressed_value / cosh(point.eta()), point.eta(), point.phi(), 0.);
0101 triggerCell.setP4(p4);
0102 triggerCell.setPosition(point);
0103
0104
0105 if (triggerCell.hwPt() > 0) {
0106 l1t::HGCalTriggerCell calibratedtriggercell(triggerCell);
0107 if (isNose) {
0108 calibrationNose_->calibrateInGeV(calibratedtriggercell);
0109 } else if (isSilicon) {
0110 if (isEM) {
0111 calibrationEE_->calibrateInGeV(calibratedtriggercell);
0112 } else {
0113 calibrationHEsi_->calibrateInGeV(calibratedtriggercell);
0114 }
0115 } else {
0116 calibrationHEsc_->calibrateInGeV(calibratedtriggercell);
0117 }
0118 triggerCellColl.push_back(0, calibratedtriggercell);
0119 }
0120 }
0121 }
0122 }