CMS 3D CMS Logo

PixelEndcapName.cc

Go to the documentation of this file.
00001 #include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"
00002 
00003 #include <sstream>
00004 
00005 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00006 
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 
00009 using namespace std;
00010 
00011 PixelEndcapName::PixelEndcapName(const DetId & id)
00012   : PixelModuleName(false)
00013 {
00014   PXFDetId cmssw_numbering(id);
00015   int side = cmssw_numbering.side();
00016 
00017   int tmpBlade = cmssw_numbering.blade();
00018   bool outer = false;
00019   if (tmpBlade >= 7 && tmpBlade <= 18) {
00020     outer = true;
00021     theBlade = tmpBlade-6;
00022   } else if( tmpBlade <=6 ) { 
00023     theBlade = 7-tmpBlade; 
00024   } else if( tmpBlade >= 19) { 
00025     theBlade = 31-tmpBlade; 
00026   } 
00027 
00028 
00029        if( side == 1 &&  outer ) thePart = mO;
00030   else if( side == 1 && !outer ) thePart = mI;
00031   else if( side == 2 &&  outer ) thePart = pO;
00032   else if( side == 2 && !outer ) thePart = pI;
00033  
00034 
00035   theDisk = cmssw_numbering.disk();
00036   thePannel = cmssw_numbering.panel();
00037   thePlaquette = cmssw_numbering.module();
00038 }
00039 
00040 // constructor from name string
00041 PixelEndcapName::PixelEndcapName(std::string name)
00042   : PixelModuleName(false), thePart(mO), theDisk(0), 
00043     theBlade(0), thePannel(0), thePlaquette(0) {
00044 
00045   // parse the name string
00046   // first, check to make sure this is an FPix name, should start with "FPix_"
00047   // also check to make sure the needed parts are present
00048   if ( (name.substr(0, 5) != "FPix_") ||
00049        (name.find("_B") == string::npos) || 
00050        (name.find("_D") == string::npos) ||
00051        (name.find("_BLD") == string::npos) || 
00052        (name.find("_PNL") == string::npos) ||
00053        (name.find("_PLQ") == string::npos) ) {
00054     edm::LogError ("BadNameString|SiPixel") 
00055       << "Bad name string in PixelEndcapName::PixelEndcapName(std::string): "
00056       << name;
00057     return;
00058   }
00059 
00060   // strip off ROC part if it's there
00061   if (name.find("_ROC") != string::npos)
00062     name = name.substr(0, name.find("_ROC"));
00063 
00064   // get the half cylinder
00065   string hcString = name.substr(name.find("_B")+2, name.find("_D")-name.find("_B")-2);
00066   if (hcString == "mO") thePart = mO;
00067   else if (hcString == "mI") thePart = mI;
00068   else if (hcString == "pO") thePart = pO;
00069   else if (hcString == "pI") thePart = pI;
00070   else {
00071     edm::LogError ("BadNameString|SiPixel") 
00072       << "Unable to determine half cylinder in PixelEndcapName::PixelEndcapName(std::string): "
00073       << name;
00074   }
00075 
00076   // get the disk
00077   string diskString = name.substr(name.find("_D")+2, name.find("_BLD")-name.find("_D")-2);
00078   if (diskString == "1") theDisk = 1;
00079   else if (diskString == "2") theDisk = 2;
00080   else if (diskString == "3") theDisk = 3;
00081   else {
00082     edm::LogError ("BadNameString|SiPixel") 
00083       << "Unable to determine disk number in PixelEndcapName::PixelEndcapName(std::string): "
00084       << name;
00085   }
00086 
00087   // get the blade
00088   string bladeString = name.substr(name.find("_BLD")+4, name.find("_PNL")-name.find("_BLD")-4);
00089   // since atoi() doesn't report errors, do it the long way
00090   if (bladeString == "1") theBlade = 1;
00091   else if (bladeString == "2") theBlade = 2;
00092   else if (bladeString == "3") theBlade = 3;
00093   else if (bladeString == "4") theBlade = 4;
00094   else if (bladeString == "5") theBlade = 5;
00095   else if (bladeString == "6") theBlade = 6;
00096   else if (bladeString == "7") theBlade = 7;
00097   else if (bladeString == "8") theBlade = 8;
00098   else if (bladeString == "9") theBlade = 9;
00099   else if (bladeString == "10") theBlade = 10;
00100   else if (bladeString == "11") theBlade = 11;
00101   else if (bladeString == "12") theBlade = 12;
00102   else {
00103     edm::LogError ("BadNameString|SiPixel") 
00104       << "Unable to determine blade number in PixelEndcapName::PixelEndcapName(std::string): "
00105       << name;
00106   }
00107 
00108   // find the panel
00109   string panelString = name.substr(name.find("_PNL")+4, name.find("_PLQ")-name.find("_PNL")-4);
00110   if (panelString == "1") thePannel = 1;
00111   else if (panelString == "2") thePannel = 2;
00112   else {
00113     edm::LogError ("BadNameString|SiPixel") 
00114       << "Unable to determine panel number in PixelEndcapName::PixelEndcapName(std::string): "
00115       << name;
00116   }
00117 
00118   // find the plaquette
00119   string plaquetteString = name.substr(name.find("_PLQ")+4, name.size()-name.find("_PLQ")-4);
00120   if (plaquetteString == "1") thePlaquette = 1;
00121   else if (plaquetteString == "2") thePlaquette = 2;
00122   else if (plaquetteString == "3") thePlaquette = 3;
00123   else if (plaquetteString == "4") thePlaquette = 4;
00124   else {
00125     edm::LogError ("BadNameString|SiPixel") 
00126       << "Unable to determine plaquette number in PixelEndcapName::PixelEndcapName(std::string): "
00127       << name;
00128   }
00129 
00130 } // PixelEndcapName::PixelEndcapName(std::string name)
00131 
00132 PixelModuleName::ModuleType  PixelEndcapName::moduleType() const
00133 {
00134   ModuleType type = v1x2;
00135   if (pannelName() == 1) {
00136     if (plaquetteName() == 1)      { type = v1x2; }
00137     else if (plaquetteName() == 2) { type = v2x3; }
00138     else if (plaquetteName() == 3) { type = v2x4; }
00139     else if (plaquetteName() == 4) { type = v1x5; }
00140   }
00141   else {
00142     if (plaquetteName() == 1)      { type = v2x3; }
00143     else if (plaquetteName() == 2) { type = v2x4; }
00144     else if (plaquetteName() == 3) { type = v2x5; }
00145   }
00146   return type;
00147 }
00148 
00149 bool PixelEndcapName::operator== (const PixelModuleName & o) const
00150 {
00151   if (!o.isBarrel()) {
00152     const PixelEndcapName * other = dynamic_cast<const PixelEndcapName *>(&o);
00153     return (    other 
00154              && thePart      == other->thePart
00155              && theDisk      == other->theDisk
00156              && theBlade     == other->theBlade
00157              && thePannel    == other->thePannel
00158              && thePlaquette == other->thePlaquette ); 
00159   } else return false;
00160 }
00161 
00162 
00163 string PixelEndcapName::name() const 
00164 {
00165   std::ostringstream stm;
00166   stm <<"FPix_B"<<thePart<<"_D"<<theDisk<<"_BLD"<<theBlade<<"_PNL"<<thePannel<<"_PLQ"<<thePlaquette;
00167   return stm.str();
00168 }
00169 
00170 std::ostream & operator<<( std::ostream& out, const PixelEndcapName::HalfCylinder& t)
00171 {
00172   switch (t) {
00173     case(PixelEndcapName::pI) : {out << "pI"; break;}
00174     case(PixelEndcapName::pO) : {out << "pO"; break;}
00175     case(PixelEndcapName::mI) : {out << "mI"; break;}
00176     case(PixelEndcapName::mO) : {out << "mO"; break;}
00177     default: out << "unknown";
00178   };
00179   return out;
00180 }
00181 
00182 // return the DetId
00183 PXFDetId PixelEndcapName::getDetId() {
00184   
00185   uint32_t side = 0;
00186   uint32_t disk = 0;
00187   uint32_t blade = 0;
00188   uint32_t panel = 0;
00189   uint32_t module = 0;
00190 
00191   // figure out the side
00192   HalfCylinder hc = halfCylinder();
00193   if (hc == mO || hc == mI) side = 1;
00194   else if (hc == pO || hc == pI) side = 2;
00195   
00196   // get disk/blade/panel/module numbers from PixelEndcapName object
00197   disk = static_cast<uint32_t>(diskName());
00198   uint32_t tmpBlade = static_cast<uint32_t>(bladeName());
00199   panel = static_cast<uint32_t>(pannelName());
00200   module = static_cast<uint32_t>(plaquetteName());
00201 
00202   // convert blade numbering to cmssw convention
00203   bool outer = false;
00204   outer = (hc == mO) || (hc == pO);
00205   if (outer) {
00206     blade = tmpBlade + 6;
00207   }
00208   else { // inner
00209     if (tmpBlade <= 6) blade = 7 - tmpBlade;
00210     else if (tmpBlade <= 12) blade = 31 - tmpBlade;
00211   }
00212 
00213   // create and return the DetId
00214   return PXFDetId(side, disk, blade, panel, module);
00215 
00216 } // PXFDetId PixelEndcapName::getDetId()

Generated on Tue Jun 9 17:31:41 2009 for CMSSW by  doxygen 1.5.4