Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:06

0001 #include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h"
0002 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0003 #include "Geometry/HGCalCommonData/interface/HGCalGeomTools.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "Geometry/HGCalCommonData/interface/HGCalCell.h"
0006 
0007 #include <algorithm>
0008 #include <array>
0009 #include <sstream>
0010 
0011 //#define EDM_ML_DEBUG
0012 
0013 bool HGCalWaferMask::maskCell(int u, int v, int n, int ncor, int fcor, int corners) {
0014   /*
0015 Masks each cell (or not) according to its wafer and cell position (detId) and to the user needs (corners).
0016 Each wafer has k_CornerSize corners which are defined in anti-clockwise order starting from the corner at the top, which is always #0. 'ncor' denotes the number of corners inside the physical region. 'fcor' is the defined to be the first corner that appears inside the detector's physical volume in anti-clockwise order. 
0017 The argument 'corners' controls the types of wafers the user wants: for instance, corners=3 masks all wafers that have at least 3 corners inside the physical region. 
0018  */
0019   bool mask(false);
0020   if (ncor < corners) {
0021     mask = true;
0022   } else {
0023     if (ncor == HGCalGeomTools::k_fourCorners) {
0024       switch (fcor) {
0025         case (0): {
0026           mask = (v >= n);
0027           break;
0028         }
0029         case (1): {
0030           mask = (u >= n);
0031           break;
0032         }
0033         case (2): {
0034           mask = (u > v);
0035           break;
0036         }
0037         case (3): {
0038           mask = (v < n);
0039           break;
0040         }
0041         case (4): {
0042           mask = (u < n);
0043           break;
0044         }
0045         default: {
0046           mask = (u <= v);
0047           break;
0048         }
0049       }
0050     } else {
0051       switch (fcor) {
0052         case (0): {
0053           if (ncor == HGCalGeomTools::k_threeCorners) {
0054             mask = !((u > 2 * v) && (v < n));
0055           } else {
0056             mask = ((u >= n) && (v >= n) && ((u + v) > (3 * n - 2)));
0057           }
0058           break;
0059         }
0060         case (1): {
0061           if (ncor == HGCalGeomTools::k_threeCorners) {
0062             mask = !((u + v) < n);
0063           } else {
0064             mask = ((u >= n) && (u > v) && ((2 * u - v) > 2 * n));
0065           }
0066           break;
0067         }
0068         case (2): {
0069           if (ncor == HGCalGeomTools::k_threeCorners) {
0070             mask = !((u < n) && (v > u) && (v > (2 * u - 1)));
0071           } else {
0072             mask = ((u > 2 * v) && (v < n));
0073           }
0074           break;
0075         }
0076         case (3): {
0077           if (ncor == HGCalGeomTools::k_threeCorners) {
0078             mask = !((v >= u) && ((2 * v - u) > (2 * n - 2)));
0079           } else {
0080             mask = ((u + v) < n);
0081           }
0082           break;
0083         }
0084         case (4): {
0085           if (ncor == HGCalGeomTools::k_threeCorners) {
0086             mask = !((u >= n) && (v >= n) && ((u + v) > (3 * n - 2)));
0087           } else {
0088             mask = ((u < n) && (v > u) && (v > (2 * u - 1)));
0089           }
0090           break;
0091         }
0092         default: {
0093           if (ncor == HGCalGeomTools::k_threeCorners) {
0094             mask = !((u >= n) && (u > v) && ((2 * u - v) > 2 * n));
0095           } else {
0096             mask = ((v >= u) && ((2 * v - u) > (2 * n - 2)));
0097           }
0098           break;
0099         }
0100       }
0101     }
0102   }
0103 #ifdef EDM_ML_DEBUG
0104   edm::LogVerbatim("HGCalGeom") << "Corners: " << ncor << ":" << fcor << " N " << n << " u " << u << " v " << v
0105                                 << " Mask " << mask;
0106 #endif
0107   return mask;
0108 }
0109 
0110 bool HGCalWaferMask::goodCell(int u, int v, int n, int type, int rotn) {
0111   // for V15 and V16
0112   bool good(false);
0113   int n2 = n / 2;
0114   int n4 = n / 4;
0115   int n3 = (n + 1) / 3;
0116   switch (type) {
0117     case (HGCalTypes::WaferFull): {  //WaferFull
0118       good = true;
0119       break;
0120     }
0121     case (HGCalTypes::WaferFive): {  //WaferFive
0122       switch (rotn) {
0123         case (HGCalTypes::WaferCorner0): {
0124           int u2 = u / 2;
0125           good = ((v - u2) <= n);
0126           break;
0127         }
0128         case (HGCalTypes::WaferCorner1): {
0129           good = ((v + u) < (3 * n));
0130           break;
0131         }
0132         case (HGCalTypes::WaferCorner2): {
0133           int v2 = (v + 1) / 2;
0134           good = ((u - v2) <= n);
0135           break;
0136         }
0137         case (HGCalTypes::WaferCorner3): {
0138           int u2 = (u - 1) / 2;
0139           good = (u2 <= v);
0140           break;
0141         }
0142         case (HGCalTypes::WaferCorner4): {
0143           good = ((v + u) >= n - 1);
0144           break;
0145         }
0146         default: {
0147           int v2 = v / 2;
0148           good = (u >= v2);
0149           break;
0150         }
0151       }
0152       break;
0153     }
0154     case (HGCalTypes::WaferChopTwo): {  //WaferChopTwo
0155       switch (rotn) {
0156         case (HGCalTypes::WaferCorner0): {
0157           good = (v < (3 * n2));
0158           break;
0159         }
0160         case (HGCalTypes::WaferCorner1): {
0161           good = (u < (3 * n2));
0162           break;
0163         }
0164         case (HGCalTypes::WaferCorner2): {
0165           good = ((u - v) <= n2);
0166           break;
0167         }
0168         case (HGCalTypes::WaferCorner3): {
0169           good = (v >= n2);
0170           break;
0171         }
0172         case (HGCalTypes::WaferCorner4): {
0173           good = (u >= n2 - 1);
0174           break;
0175         }
0176         default: {
0177           good = ((v - u) < n2);
0178           break;
0179         }
0180       }
0181       break;
0182     }
0183     case (HGCalTypes::WaferChopTwoM): {  //WaferChopTwoM
0184       switch (rotn) {
0185         case (HGCalTypes::WaferCorner0): {
0186           good = (v < (5 * n4));
0187           break;
0188         }
0189         case (HGCalTypes::WaferCorner1): {
0190           good = (u <= (5 * n4));
0191           break;
0192         }
0193         case (HGCalTypes::WaferCorner2): {
0194           good = ((u - v) <= n4);
0195           break;
0196         }
0197         case (HGCalTypes::WaferCorner3): {
0198           good = (v >= (3 * n4 - 1));
0199           break;
0200         }
0201         case (HGCalTypes::WaferCorner4): {
0202           good = (u >= (3 * n4));
0203           break;
0204         }
0205         default: {
0206           good = ((v - u) <= n4);
0207           break;
0208         }
0209       }
0210       break;
0211     }
0212     case (HGCalTypes::WaferHalf): {  //WaferHalf
0213       switch (rotn) {
0214         case (HGCalTypes::WaferCorner0): {
0215           good = (v < n);
0216           break;
0217         }
0218         case (HGCalTypes::WaferCorner1): {
0219           good = (u <= n);
0220           break;
0221         }
0222         case (HGCalTypes::WaferCorner2): {
0223           good = (v >= u);
0224           break;
0225         }
0226         case (HGCalTypes::WaferCorner3): {
0227           good = (v >= n - 1);
0228           break;
0229         }
0230         case (HGCalTypes::WaferCorner4): {
0231           good = (u >= n);
0232           break;
0233         }
0234         default: {
0235           good = (u >= v);
0236           break;
0237         }
0238       }
0239       break;
0240     }
0241     case (HGCalTypes::WaferSemi): {  //WaferSemi
0242       switch (rotn) {
0243         case (HGCalTypes::WaferCorner0): {
0244           good = ((u + v) <= (2 * n));
0245           break;
0246         }
0247         case (HGCalTypes::WaferCorner1): {
0248           good = ((2 * u - v) <= (n + 1));
0249           break;
0250         }
0251         case (HGCalTypes::WaferCorner2): {
0252           good = ((2 * v - u) >= (n - 2));
0253           break;
0254         }
0255         case (HGCalTypes::WaferCorner3): {
0256           good = ((u + v) >= (2 * n - 2));
0257           break;
0258         }
0259         case (HGCalTypes::WaferCorner4): {
0260           good = ((2 * u - v) >= (n - 1));
0261           break;
0262         }
0263         default: {
0264           good = ((2 * v - u) <= n);
0265           break;
0266         }
0267       }
0268       break;
0269     }
0270     case (HGCalTypes::WaferThree): {  //WaferThree
0271       switch (rotn) {
0272         case (HGCalTypes::WaferCorner0): {
0273           good = ((v + u) <= n);
0274           break;
0275         }
0276         case (HGCalTypes::WaferCorner1): {
0277           good = ((2 * u - v) <= 1);
0278           break;
0279         }
0280         case (HGCalTypes::WaferCorner2): {
0281           int u2 = ((u > 0) ? (u / 2) : 0);
0282           int uv = v - u2;
0283           good = (uv >= (n - 1));
0284           break;
0285         }
0286         case (HGCalTypes::WaferCorner3): {
0287           good = ((v + u) >= (3 * n - 2));
0288           break;
0289         }
0290         case (HGCalTypes::WaferCorner4): {
0291           int uv = 2 * u - v;
0292           good = (uv >= (2 * n - 1));
0293           break;
0294         }
0295         default: {
0296           int uv = u - 2 * v;
0297           good = (uv >= 0);
0298           break;
0299         }
0300       }
0301       break;
0302     }
0303     case (HGCalTypes::WaferSemi2): {  //WaferSemi2
0304       switch (rotn) {
0305         case (HGCalTypes::WaferCorner0): {
0306           good = ((u + v) <= (4 * n3 + 1));
0307           break;
0308         }
0309         case (HGCalTypes::WaferCorner1): {
0310           good = ((2 * u - v) <= n2);
0311           break;
0312         }
0313         case (HGCalTypes::WaferCorner2): {
0314           int u2 = ((u + 1) / 2);
0315           good = ((v - u2) >= (3 * n4 - 1));
0316           break;
0317         }
0318         case (HGCalTypes::WaferCorner3): {
0319           good = ((u + v) >= (5 * n2 - 1));
0320           break;
0321         }
0322         case (HGCalTypes::WaferCorner4): {
0323           good = ((2 * u - v) >= (3 * n2));
0324           break;
0325         }
0326         default: {
0327           int u2 = (u + 1) / 2;
0328           good = ((v - u2) < n4);
0329           break;
0330         }
0331       }
0332       break;
0333     }
0334     case (HGCalTypes::WaferFive2): {  //WaferFive2
0335       switch (rotn) {
0336         case (HGCalTypes::WaferCorner0): {
0337           good = ((2 * v - u) <= (3 * n2));
0338           break;
0339         }
0340         case (HGCalTypes::WaferCorner1): {
0341           good = ((u + v) < (5 * n2));
0342           break;
0343         }
0344         case (HGCalTypes::WaferCorner2): {
0345           good = ((2 * u - v) >= (3 * n2));
0346           break;
0347         }
0348         case (HGCalTypes::WaferCorner3): {
0349           good = ((2 * v - u) >= n3);
0350           break;
0351         }
0352         case (HGCalTypes::WaferCorner4): {
0353           good = ((u + v) > (4 * n3));
0354           break;
0355         }
0356         default: {
0357           good = ((2 * u - v) >= n2);
0358           break;
0359         }
0360       }
0361       break;
0362     }
0363     case (HGCalTypes::WaferHalf2): {  //WaferHalf2
0364       switch (rotn) {
0365         case (HGCalTypes::WaferCorner0): {
0366           good = (v <= (3 * n4));
0367           break;
0368         }
0369         case (HGCalTypes::WaferCorner1): {
0370           good = (u <= (3 * n4));
0371           break;
0372         }
0373         case (HGCalTypes::WaferCorner2): {
0374           good = ((v - u) >= n4 - 1);
0375           break;
0376         }
0377         case (HGCalTypes::WaferCorner3): {
0378           good = (v >= (5 * n4 - 1));
0379           break;
0380         }
0381         case (HGCalTypes::WaferCorner4): {
0382           good = (u >= (5 * n4 - 1));
0383           break;
0384         }
0385         default: {
0386           good = ((u - v) >= n4);
0387           break;
0388         }
0389       }
0390       break;
0391     }
0392   }
0393 #ifdef EDM_ML_DEBUG
0394   edm::LogVerbatim("HGCalGeom") << "u|v " << u << ":" << v << " N " << n << " type " << type << " rot " << rotn
0395                                 << " good " << good;
0396 #endif
0397   return good;
0398 }
0399 
0400 bool HGCalWaferMask::goodCell(int u, int v, int waferType) {
0401   // for V17
0402   bool good(false);
0403   switch (waferType) {
0404     case (HGCalTypes::WaferFull): {  //WaferFull
0405       good = true;
0406       break;
0407     }
0408     case (HGCalTypes::WaferLDTop): {
0409       good = (u * HGCalTypes::edgeWaferLDTop[0] + v * HGCalTypes::edgeWaferLDTop[1] <= HGCalTypes::edgeWaferLDTop[2]);
0410       break;
0411     }
0412     case (HGCalTypes::WaferLDBottom): {
0413       good = (u * HGCalTypes::edgeWaferLDBottom[0] + v * HGCalTypes::edgeWaferLDBottom[1] <=
0414               HGCalTypes::edgeWaferLDBottom[2]);
0415       break;
0416     }
0417     case (HGCalTypes::WaferLDLeft): {
0418       good =
0419           (u * HGCalTypes::edgeWaferLDLeft[0] + v * HGCalTypes::edgeWaferLDLeft[1] <= HGCalTypes::edgeWaferLDLeft[2]);
0420       break;
0421     }
0422     case (HGCalTypes::WaferLDRight): {
0423       good = (u * HGCalTypes::edgeWaferLDRight[0] + v * HGCalTypes::edgeWaferLDRight[1] <=
0424               HGCalTypes::edgeWaferLDRight[2]);
0425       break;
0426     }
0427     case (HGCalTypes::WaferLDFive): {
0428       good =
0429           (u * HGCalTypes::edgeWaferLDFive[0] + v * HGCalTypes::edgeWaferLDFive[1] <= HGCalTypes::edgeWaferLDFive[2]);
0430       break;
0431     }
0432     case (HGCalTypes::WaferLDThree): {
0433       good = (u * HGCalTypes::edgeWaferLDThree[0] + v * HGCalTypes::edgeWaferLDThree[1] <=
0434               HGCalTypes::edgeWaferLDThree[2]);
0435       break;
0436     }
0437     case (HGCalTypes::WaferHDTop): {
0438       good = (u * HGCalTypes::edgeWaferHDTop[0] + v * HGCalTypes::edgeWaferHDTop[1] <= HGCalTypes::edgeWaferHDTop[2]);
0439       break;
0440     }
0441     case (HGCalTypes::WaferHDBottom): {
0442       good = (u * HGCalTypes::edgeWaferHDBottom[0] + v * HGCalTypes::edgeWaferHDBottom[1] <=
0443               HGCalTypes::edgeWaferHDBottom[2]);
0444       break;
0445     }
0446     case (HGCalTypes::WaferHDLeft): {
0447       good =
0448           (u * HGCalTypes::edgeWaferHDLeft[0] + v * HGCalTypes::edgeWaferHDLeft[1] <= HGCalTypes::edgeWaferHDLeft[2]);
0449       break;
0450     }
0451     case (HGCalTypes::WaferHDRight): {
0452       good = (u * HGCalTypes::edgeWaferHDRight[0] + v * HGCalTypes::edgeWaferHDRight[1] <=
0453               HGCalTypes::edgeWaferHDRight[2]);
0454       break;
0455     }
0456     case (HGCalTypes::WaferHDFive): {
0457       good =
0458           (u * HGCalTypes::edgeWaferHDFive[0] + v * HGCalTypes::edgeWaferHDFive[1] <= HGCalTypes::edgeWaferHDFive[2]);
0459       break;
0460     }
0461   }
0462 #ifdef EDM_ML_DEBUG
0463   edm::LogVerbatim("HGCalGeom") << "u|v " << u << ":" << v << " WaferType " << waferType << " good " << good;
0464 #endif
0465   return good;
0466 }
0467 
0468 int HGCalWaferMask::getRotation(int zside, int type, int rotn) {
0469   // Needs extension for V17
0470   if (rotn >= HGCalTypes::WaferCornerMax)
0471     rotn = HGCalTypes::WaferCorner0;
0472   int newrotn(rotn);
0473   if ((zside < 0) && (type != HGCalTypes::WaferFull)) {
0474     if ((type == HGCalTypes::WaferFive) || (type == HGCalTypes::WaferFive2)) {  //WaferFive/WaferFive2
0475       static constexpr int rot1[HGCalTypes::WaferCornerMax] = {HGCalTypes::WaferCorner4,
0476                                                                HGCalTypes::WaferCorner3,
0477                                                                HGCalTypes::WaferCorner2,
0478                                                                HGCalTypes::WaferCorner1,
0479                                                                HGCalTypes::WaferCorner0,
0480                                                                HGCalTypes::WaferCorner5};
0481       newrotn = rot1[rotn];
0482     } else if ((type == HGCalTypes::WaferThree) || (type == HGCalTypes::WaferSemi) ||
0483                (type == HGCalTypes::WaferSemi2)) {  //WaferThree/WaferSemi/WaferSemi2
0484       static constexpr int rot2[HGCalTypes::WaferCornerMax] = {HGCalTypes::WaferCorner2,
0485                                                                HGCalTypes::WaferCorner1,
0486                                                                HGCalTypes::WaferCorner0,
0487                                                                HGCalTypes::WaferCorner5,
0488                                                                HGCalTypes::WaferCorner4,
0489                                                                HGCalTypes::WaferCorner3};
0490       newrotn = rot2[rotn];
0491     } else {  //WaferHalf/WaferChopTwo/WaferChopTwoM/WaferHalf2
0492       static constexpr int rot3[HGCalTypes::WaferCornerMax] = {HGCalTypes::WaferCorner3,
0493                                                                HGCalTypes::WaferCorner2,
0494                                                                HGCalTypes::WaferCorner1,
0495                                                                HGCalTypes::WaferCorner0,
0496                                                                HGCalTypes::WaferCorner5,
0497                                                                HGCalTypes::WaferCorner4};
0498       newrotn = rot3[rotn];
0499     }
0500   }
0501 #ifdef EDM_ML_DEBUG
0502   edm::LogVerbatim("HGCalGeom") << "zside " << zside << " type " << type << " rotn " << rotn << ":" << newrotn;
0503 #endif
0504   return newrotn;
0505 }
0506 
0507 std::pair<int, int> HGCalWaferMask::getTypeMode(const double& xpos,
0508                                                 const double& ypos,
0509                                                 const double& delX,
0510                                                 const double& delY,
0511                                                 const double& rin,
0512                                                 const double& rout,
0513                                                 const int& wType,
0514                                                 const int& mode,
0515                                                 const bool& v17OrLess,
0516                                                 const bool& debug) {
0517   // No need to extend this for V17 -- use flat file information only
0518   int ncor(0), iok(0);
0519   int type(HGCalTypes::WaferFull), rotn(HGCalTypes::WaferCorner0);
0520   double c22(HGCalTypes::c22), c27(HGCalTypes::c27), c61(HGCalTypes::c61);
0521   double c77(HGCalTypes::c77), c88(HGCalTypes::c88);
0522   if (v17OrLess) {
0523     c22 = HGCalTypes::c22O;
0524     c27 = HGCalTypes::c27O;
0525     c61 = HGCalTypes::c61O;
0526     c77 = HGCalTypes::c77O;
0527     c88 = HGCalTypes::c88O;
0528   }
0529 
0530   static constexpr int corners = 6;
0531   static constexpr int base = 10;
0532   double rin2 = rin * rin;
0533   double rout2 = rout * rout;
0534   double dx0[corners] = {HGCalTypes::c00 * delX,
0535                          HGCalTypes::c10 * delX,
0536                          HGCalTypes::c10 * delX,
0537                          HGCalTypes::c00 * delX,
0538                          -HGCalTypes::c10 * delX,
0539                          -HGCalTypes::c10 * delX};
0540   double dy0[corners] = {-HGCalTypes::c10 * delY,
0541                          -HGCalTypes::c50 * delY,
0542                          HGCalTypes::c50 * delY,
0543                          HGCalTypes::c10 * delY,
0544                          HGCalTypes::c50 * delY,
0545                          -HGCalTypes::c50 * delY};
0546   double xc[corners], yc[corners];
0547   for (int k = 0; k < corners; ++k) {
0548     xc[k] = xpos + dx0[k];
0549     yc[k] = ypos + dy0[k];
0550     double rpos2 = (xc[k] * xc[k] + yc[k] * yc[k]);
0551     if (rpos2 <= rout2 && rpos2 >= rin2) {
0552       ++ncor;
0553       iok = iok * base + 1;
0554     } else {
0555       iok *= base;
0556     }
0557   }
0558   if (debug)
0559     edm::LogVerbatim("HGCalGeom") << "I/p: xp " << xpos << " yp " << ypos << " dX " << delX << " dY " << delY << " rin "
0560                                   << rin << " rout " << rout << " wtype " << wType << " mode " << mode << " Corners "
0561                                   << ncor << " iok " << iok;
0562 
0563   static constexpr int ipat5[corners] = {101111, 110111, 111011, 111101, 111110, 11111};
0564   static constexpr int ipat4[corners] = {100111, 110011, 111001, 111100, 11110, 1111};
0565   static constexpr int ipat3[corners] = {100011, 110001, 111000, 11100, 1110, 111};
0566   static constexpr int ipat2[corners] = {11, 100001, 110000, 11000, 1100, 110};
0567   double dx1[corners] = {HGCalTypes::c50 * delX,
0568                          HGCalTypes::c10 * delX,
0569                          HGCalTypes::c50 * delX,
0570                          -HGCalTypes::c50 * delX,
0571                          -HGCalTypes::c10 * delX,
0572                          -HGCalTypes::c50 * delX};
0573   double dy1[corners] = {-HGCalTypes::c75 * delY,
0574                          HGCalTypes::c00 * delY,
0575                          HGCalTypes::c75 * delY,
0576                          HGCalTypes::c75 * delY,
0577                          HGCalTypes::c00 * delY,
0578                          -HGCalTypes::c75 * delY};
0579   double dx2[corners] = {HGCalTypes::c50 * delX,
0580                          -HGCalTypes::c50 * delX,
0581                          -HGCalTypes::c10 * delX,
0582                          -HGCalTypes::c50 * delX,
0583                          HGCalTypes::c50 * delX,
0584                          HGCalTypes::c10 * delX};
0585   double dy2[corners] = {HGCalTypes::c75 * delY,
0586                          HGCalTypes::c75 * delY,
0587                          HGCalTypes::c00 * delY,
0588                          -HGCalTypes::c75 * delY,
0589                          -HGCalTypes::c75 * delY,
0590                          HGCalTypes::c00 * delY};
0591   double dx3[corners] = {
0592       c22 * delX, HGCalTypes::c10 * delX, c77 * delX, -c22 * delX, -HGCalTypes::c10 * delX, -c77 * delX};
0593   double dy3[corners] = {-c88 * delY, -c27 * delY, c61 * delY, c88 * delY, c27 * delY, -c61 * delY};
0594   double dx4[corners] = {
0595       c22 * delX, -c77 * delX, -HGCalTypes::c10 * delX, -c22 * delX, c77 * delX, HGCalTypes::c10 * delX};
0596   double dy4[corners] = {c88 * delY, c61 * delY, -c27 * delY, -c88 * delY, -c61 * delY, c27 * delY};
0597   double dx5[corners] = {-HGCalTypes::c50 * delX,
0598                          -HGCalTypes::c10 * delX,
0599                          -HGCalTypes::c50 * delX,
0600                          HGCalTypes::c50 * delX,
0601                          HGCalTypes::c10 * delX,
0602                          HGCalTypes::c50 * delX};
0603   double dy5[corners] = {HGCalTypes::c75 * delY,
0604                          HGCalTypes::c00 * delY,
0605                          -HGCalTypes::c75 * delY,
0606                          -HGCalTypes::c75 * delY,
0607                          HGCalTypes::c00 * delY,
0608                          HGCalTypes::c75 * delY};
0609   double dx6[corners] = {
0610       -c77 * delX, -HGCalTypes::c10 * delX, -c22 * delX, c77 * delX, HGCalTypes::c10 * delX, c22 * delX};
0611   double dy6[corners] = {c61 * delY, -c27 * delY, -c88 * delY, -c61 * delY, c27 * delY, c88 * delY};
0612   double dx7[corners] = {
0613       -c22 * delX, -HGCalTypes::c10 * delX, -c77 * delX, c22 * delX, HGCalTypes::c10 * delX, c77 * delX};
0614   double dy7[corners] = {c88 * delY, c27 * delY, -c61 * delY, -c88 * delY, -c27 * delY, c61 * delY};
0615   double dx8[corners] = {
0616       c77 * delX, HGCalTypes::c10 * delX, c22 * delX, -c77 * delX, -HGCalTypes::c10 * delX, -c22 * delX};
0617   double dy8[corners] = {-c61 * delY, c27 * delY, c88 * delY, c61 * delY, -c27 * delY, -c88 * delY};
0618   double dx9[corners] = {
0619       -c22 * delX, c77 * delX, HGCalTypes::c10 * delX, c22 * delX, -c77 * delX, -HGCalTypes::c10 * delX};
0620   double dy9[corners] = {-c88 * delY, -c61 * delY, c27 * delY, c88 * delY, c61 * delY, -c27 * delY};
0621 
0622   if (ncor == HGCalGeomTools::k_allCorners) {
0623   } else if (ncor == HGCalGeomTools::k_fiveCorners) {
0624     rotn = static_cast<int>(std::find(ipat5, ipat5 + 6, iok) - ipat5);
0625     type = HGCalTypes::WaferFive;
0626   } else if (ncor == HGCalGeomTools::k_fourCorners) {
0627     rotn = static_cast<int>(std::find(ipat4, ipat4 + 6, iok) - ipat4);
0628     type = HGCalTypes::WaferHalf;
0629     double rpos12 = ((xpos + dx1[rotn]) * (xpos + dx1[rotn]) + (ypos + dy1[rotn]) * (ypos + dy1[rotn]));
0630     double rpos22(0);
0631     if (rpos12 <= rout2 && rpos12 >= rin2) {
0632       rpos22 = ((xpos + dx2[rotn]) * (xpos + dx2[rotn]) + (ypos + dy2[rotn]) * (ypos + dy2[rotn]));
0633       if (rpos22 <= rout2 && rpos22 >= rin2)
0634         type = HGCalTypes::WaferChopTwo;
0635     }
0636     if (debug)
0637       edm::LogVerbatim("HGCalGeom") << "Test for Chop2 " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
0638                                     << type;
0639     if ((type == HGCalTypes::WaferHalf) && (wType == 0)) {
0640       rpos12 = ((xpos + dx3[rotn]) * (xpos + dx3[rotn]) + (ypos + dy3[rotn]) * (ypos + dy3[rotn]));
0641       if (rpos12 <= rout2 && rpos12 >= rin2) {
0642         rpos22 = ((xpos + dx4[rotn]) * (xpos + dx4[rotn]) + (ypos + dy4[rotn]) * (ypos + dy4[rotn]));
0643         if (rpos22 <= rout2 && rpos22 >= rin2)
0644           type = HGCalTypes::WaferChopTwoM;
0645       }
0646       if (debug)
0647         edm::LogVerbatim("HGCalGeom") << "Test for Chop2M " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
0648                                       << type;
0649     }
0650   } else if (ncor == HGCalGeomTools::k_threeCorners) {
0651     rotn = static_cast<int>(std::find(ipat3, ipat3 + 6, iok) - ipat3);
0652     type = HGCalTypes::WaferThree;
0653     double rpos12 = ((xpos + dx7[rotn]) * (xpos + dx7[rotn]) + (ypos + dy7[rotn]) * (ypos + dy7[rotn]));
0654     double rpos22(0);
0655     if (rpos12 <= rout2 && rpos12 >= rin2) {
0656       rpos22 = ((xpos + dx8[rotn]) * (xpos + dx8[rotn]) + (ypos + dy8[rotn]) * (ypos + dy8[rotn]));
0657       if (rpos22 <= rout2 && rpos22 >= rin2)
0658         type = HGCalTypes::WaferFive2;
0659     }
0660     if (debug)
0661       edm::LogVerbatim("HGCalGeom") << "Test for Five2 " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
0662                                     << type;
0663     if ((type == HGCalTypes::WaferThree) && (wType == 0)) {
0664       rpos12 = ((xpos + dx1[rotn]) * (xpos + dx1[rotn]) + (ypos + dy1[rotn]) * (ypos + dy1[rotn]));
0665       if (rpos12 <= rout2 && rpos12 >= rin2) {
0666         rpos22 = ((xpos + dx5[rotn]) * (xpos + dx5[rotn]) + (ypos + dy5[rotn]) * (ypos + dy5[rotn]));
0667         if (rpos22 <= rout2 && rpos22 >= rin2)
0668           type = HGCalTypes::WaferSemi;
0669       }
0670       if (debug)
0671         edm::LogVerbatim("HGCalGeom") << "Test for Semi " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
0672                                       << type;
0673     }
0674     if ((type == HGCalTypes::WaferThree) && (wType == 0)) {
0675       rpos12 = ((xpos + dx3[rotn]) * (xpos + dx3[rotn]) + (ypos + dy3[rotn]) * (ypos + dy3[rotn]));
0676       if (rpos12 <= rout2 && rpos12 >= rin2) {
0677         rpos22 = ((xpos + dx6[rotn]) * (xpos + dx6[rotn]) + (ypos + dy6[rotn]) * (ypos + dy6[rotn]));
0678         if (rpos22 <= rout2 && rpos22 >= rin2)
0679           type = HGCalTypes::WaferSemi2;
0680       }
0681       if (debug)
0682         edm::LogVerbatim("HGCalGeom") << "Test for SemiM " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
0683                                       << type;
0684     }
0685   } else if (ncor == HGCalGeomTools::k_twoCorners) {
0686     rotn = static_cast<int>(std::find(ipat2, ipat2 + 6, iok) - ipat2);
0687     type = HGCalTypes::WaferOut;
0688     double rpos12 = ((xpos + dx7[rotn]) * (xpos + dx7[rotn]) + (ypos + dy7[rotn]) * (ypos + dy7[rotn]));
0689     double rpos22(0);
0690     if (rpos12 <= rout2 && rpos12 >= rin2) {
0691       rpos22 = ((xpos + dx9[rotn]) * (xpos + dx9[rotn]) + (ypos + dy9[rotn]) * (ypos + dy9[rotn]));
0692       if (rpos22 <= rout2 && rpos22 >= rin2)
0693         type = HGCalTypes::WaferHalf2;
0694       else
0695         rotn = HGCalTypes::WaferCorner0;
0696     }
0697     if (debug)
0698       edm::LogVerbatim("HGCalGeom") << "Test for Half2 " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
0699                                     << type;
0700   } else {
0701     type = HGCalTypes::WaferOut;
0702   }
0703 
0704   if (debug)
0705     edm::LogVerbatim("HGCalGeom") << "I/p: xpos " << xpos << " ypos " << ypos << " dX " << delX << " dY " << delY
0706                                   << " rin " << rin << " rout " << rout << " wType " << wType << " mode " << mode
0707                                   << " O/p: ok " << iok << " ncor " << ncor << " type " << type << " rotn " << rotn;
0708   return ((mode == 0) ? std::make_pair(ncor, rotn) : std::make_pair(type, (rotn + HGCalTypes::k_OffsetRotation)));
0709 }
0710 
0711 bool HGCalWaferMask::goodTypeMode(const double& xpos,
0712                                   const double& ypos,
0713                                   const double& delX,
0714                                   const double& delY,
0715                                   const double& rin,
0716                                   const double& rout,
0717                                   const int& part,
0718                                   const int& rotn,
0719                                   const bool& v17OrLess,
0720                                   const bool& debug) {
0721   // Needs extension for V17 or above
0722   double c22(HGCalTypes::c22), c27(HGCalTypes::c27), c61(HGCalTypes::c61);
0723   double c77(HGCalTypes::c77), c88(HGCalTypes::c88);
0724   if (v17OrLess) {
0725     c22 = HGCalTypes::c22O;
0726     c27 = HGCalTypes::c27O;
0727     c61 = HGCalTypes::c61O;
0728     c77 = HGCalTypes::c77O;
0729     c88 = HGCalTypes::c88O;
0730   }
0731 
0732   if (part < 0 || part > HGCalTypes::WaferSizeMax)
0733     return false;
0734   if (rotn < 0 || rotn > HGCalTypes::WaferCornerMax)
0735     return false;
0736   double rin2 = rin * rin;
0737   double rout2 = rout * rout;
0738   double rpos2(0);
0739   static constexpr int corners = HGCalTypes::WaferCornerMax;
0740   static constexpr int corner2 = 2 * HGCalTypes::WaferCornerMax;
0741   static constexpr int base = 10;
0742   static constexpr int base2 = 100;
0743   double dx0[corners] = {HGCalTypes::c00 * delX,
0744                          HGCalTypes::c10 * delX,
0745                          HGCalTypes::c10 * delX,
0746                          HGCalTypes::c00 * delX,
0747                          -HGCalTypes::c10 * delX,
0748                          -HGCalTypes::c10 * delX};
0749   double dy0[corners] = {-HGCalTypes::c10 * delY,
0750                          -HGCalTypes::c50 * delY,
0751                          HGCalTypes::c50 * delY,
0752                          HGCalTypes::c10 * delY,
0753                          HGCalTypes::c50 * delY,
0754                          -HGCalTypes::c50 * delY};
0755   double dx1[corners] = {HGCalTypes::c50 * delX,
0756                          HGCalTypes::c10 * delX,
0757                          HGCalTypes::c50 * delX,
0758                          -HGCalTypes::c50 * delX,
0759                          -HGCalTypes::c10 * delX,
0760                          -HGCalTypes::c50 * delX};
0761   double dy1[corners] = {-HGCalTypes::c75 * delY,
0762                          HGCalTypes::c00 * delY,
0763                          HGCalTypes::c75 * delY,
0764                          HGCalTypes::c75 * delY,
0765                          HGCalTypes::c00 * delY,
0766                          -HGCalTypes::c75 * delY};
0767   double dx2[corner2] = {c22 * delX,
0768                          c77 * delX,
0769                          HGCalTypes::c10 * delX,
0770                          HGCalTypes::c10 * delX,
0771                          c77 * delX,
0772                          c22 * delX,
0773                          -c22 * delX,
0774                          -c77 * delX,
0775                          -HGCalTypes::c10 * delX,
0776                          -HGCalTypes::c10 * delX,
0777                          -c77 * delX,
0778                          -c22 * delX};
0779   double dy2[corner2] = {-c88 * delY,
0780                          -c61 * delY,
0781                          -c27 * delY,
0782                          c27 * delY,
0783                          c61 * delY,
0784                          c88 * delY,
0785                          c88 * delY,
0786                          c61 * delY,
0787                          c27 * delY,
0788                          -c27 * delY,
0789                          -c61 * delY,
0790                          -c88 * delY};
0791   bool ok(true);
0792   int ncf(-1);
0793   switch (part) {
0794     case (HGCalTypes::WaferThree): {
0795       static constexpr int nc0[corners] = {450, 150, 201, 312, 423, 534};
0796       int nc = nc0[rotn];
0797       for (int k1 = 0; k1 < 3; ++k1) {
0798         int k = nc % base;
0799         double xc1 = xpos + dx0[k];
0800         double yc1 = ypos + dy0[k];
0801         rpos2 = (xc1 * xc1 + yc1 * yc1);
0802         if ((rpos2 > rout2) || (rpos2 < rin2)) {
0803           ok = false;
0804           ncf = k;
0805           break;
0806         }
0807         nc /= base;
0808       }
0809       break;
0810     }
0811     case (HGCalTypes::WaferSemi2): {
0812       static constexpr int nc10[corners] = {450, 150, 201, 312, 423, 534};
0813       static constexpr int nc11[corners] = {700, 902, 1104, 106, 308, 510};
0814       int nc = nc10[rotn];
0815       for (int k1 = 0; k1 < 3; ++k1) {
0816         int k = nc % base;
0817         double xc1 = xpos + dx0[k];
0818         double yc1 = ypos + dy0[k];
0819         rpos2 = (xc1 * xc1 + yc1 * yc1);
0820         if ((rpos2 > rout2) || (rpos2 < rin2)) {
0821           ok = false;
0822           ncf = k;
0823           break;
0824         }
0825         nc /= base;
0826       }
0827       nc = nc11[rotn];
0828       for (int k1 = 0; k1 < 2; ++k1) {
0829         int k = nc % base2;
0830         double xc1 = xpos + dx2[k];
0831         double yc1 = ypos + dy2[k];
0832         rpos2 = (xc1 * xc1 + yc1 * yc1);
0833         if ((rpos2 > rout2) || (rpos2 < rin2)) {
0834           ok = false;
0835           ncf = k + base2;
0836           break;
0837         }
0838         nc /= base2;
0839       }
0840       break;
0841     }
0842     case (HGCalTypes::WaferSemi): {
0843       static constexpr int nc20[corners] = {450, 150, 201, 312, 423, 534};
0844       static constexpr int nc21[corners] = {30, 14, 25, 30, 41, 52};
0845       int nc = nc20[rotn];
0846       for (int k1 = 0; k1 < 3; ++k1) {
0847         int k = nc % base;
0848         double xc1 = xpos + dx0[k];
0849         double yc1 = ypos + dy0[k];
0850         rpos2 = (xc1 * xc1 + yc1 * yc1);
0851         if ((rpos2 > rout2) || (rpos2 < rin2)) {
0852           ok = false;
0853           ncf = k;
0854           break;
0855         }
0856         nc /= base;
0857       }
0858       nc = nc21[rotn];
0859       for (int k1 = 0; k1 < 2; ++k1) {
0860         int k = nc % base;
0861         double xc1 = xpos + dx1[k];
0862         double yc1 = ypos + dy1[k];
0863         rpos2 = (xc1 * xc1 + yc1 * yc1);
0864         if ((rpos2 > rout2) || (rpos2 < rin2)) {
0865           ok = false;
0866           ncf = k + base2;
0867           break;
0868         }
0869         nc /= base;
0870       }
0871       break;
0872     }
0873     case (HGCalTypes::WaferHalf): {
0874       static constexpr int nc3[corners] = {3450, 1450, 2501, 3012, 4123, 5234};
0875       int nc = nc3[rotn];
0876       for (int k1 = 0; k1 < 4; ++k1) {
0877         int k = nc % base;
0878         double xc1 = xpos + dx0[k];
0879         double yc1 = ypos + dy0[k];
0880         rpos2 = (xc1 * xc1 + yc1 * yc1);
0881         if ((rpos2 > rout2) || (rpos2 < rin2)) {
0882           ok = false;
0883           ncf = k;
0884           break;
0885         }
0886         nc /= base;
0887       }
0888       break;
0889     }
0890     case (HGCalTypes::WaferChopTwoM): {
0891       static constexpr int nc40[corners] = {3450, 1450, 2501, 3012, 4123, 5234};
0892       static constexpr int nc41[corners] = {500, 702, 904, 1106, 108, 310};
0893       int nc = nc40[rotn];
0894       for (int k1 = 0; k1 < 4; ++k1) {
0895         int k = nc % base;
0896         double xc1 = xpos + dx0[k];
0897         double yc1 = ypos + dy0[k];
0898         rpos2 = (xc1 * xc1 + yc1 * yc1);
0899         if ((rpos2 > rout2) || (rpos2 < rin2)) {
0900           ok = false;
0901           ncf = k;
0902           break;
0903         }
0904         nc /= base;
0905       }
0906       nc = nc41[rotn];
0907       for (int k1 = 0; k1 < 2; ++k1) {
0908         int k = nc % base2;
0909         double xc1 = xpos + dx2[k];
0910         double yc1 = ypos + dy2[k];
0911         rpos2 = (xc1 * xc1 + yc1 * yc1);
0912         if ((rpos2 > rout2) || (rpos2 < rin2)) {
0913           ok = false;
0914           ncf = k + base2;
0915           break;
0916         }
0917         nc /= base2;
0918       }
0919       break;
0920     }
0921     case (HGCalTypes::WaferChopTwo): {
0922       static constexpr int nc50[corners] = {3450, 1450, 2501, 3012, 4123, 5234};
0923       static constexpr int nc51[corners] = {20, 13, 24, 35, 40, 51};
0924       int nc = nc50[rotn];
0925       for (int k1 = 0; k1 < 4; ++k1) {
0926         int k = nc % base;
0927         double xc1 = xpos + dx0[k];
0928         double yc1 = ypos + dy0[k];
0929         rpos2 = (xc1 * xc1 + yc1 * yc1);
0930         if ((rpos2 > rout2) || (rpos2 < rin2)) {
0931           ok = false;
0932           ncf = k;
0933           break;
0934         }
0935         nc /= base;
0936       }
0937       nc = nc51[rotn];
0938       for (int k1 = 0; k1 < 2; ++k1) {
0939         int k = nc % base;
0940         double xc1 = xpos + dx1[k];
0941         double yc1 = ypos + dy1[k];
0942         rpos2 = (xc1 * xc1 + yc1 * yc1);
0943         if ((rpos2 > rout2) || (rpos2 < rin2)) {
0944           ok = false;
0945           ncf = k + base2;
0946           break;
0947         }
0948         nc /= base;
0949       }
0950       break;
0951     }
0952     case (HGCalTypes::WaferFive): {
0953       static constexpr int nc6[corners] = {23450, 13450, 24501, 35012, 40123, 51234};
0954       int nc = nc6[rotn];
0955       for (int k1 = 0; k1 < 5; ++k1) {
0956         int k = nc % base;
0957         double xc1 = xpos + dx0[k];
0958         double yc1 = ypos + dy0[k];
0959         rpos2 = (xc1 * xc1 + yc1 * yc1);
0960         if ((rpos2 > rout2) || (rpos2 < rin2)) {
0961           ok = false;
0962           ncf = k;
0963           break;
0964         }
0965       }
0966       break;
0967     }
0968     case (HGCalTypes::WaferFive2): {
0969       static constexpr int nc60[corners] = {450, 150, 201, 312, 423, 534};
0970       static constexpr int nc61[corners] = {601, 803, 1005, 7, 209, 411};
0971       int nc = nc60[rotn];
0972       for (int k1 = 0; k1 < 3; ++k1) {
0973         int k = nc % base;
0974         double xc1 = xpos + dx0[k];
0975         double yc1 = ypos + dy0[k];
0976         rpos2 = (xc1 * xc1 + yc1 * yc1);
0977         if ((rpos2 > rout2) || (rpos2 < rin2)) {
0978           ok = false;
0979           ncf = k;
0980           break;
0981         }
0982         nc /= base;
0983       }
0984       nc = nc61[rotn];
0985       for (int k1 = 0; k1 < 2; ++k1) {
0986         int k = nc % base2;
0987         double xc1 = xpos + dx2[k];
0988         double yc1 = ypos + dy2[k];
0989         rpos2 = (xc1 * xc1 + yc1 * yc1);
0990         if ((rpos2 > rout2) || (rpos2 < rin2)) {
0991           ok = false;
0992           ncf = k + base2;
0993           break;
0994         }
0995         nc /= base2;
0996       }
0997       break;
0998     }
0999     case (HGCalTypes::WaferHalf2): {
1000       static constexpr int nc70[corners] = {45, 50, 1, 12, 23, 34};
1001       static constexpr int nc71[corners] = {611, 801, 1003, 5, 207, 409};
1002       int nc = nc70[rotn];
1003       for (int k1 = 0; k1 < 2; ++k1) {
1004         int k = nc % base;
1005         double xc1 = xpos + dx0[k];
1006         double yc1 = ypos + dy0[k];
1007         rpos2 = (xc1 * xc1 + yc1 * yc1);
1008         if ((rpos2 > rout2) || (rpos2 < rin2)) {
1009           ok = false;
1010           ncf = k;
1011           break;
1012         }
1013         nc /= base;
1014       }
1015       nc = nc71[rotn];
1016       for (int k1 = 0; k1 < 2; ++k1) {
1017         int k = nc % base2;
1018         double xc1 = xpos + dx2[k];
1019         double yc1 = ypos + dy2[k];
1020         rpos2 = (xc1 * xc1 + yc1 * yc1);
1021         if ((rpos2 > rout2) || (rpos2 < rin2)) {
1022           ok = false;
1023           ncf = k + base2;
1024           break;
1025         }
1026         nc /= base2;
1027       }
1028       break;
1029     }
1030     default: {
1031       for (int k = 0; k < corners; ++k) {
1032         double xc1 = xpos + dx0[k];
1033         double yc1 = ypos + dy0[k];
1034         rpos2 = (xc1 * xc1 + yc1 * yc1);
1035         if ((rpos2 > rout2) || (rpos2 < rin2)) {
1036           ok = false;
1037           ncf = k;
1038           break;
1039         }
1040       }
1041       break;
1042     }
1043   }
1044   if (debug || (!ok))
1045     edm::LogVerbatim("HGCalGeom") << "I/p: xpos " << xpos << " ypos " << ypos << " dX " << delX << " dY " << delY
1046                                   << " rin " << rin << " rout " << rout << " part " << part << " rotn " << rotn
1047                                   << " Results: ok " << ok << " ncf " << ncf << " rin " << rin2 << " rout " << rout2
1048                                   << " rpos " << rpos2;
1049   return ok;
1050 }
1051 
1052 std::vector<std::pair<double, double> > HGCalWaferMask::waferXY(const int& part,
1053                                                                 const int& ori,
1054                                                                 const int& zside,
1055                                                                 const double& waferSize,
1056                                                                 const double& offset,
1057                                                                 const double& xpos,
1058                                                                 const double& ypos,
1059                                                                 const bool& v17OrLess) {
1060   // Good for V15 and V16 versions
1061   std::vector<std::pair<double, double> > xy;
1062   int orient = getRotation(-zside, part, ori);
1063 #ifdef EDM_ML_DEBUG
1064   edm::LogVerbatim("HGCalGeom") << "Part " << part << " zSide " << zside << " Orient " << ori << ":" << orient;
1065 #endif
1066   double c22(HGCalTypes::c22), c27(HGCalTypes::c27), c61(HGCalTypes::c61);
1067   double c77(HGCalTypes::c77), c88(HGCalTypes::c88);
1068   if (v17OrLess) {
1069     c22 = HGCalTypes::c22O;
1070     c27 = HGCalTypes::c27O;
1071     c61 = HGCalTypes::c61O;
1072     c77 = HGCalTypes::c77O;
1073     c88 = HGCalTypes::c88O;
1074   }
1075   /*
1076     The exact contour of partial wafers are obtained by joining points on
1077     the circumference of a full wafer.
1078     Numbering the points along the edges of a hexagonal wafer, starting from
1079     the bottom corner:
1080 
1081                                    3
1082                                15     18
1083                              9           8
1084                           19               14
1085                         4                     2 
1086                        16                    23
1087                        10                     7
1088                        20                    13
1089                         5                     1
1090                           17               22
1091                             11           6
1092                                21     12
1093                                    0
1094 
1095     Depending on the wafer type and orientation index, the corners
1096     are chosen in the variable *np*
1097   */
1098   double delX = 0.5 * waferSize;
1099   double delY = delX / sin_60_;
1100   double dx[48] = {HGCalTypes::c00 * delX,
1101                    HGCalTypes::c10 * delX,
1102                    HGCalTypes::c10 * delX,
1103                    HGCalTypes::c00 * delX,
1104                    -HGCalTypes::c10 * delX,
1105                    -HGCalTypes::c10 * delX,
1106                    HGCalTypes::c50 * delX,
1107                    HGCalTypes::c10 * delX,
1108                    HGCalTypes::c50 * delX,
1109                    -HGCalTypes::c50 * delX,
1110                    -HGCalTypes::c10 * delX,
1111                    -HGCalTypes::c50 * delX,
1112                    c22 * delX,
1113                    HGCalTypes::c10 * delX,
1114                    c77 * delX,
1115                    -c22 * delX,
1116                    -HGCalTypes::c10 * delX,
1117                    -c77 * delX,
1118                    c22 * delX,
1119                    -c77 * delX,
1120                    -HGCalTypes::c10 * delX,
1121                    -c22 * delX,
1122                    c77 * delX,
1123                    HGCalTypes::c10 * delX,
1124                    HGCalTypes::c50 * delX,
1125                    HGCalTypes::c10 * delX,
1126                    HGCalTypes::c50 * delX,
1127                    -HGCalTypes::c50 * delX,
1128                    -HGCalTypes::c10 * delX,
1129                    -HGCalTypes::c50 * delX,
1130                    HGCalTypes::c50 * delX,
1131                    HGCalTypes::c10 * delX,
1132                    HGCalTypes::c50 * delX,
1133                    -HGCalTypes::c50 * delX,
1134                    -HGCalTypes::c10 * delX,
1135                    -HGCalTypes::c50 * delX,
1136                    c22 * delX,
1137                    HGCalTypes::c10 * delX,
1138                    c77 * delX,
1139                    -c22 * delX,
1140                    -HGCalTypes::c10 * delX,
1141                    -c77 * delX,
1142                    c22 * delX,
1143                    -c77 * delX,
1144                    -HGCalTypes::c10 * delX,
1145                    -c22 * delX,
1146                    c77 * delX,
1147                    HGCalTypes::c10 * delX};
1148   double dy[48] = {-HGCalTypes::c10 * delY,
1149                    -HGCalTypes::c50 * delY,
1150                    HGCalTypes::c50 * delY,
1151                    HGCalTypes::c10 * delY,
1152                    HGCalTypes::c50 * delY,
1153                    -HGCalTypes::c50 * delY,
1154                    -HGCalTypes::c75 * delY,
1155                    HGCalTypes::c00 * delY,
1156                    HGCalTypes::c75 * delY,
1157                    HGCalTypes::c75 * delY,
1158                    HGCalTypes::c00 * delY,
1159                    -HGCalTypes::c75 * delY,
1160                    -c88 * delY,
1161                    -c27 * delY,
1162                    c61 * delY,
1163                    c88 * delY,
1164                    c27 * delY,
1165                    -c61 * delY,
1166                    c88 * delY,
1167                    c61 * delY,
1168                    -c27 * delY,
1169                    -c88 * delY,
1170                    -c61 * delY,
1171                    c27 * delY,
1172                    -HGCalTypes::c75 * delY,
1173                    HGCalTypes::c00 * delY,
1174                    -HGCalTypes::c75 * delY,
1175                    HGCalTypes::c00 * delY,
1176                    HGCalTypes::c75 * delY,
1177                    HGCalTypes::c75 * delY,
1178                    HGCalTypes::c00 * delY,
1179                    -HGCalTypes::c75 * delY,
1180                    HGCalTypes::c75 * delY,
1181                    HGCalTypes::c75 * delY,
1182                    HGCalTypes::c00 * delY,
1183                    -HGCalTypes::c75 * delY,
1184                    -c88 * delY,
1185                    -c27 * delY,
1186                    c61 * delY,
1187                    c88 * delY,
1188                    c27 * delY,
1189                    -c61 * delY,
1190                    c88 * delY,
1191                    c61 * delY,
1192                    -c27 * delY,
1193                    -c88 * delY,
1194                    -c61 * delY,
1195                    c27 * delY};
1196 
1197   double offsetx[48] = {0.0,
1198                         -offset,
1199                         -offset,
1200                         0.0,
1201                         offset,
1202                         offset,
1203                         -offset * cos_60_,
1204                         -offset,
1205                         -offset * cos_60_,
1206                         offset * cos_60_,
1207                         offset,
1208                         offset * cos_60_,
1209                         -offset * cos_60_,
1210                         -offset,
1211                         -offset * cos_60_,
1212                         offset * cos_60_,
1213                         offset,
1214                         offset * cos_60_,
1215                         -offset * cos_60_,
1216                         offset * cos_60_,
1217                         offset,
1218                         offset * cos_60_,
1219                         -offset * cos_60_,
1220                         -offset,
1221                         0.0,
1222                         -offset,
1223                         -offset,
1224                         0.0,
1225                         offset,
1226                         offset,
1227                         0.0,
1228                         offset,
1229                         offset,
1230                         0.0,
1231                         -offset,
1232                         -offset,
1233                         0.0,
1234                         -offset,
1235                         -offset,
1236                         0.0,
1237                         offset,
1238                         offset,
1239                         0.0,
1240                         offset,
1241                         offset,
1242                         0.0,
1243                         -offset,
1244                         -offset};
1245   double offsety[48] = {offset / sin_60_,
1246                         offset / tan_60_,
1247                         -offset / tan_60_,
1248                         -offset / sin_60_,
1249                         -offset / tan_60_,
1250                         offset / tan_60_,
1251                         offset * sin_60_,
1252                         0.0,
1253                         -offset * sin_60_,
1254                         -offset * sin_60_,
1255                         0.0,
1256                         offset * sin_60_,
1257                         offset * sin_60_,
1258                         0.0,
1259                         -offset * sin_60_,
1260                         -offset * sin_60_,
1261                         0.0,
1262                         offset * sin_60_,
1263                         -offset * sin_60_,
1264                         -offset * sin_60_,
1265                         0.0,
1266                         offset * sin_60_,
1267                         offset * sin_60_,
1268                         0.0,
1269                         offset / sin_60_,
1270                         offset / tan_60_,
1271                         -offset / tan_60_,
1272                         -offset / sin_60_,
1273                         -offset / tan_60_,
1274                         -offset / sin_60_,
1275                         -offset / tan_60_,
1276                         offset / tan_60_,
1277                         offset / sin_60_,
1278                         offset / tan_60_,
1279                         -offset / tan_60_,
1280                         offset / tan_60_,
1281                         offset / sin_60_,
1282                         offset / tan_60_,
1283                         -offset / tan_60_,
1284                         -offset / sin_60_,
1285                         -offset / tan_60_,
1286                         offset / tan_60_,
1287                         -offset / sin_60_,
1288                         -offset / tan_60_,
1289                         offset / tan_60_,
1290                         offset / sin_60_,
1291                         offset / tan_60_,
1292                         -offset / tan_60_};
1293 
1294   if (part == HGCalTypes::WaferFull) {
1295     int np[7] = {0, 1, 2, 3, 4, 5, 0};
1296     for (int k = 0; k < 7; ++k)
1297       xy.push_back(std::make_pair((xpos + dx[np[k]] + offsetx[np[k]]), (ypos + dy[np[k]] + offsety[np[k]])));
1298   } else if (part == HGCalTypes::WaferFive) {
1299     int np[6][6] = {{0, 2, 3, 4, 5, 0},
1300                     {1, 3, 4, 5, 0, 1},
1301                     {2, 4, 5, 0, 1, 2},
1302                     {3, 5, 0, 1, 2, 3},
1303                     {4, 0, 1, 2, 3, 4},
1304                     {5, 1, 2, 3, 4, 5}};
1305     for (int k = 0; k < 6; ++k) {
1306       xy.push_back(std::make_pair((xpos + dx[np[orient][k]] + offsetx[np[orient][k]]),
1307                                   (ypos + dy[np[orient][k]] + offsety[np[orient][k]])));
1308 #ifdef EDM_ML_DEBUG
1309       edm::LogVerbatim("HGCalGeom") << "WaferFull " << k << " np " << np[orient][k] << " dx "
1310                                     << dx[np[orient][k]] + offsetx[np[orient][k]] << " dy "
1311                                     << dy[np[orient][k]] + offsety[np[orient][k]];
1312 #endif
1313     }
1314   } else if (part == HGCalTypes::WaferHalf) {
1315     int np[6][5] = {
1316         {0, 3, 4, 5, 0}, {1, 4, 5, 0, 1}, {2, 5, 0, 1, 2}, {3, 0, 1, 2, 3}, {4, 1, 2, 3, 4}, {5, 2, 3, 4, 5}};
1317     for (int k = 0; k < 5; ++k) {
1318       xy.push_back(std::make_pair((xpos + dx[np[orient][k]] + offsetx[np[orient][k]]),
1319                                   (ypos + dy[np[orient][k]] + offsety[np[orient][k]])));
1320 #ifdef EDM_ML_DEBUG
1321       edm::LogVerbatim("HGCalGeom") << "WaferHalf " << k << " np " << np[orient][k] << " dx "
1322                                     << dx[np[orient][k]] + offsetx[np[orient][k]] << " dy "
1323                                     << dy[np[orient][k]] + offsety[np[orient][k]];
1324 #endif
1325     }
1326   } else if (part == HGCalTypes::WaferThree) {
1327     int np[6][4] = {{0, 4, 5, 0}, {1, 5, 0, 1}, {2, 0, 1, 2}, {3, 1, 2, 3}, {4, 2, 3, 4}, {5, 3, 4, 5}};
1328     for (int k = 0; k < 4; ++k) {
1329       xy.push_back(std::make_pair((xpos + dx[np[orient][k]] + offsetx[np[orient][k]]),
1330                                   (ypos + dy[np[orient][k]] + offsety[np[orient][k]])));
1331 #ifdef EDM_ML_DEBUG
1332       edm::LogVerbatim("HGCalGeom") << "WaferThree " << k << " np " << np[orient][k] << " dx "
1333                                     << dx[np[orient][k]] + offsetx[np[orient][k]] << " dy "
1334                                     << dy[np[orient][k]] + offsety[np[orient][k]];
1335 #endif
1336     }
1337   } else if (part == HGCalTypes::WaferChopTwo) {
1338     int np[6][7] = {{24, 32, 3, 4, 5, 0, 24},
1339                     {25, 33, 4, 5, 0, 1, 25},
1340                     {26, 34, 5, 0, 1, 2, 26},
1341                     {27, 35, 0, 1, 2, 3, 27},
1342                     {28, 30, 1, 2, 3, 4, 28},
1343                     {29, 31, 2, 3, 4, 5, 29}};
1344     for (int k = 0; k < 7; ++k) {
1345       xy.push_back(std::make_pair((xpos + dx[np[orient][k]] + offsetx[np[orient][k]]),
1346                                   (ypos + dy[np[orient][k]] + offsety[np[orient][k]])));
1347 #ifdef EDM_ML_DEBUG
1348       edm::LogVerbatim("HGCalGeom") << "WaferChopTwo " << k << " np " << np[orient][k] << " dx "
1349                                     << dx[np[orient][k]] + offsetx[np[orient][k]] << " dy "
1350                                     << dy[np[orient][k]] + offsety[np[orient][k]];
1351 #endif
1352     }
1353   } else if (part == HGCalTypes::WaferSemi) {
1354     int np[6][6] = {{6, 9, 4, 5, 0, 6},
1355                     {7, 10, 5, 0, 1, 7},
1356                     {8, 11, 0, 1, 2, 8},
1357                     {9, 6, 1, 2, 3, 9},
1358                     {10, 7, 2, 3, 4, 10},
1359                     {11, 8, 3, 4, 5, 11}};
1360     for (int k = 0; k < 6; ++k) {
1361       xy.push_back(std::make_pair((xpos + dx[np[orient][k]] + offsetx[np[orient][k]]),
1362                                   (ypos + dy[np[orient][k]] + offsety[np[orient][k]])));
1363 #ifdef EDM_ML_DEBUG
1364       edm::LogVerbatim("HGCalGeom") << "WaferSemi " << k << " np " << np[orient][k] << " dx "
1365                                     << dx[np[orient][k]] + offsetx[np[orient][k]] << " dy "
1366                                     << dy[np[orient][k]] + offsety[np[orient][k]];
1367 #endif
1368     }
1369   } else if (part == HGCalTypes::WaferChopTwoM) {
1370     int np[6][7] = {{36, 42, 3, 4, 5, 0, 36},
1371                     {37, 43, 4, 5, 0, 1, 37},
1372                     {38, 44, 5, 0, 1, 2, 38},
1373                     {39, 45, 0, 1, 2, 3, 39},
1374                     {40, 46, 1, 2, 3, 4, 40},
1375                     {41, 47, 2, 3, 4, 5, 41}};
1376     for (int k = 0; k < 7; ++k) {
1377       xy.push_back(std::make_pair((xpos + dx[np[orient][k]] + offsetx[np[orient][k]]),
1378                                   (ypos + dy[np[orient][k]] + offsety[np[orient][k]])));
1379 #ifdef EDM_ML_DEBUG
1380       edm::LogVerbatim("HGCalGeom") << " WaferChopTwoM " << k << " np " << np[orient][k] << " dx "
1381                                     << dx[np[orient][k]] + offsetx[np[orient][k]] << " dy "
1382                                     << dy[np[orient][k]] + offsety[np[orient][k]];
1383 #endif
1384     }
1385   } else if (part == HGCalTypes::WaferSemi2) {
1386     int np[6][6] = {{12, 19, 4, 5, 0, 12},
1387                     {13, 20, 5, 0, 1, 13},
1388                     {14, 21, 0, 1, 2, 14},
1389                     {15, 22, 1, 2, 3, 15},
1390                     {16, 23, 2, 3, 4, 16},
1391                     {17, 18, 3, 4, 5, 17}};
1392     for (int k = 0; k < 6; ++k) {
1393       xy.push_back(std::make_pair((xpos + dx[np[orient][k]] + offsetx[np[orient][k]]),
1394                                   (ypos + dy[np[orient][k]] + offsety[np[orient][k]])));
1395 #ifdef EDM_ML_DEBUG
1396       edm::LogVerbatim("HGCalGeom") << "WaferSemi2 " << k << " np " << np[orient][k] << " dx "
1397                                     << dx[np[orient][k]] + offsetx[np[orient][k]] << " dy "
1398                                     << dy[np[orient][k]] + offsety[np[orient][k]];
1399 #endif
1400     }
1401   } else if (part == HGCalTypes::WaferFive2) {
1402     int np[6][6] = {{22, 15, 4, 5, 0, 22},
1403                     {23, 16, 5, 0, 1, 23},
1404                     {18, 17, 0, 1, 2, 18},
1405                     {19, 12, 1, 2, 3, 19},
1406                     {20, 13, 2, 3, 4, 20},
1407                     {21, 14, 3, 4, 5, 21}};
1408     for (int k = 0; k < 6; ++k) {
1409       xy.push_back(std::make_pair((xpos + dx[np[orient][k]] + offsetx[np[orient][k]]),
1410                                   (ypos + dy[np[orient][k]] + offsety[np[orient][k]])));
1411 #ifdef EDM_ML_DEBUG
1412       edm::LogVerbatim("HGCalGeom") << "WaferFive2 " << k << " np " << np[orient][k] << " dx "
1413                                     << dx[np[orient][k]] + offsetx[np[orient][k]] << " dy "
1414                                     << dy[np[orient][k]] + offsety[np[orient][k]];
1415 #endif
1416     }
1417   } else if (part == HGCalTypes::WaferHalf2) {
1418     int np[6][5] = {{45, 39, 4, 5, 45},
1419                     {46, 40, 5, 0, 46},
1420                     {47, 41, 0, 1, 47},
1421                     {42, 36, 1, 2, 42},
1422                     {43, 37, 2, 3, 43},
1423                     {44, 38, 3, 4, 44}};
1424     for (int k = 0; k < 5; ++k) {
1425       xy.push_back(std::make_pair((xpos + dx[np[orient][k]] + offsetx[np[orient][k]]),
1426                                   (ypos + dy[np[orient][k]] + offsety[np[orient][k]])));
1427 #ifdef EDM_ML_DEBUG
1428       edm::LogVerbatim("HGCalGeom") << "WaferHalf2 " << k << " np " << np[orient][k] << " dx "
1429                                     << dx[np[orient][k]] + offsetx[np[orient][k]] << " dy "
1430                                     << dy[np[orient][k]] + offsety[np[orient][k]];
1431 #endif
1432     }
1433   }
1434 #ifdef EDM_ML_DEBUG
1435   edm::LogVerbatim("HGCalGeom") << "I/p: part " << part << " ori " << ori << " zside " << zside << " dX " << delX
1436                                 << " dY " << delY << " xpos " << xpos << " ypos " << ypos << " O/p having " << xy.size()
1437                                 << " points:";
1438   std::ostringstream st1;
1439   for (unsigned int i = 0; i < xy.size(); ++i)
1440     st1 << " [" << i << "] " << xy[i].first << ":" << xy[i].second;
1441   edm::LogVerbatim("HGCalGeom") << st1.str();
1442 #endif
1443   return xy;
1444 }
1445 
1446 std::vector<std::pair<double, double> > HGCalWaferMask::waferXY(const int& part,
1447                                                                 const int& place,
1448                                                                 const double& waferSize,
1449                                                                 const double& offset,
1450                                                                 const double& xpos,
1451                                                                 const double& ypos,
1452                                                                 const bool& v17OrLess) {
1453   std::vector<std::pair<double, double> > xy;
1454   // Good for V17 version and uses partial wafer type & placement index
1455 #ifdef EDM_ML_DEBUG
1456   edm::LogVerbatim("HGCalGeom") << "Part " << part << " Placement Index " << place;
1457 #endif
1458   double c22(HGCalTypes::c22), c27(HGCalTypes::c27), c61(HGCalTypes::c61);
1459   double c77(HGCalTypes::c77), c88(HGCalTypes::c88);
1460   double c221(HGCalTypes::c221), c271(HGCalTypes::c271), c611(HGCalTypes::c611);
1461   double c771(HGCalTypes::c771), c881(HGCalTypes::c881);
1462   if (v17OrLess) {
1463     c22 = HGCalTypes::c22O;
1464     c27 = HGCalTypes::c27O;
1465     c61 = HGCalTypes::c61O;
1466     c77 = HGCalTypes::c77O;
1467     c88 = HGCalTypes::c88O;
1468     c221 = c22;
1469     c271 = c27;
1470     c611 = c61;
1471     c771 = c77;
1472     c881 = c88;
1473   }
1474   /*
1475     The exact contour of partial wafers are obtained by joining points on
1476     the circumference of a full wafer.
1477     Numbering the points along the edges of a hexagonal wafer, starting from
1478     the bottom corner:
1479                                    3
1480                                15     18
1481                              9           8
1482                           19               14
1483                         4                     2 
1484                        16                    23
1485                        10                     7
1486                        20                    13
1487                         5                     1
1488                           17               22
1489                             11           6
1490                                21     12
1491                                    0
1492     Depending on the wafer type and placement index, the corners
1493     are chosen in the variable *np*
1494         The points 24-35 are the same as points 12-23 with different offset
1495   */
1496   double delX = 0.5 * waferSize;
1497   double delY = delX / sin_60_;
1498   double dx[60] = {
1499       HGCalTypes::c00 * delX,
1500       HGCalTypes::c10 * delX,
1501       HGCalTypes::c10 * delX,
1502       HGCalTypes::c00 * delX,
1503       -HGCalTypes::c10 * delX,
1504       -HGCalTypes::c10 * delX,
1505       HGCalTypes::c50 * delX,
1506       HGCalTypes::c10 * delX,
1507       HGCalTypes::c50 * delX,
1508       -HGCalTypes::c50 * delX,
1509       -HGCalTypes::c10 * delX,
1510       -HGCalTypes::c50 * delX,
1511       c221 * delX,
1512       HGCalTypes::c10 * delX,
1513       c771 * delX,
1514       -c221 * delX,
1515       -HGCalTypes::c10 * delX,
1516       -c771 * delX,
1517       c221 * delX,
1518       -c771 * delX,
1519       -HGCalTypes::c10 * delX,
1520       -c221 * delX,
1521       c771 * delX,
1522       HGCalTypes::c10 * delX,
1523       c22 * delX,
1524       HGCalTypes::c10 * delX,
1525       c77 * delX,
1526       -c22 * delX,
1527       -HGCalTypes::c10 * delX,
1528       -c77 * delX,
1529       c22 * delX,
1530       -c77 * delX,
1531       -HGCalTypes::c10 * delX,
1532       -c22 * delX,
1533       c77 * delX,
1534       HGCalTypes::c10 * delX,
1535       HGCalTypes::c00 * delX,
1536       HGCalTypes::c10 * delX,
1537       HGCalTypes::c10 * delX,
1538       HGCalTypes::c00 * delX,
1539       -HGCalTypes::c10 * delX,
1540       -HGCalTypes::c10 * delX,
1541       HGCalTypes::c00 * delX,
1542       HGCalTypes::c10 * delX,
1543       HGCalTypes::c10 * delX,
1544       HGCalTypes::c00 * delX,
1545       -HGCalTypes::c10 * delX,
1546       -HGCalTypes::c10 * delX,
1547       HGCalTypes::c00 * delX,
1548       HGCalTypes::c10 * delX,
1549       HGCalTypes::c10 * delX,
1550       HGCalTypes::c00 * delX,
1551       -HGCalTypes::c10 * delX,
1552       -HGCalTypes::c10 * delX,
1553       HGCalTypes::c00 * delX,
1554       HGCalTypes::c10 * delX,
1555       HGCalTypes::c10 * delX,
1556       HGCalTypes::c00 * delX,
1557       -HGCalTypes::c10 * delX,
1558       -HGCalTypes::c10 * delX,
1559   };
1560   double dy[60] = {
1561       -HGCalTypes::c10 * delY,
1562       -HGCalTypes::c50 * delY,
1563       HGCalTypes::c50 * delY,
1564       HGCalTypes::c10 * delY,
1565       HGCalTypes::c50 * delY,
1566       -HGCalTypes::c50 * delY,
1567       -HGCalTypes::c75 * delY,
1568       HGCalTypes::c00 * delY,
1569       HGCalTypes::c75 * delY,
1570       HGCalTypes::c75 * delY,
1571       HGCalTypes::c00 * delY,
1572       -HGCalTypes::c75 * delY,
1573       -c881 * delY,
1574       -c271 * delY,
1575       c611 * delY,
1576       c881 * delY,
1577       c271 * delY,
1578       -c611 * delY,
1579       c881 * delY,
1580       c611 * delY,
1581       -c271 * delY,
1582       -c881 * delY,
1583       -c611 * delY,
1584       c271 * delY,
1585       -c88 * delY,
1586       -c27 * delY,
1587       c61 * delY,
1588       c88 * delY,
1589       c27 * delY,
1590       -c61 * delY,
1591       c88 * delY,
1592       c61 * delY,
1593       -c27 * delY,
1594       -c88 * delY,
1595       -c61 * delY,
1596       c27 * delY,
1597       -HGCalTypes::c10 * delY,
1598       -HGCalTypes::c50 * delY,
1599       HGCalTypes::c50 * delY,
1600       HGCalTypes::c10 * delY,
1601       HGCalTypes::c50 * delY,
1602       -HGCalTypes::c50 * delY,
1603       -HGCalTypes::c10 * delY,
1604       -HGCalTypes::c50 * delY,
1605       HGCalTypes::c50 * delY,
1606       HGCalTypes::c10 * delY,
1607       HGCalTypes::c50 * delY,
1608       -HGCalTypes::c50 * delY,
1609       -HGCalTypes::c10 * delY,
1610       -HGCalTypes::c50 * delY,
1611       HGCalTypes::c50 * delY,
1612       HGCalTypes::c10 * delY,
1613       HGCalTypes::c50 * delY,
1614       -HGCalTypes::c50 * delY,
1615       -HGCalTypes::c10 * delY,
1616       -HGCalTypes::c50 * delY,
1617       HGCalTypes::c50 * delY,
1618       HGCalTypes::c10 * delY,
1619       HGCalTypes::c50 * delY,
1620       -HGCalTypes::c50 * delY,
1621   };
1622 
1623   double offsetx[60] = {0.0,
1624                         -offset,
1625                         -offset,
1626                         0.0,
1627                         offset,
1628                         offset,
1629                         -offset * cos_60_,
1630                         -offset,
1631                         -offset * cos_60_,
1632                         offset * cos_60_,
1633                         offset,
1634                         offset * cos_60_,
1635                         -offset * cos_60_,
1636                         -offset,
1637                         -offset * cos_60_,
1638                         offset * cos_60_,
1639                         offset,
1640                         offset * cos_60_,
1641                         -offset * cos_60_,
1642                         offset * cos_60_,
1643                         offset,
1644                         offset * cos_60_,
1645                         -offset * cos_60_,
1646                         -offset,
1647                         0.0,
1648                         -offset,
1649                         -offset,
1650                         0.0,
1651                         offset,
1652                         offset,
1653                         0.0,
1654                         offset,
1655                         offset,
1656                         0.0,
1657                         -offset,
1658                         -offset,
1659                         -offset,
1660                         -offset / cos_60_,
1661                         -offset,
1662                         offset,
1663                         offset / cos_60_,
1664                         offset,
1665                         offset,
1666                         -offset,
1667                         -offset / cos_60_,
1668                         -offset,
1669                         offset,
1670                         offset / cos_60_,
1671                         -offset * cos_60_,
1672                         -offset,
1673                         -offset * cos_60_,
1674                         offset * cos_60_,
1675                         offset,
1676                         offset * cos_60_,
1677                         offset * cos_60_,
1678                         -offset * cos_60_,
1679                         -offset,
1680                         -offset * cos_60_,
1681                         offset * cos_60_,
1682                         offset};
1683   double offsety[60] = {offset / sin_60_,
1684                         offset / tan_60_,
1685                         -offset / tan_60_,
1686                         -offset / sin_60_,
1687                         -offset / tan_60_,
1688                         offset / tan_60_,
1689                         offset * sin_60_,
1690                         0.0,
1691                         -offset * sin_60_,
1692                         -offset * sin_60_,
1693                         0.0,
1694                         offset * sin_60_,
1695                         offset * sin_60_,
1696                         0.0,
1697                         -offset * sin_60_,
1698                         -offset * sin_60_,
1699                         0.0,
1700                         offset * sin_60_,
1701                         -offset * sin_60_,
1702                         -offset * sin_60_,
1703                         0.0,
1704                         offset * sin_60_,
1705                         offset * sin_60_,
1706                         0.0,
1707                         offset / sin_60_,
1708                         offset / tan_60_,
1709                         -offset / tan_60_,
1710                         -offset / sin_60_,
1711                         -offset / tan_60_,
1712                         offset / tan_60_,
1713                         -offset / sin_60_,
1714                         -offset / tan_60_,
1715                         offset / tan_60_,
1716                         offset / sin_60_,
1717                         offset / tan_60_,
1718                         -offset / tan_60_,
1719                         offset * tan_60_,
1720                         0,
1721                         -offset * tan_60_,
1722                         -offset * tan_60_,
1723                         0,
1724                         offset * tan_60_,
1725                         offset * tan_60_,
1726                         offset * tan_60_,
1727                         0,
1728                         -offset * tan_60_,
1729                         -offset * tan_60_,
1730                         0,
1731                         offset * sin_60_,
1732                         0,
1733                         -offset * sin_60_,
1734                         -offset * sin_60_,
1735                         0,
1736                         offset * sin_60_,
1737                         offset * sin_60_,
1738                         offset * sin_60_,
1739                         0,
1740                         -offset * sin_60_,
1741                         -offset * sin_60_,
1742                         0};
1743 
1744   if (part == HGCalTypes::WaferFull) {
1745     int np[7] = {0, 1, 2, 3, 4, 5, 0};
1746     for (int k = 0; k < 7; ++k) {
1747       xy.push_back(std::make_pair((xpos + dx[np[k]] + offsetx[np[k]]), (ypos + dy[np[k]] + offsety[np[k]])));
1748 #ifdef EDM_ML_DEBUG
1749       edm::LogVerbatim("HGCalGeom") << "WaferFull " << k << " np 7 dx " << (dx[np[k]] + offsetx[np[k]]) << " dy "
1750                                     << (dy[np[k]] + offsety[np[k]]);
1751 #endif
1752     }
1753   } else if (part == HGCalTypes::WaferLDTop) {
1754     int np[12][5] = {{0, 1, 4, 5, 0},
1755                      {1, 2, 5, 0, 1},
1756                      {2, 3, 0, 1, 2},
1757                      {3, 4, 1, 2, 3},
1758                      {4, 5, 2, 3, 4},
1759                      {5, 0, 3, 4, 5},
1760                      {0, 1, 2, 5, 0},
1761                      {5, 0, 1, 4, 5},
1762                      {4, 5, 0, 3, 4},
1763                      {3, 4, 5, 2, 3},
1764                      {2, 3, 4, 1, 2},
1765                      {1, 2, 3, 0, 1}};
1766     for (int k = 0; k < 5; ++k) {
1767       xy.push_back(std::make_pair((xpos + dx[np[place][k]] + offsetx[np[place][k]]),
1768                                   (ypos + dy[np[place][k]] + offsety[np[place][k]])));
1769 #ifdef EDM_ML_DEBUG
1770       edm::LogVerbatim("HGCalGeom") << "WaferLDTop " << k << " np " << np[place][k] << " dx "
1771                                     << dx[np[place][k]] + offsetx[np[place][k]] << " dy "
1772                                     << dy[np[place][k]] + offsety[np[place][k]];
1773 #endif
1774     }
1775   } else if (part == HGCalTypes::WaferLDBottom) {
1776     int np[12][5] = {{1, 2, 3, 4, 1},
1777                      {2, 3, 4, 5, 2},
1778                      {3, 4, 5, 0, 3},
1779                      {4, 5, 0, 1, 4},
1780                      {5, 0, 1, 2, 5},
1781                      {0, 1, 2, 3, 0},
1782                      {5, 2, 3, 4, 5},
1783                      {4, 1, 2, 3, 4},
1784                      {3, 0, 1, 2, 3},
1785                      {2, 5, 0, 1, 2},
1786                      {1, 4, 5, 0, 1},
1787                      {0, 3, 4, 5, 0}};
1788     for (int k = 0; k < 5; ++k) {
1789       xy.push_back(std::make_pair((xpos + dx[np[place][k]] + offsetx[np[place][k]]),
1790                                   (ypos + dy[np[place][k]] + offsety[np[place][k]])));
1791 #ifdef EDM_ML_DEBUG
1792       edm::LogVerbatim("HGCalGeom") << "WaferLDBottom " << k << " np " << np[place][k] << " dx "
1793                                     << dx[np[place][k]] + offsetx[np[place][k]] << " dy "
1794                                     << dy[np[place][k]] + offsety[np[place][k]];
1795 #endif
1796     }
1797   } else if (part == HGCalTypes::WaferLDLeft) {
1798     int np[12][6] = {{0, 1, 2, 8, 11, 0},
1799                      {1, 2, 3, 9, 6, 1},
1800                      {2, 3, 4, 10, 7, 2},
1801                      {3, 4, 5, 11, 8, 3},
1802                      {4, 5, 0, 6, 9, 4},
1803                      {5, 0, 1, 7, 10, 5},
1804                      {0, 6, 9, 4, 5, 0},
1805                      {5, 11, 8, 3, 4, 5},
1806                      {4, 10, 7, 2, 3, 4},
1807                      {3, 9, 6, 1, 2, 3},
1808                      {2, 8, 11, 0, 1, 2},
1809                      {1, 7, 10, 5, 0, 1}};
1810     for (int k = 0; k < 6; ++k) {
1811       xy.push_back(std::make_pair((xpos + dx[np[place][k]] + offsetx[np[place][k]]),
1812                                   (ypos + dy[np[place][k]] + offsety[np[place][k]])));
1813 #ifdef EDM_ML_DEBUG
1814       edm::LogVerbatim("HGCalGeom") << "WaferLDLeft " << k << " np " << np[place][k] << " dx "
1815                                     << dx[np[place][k]] + offsetx[np[place][k]] << " dy "
1816                                     << dy[np[place][k]] + offsety[np[place][k]];
1817 #endif
1818     }
1819   } else if (part == HGCalTypes::WaferLDRight) {
1820     int np[12][6] = {{5, 11, 8, 3, 4, 5},
1821                      {0, 6, 9, 4, 5, 0},
1822                      {1, 7, 10, 5, 0, 1},
1823                      {2, 8, 11, 0, 1, 2},
1824                      {3, 9, 6, 1, 2, 3},
1825                      {4, 10, 7, 2, 3, 4},
1826                      {1, 2, 3, 9, 6, 1},
1827                      {0, 1, 2, 8, 11, 0},
1828                      {5, 0, 1, 7, 10, 5},
1829                      {4, 5, 0, 6, 9, 4},
1830                      {3, 4, 5, 11, 8, 3},
1831                      {2, 3, 4, 10, 7, 2}};
1832     for (int k = 0; k < 6; ++k) {
1833       xy.push_back(std::make_pair((xpos + dx[np[place][k]] + offsetx[np[place][k]]),
1834                                   (ypos + dy[np[place][k]] + offsety[np[place][k]])));
1835 #ifdef EDM_ML_DEBUG
1836       edm::LogVerbatim("HGCalGeom") << "WaferLDRight " << k << " np " << np[place][k] << " dx "
1837                                     << dx[np[place][k]] + offsetx[np[place][k]] << " dy "
1838                                     << dy[np[place][k]] + offsety[np[place][k]];
1839 #endif
1840     }
1841   } else if (part == HGCalTypes::WaferLDFive) {
1842     int np[12][6] = {{0, 1, 2, 57, 53, 0},
1843                      {1, 2, 3, 58, 48, 1},
1844                      {2, 3, 4, 59, 49, 2},
1845                      {3, 4, 5, 54, 50, 3},
1846                      {4, 5, 0, 55, 51, 4},
1847                      {5, 0, 1, 56, 52, 5},
1848                      {0, 1, 3, 58, 53, 0},
1849                      {5, 0, 2, 57, 52, 5},
1850                      {4, 5, 1, 56, 51, 4},
1851                      {3, 4, 0, 55, 50, 3},
1852                      {2, 3, 5, 54, 49, 2},
1853                      {1, 2, 4, 59, 48, 1}};
1854     for (int k = 0; k < 6; ++k) {
1855       xy.push_back(std::make_pair((xpos + dx[np[place][k]] + offsetx[np[place][k]]),
1856                                   (ypos + dy[np[place][k]] + offsety[np[place][k]])));
1857 #ifdef EDM_ML_DEBUG
1858       edm::LogVerbatim("HGCalGeom") << "WaferLDFive " << k << " np " << np[place][k] << " dx "
1859                                     << dx[np[place][k]] + offsetx[np[place][k]] << " dy "
1860                                     << dy[np[place][k]] + offsety[np[place][k]];
1861 #endif
1862     }
1863   } else if (part == HGCalTypes::WaferLDThree) {
1864     int np[12][4] = {{41, 45, 4, 41},
1865                      {36, 46, 5, 36},
1866                      {37, 47, 0, 37},
1867                      {38, 42, 1, 38},
1868                      {39, 43, 2, 39},
1869                      {40, 44, 3, 40},
1870                      {43, 2, 39, 43},
1871                      {42, 1, 38, 42},
1872                      {47, 0, 37, 47},
1873                      {46, 5, 36, 46},
1874                      {45, 4, 41, 45},
1875                      {44, 3, 40, 44}};
1876     for (int k = 0; k < 4; ++k) {
1877       xy.push_back(std::make_pair((xpos + dx[np[place][k]] + offsetx[np[place][k]]),
1878                                   (ypos + dy[np[place][k]] + offsety[np[place][k]])));
1879 #ifdef EDM_ML_DEBUG
1880       edm::LogVerbatim("HGCalGeom") << "WaferLDThree " << k << " np " << np[place][k] << " dx "
1881                                     << dx[np[place][k]] + offsetx[np[place][k]] << " dy "
1882                                     << dy[np[place][k]] + offsety[np[place][k]];
1883 #endif
1884     }
1885   } else if (part == HGCalTypes::WaferHDTop) {
1886     int np[12][5] = {{0, 34, 28, 5, 0},
1887                      {1, 35, 29, 0, 1},
1888                      {2, 30, 24, 1, 2},
1889                      {3, 31, 25, 2, 3},
1890                      {4, 32, 26, 3, 4},
1891                      {5, 33, 27, 4, 5},
1892                      {0, 1, 35, 29, 0},
1893                      {5, 0, 34, 28, 5},
1894                      {4, 5, 33, 27, 4},
1895                      {3, 4, 32, 26, 3},
1896                      {2, 3, 31, 25, 2},
1897                      {1, 2, 30, 24, 1}};
1898     for (int k = 0; k < 5; ++k) {
1899       xy.push_back(std::make_pair((xpos + dx[np[place][k]] + offsetx[np[place][k]]),
1900                                   (ypos + dy[np[place][k]] + offsety[np[place][k]])));
1901 #ifdef EDM_ML_DEBUG
1902       edm::LogVerbatim("HGCalGeom") << "WaferHDTop " << k << " np " << np[place][k] << " dx "
1903                                     << dx[np[place][k]] + offsetx[np[place][k]] << " dy "
1904                                     << dy[np[place][k]] + offsety[np[place][k]];
1905 #endif
1906     }
1907   } else if (part == HGCalTypes::WaferHDBottom) {
1908     int np[12][7] = {{1, 2, 3, 4, 28, 34, 1},
1909                      {2, 3, 4, 5, 29, 35, 2},
1910                      {3, 4, 5, 0, 24, 30, 3},
1911                      {4, 5, 0, 1, 25, 31, 4},
1912                      {5, 0, 1, 2, 26, 32, 5},
1913                      {0, 1, 2, 3, 27, 33, 0},
1914                      {5, 29, 35, 2, 3, 4, 5},
1915                      {4, 28, 34, 1, 2, 3, 4},
1916                      {3, 27, 33, 0, 1, 2, 3},
1917                      {2, 26, 32, 5, 0, 1, 2},
1918                      {1, 25, 31, 4, 5, 0, 1},
1919                      {0, 24, 30, 3, 4, 5, 0}};
1920     for (int k = 0; k < 7; ++k) {
1921       xy.push_back(std::make_pair((xpos + dx[np[place][k]] + offsetx[np[place][k]]),
1922                                   (ypos + dy[np[place][k]] + offsety[np[place][k]])));
1923 #ifdef EDM_ML_DEBUG
1924       edm::LogVerbatim("HGCalGeom") << "WaferHDBottom " << k << " np " << np[place][k] << " dx "
1925                                     << dx[np[place][k]] + offsetx[np[place][k]] << " dy "
1926                                     << dy[np[place][k]] + offsety[np[place][k]];
1927 #endif
1928     }
1929   } else if (part == HGCalTypes::WaferHDLeft) {
1930     int np[12][6] = {{0, 1, 2, 14, 21, 0},
1931                      {1, 2, 3, 15, 22, 1},
1932                      {2, 3, 4, 16, 23, 2},
1933                      {3, 4, 5, 17, 18, 3},
1934                      {4, 5, 0, 12, 19, 4},
1935                      {5, 0, 1, 13, 20, 5},
1936                      {0, 12, 19, 4, 5, 0},
1937                      {5, 17, 18, 3, 4, 5},
1938                      {4, 16, 23, 2, 3, 4},
1939                      {3, 15, 22, 1, 2, 3},
1940                      {2, 14, 21, 0, 1, 2},
1941                      {1, 13, 20, 5, 0, 1}};
1942     for (int k = 0; k < 6; ++k) {
1943       xy.push_back(std::make_pair((xpos + dx[np[place][k]] + offsetx[np[place][k]]),
1944                                   (ypos + dy[np[place][k]] + offsety[np[place][k]])));
1945 #ifdef EDM_ML_DEBUG
1946       edm::LogVerbatim("HGCalGeom") << "WaferHDLeft " << k << " np " << np[place][k] << " dx "
1947                                     << dx[np[place][k]] + offsetx[np[place][k]] << " dy "
1948                                     << dy[np[place][k]] + offsety[np[place][k]];
1949 #endif
1950     }
1951   } else if (part == HGCalTypes::WaferHDRight) {
1952     int np[12][6] = {{5, 17, 18, 3, 4, 5},
1953                      {0, 12, 19, 4, 5, 0},
1954                      {1, 13, 20, 5, 0, 1},
1955                      {2, 14, 21, 0, 1, 2},
1956                      {3, 15, 22, 1, 2, 3},
1957                      {4, 16, 23, 2, 3, 4},
1958                      {1, 2, 3, 15, 22, 1},
1959                      {0, 1, 2, 14, 21, 0},
1960                      {5, 0, 1, 13, 20, 5},
1961                      {4, 5, 0, 12, 19, 4},
1962                      {3, 4, 5, 17, 18, 3},
1963                      {2, 3, 4, 16, 23, 2}};
1964     for (int k = 0; k < 6; ++k) {
1965       xy.push_back(std::make_pair((xpos + dx[np[place][k]] + offsetx[np[place][k]]),
1966                                   (ypos + dy[np[place][k]] + offsety[np[place][k]])));
1967 #ifdef EDM_ML_DEBUG
1968       edm::LogVerbatim("HGCalGeom") << "WaferHDRight " << k << " np " << np[place][k] << " dx "
1969                                     << dx[np[place][k]] + offsetx[np[place][k]] << " dy "
1970                                     << dy[np[place][k]] + offsety[np[place][k]];
1971 #endif
1972     }
1973   } else if (part == HGCalTypes::WaferHDFive) {
1974     int np[12][6] = {{0, 1, 2, 18, 17, 0},
1975                      {1, 2, 3, 19, 12, 1},
1976                      {2, 3, 4, 20, 13, 2},
1977                      {3, 4, 5, 21, 14, 3},
1978                      {4, 5, 0, 22, 15, 4},
1979                      {5, 0, 1, 23, 16, 5},
1980                      {0, 22, 15, 4, 5, 0},
1981                      {5, 21, 14, 3, 4, 5},
1982                      {4, 20, 13, 2, 3, 4},
1983                      {3, 19, 12, 1, 2, 3},
1984                      {2, 18, 17, 0, 1, 2},
1985                      {1, 23, 16, 5, 0, 1}};
1986     for (int k = 0; k < 6; ++k) {
1987       xy.push_back(std::make_pair((xpos + dx[np[place][k]] + offsetx[np[place][k]]),
1988                                   (ypos + dy[np[place][k]] + offsety[np[place][k]])));
1989 #ifdef EDM_ML_DEBUG
1990       edm::LogVerbatim("HGCalGeom") << "WaferHDFive " << k << " np " << np[place][k] << " dx "
1991                                     << dx[np[place][k]] + offsetx[np[place][k]] << " dy "
1992                                     << dy[np[place][k]] + offsety[np[place][k]];
1993 #endif
1994     }
1995   }
1996 #ifdef EDM_ML_DEBUG
1997   edm::LogVerbatim("HGCalGeom") << "I/p: part " << part << " place " << place << " dX " << delX << " dY " << delY
1998                                 << " xpos " << xpos << " ypos " << ypos << " O/p having " << xy.size() << " points:";
1999   std::ostringstream st1;
2000   for (unsigned int i = 0; i < xy.size(); ++i)
2001     st1 << " [" << i << "] " << xy[i].first << ":" << xy[i].second;
2002   edm::LogVerbatim("HGCalGeom") << st1.str();
2003 #endif
2004   return xy;
2005 }
2006 
2007 std::array<double, 4> HGCalWaferMask::maskCut(
2008     const int& part, const int& placement, const double& waferSize, const double& offset, const bool& v17OrLess) {
2009   double c22(HGCalTypes::c22), c271(HGCalTypes::c271);
2010   if (v17OrLess) {
2011     c22 = HGCalTypes::c22O;
2012     c271 = HGCalTypes::c27O;
2013   }
2014   double delX = 0.5 * waferSize;
2015   double delY = 2 * delX / sqrt3_;
2016   double tresh = std::abs(offset / cos_1[placement]);
2017   std::array<double, 4> criterion;
2018   switch (part) {
2019     case (HGCalTypes::WaferLDTop): {
2020       criterion[0] = tan_1[placement];
2021       criterion[1] = 1.0;
2022       criterion[2] = 0.0;
2023       criterion[3] = tresh;
2024       break;
2025     }
2026     case (HGCalTypes::WaferLDBottom): {
2027       criterion[0] = -tan_1[placement];
2028       criterion[1] = -1.0;
2029       criterion[2] = 0.0;
2030       criterion[3] = tresh;
2031       break;
2032     }
2033     case (HGCalTypes::WaferLDLeft): {
2034       criterion[0] = 1.0;
2035       criterion[1] = -tan_1[placement];
2036       criterion[2] = 0.0;
2037       criterion[3] = tresh;
2038       break;
2039     }
2040     case (HGCalTypes::WaferLDRight): {
2041       criterion[0] = -1.0;
2042       criterion[1] = tan_1[placement];
2043       criterion[2] = 0.0;
2044       criterion[3] = tresh;
2045       break;
2046     }
2047     case (HGCalTypes::WaferLDFive): {
2048       criterion[0] = 1;
2049       criterion[1] = -tan_1[placement];
2050       criterion[2] = ((HGCalTypes::c50 * delY) / cos_1[placement]);
2051       criterion[3] = tresh;
2052       break;
2053     }
2054     case (HGCalTypes::WaferLDThree): {
2055       criterion[0] = -1;
2056       criterion[1] = tan_1[placement];
2057       criterion[2] = -((HGCalTypes::c50 * delY) / cos_1[placement]);
2058       criterion[3] = tresh;
2059       break;
2060     }
2061     case (HGCalTypes::WaferHDTop): {
2062       criterion[0] = tan_1[placement];
2063       criterion[1] = 1;
2064       criterion[2] = ((c22 * delX) / cos_1[placement]);
2065       criterion[3] = tresh;
2066       break;
2067     }
2068     case (HGCalTypes::WaferHDBottom): {
2069       criterion[0] = -tan_1[placement];
2070       criterion[1] = -1;
2071       criterion[2] = -((c22 * delX) / cos_1[placement]);
2072       criterion[3] = tresh;
2073       break;
2074     }
2075     case (HGCalTypes::WaferHDLeft): {
2076       criterion[0] = 1.0;
2077       criterion[1] = -tan_1[placement];
2078       criterion[2] = ((c271 * delY) / cos_1[placement]);
2079       criterion[3] = tresh;
2080       break;
2081     }
2082     case (HGCalTypes::WaferHDRight): {
2083       criterion[0] = -1.0;
2084       criterion[1] = tan_1[placement];
2085       criterion[2] = -((c271 * delY) / cos_1[placement]);
2086       criterion[3] = tresh;
2087       break;
2088     }
2089     case (HGCalTypes::WaferHDFive): {
2090       criterion[0] = -1.0;
2091       criterion[1] = tan_1[placement];
2092       criterion[2] = ((c271 * delY) / cos_1[placement]);
2093       criterion[3] = tresh;
2094       break;
2095     }
2096   }
2097   criterion[1] = (placement > HGCalCell::cellPlacementExtra) ? criterion[1] : -criterion[1];
2098   return criterion;
2099 }