Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "Geometry/ForwardGeometry/interface/ZdcTopology.h"
0002 #include <cmath>
0003 #include <iostream>
0004 #include <algorithm>
0005 
0006 static const int ICH_EM_MAX = 5;
0007 static const int ICH_HAD_MAX = 4;
0008 static const int ICH_LUM_MAX = 2;
0009 static const int ICH_RPD_MAX = 16;
0010 
0011 ZdcTopology::ZdcTopology()
0012     : excludeEM_(false),
0013       excludeHAD_(false),
0014       excludeLUM_(false),
0015       excludeRPD_(false),
0016       excludeZP_(false),
0017       excludeZN_(false),
0018       firstEMModule_(1),
0019       lastEMModule_(5),
0020       firstHADModule_(1),
0021       lastHADModule_(4),
0022       firstLUMModule_(1),
0023       lastLUMModule_(2),
0024       firstRPDModule_(1),
0025       lastRPDModule_(16) {}
0026 
0027 bool ZdcTopology::valid(const HcalZDCDetId& id) const {
0028   // check the raw rules
0029   bool ok = validRaw(id);
0030   ok = ok && !isExcluded(id);
0031   return ok;
0032 }
0033 
0034 bool ZdcTopology::isExcluded(const HcalZDCDetId& id) const {
0035   bool exed = false;
0036 
0037   // check for section exclutions
0038   switch (id.section()) {
0039     case (HcalZDCDetId::EM):
0040       exed = excludeEM_;
0041       break;
0042     case (HcalZDCDetId::HAD):
0043       exed = excludeHAD_;
0044       break;
0045     case (HcalZDCDetId::LUM):
0046       exed = excludeLUM_;
0047       break;
0048     case (HcalZDCDetId::RPD):
0049       exed = excludeRPD_;
0050       break;
0051     default:
0052       exed = false;
0053   }
0054 
0055   // check the entire list
0056   if (!exed && !exclusionList_.empty()) {
0057     std::vector<HcalZDCDetId>::const_iterator i = std::lower_bound(exclusionList_.begin(), exclusionList_.end(), id);
0058     if (i != exclusionList_.end() && *i == id)
0059       exed = true;
0060   }
0061   return exed;
0062 }
0063 
0064 void ZdcTopology::exclude(const HcalZDCDetId& id) {
0065   std::vector<HcalZDCDetId>::iterator i = std::lower_bound(exclusionList_.begin(), exclusionList_.end(), id);
0066   if (i == exclusionList_.end() || *i != id) {
0067     exclusionList_.insert(i, id);
0068   }
0069 }
0070 
0071 void ZdcTopology::exclude(int zside) {
0072   switch (zside) {
0073     case (1):
0074       excludeZP_ = true;
0075       break;
0076     case (-1):
0077       excludeZN_ = true;
0078       break;
0079     default:
0080       break;
0081   }
0082 }
0083 
0084 void ZdcTopology::exclude(int zside, HcalZDCDetId::Section section) {
0085   switch (zside) {
0086     case (1):
0087       excludeZP_ = true;
0088       break;
0089     case (-1):
0090       excludeZN_ = true;
0091       break;
0092     default:
0093       break;
0094   }
0095   switch (section) {
0096     case (HcalZDCDetId::EM):
0097       excludeEM_ = true;
0098       break;
0099     case (HcalZDCDetId::HAD):
0100       excludeHAD_ = true;
0101       break;
0102     case (HcalZDCDetId::LUM):
0103       excludeLUM_ = true;
0104       break;
0105     case (HcalZDCDetId::RPD):
0106       excludeRPD_ = true;
0107       break;
0108     default:
0109       break;
0110   }
0111 }
0112 
0113 int ZdcTopology::exclude(int zside, HcalZDCDetId::Section section, int ich1, int ich2) {
0114   bool exed = false;
0115   switch (zside) {
0116     case (1):
0117       exed = excludeZP_;
0118       break;
0119     case (-1):
0120       exed = excludeZN_;
0121       break;
0122     default:
0123       exed = false;
0124   }
0125   if (exed)
0126     return 0;
0127 
0128   switch (section) {
0129     case (HcalZDCDetId::EM):
0130       exed = excludeEM_;
0131       break;
0132     case (HcalZDCDetId::HAD):
0133       exed = excludeHAD_;
0134       break;
0135     case (HcalZDCDetId::LUM):
0136       exed = excludeLUM_;
0137       break;
0138     case (HcalZDCDetId::RPD):
0139       exed = excludeRPD_;
0140       break;
0141     default:
0142       exed = false;
0143   }
0144   if (exed)
0145     return 0;
0146 
0147   bool isPositive = false;
0148   if (zside == 1)
0149     isPositive = true;
0150 
0151   int n = 0;
0152   for (int ich = ich1; ich < ich2; ich++) {
0153     HcalZDCDetId id(section, isPositive, ich);
0154     if (validRaw(id))
0155       exclude(id);
0156     n++;
0157   }
0158   return n;
0159 }
0160 
0161 bool ZdcTopology::validRaw(const HcalZDCDetId& id) const {
0162   bool ok = true;
0163   if (abs(id.zside()) != 1)
0164     ok = false;
0165   else if (id.channel() <= 0)
0166     ok = false;
0167   else if (!(id.section() == HcalZDCDetId::EM || id.section() == HcalZDCDetId::HAD ||
0168              id.section() == HcalZDCDetId::LUM))
0169     //      id.section()== HcalZDCDetId::LUM ||
0170     //      id.section()== HcalZDCDetId::RPD))
0171     ok = false;
0172   else if (id.section() == HcalZDCDetId::EM && id.channel() > ICH_EM_MAX)
0173     ok = false;
0174   else if (id.section() == HcalZDCDetId::HAD && id.channel() > ICH_HAD_MAX)
0175     ok = false;
0176   else if (id.section() == HcalZDCDetId::LUM && id.channel() > ICH_LUM_MAX)
0177     ok = false;
0178   else if (id.section() == HcalZDCDetId::RPD && id.channel() > ICH_RPD_MAX)
0179     ok = false;
0180   return ok;
0181 }
0182 
0183 std::vector<DetId> ZdcTopology::transverse(const DetId& id) const {
0184   std::vector<DetId> vNeighborsDetId;
0185   HcalZDCDetId zdcId = HcalZDCDetId(id);
0186   HcalZDCDetId zdcDetId;
0187   if (validRaw(zdcId) && zdcId.section() == HcalZDCDetId::EM) {
0188     bool isPositive = false;
0189     if (zdcId.zside() == 1)
0190       isPositive = true;
0191     if (zdcId.channel() == 1) {
0192       zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
0193       vNeighborsDetId.emplace_back(zdcDetId.rawId());
0194       return vNeighborsDetId;
0195     }
0196     if (zdcId.channel() == ICH_EM_MAX) {
0197       zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
0198       vNeighborsDetId.emplace_back(zdcDetId.rawId());
0199       return vNeighborsDetId;
0200     }
0201     zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
0202     vNeighborsDetId.emplace_back(zdcDetId.rawId());
0203     zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
0204     vNeighborsDetId.emplace_back(zdcDetId.rawId());
0205   }
0206   return vNeighborsDetId;
0207 }
0208 
0209 std::vector<DetId> ZdcTopology::longitudinal(const DetId& id) const {
0210   std::vector<DetId> vNeighborsDetId;
0211   HcalZDCDetId zdcId = HcalZDCDetId(id);
0212   HcalZDCDetId zdcDetId;
0213   if (validRaw(zdcId) && zdcId.section() == HcalZDCDetId::HAD) {
0214     bool isPositive = false;
0215     if (zdcId.zside() == 1)
0216       isPositive = true;
0217     if (zdcId.channel() == 1) {
0218       zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
0219       vNeighborsDetId.emplace_back(zdcDetId.rawId());
0220       return vNeighborsDetId;
0221     }
0222     if (zdcId.channel() == ICH_HAD_MAX) {
0223       zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
0224       vNeighborsDetId.emplace_back(zdcDetId.rawId());
0225       return vNeighborsDetId;
0226     }
0227     zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
0228     vNeighborsDetId.emplace_back(zdcDetId.rawId());
0229     zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
0230     vNeighborsDetId.emplace_back(zdcDetId.rawId());
0231   }
0232   if (validRaw(zdcId) && zdcId.section() == HcalZDCDetId::LUM) {
0233     bool isPositive = false;
0234     if (zdcId.zside() == 1)
0235       isPositive = true;
0236     if (zdcId.channel() == 1) {
0237       zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
0238       vNeighborsDetId.emplace_back(zdcDetId.rawId());
0239       return vNeighborsDetId;
0240     }
0241     if (zdcId.channel() == ICH_LUM_MAX) {
0242       zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
0243       vNeighborsDetId.emplace_back(zdcDetId.rawId());
0244       return vNeighborsDetId;
0245     }
0246   }
0247   if (validRaw(zdcId) && zdcId.section() == HcalZDCDetId::RPD) {
0248     bool isPositive = false;
0249     if (zdcId.zside() == 1)
0250       isPositive = true;
0251     if (zdcId.channel() == 1) {
0252       zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
0253       vNeighborsDetId.emplace_back(zdcDetId.rawId());
0254       return vNeighborsDetId;
0255     }
0256     if (zdcId.channel() == ICH_RPD_MAX) {
0257       zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
0258       vNeighborsDetId.emplace_back(zdcDetId.rawId());
0259       return vNeighborsDetId;
0260     }
0261   }
0262   return vNeighborsDetId;
0263 }
0264 
0265 std::vector<DetId> ZdcTopology::east(const DetId& /*id*/) const {
0266   std::cout << "ZdcTopology::east() not yet implemented" << std::endl;
0267   std::vector<DetId> vNeighborsDetId;
0268   return vNeighborsDetId;
0269 }
0270 
0271 std::vector<DetId> ZdcTopology::west(const DetId& /*id*/) const {
0272   std::cout << "ZdcTopology::west() not yet implemented" << std::endl;
0273   std::vector<DetId> vNeighborsDetId;
0274   return vNeighborsDetId;
0275 }
0276 
0277 std::vector<DetId> ZdcTopology::north(const DetId& /*id*/) const {
0278   std::cout << "ZdcTopology::north() not yet implemented" << std::endl;
0279   std::vector<DetId> vNeighborsDetId;
0280   return vNeighborsDetId;
0281 }
0282 std::vector<DetId> ZdcTopology::south(const DetId& /*id*/) const {
0283   std::cout << "ZdcTopology::south() not yet implemented" << std::endl;
0284   std::vector<DetId> vNeighborsDetId;
0285   return vNeighborsDetId;
0286 }
0287 std::vector<DetId> ZdcTopology::up(const DetId& /*id*/) const {
0288   std::cout << "ZdcTopology::up() not yet implemented" << std::endl;
0289   std::vector<DetId> vNeighborsDetId;
0290   return vNeighborsDetId;
0291 }
0292 std::vector<DetId> ZdcTopology::down(const DetId& /*id*/) const {
0293   std::cout << "ZdcTopology::down() not yet implemented" << std::endl;
0294   std::vector<DetId> vNeighborsDetId;
0295   return vNeighborsDetId;
0296 }
0297 
0298 int ZdcTopology::ncells(HcalZDCDetId::Section section) const {
0299   int ncells = 0;
0300   switch (section) {
0301     case (HcalZDCDetId::EM):
0302       ncells = ICH_EM_MAX;
0303       break;
0304     case (HcalZDCDetId::HAD):
0305       ncells = ICH_HAD_MAX;
0306       break;
0307     case (HcalZDCDetId::LUM):
0308       ncells = ICH_LUM_MAX;
0309       break;
0310     case (HcalZDCDetId::RPD):
0311       ncells = ICH_RPD_MAX;
0312       break;
0313     case (HcalZDCDetId::Unknown):
0314       ncells = 0;
0315       break;
0316   }
0317   return ncells;
0318 }
0319 
0320 int ZdcTopology::firstCell(HcalZDCDetId::Section section) const {
0321   int firstCell = 0;
0322   switch (section) {
0323     case (HcalZDCDetId::EM):
0324       firstCell = firstEMModule_;
0325       break;
0326     case (HcalZDCDetId::HAD):
0327       firstCell = firstHADModule_;
0328       break;
0329     case (HcalZDCDetId::LUM):
0330       firstCell = firstLUMModule_;
0331       break;
0332     case (HcalZDCDetId::RPD):
0333       firstCell = firstRPDModule_;
0334       break;
0335     case (HcalZDCDetId::Unknown):
0336       firstCell = 0;
0337       break;
0338   }
0339   return firstCell;
0340 }
0341 
0342 int ZdcTopology::lastCell(HcalZDCDetId::Section section) const {
0343   int lastCell = 0;
0344   switch (section) {
0345     case (HcalZDCDetId::EM):
0346       lastCell = lastEMModule_;
0347       break;
0348     case (HcalZDCDetId::HAD):
0349       lastCell = lastHADModule_;
0350       break;
0351     case (HcalZDCDetId::LUM):
0352       lastCell = lastLUMModule_;
0353       break;
0354     case (HcalZDCDetId::RPD):
0355       lastCell = lastRPDModule_;
0356       break;
0357     case (HcalZDCDetId::Unknown):
0358       lastCell = 0;
0359       break;
0360   }
0361   return lastCell;
0362 }