File indexing completed on 2024-04-06 12:19:52
0001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctGlobalEnergyAlgos.h"
0002
0003 #include "CondFormats/L1TObjects/interface/L1GctJetFinderParams.h"
0004
0005 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelEnergyFpga.h"
0006 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelJetFpga.h"
0007 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctGlobalHfSumAlgos.h"
0008
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010
0011 using std::endl;
0012 using std::max;
0013 using std::ostream;
0014 using std::vector;
0015
0016 L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos(const std::vector<L1GctWheelEnergyFpga*>& wheelFpga,
0017 const std::vector<L1GctWheelJetFpga*>& wheelJetFpga)
0018 : L1GctProcessor(),
0019 m_plusWheelFpga(wheelFpga.at(1)),
0020 m_minusWheelFpga(wheelFpga.at(0)),
0021 m_plusWheelJetFpga(wheelJetFpga.at(1)),
0022 m_minusWheelJetFpga(wheelJetFpga.at(0)),
0023 m_metComponents(0, 0, L1GctMet::cordicTranslate),
0024 m_mhtComponents(0, 0, L1GctMet::useHtMissLut),
0025 m_exValPlusWheel(),
0026 m_eyValPlusWheel(),
0027 m_etValPlusWheel(),
0028 m_htValPlusWheel(),
0029 m_exVlMinusWheel(),
0030 m_eyVlMinusWheel(),
0031 m_etVlMinusWheel(),
0032 m_htVlMinusWheel(),
0033 m_exValPlusPipe(),
0034 m_eyValPlusPipe(),
0035 m_etValPlusPipe(),
0036 m_htValPlusPipe(),
0037 m_exVlMinusPipe(),
0038 m_eyVlMinusPipe(),
0039 m_etVlMinusPipe(),
0040 m_htVlMinusPipe(),
0041 m_outputEtMiss(),
0042 m_outputEtMissPhi(),
0043 m_outputEtSum(),
0044 m_outputEtHad(),
0045 m_setupOk(true) {
0046 if (wheelFpga.size() != 2) {
0047 m_setupOk = false;
0048 if (m_verbose) {
0049 edm::LogWarning("L1GctSetupError") << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() : Global Energy Algos "
0050 "has been incorrectly constructed!\n"
0051 << "This class needs two wheel card pointers. "
0052 << "Number of wheel card pointers present is " << wheelFpga.size() << ".\n";
0053 }
0054 }
0055
0056 if (wheelJetFpga.size() != 2) {
0057 m_setupOk = false;
0058 if (m_verbose) {
0059 edm::LogWarning("L1GctSetupError") << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() : Global Energy Algos "
0060 "has been incorrectly constructed!\n"
0061 << "This class needs two wheel jet fpga pointers. "
0062 << "Number of wheel jet fpga pointers present is " << wheelJetFpga.size()
0063 << ".\n";
0064 }
0065 }
0066
0067 if (m_plusWheelFpga == nullptr) {
0068 m_setupOk = false;
0069 if (m_verbose) {
0070 edm::LogWarning("L1GctSetupError")
0071 << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() has been incorrectly constructed!\n"
0072 << "Plus Wheel Fpga pointer has not been set!\n";
0073 }
0074 }
0075 if (m_minusWheelFpga == nullptr) {
0076 m_setupOk = false;
0077 if (m_verbose) {
0078 edm::LogWarning("L1GctSetupError")
0079 << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() has been incorrectly constructed!\n"
0080 << "Minus Wheel Fpga pointer has not been set!\n";
0081 }
0082 }
0083 if (m_plusWheelJetFpga == nullptr) {
0084 m_setupOk = false;
0085 if (m_verbose) {
0086 edm::LogWarning("L1GctSetupError")
0087 << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() has been incorrectly constructed!\n"
0088 << "Plus Wheel Jet Fpga pointer has not been set!\n";
0089 }
0090 }
0091 if (m_minusWheelJetFpga == nullptr) {
0092 m_setupOk = false;
0093 if (m_verbose) {
0094 edm::LogWarning("L1GctSetupError")
0095 << "L1GctGlobalEnergyAlgos::L1GctGlobalEnergyAlgos() has been incorrectly constructed!\n"
0096 << "Minus Wheel Jet Fpga pointer has not been set!\n";
0097 }
0098 }
0099
0100
0101
0102
0103 m_metComponents.setBitShift(1);
0104
0105
0106 m_mhtComponents.setBitShift(0);
0107
0108
0109 m_hfSumProcessor = new L1GctGlobalHfSumAlgos(wheelJetFpga);
0110
0111 m_setupOk &= m_hfSumProcessor->setupOk();
0112
0113 if (!m_setupOk && m_verbose) {
0114 edm::LogError("L1GctSetupError") << "L1GctGlobalEnergyAlgos has been incorrectly constructed";
0115 }
0116 }
0117
0118 L1GctGlobalEnergyAlgos::~L1GctGlobalEnergyAlgos() {
0119 if (m_hfSumProcessor != nullptr) {
0120 delete m_hfSumProcessor;
0121 }
0122 }
0123
0124 ostream& operator<<(ostream& os, const L1GctGlobalEnergyAlgos& fpga) {
0125 os << "===L1GctGlobalEnergyAlgos===" << endl;
0126 os << "WheelEnergyFpga* minus = " << fpga.m_minusWheelFpga << endl;
0127 os << "WheelEnergyFpga* plus = " << fpga.m_plusWheelFpga << endl;
0128 os << "WheelJetFpga* minus = " << fpga.m_minusWheelJetFpga << endl;
0129 os << "WheelJetFpga* plus = " << fpga.m_plusWheelJetFpga << endl;
0130 os << "Inputs from Plus wheel:" << endl;
0131 os << " Ex " << fpga.m_exValPlusWheel << "\n Ey " << fpga.m_eyValPlusWheel << endl;
0132 os << " Et " << fpga.m_etValPlusWheel << "\n Ht " << fpga.m_htValPlusWheel << endl;
0133 os << "Inputs from Minus wheel:" << endl;
0134 os << " Ex " << fpga.m_exVlMinusWheel << "\n Ey " << fpga.m_eyVlMinusWheel << endl;
0135 os << " Et " << fpga.m_etVlMinusWheel << "\n Ht " << fpga.m_htVlMinusWheel << endl;
0136 int bxZero = -fpga.bxMin();
0137 if (bxZero >= 0 && bxZero < fpga.numOfBx()) {
0138 os << "Output Etmiss " << fpga.m_outputEtMiss.contents.at(bxZero) << endl;
0139 os << "Output Etmiss Phi " << fpga.m_outputEtMissPhi.contents.at(bxZero) << endl;
0140 os << "Output EtSum " << fpga.m_outputEtSum.contents.at(bxZero) << endl;
0141 os << "Output EtHad " << fpga.m_outputEtHad.contents.at(bxZero) << endl;
0142 }
0143 os << *fpga.m_hfSumProcessor;
0144
0145 return os;
0146 }
0147
0148
0149 void L1GctGlobalEnergyAlgos::reset() {
0150 L1GctProcessor::reset();
0151 m_hfSumProcessor->reset();
0152 }
0153
0154
0155 void L1GctGlobalEnergyAlgos::setBxRange(const int firstBx, const int numberOfBx) {
0156 L1GctProcessor::setBxRange(firstBx, numberOfBx);
0157 m_hfSumProcessor->setBxRange(firstBx, numberOfBx);
0158 }
0159
0160 void L1GctGlobalEnergyAlgos::setNextBx(const int bx) {
0161 L1GctProcessor::setNextBx(bx);
0162 m_hfSumProcessor->setNextBx(bx);
0163 }
0164
0165 void L1GctGlobalEnergyAlgos::resetProcessor() {
0166 m_exValPlusWheel.reset();
0167 m_exVlMinusWheel.reset();
0168 m_eyValPlusWheel.reset();
0169 m_eyVlMinusWheel.reset();
0170 m_etValPlusWheel.reset();
0171 m_etVlMinusWheel.reset();
0172 m_htValPlusWheel.reset();
0173 m_htVlMinusWheel.reset();
0174 m_hxValPlusWheel.reset();
0175 m_hxVlMinusWheel.reset();
0176 m_hyValPlusWheel.reset();
0177 m_hyVlMinusWheel.reset();
0178 }
0179
0180 void L1GctGlobalEnergyAlgos::resetPipelines() {
0181 m_outputEtMiss.reset(numOfBx());
0182 m_outputEtMissPhi.reset(numOfBx());
0183 m_outputEtSum.reset(numOfBx());
0184 m_outputEtHad.reset(numOfBx());
0185 m_outputHtMiss.reset(numOfBx());
0186 m_outputHtMissPhi.reset(numOfBx());
0187
0188 m_exValPlusPipe.reset(numOfBx());
0189 m_eyValPlusPipe.reset(numOfBx());
0190 m_etValPlusPipe.reset(numOfBx());
0191 m_htValPlusPipe.reset(numOfBx());
0192 m_hxValPlusPipe.reset(numOfBx());
0193 m_hyValPlusPipe.reset(numOfBx());
0194
0195 m_exVlMinusPipe.reset(numOfBx());
0196 m_eyVlMinusPipe.reset(numOfBx());
0197 m_etVlMinusPipe.reset(numOfBx());
0198 m_htVlMinusPipe.reset(numOfBx());
0199 m_hxVlMinusPipe.reset(numOfBx());
0200 m_hyVlMinusPipe.reset(numOfBx());
0201 }
0202
0203 void L1GctGlobalEnergyAlgos::fetchInput() {
0204 if (m_setupOk) {
0205
0206 m_exValPlusWheel = m_plusWheelFpga->getOutputEx();
0207 m_eyValPlusWheel = m_plusWheelFpga->getOutputEy();
0208 m_etValPlusWheel = m_plusWheelFpga->getOutputEt();
0209 m_htValPlusWheel = m_plusWheelFpga->getOutputHt();
0210 m_hxValPlusWheel = m_plusWheelJetFpga->getOutputHx();
0211 m_hyValPlusWheel = m_plusWheelJetFpga->getOutputHy();
0212
0213 m_exVlMinusWheel = m_minusWheelFpga->getOutputEx();
0214 m_eyVlMinusWheel = m_minusWheelFpga->getOutputEy();
0215 m_etVlMinusWheel = m_minusWheelFpga->getOutputEt();
0216 m_htVlMinusWheel = m_minusWheelFpga->getOutputHt();
0217 m_hxVlMinusWheel = m_minusWheelJetFpga->getOutputHx();
0218 m_hyVlMinusWheel = m_minusWheelJetFpga->getOutputHy();
0219
0220 m_hfSumProcessor->fetchInput();
0221 }
0222 }
0223
0224
0225 void L1GctGlobalEnergyAlgos::process() {
0226 if (m_setupOk) {
0227
0228 m_exValPlusPipe.store(m_exValPlusWheel, bxRel());
0229 m_eyValPlusPipe.store(m_eyValPlusWheel, bxRel());
0230 m_etValPlusPipe.store(m_etValPlusWheel, bxRel());
0231 m_htValPlusPipe.store(m_htValPlusWheel, bxRel());
0232 m_hxValPlusPipe.store(m_hxValPlusWheel, bxRel());
0233 m_hyValPlusPipe.store(m_hyValPlusWheel, bxRel());
0234
0235 m_exVlMinusPipe.store(m_exVlMinusWheel, bxRel());
0236 m_eyVlMinusPipe.store(m_eyVlMinusWheel, bxRel());
0237 m_etVlMinusPipe.store(m_etVlMinusWheel, bxRel());
0238 m_htVlMinusPipe.store(m_htVlMinusWheel, bxRel());
0239 m_hxVlMinusPipe.store(m_hxVlMinusWheel, bxRel());
0240 m_hyVlMinusPipe.store(m_hyVlMinusWheel, bxRel());
0241
0242
0243 etComponentType ExSum, EySum;
0244 etmiss_vec EtMissing, HtMissing;
0245
0246
0247
0248
0249 ExSum = m_exValPlusWheel + m_exVlMinusWheel;
0250 EySum = m_eyValPlusWheel + m_eyVlMinusWheel;
0251
0252
0253
0254 m_metComponents.setComponents(ExSum, EySum);
0255 EtMissing = m_metComponents.metVector();
0256 if (EtMissing.phi.value() > 35) {
0257 EtMissing.phi.setValue(EtMissing.phi.value() - 36);
0258 } else {
0259 EtMissing.phi.setValue(EtMissing.phi.value() + 36);
0260 }
0261 if (EtMissing.mag.value() == etMissMaxValue)
0262 EtMissing.mag.setOverFlow(true);
0263
0264 m_outputEtMiss.store(EtMissing.mag, bxRel());
0265 m_outputEtMissPhi.store(EtMissing.phi, bxRel());
0266
0267
0268
0269
0270 ExSum = m_hxValPlusWheel + m_hxVlMinusWheel;
0271 EySum = m_hyValPlusWheel + m_hyVlMinusWheel;
0272
0273
0274 m_mhtComponents.setComponents(ExSum, EySum);
0275 HtMissing = m_mhtComponents.metVector();
0276 if (HtMissing.phi.value() > 8) {
0277 HtMissing.phi.setValue(HtMissing.phi.value() - 9);
0278 } else {
0279 HtMissing.phi.setValue(HtMissing.phi.value() + 9);
0280 }
0281
0282
0283 static const unsigned MAX_HT_VALUE = 0x7f;
0284 static const unsigned PHI_HT_MASK = 0x1f;
0285 if ((HtMissing.mag.value() > MAX_HT_VALUE) || (HtMissing.mag.overFlow())) {
0286 HtMissing.mag.setValue(MAX_HT_VALUE);
0287 }
0288 HtMissing.phi.setValue(HtMissing.phi.value() & PHI_HT_MASK);
0289 m_outputHtMiss.store(HtMissing.mag, bxRel());
0290 m_outputHtMissPhi.store(HtMissing.phi, bxRel());
0291
0292
0293
0294
0295 etTotalType ettTemp = m_etValPlusWheel + m_etVlMinusWheel;
0296 if (ettTemp.overFlow())
0297 ettTemp.setValue(etTotalMaxValue);
0298 etHadType httTemp = m_htValPlusWheel + m_htVlMinusWheel;
0299 if (httTemp.overFlow())
0300 httTemp.setValue(etHadMaxValue);
0301 m_outputEtSum.store(ettTemp, bxRel());
0302 m_outputEtHad.store(httTemp, bxRel());
0303
0304 m_hfSumProcessor->process();
0305 }
0306 }
0307
0308
0309
0310
0311 void L1GctGlobalEnergyAlgos::setJetFinderParams(const L1GctJetFinderParams* const jfpars) {
0312
0313
0314 m_mhtComponents.setEtComponentLsb(jfpars->getHtLsbGeV() / 2);
0315 }
0316
0317 void L1GctGlobalEnergyAlgos::setHtMissScale(const L1CaloEtScale* const scale) { m_mhtComponents.setEtScale(scale); }
0318
0319
0320
0321
0322 bool L1GctGlobalEnergyAlgos::setupOk() const {
0323 return (m_setupOk && m_hfSumProcessor != nullptr && m_hfSumProcessor->setupOk());
0324 }
0325
0326
0327
0328
0329 void L1GctGlobalEnergyAlgos::setInputWheelEx(unsigned wheel, int energy, bool overflow) {
0330 if (wheel == 0) {
0331 m_exValPlusWheel.setValue(energy);
0332 m_exValPlusWheel.setOverFlow(overflow);
0333 } else if (wheel == 1) {
0334 m_exVlMinusWheel.setValue(energy);
0335 m_exVlMinusWheel.setOverFlow(overflow);
0336 }
0337 }
0338
0339
0340
0341
0342 void L1GctGlobalEnergyAlgos::setInputWheelEy(unsigned wheel, int energy, bool overflow) {
0343 if (wheel == 0) {
0344 m_eyValPlusWheel.setValue(energy);
0345 m_eyValPlusWheel.setOverFlow(overflow);
0346 } else if (wheel == 1) {
0347 m_eyVlMinusWheel.setValue(energy);
0348 m_eyVlMinusWheel.setOverFlow(overflow);
0349 }
0350 }
0351
0352
0353
0354
0355 void L1GctGlobalEnergyAlgos::setInputWheelEt(unsigned wheel, unsigned energy, bool overflow) {
0356 if (wheel == 0) {
0357 m_etValPlusWheel.setValue(energy);
0358 m_etValPlusWheel.setOverFlow(overflow);
0359 } else if (wheel == 1) {
0360 m_etVlMinusWheel.setValue(energy);
0361 m_etVlMinusWheel.setOverFlow(overflow);
0362 }
0363 }
0364
0365
0366
0367
0368 void L1GctGlobalEnergyAlgos::setInputWheelHt(unsigned wheel, unsigned energy, bool overflow) {
0369 if (wheel == 0) {
0370 m_htValPlusWheel.setValue(energy);
0371 m_htValPlusWheel.setOverFlow(overflow);
0372 } else if (wheel == 1) {
0373 m_htVlMinusWheel.setValue(energy);
0374 m_htVlMinusWheel.setOverFlow(overflow);
0375 }
0376 }
0377
0378
0379
0380
0381 void L1GctGlobalEnergyAlgos::setInputWheelHx(unsigned wheel, unsigned energy, bool overflow) {
0382 if (wheel == 0) {
0383 m_hxValPlusWheel.setValue(energy);
0384 m_hxValPlusWheel.setOverFlow(overflow);
0385 } else if (wheel == 1) {
0386 m_hxVlMinusWheel.setValue(energy);
0387 m_hxVlMinusWheel.setOverFlow(overflow);
0388 }
0389 }
0390
0391
0392
0393
0394 void L1GctGlobalEnergyAlgos::setInputWheelHy(unsigned wheel, unsigned energy, bool overflow) {
0395 if (wheel == 0) {
0396 m_hyValPlusWheel.setValue(energy);
0397 m_hyValPlusWheel.setOverFlow(overflow);
0398 } else if (wheel == 1) {
0399 m_hyVlMinusWheel.setValue(energy);
0400 m_hyVlMinusWheel.setOverFlow(overflow);
0401 }
0402 }