test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HBHELinearMap.cc
Go to the documentation of this file.
1 #include <cassert>
3 #include <algorithm>
4 
6 
7 void HBHELinearMap::getChannelTriple(const unsigned index, unsigned* depth,
8  int* ieta, unsigned* iphi) const
9 {
10  if (index >= ChannelCount)
11  throw cms::Exception("In HBHELinearMap::getChannelTriple: "
12  "input index out of range");
13  const HBHEChannelId& id = lookup_[index];
14  if (depth)
15  *depth = id.depth();
16  if (ieta)
17  *ieta = id.ieta();
18  if (iphi)
19  *iphi = id.iphi();
20 }
21 
22 unsigned HBHELinearMap::find(const unsigned depth, const int ieta,
23  const unsigned iphi) const
24 {
25  const HBHEChannelId id(depth, ieta, iphi);
26  const unsigned loc = std::lower_bound(
27  inverse_.begin(), inverse_.end(), MapPair(id, 0U)) - inverse_.begin();
28  if (loc < ChannelCount)
29  if (inverse_[loc].first == id)
30  return inverse_[loc].second;
31  return ChannelCount;
32 }
33 
34 bool HBHELinearMap::isValidTriple(const unsigned depth, const int ieta,
35  const unsigned iphi) const
36 {
37  const unsigned ind = find(depth, ieta, iphi);
38  return ind < ChannelCount;
39 }
40 
41 unsigned HBHELinearMap::linearIndex(const unsigned depth, const int ieta,
42  const unsigned iphi) const
43 {
44  const unsigned ind = find(depth, ieta, iphi);
45  if (ind >= ChannelCount)
46  throw cms::Exception("In HBHELinearMap::linearIndex: "
47  "invalid channel triple");
48  return ind;
49 }
50 
52 {
53  unsigned l = 0;
54  unsigned depth = 1;
55 
56  for (int ieta = -29; ieta <= -21; ++ieta)
57  for (unsigned iphi=1; iphi<72; iphi+=2)
58  lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
59 
60  for (int ieta = -20; ieta <= 20; ++ieta)
61  if (ieta)
62  for (unsigned iphi=1; iphi<=72; ++iphi)
63  lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
64 
65  for (int ieta = 21; ieta <= 29; ++ieta)
66  for (unsigned iphi=1; iphi<72; iphi+=2)
67  lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
68 
69  depth = 2;
70 
71  for (int ieta = -29; ieta <= -21; ++ieta)
72  for (unsigned iphi=1; iphi<72; iphi+=2)
73  lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
74 
75  for (int ieta = -20; ieta <= -18; ++ieta)
76  for (unsigned iphi=1; iphi<=72; ++iphi)
77  lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
78 
79  for (int ieta = -16; ieta <= -15; ++ieta)
80  for (unsigned iphi=1; iphi<=72; ++iphi)
81  lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
82 
83  for (int ieta = 15; ieta <= 16; ++ieta)
84  for (unsigned iphi=1; iphi<=72; ++iphi)
85  lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
86 
87  for (int ieta = 18; ieta <= 20; ++ieta)
88  for (unsigned iphi=1; iphi<=72; ++iphi)
89  lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
90 
91  for (int ieta = 21; ieta <= 29; ++ieta)
92  for (unsigned iphi=1; iphi<72; iphi+=2)
93  lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
94 
95  depth = 3;
96 
97  for (int ieta = -28; ieta <= -27; ++ieta)
98  for (unsigned iphi=1; iphi<72; iphi+=2)
99  lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
100 
101  for (int ieta = -16; ieta <= -16; ++ieta)
102  for (unsigned iphi=1; iphi<=72; ++iphi)
103  lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
104 
105  for (int ieta = 16; ieta <= 16; ++ieta)
106  for (unsigned iphi=1; iphi<=72; ++iphi)
107  lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
108 
109  for (int ieta = 27; ieta <= 28; ++ieta)
110  for (unsigned iphi=1; iphi<72; iphi+=2)
111  lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
112 
113  assert(l == ChannelCount);
114 
115  inverse_.reserve(ChannelCount);
116  for (unsigned i=0; i<ChannelCount; ++i)
117  inverse_.push_back(MapPair(lookup_[i], i));
118  std::sort(inverse_.begin(), inverse_.end());
119 }
120 
122  const int ieta)
123 {
124  const unsigned abseta = std::abs(ieta);
125 
126  // Make sure the arguments are in range
127  if (!(abseta <= 29U))
128  throw cms::Exception("In HBHELinearMap::getSubdetector: "
129  "eta argument out of range");
130  if (!(depth > 0U && depth < 4U))
131  throw cms::Exception("In HBHELinearMap::getSubdetector: "
132  "depth argument out of range");
133  if (abseta == 29U)
134  if (!(depth <= 2U))
135  throw cms::Exception("In HBHELinearMap::getSubdetector: "
136  "depth argument out of range "
137  "for |ieta| = 29");
138  if (abseta <= 15U)
139  return HcalBarrel;
140  else if (abseta == 16U)
141  return depth <= 2U ? HcalBarrel : HcalEndcap;
142  else
143  return HcalEndcap;
144 }
145 
147 {
148  static const HBHELinearMap chMap;
149  return chMap;
150 }
Definition: DDLMap.h:28
int i
Definition: DBlmapReader.cc:9
HBHEChannelId lookup_[ChannelCount]
Definition: HBHELinearMap.h:84
assert(m_qm.get())
static HcalSubdetector getSubdetector(unsigned depth, int ieta)
ChannelMap inverse_
Definition: HBHELinearMap.h:85
void getChannelTriple(unsigned index, unsigned *depth, int *ieta, unsigned *iphi) const
Definition: HBHELinearMap.cc:7
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned find(unsigned depth, int ieta, unsigned iphi) const
bool isValidTriple(unsigned depth, int ieta, unsigned iphi) const
std::pair< HBHEChannelId, unsigned > MapPair
Definition: HBHELinearMap.h:79
const HBHELinearMap & hbheChannelMap()
unsigned linearIndex(unsigned depth, int ieta, unsigned iphi) const