CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1CaloEtScale.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1TObjects
4 // Class : L1CaloEtScale
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Author:
10 // Created: Wed Sep 27 17:18:27 CEST 2006
11 // $Id:
12 
14 
16 #include <stdexcept>
17 
18 using std::endl;
19 using std::ostream;
20 using std::vector;
21 
22 // default constructor (testing only!)
23 L1CaloEtScale::L1CaloEtScale() : m_linScaleMax(0x3ff), m_rankScaleMax(0x3f), m_linearLsb(1.0) {
24  for (unsigned i = 0; i < m_rankScaleMax; i++) {
25  m_thresholds.push_back(m_linearLsb * i);
26  }
27 }
28 
29 // ctor that provides backwards compatibility with fixed max scale values
30 // OK to use this with e/gamma and rank scales
31 L1CaloEtScale::L1CaloEtScale(const double linearLsbInGeV, const vector<double>& thresholdsInGeV)
32  : m_linScaleMax(0x3ff), m_rankScaleMax(0x3f), m_linearLsb(linearLsbInGeV), m_thresholds(thresholdsInGeV) {
33  // protect against too many thresholds!
34  // while ( m_threshold.size() > (L1GctJetScale::maxRank+1) ) {
35  // m_thresholds.pop_back();
36  // }
37 }
38 
39 // ctor that sets scale max values
40 L1CaloEtScale::L1CaloEtScale(const unsigned linScaleMax,
41  const unsigned rankScaleMax,
42  const double linearLsbInGeV,
43  const vector<double>& thresholdsInGeV)
44  : m_linScaleMax(linScaleMax),
45  m_rankScaleMax(rankScaleMax),
46  m_linearLsb(linearLsbInGeV),
47  m_thresholds(thresholdsInGeV) {}
48 
50 
51 // convert from linear Et to rank
52 uint16_t L1CaloEtScale::rank(const uint16_t linear) const { return rank((linear & m_linScaleMax) * m_linearLsb); }
53 
55 uint16_t L1CaloEtScale::rank(const double EtInGeV) const {
56  uint16_t out = 0;
57 
58  for (unsigned i = 0; i < m_thresholds.size() && i < (unsigned)(m_rankScaleMax + 1); i++) {
59  if (EtInGeV >= m_thresholds.at(i)) {
60  out = i;
61  }
62  }
63 
64  return out & m_rankScaleMax;
65 }
66 
67 // convert from rank to Et/GeV
68 double L1CaloEtScale::et(const uint16_t rank) const {
69  // return bin centre, except for highest bin
70  // if (rank < m_thresholds.size()-1) {
71  // return (m_thresholds[rank+1]+m_thresholds[rank]) / 2;
72  // }
73  // else {
74  // return m_thresholds.back();
75  // }
76 
77  // return bin lower edge
78  try {
79  return m_thresholds.at(rank);
80  } catch (std::out_of_range const&) {
81  throw cms::Exception("OutOfRange") << "Index out of range in L1CaloEtScale::et(rank)" << std::endl;
82  }
83 }
84 
85 void L1CaloEtScale::print(ostream& s) const {
86  s << "L1CaloEtScale :" << endl;
87  s << " Input scale max = " << m_linScaleMax << endl;
88  s << " Input LSB = " << m_linearLsb << " GeV" << endl;
89  s << " Rank scale max = " << m_rankScaleMax << endl;
90  for (unsigned i = 0; i < m_thresholds.size(); i++) {
91  s << " Threshold " << i << " = " << m_thresholds[i] << " GeV" << endl;
92  }
93 }
94 
95 std::ostream& operator<<(std::ostream& os, const L1CaloEtScale obj) {
96  os << "L1CaloEtScale :" << endl;
97  os << " Input scale max = " << obj.linScaleMax() << endl;
98  os << " Input LSB = " << obj.linearLsb() << " GeV" << endl;
99  os << " Rank scale max = " << obj.rankScaleMax() << endl;
100  for (unsigned i = 0; i < obj.getThresholds().size(); i++) {
101  os << " Threshold " << i << " = " << obj.getThresholds().at(i) << " GeV" << endl;
102  }
103  return os;
104 }
uint16_t m_linScaleMax
linear scale maximum
Definition: L1CaloEtScale.h:72
uint16_t m_rankScaleMax
rank scale maximum
Definition: L1CaloEtScale.h:75
double m_linearLsb
LSB of linear scale in GeV.
Definition: L1CaloEtScale.h:78
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
double et(const uint16_t rank) const
convert from rank to physically meaningful quantity
double linearLsb() const
get LSB of linear input scale
Definition: L1CaloEtScale.h:54
uint16_t rank(const uint16_t linear) const
convert from linear Et scale to rank scale
void print(std::ostream &s) const
const std::vector< double > & getThresholds() const
get thresholds
Definition: L1CaloEtScale.h:66
L1CaloEtScale()
default constructor, for testing (out = in)
std::vector< double > m_thresholds
thresholds associated with rank scale in GeV
Definition: L1CaloEtScale.h:81
unsigned linScaleMax() const
Definition: L1CaloEtScale.h:48
float linear(float x)
unsigned rankScaleMax() const
Definition: L1CaloEtScale.h:51