Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:49

0001 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include <sstream>
0006 
0007 TrackerTopology::TrackerTopology(const PixelBarrelValues &pxb,
0008                                  const PixelEndcapValues &pxf,
0009                                  const TECValues &tecv,
0010                                  const TIBValues &tibv,
0011                                  const TIDValues &tidv,
0012                                  const TOBValues &tobv)
0013     : pbVals_(pxb),
0014       pfVals_(pxf),
0015       tobVals_(tobv),
0016       tibVals_(tibv),
0017       tidVals_(tidv),
0018       tecVals_(tecv),
0019       bits_per_field{[PBModule] = {pbVals_.moduleStartBit_, pbVals_.moduleMask_, PixelSubdetector::PixelBarrel},
0020                      [PBLadder] = {pbVals_.ladderStartBit_, pbVals_.ladderMask_, PixelSubdetector::PixelBarrel},
0021                      [PBLayer] = {pbVals_.layerStartBit_, pbVals_.layerMask_, PixelSubdetector::PixelBarrel},
0022                      [PFModule] = {pfVals_.moduleStartBit_, pfVals_.moduleMask_, PixelSubdetector::PixelEndcap},
0023                      [PFPanel] = {pfVals_.panelStartBit_, pfVals_.panelMask_, PixelSubdetector::PixelEndcap},
0024                      [PFBlade] = {pfVals_.bladeStartBit_, pfVals_.bladeMask_, PixelSubdetector::PixelEndcap},
0025                      [PFDisk] = {pfVals_.diskStartBit_, pfVals_.diskMask_, PixelSubdetector::PixelEndcap},
0026                      [PFSide] = {pfVals_.sideStartBit_, pfVals_.sideMask_, PixelSubdetector::PixelEndcap}} {}
0027 
0028 unsigned int TrackerTopology::side(const DetId &id) const {
0029   uint32_t subdet = id.subdetId();
0030   if (subdet == PixelSubdetector::PixelBarrel)
0031     return 0;
0032   if (subdet == PixelSubdetector::PixelEndcap)
0033     return pxfSide(id);
0034   if (subdet == SiStripSubdetector::TIB)
0035     return 0;
0036   if (subdet == SiStripSubdetector::TID)
0037     return tidSide(id);
0038   if (subdet == SiStripSubdetector::TOB)
0039     return 0;
0040   if (subdet == SiStripSubdetector::TEC)
0041     return tecSide(id);
0042 
0043   throw cms::Exception("Invalid DetId") << "Unsupported DetId in TrackerTopology::side";
0044   return 0;
0045 }
0046 
0047 unsigned int TrackerTopology::layer(const DetId &id) const {
0048   uint32_t subdet = id.subdetId();
0049   if (subdet == PixelSubdetector::PixelBarrel)
0050     return pxbLayer(id);
0051   if (subdet == PixelSubdetector::PixelEndcap)
0052     return pxfDisk(id);
0053   if (subdet == SiStripSubdetector::TIB)
0054     return tibLayer(id);
0055   if (subdet == SiStripSubdetector::TID)
0056     return tidWheel(id);
0057   if (subdet == SiStripSubdetector::TOB)
0058     return tobLayer(id);
0059   if (subdet == SiStripSubdetector::TEC)
0060     return tecWheel(id);
0061 
0062   throw cms::Exception("Invalid DetId") << "Unsupported DetId in TrackerTopology::layer";
0063   return 0;
0064 }
0065 
0066 unsigned int TrackerTopology::module(const DetId &id) const {
0067   uint32_t subdet = id.subdetId();
0068   if (subdet == PixelSubdetector::PixelBarrel)
0069     return pxbModule(id);
0070   if (subdet == PixelSubdetector::PixelEndcap)
0071     return pxfModule(id);
0072   if (subdet == SiStripSubdetector::TIB)
0073     return tibModule(id);
0074   if (subdet == SiStripSubdetector::TID)
0075     return tidModule(id);
0076   if (subdet == SiStripSubdetector::TOB)
0077     return tobModule(id);
0078   if (subdet == SiStripSubdetector::TEC)
0079     return tecModule(id);
0080 
0081   throw cms::Exception("Invalid DetId") << "Unsupported DetId in TrackerTopology::module";
0082   return 0;
0083 }
0084 
0085 uint32_t TrackerTopology::glued(const DetId &id) const {
0086   uint32_t subdet = id.subdetId();
0087   if (subdet == PixelSubdetector::PixelBarrel)
0088     return 0;
0089   if (subdet == PixelSubdetector::PixelEndcap)
0090     return 0;
0091   if (subdet == SiStripSubdetector::TIB)
0092     return tibGlued(id);
0093   if (subdet == SiStripSubdetector::TID)
0094     return tidGlued(id);
0095   if (subdet == SiStripSubdetector::TOB)
0096     return tobGlued(id);
0097   if (subdet == SiStripSubdetector::TEC)
0098     return tecGlued(id);
0099 
0100   throw cms::Exception("Invalid DetId") << "Unsupported DetId in TrackerTopology::glued";
0101   return 0;
0102 }
0103 
0104 uint32_t TrackerTopology::stack(const DetId &id) const {
0105   uint32_t subdet = id.subdetId();
0106   if (subdet == PixelSubdetector::PixelBarrel)
0107     return 0;
0108   if (subdet == PixelSubdetector::PixelEndcap)
0109     return 0;
0110   if (subdet == SiStripSubdetector::TIB)
0111     return tibStack(id);
0112   if (subdet == SiStripSubdetector::TID)
0113     return tidStack(id);
0114   if (subdet == SiStripSubdetector::TOB)
0115     return tobStack(id);
0116   if (subdet == SiStripSubdetector::TEC)
0117     return tecStack(id);
0118 
0119   throw cms::Exception("Invalid DetId") << "Unsupported DetId in TrackerTopology::stack";
0120 }
0121 
0122 uint32_t TrackerTopology::lower(const DetId &id) const {
0123   uint32_t subdet = id.subdetId();
0124   if (subdet == PixelSubdetector::PixelBarrel)
0125     return 0;
0126   if (subdet == PixelSubdetector::PixelEndcap)
0127     return 0;
0128   if (subdet == SiStripSubdetector::TIB)
0129     return tibLower(id);
0130   if (subdet == SiStripSubdetector::TID)
0131     return tidLower(id);
0132   if (subdet == SiStripSubdetector::TOB)
0133     return tobLower(id);
0134   if (subdet == SiStripSubdetector::TEC)
0135     return tecLower(id);
0136 
0137   throw cms::Exception("Invalid DetId") << "Unsupported DetId in TrackerTopology::lower";
0138 }
0139 
0140 uint32_t TrackerTopology::upper(const DetId &id) const {
0141   uint32_t subdet = id.subdetId();
0142   if (subdet == PixelSubdetector::PixelBarrel)
0143     return 0;
0144   if (subdet == PixelSubdetector::PixelEndcap)
0145     return 0;
0146   if (subdet == SiStripSubdetector::TIB)
0147     return tibUpper(id);
0148   if (subdet == SiStripSubdetector::TID)
0149     return tidUpper(id);
0150   if (subdet == SiStripSubdetector::TOB)
0151     return tobUpper(id);
0152   if (subdet == SiStripSubdetector::TEC)
0153     return tecUpper(id);
0154 
0155   throw cms::Exception("Invalid DetId") << "Unsupported DetId in TrackerTopology::upper";
0156 }
0157 
0158 bool TrackerTopology::isStereo(const DetId &id) const {
0159   uint32_t subdet = id.subdetId();
0160   if (subdet == PixelSubdetector::PixelBarrel)
0161     return false;
0162   if (subdet == PixelSubdetector::PixelEndcap)
0163     return false;
0164   if (subdet == SiStripSubdetector::TIB)
0165     return tibStereo(id) != 0;
0166   if (subdet == SiStripSubdetector::TID)
0167     return tidStereo(id) != 0;
0168   if (subdet == SiStripSubdetector::TOB)
0169     return tobStereo(id) != 0;
0170   if (subdet == SiStripSubdetector::TEC)
0171     return tecStereo(id) != 0;
0172 
0173   throw cms::Exception("Invalid DetId") << "Unsupported DetId in TrackerTopology::isStereo";
0174   return false;
0175 }
0176 
0177 bool TrackerTopology::isRPhi(const DetId &id) const {
0178   uint32_t subdet = id.subdetId();
0179   if (subdet == PixelSubdetector::PixelBarrel)
0180     return false;
0181   if (subdet == PixelSubdetector::PixelEndcap)
0182     return false;
0183   if (subdet == SiStripSubdetector::TIB)
0184     return tibRPhi(id) != 0;
0185   if (subdet == SiStripSubdetector::TID)
0186     return tidRPhi(id) != 0;
0187   if (subdet == SiStripSubdetector::TOB)
0188     return tobRPhi(id) != 0;
0189   if (subdet == SiStripSubdetector::TEC)
0190     return tecRPhi(id) != 0;
0191 
0192   throw cms::Exception("Invalid DetId") << "Unsupported DetId in TrackerTopology::isRPhi";
0193   return false;
0194 }
0195 bool TrackerTopology::isLower(const DetId &id) const {
0196   uint32_t subdet = id.subdetId();
0197   if (subdet == PixelSubdetector::PixelBarrel)
0198     return false;
0199   if (subdet == PixelSubdetector::PixelEndcap)
0200     return false;
0201   if (subdet == SiStripSubdetector::TIB)
0202     return tibLower(id) != 0;
0203   if (subdet == SiStripSubdetector::TID)
0204     return tidLower(id) != 0;
0205   if (subdet == SiStripSubdetector::TOB)
0206     return tobLower(id) != 0;
0207   if (subdet == SiStripSubdetector::TEC)
0208     return tecLower(id) != 0;
0209 
0210   throw cms::Exception("Invalid DetId") << "Unsupported DetId in TrackerTopology::isLower";
0211   return false;
0212 }
0213 
0214 bool TrackerTopology::isUpper(const DetId &id) const {
0215   uint32_t subdet = id.subdetId();
0216   if (subdet == PixelSubdetector::PixelBarrel)
0217     return false;
0218   if (subdet == PixelSubdetector::PixelEndcap)
0219     return false;
0220   if (subdet == SiStripSubdetector::TIB)
0221     return tibUpper(id) != 0;
0222   if (subdet == SiStripSubdetector::TID)
0223     return tidUpper(id) != 0;
0224   if (subdet == SiStripSubdetector::TOB)
0225     return tobUpper(id) != 0;
0226   if (subdet == SiStripSubdetector::TEC)
0227     return tecUpper(id) != 0;
0228 
0229   throw cms::Exception("Invalid DetId") << "Unsupported DetId in TrackerTopology::isUpper";
0230   return false;
0231 }
0232 
0233 DetId TrackerTopology::partnerDetId(const DetId &id) const {
0234   uint32_t subdet = id.subdetId();
0235   if (subdet == PixelSubdetector::PixelBarrel)
0236     return 0;
0237   if (subdet == PixelSubdetector::PixelEndcap)
0238     return 0;
0239   if (subdet == SiStripSubdetector::TIB)
0240     return tibPartnerDetId(id);
0241   if (subdet == SiStripSubdetector::TID)
0242     return tidPartnerDetId(id);
0243   if (subdet == SiStripSubdetector::TOB)
0244     return tobPartnerDetId(id);
0245   if (subdet == SiStripSubdetector::TEC)
0246     return tecPartnerDetId(id);
0247 
0248   throw cms::Exception("Invalid DetId") << "Unsupported DetId in TrackerTopology::partnerDetId";
0249   return 0;
0250 }
0251 
0252 std::string TrackerTopology::print(DetId id) const {
0253   uint32_t subdet = id.subdetId();
0254   std::stringstream strstr;
0255 
0256   if (subdet == PixelSubdetector::PixelBarrel) {
0257     unsigned int theLayer = pxbLayer(id);
0258     unsigned int theLadder = pxbLadder(id);
0259     unsigned int theModule = pxbModule(id);
0260     strstr << "PixelBarrel"
0261            << " Layer " << theLayer << " Ladder " << theLadder << " Module " << theModule;
0262     strstr << " (" << id.rawId() << ")";
0263     return strstr.str();
0264   }
0265 
0266   if (subdet == PixelSubdetector::PixelEndcap) {
0267     unsigned int theSide = pxfSide(id);
0268     unsigned int theDisk = pxfDisk(id);
0269     unsigned int theBlade = pxfBlade(id);
0270     unsigned int thePanel = pxfPanel(id);
0271     unsigned int theModule = pxfModule(id);
0272     std::string side = (pxfSide(id) == 1) ? "-" : "+";
0273     strstr << "PixelEndcap"
0274            << " Side   " << theSide << side << " Disk   " << theDisk << " Blade  " << theBlade << " Panel  " << thePanel
0275            << " Module " << theModule;
0276     strstr << " (" << id.rawId() << ")";
0277     return strstr.str();
0278   }
0279 
0280   if (subdet == SiStripSubdetector::TIB) {
0281     unsigned int theLayer = tibLayer(id);
0282     std::vector<unsigned int> theString = tibStringInfo(id);
0283     unsigned int theModule = tibModule(id);
0284     std::string side;
0285     std::string part;
0286     side = (theString[0] == 1) ? "-" : "+";
0287     part = (theString[1] == 1) ? "int" : "ext";
0288     std::string type;
0289     type = (isStereo(id)) ? "stereo" : type;
0290     type = (isRPhi(id)) ? "r-phi" : type;
0291     type = (isStereo(id) || isRPhi(id)) ? type + " glued" : "module";
0292     std::string typeUpgrade;
0293     typeUpgrade = (isLower(id)) ? "lower" : typeUpgrade;
0294     typeUpgrade = (isUpper(id)) ? "upper" : typeUpgrade;
0295     typeUpgrade = (isUpper(id) || isLower(id)) ? typeUpgrade + " stack" : "module";
0296     strstr << "TIB" << side << " Layer " << theLayer << " " << part << " String " << theString[2];
0297     strstr << " Module for phase0 " << theModule << " " << type;
0298     strstr << " Module for phase2 " << theModule << " " << typeUpgrade;
0299     strstr << " (" << id.rawId() << ")";
0300     return strstr.str();
0301   }
0302 
0303   if (subdet == SiStripSubdetector::TID) {
0304     unsigned int theSide = tidSide(id);
0305     unsigned int theWheel = tidWheel(id);
0306     unsigned int theRing = tidRing(id);
0307     std::vector<unsigned int> theModule = tidModuleInfo(id);
0308     std::string side;
0309     std::string part;
0310     side = (tidSide(id) == 1) ? "-" : "+";
0311     part = (theModule[0] == 1) ? "back" : "front";
0312     std::string type;
0313     type = (isStereo(id)) ? "stereo" : type;
0314     type = (isRPhi(id)) ? "r-phi" : type;
0315     type = (isStereo(id) || isRPhi(id)) ? type + " glued" : "module";
0316     std::string typeUpgrade;
0317     typeUpgrade = (isLower(id)) ? "lower" : typeUpgrade;
0318     typeUpgrade = (isUpper(id)) ? "upper" : typeUpgrade;
0319     typeUpgrade = (isUpper(id) || isLower(id)) ? typeUpgrade + " stack" : "module";
0320     strstr << "TID"
0321            << " Side   " << theSide << side << " Wheel " << theWheel << " Ring " << theRing << " " << part;
0322     strstr << " Module for phase0 " << theModule[1] << " " << type;
0323     strstr << " Module for phase2 " << theModule[1] << " " << typeUpgrade;
0324     strstr << " (" << id.rawId() << ")";
0325     return strstr.str();
0326   }
0327 
0328   if (subdet == SiStripSubdetector::TOB) {
0329     unsigned int theLayer = tobLayer(id);
0330     std::vector<unsigned int> theRod = tobRodInfo(id);
0331     unsigned int theModule = tobModule(id);
0332     std::string side;
0333     std::string part;
0334     side = (((theRod[0] == 1) ? "-" : ((theRod[0] == 2) ? "+" : (theRod[0] == 3) ? "0" : "")));
0335     //    side = (theRod[0] == 2 ) ? "+" : "";
0336     //    side = (theRod[0] == 3 ) ? "0" : "";
0337     std::string type;
0338     type = (isStereo(id)) ? "stereo" : type;
0339     type = (isRPhi(id)) ? "r-phi" : type;
0340     type = (isStereo(id) || isRPhi(id)) ? type + " glued" : "module";
0341     std::string typeUpgrade;
0342     typeUpgrade = (isLower(id)) ? "lower" : typeUpgrade;
0343     typeUpgrade = (isUpper(id)) ? "upper" : typeUpgrade;
0344     typeUpgrade = (isUpper(id) || isLower(id)) ? typeUpgrade + " stack" : "module";
0345     strstr << "TOB" << side << " Layer " << theLayer << " Rod " << theRod[1];
0346     strstr << " Module for phase0 " << theModule << " " << type;
0347     strstr << " Module for phase2 " << theModule << " " << typeUpgrade;
0348     strstr << " (" << id.rawId() << ")";
0349     return strstr.str();
0350   }
0351 
0352   if (subdet == SiStripSubdetector::TEC) {
0353     unsigned int theSide = tecSide(id);
0354     unsigned int theWheel = tecWheel(id);
0355     unsigned int theModule = tecModule(id);
0356     std::vector<unsigned int> thePetal = tecPetalInfo(id);
0357     unsigned int theRing = tecRing(id);
0358     std::string side;
0359     std::string petal;
0360     side = (tecSide(id) == 1) ? "-" : "+";
0361     petal = (thePetal[0] == 1) ? "back" : "front";
0362     std::string type;
0363     type = (isStereo(id)) ? "stereo" : type;
0364     type = (isRPhi(id)) ? "r-phi" : type;
0365     type = (isStereo(id) || isRPhi(id)) ? type + " glued" : "module";
0366     std::string typeUpgrade;
0367     typeUpgrade = (isLower(id)) ? "lower" : typeUpgrade;
0368     typeUpgrade = (isUpper(id)) ? "upper" : typeUpgrade;
0369     typeUpgrade = (isUpper(id) || isLower(id)) ? typeUpgrade + " stack" : "module";
0370     strstr << "TEC"
0371            << " Side   " << theSide << side << " Wheel " << theWheel << " Petal " << thePetal[1] << " " << petal
0372            << " Ring " << theRing;
0373     strstr << " Module for phase0 " << theModule << " " << type;
0374     strstr << " Module for phase2 " << theModule << " " << typeUpgrade;
0375     strstr << " (" << id.rawId() << ")";
0376 
0377     return strstr.str();
0378   }
0379 
0380   throw cms::Exception("Invalid DetId") << "Unsupported DetId in TrackerTopology::module";
0381   return strstr.str();
0382 }
0383 
0384 SiStripModuleGeometry TrackerTopology::moduleGeometry(const DetId &id) const {
0385   switch (id.subdetId()) {
0386     case SiStripSubdetector::TIB:
0387       return tibLayer(id) < 3 ? SiStripModuleGeometry::IB1 : SiStripModuleGeometry::IB2;
0388     case SiStripSubdetector::TOB:
0389       return tobLayer(id) < 5 ? SiStripModuleGeometry::OB2 : SiStripModuleGeometry::OB1;
0390     case SiStripSubdetector::TID:
0391       switch (tidRing(id)) {
0392         case 1:
0393           return SiStripModuleGeometry::W1A;
0394         case 2:
0395           return SiStripModuleGeometry::W2A;
0396         case 3:
0397           return SiStripModuleGeometry::W3A;
0398       }
0399       return SiStripModuleGeometry::UNKNOWNGEOMETRY;
0400     case SiStripSubdetector::TEC:
0401       switch (tecRing(id)) {
0402         case 1:
0403           return SiStripModuleGeometry::W1B;
0404         case 2:
0405           return SiStripModuleGeometry::W2B;
0406         case 3:
0407           return SiStripModuleGeometry::W3B;
0408         case 4:
0409           return SiStripModuleGeometry::W4;
0410           //generic function to return DetIds and boolean factors
0411         case 5:
0412           return SiStripModuleGeometry::W5;
0413         case 6:
0414           return SiStripModuleGeometry::W6;
0415         case 7:
0416           return SiStripModuleGeometry::W7;
0417       }
0418   }
0419   return SiStripModuleGeometry::UNKNOWNGEOMETRY;
0420 }
0421 int TrackerTopology::getOTLayerNumber(const DetId &id) const {
0422   int layer = -1;
0423 
0424   if (id.det() == DetId::Tracker) {
0425     if (id.subdetId() == SiStripSubdetector::TOB) {
0426       layer = tobLayer(id);
0427     } else if (id.subdetId() == SiStripSubdetector::TID) {
0428       layer = 100 * tidSide(id) + tidWheel(id);
0429     } else {
0430       edm::LogInfo("TrackerTopology") << ">>> Invalid subdetId()  ";
0431     }
0432   }
0433   return layer;
0434 }
0435 
0436 int TrackerTopology::getITPixelLayerNumber(const DetId &id) const {
0437   int layer = -1;
0438 
0439   if (id.det() == DetId::Tracker) {
0440     if (id.subdetId() == PixelSubdetector::PixelBarrel) {
0441       layer = pxbLayer(id);
0442     } else if (id.subdetId() == PixelSubdetector::PixelEndcap) {
0443       layer = 100 * pxfSide(id) + pxfDisk(id);
0444     } else {
0445       edm::LogInfo("TrackerTopology") << ">>> Invalid subdetId()  ";
0446     }
0447   }
0448   return layer;
0449 }