Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DataFormats_SiStripDetId_SiStripDetId_h
0002 #define DataFormats_SiStripDetId_SiStripDetId_h
0003 
0004 #include "DataFormats/DetId/interface/DetId.h"
0005 #include "DataFormats/SiStripDetId/interface/SiStripEnums.h"
0006 #include <ostream>
0007 
0008 class SiStripDetId;
0009 
0010 /** Debug info for SiStripDetId class. */
0011 std::ostream &operator<<(std::ostream &, const SiStripDetId &);
0012 
0013 /**
0014     @class SiStripDetId
0015     @author R.Bainbridge
0016     @brief Detector identifier class for the strip tracker.
0017 */
0018 class SiStripDetId : public DetId {
0019 public:
0020   // ---------- Constructors, enumerated types ----------
0021 
0022   /** Construct a null id */
0023   SiStripDetId() : DetId() { ; }
0024 
0025   /** Construct from a raw value */
0026   SiStripDetId(const uint32_t &raw_id) : DetId(raw_id) { ; }
0027 
0028   /** Construct from generic DetId */
0029   SiStripDetId(const DetId &det_id) : DetId(det_id.rawId()) { ; }
0030 
0031   /** Construct and fill only the det and sub-det fields. */
0032   SiStripDetId(Detector det, int subdet) : DetId(det, subdet) { ; }
0033 
0034   /** Enumerated type for tracker sub-deteector systems. */
0035   using SubDetector = SiStripSubdetector::Subdetector;
0036   static constexpr auto UNKNOWN = SiStripSubdetector::UNKNOWN;
0037   static constexpr auto TIB = SiStripSubdetector::TIB;
0038   static constexpr auto TID = SiStripSubdetector::TID;
0039   static constexpr auto TOB = SiStripSubdetector::TOB;
0040   static constexpr auto TEC = SiStripSubdetector::TEC;
0041 
0042   // ---------- Common methods ----------
0043 
0044   /** Returns enumerated type specifying sub-detector. */
0045   inline SubDetector subDetector() const;
0046 
0047   /** Returns enumerated type specifying sub-detector. */
0048   inline SiStripModuleGeometry moduleGeometry() const;
0049 
0050   /** A non-zero value means a glued module, null means not glued. */
0051   inline uint32_t glued() const;
0052 
0053   /** A non-zero value means a stereo module, null means not stereo. */
0054   inline uint32_t stereo() const;
0055 
0056   /** Returns DetId of the partner module if glued, otherwise null. */
0057   inline uint32_t partnerDetId() const;
0058 
0059   /** Returns strip length of strip tracker sensor, otherwise null. */
0060   inline double stripLength() const;
0061 
0062   // ---------- Constructors that set "reserved" field ----------
0063 
0064   /** Construct from a raw value and set "reserved" field. */
0065   SiStripDetId(const uint32_t &raw_id, const uint16_t &reserved) : DetId(raw_id) {
0066     id_ &= (~static_cast<uint32_t>(reservedMask_ << reservedStartBit_));
0067     id_ |= ((reserved & reservedMask_) << reservedStartBit_);
0068   }
0069 
0070   // -----------------------------------------------------------------------------
0071   //
0072 
0073   /** Construct from generic DetId and set "reserved" field. */
0074   SiStripDetId(const DetId &det_id, const uint16_t &reserved) : DetId(det_id.rawId()) {
0075     id_ &= (~static_cast<uint32_t>(reservedMask_ << reservedStartBit_));
0076     id_ |= ((reserved & reservedMask_) << reservedStartBit_);
0077   }
0078 
0079   /** Returns value of "reserved" field. */
0080   inline uint16_t reserved() const;
0081 
0082 private:
0083   /** Position of "reserved" bit field. */
0084   static const uint16_t reservedStartBit_ = 20;
0085 
0086   /** */
0087   static const uint32_t sterStartBit_ = 0;
0088 
0089   /** Mask for "reserved" bit field (3-bits wide). */
0090   static const uint16_t reservedMask_ = 0x7;
0091 
0092   /** */
0093   static const uint32_t sterMask_ = 0x3;
0094 
0095   static const unsigned layerStartBit_ = 14;
0096   static const unsigned layerMask_ = 0x7;
0097   static const unsigned ringStartBitTID_ = 9;
0098   static const unsigned ringMaskTID_ = 0x3;
0099   static const unsigned ringStartBitTEC_ = 5;
0100   static const unsigned ringMaskTEC_ = 0x7;
0101 };
0102 
0103 // ---------- inline methods ----------
0104 
0105 SiStripDetId::SubDetector SiStripDetId::subDetector() const {
0106   return static_cast<SiStripDetId::SubDetector>(subdetId());
0107 }
0108 
0109 SiStripModuleGeometry SiStripDetId::moduleGeometry() const {
0110   auto geometry = SiStripModuleGeometry::UNKNOWNGEOMETRY;
0111   switch (subDetector()) {
0112     case TIB:
0113       geometry =
0114           int((id_ >> layerStartBit_) & layerMask_) < 3 ? SiStripModuleGeometry::IB1 : SiStripModuleGeometry::IB2;
0115       break;
0116     case TOB:
0117       geometry =
0118           int((id_ >> layerStartBit_) & layerMask_) < 5 ? SiStripModuleGeometry::OB2 : SiStripModuleGeometry::OB1;
0119       break;
0120     case TID:
0121       switch ((id_ >> ringStartBitTID_) & ringMaskTID_) {
0122         case 1:
0123           geometry = SiStripModuleGeometry::W1A;
0124           break;
0125         case 2:
0126           geometry = SiStripModuleGeometry::W2A;
0127           break;
0128         case 3:
0129           geometry = SiStripModuleGeometry::W3A;
0130           break;
0131       }
0132       break;
0133     case TEC:
0134       switch ((id_ >> ringStartBitTEC_) & ringMaskTEC_) {
0135         case 1:
0136           geometry = SiStripModuleGeometry::W1B;
0137           break;
0138         case 2:
0139           geometry = SiStripModuleGeometry::W2B;
0140           break;
0141         case 3:
0142           geometry = SiStripModuleGeometry::W3B;
0143           break;
0144         case 4:
0145           geometry = SiStripModuleGeometry::W4;
0146           break;
0147         case 5:
0148           geometry = SiStripModuleGeometry::W5;
0149           break;
0150         case 6:
0151           geometry = SiStripModuleGeometry::W6;
0152           break;
0153         case 7:
0154           geometry = SiStripModuleGeometry::W7;
0155           break;
0156       }
0157     case UNKNOWN:
0158     default:;
0159   }
0160   return geometry;
0161 }
0162 
0163 uint32_t SiStripDetId::glued() const {
0164   uint32_t testId = (id_ >> sterStartBit_) & sterMask_;
0165   return (testId == 0) ? 0 : (id_ - testId);
0166 }
0167 
0168 uint32_t SiStripDetId::stereo() const { return (((id_ >> sterStartBit_) & sterMask_) == 1) ? 1 : 0; }
0169 
0170 uint32_t SiStripDetId::partnerDetId() const {
0171   uint32_t testId = (id_ >> sterStartBit_) & sterMask_;
0172   if (testId == 1) {
0173     testId = id_ + 1;
0174   } else if (testId == 2) {
0175     testId = id_ - 1;
0176   } else {
0177     testId = 0;
0178   }
0179   return testId;
0180 }
0181 
0182 double SiStripDetId::stripLength() const { return 0.; }
0183 
0184 uint16_t SiStripDetId::reserved() const { return static_cast<uint16_t>((id_ >> reservedStartBit_) & reservedMask_); }
0185 
0186 #endif  // DataFormats_SiStripDetId_SiStripDetId_h