CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/L1Trigger/GlobalCaloTrigger/src/L1GctGlobalHfSumAlgos.cc

Go to the documentation of this file.
00001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctGlobalHfSumAlgos.h"
00002 
00003 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
00004 
00005 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctWheelJetFpga.h"
00006 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctHfBitCountsLut.h"
00007 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctHfEtSumsLut.h"
00008 
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 L1GctGlobalHfSumAlgos::L1GctGlobalHfSumAlgos(std::vector<L1GctWheelJetFpga*> wheelJetFpga) :
00012   L1GctProcessor(),
00013   m_plusWheelJetFpga(wheelJetFpga.at(1)),
00014   m_minusWheelJetFpga(wheelJetFpga.at(0)),
00015   m_bitCountLuts(), m_etSumLuts(),
00016   m_hfInputSumsPlusWheel(),
00017   m_hfInputSumsMinusWheel(),
00018   m_hfOutputSumsPipe(),
00019   m_setupOk(true)
00020 {
00021   if(wheelJetFpga.size() != 2)
00022     {
00023       m_setupOk = false;
00024       if (m_verbose) {
00025         edm::LogWarning("L1GctSetupError")
00026           << "L1GctGlobalHfSumAlgos::L1GctGlobalHfSumAlgos() : Global HfSum Algos has been incorrectly constructed!\n"
00027           << "This class needs two wheel jet fpga pointers. "
00028           << "Number of wheel jet fpga pointers present is " << wheelJetFpga.size() << ".\n";
00029       }
00030     }
00031   
00032   if(m_plusWheelJetFpga == 0)
00033     {
00034       m_setupOk = false;
00035       if (m_verbose) {
00036         edm::LogWarning("L1GctSetupError")
00037           << "L1GctGlobalHfSumAlgos::L1GctGlobalHfSumAlgos() has been incorrectly constructed!\n"
00038           << "Plus Wheel Jet Fpga pointer has not been set!\n";
00039       }
00040     }
00041   if(m_minusWheelJetFpga == 0)
00042     {
00043       m_setupOk = false;
00044       if (m_verbose) {
00045         edm::LogWarning("L1GctSetupError")
00046           << "L1GctGlobalHfSumAlgos::L1GctGlobalHfSumAlgos() has been incorrectly constructed!\n"
00047           << "Minus Wheel Jet Fpga pointer has not been set!\n";
00048       }
00049     }
00050 
00051     if (!m_setupOk && m_verbose) {
00052       edm::LogError("L1GctSetupError") << "L1GctGlobalEnergyAlgos has been incorrectly constructed";
00053     }
00054 }
00055 
00056 L1GctGlobalHfSumAlgos::~L1GctGlobalHfSumAlgos()
00057 {
00058   std::map<L1GctHfEtSumsLut::hfLutType, const L1GctHfBitCountsLut*>::const_iterator bclut = m_bitCountLuts.begin();
00059   while (bclut != m_bitCountLuts.end()) {
00060     delete bclut->second;
00061     bclut++;
00062   }
00063   std::map<L1GctHfEtSumsLut::hfLutType, const L1GctHfEtSumsLut*>::const_iterator eslut = m_etSumLuts.begin();
00064   while (eslut != m_etSumLuts.end()) {
00065     delete eslut->second;
00066     eslut++;
00067   }
00068 }
00069 
00070 std::ostream& operator << (std::ostream& os, const L1GctGlobalHfSumAlgos& fpga)
00071 {
00072   os << "===L1GctGlobalHfSumAlgos===" << std::endl;
00073   os << "WheelJetFpga* plus  = " << fpga.m_plusWheelJetFpga << std::endl;
00074   os << "Plus wheel inputs:" << std::endl;
00075   os << "Bit counts ring 1: " << fpga.m_hfInputSumsPlusWheel.nOverThreshold0 
00076      << ", ring 2: " << fpga.m_hfInputSumsPlusWheel.nOverThreshold1 << std::endl;
00077   os << "Et sums ring 1: " << fpga.m_hfInputSumsPlusWheel.etSum0 
00078      << ", ring 2: " << fpga.m_hfInputSumsPlusWheel.etSum1 << std::endl;
00079   os << "WheelJetFpga* minus = " << fpga.m_minusWheelJetFpga << std::endl;
00080   os << "Minus wheel inputs:" << std::endl;
00081   os << "Bit counts ring 1: " << fpga.m_hfInputSumsMinusWheel.nOverThreshold0 
00082      << ", ring 2: " << fpga.m_hfInputSumsMinusWheel.nOverThreshold1 << std::endl;
00083   os << "Et sums ring 1: " << fpga.m_hfInputSumsMinusWheel.etSum0 
00084      << ", ring 2: " << fpga.m_hfInputSumsMinusWheel.etSum1 << std::endl;
00085 
00086   int bxZero = -fpga.bxMin();
00087   if (bxZero>=0 && bxZero<fpga.numOfBx()) {
00088     os << "Output word " << std::hex << fpga.hfSumsWord().at(bxZero) << std::dec << std::endl;
00089   }
00090 
00091   return os;
00092 }
00093 
00094 void L1GctGlobalHfSumAlgos::resetProcessor() {
00095   m_hfInputSumsPlusWheel.reset();
00096   m_hfInputSumsMinusWheel.reset();
00097 }
00098 
00099 void L1GctGlobalHfSumAlgos::resetPipelines() {
00100   m_hfOutputSumsPipe.clear();
00101   Pipeline<uint16_t> temp(numOfBx());
00102   // Make one copy of the empty pipeline for each type of Hf lut
00103   unsigned nTypes = (unsigned) L1GctHfEtSumsLut::numberOfLutTypes;
00104   for (unsigned t=0; t<nTypes; ++t) {
00105     m_hfOutputSumsPipe[ (L1GctHfEtSumsLut::hfLutType) t] = temp;
00106   }
00107 }
00108 
00109 void L1GctGlobalHfSumAlgos::fetchInput() {
00110   if (m_setupOk) {
00111     m_hfInputSumsPlusWheel  = m_plusWheelJetFpga->getOutputHfSums();
00112     m_hfInputSumsMinusWheel = m_minusWheelJetFpga->getOutputHfSums();
00113   }
00114 }
00115 
00116 
00117 // process the event
00118 void L1GctGlobalHfSumAlgos::process()
00119 {
00120   if (m_setupOk) {
00121     // step through the different types of Hf summed quantity
00122     // and store each one in turn into the relevant pipeline
00123 
00124     // bit count, positive eta, ring 1
00125     storeBitCount(L1GctHfEtSumsLut::bitCountPosEtaRing1, m_hfInputSumsPlusWheel.nOverThreshold0.value() );
00126 
00127     // bit count, negative eta, ring 1
00128     storeBitCount(L1GctHfEtSumsLut::bitCountNegEtaRing1, m_hfInputSumsMinusWheel.nOverThreshold0.value() );
00129 
00130     // bit count, positive eta, ring 2
00131     storeBitCount(L1GctHfEtSumsLut::bitCountPosEtaRing2, m_hfInputSumsPlusWheel.nOverThreshold1.value() );
00132 
00133     // bit count, negative eta, ring 2
00134     storeBitCount(L1GctHfEtSumsLut::bitCountNegEtaRing2, m_hfInputSumsMinusWheel.nOverThreshold1.value() );
00135 
00136     // et sum, positive eta, ring 1
00137     storeEtSum(L1GctHfEtSumsLut::etSumPosEtaRing1, m_hfInputSumsPlusWheel.etSum0.value() );
00138 
00139     // et sum, negative eta, ring 1
00140     storeEtSum(L1GctHfEtSumsLut::etSumNegEtaRing1, m_hfInputSumsMinusWheel.etSum0.value() );
00141 
00142     // et sum, positive eta, ring 2
00143     storeEtSum(L1GctHfEtSumsLut::etSumPosEtaRing2, m_hfInputSumsPlusWheel.etSum1.value() );
00144 
00145     // et sum, negative eta, ring 2
00146     storeEtSum(L1GctHfEtSumsLut::etSumNegEtaRing2, m_hfInputSumsMinusWheel.etSum1.value() );
00147 
00148   }
00149 }
00150 
00151 // Convert bit count value using LUT and store in the pipeline
00152 void L1GctGlobalHfSumAlgos::storeBitCount(L1GctHfEtSumsLut::hfLutType type, uint16_t value) {
00153   std::map<L1GctHfEtSumsLut::hfLutType, const L1GctHfBitCountsLut*>::const_iterator bclut = m_bitCountLuts.find(type);
00154   if (bclut != m_bitCountLuts.end()) {
00155     m_hfOutputSumsPipe[type].store( (*bclut->second)[value], bxRel() );
00156   }
00157 }
00158 
00159 // Convert et sum value using LUT and store in the pipeline
00160 void L1GctGlobalHfSumAlgos::storeEtSum(L1GctHfEtSumsLut::hfLutType type, uint16_t value) {
00161   std::map<L1GctHfEtSumsLut::hfLutType, const L1GctHfEtSumsLut*>::const_iterator eslut = m_etSumLuts.find(type);
00162   if (eslut != m_etSumLuts.end()) {
00163     m_hfOutputSumsPipe[type].store( (*eslut->second)[value], bxRel() );
00164   }
00165 }
00166 
00167 
00168 
00170 std::vector<uint16_t> L1GctGlobalHfSumAlgos::hfSumsOutput(const L1GctHfEtSumsLut::hfLutType type) const
00171 {
00172   std::vector<uint16_t> result(numOfBx());
00173   std::map<L1GctHfEtSumsLut::hfLutType, Pipeline<uint16_t> >::const_iterator lut=m_hfOutputSumsPipe.find(type);
00174   if (lut != m_hfOutputSumsPipe.end()) {
00175     result = (lut->second).contents;
00176   }
00177 
00178   return result;
00179 
00180 }
00181 
00182 std::vector<unsigned> L1GctGlobalHfSumAlgos::hfSumsWord() const {
00183   std::vector<unsigned> result(numOfBx(), 0x00001000);
00184   std::vector<uint16_t> outputBits;
00185 
00186   outputBits = hfSumsOutput(L1GctHfEtSumsLut::bitCountPosEtaRing1);
00187   for (unsigned bx=0; bx<outputBits.size(); bx++) { result.at(bx) |= outputBits.at(bx); }
00188 
00189   outputBits = hfSumsOutput(L1GctHfEtSumsLut::bitCountNegEtaRing1);
00190   for (unsigned bx=0; bx<outputBits.size(); bx++) { result.at(bx) |= outputBits.at(bx) << 3; }
00191 
00192   outputBits = hfSumsOutput(L1GctHfEtSumsLut::bitCountPosEtaRing2);
00193   for (unsigned bx=0; bx<outputBits.size(); bx++) { result.at(bx) |= outputBits.at(bx) << 6; }
00194 
00195   outputBits = hfSumsOutput(L1GctHfEtSumsLut::bitCountNegEtaRing2);
00196   for (unsigned bx=0; bx<outputBits.size(); bx++) { result.at(bx) |= outputBits.at(bx) << 9; }
00197 
00198   outputBits = hfSumsOutput(L1GctHfEtSumsLut::etSumPosEtaRing1);
00199   for (unsigned bx=0; bx<outputBits.size(); bx++) { result.at(bx) |= outputBits.at(bx) << 12; }
00200 
00201   outputBits = hfSumsOutput(L1GctHfEtSumsLut::etSumNegEtaRing1);
00202   for (unsigned bx=0; bx<outputBits.size(); bx++) { result.at(bx) |= outputBits.at(bx) << 16; }
00203 
00204   outputBits = hfSumsOutput(L1GctHfEtSumsLut::etSumPosEtaRing2);
00205   for (unsigned bx=0; bx<outputBits.size(); bx++) { result.at(bx) |= outputBits.at(bx) << 19; }
00206 
00207   outputBits = hfSumsOutput(L1GctHfEtSumsLut::etSumNegEtaRing2);
00208   for (unsigned bx=0; bx<outputBits.size(); bx++) { result.at(bx) |= outputBits.at(bx) << 22; }
00209 
00210   return result;
00211 }
00212 
00214 void L1GctGlobalHfSumAlgos::setupLuts(const L1CaloEtScale* scale)
00215 {
00216   // Replaces existing list of luts with a new one
00217   while (!m_bitCountLuts.empty()) {
00218     delete m_bitCountLuts.begin()->second;
00219     m_bitCountLuts.erase(m_bitCountLuts.begin());
00220   }
00221   m_bitCountLuts[L1GctHfEtSumsLut::bitCountPosEtaRing1] = new L1GctHfBitCountsLut(L1GctHfEtSumsLut::bitCountPosEtaRing1);
00222   m_bitCountLuts[L1GctHfEtSumsLut::bitCountPosEtaRing2] = new L1GctHfBitCountsLut(L1GctHfEtSumsLut::bitCountPosEtaRing2);
00223   m_bitCountLuts[L1GctHfEtSumsLut::bitCountNegEtaRing1] = new L1GctHfBitCountsLut(L1GctHfEtSumsLut::bitCountNegEtaRing1);
00224   m_bitCountLuts[L1GctHfEtSumsLut::bitCountNegEtaRing2] = new L1GctHfBitCountsLut(L1GctHfEtSumsLut::bitCountNegEtaRing2);
00225 
00226   while (!m_etSumLuts.empty()) {
00227     delete m_etSumLuts.begin()->second;
00228     m_etSumLuts.erase(m_etSumLuts.begin());
00229   }
00230   m_etSumLuts[L1GctHfEtSumsLut::etSumPosEtaRing1] = new L1GctHfEtSumsLut(L1GctHfEtSumsLut::etSumPosEtaRing1, scale);
00231   m_etSumLuts[L1GctHfEtSumsLut::etSumPosEtaRing2] = new L1GctHfEtSumsLut(L1GctHfEtSumsLut::etSumPosEtaRing2, scale);
00232   m_etSumLuts[L1GctHfEtSumsLut::etSumNegEtaRing1] = new L1GctHfEtSumsLut(L1GctHfEtSumsLut::etSumNegEtaRing1, scale);
00233   m_etSumLuts[L1GctHfEtSumsLut::etSumNegEtaRing2] = new L1GctHfEtSumsLut(L1GctHfEtSumsLut::etSumNegEtaRing2, scale);
00234 
00235 }
00236 
00238 const L1GctHfBitCountsLut* L1GctGlobalHfSumAlgos::getBCLut(const L1GctHfEtSumsLut::hfLutType type) const
00239 {
00240   std::map<L1GctHfEtSumsLut::hfLutType, const L1GctHfBitCountsLut*>::const_iterator bclut = m_bitCountLuts.find(type);
00241   if (bclut != m_bitCountLuts.end()) {
00242     return (bclut->second);
00243   } else {
00244    return 0;
00245   }
00246 }
00247 
00248 const L1GctHfEtSumsLut* L1GctGlobalHfSumAlgos::getESLut(const L1GctHfEtSumsLut::hfLutType type) const
00249 {
00250   std::map<L1GctHfEtSumsLut::hfLutType, const L1GctHfEtSumsLut*>::const_iterator eslut = m_etSumLuts.find(type);
00251   if (eslut != m_etSumLuts.end()) {
00252     return (eslut->second);
00253   } else {
00254     return 0;
00255   }
00256 }
00257 
00259 std::vector<double> L1GctGlobalHfSumAlgos::getThresholds(const L1GctHfEtSumsLut::hfLutType type) const
00260 {
00261   std::vector<double> result;
00262   const L1GctHfEtSumsLut* ESLut = getESLut(type);
00263   if (ESLut != 0) { result = ESLut->lutFunction()->getThresholds(); }
00264   return result;
00265 } 
00266