CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/DataFormats/SiStripDetId/interface/SiStripDetId.h

Go to the documentation of this file.
00001 #ifndef DataFormats_SiStripDetId_SiStripDetId_h
00002 #define DataFormats_SiStripDetId_SiStripDetId_h
00003 
00004 #include "DataFormats/DetId/interface/DetId.h"
00005 #include <ostream>
00006 
00007 class SiStripDetId;
00008 
00010 std::ostream& operator<< ( std::ostream&, const SiStripDetId& );
00011 
00017 class SiStripDetId : public DetId {
00018   
00019  public:
00020 
00021   // ---------- Constructors, enumerated types ----------
00022   
00024   SiStripDetId()  : DetId() {;}
00025 
00027   SiStripDetId( const uint32_t& raw_id ) : DetId( raw_id ) {;}
00028 
00030   SiStripDetId( const DetId& det_id )  : DetId( det_id.rawId() ) {;}
00031 
00033   SiStripDetId( Detector det, int subdet ) : DetId( det, subdet ) {;}
00034 
00036   enum SubDetector { UNKNOWN=0, TIB=3, TID=4, TOB=5, TEC=6 };
00037   
00039   enum ModuleGeometry {UNKNOWNGEOMETRY, IB1, IB2, OB1, OB2, W1A, W2A, W3A, W1B, W2B, W3B, W4, W5, W6, W7};
00040 
00041   // ---------- Common methods ----------
00042 
00044   inline SubDetector subDetector() const;
00045   
00047   inline ModuleGeometry moduleGeometry() const;
00048 
00050   inline uint32_t glued() const;
00051   
00053   inline uint32_t stereo() const;
00054 
00056   inline uint32_t partnerDetId() const;
00057  
00059   inline double stripLength() const;
00060   
00061   
00062   // ---------- Constructors that set "reserved" field ----------
00063   
00065   SiStripDetId( const uint32_t& raw_id, 
00066                 const uint16_t& reserved )
00067     : DetId( raw_id ) 
00068   {
00069     id_ &= ( ~static_cast<uint32_t>(reservedMask_<<reservedStartBit_) );
00070     id_ |= ( ( reserved & reservedMask_ ) << reservedStartBit_ );
00071   }
00072   
00073   // -----------------------------------------------------------------------------
00074   //
00075   
00077   SiStripDetId( const DetId& det_id, 
00078                 const uint16_t& reserved )
00079     : DetId( det_id.rawId() ) 
00080   {
00081     id_ &= ( ~static_cast<uint32_t>(reservedMask_<<reservedStartBit_) );
00082     id_ |= ( ( reserved & reservedMask_ ) << reservedStartBit_ );
00083   }
00084 
00085   
00087   inline uint16_t reserved() const;
00088   
00089 private:
00090   
00092   static const uint16_t reservedStartBit_ = 20;
00093   
00095   static const uint32_t sterStartBit_ = 0;
00096 
00098   static const uint16_t reservedMask_ = 0x7;
00099 
00101   static const uint32_t sterMask_ = 0x3;
00102 
00103   static const unsigned layerStartBit_ = 14;
00104   static const unsigned layerMask_ = 0x7;
00105   static const unsigned ringStartBitTID_= 9;
00106   static const unsigned ringMaskTID_= 0x3;
00107   static const unsigned ringStartBitTEC_= 5;
00108   static const unsigned ringMaskTEC_= 0x7;
00109   
00110 };
00111 
00112 // ---------- inline methods ----------
00113 
00114 SiStripDetId::SubDetector SiStripDetId::subDetector() const {
00115   if( det() == DetId::Tracker &&
00116       subdetId() == static_cast<int>(SiStripDetId::TIB) ) {
00117     return SiStripDetId::TIB;
00118   } else if ( det() == DetId::Tracker &&
00119               subdetId() == static_cast<int>(SiStripDetId::TID) ) {
00120     return SiStripDetId::TID;
00121   } else if ( det() == DetId::Tracker &&
00122               subdetId() == static_cast<int>(SiStripDetId::TOB) ) {
00123     return SiStripDetId::TOB;
00124   } else if ( det() == DetId::Tracker &&
00125               subdetId() == static_cast<int>(SiStripDetId::TEC) ) {
00126     return SiStripDetId::TEC;
00127   } else {
00128     return SiStripDetId::UNKNOWN;
00129   }
00130 }
00131 
00132 SiStripDetId::ModuleGeometry SiStripDetId::moduleGeometry() const {
00133   switch(subDetector()) {
00134   case TIB: return int((id_>>layerStartBit_) & layerMask_)<3? IB1 : IB2;
00135   case TOB: return int((id_>>layerStartBit_) & layerMask_)<5? OB2 : OB1;
00136   case TID: switch ((id_>>ringStartBitTID_) & ringMaskTID_) {
00137     case 1: return W1A;
00138     case 2: return W2A;
00139     case 3: return W3A;
00140     }
00141   case TEC: switch ((id_>>ringStartBitTEC_) & ringMaskTEC_) {
00142     case 1: return W1B;
00143     case 2: return W2B;
00144     case 3: return W3B;
00145     case 4: return W4;
00146     case 5: return W5;
00147     case 6: return W6;
00148     case 7: return W7;
00149     }
00150   case UNKNOWN: default: return UNKNOWNGEOMETRY;
00151   }
00152 }
00153 
00154 uint32_t SiStripDetId::glued() const {
00155   if ( ((id_>>sterStartBit_) & sterMask_ ) == 1 ) {
00156     return ( id_ - 1 );
00157   } else if ( ((id_>>sterStartBit_) & sterMask_ ) == 2 ) {
00158     return ( id_ - 2 );
00159   } else { return 0; }
00160 }
00161  
00162 uint32_t SiStripDetId::stereo() const {
00163   if ( ((id_>>sterStartBit_ ) & sterMask_ ) == 1 ) {
00164     return ( (id_>>sterStartBit_) & sterMask_ );
00165   } else { return 0; }
00166 }
00167  
00168 uint32_t SiStripDetId::partnerDetId() const {
00169   if ( ((id_>>sterStartBit_) & sterMask_ ) == 1 ) {
00170     return ( id_ + 1 );
00171   } else if ( ((id_>>sterStartBit_) & sterMask_ ) == 2 ) {
00172     return ( id_ - 1 );
00173   } else { return 0; }
00174 }
00175  
00176 double SiStripDetId::stripLength() const {
00177   return 0.;
00178 }
00179 
00180 
00181 uint16_t SiStripDetId::reserved() const { 
00182   return static_cast<uint16_t>( (id_>>reservedStartBit_) & reservedMask_ );
00183 }
00184 
00185 #endif // DataFormats_SiStripDetId_SiStripDetId_h
00186