CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DataFormats/SiPixelDetId/src/PixelBarrelName.cc

Go to the documentation of this file.
00001 #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
00002 
00003 #include <sstream>
00004 #include <iostream>
00005 
00006 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 
00009 using namespace std;
00010 
00011 
00012 PixelBarrelName::PixelBarrelName(const DetId & id) 
00013   : PixelModuleName(true)
00014 {
00015  
00016 //  uint32_t rawId = id.rawId(); 
00017   PXBDetId cmssw_numbering(id);
00018 
00019 
00020   theLayer = cmssw_numbering.layer();
00021 
00022   int oldModule = cmssw_numbering.module() -4; if (oldModule<=0) oldModule--;
00023 
00024   int oldLadder = cmssw_numbering.ladder();
00025   if (theLayer == 1) {
00026     if (oldLadder <= 5) oldLadder = 6-oldLadder;
00027     else if (oldLadder >= 6 && oldLadder <= 15 ) oldLadder = 5-oldLadder;
00028     else if (oldLadder >= 16) oldLadder = 26-oldLadder;
00029   } 
00030   else if (theLayer == 2) {
00031     if (oldLadder <= 8) oldLadder = 9-oldLadder;
00032     else if (oldLadder >= 9 && oldLadder <= 24) oldLadder = 8-oldLadder;
00033     else if (oldLadder >= 25) oldLadder = 41-oldLadder; 
00034   } 
00035   else if (theLayer == 3) {
00036     if (oldLadder <= 11) oldLadder = 12-oldLadder;
00037     else if (oldLadder >= 12 && oldLadder <= 33) oldLadder = 11-oldLadder;
00038     else if (oldLadder >= 34) oldLadder = 56-oldLadder;
00039   } 
00040 
00041   //
00042   // part
00043   //
00044   if      (oldModule < 0 && oldLadder < 0) thePart = mO; 
00045   else if (oldModule > 0 && oldLadder < 0) thePart = pO;
00046   else if (oldModule < 0 && oldLadder > 0) thePart = mI;
00047   else if (oldModule > 0 && oldLadder > 0) thePart = pI;
00048   
00049 
00050   //
00051   // ladder
00052   //
00053   theLadder = abs(oldLadder);
00054 
00055   //
00056   // module
00057   //
00058   theModule = abs(oldModule);
00059  
00060 }
00061 
00062 // constructor from name string
00063 PixelBarrelName::PixelBarrelName(std::string name) 
00064   : PixelModuleName(true), thePart(mO), theLayer(0),
00065     theModule(0), theLadder(0) {
00066 
00067   // parse the name string
00068   // first, check to make sure this is an BPix name, should start with "BPix_"
00069   // also check to make sure the needed parts are present
00070   if ( (name.substr(0, 5) != "BPix_") ||
00071        (name.find("_B") == string::npos) || 
00072        (name.find("_LYR") == string::npos) ||
00073        (name.find("_LDR") == string::npos) || 
00074        (name.find("_MOD") == string::npos) ) {
00075     edm::LogError ("BadNameString|SiPixel") 
00076       << "Bad name string in PixelBarrelName::PixelBarrelName(std::string): "
00077       << name;
00078     return;
00079   }
00080 
00081   // strip off ROC part if it's there
00082   if (name.find("_ROC") != string::npos)
00083     name = name.substr(0, name.find("_ROC"));
00084 
00085   // find shell
00086   string shellString = name.substr(name.find("_B")+2, name.find("_SEC")-name.find("_B")-2);
00087   if (shellString == "mO") thePart = mO;
00088   else if (shellString == "mI") thePart = mI;
00089   else if (shellString == "pO") thePart = pO;
00090   else if (shellString == "pI") thePart = pI;
00091   else {
00092     edm::LogError ("BadNameString|SiPixel")
00093       << "Unable to determine shell in PixelBarrelName::PixelBarrelName(std::string): "
00094       << name;
00095   }
00096 
00097   // find the layer
00098   string layerString = name.substr(name.find("_LYR")+4, name.find("_LDR")-name.find("_LYR")-4);
00099   if (layerString == "1") theLayer = 1;
00100   else if (layerString == "2") theLayer = 2;
00101   else if (layerString == "3") theLayer = 3;
00102   else {
00103     edm::LogError ("BadNameString|SiPixel")
00104       << "Unable to determine layer in PixelBarrelName::PixelBarrelName(std::string): "
00105       << name;
00106   }
00107 
00108   // find the ladder
00109   string ladderString = name.substr(name.find("_LDR")+4, name.find("_MOD")-name.find("_LDR")-4);
00110   if (ladderString == "1H") theLadder = 1;
00111   else if (ladderString == "10H" && theLayer == 1) theLadder = 10;
00112   else if (ladderString == "16H" && theLayer == 2) theLadder = 16;
00113   else if (ladderString == "22H" && theLayer == 3) theLadder = 22;
00114   else if (ladderString.substr(ladderString.size()-1, 1) == "F") {
00115     int ladderNum = atoi(ladderString.substr(0, ladderString.size() -1).c_str());
00116     if (theLayer == 1 && ladderNum > 1 && ladderNum < 10) theLadder = ladderNum;
00117     else if (theLayer == 2 && ladderNum > 1 && ladderNum < 16) theLadder = ladderNum;
00118     else if (theLayer == 3 && ladderNum > 1 && ladderNum < 22) theLadder = ladderNum;
00119     else {
00120       edm::LogError ("BadNameString|SiPixel")
00121         << "Unable to determine ladder in PixelBarrelName::PixelBarrelName(std::string): "
00122         << name;
00123     }
00124   } // full ladders
00125   else {
00126     edm::LogError ("BadNameString|SiPixel")
00127       << "Unable to determine ladder in PixelBarrelName::PixelBarrelName(std::string): "
00128       << name;
00129   }
00130 
00131   // find the module
00132   string moduleString = name.substr(name.find("_MOD")+4, name.size()-name.find("_MOD")-4);
00133   if (moduleString == "1") theModule = 1;
00134   else if (moduleString == "2") theModule = 2;
00135   else if (moduleString == "3") theModule = 3;
00136   else if (moduleString == "4") theModule = 4;
00137   else {
00138     edm::LogError ("BadNameString|SiPixel")
00139       << "Unable to determine module in PixelBarrelName::PixelBarrelName(std::string): "
00140       << name;
00141   }
00142 
00143 } // PixelBarrelName::PixelBarrelName(std::string name)
00144 
00145 int PixelBarrelName::sectorName() const
00146 {
00147   int sector = 0;
00148   if (theLayer==1) {
00149     switch (theLadder) {
00150     case 1 : case 2: {sector = 1; break;}
00151     case 3 :         {sector = 2; break;}
00152     case 4 :         {sector = 3; break;}
00153     case 5 :         {sector = 4; break;}
00154     case 6 :         {sector = 5; break;}
00155     case 7 :         {sector = 6; break;}
00156     case 8 :         {sector = 7; break;}
00157     case 9 : case 10:{sector = 8; break;}
00158     default: ;
00159     };
00160   } else if (theLayer==2) {
00161     switch (theLadder) {
00162     case  1 : case  2: {sector = 1; break;}
00163     case  3 : case  4: {sector = 2; break;}
00164     case  5 : case  6: {sector = 3; break;}
00165     case  7 : case  8: {sector = 4; break;}
00166     case  9 : case 10: {sector = 5; break;}
00167     case 11 : case 12: {sector = 6; break;}
00168     case 13 : case 14: {sector = 7; break;}
00169     case 15 : case 16: {sector = 8; break;}
00170     default: ;
00171     };
00172   } else if (theLayer==3) {
00173     switch (theLadder) {
00174     case  1 : case  2: case  3: {sector = 1; break;}
00175     case  4 : case  5: case  6: {sector = 2; break;}
00176     case  7 : case  8: case  9: {sector = 3; break;}
00177     case 10 : case 11:          {sector = 4; break;}
00178     case 12 : case 13:          {sector = 5; break;}
00179     case 14 : case 15: case 16: {sector = 6; break;}
00180     case 17 : case 18: case 19: {sector = 7; break;}
00181     case 20 : case 21: case 22: {sector = 8; break;}
00182     default: ;
00183     };
00184   }
00185   return sector;
00186 
00187 }
00188 
00189 bool PixelBarrelName::isHalfModule() const 
00190 {
00191   bool halfModule = false;
00192   if (theLadder == 1) halfModule = true;
00193   if (theLayer == 1 && theLadder == 10) halfModule = true;
00194   if (theLayer == 2 && theLadder == 16) halfModule = true;
00195   if (theLayer == 3 && theLadder == 22) halfModule = true;
00196   return halfModule;
00197 }
00198 
00199 PixelModuleName::ModuleType  PixelBarrelName::moduleType() const 
00200 {
00201   return isHalfModule() ? PixelBarrelName::v1x8 : PixelBarrelName::v2x8;
00202 }
00203 
00204 bool PixelBarrelName::operator==(const PixelModuleName &o) const
00205 {
00206   if ( o.isBarrel() ) { 
00207     const PixelBarrelName *other = dynamic_cast<const PixelBarrelName*>(&o);
00208     return (    other
00209              && thePart   == other->thePart 
00210              && theLayer  == other->theLayer 
00211              && theModule == other->theModule 
00212              && theLadder == other->theLadder);
00213   } else return false; 
00214 }
00215 
00216 string PixelBarrelName::name() const 
00217 {
00218    std::ostringstream stm;
00219    
00220    stm<<"BPix_B"<<thePart<<"_SEC"<<sectorName()<<"_LYR"<<theLayer<<"_LDR"<<theLadder;
00221    if ( isHalfModule() ) stm <<"H"; else stm <<"F";
00222    stm << "_MOD" << theModule;
00223 
00224    return stm.str();
00225 }
00226 
00227 // return the DetId
00228 PXBDetId PixelBarrelName::getDetId() {
00229   
00230   uint32_t layer = 0;
00231   uint32_t ladder = 0;
00232   uint32_t module = 0;
00233 
00234   layer = layerName();
00235   uint32_t tmpLadder = ladderName();
00236   uint32_t tmpModule = moduleName();
00237 
00238   // translate the ladder number from the naming convention to the cmssw convention
00239   bool outer = false;
00240   Shell shell = thePart;
00241   outer = (shell == mO) || (shell == pO);
00242   if (outer) {
00243     if (layer == 1)
00244       ladder = tmpLadder + 5;
00245     else if (layer == 2)
00246       ladder = tmpLadder + 8;
00247     else if (layer == 3)
00248       ladder = tmpLadder + 11;
00249   } // outer
00250   else { // inner
00251     if (layer == 1) {
00252       if (tmpLadder <= 5) ladder = 6 - tmpLadder;
00253       else if (tmpLadder <= 10) ladder = 26 - tmpLadder;
00254     } // layer 1
00255     else if (layer == 2) {
00256       if (tmpLadder <= 8) ladder = 9 - tmpLadder;
00257       else if (tmpLadder <= 16) ladder = 41 - tmpLadder;
00258     } // layer 2
00259     else if (layer == 3) {
00260       if (tmpLadder <= 11) ladder = 12 - tmpLadder;
00261       else if (tmpLadder <= 22) ladder = 56 - tmpLadder;
00262     } // layer 3
00263   } // inner
00264 
00265   // translate the module number from naming convention to cmssw convention
00266   // numbering starts at positive z
00267   if (shell == pO || shell == pI)
00268     module = tmpModule + 4;
00269   else // negative z side
00270     module = 5 - tmpModule;
00271 
00272   return PXBDetId(layer, ladder, module);
00273 
00274 } // PXBDetId PixelBarrelName::getDetId()
00275 
00276 std::ostream & operator<<( std::ostream& out, const PixelBarrelName::Shell& t)
00277 {
00278   switch (t) {
00279     case(PixelBarrelName::pI) : {out << "pI"; break;}
00280     case(PixelBarrelName::pO) : {out << "pO"; break;}
00281     case(PixelBarrelName::mI) : {out << "mI"; break;}
00282     case(PixelBarrelName::mO) : {out << "mO"; break;}
00283     default: out << "unknown";
00284   };
00285   return out;
00286 }