Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:19

0001 // -*- C++ -*-
0002 //
0003 // Package:     L1TObjects
0004 // Class  :     L1CaloEtScale
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Author:
0010 // Created:     Wed Sep 27 17:18:27 CEST 2006
0011 // $Id:
0012 
0013 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
0014 
0015 #include "FWCore/Utilities/interface/Exception.h"
0016 #include <stdexcept>
0017 
0018 using std::endl;
0019 using std::ostream;
0020 using std::vector;
0021 
0022 // default constructor (testing only!)
0023 L1CaloEtScale::L1CaloEtScale() : m_linScaleMax(0x3ff), m_rankScaleMax(0x3f), m_linearLsb(1.0) {
0024   for (unsigned i = 0; i < m_rankScaleMax; i++) {
0025     m_thresholds.push_back(m_linearLsb * i);
0026   }
0027 }
0028 
0029 // ctor that provides backwards compatibility with fixed max scale values
0030 // OK to use this with e/gamma and rank scales
0031 L1CaloEtScale::L1CaloEtScale(const double linearLsbInGeV, const vector<double>& thresholdsInGeV)
0032     : m_linScaleMax(0x3ff), m_rankScaleMax(0x3f), m_linearLsb(linearLsbInGeV), m_thresholds(thresholdsInGeV) {
0033   // protect against too many thresholds!
0034   //  while ( m_threshold.size() > (L1GctJetScale::maxRank+1) ) {
0035   //    m_thresholds.pop_back();
0036   //  }
0037 }
0038 
0039 // ctor that sets scale max values
0040 L1CaloEtScale::L1CaloEtScale(const unsigned linScaleMax,
0041                              const unsigned rankScaleMax,
0042                              const double linearLsbInGeV,
0043                              const vector<double>& thresholdsInGeV)
0044     : m_linScaleMax(linScaleMax),
0045       m_rankScaleMax(rankScaleMax),
0046       m_linearLsb(linearLsbInGeV),
0047       m_thresholds(thresholdsInGeV) {}
0048 
0049 L1CaloEtScale::~L1CaloEtScale() {}
0050 
0051 // convert from linear Et to rank
0052 uint16_t L1CaloEtScale::rank(const uint16_t linear) const { return rank((linear & m_linScaleMax) * m_linearLsb); }
0053 
0054 /// convert from Et in GeV to rank
0055 uint16_t L1CaloEtScale::rank(const double EtInGeV) const {
0056   uint16_t out = 0;
0057 
0058   for (unsigned i = 0; i < m_thresholds.size() && i < (unsigned)(m_rankScaleMax + 1); i++) {
0059     if (EtInGeV >= m_thresholds.at(i)) {
0060       out = i;
0061     }
0062   }
0063 
0064   return out & m_rankScaleMax;
0065 }
0066 
0067 // convert from rank to Et/GeV
0068 double L1CaloEtScale::et(const uint16_t rank) const {
0069   // return bin centre, except for highest bin
0070   //   if (rank < m_thresholds.size()-1) {
0071   //     return (m_thresholds[rank+1]+m_thresholds[rank]) / 2;
0072   //   }
0073   //   else {
0074   //     return m_thresholds.back();
0075   //   }
0076 
0077   // return bin lower edge
0078   try {
0079     return m_thresholds.at(rank);
0080   } catch (std::out_of_range const&) {
0081     throw cms::Exception("OutOfRange") << "Index out of range in L1CaloEtScale::et(rank)" << std::endl;
0082   }
0083 }
0084 
0085 void L1CaloEtScale::print(ostream& s) const {
0086   s << "L1CaloEtScale :" << endl;
0087   s << "  Input scale max = " << m_linScaleMax << endl;
0088   s << "  Input LSB       = " << m_linearLsb << " GeV" << endl;
0089   s << "  Rank scale max  = " << m_rankScaleMax << endl;
0090   for (unsigned i = 0; i < m_thresholds.size(); i++) {
0091     s << "  Threshold " << i << " = " << m_thresholds[i] << " GeV" << endl;
0092   }
0093 }
0094 
0095 std::ostream& operator<<(std::ostream& os, const L1CaloEtScale obj) {
0096   os << "L1CaloEtScale :" << endl;
0097   os << "  Input scale max = " << obj.linScaleMax() << endl;
0098   os << "  Input LSB       = " << obj.linearLsb() << " GeV" << endl;
0099   os << "  Rank scale max  = " << obj.rankScaleMax() << endl;
0100   for (unsigned i = 0; i < obj.getThresholds().size(); i++) {
0101     os << "  Threshold " << i << " = " << obj.getThresholds().at(i) << " GeV" << endl;
0102   }
0103   return os;
0104 }