Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:09

0001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctGlobalHfSumAlgos.h"
0002 
0003 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
0004 
0005 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelJetFpga.h"
0006 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctHfBitCountsLut.h"
0007 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctHfEtSumsLut.h"
0008 
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 L1GctGlobalHfSumAlgos::L1GctGlobalHfSumAlgos(const std::vector<L1GctWheelJetFpga*>& wheelJetFpga)
0012     : L1GctProcessor(),
0013       m_plusWheelJetFpga(wheelJetFpga.at(1)),
0014       m_minusWheelJetFpga(wheelJetFpga.at(0)),
0015       m_bitCountLuts(),
0016       m_etSumLuts(),
0017       m_hfInputSumsPlusWheel(),
0018       m_hfInputSumsMinusWheel(),
0019       m_hfOutputSumsPipe(),
0020       m_setupOk(true) {
0021   if (wheelJetFpga.size() != 2) {
0022     m_setupOk = false;
0023     if (m_verbose) {
0024       edm::LogWarning("L1GctSetupError")
0025           << "L1GctGlobalHfSumAlgos::L1GctGlobalHfSumAlgos() : Global HfSum Algos has been incorrectly constructed!\n"
0026           << "This class needs two wheel jet fpga pointers. "
0027           << "Number of wheel jet fpga pointers present is " << wheelJetFpga.size() << ".\n";
0028     }
0029   }
0030 
0031   if (m_plusWheelJetFpga == nullptr) {
0032     m_setupOk = false;
0033     if (m_verbose) {
0034       edm::LogWarning("L1GctSetupError")
0035           << "L1GctGlobalHfSumAlgos::L1GctGlobalHfSumAlgos() has been incorrectly constructed!\n"
0036           << "Plus Wheel Jet Fpga pointer has not been set!\n";
0037     }
0038   }
0039   if (m_minusWheelJetFpga == nullptr) {
0040     m_setupOk = false;
0041     if (m_verbose) {
0042       edm::LogWarning("L1GctSetupError")
0043           << "L1GctGlobalHfSumAlgos::L1GctGlobalHfSumAlgos() has been incorrectly constructed!\n"
0044           << "Minus Wheel Jet Fpga pointer has not been set!\n";
0045     }
0046   }
0047 
0048   if (!m_setupOk && m_verbose) {
0049     edm::LogError("L1GctSetupError") << "L1GctGlobalEnergyAlgos has been incorrectly constructed";
0050   }
0051 }
0052 
0053 L1GctGlobalHfSumAlgos::~L1GctGlobalHfSumAlgos() {
0054   std::map<L1GctHfEtSumsLut::hfLutType, const L1GctHfBitCountsLut*>::const_iterator bclut = m_bitCountLuts.begin();
0055   while (bclut != m_bitCountLuts.end()) {
0056     delete bclut->second;
0057     bclut++;
0058   }
0059   std::map<L1GctHfEtSumsLut::hfLutType, const L1GctHfEtSumsLut*>::const_iterator eslut = m_etSumLuts.begin();
0060   while (eslut != m_etSumLuts.end()) {
0061     delete eslut->second;
0062     eslut++;
0063   }
0064 }
0065 
0066 std::ostream& operator<<(std::ostream& os, const L1GctGlobalHfSumAlgos& fpga) {
0067   os << "===L1GctGlobalHfSumAlgos===" << std::endl;
0068   os << "WheelJetFpga* plus  = " << fpga.m_plusWheelJetFpga << std::endl;
0069   os << "Plus wheel inputs:" << std::endl;
0070   os << "Bit counts ring 1: " << fpga.m_hfInputSumsPlusWheel.nOverThreshold0
0071      << ", ring 2: " << fpga.m_hfInputSumsPlusWheel.nOverThreshold1 << std::endl;
0072   os << "Et sums ring 1: " << fpga.m_hfInputSumsPlusWheel.etSum0 << ", ring 2: " << fpga.m_hfInputSumsPlusWheel.etSum1
0073      << std::endl;
0074   os << "WheelJetFpga* minus = " << fpga.m_minusWheelJetFpga << std::endl;
0075   os << "Minus wheel inputs:" << std::endl;
0076   os << "Bit counts ring 1: " << fpga.m_hfInputSumsMinusWheel.nOverThreshold0
0077      << ", ring 2: " << fpga.m_hfInputSumsMinusWheel.nOverThreshold1 << std::endl;
0078   os << "Et sums ring 1: " << fpga.m_hfInputSumsMinusWheel.etSum0 << ", ring 2: " << fpga.m_hfInputSumsMinusWheel.etSum1
0079      << std::endl;
0080 
0081   int bxZero = -fpga.bxMin();
0082   if (bxZero >= 0 && bxZero < fpga.numOfBx()) {
0083     os << "Output word " << std::hex << fpga.hfSumsWord().at(bxZero) << std::dec << std::endl;
0084   }
0085 
0086   return os;
0087 }
0088 
0089 void L1GctGlobalHfSumAlgos::resetProcessor() {
0090   m_hfInputSumsPlusWheel.reset();
0091   m_hfInputSumsMinusWheel.reset();
0092 }
0093 
0094 void L1GctGlobalHfSumAlgos::resetPipelines() {
0095   m_hfOutputSumsPipe.clear();
0096   Pipeline<uint16_t> temp(numOfBx());
0097   // Make one copy of the empty pipeline for each type of Hf lut
0098   unsigned nTypes = (unsigned)L1GctHfEtSumsLut::numberOfLutTypes;
0099   for (unsigned t = 0; t < nTypes; ++t) {
0100     m_hfOutputSumsPipe[(L1GctHfEtSumsLut::hfLutType)t] = temp;
0101   }
0102 }
0103 
0104 void L1GctGlobalHfSumAlgos::fetchInput() {
0105   if (m_setupOk) {
0106     m_hfInputSumsPlusWheel = m_plusWheelJetFpga->getOutputHfSums();
0107     m_hfInputSumsMinusWheel = m_minusWheelJetFpga->getOutputHfSums();
0108   }
0109 }
0110 
0111 // process the event
0112 void L1GctGlobalHfSumAlgos::process() {
0113   if (m_setupOk) {
0114     // step through the different types of Hf summed quantity
0115     // and store each one in turn into the relevant pipeline
0116 
0117     // bit count, positive eta, ring 1
0118     storeBitCount(L1GctHfEtSumsLut::bitCountPosEtaRing1, m_hfInputSumsPlusWheel.nOverThreshold0.value());
0119 
0120     // bit count, negative eta, ring 1
0121     storeBitCount(L1GctHfEtSumsLut::bitCountNegEtaRing1, m_hfInputSumsMinusWheel.nOverThreshold0.value());
0122 
0123     // bit count, positive eta, ring 2
0124     storeBitCount(L1GctHfEtSumsLut::bitCountPosEtaRing2, m_hfInputSumsPlusWheel.nOverThreshold1.value());
0125 
0126     // bit count, negative eta, ring 2
0127     storeBitCount(L1GctHfEtSumsLut::bitCountNegEtaRing2, m_hfInputSumsMinusWheel.nOverThreshold1.value());
0128 
0129     // et sum, positive eta, ring 1
0130     storeEtSum(L1GctHfEtSumsLut::etSumPosEtaRing1, m_hfInputSumsPlusWheel.etSum0.value());
0131 
0132     // et sum, negative eta, ring 1
0133     storeEtSum(L1GctHfEtSumsLut::etSumNegEtaRing1, m_hfInputSumsMinusWheel.etSum0.value());
0134 
0135     // et sum, positive eta, ring 2
0136     storeEtSum(L1GctHfEtSumsLut::etSumPosEtaRing2, m_hfInputSumsPlusWheel.etSum1.value());
0137 
0138     // et sum, negative eta, ring 2
0139     storeEtSum(L1GctHfEtSumsLut::etSumNegEtaRing2, m_hfInputSumsMinusWheel.etSum1.value());
0140   }
0141 }
0142 
0143 // Convert bit count value using LUT and store in the pipeline
0144 void L1GctGlobalHfSumAlgos::storeBitCount(L1GctHfEtSumsLut::hfLutType type, uint16_t value) {
0145   std::map<L1GctHfEtSumsLut::hfLutType, const L1GctHfBitCountsLut*>::const_iterator bclut = m_bitCountLuts.find(type);
0146   if (bclut != m_bitCountLuts.end()) {
0147     m_hfOutputSumsPipe[type].store((*bclut->second)[value], bxRel());
0148   }
0149 }
0150 
0151 // Convert et sum value using LUT and store in the pipeline
0152 void L1GctGlobalHfSumAlgos::storeEtSum(L1GctHfEtSumsLut::hfLutType type, uint16_t value) {
0153   std::map<L1GctHfEtSumsLut::hfLutType, const L1GctHfEtSumsLut*>::const_iterator eslut = m_etSumLuts.find(type);
0154   if (eslut != m_etSumLuts.end()) {
0155     m_hfOutputSumsPipe[type].store((*eslut->second)[value], bxRel());
0156   }
0157 }
0158 
0159 /// Access to output quantities
0160 std::vector<uint16_t> L1GctGlobalHfSumAlgos::hfSumsOutput(const L1GctHfEtSumsLut::hfLutType type) const {
0161   std::vector<uint16_t> result(numOfBx());
0162   std::map<L1GctHfEtSumsLut::hfLutType, Pipeline<uint16_t> >::const_iterator lut = m_hfOutputSumsPipe.find(type);
0163   if (lut != m_hfOutputSumsPipe.end()) {
0164     result = (lut->second).contents;
0165   }
0166 
0167   return result;
0168 }
0169 
0170 std::vector<unsigned> L1GctGlobalHfSumAlgos::hfSumsWord() const {
0171   std::vector<unsigned> result(numOfBx(), 0x00001000);
0172   std::vector<uint16_t> outputBits;
0173 
0174   outputBits = hfSumsOutput(L1GctHfEtSumsLut::bitCountPosEtaRing1);
0175   for (unsigned bx = 0; bx < outputBits.size(); bx++) {
0176     result.at(bx) |= outputBits.at(bx);
0177   }
0178 
0179   outputBits = hfSumsOutput(L1GctHfEtSumsLut::bitCountNegEtaRing1);
0180   for (unsigned bx = 0; bx < outputBits.size(); bx++) {
0181     result.at(bx) |= outputBits.at(bx) << 3;
0182   }
0183 
0184   outputBits = hfSumsOutput(L1GctHfEtSumsLut::bitCountPosEtaRing2);
0185   for (unsigned bx = 0; bx < outputBits.size(); bx++) {
0186     result.at(bx) |= outputBits.at(bx) << 6;
0187   }
0188 
0189   outputBits = hfSumsOutput(L1GctHfEtSumsLut::bitCountNegEtaRing2);
0190   for (unsigned bx = 0; bx < outputBits.size(); bx++) {
0191     result.at(bx) |= outputBits.at(bx) << 9;
0192   }
0193 
0194   outputBits = hfSumsOutput(L1GctHfEtSumsLut::etSumPosEtaRing1);
0195   for (unsigned bx = 0; bx < outputBits.size(); bx++) {
0196     result.at(bx) |= outputBits.at(bx) << 12;
0197   }
0198 
0199   outputBits = hfSumsOutput(L1GctHfEtSumsLut::etSumNegEtaRing1);
0200   for (unsigned bx = 0; bx < outputBits.size(); bx++) {
0201     result.at(bx) |= outputBits.at(bx) << 16;
0202   }
0203 
0204   outputBits = hfSumsOutput(L1GctHfEtSumsLut::etSumPosEtaRing2);
0205   for (unsigned bx = 0; bx < outputBits.size(); bx++) {
0206     result.at(bx) |= outputBits.at(bx) << 19;
0207   }
0208 
0209   outputBits = hfSumsOutput(L1GctHfEtSumsLut::etSumNegEtaRing2);
0210   for (unsigned bx = 0; bx < outputBits.size(); bx++) {
0211     result.at(bx) |= outputBits.at(bx) << 22;
0212   }
0213 
0214   return result;
0215 }
0216 
0217 /// Setup luts
0218 void L1GctGlobalHfSumAlgos::setupLuts(const L1CaloEtScale* scale) {
0219   // Replaces existing list of luts with a new one
0220   while (!m_bitCountLuts.empty()) {
0221     delete m_bitCountLuts.begin()->second;
0222     m_bitCountLuts.erase(m_bitCountLuts.begin());
0223   }
0224   m_bitCountLuts[L1GctHfEtSumsLut::bitCountPosEtaRing1] =
0225       new L1GctHfBitCountsLut(L1GctHfEtSumsLut::bitCountPosEtaRing1);
0226   m_bitCountLuts[L1GctHfEtSumsLut::bitCountPosEtaRing2] =
0227       new L1GctHfBitCountsLut(L1GctHfEtSumsLut::bitCountPosEtaRing2);
0228   m_bitCountLuts[L1GctHfEtSumsLut::bitCountNegEtaRing1] =
0229       new L1GctHfBitCountsLut(L1GctHfEtSumsLut::bitCountNegEtaRing1);
0230   m_bitCountLuts[L1GctHfEtSumsLut::bitCountNegEtaRing2] =
0231       new L1GctHfBitCountsLut(L1GctHfEtSumsLut::bitCountNegEtaRing2);
0232 
0233   while (!m_etSumLuts.empty()) {
0234     delete m_etSumLuts.begin()->second;
0235     m_etSumLuts.erase(m_etSumLuts.begin());
0236   }
0237   m_etSumLuts[L1GctHfEtSumsLut::etSumPosEtaRing1] = new L1GctHfEtSumsLut(L1GctHfEtSumsLut::etSumPosEtaRing1, scale);
0238   m_etSumLuts[L1GctHfEtSumsLut::etSumPosEtaRing2] = new L1GctHfEtSumsLut(L1GctHfEtSumsLut::etSumPosEtaRing2, scale);
0239   m_etSumLuts[L1GctHfEtSumsLut::etSumNegEtaRing1] = new L1GctHfEtSumsLut(L1GctHfEtSumsLut::etSumNegEtaRing1, scale);
0240   m_etSumLuts[L1GctHfEtSumsLut::etSumNegEtaRing2] = new L1GctHfEtSumsLut(L1GctHfEtSumsLut::etSumNegEtaRing2, scale);
0241 }
0242 
0243 /// Get lut pointers
0244 const L1GctHfBitCountsLut* L1GctGlobalHfSumAlgos::getBCLut(const L1GctHfEtSumsLut::hfLutType type) const {
0245   std::map<L1GctHfEtSumsLut::hfLutType, const L1GctHfBitCountsLut*>::const_iterator bclut = m_bitCountLuts.find(type);
0246   if (bclut != m_bitCountLuts.end()) {
0247     return (bclut->second);
0248   } else {
0249     return nullptr;
0250   }
0251 }
0252 
0253 const L1GctHfEtSumsLut* L1GctGlobalHfSumAlgos::getESLut(const L1GctHfEtSumsLut::hfLutType type) const {
0254   std::map<L1GctHfEtSumsLut::hfLutType, const L1GctHfEtSumsLut*>::const_iterator eslut = m_etSumLuts.find(type);
0255   if (eslut != m_etSumLuts.end()) {
0256     return (eslut->second);
0257   } else {
0258     return nullptr;
0259   }
0260 }
0261 
0262 /// Get thresholds
0263 std::vector<double> L1GctGlobalHfSumAlgos::getThresholds(const L1GctHfEtSumsLut::hfLutType type) const {
0264   std::vector<double> result;
0265   const L1GctHfEtSumsLut* ESLut = getESLut(type);
0266   if (ESLut != nullptr) {
0267     result = ESLut->lutFunction()->getThresholds();
0268   }
0269   return result;
0270 }