File indexing completed on 2024-04-06 12:20:24
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "L1Trigger/L1TCalorimeter/interface/Stage2Layer2EtSumAlgorithmFirmware.h"
0011 #include "L1Trigger/L1TCalorimeter/interface/CaloTools.h"
0012 #include <cmath>
0013
0014 l1t::Stage2Layer2EtSumAlgorithmFirmwareImp1::Stage2Layer2EtSumAlgorithmFirmwareImp1(CaloParamsHelper const* params)
0015 : params_(params) {
0016
0017 metEtaMax_ = params_->etSumEtaMax(2);
0018 metEtaMaxHF_ = CaloTools::kHFEnd;
0019 ettEtaMax_ = params_->etSumEtaMax(0);
0020 ettEtaMaxHF_ = CaloTools::kHFEnd;
0021
0022 nTowThresholdHw_ = floor(params_->etSumEtThreshold(4) / params_->towerLsbSum());
0023 nTowEtaMax_ = params_->etSumEtaMax(4);
0024 }
0025
0026 void l1t::Stage2Layer2EtSumAlgorithmFirmwareImp1::processEvent(const std::vector<l1t::CaloTower>& towers,
0027 std::vector<l1t::EtSum>& etsums) {
0028 unsigned int ntowers(0);
0029 math::XYZTLorentzVector p4;
0030
0031 int nTT4 = CaloTools::calNrTowers(-1 * params_->egPUSParam(1),
0032 params_->egPUSParam(1),
0033 1,
0034 72,
0035 towers,
0036 1 + params_->pileUpTowerThreshold(),
0037 999,
0038 CaloTools::CALO);
0039 if (nTT4 > 255)
0040 nTT4 = 255;
0041 unsigned int compNTT4 = params_->egCompressShapesLUT()->data((0x1 << 7) + (0x1 << 8) + (0x1 << 5) + nTT4);
0042
0043
0044 for (int etaSide = 1; etaSide >= -1; etaSide -= 2) {
0045 int ex(0), ey(0), et(0);
0046 int exHF(0), eyHF(0), etHF(0);
0047 int etem(0);
0048 unsigned int mb0(0), mb1(0);
0049
0050 bool ettSat(false), ettHFSat(false), ecalEtSat(false), metSat(false), metHFSat(false);
0051
0052 for (unsigned absieta = 1; absieta <= (unsigned int)CaloTools::mpEta(CaloTools::kHFEnd); absieta++) {
0053 int ieta = etaSide * absieta;
0054
0055 towEtMetThresh_ = 0;
0056 towEtSumEtThresh_ = 0;
0057 towEtEcalSumThresh_ = 0;
0058
0059 if (!params_->etSumBypassMetPUS()) {
0060 if (params_->etSumMetPUSType() == "LUT") {
0061 unsigned int towEtMetLUTAddr = (compNTT4 << 6) | (abs(ieta));
0062 if (abs(ieta) < 13)
0063 towEtMetLUTAddr = abs(ieta);
0064 towEtMetThresh_ = params_->etSumMetPUSLUT()->data(towEtMetLUTAddr);
0065 } else {
0066 if (params_->etSumMetPUSType() != "None" && params_->etSumMetPUSType() != "none") {
0067 edm::LogError("l1t|stage 2") << "Invalid PUS type in calo params. Not applying PUS to Stage 2 MET"
0068 << std::endl;
0069 return;
0070 }
0071 }
0072 }
0073
0074 if (!params_->etSumBypassEttPUS()) {
0075 if (params_->etSumEttPUSType() == "LUT") {
0076 unsigned int towEtSumEtLUTAddr = (compNTT4 << 6) | (abs(ieta));
0077 if (abs(ieta) < 13)
0078 towEtSumEtLUTAddr = abs(ieta);
0079 towEtSumEtThresh_ = params_->etSumEttPUSLUT()->data(towEtSumEtLUTAddr);
0080 } else {
0081 if (params_->etSumEttPUSType() != "None" && params_->etSumEttPUSType() != "none") {
0082 edm::LogError("l1t|stage 2") << "Invalid PUS type in calo params. Not applying PUS to Stage 2 ETT"
0083 << std::endl;
0084 return;
0085 }
0086 }
0087 }
0088
0089 if (!params_->etSumBypassEcalSumPUS()) {
0090 if (params_->etSumEcalSumPUSType() == "LUT") {
0091 unsigned int towEtEcalSumLUTAddr = (compNTT4 << 6) | (abs(ieta));
0092 if (abs(ieta) < 13)
0093 towEtEcalSumLUTAddr = abs(ieta);
0094 towEtEcalSumThresh_ = params_->etSumEcalSumPUSLUT()->data(towEtEcalSumLUTAddr);
0095 } else {
0096 if (params_->etSumEcalSumPUSType() != "None" && params_->etSumEcalSumPUSType() != "none") {
0097 edm::LogError("l1t|stage 2") << "Invalid PUS type in calo params. Not applying PUS to Stage 2 Ecal ETT"
0098 << std::endl;
0099 return;
0100 }
0101 }
0102 }
0103
0104 int ringEx(0), ringEy(0), ringEt(0);
0105 int ringExHF(0), ringEyHF(0), ringEtHF(0);
0106 int ringEtEm(0);
0107 unsigned int ringMB0(0), ringMB1(0);
0108 unsigned int ringNtowers(0);
0109
0110 for (int iphi = 1; iphi <= CaloTools::kHBHENrPhi; iphi++) {
0111 l1t::CaloTower tower = l1t::CaloTools::getTower(towers, CaloTools::caloEta(ieta), iphi);
0112
0113
0114
0115 if (tower.hwPt() > towEtMetThresh_ && CaloTools::mpEta(abs(tower.hwEta())) <= CaloTools::mpEta(metEtaMax_) &&
0116 !metSat) {
0117
0118
0119
0120
0121 if (tower.hwPt() == CaloTools::kSatHcal || tower.hwPt() == CaloTools::kSatEcal ||
0122 tower.hwPt() == CaloTools::kSatTower)
0123 metSat = true;
0124 ringEx += (int)(tower.hwPt() * CaloTools::cos_coeff[iphi - 1]);
0125 ringEy += (int)(tower.hwPt() * CaloTools::sin_coeff[iphi - 1]);
0126 }
0127
0128
0129 if (tower.hwPt() > towEtMetThresh_ && CaloTools::mpEta(abs(tower.hwEta())) <= CaloTools::mpEta(metEtaMaxHF_) &&
0130 !metHFSat) {
0131 if (tower.hwPt() == CaloTools::kSatHcal || tower.hwPt() == CaloTools::kSatEcal ||
0132 tower.hwPt() == CaloTools::kSatTower)
0133 metHFSat = true;
0134 ringExHF += (int)(tower.hwPt() * CaloTools::cos_coeff[iphi - 1]);
0135 ringEyHF += (int)(tower.hwPt() * CaloTools::sin_coeff[iphi - 1]);
0136 }
0137
0138
0139 if (tower.hwPt() > towEtSumEtThresh_ && CaloTools::mpEta(abs(tower.hwEta())) <= CaloTools::mpEta(ettEtaMax_) &&
0140 !ettSat) {
0141 if (tower.hwPt() == CaloTools::kSatHcal || tower.hwPt() == CaloTools::kSatEcal ||
0142 tower.hwPt() == CaloTools::kSatTower)
0143 ettSat = true;
0144 ringEt += tower.hwPt();
0145 }
0146
0147
0148 if (tower.hwPt() > towEtSumEtThresh_ &&
0149 CaloTools::mpEta(abs(tower.hwEta())) <= CaloTools::mpEta(ettEtaMaxHF_) && !ettHFSat) {
0150 if (tower.hwPt() == CaloTools::kSatHcal || tower.hwPt() == CaloTools::kSatEcal ||
0151 tower.hwPt() == CaloTools::kSatTower)
0152 ettHFSat = true;
0153 ringEtHF += tower.hwPt();
0154 }
0155
0156
0157 if (tower.hwPt() > towEtEcalSumThresh_ &&
0158 CaloTools::mpEta(abs(tower.hwEta())) <= CaloTools::mpEta(ettEtaMax_) && !ecalEtSat) {
0159 if (tower.hwPt() == CaloTools::kSatEcal || tower.hwPt() == CaloTools::kSatTower)
0160 ecalEtSat = true;
0161 ringEtEm += tower.hwEtEm();
0162 }
0163
0164
0165 if (CaloTools::mpEta(abs(tower.hwEta())) >= CaloTools::mpEta(CaloTools::kHFBegin) &&
0166 CaloTools::mpEta(abs(tower.hwEta())) <= CaloTools::mpEta(CaloTools::kHFEnd) && (tower.hwQual() & 0x4) > 0)
0167 ringMB0 += 1;
0168 if (CaloTools::mpEta(abs(tower.hwEta())) >= CaloTools::mpEta(CaloTools::kHFBegin) &&
0169 CaloTools::mpEta(abs(tower.hwEta())) <= CaloTools::mpEta(CaloTools::kHFEnd) && (tower.hwQual() & 0x8) > 0)
0170 ringMB1 += 1;
0171
0172
0173 if (tower.hwPt() > nTowThresholdHw_ && CaloTools::mpEta(abs(tower.hwEta())) <= nTowEtaMax_)
0174 ringNtowers += 1;
0175 }
0176
0177 ex += ringEx;
0178 ey += ringEy;
0179 et += ringEt;
0180 etHF += ringEtHF;
0181 exHF += ringExHF;
0182 eyHF += ringEyHF;
0183
0184 etem += ringEtEm;
0185
0186 mb0 += ringMB0;
0187 mb1 += ringMB1;
0188
0189 ntowers += ringNtowers;
0190 }
0191
0192 if (mb0 > 0xf)
0193 mb0 = 0xf;
0194 if (mb1 > 0xf)
0195 mb1 = 0xf;
0196
0197
0198
0199 if (ecalEtSat || etem > 0xffff)
0200 etem = 0xffff;
0201 if (ettSat || et > 0xffff)
0202 et = 0xffff;
0203 if (ettHFSat || etHF > 0xffff)
0204 etHF = 0xffff;
0205 if (metSat || ex > 0x7fffffff)
0206 ex = 0x7fffffff;
0207 if (metSat || ey > 0x7fffffff)
0208 ey = 0x7fffffff;
0209 if (metHFSat || exHF > 0x7fffffff)
0210 exHF = 0x7fffffff;
0211 if (metHFSat || eyHF > 0x7fffffff)
0212 eyHF = 0x7fffffff;
0213
0214 l1t::EtSum etSumTotalEt(p4, l1t::EtSum::EtSumType::kTotalEt, et, 0, 0, 0);
0215 l1t::EtSum etSumEx(p4, l1t::EtSum::EtSumType::kTotalEtx, ex, 0, 0, 0);
0216 l1t::EtSum etSumEy(p4, l1t::EtSum::EtSumType::kTotalEty, ey, 0, 0, 0);
0217
0218 l1t::EtSum etSumTotalEtHF(p4, l1t::EtSum::EtSumType::kTotalEtHF, etHF, 0, 0, 0);
0219 l1t::EtSum etSumExHF(p4, l1t::EtSum::EtSumType::kTotalEtxHF, exHF, 0, 0, 0);
0220 l1t::EtSum etSumEyHF(p4, l1t::EtSum::EtSumType::kTotalEtyHF, eyHF, 0, 0, 0);
0221
0222 l1t::EtSum etSumTotalEtEm(p4, l1t::EtSum::EtSumType::kTotalEtEm, etem, 0, 0, 0);
0223
0224 l1t::EtSum::EtSumType type0 = l1t::EtSum::EtSumType::kMinBiasHFP0;
0225 l1t::EtSum::EtSumType type1 = l1t::EtSum::EtSumType::kMinBiasHFP1;
0226 if (etaSide < 0) {
0227 type0 = l1t::EtSum::EtSumType::kMinBiasHFM0;
0228 type1 = l1t::EtSum::EtSumType::kMinBiasHFM1;
0229 }
0230 l1t::EtSum etSumMinBias0(p4, type0, mb0, 0, 0, 0);
0231 l1t::EtSum etSumMinBias1(p4, type1, mb1, 0, 0, 0);
0232
0233 etsums.push_back(etSumTotalEt);
0234 etsums.push_back(etSumEx);
0235 etsums.push_back(etSumEy);
0236
0237 etsums.push_back(etSumTotalEtHF);
0238 etsums.push_back(etSumExHF);
0239 etsums.push_back(etSumEyHF);
0240
0241 etsums.push_back(etSumTotalEtEm);
0242
0243 etsums.push_back(etSumMinBias0);
0244 etsums.push_back(etSumMinBias1);
0245 }
0246
0247
0248 l1t::EtSum etSumNtowers(p4, l1t::EtSum::EtSumType::kTowerCount, ntowers, 0, 0, 0);
0249 etsums.push_back(etSumNtowers);
0250 }