CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/DataFormats/TrackerCommon/interface/TrackerTopology.h

Go to the documentation of this file.
00001 #ifndef TRACKERTOPOLOGY_H
00002 #define TRACKERTOPOLOGY_H
00003 
00004 #include "DataFormats/DetId/interface/DetId.h"
00005 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00006 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00007 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00008 
00009 #include <vector>
00010 #include <string>
00011 
00012 //knower of all things tracker geometry
00013 //flexible replacement for PXBDetId and friends
00014 //to implement
00015 // endcap pixel
00016 
00017 
00018 class TrackerTopology {
00019 
00020  public:
00021 
00022   struct PixelBarrelValues {
00023     unsigned int layerStartBit_;
00024     unsigned int ladderStartBit_;
00025     unsigned int moduleStartBit_;
00026     unsigned int layerMask_;
00027     unsigned int ladderMask_;
00028     unsigned int moduleMask_;
00029   };
00030 
00031   struct PixelEndcapValues {
00032     unsigned int sideStartBit_;
00033     unsigned int diskStartBit_;
00034     unsigned int bladeStartBit_;
00035     unsigned int panelStartBit_;
00036     unsigned int moduleStartBit_;
00037     unsigned int sideMask_;
00038     unsigned int diskMask_;
00039     unsigned int bladeMask_;
00040     unsigned int panelMask_;
00041     unsigned int moduleMask_;
00042   };
00043 
00044   struct TECValues {
00045     unsigned int sideStartBit_;
00046     unsigned int wheelStartBit_;
00047     unsigned int petal_fw_bwStartBit_;
00048     unsigned int petalStartBit_;
00049     unsigned int ringStartBit_;
00050     unsigned int moduleStartBit_;
00051     unsigned int sterStartBit_;
00052     unsigned int sideMask_;
00053     unsigned int wheelMask_;
00054     unsigned int petal_fw_bwMask_;
00055     unsigned int petalMask_;
00056     unsigned int ringMask_;
00057     unsigned int moduleMask_;
00058     unsigned int sterMask_;
00059   };
00060 
00061   struct TIBValues {
00062     unsigned int layerStartBit_;
00063     unsigned int str_fw_bwStartBit_;
00064     unsigned int str_int_extStartBit_;
00065     unsigned int strStartBit_;
00066     unsigned int moduleStartBit_;
00067     unsigned int sterStartBit_;
00068 
00069     unsigned int layerMask_;
00070     unsigned int str_fw_bwMask_;
00071     unsigned int str_int_extMask_;
00072     unsigned int strMask_;
00073     unsigned int moduleMask_;
00074     unsigned int sterMask_;
00075   };
00076 
00077   struct TIDValues {
00078     unsigned int sideStartBit_;
00079     unsigned int wheelStartBit_;
00080     unsigned int ringStartBit_;
00081     unsigned int module_fw_bwStartBit_;
00082     unsigned int moduleStartBit_;
00083     unsigned int sterStartBit_;
00084     unsigned int sideMask_;
00085     unsigned int wheelMask_;
00086     unsigned int ringMask_;
00087     unsigned int module_fw_bwMask_;
00088     unsigned int moduleMask_;
00089     unsigned int sterMask_;
00090   };
00091 
00092   struct TOBValues {
00093     unsigned int layerStartBit_;
00094     unsigned int rod_fw_bwStartBit_;
00095     unsigned int rodStartBit_;
00096     unsigned int moduleStartBit_;
00097     unsigned int sterStartBit_;
00098     unsigned int layerMask_;
00099     unsigned int rod_fw_bwMask_;
00100     unsigned int rodMask_;
00101     unsigned int moduleMask_;
00102     unsigned int sterMask_;
00103   };
00104 
00105 
00106   
00107   TrackerTopology( const PixelBarrelValues pxb, const PixelEndcapValues pxf,
00108                    const TECValues tecv, const TIBValues tibv, 
00109                    const TIDValues tidv, const TOBValues tobv);
00110 
00111   unsigned int layer(const DetId &id) const;
00112   unsigned int module(const DetId &id) const;
00113 
00114   // layer numbers
00115   unsigned int pxbLayer(const DetId &id) const {
00116     return int((id.rawId()>>pbVals_.layerStartBit_) & pbVals_.layerMask_);
00117   }
00118   unsigned int tobLayer(const DetId &id) const {
00119     return int((id.rawId()>>tobVals_.layerStartBit_) & tobVals_.layerMask_);
00120   }
00121   unsigned int tibLayer(const DetId &id) const {
00122     return int((id.rawId()>>tibVals_.layerStartBit_) & tibVals_.layerMask_);
00123   }
00124 
00125 
00126   //ladder
00127   unsigned int pxbLadder(const DetId &id) const {
00128     return ((id.rawId()>>pbVals_.ladderStartBit_) & pbVals_.ladderMask_) ;
00129   }
00130 
00131   //module
00132   unsigned int pxbModule(const DetId &id) const {
00133     return ((id.rawId()>>pbVals_.moduleStartBit_)& pbVals_.moduleMask_);
00134   }
00135   unsigned int pxfModule(const DetId &id) const {
00136     return int((id.rawId()>>pfVals_.moduleStartBit_) & pfVals_.moduleMask_);
00137   }
00138   unsigned int tobModule(const DetId &id) const {
00139     return ((id.rawId()>>tobVals_.moduleStartBit_)& tobVals_.moduleMask_);
00140   }
00141   unsigned int tecModule(const DetId &id) const { 
00142     return ((id.rawId()>>tecVals_.moduleStartBit_) & tecVals_.moduleMask_);
00143   }
00144   unsigned int tibModule(const DetId &id) const {
00145     return ((id.rawId()>>tibVals_.moduleStartBit_)& tibVals_.moduleMask_);
00146   }
00147   unsigned int tidModule(const DetId &id) const {
00148     return ((id.rawId()>>tidVals_.moduleStartBit_)& tidVals_.moduleMask_);
00149   }
00150 
00151 
00152   //side
00153   unsigned int tobSide(const DetId &id) const {
00154     return ((id.rawId()>>tobVals_.rod_fw_bwStartBit_) & tobVals_.rod_fw_bwMask_);
00155   }
00156 
00157   unsigned int tecSide(const DetId &id) const {
00158     return ((id.rawId()>>tecVals_.sideStartBit_)&tecVals_.sideMask_);
00159   }
00160 
00161   unsigned int tibSide(const DetId &id) const {
00162     return ((id.rawId()>>tibVals_.str_fw_bwStartBit_) & tibVals_.str_fw_bwMask_);
00163   }
00164 
00165   unsigned int tidSide(const DetId &id) const {
00166     return ((id.rawId()>>tidVals_.sideStartBit_)&tidVals_.sideMask_);
00167   }
00168 
00169   unsigned int pxfSide(const DetId &id) const {
00170     return ((id.rawId()>>pfVals_.sideStartBit_)&pfVals_.sideMask_);
00171   }
00172 
00173   //rod
00174   unsigned int tobRod(const DetId &id) const {
00175     return  ((id.rawId()>>tobVals_.rodStartBit_) & tobVals_.rodMask_);
00176   }
00177 
00178   //wheel
00179   unsigned int tecWheel(const DetId &id) const { 
00180     return ((id.rawId()>>tecVals_.wheelStartBit_) & tecVals_.wheelMask_) ;
00181   }
00182   unsigned int tidWheel(const DetId &id) const { 
00183     return ((id.rawId()>>tidVals_.wheelStartBit_) & tidVals_.wheelMask_) ;
00184   }
00185 
00186   //order
00187   unsigned int tecOrder(const DetId &id) const { 
00188     return ((id.rawId()>>tecVals_.petal_fw_bwStartBit_) & tecVals_.petal_fw_bwMask_);
00189   }
00190   unsigned int tibOrder(const DetId &id) const { 
00191     return ((id.rawId()>>tibVals_.str_int_extStartBit_) & tibVals_.str_int_extMask_);
00192   }
00193   unsigned int tidOrder(const DetId &id) const { 
00194     return ((id.rawId()>>tidVals_.module_fw_bwStartBit_) & tidVals_.module_fw_bwMask_);
00195   }
00196 
00197 
00199   unsigned int tecRing(const DetId &id) const { 
00200     return ((id.rawId()>>tecVals_.ringStartBit_) & tecVals_.ringMask_) ;
00201   }
00202   unsigned int tidRing(const DetId &id) const { 
00203     return ((id.rawId()>>tidVals_.ringStartBit_) & tidVals_.ringMask_) ;
00204   }
00205 
00206 
00207   //petal
00208   unsigned int tecPetalNumber(const DetId &id) const
00209   { return ((id.rawId()>>tecVals_.petalStartBit_) & tecVals_.petalMask_);}
00210 
00211 
00212   
00213 
00214   //misc tob
00215   std::vector<unsigned int> tobRodInfo(const DetId &id) const {
00216     std::vector<unsigned int> num;
00217     num.push_back( tobSide(id) );
00218     num.push_back( tobRod(id) );
00219     return num ;
00220   }
00221 
00222   bool tobIsDoubleSide(const DetId &id) const { return SiStripDetId(id).glued()==0 && (tobLayer(id)==1 || tobLayer(id)==2);}
00223   bool tecIsDoubleSide(const DetId &id) const { return SiStripDetId(id).glued()==0 && (tecRing(id)==1 || tecRing(id)==2 || tecRing(id)==5);}
00224   bool tibIsDoubleSide(const DetId &id) const { return SiStripDetId(id).glued()==0 && (tibLayer(id)==1 || tibLayer(id)==2);}
00225   bool tidIsDoubleSide(const DetId &id) const { return SiStripDetId(id).glued()==0 && (tidRing(id)==1 || tidRing(id)==2);}
00226 
00227   bool tobIsZPlusSide(const DetId &id) const {return !tobIsZMinusSide(id);}
00228   bool tobIsZMinusSide(const DetId &id) const { return tobSide(id)==1;}
00229 
00230   bool tibIsZPlusSide(const DetId &id) const {return !tibIsZMinusSide(id);}
00231   bool tibIsZMinusSide(const DetId &id) const { return tibSide(id)==1;}
00232 
00233   bool tidIsZPlusSide(const DetId &id) const {return !tidIsZMinusSide(id);}
00234   bool tidIsZMinusSide(const DetId &id) const { return tidSide(id)==1;}
00235 
00236   bool tecIsZPlusSide(const DetId &id) const {return !tecIsZMinusSide(id);}
00237   bool tecIsZMinusSide(const DetId &id) const { return tecSide(id)==1;}
00238 
00239   //these are from the old TOB/TEC/TID/TIB DetId
00240   bool tobIsStereo(const DetId &id) const {return tobStereo(id)!=0 && !tobIsDoubleSide(id);}
00241   bool tecIsStereo(const DetId &id) const {return tecStereo(id)!=0 && !tecIsDoubleSide(id);}
00242   bool tibIsStereo(const DetId &id) const {return tibStereo(id)!=0 && !tibIsDoubleSide(id);}
00243   bool tidIsStereo(const DetId &id) const {return tidStereo(id)!=0 && !tidIsDoubleSide(id);}
00244 
00245   //these are clones of the old SiStripDetId
00246   uint32_t tobStereo(const DetId &id) const {
00247     if ( ((id.rawId() >>tobVals_.sterStartBit_ ) & tobVals_.sterMask_ ) == 1 ) {
00248       return ( (id.rawId()>>tobVals_.sterStartBit_) & tobVals_.sterMask_ );
00249     } else { return 0; }
00250   }
00251 
00252   uint32_t tibStereo(const DetId &id) const {
00253     if ( ((id.rawId() >>tibVals_.sterStartBit_ ) & tibVals_.sterMask_ ) == 1 ) {
00254       return ( (id.rawId()>>tibVals_.sterStartBit_) & tibVals_.sterMask_ );
00255     } else { return 0; }
00256   }
00257 
00258   uint32_t tidStereo(const DetId &id) const {
00259     if ( ((id.rawId() >>tidVals_.sterStartBit_ ) & tidVals_.sterMask_ ) == 1 ) {
00260       return ( (id.rawId()>>tidVals_.sterStartBit_) & tidVals_.sterMask_ );
00261     } else { return 0; }
00262   }
00263 
00264   uint32_t tecStereo(const DetId &id) const {
00265     if ( ((id.rawId() >>tecVals_.sterStartBit_ ) & tecVals_.sterMask_ ) == 1 ) {
00266       return ( (id.rawId()>>tecVals_.sterStartBit_) & tecVals_.sterMask_ );
00267     } else { return 0; }
00268   }
00269 
00270   uint32_t tibGlued(const DetId &id) const {
00271     if ( ((id.rawId()>>tibVals_.sterStartBit_) & tibVals_.sterMask_ ) == 1 ) {
00272       return ( id.rawId() - 1 );
00273     } else if ( ((id.rawId()>>tibVals_.sterStartBit_) & tibVals_.sterMask_ ) == 2 ) {
00274       return ( id.rawId() - 2 );
00275     } else { return 0; }
00276   }
00277 
00278   uint32_t tecGlued(const DetId &id) const {
00279     if ( ((id.rawId()>>tecVals_.sterStartBit_) & tecVals_.sterMask_ ) == 1 ) {
00280       return ( id.rawId() - 1 );
00281     } else if ( ((id.rawId()>>tecVals_.sterStartBit_) & tecVals_.sterMask_ ) == 2 ) {
00282       return ( id.rawId() - 2 );
00283     } else { return 0; }
00284   }
00285 
00286   uint32_t tobGlued(const DetId &id) const {
00287     if ( ((id.rawId()>>tobVals_.sterStartBit_) & tobVals_.sterMask_ ) == 1 ) {
00288       return ( id.rawId() - 1 );
00289     } else if ( ((id.rawId()>>tobVals_.sterStartBit_) & tobVals_.sterMask_ ) == 2 ) {
00290       return ( id.rawId() - 2 );
00291     } else { return 0; }
00292   }
00293 
00294   uint32_t tidGlued(const DetId &id) const {
00295     if ( ((id.rawId()>>tidVals_.sterStartBit_) & tidVals_.sterMask_ ) == 1 ) {
00296       return ( id.rawId() - 1 );
00297     } else if ( ((id.rawId()>>tidVals_.sterStartBit_) & tidVals_.sterMask_ ) == 2 ) {
00298       return ( id.rawId() - 2 );
00299     } else { return 0; }
00300   }
00301 
00302   bool tobIsRPhi(const DetId &id) const { return SiStripDetId(id).stereo()==0 && !tobIsDoubleSide(id);}
00303   bool tecIsRPhi(const DetId &id) const { return SiStripDetId(id).stereo()==0 && !tecIsDoubleSide(id);}
00304   bool tibIsRPhi(const DetId &id) const { return SiStripDetId(id).stereo()==0 && !tibIsDoubleSide(id);}
00305   bool tidIsRPhi(const DetId &id) const { return SiStripDetId(id).stereo()==0 && !tidIsDoubleSide(id);}
00306 
00307 
00308   //misc tec
00309   std::vector<unsigned int> tecPetalInfo(const DetId &id) const {
00310     std::vector<unsigned int> num;
00311     num.push_back(tecOrder(id));
00312     num.push_back(tecPetalNumber(id));
00313     return num ;
00314   }
00315 
00316   bool tecIsBackPetal(const DetId &id) const {
00317     return (tecOrder(id)==1);
00318   }
00319 
00320   bool tecIsFrontPetal(const DetId &id) const {return !tecIsBackPetal(id);}
00321 
00322   //misc tib
00323   unsigned int tibString(const DetId &id) const {
00324     return (id.rawId()>>tibVals_.strStartBit_)&tibVals_.strMask_;
00325   }
00326 
00327   std::vector<unsigned int> tibStringInfo(const DetId &id) const
00328     { std::vector<unsigned int> num;
00329       num.push_back( tibSide(id) );
00330       num.push_back( tibOrder(id) );
00331       num.push_back(tibString(id));
00332       return num ;
00333     }
00334 
00335   bool tibIsInternalString(const DetId &id) const {
00336     return (tibOrder(id)==1);
00337   }
00338 
00339   bool tibIsExternalString(const DetId &id) const {
00340     return !tibIsInternalString(id);
00341   }
00342 
00343   //misc tid
00344   std::vector<unsigned int> tidModuleInfo(const DetId &id) const {
00345     std::vector<unsigned int> num;
00346     num.push_back( tidOrder(id) );
00347     num.push_back( tidModule(id) );
00348     return num ;
00349   }
00350 
00351   bool tidIsBackRing(const DetId &id) const {
00352     return (tidOrder(id)==1);
00353   }
00354 
00355   bool tidIsFrontRing(const DetId &id) const {return !tidIsBackRing(id);}
00356 
00357 
00358   //misc pf
00359   unsigned int pxfDisk(const DetId &id) const {
00360     return int((id.rawId()>>pfVals_.diskStartBit_) & pfVals_.diskMask_);
00361   }
00362   unsigned int pxfBlade(const DetId &id) const {
00363     return int((id.rawId()>>pfVals_.bladeStartBit_) & pfVals_.bladeMask_);
00364   }
00365   unsigned int pxfPanel(const DetId &id) const {
00366     return int((id.rawId()>>pfVals_.panelStartBit_) & pfVals_.panelMask_);
00367   }
00368 
00369   //old constructors, now return DetId
00370   DetId pxbDetId(uint32_t layer,
00371                  uint32_t ladder,
00372                  uint32_t module) const {
00373     //uply
00374     DetId id(DetId::Tracker,PixelSubdetector::PixelBarrel);
00375     uint32_t rawid=id.rawId();
00376     rawid |= (layer& pbVals_.layerMask_) << pbVals_.layerStartBit_     |
00377       (ladder& pbVals_.ladderMask_) << pbVals_.ladderStartBit_  |
00378       (module& pbVals_.moduleMask_) << pbVals_.moduleStartBit_;
00379     return DetId(rawid);
00380   }
00381 
00382   DetId pxfDetId(uint32_t side,
00383                  uint32_t disk,
00384                  uint32_t blade,
00385                  uint32_t panel,
00386                  uint32_t module) const {
00387     DetId id(DetId::Tracker,PixelSubdetector::PixelEndcap);
00388     uint32_t rawid=id.rawId();
00389     rawid |= (side& pfVals_.sideMask_)  << pfVals_.sideStartBit_   |
00390       (disk& pfVals_.diskMask_)        << pfVals_.diskStartBit_      |
00391       (blade& pfVals_.bladeMask_)      << pfVals_.bladeStartBit_     |
00392       (panel& pfVals_.panelMask_)      << pfVals_.panelStartBit_     |
00393       (module& pfVals_.moduleMask_)    << pfVals_.moduleStartBit_  ;
00394     return DetId(rawid);
00395   }
00396 
00397   DetId tecDetId(uint32_t side, uint32_t wheel,
00398                  uint32_t petal_fw_bw, uint32_t petal,
00399                  uint32_t ring, uint32_t module, uint32_t ster) const {  
00400 
00401     DetId id=SiStripDetId(DetId::Tracker,StripSubdetector::TEC);
00402     uint32_t rawid=id.rawId();
00403 
00404     rawid |= (side& tecVals_.sideMask_)         << tecVals_.sideStartBit_ |
00405       (wheel& tecVals_.wheelMask_)             << tecVals_.wheelStartBit_ |
00406       (petal_fw_bw& tecVals_.petal_fw_bwMask_) << tecVals_.petal_fw_bwStartBit_ |
00407       (petal& tecVals_.petalMask_)             << tecVals_.petalStartBit_ |
00408       (ring& tecVals_.ringMask_)               << tecVals_.ringStartBit_ |
00409       (module& tecVals_.moduleMask_)                 << tecVals_.moduleStartBit_ |
00410       (ster& tecVals_.sterMask_)               << tecVals_.sterStartBit_ ;
00411     return DetId(rawid);
00412   }
00413 
00414   DetId tibDetId(uint32_t layer,
00415                  uint32_t str_fw_bw,
00416                  uint32_t str_int_ext,
00417                  uint32_t str,
00418                  uint32_t module,
00419                  uint32_t ster) const {
00420     DetId id=SiStripDetId(DetId::Tracker,StripSubdetector::TIB);
00421     uint32_t rawid=id.rawId();
00422     rawid |= (layer& tibVals_.layerMask_) << tibVals_.layerStartBit_ |
00423       (str_fw_bw& tibVals_.str_fw_bwMask_) << tibVals_.str_fw_bwStartBit_ |
00424       (str_int_ext& tibVals_.str_int_extMask_) << tibVals_.str_int_extStartBit_ |
00425       (str& tibVals_.strMask_) << tibVals_.strStartBit_ |
00426       (module& tibVals_.moduleMask_) << tibVals_.moduleStartBit_ |
00427       (ster& tibVals_.sterMask_) << tibVals_.sterStartBit_ ;
00428     return DetId(rawid);
00429   }
00430 
00431   DetId tidDetId(uint32_t side,
00432                  uint32_t wheel,
00433                  uint32_t ring,
00434                  uint32_t module_fw_bw,
00435                  uint32_t module,
00436                  uint32_t ster) const { 
00437     DetId id=SiStripDetId(DetId::Tracker,StripSubdetector::TID);
00438     uint32_t rawid=id.rawId();
00439     rawid |= (side& tidVals_.sideMask_)      << tidVals_.sideStartBit_    |
00440       (wheel& tidVals_.wheelMask_)          << tidVals_.wheelStartBit_      |
00441       (ring& tidVals_.ringMask_)            << tidVals_.ringStartBit_       |
00442       (module_fw_bw& tidVals_.module_fw_bwMask_)  << tidVals_.module_fw_bwStartBit_  |
00443       (module& tidVals_.moduleMask_)              << tidVals_.moduleStartBit_        |
00444       (ster& tidVals_.sterMask_)            << tidVals_.sterStartBit_ ;
00445     return DetId(rawid);
00446   }
00447 
00448   DetId tobDetId(uint32_t layer,
00449                  uint32_t rod_fw_bw,
00450                  uint32_t rod,
00451                  uint32_t module,
00452                  uint32_t ster) const {
00453     DetId id=SiStripDetId(DetId::Tracker,StripSubdetector::TOB);
00454     uint32_t rawid=id.rawId();
00455     rawid |= (layer& tobVals_.layerMask_) << tobVals_.layerStartBit_ |
00456       (rod_fw_bw& tobVals_.rod_fw_bwMask_) << tobVals_.rod_fw_bwStartBit_ |
00457       (rod& tobVals_.rodMask_) << tobVals_.rodStartBit_ |
00458       (module& tobVals_.moduleMask_) << tobVals_.moduleStartBit_ |
00459       (ster& tobVals_.sterMask_) << tobVals_.sterStartBit_ ;
00460     return DetId(rawid);
00461   }
00462 
00463   std::string print(DetId detid) const;
00464 
00465  private:
00466 
00467   PixelBarrelValues pbVals_;
00468   PixelEndcapValues pfVals_;
00469 
00470   TOBValues tobVals_;
00471   TIBValues tibVals_;
00472   TIDValues tidVals_;
00473   TECValues tecVals_;
00474   
00475 };
00476 
00477 #endif
00478