Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:15

0001 #include <cassert>
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include <algorithm>
0004 
0005 #include "CondFormats/HcalObjects/interface/HBHELinearMap.h"
0006 
0007 void HBHELinearMap::getChannelTriple(const unsigned index, unsigned* depth, int* ieta, unsigned* iphi) const {
0008   if (index >= ChannelCount)
0009     throw cms::Exception(
0010         "In HBHELinearMap::getChannelTriple: "
0011         "input index out of range");
0012   const HBHEChannelId& id = lookup_[index];
0013   if (depth)
0014     *depth = id.depth();
0015   if (ieta)
0016     *ieta = id.ieta();
0017   if (iphi)
0018     *iphi = id.iphi();
0019 }
0020 
0021 unsigned HBHELinearMap::find(const unsigned depth, const int ieta, const unsigned iphi) const {
0022   const HBHEChannelId id(depth, ieta, iphi);
0023   const unsigned loc = std::lower_bound(inverse_.begin(), inverse_.end(), MapPair(id, 0U)) - inverse_.begin();
0024   if (loc < ChannelCount)
0025     if (inverse_[loc].first == id)
0026       return inverse_[loc].second;
0027   return ChannelCount;
0028 }
0029 
0030 bool HBHELinearMap::isValidTriple(const unsigned depth, const int ieta, const unsigned iphi) const {
0031   const unsigned ind = find(depth, ieta, iphi);
0032   return ind < ChannelCount;
0033 }
0034 
0035 unsigned HBHELinearMap::linearIndex(const unsigned depth, const int ieta, const unsigned iphi) const {
0036   const unsigned ind = find(depth, ieta, iphi);
0037   if (ind >= ChannelCount)
0038     throw cms::Exception(
0039         "In HBHELinearMap::linearIndex: "
0040         "invalid channel triple");
0041   return ind;
0042 }
0043 
0044 HBHELinearMap::HBHELinearMap() {
0045   unsigned l = 0;
0046   unsigned depth = 1;
0047 
0048   for (int ieta = -29; ieta <= -21; ++ieta)
0049     for (unsigned iphi = 1; iphi < 72; iphi += 2)
0050       lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
0051 
0052   for (int ieta = -20; ieta <= 20; ++ieta)
0053     if (ieta)
0054       for (unsigned iphi = 1; iphi <= 72; ++iphi)
0055         lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
0056 
0057   for (int ieta = 21; ieta <= 29; ++ieta)
0058     for (unsigned iphi = 1; iphi < 72; iphi += 2)
0059       lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
0060 
0061   depth = 2;
0062 
0063   for (int ieta = -29; ieta <= -21; ++ieta)
0064     for (unsigned iphi = 1; iphi < 72; iphi += 2)
0065       lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
0066 
0067   for (int ieta = -20; ieta <= -18; ++ieta)
0068     for (unsigned iphi = 1; iphi <= 72; ++iphi)
0069       lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
0070 
0071   for (int ieta = -16; ieta <= -15; ++ieta)
0072     for (unsigned iphi = 1; iphi <= 72; ++iphi)
0073       lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
0074 
0075   for (int ieta = 15; ieta <= 16; ++ieta)
0076     for (unsigned iphi = 1; iphi <= 72; ++iphi)
0077       lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
0078 
0079   for (int ieta = 18; ieta <= 20; ++ieta)
0080     for (unsigned iphi = 1; iphi <= 72; ++iphi)
0081       lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
0082 
0083   for (int ieta = 21; ieta <= 29; ++ieta)
0084     for (unsigned iphi = 1; iphi < 72; iphi += 2)
0085       lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
0086 
0087   depth = 3;
0088 
0089   for (int ieta = -28; ieta <= -27; ++ieta)
0090     for (unsigned iphi = 1; iphi < 72; iphi += 2)
0091       lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
0092 
0093   for (int ieta = -16; ieta <= -16; ++ieta)
0094     for (unsigned iphi = 1; iphi <= 72; ++iphi)
0095       lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
0096 
0097   for (int ieta = 16; ieta <= 16; ++ieta)
0098     for (unsigned iphi = 1; iphi <= 72; ++iphi)
0099       lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
0100 
0101   for (int ieta = 27; ieta <= 28; ++ieta)
0102     for (unsigned iphi = 1; iphi < 72; iphi += 2)
0103       lookup_[l++] = HBHEChannelId(depth, ieta, iphi);
0104 
0105   assert(l == ChannelCount);
0106 
0107   inverse_.reserve(ChannelCount);
0108   for (unsigned i = 0; i < ChannelCount; ++i)
0109     inverse_.push_back(MapPair(lookup_[i], i));
0110   std::sort(inverse_.begin(), inverse_.end());
0111 }
0112 
0113 HcalSubdetector HBHELinearMap::getSubdetector(const unsigned depth, const int ieta) {
0114   const unsigned abseta = std::abs(ieta);
0115 
0116   // Make sure the arguments are in range
0117   if (!(abseta <= 29U))
0118     throw cms::Exception(
0119         "In HBHELinearMap::getSubdetector: "
0120         "eta argument out of range");
0121   if (!(depth > 0U && depth < 4U))
0122     throw cms::Exception(
0123         "In HBHELinearMap::getSubdetector: "
0124         "depth argument out of range");
0125   if (abseta == 29U)
0126     if (!(depth <= 2U))
0127       throw cms::Exception(
0128           "In HBHELinearMap::getSubdetector: "
0129           "depth argument out of range "
0130           "for |ieta| = 29");
0131   if (abseta <= 15U)
0132     return HcalBarrel;
0133   else if (abseta == 16U)
0134     return depth <= 2U ? HcalBarrel : HcalEndcap;
0135   else
0136     return HcalEndcap;
0137 }
0138 
0139 const HBHELinearMap& hbheChannelMap() {
0140   static const HBHELinearMap chMap;
0141   return chMap;
0142 }