Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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   // Remove disconnected modules and invalid cells
0043   for (const auto& digiData : digiColl) {
0044     if (!geometry()->validCell(digiData.id()))
0045       continue;
0046     uint32_t module = geometry()->getModuleFromCell(digiData.id());
0047 
0048     // no disconnected layer for HFNose
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   constexpr int kHighDensityThickness = 0;
0063   bool isSilicon = triggerTools_.isSilicon(dataframes[0].id());
0064   bool isEM = triggerTools_.isEm(dataframes[0].id());
0065   bool isNose = triggerTools_.isNose(dataframes[0].id());
0066   int thickness = triggerTools_.thicknessIndex(dataframes[0].id());
0067   // Linearization of ADC and TOT values to the same LSB
0068   if (isSilicon) {
0069     vfeLinearizationSiImpl_->linearize(dataframes, linearized_dataframes);
0070   } else {
0071     vfeLinearizationScImpl_->linearize(dataframes, linearized_dataframes);
0072   }
0073   // Sum of sensor cells into trigger cells
0074   vfeSummationImpl_->triggerCellSums(linearized_dataframes, tc_payload);
0075   // Compression of trigger cell charges to a floating point format
0076   if (thickness == kHighDensityThickness) {
0077     vfeCompressionHDMImpl_->compress(tc_payload, tc_compressed_payload);
0078   } else {
0079     vfeCompressionLDMImpl_->compress(tc_payload, tc_compressed_payload);
0080   }
0081 
0082   // Transform map to trigger cell vector
0083   for (const auto& [tc_id, tc_value] : tc_payload) {
0084     if (tc_value > 0) {
0085       const auto& [tc_compressed_code, tc_compressed_value] = tc_compressed_payload[tc_id];
0086 
0087       if (tc_compressed_value > std::numeric_limits<int>::max())
0088         edm::LogWarning("CompressedValueDowncasting") << "Compressed value cannot fit into 32-bit word. Downcasting.";
0089 
0090       l1t::HGCalTriggerCell triggerCell(
0091           reco::LeafCandidate::LorentzVector(), static_cast<int>(tc_compressed_value), 0, 0, 0, tc_id);
0092 
0093       if (tc_compressed_code > std::numeric_limits<uint32_t>::max())
0094         edm::LogWarning("CompressedValueDowncasting") << "Compressed code cannot fit into 32-bit word. Downcasting.";
0095 
0096       triggerCell.setCompressedCharge(static_cast<uint32_t>(tc_compressed_code));
0097       triggerCell.setUncompressedCharge(tc_value);
0098       GlobalPoint point = geometry()->getTriggerCellPosition(tc_id);
0099 
0100       // 'value' is hardware, so p4 is meaningless, except for eta and phi
0101       math::PtEtaPhiMLorentzVector p4((double)tc_compressed_value / cosh(point.eta()), point.eta(), point.phi(), 0.);
0102       triggerCell.setP4(p4);
0103       triggerCell.setPosition(point);
0104 
0105       // calibration
0106       if (triggerCell.hwPt() > 0) {
0107         l1t::HGCalTriggerCell calibratedtriggercell(triggerCell);
0108         if (isNose) {
0109           calibrationNose_->calibrateInGeV(calibratedtriggercell);
0110         } else if (isSilicon) {
0111           if (isEM) {
0112             calibrationEE_->calibrateInGeV(calibratedtriggercell);
0113           } else {
0114             calibrationHEsi_->calibrateInGeV(calibratedtriggercell);
0115           }
0116         } else {
0117           calibrationHEsc_->calibrateInGeV(calibratedtriggercell);
0118         }
0119         triggerCellColl.push_back(0, calibratedtriggercell);
0120       }
0121     }
0122   }
0123 }