CMS 3D CMS Logo

L1GctHtMissLut.cc
Go to the documentation of this file.
2 
4 
5 #include <cmath>
6 
7 //DEFINE STATICS
10 
12  : L1GctLut<NAddress, NData>(), m_etScale(scale), m_componentLsb(lsb) {
13  if (scale != nullptr)
14  m_setupOk = true;
15 }
16 
17 L1GctHtMissLut::L1GctHtMissLut() : L1GctLut<NAddress, NData>(), m_etScale(nullptr), m_componentLsb(1.0) {}
18 
20  : L1GctLut<NAddress, NData>(), m_etScale(lut.etScale()), m_componentLsb(lut.componentLsb()) {
21  if (m_etScale != nullptr)
22  m_setupOk = true;
23 }
24 
26 
27 uint16_t L1GctHtMissLut::value(const uint16_t lutAddress) const {
28  uint16_t result = 0;
29 
30  if (lutAddress != 0) {
31  static const int maxComponent = 1 << kHxOrHyMissComponentNBits;
32  static const int componentMask = maxComponent - 1;
33 
34  static const int magnitudeMask = (1 << kHtMissMagnitudeNBits) - 1;
35  static const int angleMask = (1 << kHtMissAngleNBits) - 1;
36 
37  // Extract the bits corresponding to hx and hy components
38  int hxCompGct = static_cast<int>(lutAddress >> kHxOrHyMissComponentNBits) & componentMask;
39  int hyCompGct = static_cast<int>(lutAddress) & componentMask;
40 
41  // These are twos-complement integers - if the MSB is set, the value is negative
42  if (hxCompGct >= maxComponent / 2)
43  hxCompGct -= maxComponent;
44  if (hyCompGct >= maxComponent / 2)
45  hyCompGct -= maxComponent;
46 
47  // Convert to GeV. Add 0.5 to each component to compensate for truncation errors.
48  double hxCompGeV = m_componentLsb * (static_cast<double>(hxCompGct) + 0.5);
49  double hyCompGeV = m_componentLsb * (static_cast<double>(hyCompGct) + 0.5);
50 
51  // Convert to magnitude and angle
52  double htMissMag = sqrt(hxCompGeV * hxCompGeV + hyCompGeV * hyCompGeV);
53  double htMissAng = atan2(hyCompGeV, hxCompGeV);
54  if (htMissAng < 0.0)
55  htMissAng += 2.0 * M_PI;
56 
57  // Convert back to integer
58  int htMissMagBits = static_cast<int>(m_etScale->rank(htMissMag)) & magnitudeMask;
59  int htMissAngBits = static_cast<int>(htMissAng * 9.0 / M_PI) & angleMask;
60 
61  // Form the lut output
62  result = (htMissMagBits << kHtMissAngleNBits) | htMissAngBits;
63  }
64 
65  return result;
66 }
67 
68 std::vector<double> L1GctHtMissLut::getThresholdsGeV() const { return m_etScale->getThresholds(); }
69 
70 std::vector<unsigned> L1GctHtMissLut::getThresholdsGct() const {
71  std::vector<unsigned> result;
72  std::vector<double> thresholdsGeV = m_etScale->getThresholds();
73  for (std::vector<double>::const_iterator thr = thresholdsGeV.begin(); thr != thresholdsGeV.end(); thr++) {
74  result.push_back(static_cast<unsigned>((*thr) / (m_componentLsb)));
75  }
76  return result;
77 }
78 
80  const L1GctHtMissLut& temp(lut);
81  return temp;
82 }
83 
84 std::ostream& operator<<(std::ostream& os, const L1GctHtMissLut& lut) {
85  os << "===L1GctHtMissLut===" << std::endl;
86  std::vector<double> thresholds = lut.m_etScale->getThresholds();
87  std::vector<double>::const_iterator thr = thresholds.begin();
88  os << "Thresholds are: " << *(thr++);
89  for (; thr != thresholds.end(); thr++) {
90  os << ", " << *thr;
91  }
92  os << std::endl;
93  os << "Max values for input to et scale " << lut.m_etScale->linScaleMax() << " and for output "
94  << lut.m_etScale->rankScaleMax() << std::endl;
95  os << "LSB used for conversion is " << lut.m_componentLsb << " GeV" << std::endl;
96  os << "\n===Lookup table contents===\n" << std::endl;
98  os << *temp;
99  return os;
100 }
101 
uint16_t value(const uint16_t lutAddress) const override
const std::vector< double > & getThresholds() const
get thresholds
Definition: L1CaloEtScale.h:66
~L1GctHtMissLut() override
Destructor.
std::ostream & operator<<(std::ostream &os, const L1GctHtMissLut &lut)
std::vector< double > getThresholdsGeV() const
Get thresholds.
LUT for conversion of Ht components x and y to magnitude and angle.
Base class for LookUp Tables.
Definition: L1GctLut.h:19
unsigned linScaleMax() const
Definition: L1CaloEtScale.h:48
L1GctHtMissLut operator=(const L1GctHtMissLut &lut)
Overload = operator.
std::vector< unsigned > getThresholdsGct() const
T sqrt(T t)
Definition: SSEVec.h:19
double m_componentLsb
#define M_PI
const L1CaloEtScale * m_etScale
static const int NAddress
static const int NData
uint16_t rank(const uint16_t linear) const
convert from linear Et scale to rank scale
unsigned rankScaleMax() const
Definition: L1CaloEtScale.h:51
L1GctHtMissLut()
Default constructor.