Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:38

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