File indexing completed on 2024-04-06 12:20:42
0001 #include "L1Trigger/L1THGCal/interface/concentrator/HGCalConcentratorSuperTriggerCellImpl.h"
0002
0003 HGCalConcentratorSuperTriggerCellImpl::HGCalConcentratorSuperTriggerCellImpl(const edm::ParameterSet& conf)
0004 : fixedDataSizePerHGCROC_(conf.getParameter<bool>("fixedDataSizePerHGCROC")),
0005 coarsenTriggerCells_(conf.getParameter<std::vector<unsigned>>("coarsenTriggerCells")),
0006 coarseTCmapping_(conf.getParameter<std::vector<unsigned>>("ctcSize")),
0007 superTCmapping_(conf.getParameter<std::vector<unsigned>>("stcSize")),
0008 calibrationEE_(conf.getParameterSet("superTCCalibration_ee")),
0009 calibrationHEsi_(conf.getParameterSet("superTCCalibration_hesi")),
0010 calibrationHEsc_(conf.getParameterSet("superTCCalibration_hesc")),
0011 calibrationNose_(conf.getParameterSet("superTCCalibration_nose")),
0012 vfeCompression_(conf.getParameterSet("superTCCompression")) {
0013 std::string energyType(conf.getParameter<string>("type_energy_division"));
0014
0015 if (energyType == "superTriggerCell") {
0016 energyDivisionType_ = superTriggerCell;
0017 } else if (energyType == "oneBitFraction") {
0018 energyDivisionType_ = oneBitFraction;
0019
0020 oneBitFractionThreshold_ = conf.getParameter<double>("oneBitFractionThreshold");
0021 oneBitFractionLowValue_ = conf.getParameter<double>("oneBitFractionLowValue");
0022 oneBitFractionHighValue_ = conf.getParameter<double>("oneBitFractionHighValue");
0023
0024 } else if (energyType == "equalShare") {
0025 energyDivisionType_ = equalShare;
0026
0027 } else {
0028 energyDivisionType_ = superTriggerCell;
0029 }
0030 }
0031
0032 uint32_t HGCalConcentratorSuperTriggerCellImpl::getCompressedSTCEnergy(const SuperTriggerCell& stc) const {
0033 uint32_t code(0);
0034 uint64_t compressed_value(0);
0035 vfeCompression_.compressSingle(stc.getSumHwPt(), code, compressed_value);
0036
0037 if (compressed_value > std::numeric_limits<uint32_t>::max())
0038 edm::LogWarning("CompressedValueDowncasting") << "Compressed value cannot fit into 32-bit word. Downcasting.";
0039
0040 return static_cast<uint32_t>(compressed_value);
0041 }
0042
0043 void HGCalConcentratorSuperTriggerCellImpl::createAllTriggerCells(
0044 std::unordered_map<unsigned, SuperTriggerCell>& STCs, std::vector<l1t::HGCalTriggerCell>& trigCellVecOutput) const {
0045 for (auto& s : STCs) {
0046 std::vector<uint32_t> output_ids = superTCmapping_.getConstituentTriggerCells(s.second.getSTCId());
0047 if (output_ids.empty())
0048 continue;
0049
0050 HGCalTriggerTools::SubDetectorType subdet = triggerTools_.getSubDetectorType(output_ids.at(0));
0051 int thickness = (!output_ids.empty() ? triggerTools_.thicknessIndex(output_ids.at(0)) : 0);
0052
0053 for (const auto& id : output_ids) {
0054 if (((fixedDataSizePerHGCROC_ && thickness > kHighDensityThickness_) || coarsenTriggerCells_[subdet]) &&
0055 (id != coarseTCmapping_.getRepresentativeDetId(id))) {
0056 continue;
0057 }
0058
0059 if (!triggerTools_.getTriggerGeometry()->validTriggerCell(id)) {
0060 continue;
0061 }
0062
0063 l1t::HGCalTriggerCell triggerCell;
0064 triggerCell.setDetId(id);
0065 if (energyDivisionType_ == superTriggerCell && id != s.second.getMaxId()) {
0066 continue;
0067 }
0068
0069 DetId tc_Id(id);
0070
0071 if (superTCmapping_.getCoarseTriggerCellId(id) != s.second.getSTCId()) {
0072 throw cms::Exception("NonExistingCoarseTC")
0073 << "The coarse trigger cell correponsing to the nominal trigger cell does not exist";
0074 }
0075 trigCellVecOutput.push_back(triggerCell);
0076 if (energyDivisionType_ == oneBitFraction) {
0077
0078 if (id != s.second.getMaxId()) {
0079 float tc_fraction = getTriggerCellOneBitFraction(s.second.getTCpt(id), s.second.getSumPt());
0080 s.second.addToFractionSum(tc_fraction);
0081 }
0082 }
0083 }
0084 }
0085
0086 for (l1t::HGCalTriggerCell& tc : trigCellVecOutput) {
0087 const auto& stc = STCs[superTCmapping_.getCoarseTriggerCellId(tc.detId())];
0088 assignSuperTriggerCellEnergyAndPosition(tc, stc);
0089 }
0090 }
0091
0092 void HGCalConcentratorSuperTriggerCellImpl::assignSuperTriggerCellEnergyAndPosition(l1t::HGCalTriggerCell& c,
0093 const SuperTriggerCell& stc) const {
0094
0095 uint32_t compressed_value = getCompressedSTCEnergy(stc);
0096
0097 HGCalTriggerTools::SubDetectorType subdet = triggerTools_.getSubDetectorType(c.detId());
0098 int thickness = triggerTools_.thicknessIndex(c.detId());
0099
0100 bool isSilicon = triggerTools_.isSilicon(c.detId());
0101 bool isEM = triggerTools_.isEm(c.detId());
0102 bool isNose = triggerTools_.isNose(c.detId());
0103
0104 GlobalPoint point;
0105 if ((fixedDataSizePerHGCROC_ && thickness > kHighDensityThickness_) || coarsenTriggerCells_[subdet]) {
0106 point = coarseTCmapping_.getCoarseTriggerCellPosition(coarseTCmapping_.getCoarseTriggerCellId(c.detId()));
0107 } else {
0108 point = triggerTools_.getTCPosition(c.detId());
0109 }
0110 c.setPosition(point);
0111
0112 math::PtEtaPhiMLorentzVector p4(c.pt(), point.eta(), point.phi(), 0.);
0113 c.setP4(p4);
0114
0115 if (energyDivisionType_ == superTriggerCell) {
0116 if (c.detId() == stc.getMaxId()) {
0117 c.setHwPt(compressed_value);
0118 } else {
0119 throw cms::Exception("NonMaxIdSuperTriggerCell")
0120 << "Trigger Cell with detId not equal to the maximum of the superTriggerCell found";
0121 }
0122 } else if (energyDivisionType_ == equalShare) {
0123 double coarseTriggerCellSize =
0124 coarsenTriggerCells_[subdet]
0125 ? double(
0126 coarseTCmapping_.getConstituentTriggerCells(coarseTCmapping_.getCoarseTriggerCellId(stc.getMaxId()))
0127 .size())
0128 : 1.;
0129
0130 double denominator =
0131 fixedDataSizePerHGCROC_
0132 ? double(kTriggerCellsForDivision_)
0133 : double(superTCmapping_.getConstituentTriggerCells(stc.getSTCId()).size()) / coarseTriggerCellSize;
0134
0135 c.setHwPt(std::round(compressed_value / denominator));
0136
0137 } else if (energyDivisionType_ == oneBitFraction) {
0138 double frac = 0;
0139
0140 if (c.detId() != stc.getMaxId()) {
0141 frac = getTriggerCellOneBitFraction(stc.getTCpt(c.detId()), stc.getSumPt());
0142 } else {
0143 frac = 1 - stc.getFractionSum();
0144 }
0145
0146 c.setHwPt(std::round(compressed_value * frac));
0147 }
0148
0149 if (isNose) {
0150 calibrationNose_.calibrateInGeV(c);
0151 } else if (isSilicon) {
0152 if (isEM) {
0153 calibrationEE_.calibrateInGeV(c);
0154 } else {
0155 calibrationHEsi_.calibrateInGeV(c);
0156 }
0157 } else {
0158 calibrationHEsc_.calibrateInGeV(c);
0159 }
0160 }
0161
0162 float HGCalConcentratorSuperTriggerCellImpl::getTriggerCellOneBitFraction(float tcPt, float sumPt) const {
0163 double f = tcPt / sumPt;
0164 double frac = 0;
0165 if (f < oneBitFractionThreshold_) {
0166 frac = oneBitFractionLowValue_;
0167 } else {
0168 frac = oneBitFractionHighValue_;
0169 }
0170
0171 return frac;
0172 }
0173
0174 void HGCalConcentratorSuperTriggerCellImpl::select(const std::vector<l1t::HGCalTriggerCell>& trigCellVecInput,
0175 std::vector<l1t::HGCalTriggerCell>& trigCellVecOutput) {
0176 std::unordered_map<unsigned, SuperTriggerCell> STCs;
0177
0178 for (const l1t::HGCalTriggerCell& tc : trigCellVecInput) {
0179 uint32_t stcid = superTCmapping_.getCoarseTriggerCellId(tc.detId());
0180 STCs[stcid].add(tc, stcid);
0181 }
0182
0183 createAllTriggerCells(STCs, trigCellVecOutput);
0184 }