Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:08:10

0001 #include "Geometry/ForwardGeometry/interface/CastorTopology.h"
0002 #include <cmath>
0003 #include <iostream>
0004 #include <algorithm>
0005 
0006 static const int MODULE_EM_MAX = 2;
0007 static const int MODULE_HAD_MAX = 12;
0008 
0009 CastorTopology::CastorTopology()
0010     : excludeEM_(false),
0011       excludeHAD_(false),
0012       excludeZP_(false),
0013       excludeZN_(false),
0014       firstEMModule_(1),
0015       lastEMModule_(2),
0016       firstHADModule_(3),
0017       lastHADModule_(14) {}
0018 
0019 bool CastorTopology::valid(const HcalCastorDetId& id) const { return (validRaw(id) && !isExcluded(id)); }
0020 
0021 bool CastorTopology::isExcluded(const HcalCastorDetId& id) const {
0022   bool exed = false;
0023 
0024   // check for section exclutions
0025   switch (id.section()) {
0026     case (HcalCastorDetId::EM):
0027       exed = excludeEM_;
0028       break;
0029     case (HcalCastorDetId::HAD):
0030       exed = excludeHAD_;
0031       break;
0032     default:
0033       exed = false;
0034   }
0035 
0036   // check the entire list
0037   if (!exed && !exclusionList_.empty()) {
0038     std::vector<HcalCastorDetId>::const_iterator i = std::lower_bound(exclusionList_.begin(), exclusionList_.end(), id);
0039     if (i != exclusionList_.end() && *i == id)
0040       exed = true;
0041   }
0042   return exed;
0043 }
0044 
0045 void CastorTopology::exclude(const HcalCastorDetId& id) {
0046   std::vector<HcalCastorDetId>::iterator i = std::lower_bound(exclusionList_.begin(), exclusionList_.end(), id);
0047   if (i == exclusionList_.end() || *i != id) {
0048     exclusionList_.insert(i, id);
0049   }
0050 }
0051 
0052 void CastorTopology::exclude(int zside) {
0053   switch (zside) {
0054     case (1):
0055       excludeZP_ = true;
0056       break;
0057     case (-1):
0058       excludeZN_ = true;
0059       break;
0060     default:
0061       break;
0062   }
0063 }
0064 
0065 void CastorTopology::exclude(int zside, HcalCastorDetId::Section section) {
0066   switch (zside) {
0067     case (1):
0068       excludeZP_ = true;
0069       break;
0070     case (-1):
0071       excludeZN_ = true;
0072       break;
0073     default:
0074       break;
0075   }
0076   switch (section) {
0077     case (HcalCastorDetId::EM):
0078       excludeEM_ = true;
0079       break;
0080     case (HcalCastorDetId::HAD):
0081       excludeHAD_ = true;
0082       break;
0083     default:
0084       break;
0085   }
0086 }
0087 
0088 int CastorTopology::exclude(int zside,
0089                             HcalCastorDetId::Section section1,
0090                             int isec1,
0091                             int imod1,
0092                             HcalCastorDetId::Section section2,
0093                             int isec2,
0094                             int imod2) {
0095   bool exed = false;
0096   switch (zside) {
0097     case (1):
0098       exed = excludeZP_;
0099       break;
0100     case (-1):
0101       exed = excludeZN_;
0102       break;
0103     default:
0104       exed = false;
0105   }
0106   if (exed)
0107     return 0;
0108 
0109   /* NOTE not so sure about the exclusion */
0110   if (section1 == HcalCastorDetId::EM && section2 == HcalCastorDetId::EM) {
0111     exed = excludeEM_;
0112   } else if (section1 == HcalCastorDetId::HAD && section2 == HcalCastorDetId::HAD) {
0113     exed = excludeHAD_;
0114   } else {
0115     exed = false;
0116   };
0117 
0118   if (exed)
0119     return 0;
0120 
0121   bool isPositive = false;
0122   if (zside == 1)
0123     isPositive = true;
0124 
0125   int n = 0;
0126   for (int isec = isec1; isec < isec2; isec++) {
0127     for (int imod = imod1; imod < imod2; imod++) {
0128       HcalCastorDetId id(section1, isPositive, isec, imod);
0129       if (validRaw(id))
0130         exclude(id);
0131       n++;
0132     }
0133   }
0134   return n;
0135 }
0136 
0137 bool CastorTopology::validRaw(const HcalCastorDetId& id) const {
0138   return HcalCastorDetId::validDetId(id.section(), id.zside() > 0, id.sector(), id.module());
0139 }
0140 
0141 std::vector<DetId> CastorTopology::incSector(const DetId& id) const {
0142   std::vector<DetId> vNeighborsDetId;
0143   HcalCastorDetId castorId = HcalCastorDetId(id);
0144   HcalCastorDetId castorDetId;
0145   if (validRaw(castorId)) {
0146     bool isPositive = false;
0147     if (castorId.zside() == 1)
0148       isPositive = true;
0149     if (castorId.sector() == 1) {
0150       castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector() + 1, castorId.module());
0151       vNeighborsDetId.emplace_back(castorDetId.rawId());
0152       return vNeighborsDetId;
0153     }
0154     if (castorId.sector() == 16) {
0155       castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector() - 1, castorId.module());
0156       vNeighborsDetId.emplace_back(castorDetId.rawId());
0157       return vNeighborsDetId;
0158     }
0159     castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector() - 1, castorId.module());
0160     vNeighborsDetId.emplace_back(castorDetId.rawId());
0161     castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector() + 1, castorId.module());
0162     vNeighborsDetId.emplace_back(castorDetId.rawId());
0163   }
0164   return vNeighborsDetId;
0165 }
0166 
0167 std::vector<DetId> CastorTopology::incModule(const DetId& id) const {
0168   std::vector<DetId> vNeighborsDetId;
0169   HcalCastorDetId castorId = HcalCastorDetId(id);
0170   HcalCastorDetId castorDetId;
0171   if (validRaw(castorId) && castorId.section() == HcalCastorDetId::EM) {
0172     bool isPositive = false;
0173     if (castorId.zside() == 1)
0174       isPositive = true;
0175     if (castorId.module() == 1) {
0176       castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module() + 1);
0177       vNeighborsDetId.emplace_back(castorDetId.rawId());
0178       return vNeighborsDetId;
0179     }
0180     if (castorId.module() == MODULE_EM_MAX) {
0181       castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module() - 1);
0182       vNeighborsDetId.emplace_back(castorDetId.rawId());
0183       return vNeighborsDetId;
0184     }
0185     castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module() - 1);
0186     vNeighborsDetId.emplace_back(castorDetId.rawId());
0187     castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module() + 1);
0188     vNeighborsDetId.emplace_back(castorDetId.rawId());
0189   }
0190   if (validRaw(castorId) && castorId.section() == HcalCastorDetId::HAD) {
0191     bool isPositive = false;
0192     if (castorId.zside() == 1)
0193       isPositive = true;
0194     if (castorId.module() == 1) {
0195       castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module() + 1);
0196       vNeighborsDetId.emplace_back(castorDetId.rawId());
0197       return vNeighborsDetId;
0198     }
0199     if (castorId.module() == MODULE_HAD_MAX) {
0200       castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module() - 1);
0201       vNeighborsDetId.emplace_back(castorDetId.rawId());
0202       return vNeighborsDetId;
0203     }
0204   }
0205   return vNeighborsDetId;
0206 }
0207 
0208 std::vector<DetId> CastorTopology::east(const DetId& /*id*/) const {
0209   std::cout << "CastorTopology::east() not yet implemented" << std::endl;
0210   std::vector<DetId> vNeighborsDetId;
0211   return vNeighborsDetId;
0212 }
0213 
0214 std::vector<DetId> CastorTopology::west(const DetId& /*id*/) const {
0215   std::cout << "CastorTopology::west() not yet implemented" << std::endl;
0216   std::vector<DetId> vNeighborsDetId;
0217   return vNeighborsDetId;
0218 }
0219 
0220 std::vector<DetId> CastorTopology::north(const DetId& /*id*/) const {
0221   std::cout << "CastorTopology::north() not yet implemented" << std::endl;
0222   std::vector<DetId> vNeighborsDetId;
0223   return vNeighborsDetId;
0224 }
0225 std::vector<DetId> CastorTopology::south(const DetId& /*id*/) const {
0226   std::cout << "CastorTopology::south() not yet implemented" << std::endl;
0227   std::vector<DetId> vNeighborsDetId;
0228   return vNeighborsDetId;
0229 }
0230 std::vector<DetId> CastorTopology::up(const DetId& /*id*/) const {
0231   std::cout << "CastorTopology::up() not yet implemented" << std::endl;
0232   std::vector<DetId> vNeighborsDetId;
0233   return vNeighborsDetId;
0234 }
0235 std::vector<DetId> CastorTopology::down(const DetId& /*id*/) const {
0236   std::cout << "CastorTopology::down() not yet implemented" << std::endl;
0237   std::vector<DetId> vNeighborsDetId;
0238   return vNeighborsDetId;
0239 }
0240 
0241 int CastorTopology::ncells(HcalCastorDetId::Section section) const {
0242   int ncells = 0;
0243   switch (section) {
0244     case (HcalCastorDetId::EM):
0245       ncells = MODULE_EM_MAX * 16;
0246       break;
0247     case (HcalCastorDetId::HAD):
0248       ncells = MODULE_HAD_MAX * 16;
0249       break;
0250     case (HcalCastorDetId::Unknown):
0251       ncells = 0;
0252       break;
0253   }
0254   return ncells;
0255 }
0256 
0257 int CastorTopology::firstCell(HcalCastorDetId::Section section) const {
0258   int firstCell = 0;
0259   switch (section) {
0260     case (HcalCastorDetId::EM):
0261       firstCell = firstEMModule_;
0262       break;
0263     case (HcalCastorDetId::HAD):
0264       firstCell = firstHADModule_;
0265       break;
0266     case (HcalCastorDetId::Unknown):
0267       firstCell = 0;
0268       break;
0269   }
0270   return firstCell;
0271 }
0272 
0273 int CastorTopology::lastCell(HcalCastorDetId::Section section) const {
0274   int lastCell = 0;
0275   switch (section) {
0276     case (HcalCastorDetId::EM):
0277       lastCell = lastEMModule_;
0278       break;
0279     case (HcalCastorDetId::HAD):
0280       lastCell = lastHADModule_;
0281       break;
0282     case (HcalCastorDetId::Unknown):
0283       lastCell = 0;
0284       break;
0285   }
0286   return lastCell;
0287 }