CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/CondFormats/L1TObjects/src/L1CaloEtScale.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     L1TObjects
00004 // Class  :     L1CaloEtScale
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Author:      
00010 // Created:     Wed Sep 27 17:18:27 CEST 2006
00011 // $Id: 
00012 
00013 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
00014 
00015 #include "FWCore/Utilities/interface/Exception.h"
00016 #include <stdexcept>
00017 
00018 using std::vector;
00019 using std::ostream;
00020 using std::endl;
00021 
00022 // default constructor (testing only!)
00023 L1CaloEtScale::L1CaloEtScale() :
00024   m_linScaleMax(0x3ff),
00025   m_rankScaleMax(0x3f),
00026   m_linearLsb(1.0)
00027 {
00028   for (unsigned i=0; i<m_rankScaleMax; i++) {
00029     m_thresholds.push_back(m_linearLsb * i);
00030   }
00031 }
00032 
00033 // ctor that provides backwards compatibility with fixed max scale values
00034 // OK to use this with e/gamma and rank scales
00035 L1CaloEtScale::L1CaloEtScale(const double linearLsbInGeV, const vector<double> thresholdsInGeV) :
00036   m_linScaleMax(0x3ff),
00037   m_rankScaleMax(0x3f),
00038   m_linearLsb(linearLsbInGeV),
00039   m_thresholds(thresholdsInGeV) {
00040 
00041   // protect against too many thresholds!
00042   //  while ( m_threshold.size() > (L1GctJetScale::maxRank+1) ) {
00043   //    m_thresholds.pop_back();
00044   //  }
00045 
00046 }
00047 
00048 
00049 // ctor that sets scale max values
00050 L1CaloEtScale::L1CaloEtScale(const unsigned linScaleMax, const unsigned rankScaleMax, const double linearLsbInGeV, const vector<double> thresholdsInGeV) :
00051   m_linScaleMax(linScaleMax),
00052   m_rankScaleMax(rankScaleMax),
00053   m_linearLsb(linearLsbInGeV),
00054   m_thresholds(thresholdsInGeV) {
00055 
00056 }
00057 
00058 
00059 L1CaloEtScale::~L1CaloEtScale() {
00060 
00061 }
00062 
00063 // convert from linear Et to rank
00064 uint16_t L1CaloEtScale::rank(const uint16_t linear) const {
00065 
00066   return rank( (linear & m_linScaleMax) * m_linearLsb);
00067 
00068 }
00069 
00071 uint16_t L1CaloEtScale::rank(const double EtInGeV) const {
00072 
00073   uint16_t out = 0;
00074 
00075   for (unsigned i=0; i<m_thresholds.size() && i<(unsigned)(m_rankScaleMax+1); i++) {
00076     if ( EtInGeV >= m_thresholds.at(i) ) { out = i; }
00077   }
00078 
00079   return out & m_rankScaleMax;
00080 }
00081 
00082 // convert from rank to Et/GeV
00083 double L1CaloEtScale::et(const uint16_t rank) const {
00084 
00085   // return bin centre, except for highest bin
00086 //   if (rank < m_thresholds.size()-1) {
00087 //     return (m_thresholds[rank+1]+m_thresholds[rank]) / 2;
00088 //   }
00089 //   else {
00090 //     return m_thresholds.back();
00091 //   }
00092 
00093 // return bin lower edge
00094   try {
00095     return m_thresholds.at(rank);
00096   }
00097   catch(std::out_of_range) {
00098     throw cms::Exception("OutOfRange") << "Index out of range in L1CaloEtScale::et(rank)" << std::endl;
00099   }
00100 
00101 }
00102 
00103 void L1CaloEtScale::print(ostream& s) const {
00104   s << "L1CaloEtScale :" << endl;
00105   s << "  Input scale max = " << m_linScaleMax << endl;
00106   s << "  Input LSB       = " << m_linearLsb << " GeV" << endl;
00107   s << "  Rank scale max  = " << m_rankScaleMax << endl;
00108   for (unsigned i=0; i<m_thresholds.size(); i++) {
00109     s << "  Threshold " << i << " = " << m_thresholds[i] << " GeV" << endl;
00110   }
00111 }
00112 
00113 std::ostream& operator << (std::ostream& os, const L1CaloEtScale obj) {
00114   os << "L1CaloEtScale :" << endl;
00115   os << "  Input scale max = " << obj.linScaleMax() << endl;
00116   os << "  Input LSB       = " << obj.linearLsb() << " GeV" << endl;
00117   os << "  Rank scale max  = " << obj.rankScaleMax() << endl;
00118   for (unsigned i=0; i<obj.getThresholds().size(); i++) {
00119     os << "  Threshold " << i << " = " << obj.getThresholds().at(i) << " GeV" << endl;
00120   }
00121   return os ;
00122 }
00123 
00124 
00125