CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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::vector;
19 using std::ostream;
20 using std::endl;
21 
22 // default constructor (testing only!)
24  m_linScaleMax(0x3ff),
25  m_rankScaleMax(0x3f),
26  m_linearLsb(1.0)
27 {
28  for (unsigned i=0; i<m_rankScaleMax; i++) {
29  m_thresholds.push_back(m_linearLsb * i);
30  }
31 }
32 
33 // ctor that provides backwards compatibility with fixed max scale values
34 // OK to use this with e/gamma and rank scales
35 L1CaloEtScale::L1CaloEtScale(const double linearLsbInGeV, const vector<double>& thresholdsInGeV) :
36  m_linScaleMax(0x3ff),
37  m_rankScaleMax(0x3f),
38  m_linearLsb(linearLsbInGeV),
39  m_thresholds(thresholdsInGeV) {
40 
41  // protect against too many thresholds!
42  // while ( m_threshold.size() > (L1GctJetScale::maxRank+1) ) {
43  // m_thresholds.pop_back();
44  // }
45 
46 }
47 
48 
49 // ctor that sets scale max values
50 L1CaloEtScale::L1CaloEtScale(const unsigned linScaleMax, const unsigned rankScaleMax, const double linearLsbInGeV, const vector<double>& thresholdsInGeV) :
51  m_linScaleMax(linScaleMax),
52  m_rankScaleMax(rankScaleMax),
53  m_linearLsb(linearLsbInGeV),
54  m_thresholds(thresholdsInGeV) {
55 
56 }
57 
58 
60 
61 }
62 
63 // convert from linear Et to rank
64 uint16_t L1CaloEtScale::rank(const uint16_t linear) const {
65 
66  return rank( (linear & m_linScaleMax) * m_linearLsb);
67 
68 }
69 
71 uint16_t L1CaloEtScale::rank(const double EtInGeV) const {
72 
73  uint16_t out = 0;
74 
75  for (unsigned i=0; i<m_thresholds.size() && i<(unsigned)(m_rankScaleMax+1); i++) {
76  if ( EtInGeV >= m_thresholds.at(i) ) { out = i; }
77  }
78 
79  return out & m_rankScaleMax;
80 }
81 
82 // convert from rank to Et/GeV
83 double L1CaloEtScale::et(const uint16_t rank) const {
84 
85  // return bin centre, except for highest bin
86 // if (rank < m_thresholds.size()-1) {
87 // return (m_thresholds[rank+1]+m_thresholds[rank]) / 2;
88 // }
89 // else {
90 // return m_thresholds.back();
91 // }
92 
93 // return bin lower edge
94  try {
95  return m_thresholds.at(rank);
96  }
97  catch(std::out_of_range) {
98  throw cms::Exception("OutOfRange") << "Index out of range in L1CaloEtScale::et(rank)" << std::endl;
99  }
100 
101 }
102 
103 void L1CaloEtScale::print(ostream& s) const {
104  s << "L1CaloEtScale :" << endl;
105  s << " Input scale max = " << m_linScaleMax << endl;
106  s << " Input LSB = " << m_linearLsb << " GeV" << endl;
107  s << " Rank scale max = " << m_rankScaleMax << endl;
108  for (unsigned i=0; i<m_thresholds.size(); i++) {
109  s << " Threshold " << i << " = " << m_thresholds[i] << " GeV" << endl;
110  }
111 }
112 
113 std::ostream& operator << (std::ostream& os, const L1CaloEtScale obj) {
114  os << "L1CaloEtScale :" << endl;
115  os << " Input scale max = " << obj.linScaleMax() << endl;
116  os << " Input LSB = " << obj.linearLsb() << " GeV" << endl;
117  os << " Rank scale max = " << obj.rankScaleMax() << endl;
118  for (unsigned i=0; i<obj.getThresholds().size(); i++) {
119  os << " Threshold " << i << " = " << obj.getThresholds().at(i) << " GeV" << endl;
120  }
121  return os ;
122 }
123 
124 
125 
int i
Definition: DBlmapReader.cc:9
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:79
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:188
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:53
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:65
L1CaloEtScale()
default constructor, for testing (out = in)
std::vector< double > m_thresholds
thresholds associated with rank scale in GeV
Definition: L1CaloEtScale.h:82
unsigned linScaleMax() const
Definition: L1CaloEtScale.h:47
float linear(float x)
unsigned rankScaleMax() const
Definition: L1CaloEtScale.h:50