CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/DataFormats/SiPixelDetId/src/PixelBarrelNameUpgrade.cc

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