CMS 3D CMS Logo

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