CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/L1Trigger/GlobalCaloTrigger/src/L1GctHtMissLut.cc

Go to the documentation of this file.
00001 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctHtMissLut.h"
00002 
00003 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
00004 
00005 #include <math.h>
00006 
00007 //DEFINE STATICS
00008 const int L1GctHtMissLut::NAddress=2*L1GctHtMissLut::kHxOrHyMissComponentNBits;
00009 const int L1GctHtMissLut::NData   =L1GctHtMissLut::kHtMissMagnitudeNBits+L1GctHtMissLut::kHtMissAngleNBits;
00010 
00011 L1GctHtMissLut::L1GctHtMissLut(const L1CaloEtScale* const scale, const double lsb) :
00012   L1GctLut<NAddress,NData>(),
00013   m_etScale(scale),
00014   m_componentLsb(lsb)
00015 {
00016   if (scale != 0) m_setupOk = true;
00017 }
00018 
00019 L1GctHtMissLut::L1GctHtMissLut() :
00020   L1GctLut<NAddress,NData>(),
00021   m_etScale(0),
00022   m_componentLsb(1.0)
00023 {
00024 }
00025 
00026 L1GctHtMissLut::L1GctHtMissLut(const L1GctHtMissLut& lut) :
00027   L1GctLut<NAddress,NData>(),
00028   m_etScale(lut.etScale()),
00029   m_componentLsb(lut.componentLsb())
00030 {
00031   if (m_etScale != 0) m_setupOk = true;
00032 }
00033 
00034 L1GctHtMissLut::~L1GctHtMissLut()
00035 {
00036 }
00037 
00038 
00039 uint16_t L1GctHtMissLut::value (const uint16_t lutAddress) const
00040 {
00041   uint16_t result=0;
00042 
00043   if (lutAddress!=0) {
00044     static const int maxComponent  = 1<<kHxOrHyMissComponentNBits;
00045     static const int componentMask = maxComponent-1;
00046 
00047     static const int magnitudeMask = (1<<kHtMissMagnitudeNBits) - 1;
00048     static const int angleMask     = (1<<kHtMissAngleNBits)     - 1;
00049 
00050     // Extract the bits corresponding to hx and hy components
00051     int hxCompGct = static_cast<int>(lutAddress>>kHxOrHyMissComponentNBits) & componentMask;
00052     int hyCompGct = static_cast<int>(lutAddress) & componentMask;
00053 
00054     // These are twos-complement integers - if the MSB is set, the value is negative
00055     if (hxCompGct >= maxComponent/2) hxCompGct -= maxComponent;
00056     if (hyCompGct >= maxComponent/2) hyCompGct -= maxComponent;
00057 
00058     // Convert to GeV. Add 0.5 to each component to compensate for truncation errors.
00059     double hxCompGeV = m_componentLsb * (static_cast<double>(hxCompGct) + 0.5);
00060     double hyCompGeV = m_componentLsb * (static_cast<double>(hyCompGct) + 0.5);
00061 
00062     // Convert to magnitude and angle
00063     double htMissMag = sqrt(hxCompGeV * hxCompGeV + hyCompGeV * hyCompGeV);
00064     double htMissAng = atan2(hyCompGeV, hxCompGeV);
00065     if (htMissAng < 0.0) htMissAng += 2.0*M_PI;
00066 
00067     // Convert back to integer
00068     int htMissMagBits = static_cast<int>(m_etScale->rank(htMissMag)) & magnitudeMask;
00069     int htMissAngBits = static_cast<int>(htMissAng*9.0/M_PI) & angleMask;
00070 
00071     // Form the lut output
00072     result = (htMissMagBits << kHtMissAngleNBits) | htMissAngBits ;
00073   }
00074 
00075   return result;
00076 
00077 }
00078 
00079 
00080 std::vector<double>   L1GctHtMissLut::getThresholdsGeV() const
00081 {
00082   return m_etScale->getThresholds();
00083 }
00084 
00085 std::vector<unsigned> L1GctHtMissLut::getThresholdsGct() const
00086 {
00087   std::vector<unsigned> result;
00088   std::vector<double> thresholdsGeV = m_etScale->getThresholds();
00089   for (std::vector<double>::const_iterator thr=thresholdsGeV.begin();
00090        thr != thresholdsGeV.end(); thr++) {
00091     result.push_back(static_cast<unsigned>((*thr)/(m_componentLsb)));
00092   }
00093   return result;
00094 }
00095 
00096 L1GctHtMissLut L1GctHtMissLut::operator= (const L1GctHtMissLut& lut)
00097 {
00098   L1GctHtMissLut temp(lut);
00099   return temp;
00100 }
00101 
00102 std::ostream& operator << (std::ostream& os, const L1GctHtMissLut& lut)
00103 {
00104   os << "===L1GctHtMissLut===" << std::endl;
00105   std::vector<double> thresholds = lut.m_etScale->getThresholds();
00106   std::vector<double>::const_iterator thr = thresholds.begin();
00107   os << "Thresholds are: " << *(thr++);
00108   for ( ; thr != thresholds.end(); thr++) {
00109     os << ", " << *thr;
00110   }
00111   os << std::endl;
00112   os << "Max values for input to et scale " << lut.m_etScale->linScaleMax()
00113      << " and for output " << lut.m_etScale->rankScaleMax() << std::endl;
00114   os << "LSB used for conversion is " << lut.m_componentLsb << " GeV" << std::endl;
00115   os << "\n===Lookup table contents===\n" << std::endl;
00116   const L1GctLut<L1GctHtMissLut::NAddress,L1GctHtMissLut::NData>* temp=&lut;
00117   os << *temp;
00118   return os;
00119 }
00120 
00121 template class L1GctLut<L1GctHtMissLut::NAddress,L1GctHtMissLut::NData>;
00122 
00123