File indexing completed on 2023-03-17 10:47:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
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
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
0030
0031 L1CaloEtScale::L1CaloEtScale(const double linearLsbInGeV, const vector<double>& thresholdsInGeV)
0032 : m_linScaleMax(0x3ff), m_rankScaleMax(0x3f), m_linearLsb(linearLsbInGeV), m_thresholds(thresholdsInGeV) {
0033
0034
0035
0036
0037 }
0038
0039
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
0052 uint16_t L1CaloEtScale::rank(const uint16_t linear) const { return rank((linear & m_linScaleMax) * m_linearLsb); }
0053
0054
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
0068 double L1CaloEtScale::et(const uint16_t rank) const {
0069
0070
0071
0072
0073
0074
0075
0076
0077
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 }