Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-23 23:00:35

0001 ////////////////////////////////////////////////////////////////////////////////
0002 // File: EcalPreshowerNumberingScheme.cc
0003 // Description: Numbering scheme for preshower detector
0004 ///////////////////////////////////////////////////////////////////////////////
0005 
0006 #include "Geometry/EcalCommonData/interface/EcalPreshowerNumberingScheme.h"
0007 #include "DataFormats/EcalDetId/interface/ESDetId.h"
0008 #include <sstream>
0009 
0010 //#define EDM_ML_DEBUG
0011 
0012 EcalPreshowerNumberingScheme::EcalPreshowerNumberingScheme() : EcalNumberingScheme() {
0013   // For SFLX2a, we use copy# 1-3
0014   int vL2ax[3] = {4, 6, 10};
0015   int vL2ay[3] = {29, 31, 35};
0016   // For SFLX2b, we use copy# 1
0017   int vL2bx[1] = {2};
0018   int vL2by[1] = {25};
0019   // For SFLX3a, we use copy# 4-6
0020   int vL3ax[3] = {30, 34, 36};
0021   int vL3ay[3] = {35, 31, 29};
0022   // For SFLX3b, we use copy# 2
0023   int vL3bx[1] = {38};
0024   int vL3by[1] = {25};
0025   // For SFLX1a, we use odd number in copy# 1-52
0026   int vL1ax[26] = {2, 4, 4, 8, 8, 8, 8, 10, 12, 12, 14, 14, 20, 20, 26, 26, 28, 28, 30, 32, 32, 32, 32, 36, 36, 38};
0027   int vL1ay[26] = {21, 25, 21, 33, 29, 25, 21, 21, 25, 21, 31, 27, 32,
0028                    28, 31, 27, 25, 21, 21, 33, 29, 25, 21, 25, 21, 21};
0029   // For SFLX1b, we use copy# 2
0030   int vL1bx[1] = {22};
0031   int vL1by[1] = {27};
0032   // For SFLX1c, we use copy# 1
0033   int vL1cx[1] = {18};
0034   int vL1cy[1] = {27};
0035   // For SFLX1d, we use copy# 2
0036   int vL1dx[1] = {26};
0037   int vL1dy[1] = {23};
0038   // For SFLX1e, we use copy# 1
0039   int vL1ex[1] = {14};
0040   int vL1ey[1] = {23};
0041   // For SFLX0a, we use odd number if copy# 1-46
0042   int vL0ax[23] = {6, 6, 10, 10, 12, 12, 14, 16, 16, 18, 18, 20, 22, 22, 24, 24, 26, 28, 28, 30, 30, 34, 34};
0043   int vL0ay[23] = {26, 21, 30, 25, 34, 29, 35, 36, 31, 36, 31, 36, 36, 31, 36, 31, 35, 34, 29, 30, 25, 26, 21};
0044   // For SFL0b, we use copy# 2
0045   int vL0bx[1] = {24};
0046   int vL0by[1] = {26};
0047   // For SFL0c, we use copy# 1
0048   int vL0cx[1] = {16};
0049   int vL0cy[1] = {26};
0050 
0051   for (int i = 0; i < 1; ++i) {
0052     L1bx[i] = vL1bx[i];
0053     L1by[i] = vL1by[i];
0054     L1cx[i] = vL1cx[i];
0055     L1cy[i] = vL1cy[i];
0056     L1dx[i] = vL1dx[i];
0057     L1dy[i] = vL1dy[i];
0058     L1ex[i] = vL1ex[i];
0059     L1ey[i] = vL1ey[i];
0060     L0bx[i] = vL0bx[i];
0061     L0by[i] = vL0by[i];
0062     L0cx[i] = vL0cx[i];
0063     L0cy[i] = vL0cy[i];
0064     L3bx[i] = vL3bx[i];
0065     L3by[i] = vL3by[i];
0066     L2bx[i] = vL2bx[i];
0067     L2by[i] = vL2by[i];
0068   }
0069 
0070   for (int i = 0; i < 3; ++i) {
0071     L3ax[i] = vL3ax[i];
0072     L3ay[i] = vL3ay[i];
0073     L2ax[i] = vL2ax[i];
0074     L2ay[i] = vL2ay[i];
0075   }
0076 
0077   for (int i = 0; i < 23; ++i) {
0078     L0ax[i] = vL0ax[i];
0079     L0ay[i] = vL0ay[i];
0080   }
0081 
0082   for (int i = 0; i < 26; ++i) {
0083     L1ax[i] = vL1ax[i];
0084     L1ay[i] = vL1ay[i];
0085   }
0086 
0087   edm::LogVerbatim("EcalGeom") << "Creating EcalPreshowerNumberingScheme";
0088 }
0089 
0090 EcalPreshowerNumberingScheme::~EcalPreshowerNumberingScheme() {
0091   edm::LogVerbatim("EcalGeom") << "Deleting EcalPreshowerNumberingScheme";
0092 }
0093 
0094 /*
0095  * Compute the Ecal Preshower DetId.
0096  * General NB: if possible, it would be way better to just access the DetID from a hash map from G4 Volume, 
0097  * rather than recomputing it for each SimHit - see Tracker.
0098  */
0099 uint32_t EcalPreshowerNumberingScheme::getUnitID(const EcalBaseNumber& baseNumber) const {
0100   const int numberOfHierarchyLevels = baseNumber.getLevels();
0101   bool dd4hep = ((numberOfHierarchyLevels == 10) && (baseNumber.getCopyNumber(numberOfHierarchyLevels - 1) == 1) &&
0102                  (baseNumber.getLevelName(numberOfHierarchyLevels - 1) != "OCMS"));
0103 #ifdef EDM_ML_DEBUG
0104   std::ostringstream st1;
0105   for (int k = 0; k < numberOfHierarchyLevels; ++k)
0106     st1 << ", " << baseNumber.getLevelName(k) << ":" << baseNumber.getCopyNumber(k);
0107   edm::LogVerbatim("EcalGeom") << "EcalPreshowerNumberingScheme: dd4hep " << dd4hep
0108                                << " witg  geometry levels = " << numberOfHierarchyLevels << st1.str();
0109 #endif
0110   uint32_t intIndex = 0;
0111   if (numberOfHierarchyLevels > 0) {
0112     // depth index - silicon layer 1-st or 2-nd
0113     int layer = 0;
0114     if (baseNumber.getLevelName(0).find("SFSX") != std::string::npos) {
0115       layer = 1;
0116     } else if (baseNumber.getLevelName(0).find("SFSY") != std::string::npos) {
0117       layer = 2;
0118     } else {
0119       edm::LogWarning("EcalGeom") << "EcalPreshowerNumberingScheme: Wrong name"
0120                                   << " of Presh. Si. Strip : " << baseNumber.getLevelName(0);
0121     }
0122 
0123     // Z index +Z = 1 ; -Z = 2
0124 
0125     int zs = dd4hep ? baseNumber.getCopyNumber(4) : baseNumber.getCopyNumber(5);
0126     int zside = 2 * (1 - zs) + 1;
0127 
0128     // box numer and ladder copy number
0129     int box(0), ladd_copy(0);
0130     std::string ladd("");
0131     if (dd4hep) {
0132       auto num1 = numbers(baseNumber.getLevelName(2));
0133       box = num1.second;
0134       ladd_copy = num1.first;
0135       ladd = baseNumber.getLevelName(2).substr(0, 6);
0136     } else {
0137       box = baseNumber.getCopyNumber(2);
0138       ladd_copy = baseNumber.getCopyNumber(3);
0139       ladd = baseNumber.getLevelName(3).substr(0, 6);
0140     }
0141 #ifdef EDM_ML_DEBUG
0142     edm::LogVerbatim("EcalGeom") << "EcalPreshowerNumberingScheme::Box " << box << " Ladder " << ladd << ":"
0143                                  << ladd_copy;
0144 #endif
0145 
0146     int x = 0, y = 0, ix, iy, id;
0147     int mapX[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0148     int mapY[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0149 
0150     if (ladd == "SFLX0a" || ladd == "SFLY0a") {
0151       mapX[5] = mapX[6] = mapX[7] = mapX[8] = mapX[9] = 1;
0152       mapY[0] = 0;
0153       mapY[1] = 1;
0154       mapY[2] = 2;
0155       mapY[3] = 3;
0156       mapY[4] = 4;
0157       mapY[5] = 0;
0158       mapY[6] = 1;
0159       mapY[7] = 2;
0160       mapY[8] = 3;
0161       mapY[9] = 4;
0162 
0163       id = (int)((float)ladd_copy / 2 + 0.5);
0164 
0165       x = L0ax[id - 1] + mapX[box - 1000 - 1];
0166       y = L0ay[id - 1] + mapY[box - 1000 - 1];
0167 
0168       if ((ladd_copy % 2) == 0) {
0169         if (mapX[box - 1000 - 1] == 0)
0170           x += 1;
0171         else if (mapX[box - 1000 - 1] == 1)
0172           x -= 1;
0173         y = 41 - y;
0174       }
0175     }
0176     if (ladd == "SFLX0b" || ladd == "SFLY0b") {
0177       mapX[4] = mapX[5] = mapX[6] = mapX[7] = mapX[8] = 1;
0178       mapY[0] = 1;
0179       mapY[1] = 2;
0180       mapY[2] = 3;
0181       mapY[3] = 4;
0182       mapY[4] = 0;
0183       mapY[5] = 1;
0184       mapY[6] = 2;
0185       mapY[7] = 3;
0186       mapY[8] = 4;
0187       mapY[9] = 0;
0188 
0189       x = L0bx[0] + mapX[box - 2000 - 1];
0190       y = L0by[0] + mapY[box - 2000 - 1];
0191 
0192       if (ladd_copy == 1) {
0193         x = 41 - x;
0194         y = 41 - y;
0195       }
0196     }
0197     if (ladd == "SFLX0c" || ladd == "SFLY0c") {
0198       mapX[5] = mapX[6] = mapX[7] = mapX[8] = 1;
0199       mapY[0] = 0;
0200       mapY[1] = 1;
0201       mapY[2] = 2;
0202       mapY[3] = 3;
0203       mapY[4] = 4;
0204       mapY[5] = 1;
0205       mapY[6] = 2;
0206       mapY[7] = 3;
0207       mapY[8] = 4;
0208       mapY[9] = 0;
0209 
0210       x = L0cx[0] + mapX[box - 3000 - 1];
0211       y = L0cy[0] + mapY[box - 3000 - 1];
0212 
0213       if (ladd_copy == 2) {
0214         x = 41 - x;
0215         y = 41 - y;
0216       }
0217     }
0218     if (ladd == "SFLX1a" || ladd == "SFLY1a") {
0219       mapX[4] = mapX[5] = mapX[6] = mapX[7] = 1;
0220       mapY[0] = 0;
0221       mapY[1] = 1;
0222       mapY[2] = 2;
0223       mapY[3] = 3;
0224       mapY[4] = 0;
0225       mapY[5] = 1;
0226       mapY[6] = 2;
0227       mapY[7] = 3;
0228       mapY[8] = 0;
0229       mapY[9] = 0;
0230 
0231       id = (int)((float)ladd_copy / 2 + 0.5);
0232 
0233       x = L1ax[id - 1] + mapX[box - 4000 - 1];
0234       y = L1ay[id - 1] + mapY[box - 4000 - 1];
0235 
0236       if ((ladd_copy % 2) == 0) {
0237         if (mapX[box - 4000 - 1] == 0)
0238           x += 1;
0239         else if (mapX[box - 4000 - 1] == 1)
0240           x -= 1;
0241         y = 41 - y;
0242       }
0243     }
0244     if (ladd == "SFLX1b" || ladd == "SFLY1b") {
0245       mapX[3] = mapX[4] = mapX[5] = mapX[6] = 1;
0246       mapY[0] = 1;
0247       mapY[1] = 2;
0248       mapY[2] = 3;
0249       mapY[3] = 0;
0250       mapY[4] = 1;
0251       mapY[5] = 2;
0252       mapY[6] = 3;
0253       mapY[7] = 0;
0254       mapY[8] = 0;
0255       mapY[9] = 0;
0256 
0257       x = L1bx[0] + mapX[box - 5000 - 1];
0258       y = L1by[0] + mapY[box - 5000 - 1];
0259 
0260       if (ladd_copy == 1) {
0261         x = 41 - x;
0262         y = 41 - y;
0263       }
0264     }
0265     if (ladd == "SFLX1c" || ladd == "SFLY1c") {
0266       mapX[4] = mapX[5] = mapX[6] = 1;
0267       mapY[0] = 0;
0268       mapY[1] = 1;
0269       mapY[2] = 2;
0270       mapY[3] = 3;
0271       mapY[4] = 1;
0272       mapY[5] = 2;
0273       mapY[6] = 3;
0274       mapY[7] = 0;
0275       mapY[8] = 0;
0276       mapY[9] = 0;
0277 
0278       x = L1cx[0] + mapX[box - 6000 - 1];
0279       y = L1cy[0] + mapY[box - 6000 - 1];
0280 
0281       if (ladd_copy == 2) {
0282         x = 41 - x;
0283         y = 41 - y;
0284       }
0285     }
0286     if (ladd == "SFLX1d" || ladd == "SFLY1d") {
0287       mapX[2] = mapX[3] = mapX[4] = mapX[5] = 1;
0288       mapY[0] = 2;
0289       mapY[1] = 3;
0290       mapY[2] = 0;
0291       mapY[3] = 1;
0292       mapY[4] = 2;
0293       mapY[5] = 3;
0294       mapY[6] = 0;
0295       mapY[7] = 0;
0296       mapY[8] = 0;
0297       mapY[9] = 0;
0298 
0299       x = L1dx[0] + mapX[box - 7000 - 1];
0300       y = L1dy[0] + mapY[box - 7000 - 1];
0301 
0302       if (ladd_copy == 1) {
0303         x = 41 - x;
0304         y = 41 - y;
0305       }
0306     }
0307     if (ladd == "SFLX1e" || ladd == "SFLY1e") {
0308       mapX[4] = mapX[5] = 1;
0309       mapY[0] = 0;
0310       mapY[1] = 1;
0311       mapY[2] = 2;
0312       mapY[3] = 3;
0313       mapY[4] = 2;
0314       mapY[5] = 3;
0315       mapY[6] = 0;
0316       mapY[7] = 0;
0317       mapY[8] = 0;
0318       mapY[9] = 0;
0319 
0320       x = L1ex[0] + mapX[box - 8000 - 1];
0321       y = L1ey[0] + mapY[box - 8000 - 1];
0322 
0323       if (ladd_copy == 2) {
0324         x = 41 - x;
0325         y = 41 - y;
0326       }
0327     }
0328     if (ladd == "SFLX3a" || ladd == "SFLY3a") {
0329       mapX[4] = mapX[5] = mapX[6] = 1;
0330       mapY[0] = 0;
0331       mapY[1] = 1;
0332       mapY[2] = 2;
0333       mapY[3] = 3;
0334       mapY[4] = 0;
0335       mapY[5] = 1;
0336       mapY[6] = 2;
0337       mapY[7] = 0;
0338       mapY[8] = 0;
0339       mapY[9] = 0;
0340 
0341       id = (ladd_copy > 3) ? ladd_copy - 3 : 4 - ladd_copy;
0342 
0343       x = L3ax[id - 1] + mapX[box - 9000 - 1];
0344       y = L3ay[id - 1] + mapY[box - 9000 - 1];
0345 
0346       if (ladd_copy < 4) {
0347         x = 41 - x;
0348         y = 41 - y;
0349       }
0350     }
0351     if (ladd == "SFLX3b" || ladd == "SFLY3b") {
0352       mapX[4] = mapX[5] = 1;
0353       mapY[0] = 0;
0354       mapY[1] = 1;
0355       mapY[2] = 2;
0356       mapY[3] = 3;
0357       mapY[4] = 0;
0358       mapY[5] = 1;
0359       mapY[6] = 0;
0360       mapY[7] = 0;
0361       mapY[8] = 0;
0362       mapY[9] = 0;
0363 
0364       x = L3bx[0] + mapX[box - 11000 - 1];
0365       y = L3by[0] + mapY[box - 11000 - 1];
0366 
0367       if (ladd_copy == 1) {
0368         x = 41 - x;
0369         y = 41 - y;
0370       }
0371     }
0372     if (ladd == "SFLX2a" || ladd == "SFLY2a") {
0373       mapX[3] = mapX[4] = mapX[5] = mapX[6] = 1;
0374       mapY[0] = 0;
0375       mapY[1] = 1;
0376       mapY[2] = 2;
0377       mapY[3] = 0;
0378       mapY[4] = 1;
0379       mapY[5] = 2;
0380       mapY[6] = 3;
0381       mapY[7] = 0;
0382       mapY[8] = 0;
0383       mapY[9] = 0;
0384 
0385       id = (ladd_copy > 3) ? 7 - ladd_copy : ladd_copy;
0386 
0387       x = L2ax[id - 1] + mapX[box - 10000 - 1];
0388       y = L2ay[id - 1] + mapY[box - 10000 - 1];
0389 
0390       if (ladd_copy > 3) {
0391         x = 41 - x;
0392         y = 41 - y;
0393       }
0394     }
0395     if (ladd == "SFLX2b" || ladd == "SFLY2b") {
0396       mapX[2] = mapX[3] = mapX[4] = mapX[5] = 1;
0397       mapY[0] = 0;
0398       mapY[1] = 1;
0399       mapY[2] = 0;
0400       mapY[3] = 1;
0401       mapY[4] = 2;
0402       mapY[5] = 3;
0403       mapY[6] = 0;
0404       mapY[7] = 0;
0405       mapY[8] = 0;
0406       mapY[9] = 0;
0407 
0408       x = L2bx[0] + mapX[box - 12000 - 1];
0409       y = L2by[0] + mapY[box - 12000 - 1];
0410 
0411       if (ladd_copy == 2) {
0412         x = 41 - x;
0413         y = 41 - y;
0414       }
0415     }
0416 
0417     if (zside < 0 && layer == 1)
0418       x = 41 - x;
0419 
0420     ix = x;
0421     iy = y;
0422 
0423     if (layer == 2) {
0424       x = (zside > 0) ? iy : 41 - iy;
0425       y = 41 - ix;
0426     }
0427 
0428     // strip number inside wafer
0429     int strip = baseNumber.getCopyNumber(0);
0430 
0431     if (layer == 1) {
0432       if (zside > 0 && y <= 20)
0433         strip = 33 - strip;
0434       else if (zside < 0 && y > 20)
0435         strip = 33 - strip;
0436     } else if (layer == 2) {
0437       if (zside > 0 && x <= 20)
0438         strip = 33 - strip;
0439       else if (zside < 0 && x > 20)
0440         strip = 33 - strip;
0441     }
0442 
0443     intIndex = ESDetId(strip, x, y, layer, zside).rawId();
0444 
0445 #ifdef EDM_ML_DEBUG
0446     edm::LogVerbatim("EcalGeom") << "EcalPreshowerNumberingScheme : zside " << zs << ":" << zside << " Ladd " << ladd
0447                                  << " ladd_copy: " << ladd_copy << " box " << box << " x " << x << " y " << y
0448                                  << " layer " << layer << " strip " << strip << " UnitID 0x" << std::hex << intIndex
0449                                  << std::dec;
0450 
0451     for (int ich = 0; ich < numberOfHierarchyLevels; ich++)
0452       edm::LogVerbatim("EcalGeom") << "Name = " << baseNumber.getLevelName(ich)
0453                                    << " copy = " << baseNumber.getCopyNumber(ich);
0454 #endif
0455   }
0456 
0457   return intIndex;
0458 }
0459 
0460 std::pair<int, int> EcalPreshowerNumberingScheme::numbers(const std::string& name) const {
0461   int num1(-1), num2(-1);
0462   if (name.find('#') != std::string::npos) {
0463     uint32_t ip1 = name.find('#');
0464     if (name.find('!') != std::string::npos) {
0465       uint32_t ip2 = name.find('!');
0466       num1 = ::atoi(name.substr(ip1 + 1, ip2 - ip1 - 1).c_str());
0467       if (name.find('#', ip2) != std::string::npos) {
0468         uint32_t ip3 = name.find('#', ip2);
0469         num2 = ::atoi(name.substr(ip3 + 1, name.size() - ip3 - 1).c_str());
0470       }
0471     }
0472   }
0473 #ifdef EDM_ML_DEBUG
0474   edm::LogVerbatim("EcalGeom") << "EcalPreshowerNumberingScheme::Numbers from " << name << " are " << num1 << " and "
0475                                << num2;
0476 #endif
0477   return std::make_pair(num1, num2);
0478 }