Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/SiPixelDetId/interface/PixelBarrelNameUpgrade.h"
0002 
0003 #include <sstream>
0004 #include <iostream>
0005 
0006 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 
0009 using namespace std;
0010 
0011 PixelBarrelNameUpgrade::PixelBarrelNameUpgrade(const DetId& id) : PixelModuleName(true) {
0012   //  uint32_t rawId = id.rawId();
0013   PXBDetId cmssw_numbering(id);
0014 
0015   theLayer = cmssw_numbering.layer();
0016 
0017   int oldModule = cmssw_numbering.module() - 4;
0018   if (oldModule <= 0)
0019     oldModule--;  // -4, ..., -1, +1, ...,+4
0020 
0021   int oldLadder = cmssw_numbering.ladder();
0022 
0023   if (theLayer == 1) {
0024     if (oldLadder <= 3)
0025       oldLadder = 4 - oldLadder;  // +1, ..., +3
0026     else if (oldLadder >= 4 && oldLadder <= 9)
0027       oldLadder = 3 - oldLadder;  // -1, ..., -6
0028     else if (oldLadder >= 10)
0029       oldLadder = 16 - oldLadder;  // +6, ..., +4
0030   } else if (theLayer == 2) {
0031     if (oldLadder <= 7)
0032       oldLadder = 8 - oldLadder;
0033     else if (oldLadder >= 8 && oldLadder <= 21)
0034       oldLadder = 7 - oldLadder;
0035     else if (oldLadder >= 22)
0036       oldLadder = 36 - oldLadder;
0037   } else if (theLayer == 3) {
0038     if (oldLadder <= 11)
0039       oldLadder = 12 - oldLadder;
0040     else if (oldLadder >= 12 && oldLadder <= 33)
0041       oldLadder = 11 - oldLadder;
0042     else if (oldLadder >= 34)
0043       oldLadder = 56 - oldLadder;
0044   } else if (theLayer == 4) {
0045     if (oldLadder <= 16)
0046       oldLadder = 17 - oldLadder;
0047     else if (oldLadder >= 17 && oldLadder <= 48)
0048       oldLadder = 16 - oldLadder;
0049     else if (oldLadder >= 49)
0050       oldLadder = 81 - oldLadder;
0051   }
0052 
0053   //
0054   // part
0055   //
0056   if (oldModule < 0 && oldLadder < 0)
0057     thePart = mO;
0058   else if (oldModule > 0 && oldLadder < 0)
0059     thePart = pO;
0060   else if (oldModule < 0 && oldLadder > 0)
0061     thePart = mI;
0062   else if (oldModule > 0 && oldLadder > 0)
0063     thePart = pI;
0064   //std::cout << "(oldModule, oldLadder)============(" << oldModule << ", "<< oldLadder<<" )" << std::endl;
0065 
0066   //
0067   // ladder
0068   //
0069   theLadder = abs(oldLadder);
0070 
0071   //
0072   // module
0073   //
0074   theModule = abs(oldModule);
0075 }
0076 
0077 // constructor from name string
0078 PixelBarrelNameUpgrade::PixelBarrelNameUpgrade(std::string name)
0079     : PixelModuleName(true), thePart(mO), theLayer(0), theModule(0), theLadder(0) {
0080   std::cout << "NAME=" << name << std::endl;
0081   // parse the name string
0082   // first, check to make sure this is an BPix name, should start with "BPix_"
0083   // also check to make sure the needed parts are present
0084   if ((name.substr(0, 5) != "BPix_") || (name.find("_B") == string::npos) || (name.find("_LYR") == string::npos) ||
0085       (name.find("_LDR") == string::npos) || (name.find("_MOD") == string::npos)) {
0086     edm::LogError("BadNameString|SiPixel")
0087         << "Bad name string in PixelBarrelNameUpgrade::PixelBarrelName(std::string): " << name;
0088     return;
0089   }
0090 
0091   // strip off ROC part if it's there
0092   if (name.find("_ROC") != string::npos)
0093     name = name.substr(0, name.find("_ROC"));
0094 
0095   // find shell
0096   string shellString = name.substr(name.find("_B") + 2, name.find("_SEC") - name.find("_B") - 2);
0097   if (shellString == "mO")
0098     thePart = mO;
0099   else if (shellString == "mI")
0100     thePart = mI;
0101   else if (shellString == "pO")
0102     thePart = pO;
0103   else if (shellString == "pI")
0104     thePart = pI;
0105   else {
0106     edm::LogError("BadNameString|SiPixel")
0107         << "Unable to determine shell in PixelBarrelNameUpgrade::PixelBarrelName(std::string): " << name;
0108   }
0109 
0110   // find the layer
0111   string layerString = name.substr(name.find("_LYR") + 4, name.find("_LDR") - name.find("_LYR") - 4);
0112   if (layerString == "1")
0113     theLayer = 1;
0114   else if (layerString == "2")
0115     theLayer = 2;
0116   else if (layerString == "3")
0117     theLayer = 3;
0118   else if (layerString == "4")
0119     theLayer = 4;
0120   else {
0121     edm::LogError("BadNameString|SiPixel")
0122         << "Unable to determine layer in PixelBarrelNameUpgrade::PixelBarrelName(std::string): " << name;
0123   }
0124 
0125   // find the ladder
0126   string ladderString = name.substr(name.find("_LDR") + 4, name.find("_MOD") - name.find("_LDR") - 4);
0127   if (ladderString.substr(ladderString.size() - 1, 1) == "F") {
0128     int ladderNum = atoi(ladderString.substr(0, ladderString.size() - 1).c_str());
0129     if (theLayer == 1 && ladderNum >= 1 && ladderNum <= 6)
0130       theLadder = ladderNum;
0131     else if (theLayer == 2 && ladderNum >= 1 && ladderNum <= 14)
0132       theLadder = ladderNum;
0133     else if (theLayer == 3 && ladderNum >= 1 && ladderNum <= 22)
0134       theLadder = ladderNum;
0135     else if (theLayer == 4 && ladderNum >= 1 && ladderNum <= 32)
0136       theLadder = ladderNum;
0137     else {
0138       edm::LogError("BadNameString|SiPixel")
0139           << "Unable to determine ladder in PixelBarrelNameUpgrade::PixelBarrelName(std::string): " << name;
0140     }
0141   }  // full ladders
0142   else {
0143     edm::LogError("BadNameString|SiPixel")
0144         << "Unable to determine ladder in PixelBarrelNameUpgrade::PixelBarrelName(std::string): " << name;
0145   }
0146 
0147   // find the module
0148   string moduleString = name.substr(name.find("_MOD") + 4, name.size() - name.find("_MOD") - 4);
0149   if (moduleString == "1")
0150     theModule = 1;
0151   else if (moduleString == "2")
0152     theModule = 2;
0153   else if (moduleString == "3")
0154     theModule = 3;
0155   else if (moduleString == "4")
0156     theModule = 4;
0157   else {
0158     edm::LogError("BadNameString|SiPixel")
0159         << "Unable to determine module in PixelBarrelNameUpgrade::PixelBarrelName(std::string): " << name;
0160   }
0161 
0162 }  // PixelBarrelNameUpgrade::PixelBarrelName(std::string name)
0163 
0164 int PixelBarrelNameUpgrade::sectorName() const {
0165   int sector = 0;
0166   if (theLayer == 1) {
0167     switch (theLadder) {
0168       case 1: {
0169         sector = 1;
0170         break;
0171       }
0172       case 2: {
0173         sector = 2;
0174         break;
0175       }
0176       case 3: {
0177         sector = 3;
0178         break;
0179       }
0180       case 4: {
0181         sector = 6;
0182         break;
0183       }
0184       case 5: {
0185         sector = 7;
0186         break;
0187       }
0188       case 6: {
0189         sector = 8;
0190         break;
0191       }
0192       default:;
0193     };
0194   } else if (theLayer == 2) {
0195     switch (theLadder) {
0196       case 1:
0197       case 2: {
0198         sector = 1;
0199         break;
0200       }
0201       case 3:
0202       case 4: {
0203         sector = 2;
0204         break;
0205       }
0206       case 5:
0207       case 6: {
0208         sector = 3;
0209         break;
0210       }
0211       case 7: {
0212         sector = 4;
0213         break;
0214       }
0215       case 8: {
0216         sector = 5;
0217         break;
0218       }
0219       case 9:
0220       case 10: {
0221         sector = 6;
0222         break;
0223       }
0224       case 11:
0225       case 12: {
0226         sector = 7;
0227         break;
0228       }
0229       case 13:
0230       case 14: {
0231         sector = 8;
0232         break;
0233       }
0234       default:;
0235     };
0236   } else if (theLayer == 3) {
0237     switch (theLadder) {
0238       case 1:
0239       case 2:
0240       case 3: {
0241         sector = 1;
0242         break;
0243       }
0244       case 4:
0245       case 5:
0246       case 6: {
0247         sector = 2;
0248         break;
0249       }
0250       case 7:
0251       case 8:
0252       case 9: {
0253         sector = 3;
0254         break;
0255       }
0256       case 10:
0257       case 11: {
0258         sector = 4;
0259         break;
0260       }
0261       case 12:
0262       case 13: {
0263         sector = 5;
0264         break;
0265       }
0266       case 14:
0267       case 15:
0268       case 16: {
0269         sector = 6;
0270         break;
0271       }
0272       case 17:
0273       case 18:
0274       case 19: {
0275         sector = 7;
0276         break;
0277       }
0278       case 20:
0279       case 21:
0280       case 22: {
0281         sector = 8;
0282         break;
0283       }
0284       default:;
0285     };
0286   } else if (theLayer == 4) {
0287     switch (theLadder) {
0288       case 1:
0289       case 2:
0290       case 3:
0291       case 4: {
0292         sector = 1;
0293         break;
0294       }
0295       case 5:
0296       case 6:
0297       case 7:
0298       case 8: {
0299         sector = 2;
0300         break;
0301       }
0302       case 9:
0303       case 10:
0304       case 11:
0305       case 12: {
0306         sector = 3;
0307         break;
0308       }
0309       case 13:
0310       case 14:
0311       case 15:
0312       case 16: {
0313         sector = 4;
0314         break;
0315       }
0316       case 17:
0317       case 18:
0318       case 19:
0319       case 20: {
0320         sector = 5;
0321         break;
0322       }
0323       case 21:
0324       case 22:
0325       case 23:
0326       case 24: {
0327         sector = 6;
0328         break;
0329       }
0330       case 25:
0331       case 26:
0332       case 27:
0333       case 28: {
0334         sector = 7;
0335         break;
0336       }
0337       case 29:
0338       case 30:
0339       case 31:
0340       case 32: {
0341         sector = 8;
0342         break;
0343       }
0344       default:;
0345     };
0346   }
0347 
0348   return sector;
0349 }
0350 
0351 //---- this needs to be removed --------------------------------
0352 //---- there is no half module in the upgraded geometry!!! -----
0353 bool PixelBarrelNameUpgrade::isHalfModule() const {
0354   bool halfModule = false;
0355   //  if (theLadder == 1) halfModule = true;
0356   //  if (theLayer == 1 && theLadder == 10) halfModule = true;
0357   //  if (theLayer == 2 && theLadder == 16) halfModule = true;
0358   //  if (theLayer == 3 && theLadder == 22) halfModule = true;
0359   return halfModule;
0360 }
0361 
0362 PixelModuleName::ModuleType PixelBarrelNameUpgrade::moduleType() const {
0363   return isHalfModule() ? PixelBarrelNameUpgrade::v1x8 : PixelBarrelNameUpgrade::v2x8;
0364 }
0365 
0366 bool PixelBarrelNameUpgrade::operator==(const PixelModuleName& o) const {
0367   if (o.isBarrel()) {
0368     const PixelBarrelNameUpgrade* other = dynamic_cast<const PixelBarrelNameUpgrade*>(&o);
0369     return (other && thePart == other->thePart && theLayer == other->theLayer && theModule == other->theModule &&
0370             theLadder == other->theLadder);
0371   } else
0372     return false;
0373 }
0374 
0375 string PixelBarrelNameUpgrade::name() const {
0376   std::ostringstream stm;
0377 
0378   stm << "BPix_B" << thePart << "_SEC" << sectorName() << "_LYR" << theLayer << "_LDR" << theLadder;
0379   stm << "F";
0380   stm << "_MOD" << theModule;
0381 
0382   return stm.str();
0383 }
0384 /*
0385 string PixelBarrelNameUpgrade::name() const 
0386 {
0387    std::ostringstream stm;
0388    
0389    stm<<"BPix_B"<<thePart<<"_SEC"<<sectorName()<<"_LYR"<<theLayer<<"_LDR"<<theLadder;
0390    if ( isHalfModule() ) stm <<"H"; else stm <<"F";
0391    stm << "_MOD" << theModule;
0392 
0393    return stm.str();
0394 }
0395 */
0396 
0397 // return the DetId
0398 PXBDetId PixelBarrelNameUpgrade::getDetId() {
0399   uint32_t layer = 0;
0400   uint32_t ladder = 0;
0401   uint32_t module = 0;
0402 
0403   layer = layerName();
0404   uint32_t tmpLadder = ladderName();
0405   uint32_t tmpModule = moduleName();
0406 
0407   // translate the ladder number from the naming convention to the cmssw convention
0408   bool outer = false;
0409   Shell shell = thePart;
0410   outer = (shell == mO) || (shell == pO);
0411   if (outer) {
0412     if (layer == 1)
0413       ladder = tmpLadder + 3;
0414     else if (layer == 2)
0415       ladder = tmpLadder + 7;
0416     else if (layer == 3)
0417       ladder = tmpLadder + 11;
0418     else if (layer == 4)
0419       ladder = tmpLadder + 16;
0420   }       // outer
0421   else {  // inner
0422     if (layer == 1) {
0423       if (tmpLadder <= 3)
0424         ladder = 4 - tmpLadder;
0425       else if (tmpLadder <= 6)
0426         ladder = 16 - tmpLadder;
0427     }  // layer 1
0428     else if (layer == 2) {
0429       if (tmpLadder <= 7)
0430         ladder = 8 - tmpLadder;
0431       else if (tmpLadder <= 14)
0432         ladder = 36 - tmpLadder;
0433     }  // layer 2
0434     else if (layer == 3) {
0435       if (tmpLadder <= 11)
0436         ladder = 12 - tmpLadder;
0437       else if (tmpLadder <= 22)
0438         ladder = 56 - tmpLadder;
0439     }  // layer 3
0440     else if (layer == 4) {
0441       if (tmpLadder <= 16)
0442         ladder = 17 - tmpLadder;
0443       else if (tmpLadder <= 32)
0444         ladder = 81 - tmpLadder;
0445     }  // layer 4
0446   }    // inner
0447 
0448   // translate the module number from naming convention to cmssw convention
0449   // numbering starts at positive z
0450   if (shell == pO || shell == pI)
0451     module = tmpModule + 4;
0452   else  // negative z side
0453     module = 5 - tmpModule;
0454 
0455   return PXBDetId(layer, ladder, module);
0456 
0457 }  // PXBDetId PixelBarrelNameUpgrade::getDetId()
0458 
0459 std::ostream& operator<<(std::ostream& out, const PixelBarrelNameUpgrade::Shell& t) {
0460   switch (t) {
0461     case (PixelBarrelNameUpgrade::pI): {
0462       out << "pI";
0463       break;
0464     }
0465     case (PixelBarrelNameUpgrade::pO): {
0466       out << "pO";
0467       break;
0468     }
0469     case (PixelBarrelNameUpgrade::mI): {
0470       out << "mI";
0471       break;
0472     }
0473     case (PixelBarrelNameUpgrade::mO): {
0474       out << "mO";
0475       break;
0476     }
0477     default:
0478       out << "unknown";
0479   };
0480   return out;
0481 }