Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:49

0001 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0002 
0003 #include <sstream>
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0006 
0007 using namespace std;
0008 
0009 namespace {
0010   //const bool phase1 = false;
0011   const bool pilot_blade = false;
0012 }  // namespace
0013 
0014 // Decodes the pixel name from the cmssw DetID, uses tracker topology
0015 PixelEndcapName::PixelEndcapName(const DetId& id, const TrackerTopology* tt, bool phase)
0016     : PixelModuleName(false), thePart(mO), theDisk(0), theBlade(0), thePannel(0), thePlaquette(0), phase1(phase) {
0017   //PXFDetId cmssw_numbering(id);
0018   int side = tt->pxfSide(id);
0019   int tmpBlade = tt->pxfBlade(id);
0020   theDisk = tt->pxfDisk(id);
0021   thePannel = tt->pxfPanel(id);
0022   bool outer = false;  // outer means with respect to the LHC ring (x - axis) Bm(p)I/O
0023 
0024   if (phase1) {  // phase 1
0025 
0026     int ring = 0;  // ring number , according to radius, 1-lower, 2- higher
0027 
0028     if (tmpBlade >= 7 && tmpBlade <= 17) {  // ring 1, O
0029       outer = true;
0030       theBlade = tmpBlade - 6;  //7...17-->1...11
0031       ring = 1;                 // lower radius
0032 
0033     } else if (tmpBlade <= 6) {  // ring 1, I
0034       theBlade = 7 - tmpBlade;   //1...6-->6...1
0035       ring = 1;
0036 
0037     } else if (tmpBlade >= 18 && tmpBlade <= 22) {  // ring 1, I
0038       theBlade = 29 - tmpBlade;                     //18...22-->11...7
0039       ring = 1;
0040 
0041     } else if (tmpBlade >= 32 && tmpBlade <= 48) {  // ring 2, O
0042       outer = true;
0043       theBlade = tmpBlade - 31;  //32...48-->28...12
0044       ring = 2;                  // higher radius
0045 
0046     } else if (tmpBlade >= 23 && tmpBlade <= 31) {  // ring 2, I
0047       theBlade = 32 - tmpBlade;                     //23...31-->9...1
0048       ring = 2;
0049 
0050     } else if (tmpBlade >= 49 && tmpBlade <= 56) {  // ring 2, I
0051       theBlade = 66 - tmpBlade;                     //49...56-->28...21
0052       ring = 2;
0053 
0054     }  //  end
0055 
0056     thePlaquette = ring;
0057 
0058   } else {  // phase0
0059 
0060     // hack for the pilot blade
0061     if (pilot_blade && theDisk == 3) {  // do only for disk 3
0062       //cout<<tmpBlade<<" "<<theDisk<<endl;
0063       if (tmpBlade >= 1 && tmpBlade <= 4) {
0064         // convert the sequential counting of pilot blades to std. cmssw convention
0065         if (tmpBlade < 3)
0066           tmpBlade += 3;
0067         else
0068           tmpBlade += 13;
0069       } else {
0070         edm::LogError("Bad PilotBlade blade number ") << tmpBlade;
0071       }
0072     }
0073 
0074     if (tmpBlade >= 7 && tmpBlade <= 18) {
0075       outer = true;
0076       theBlade = tmpBlade - 6;
0077     } else if (tmpBlade <= 6) {
0078       theBlade = 7 - tmpBlade;
0079     } else if (tmpBlade >= 19) {
0080       theBlade = 31 - tmpBlade;
0081     }
0082 
0083     thePlaquette = tt->pxfModule(id);  // ring number is coded as plaqutte (plaqs are unused)
0084 
0085   }  // end phase1
0086 
0087   if (side == 1 && outer)
0088     thePart = mO;
0089   else if (side == 1 && !outer)
0090     thePart = mI;
0091   else if (side == 2 && outer)
0092     thePart = pO;
0093   else if (side == 2 && !outer)
0094     thePart = pI;
0095 }
0096 
0097 // Decodes the pixel name from the cmssw DetID, uses old pixel name classes
0098 PixelEndcapName::PixelEndcapName(const DetId& id, bool phase)
0099     : PixelModuleName(false), thePart(mO), theDisk(0), theBlade(0), thePannel(0), thePlaquette(0), phase1(phase) {
0100   PXFDetId cmssw_numbering(id);
0101   int side = cmssw_numbering.side();
0102   int tmpBlade = cmssw_numbering.blade();
0103   theDisk = cmssw_numbering.disk();
0104   thePannel = cmssw_numbering.panel();
0105   bool outer = false;  // outer means with respect to the LHC ring (x - axis)
0106 
0107   if (phase1) {  // phase1
0108 
0109     int ring = 0;  // ring number , according to radius, 1-lower, 2- higher
0110 
0111     if (tmpBlade >= 7 && tmpBlade <= 17) {  // ring 1, O
0112       outer = true;
0113       theBlade = tmpBlade - 6;  //7...17-->1...11
0114       ring = 1;                 // lower radius
0115 
0116     } else if (tmpBlade <= 6) {  // ring 1, I
0117       theBlade = 7 - tmpBlade;   //1...6-->6...1
0118       ring = 1;
0119 
0120     } else if (tmpBlade >= 18 && tmpBlade <= 22) {  // ring 1, I
0121       theBlade = 29 - tmpBlade;                     //18...22-->11...7
0122       ring = 1;
0123 
0124     } else if (tmpBlade >= 32 && tmpBlade <= 48) {  // ring 2, O
0125       outer = true;
0126       theBlade = tmpBlade - 31;  //32...48-->28...12
0127       ring = 2;                  // higher radius
0128 
0129     } else if (tmpBlade >= 23 && tmpBlade <= 31) {  // ring 2, I
0130       theBlade = 32 - tmpBlade;                     //23...31-->9...1
0131       ring = 2;
0132 
0133     } else if (tmpBlade >= 49 && tmpBlade <= 56) {  // ring 2, I
0134       theBlade = 66 - tmpBlade;                     //49...56-->28...21
0135       ring = 2;
0136 
0137     }  //  end
0138 
0139     thePlaquette = ring;
0140 
0141   } else {  // phase 0
0142 
0143     // hack for the pilot blade
0144     if (pilot_blade && theDisk == 3) {  // do only for disk 3
0145       if (tmpBlade >= 1 && tmpBlade <= 4) {
0146         // convert the sequential counting of pilot blades to std. cmssw convention
0147         if (tmpBlade < 3)
0148           tmpBlade += 3;
0149         else
0150           tmpBlade += 13;
0151       } else {
0152         edm::LogError("Bad PilotBlade blade number ") << tmpBlade;
0153       }
0154     }
0155 
0156     if (tmpBlade >= 7 && tmpBlade <= 18) {
0157       outer = true;  // outer means with respect to the LHC ring (x - axis)
0158       theBlade = tmpBlade - 6;
0159     } else if (tmpBlade <= 6) {
0160       theBlade = 7 - tmpBlade;
0161     } else if (tmpBlade >= 19) {
0162       theBlade = 31 - tmpBlade;
0163     }
0164 
0165     thePlaquette = cmssw_numbering.module();
0166 
0167   }  // end phase1
0168 
0169   if (side == 1 && outer)
0170     thePart = mO;
0171   else if (side == 1 && !outer)
0172     thePart = mI;
0173   else if (side == 2 && outer)
0174     thePart = pO;
0175   else if (side == 2 && !outer)
0176     thePart = pI;
0177 }
0178 
0179 // constructor from name string
0180 PixelEndcapName::PixelEndcapName(std::string name, bool phase)
0181     : PixelModuleName(false), thePart(mO), theDisk(0), theBlade(0), thePannel(0), thePlaquette(0), phase1(phase) {
0182   // parse the name string
0183   // first, check to make sure this is an FPix name, should start with "FPix_"
0184   // also check to make sure the needed parts are present
0185   if ((name.substr(0, 5) != "FPix_") || (name.find("_B") == string::npos) || (name.find("_D") == string::npos) ||
0186       (name.find("_BLD") == string::npos) || (name.find("_PNL") == string::npos) ||
0187       ((phase1 && name.find("_RNG") == string::npos)) || ((!phase1 && name.find("_PLQ") == string::npos))) {
0188     edm::LogError("BadNameString|SiPixel")
0189         << "Bad name string in PixelEndcapName::PixelEndcapName(std::string): " << name;
0190     return;
0191   }
0192 
0193   // strip off ROC part if it's there
0194   if (name.find("_ROC") != string::npos)
0195     name = name.substr(0, name.find("_ROC"));
0196 
0197   // get the half cylinder
0198   string hcString = name.substr(name.find("_B") + 2, name.find("_D") - name.find("_B") - 2);
0199   if (hcString == "mO")
0200     thePart = mO;
0201   else if (hcString == "mI")
0202     thePart = mI;
0203   else if (hcString == "pO")
0204     thePart = pO;
0205   else if (hcString == "pI")
0206     thePart = pI;
0207   else {
0208     edm::LogError("BadNameString|SiPixel")
0209         << "Unable to determine half cylinder in PixelEndcapName::PixelEndcapName(std::string): " << name;
0210   }
0211 
0212   // get the disk
0213   string diskString = name.substr(name.find("_D") + 2, name.find("_BLD") - name.find("_D") - 2);
0214   if (diskString == "1")
0215     theDisk = 1;
0216   else if (diskString == "2")
0217     theDisk = 2;
0218   else if (diskString == "3")
0219     theDisk = 3;
0220   else {
0221     edm::LogError("BadNameString|SiPixel")
0222         << "Unable to determine disk number in PixelEndcapName::PixelEndcapName(std::string): " << name;
0223   }
0224 
0225   // get the blade
0226   string bladeString = name.substr(name.find("_BLD") + 4, name.find("_PNL") - name.find("_BLD") - 4);
0227   // since atoi() doesn't report errors, do it the long way
0228   if (bladeString == "1")
0229     theBlade = 1;
0230   else if (bladeString == "2")
0231     theBlade = 2;
0232   else if (bladeString == "3")
0233     theBlade = 3;
0234   else if (bladeString == "4")
0235     theBlade = 4;
0236   else if (bladeString == "5")
0237     theBlade = 5;
0238   else if (bladeString == "6")
0239     theBlade = 6;
0240   else if (bladeString == "7")
0241     theBlade = 7;
0242   else if (bladeString == "8")
0243     theBlade = 8;
0244   else if (bladeString == "9")
0245     theBlade = 9;
0246   else if (bladeString == "10")
0247     theBlade = 10;
0248   else if (bladeString == "11")
0249     theBlade = 11;
0250   else if (bladeString == "12")
0251     theBlade = 12;
0252   else if (bladeString == "13")
0253     theBlade = 13;
0254   else if (bladeString == "14")
0255     theBlade = 14;
0256   else if (bladeString == "15")
0257     theBlade = 15;
0258   else if (bladeString == "16")
0259     theBlade = 16;
0260   else if (bladeString == "17")
0261     theBlade = 17;
0262   else {
0263     edm::LogError("BadNameString|SiPixel")
0264         << "Unable to determine blade number in PixelEndcapName::PixelEndcapName(std::string): " << name;
0265   }
0266 
0267   // find the panel
0268   string panelString;
0269   if (phase1)
0270     panelString = name.substr(name.find("_PNL") + 4, name.find("_RNG") - name.find("_PNL") - 4);
0271   else
0272     panelString = name.substr(name.find("_PNL") + 4, name.find("_PLQ") - name.find("_PNL") - 4);
0273 
0274   if (panelString == "1")
0275     thePannel = 1;
0276   else if (panelString == "2")
0277     thePannel = 2;
0278   else {
0279     edm::LogError("BadNameString|SiPixel")
0280         << "Unable to determine panel number in PixelEndcapName::PixelEndcapName(std::string): " << name;
0281   }
0282 
0283   // find the plaquette, for phase 1 this is the rung number
0284   if (phase1) {  // phase1
0285 
0286     string ringString = name.substr(name.find("_RNG") + 4, name.size() - name.find("_RNG") - 4);
0287     if (ringString == "1")
0288       thePlaquette = 1;  // code ring in the plaquette
0289     else if (ringString == "2")
0290       thePlaquette = 2;
0291     else {
0292       edm::LogError("BadNameString|SiPixel")
0293           << "Unable to determine ring number in PixelEndcapName::PixelEndcapName(std::string): " << name;
0294     }
0295 
0296   } else {  // phase 0
0297 
0298     // find the plaquette
0299     string plaquetteString = name.substr(name.find("_PLQ") + 4, name.size() - name.find("_PLQ") - 4);
0300     if (plaquetteString == "1")
0301       thePlaquette = 1;
0302     else if (plaquetteString == "2")
0303       thePlaquette = 2;
0304     else if (plaquetteString == "3")
0305       thePlaquette = 3;
0306     else if (plaquetteString == "4")
0307       thePlaquette = 4;
0308     else {
0309       edm::LogError("BadNameString|SiPixel")
0310           << "Unable to determine plaquette number in PixelEndcapName::PixelEndcapName(std::string): " << name;
0311     }
0312 
0313   }  // end phase1
0314 
0315 }  // PixelEndcapName::PixelEndcapName(std::string name)
0316 
0317 PixelModuleName::ModuleType PixelEndcapName::moduleType() const {
0318   ModuleType type = v1x2;
0319 
0320   if (phase1) {  // phase1
0321 
0322     type = v2x8;
0323 
0324   } else {  // phase 0
0325 
0326     if (pannelName() == 1) {
0327       if (plaquetteName() == 1) {
0328         type = v1x2;
0329       } else if (plaquetteName() == 2) {
0330         type = v2x3;
0331       } else if (plaquetteName() == 3) {
0332         type = v2x4;
0333       } else if (plaquetteName() == 4) {
0334         type = v1x5;
0335       }
0336     } else {
0337       if (plaquetteName() == 1) {
0338         type = v2x3;
0339       } else if (plaquetteName() == 2) {
0340         type = v2x4;
0341       } else if (plaquetteName() == 3) {
0342         type = v2x5;
0343       }
0344     }
0345 
0346     // hack for the pilot blade
0347     if (pilot_blade && theDisk == 3) {
0348       type = v2x8;
0349     }  // do only for disk 3
0350 
0351   }  // end phase1
0352 
0353   return type;
0354 }
0355 
0356 bool PixelEndcapName::operator==(const PixelModuleName& o) const {
0357   if (!o.isBarrel()) {
0358     const PixelEndcapName* other = dynamic_cast<const PixelEndcapName*>(&o);
0359     return (other && thePart == other->thePart && theDisk == other->theDisk && theBlade == other->theBlade &&
0360             thePannel == other->thePannel && thePlaquette == other->thePlaquette);
0361   } else
0362     return false;
0363 }
0364 
0365 string PixelEndcapName::name() const {
0366   std::ostringstream stm;
0367 
0368   if (phase1)
0369     stm << "FPix_B" << thePart << "_D" << theDisk << "_BLD" << theBlade << "_PNL" << thePannel << "_RNG"
0370         << thePlaquette;
0371   else
0372     stm << "FPix_B" << thePart << "_D" << theDisk << "_BLD" << theBlade << "_PNL" << thePannel << "_PLQ"
0373         << thePlaquette;
0374 
0375   return stm.str();
0376 }
0377 
0378 std::ostream& operator<<(std::ostream& out, const PixelEndcapName::HalfCylinder& t) {
0379   switch (t) {
0380     case (PixelEndcapName::pI): {
0381       out << "pI";
0382       break;
0383     }
0384     case (PixelEndcapName::pO): {
0385       out << "pO";
0386       break;
0387     }
0388     case (PixelEndcapName::mI): {
0389       out << "mI";
0390       break;
0391     }
0392     case (PixelEndcapName::mO): {
0393       out << "mO";
0394       break;
0395     }
0396     default:
0397       out << "unknown";
0398   };
0399   return out;
0400 }
0401 
0402 // return the DetId
0403 DetId PixelEndcapName::getDetId(const TrackerTopology* tt) {
0404   uint32_t side = 0;
0405   uint32_t disk = 0;
0406   uint32_t blade = 0;
0407   uint32_t panel = 0;
0408   uint32_t module = 0;
0409 
0410   // figure out the side
0411   HalfCylinder hc = halfCylinder();
0412   if (hc == mO || hc == mI)
0413     side = 1;
0414   else if (hc == pO || hc == pI)
0415     side = 2;
0416 
0417   // get disk/blade/panel/module numbers from PixelEndcapName object
0418   disk = static_cast<uint32_t>(diskName());
0419   uint32_t tmpBlade = static_cast<uint32_t>(bladeName());
0420   panel = static_cast<uint32_t>(pannelName());
0421 
0422   // convert blade numbering to cmssw convention
0423   bool outer = false;
0424   outer = (hc == mO) || (hc == pO);
0425 
0426   if (phase1) {  // phase1
0427 
0428     module = 1;
0429     int ring = static_cast<uint32_t>(ringName());  // this is ring for phase1
0430     if (ring == 1) {                               // ring 1, lower radius
0431       if (outer) {
0432         if (tmpBlade >= 1 && tmpBlade <= 11)
0433           blade = tmpBlade + 6;
0434       } else {  //inner
0435         if (tmpBlade <= 6)
0436           blade = 7 - tmpBlade;
0437         else
0438           blade = 29 - tmpBlade;
0439       }
0440 
0441     } else if (ring == 2) {  //ring 2, upper radius
0442       if (outer) {
0443         if (tmpBlade >= 1 && tmpBlade <= 17)
0444           blade = tmpBlade + 31;
0445       } else {  //inner
0446         if (tmpBlade <= 9)
0447           blade = 32 - tmpBlade;
0448         else
0449           blade = 66 - tmpBlade;
0450       }
0451     }
0452 
0453   } else {  // phase 0
0454 
0455     if (outer) {
0456       blade = tmpBlade + 6;
0457     } else {  // inner
0458       if (tmpBlade <= 6)
0459         blade = 7 - tmpBlade;
0460       else if (tmpBlade <= 12)
0461         blade = 31 - tmpBlade;
0462     }
0463 
0464     // hack for the pilot blade
0465     if (pilot_blade && theDisk == 3) {  // do only for disk 3
0466       //cout<<tmpBlade<<" "<<blade<<endl;
0467       if (blade <= 5)
0468         blade -= 3;
0469       else
0470         blade -= 13;
0471       //cout<<tmpBlade<<" "<<blade<<endl;
0472     }
0473 
0474     module = static_cast<uint32_t>(plaquetteName());
0475   }  // end phase1
0476 
0477   // create and return the DetId
0478   DetId id = tt->pxfDetId(side, disk, blade, panel, module);
0479 
0480   return id;
0481 
0482 }  // PXFDetId PixelEndcapName::getDetId()
0483 
0484 // return the DetId
0485 PXFDetId PixelEndcapName::getDetId() {
0486   uint32_t side = 0;
0487   uint32_t disk = 0;
0488   uint32_t blade = 0;
0489   uint32_t panel = 0;
0490   uint32_t module = 0;
0491 
0492   // figure out the side
0493   HalfCylinder hc = halfCylinder();
0494   if (hc == mO || hc == mI)
0495     side = 1;
0496   else if (hc == pO || hc == pI)
0497     side = 2;
0498 
0499   // get disk/blade/panel/module numbers from PixelEndcapName object
0500   disk = static_cast<uint32_t>(diskName());
0501   uint32_t tmpBlade = static_cast<uint32_t>(bladeName());
0502   panel = static_cast<uint32_t>(pannelName());
0503 
0504   // convert blade numbering to cmssw convention
0505   bool outer = false;
0506   outer = (hc == mO) || (hc == pO);
0507 
0508   if (phase1) {  // phase1
0509 
0510     module = 1;                                    // for phase 1 always 1,
0511     int ring = static_cast<uint32_t>(ringName());  // this is ring for phase1
0512     if (ring == 1) {                               // ring 1, lower radius
0513       if (outer) {
0514         if (tmpBlade >= 1 && tmpBlade <= 11)
0515           blade = tmpBlade + 6;
0516       } else {  //inner
0517         if (tmpBlade <= 6)
0518           blade = 7 - tmpBlade;
0519         else
0520           blade = 29 - tmpBlade;
0521       }
0522 
0523     } else if (ring == 2) {  //ring 2, upper radius
0524       if (outer) {
0525         if (tmpBlade >= 1 && tmpBlade <= 17)
0526           blade = tmpBlade + 31;
0527       } else {  //inner
0528         if (tmpBlade <= 9)
0529           blade = 32 - tmpBlade;
0530         else
0531           blade = 66 - tmpBlade;
0532       }
0533     }
0534 
0535   } else {  // phase 0
0536 
0537     if (outer) {
0538       blade = tmpBlade + 6;
0539     } else {  // inner
0540       if (tmpBlade <= 6)
0541         blade = 7 - tmpBlade;
0542       else if (tmpBlade <= 12)
0543         blade = 31 - tmpBlade;
0544     }
0545 
0546     // hack for the pilot blade
0547     if (pilot_blade && theDisk == 3) {  // do only for disk 3
0548       //cout<<tmpBlade<<" "<<blade<<endl;
0549       if (blade <= 5)
0550         blade -= 3;
0551       else
0552         blade -= 13;
0553       //cout<<tmpBlade<<" "<<blade<<endl;
0554     }
0555 
0556     module = static_cast<uint32_t>(plaquetteName());
0557   }  // end phase1
0558 
0559   // create and return the DetId
0560   return PXFDetId(side, disk, blade, panel, module);
0561 
0562 }  // PXFDetId PixelEndcapName::getDetId()