Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-06 04:26:57

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "Geometry/HGCalCommonData/interface/HGCalCellOffset.h"
0003 #include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
0004 #include <vector>
0005 #include <iostream>
0006 
0007 //#define EDM_ML_DEBUG
0008 
0009 HGCalCellOffset::HGCalCellOffset(double waferSize,
0010                                  int32_t nFine,
0011                                  int32_t nCoarse,
0012                                  double guardRingOffset_,
0013                                  double mouseBiteCut_,
0014                                  double sizeOffset_) {
0015   ncell_[0] = nFine;
0016   ncell_[1] = nCoarse;
0017   hgcalcell_ = std::make_unique<HGCalCell>(waferSize, nFine, nCoarse);
0018   double guardRingSizeOffset_ = guardRingOffset_ + sizeOffset_;
0019   for (int k = 0; k < 2; ++k) {  // k refers to type of wafer fine or coarse
0020     cellX_[k] = waferSize / (3 * ncell_[k]);
0021     cellY_[k] = sqrt3By2_ * cellX_[k];
0022     // For formulas used please refer to https://indico.cern.ch/event/1297259/contributions/5455745/attachments/2667954/4722855/Cell_centroid.pdf
0023     for (int j = 0; j < 6; ++j) {  // j refers to type of cell : corner, truncated, extended, truncatedMB, extendedMB
0024       if (j == HGCalCell::fullCell) {
0025         for (int i = 0; i < 6; ++i) {
0026           offsetX[k][j][i] = 0.0;
0027           offsetY[k][j][i] = 0.0;
0028           cellArea[k][j] = 3 * sqrt3By2_ * std::pow(cellX_[k], 2);
0029         }
0030       } else if (j == HGCalCell::cornerCell) {  // Offset for corner cells
0031         if (k == 0) {
0032           double h = (mouseBiteCut_ - sqrt3By2_ * cellX_[k]);
0033           double H = mouseBiteCut_ + guardRingOffset_ - (1 / sqrt3By2_ * guardRingOffset_);
0034           double h1 = H - (sqrt3_ / 4 * cellX_[k]) + (guardRingSizeOffset_ / (2 * sqrt3_));
0035           double h2 = H - (sqrt3_ / 2 * cellX_[k]) + (guardRingSizeOffset_ / (2 * sqrt3_));
0036           double totalArea = 11.0 * sqrt3_ * std::pow(cellX_[k], 2) / 8.0;
0037           double cutArea1 =
0038               (sqrt3By2_ * cellX_[k] * guardRingSizeOffset_) - (0.5 / sqrt3_ * std::pow(guardRingSizeOffset_, 2));
0039           double cutArea2 =
0040               (sqrt3_ * cellX_[k] * guardRingSizeOffset_) - (0.5 / sqrt3_ * std::pow(guardRingSizeOffset_, 2));
0041           double A1 = 2.0 * cellX_[k] * h - std::pow(h, 2) / (sqrt3_);
0042           double A2 = sqrt3By2_ * cellX_[k] * cellX_[k];
0043           double A3 = sqrt3By2_ * cellX_[k] * cellX_[k] / 4.0;
0044           double cutArea3 =
0045               sqrt3_ * std::pow(H, 2) - (1 / sqrt3By2_ * std::pow(h1, 2)) - (1 / sqrt3By2_ * std::pow(h2, 2));
0046           //std::cout << "h1 " << h1 << " h2 " << h2 << " H " << H << " cutarea1 " << cutArea1 << " cutarea2 " << cutArea2 << " cutarea3 " << cutArea3 << "  " << cellX_[k] << " " << guardRingSizeOffset_ << std::endl;
0047           double x3_1 = -(((2.0 * std::pow(h, 3)) / (3.0 * sqrt3_) - cellX_[k] * std::pow(h, 2)) / A1);
0048           double y3_1 = 0;
0049           double x3_2 = -(sqrt3By2_ * cellX_[k] / 3);
0050           double y3_2 = cellX_[k] / 6.0;
0051           double x3_3 = -(cellX_[k] * sqrt3_ / 4.0);
0052           double y3_3 = cellX_[k] * 11.0 / 12.0;
0053 
0054           double x1 = -(3.0 * sqrt3_ * cellX_[k] / 8.0 - sqrt3_ * guardRingOffset_ / 4.0);
0055           double y1 = 5.0 * cellX_[k] / 12.0 - guardRingOffset_ / 4.0;
0056           double x2 = -((0.5 * cellX_[k] - 0.5 * guardRingOffset_) * sqrt3By2_);
0057           double y2 = -(0.5 * cellX_[k] - 0.5 * guardRingOffset_) * 0.5;
0058           double x3 = (A1 * x3_1 + A2 * x3_2 + A3 * x3_3) / cutArea3;
0059           double y3 = (A1 * y3_1 + A2 * y3_2 + A3 * y3_3) / cutArea3;
0060           cellArea[k][j] = totalArea - cutArea1 - cutArea2 - cutArea3;
0061           double xMag1 =
0062               ((5.0 * sqrt3_ * cellX_[k] / 132.0) * totalArea - (cutArea1 * x1) - (cutArea2 * x2) - (cutArea3 * x3)) /
0063               (cellArea[k][j]);
0064           double yMag1 =
0065               ((19.0 * cellX_[k] / 132.0) * totalArea - (cutArea1 * y1) - (cutArea2 * y2) - (cutArea3 * y3)) /
0066               (cellArea[k][j]);
0067 
0068           double xMag = 0.5 * xMag1 + sqrt3By2_ * yMag1;
0069           double yMag = sqrt3By2_ * xMag1 - 0.5 * yMag1;
0070 
0071           std::array<double, 6> tempOffsetX = {{(sqrt3By2_ * xMag - 0.5 * yMag),
0072                                                 yMag,
0073                                                 yMag,
0074                                                 (sqrt3By2_ * xMag - 0.5 * yMag),
0075                                                 (-sqrt3By2_ * xMag - 0.5 * yMag),
0076                                                 (-sqrt3By2_ * xMag - 0.5 * yMag)}};
0077           std::array<double, 6> tempOffsetY = {{(0.5 * xMag + sqrt3By2_ * yMag),
0078                                                 xMag,
0079                                                 -xMag,
0080                                                 (-0.5 * xMag - sqrt3By2_ * yMag),
0081                                                 (0.5 * xMag - sqrt3By2_ * yMag),
0082                                                 (-0.5 * xMag + sqrt3By2_ * yMag)}};
0083 
0084           for (int i = 0; i < 6; ++i) {
0085             offsetX[k][j][i] = tempOffsetX[i];
0086             offsetY[k][j][i] = tempOffsetY[i];
0087           }
0088         } else if (k == 1) {
0089           double h = (mouseBiteCut_ - guardRingOffset_) / sqrt3By2_ - cellX_[k] / 2;
0090           double H = mouseBiteCut_ + guardRingOffset_ - (1 / sqrt3By2_ * guardRingOffset_);
0091           double h1 = H - (sqrt3_ / 4 * cellX_[k]) + (guardRingSizeOffset_ / (2 * sqrt3_));
0092           double h2 = H - (sqrt3_ / 2 * cellX_[k]) + (guardRingSizeOffset_ / (2 * sqrt3_));
0093           double totalArea = 11.0 * sqrt3_ * std::pow(cellX_[k], 2) / 8.0;
0094           double cutArea1 =
0095               (sqrt3By2_ * cellX_[k] * guardRingSizeOffset_) - (0.5 / sqrt3_ * std::pow(guardRingSizeOffset_, 2));
0096           double cutArea2 =
0097               (sqrt3_ * cellX_[k] * guardRingSizeOffset_) - (0.5 / sqrt3_ * std::pow(guardRingSizeOffset_, 2));
0098           double cutArea3 =
0099               sqrt3_ * std::pow(H, 2) - (1 / sqrt3By2_ * std::pow(h1, 2)) - (1 / sqrt3By2_ * std::pow(h2, 2));
0100           //double cutArea3 = sqrt3_ * std::pow((mouseBiteCut_ - guardRingOffset_), 2) - sqrt3By2_ * std::pow(h, 2);
0101 
0102           double x2_0 = (0.375 * cellX_[k] * cellX_[k] - (0.25 * cellX_[k] * guardRingOffset_) +
0103                          std::pow(guardRingOffset_, 2) / 18) /
0104                         (sqrt3By2_ * cellX_[k] + guardRingOffset_ / (2 * sqrt3_));
0105           double y2_0 = (sqrt3_ * cellX_[k] * guardRingOffset_ / 4 + std::pow(guardRingOffset_, 2) / (6 * sqrt3_)) /
0106                         (sqrt3By2_ * cellX_[k] + guardRingOffset_ / (2 * sqrt3_));
0107           double x3_1 = -(cellX_[k] - guardRingOffset_ - 2 * (mouseBiteCut_ - guardRingOffset_) / 3) * sqrt3By2_;
0108           double y3_1 = 0.5 * (cellX_[k] - guardRingOffset_ - 2 * (mouseBiteCut_ - guardRingOffset_) / 3);
0109           double x3_2 = -((3 * cellX_[k] / 2 - h / 3) * sqrt3By2_ + sqrt3_ * h / 6);
0110           double y3_2 = -(cellX_[k] / 4 + 4 * h / 6);
0111           double A1 = sqrt3_ * std::pow((mouseBiteCut_ - guardRingOffset_), 2);
0112           double A2 = sqrt3By2_ * std::pow(h, 2);
0113 
0114           double x1 = 0;
0115           double y1 = 0.5 * cellX_[k] - 0.5 * guardRingOffset_;
0116           double x2 = -(1.5 * sqrt3By2_ * cellX_[k] - x2_0 * 0.5 - y2_0 * sqrt3By2_);
0117           double y2 = -(0.25 * cellX_[k] - x2_0 * sqrt3By2_ + y2_0 / 2);
0118           double x3 = (A1 * x3_1 - A2 * x3_2) / (A1 - A2);
0119           double y3 = (A1 * y3_1 - A2 * y3_2) / (A1 - A2);
0120           cellArea[k][j] = totalArea - cutArea1 - cutArea2 - cutArea3;
0121           double xMag1 = ((0.0) * totalArea - (cutArea1 * x1) - (cutArea2 * x2) - (cutArea3 * x3)) / (cellArea[k][j]);
0122           double yMag1 = ((-5 * cellX_[k] / 42) * totalArea - (cutArea1 * y1) - (cutArea2 * y2) - (cutArea3 * y3)) /
0123                          (cellArea[k][j]);
0124 
0125           double xMag = -0.5 * xMag1 - sqrt3By2_ * yMag1;
0126           double yMag = sqrt3By2_ * xMag1 - 0.5 * yMag1;
0127 
0128           std::array<double, 6> tempOffsetX = {{(sqrt3By2_ * xMag - 0.5 * yMag),
0129                                                 yMag,
0130                                                 yMag,
0131                                                 (sqrt3By2_ * xMag - 0.5 * yMag),
0132                                                 (-sqrt3By2_ * xMag - 0.5 * yMag),
0133                                                 (-sqrt3By2_ * xMag - 0.5 * yMag)}};
0134           std::array<double, 6> tempOffsetY = {{(0.5 * xMag + sqrt3By2_ * yMag),
0135                                                 xMag,
0136                                                 -xMag,
0137                                                 (-0.5 * xMag - sqrt3By2_ * yMag),
0138                                                 (0.5 * xMag - sqrt3By2_ * yMag),
0139                                                 (-0.5 * xMag + sqrt3By2_ * yMag)}};
0140           for (int i = 0; i < 6; ++i) {
0141             offsetX[k][j][i] = tempOffsetX[i];
0142             offsetY[k][j][i] = tempOffsetY[i];
0143           }
0144         }
0145       } else if (j == HGCalCell::truncatedCell) {                          // Offset for truncated cells
0146         double totalArea = (5.0 * sqrt3_ / 4.0) * std::pow(cellX_[k], 2);  // Area of cell without any dead zone
0147         double cutArea =
0148             cellX_[k] * sqrt3_ * guardRingSizeOffset_;  // Area of inactive region form guardring and other effects
0149         cellArea[k][j] = totalArea - cutArea;
0150         double offMag = (((-2.0 / 15.0) * totalArea * cellX_[k]) - ((cellX_[k] - (0.5 * guardRingOffset_)) * cutArea)) /
0151                         (cellArea[k][j]);  // Magnitude of offset
0152         // (x, y) coordinates of offset for 6 sides of wafer starting from bottom left edge in clockwise direction
0153         // offset_x = -Offset_magnitude * sin(30 + 60*i) i in (0-6)
0154         // offset_y = -Offset_magnitude * cos(30 + 60*i) i in (0-6)
0155         std::array<double, 6> tempOffsetX = {
0156             {-0.5 * offMag, -offMag, -0.5 * offMag, 0.5 * offMag, offMag, 0.5 * offMag}};
0157         std::array<double, 6> tempOffsetY = {
0158             {-sqrt3By2_ * offMag, 0.0, sqrt3By2_ * offMag, sqrt3By2_ * offMag, 0.0, -sqrt3By2_ * offMag}};
0159         for (int i = 0; i < 6; ++i) {
0160           offsetX[k][j][i] = tempOffsetX[i];
0161           offsetY[k][j][i] = tempOffsetY[i];
0162         }
0163       } else if (j == HGCalCell::extendedCell) {                           //Offset for extended cells
0164         double totalArea = (7.0 * sqrt3_ / 4.0) * std::pow(cellX_[k], 2);  // Area of cell without any dead zone
0165         double cutArea =
0166             cellX_[k] * sqrt3_ * guardRingSizeOffset_;  // Area of inactive region form guardring and other effects
0167         cellArea[k][j] = totalArea - cutArea;
0168         double offMag =  // Magnitude of offset
0169             (((5.0 / 42.0) * totalArea * cellX_[k]) - ((cellX_[k] - (0.5 * guardRingOffset_))) * (cutArea)) /
0170             (cellArea[k][j]);
0171         // (x, y) coordinates of offset for 6 sides of wafer starting from bottom left edge in clockwise direction
0172         // offset_x = -Offset_magnitude * sin(30 + 60*i) i in (0-6)
0173         // offset_y = -Offset_magnitude * cos(30 + 60*i) i in (0-6)
0174         std::array<double, 6> tempOffsetX = {
0175             {-0.5 * offMag, -offMag, -0.5 * offMag, 0.5 * offMag, offMag, 0.5 * offMag}};
0176         std::array<double, 6> tempOffsetY = {
0177             {-sqrt3By2_ * offMag, 0.0, sqrt3By2_ * offMag, sqrt3By2_ * offMag, 0.0, -sqrt3By2_ * offMag}};
0178         for (int i = 0; i < 6; ++i) {
0179           offsetX[k][j][i] = tempOffsetX[i];
0180           offsetY[k][j][i] = tempOffsetY[i];
0181         }
0182       } else if (j == HGCalCell::truncatedMBCell) {
0183         double H = mouseBiteCut_ + guardRingOffset_ - (1 / sqrt3By2_ * guardRingOffset_);
0184         double h = H - (sqrt3_ / 2 * cellX_[k]) + (guardRingSizeOffset_ / (2 * sqrt3_));
0185         if (h > 0) {
0186           double totalArea = 5.0 * sqrt3_ * std::pow(cellX_[k], 2) / 4.0;
0187 
0188           double cutArea1 = (sqrt3_ * cellX_[k] * guardRingSizeOffset_);
0189           double cutArea2 = std::pow(h, 2) / sqrt3By2_;
0190 
0191           double x1 = -(0.5 * cellX_[k] - 0.5 * guardRingOffset_) * sqrt3By2_;
0192           double y1 = -(0.5 * cellX_[k] - 0.5 * guardRingOffset_) * 0.5;
0193           double x2 = -((sqrt3By2_ * cellX_[k]) - (2.0 * h) / 3.0);
0194           double y2 = 0.5 * cellX_[k] - (2.0 * h) / (3.0 * sqrt3_);
0195           cellArea[k][j] = totalArea - cutArea1 - cutArea2;
0196           //std::cout << "trunMB h " << h << " tot " << totalArea << " cutArea1 " << cutArea1 << " cutArea2 " << cutArea2 << std::endl;
0197           double xMag1 =
0198               ((sqrt3_ * cellX_[k] / 15.0) * totalArea - (cutArea1 * x1) - (cutArea2 * x2)) / (cellArea[k][j]);
0199           double yMag1 = ((cellX_[k] / 15.0) * totalArea - (cutArea1 * y1) - (cutArea2 * y2)) / (cellArea[k][j]);
0200           double xMag = -yMag1;
0201           double yMag = -xMag1;
0202 
0203           std::array<double, 6> tempOffsetX = {{(sqrt3By2_ * xMag - 0.5 * yMag),
0204                                                 (-sqrt3By2_ * xMag - 0.5 * yMag),
0205                                                 (-sqrt3By2_ * xMag - 0.5 * yMag),
0206                                                 (sqrt3By2_ * xMag - 0.5 * yMag),
0207                                                 yMag,
0208                                                 yMag}};
0209           std::array<double, 6> tempOffsetY = {{(0.5 * xMag + sqrt3By2_ * yMag),
0210                                                 (0.5 * xMag - sqrt3By2_ * yMag),
0211                                                 (-0.5 * xMag + sqrt3By2_ * yMag),
0212                                                 (-0.5 * xMag - sqrt3By2_ * yMag),
0213                                                 xMag,
0214                                                 -xMag}};
0215           for (int i = 0; i < 6; ++i) {
0216             offsetX[k][j][i] = tempOffsetX[i];
0217             offsetY[k][j][i] = tempOffsetY[i];
0218           }
0219         } else {
0220           cellArea[k][j] = cellArea[k][HGCalCell::truncatedCell];
0221           std::array<double, 6> tempOffsetX = {{offsetX[k][HGCalCell::truncatedCell][0],
0222                                                 offsetX[k][HGCalCell::truncatedCell][0],
0223                                                 offsetX[k][HGCalCell::truncatedCell][2],
0224                                                 offsetX[k][HGCalCell::truncatedCell][2],
0225                                                 offsetX[k][HGCalCell::truncatedCell][4],
0226                                                 offsetX[k][HGCalCell::truncatedCell][4]}};
0227           std::array<double, 6> tempOffsetY = {{offsetY[k][HGCalCell::truncatedCell][0],
0228                                                 offsetY[k][HGCalCell::truncatedCell][0],
0229                                                 offsetY[k][HGCalCell::truncatedCell][2],
0230                                                 offsetY[k][HGCalCell::truncatedCell][2],
0231                                                 offsetY[k][HGCalCell::truncatedCell][4],
0232                                                 offsetY[k][HGCalCell::truncatedCell][4]}};
0233           for (int i = 0; i < 6; ++i) {
0234             offsetX[k][j][i] = tempOffsetX[i];
0235             offsetY[k][j][i] = tempOffsetY[i];
0236           }
0237         }
0238       } else if (j == HGCalCell::extendedMBCell) {
0239         double H = mouseBiteCut_ + guardRingOffset_ - (1 / sqrt3By2_ * guardRingOffset_);
0240         double h = H - (sqrt3_ / 4 * cellX_[k]) + (guardRingSizeOffset_ / (2 * sqrt3_));
0241 
0242         double totalArea = 7.0 * sqrt3_ * std::pow(cellX_[k], 2) / 4.0;
0243         double cutArea1 = (sqrt3_ * cellX_[k] * guardRingSizeOffset_);
0244         double cutArea2 = std::pow(h, 2) / sqrt3By2_;
0245 
0246         double x1 = -(sqrt3By2_ * cellX_[k] - sqrt3By2_ * guardRingOffset_ / 2.0);
0247         double y1 = (0.5 * cellX_[k] - 0.25 * guardRingOffset_);
0248         double x2 = -(sqrt3By2_ * 1.5 * cellX_[k] - h / sqrt3_);
0249         double y2 = -0.25 * cellX_[k] + h / 3.0;
0250         cellArea[k][j] = totalArea - cutArea1 - cutArea2;
0251         //std::cout << H << "trunMB h " << h << " tot " << totalArea << " cutArea1 " << cutArea1 << " cutArea2 " << cutArea2 << std::endl;
0252         double xMag1 =
0253             ((-10.0 * sqrt3_ * cellX_[k] / 168.0) * totalArea - (cutArea1 * x1) - (cutArea2 * x2)) / (cellArea[k][j]);
0254         double yMag1 = ((10.0 * cellX_[k] / 168.0) * totalArea - (cutArea1 * y1) - (cutArea2 * y2)) / (cellArea[k][j]);
0255 
0256         double xMag = yMag1;
0257         double yMag = -xMag1;
0258 
0259         std::array<double, 6> tempOffsetX = {{(sqrt3By2_ * xMag - 0.5 * yMag),
0260                                               yMag,
0261                                               yMag,
0262                                               (sqrt3By2_ * xMag - 0.5 * yMag),
0263                                               (-sqrt3By2_ * xMag - 0.5 * yMag),
0264                                               (-sqrt3By2_ * xMag - 0.5 * yMag)}};
0265         std::array<double, 6> tempOffsetY = {{(0.5 * xMag + sqrt3By2_ * yMag),
0266                                               xMag,
0267                                               -xMag,
0268                                               (-0.5 * xMag - sqrt3By2_ * yMag),
0269                                               (0.5 * xMag - sqrt3By2_ * yMag),
0270                                               (-0.5 * xMag + sqrt3By2_ * yMag)}};
0271         for (int i = 0; i < 6; ++i) {
0272           offsetX[k][j][i] = tempOffsetX[i];
0273           offsetY[k][j][i] = tempOffsetY[i];
0274         }
0275       }
0276     }
0277     for (int j = HGCalCell::partiaclWaferCellsOffset; j < (11 + HGCalCell::partiaclWaferCellsOffset);
0278          ++j) {  //For cells in partial wafers
0279       if (j == (HGCalCell::halfCell)) {
0280         double totalArea = (3.0 * sqrt3_ / 4.0) * std::pow(cellX_[k], 2);
0281         double cutArea = cellX_[k] * 2.0 * guardRingOffset_ - std::pow(guardRingOffset_, 2) / sqrt3_;
0282         cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = totalArea - cutArea;
0283         double x1 = (-cellX_[k] * guardRingOffset_ + 2 * std::pow(guardRingOffset_, 2) / (3 * sqrt3_)) /
0284                     (2 * cellX_[k] - guardRingOffset_ / sqrt3_);
0285         double y1 = 0;
0286         double xMag = ((-2.0 * sqrt3_ * cellX_[k] / 9.0) * totalArea - (cutArea * x1)) /
0287                       (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0288         double yMag = (0 * totalArea - (cutArea * y1)) / (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0289 
0290         std::array<double, 6> tempOffsetX = {{(-sqrt3By2_ * xMag - 0.5 * yMag),
0291                                               (-sqrt3By2_ * xMag + 0.5 * yMag),
0292                                               yMag,
0293                                               (sqrt3By2_ * xMag + 0.5 * yMag),
0294                                               (sqrt3By2_ * xMag - 0.5 * yMag),
0295                                               -yMag}};
0296         std::array<double, 6> tempOffsetY = {{(0.5 * xMag - sqrt3By2_ * yMag),
0297                                               (-sqrt3By2_ * yMag - 0.5 * xMag),
0298                                               -xMag,
0299                                               (-0.5 * xMag + sqrt3By2_ * yMag),
0300                                               (0.5 * xMag + sqrt3By2_ * yMag),
0301                                               xMag}};
0302 
0303         for (int i = 0; i < 6; ++i) {
0304           offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetX[i];
0305           offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetY[i];
0306         }
0307       } else if (j == (HGCalCell::halfTrunCell)) {
0308         double totalArea = 5 * sqrt3_ * std::pow(cellX_[k], 2) / 8;
0309         double cutArea1 = (sqrt3By2_ * cellX_[k] * guardRingSizeOffset_) - guardRingOffset_ * guardRingSizeOffset_;
0310         double cutArea2 = (3 * cellX_[k] * guardRingOffset_) / 2 - std::pow(guardRingOffset_, 2) / (2 * sqrt3_);
0311 
0312         double x1 = -sqrt3_ * cellX_[k] / 4;
0313         double y1 = (0.5 * cellX_[k] - 0.5 * guardRingOffset_);
0314         double x2 = (-3 * cellX_[k] * guardRingOffset_ / 4 + std::pow(guardRingOffset_, 2) / (3 * sqrt3_)) /
0315                     (3 * cellX_[k] / 2 - guardRingOffset_ / (2 * sqrt3_));
0316         double y2 = (-cellX_[k] * guardRingOffset_ / (2 * sqrt3_) + std::pow(guardRingOffset_, 2) / 18 -
0317                      3 * std::pow(cellX_[k], 2) / 8) /
0318                     (3 * cellX_[k] / 2 - guardRingOffset_ / (2 * sqrt3_));
0319         cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = totalArea - cutArea1 - cutArea2;
0320         double xMag1 = ((-7 * sqrt3_ * cellX_[k] / 30) * totalArea - (cutArea1 * x1) - (cutArea2 * x2)) /
0321                        (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0322         double yMag = ((-2 * cellX_[k] / 15) * totalArea - (cutArea1 * y1) - (cutArea2 * y2)) /
0323                       (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0324         double xMag = -xMag1;
0325 
0326         std::array<double, 6> tempOffsetX = {{(-sqrt3By2_ * xMag - 0.5 * yMag),
0327                                               (-sqrt3By2_ * xMag + 0.5 * yMag),
0328                                               yMag,
0329                                               (sqrt3By2_ * xMag + 0.5 * yMag),
0330                                               (sqrt3By2_ * xMag - 0.5 * yMag),
0331                                               -yMag}};
0332         std::array<double, 6> tempOffsetY = {{(0.5 * xMag - sqrt3By2_ * yMag),
0333                                               (-sqrt3By2_ * yMag - 0.5 * xMag),
0334                                               -xMag,
0335                                               (-0.5 * xMag + sqrt3By2_ * yMag),
0336                                               (0.5 * xMag + sqrt3By2_ * yMag),
0337                                               xMag}};
0338         for (int i = 0; i < 6; ++i) {
0339           offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetX[i];
0340           offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetY[i];
0341         }
0342       } else if (j == (HGCalCell::halfExtCell)) {
0343         double totalArea = (7.0 * sqrt3_ / 8.0) * std::pow(cellX_[k], 2);
0344         double cutArea1 = cellX_[k] * sqrt3By2_ * guardRingOffset_ - std::pow(guardRingOffset_, 2);
0345         double cutArea2 = cellX_[k] * 2.0 * guardRingOffset_ - std::pow(guardRingOffset_, 2) / (2 * sqrt3_);
0346         cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = totalArea - cutArea1 - cutArea2;
0347 
0348         double x1 = -sqrt3By2_ * cellX_[k] / 2;
0349         double y1 = -(cellX_[k] - guardRingOffset_ / 2);
0350         double x2 = (-cellX_[k] * guardRingOffset_ + std::pow(guardRingOffset_, 2) / (3 * sqrt3_)) /
0351                     (2 * cellX_[k] - guardRingOffset_ / (2 * sqrt3_));
0352         double y2 = (-cellX_[k] * guardRingOffset_ / (2 * sqrt3_) + std::pow(guardRingOffset_, 2) / 18) /
0353                     (2 * cellX_[k] - guardRingOffset_ / (2 * sqrt3_));
0354         double xMag = ((-5 * sqrt3_ * cellX_[k] / 21.0) * totalArea - (cutArea1 * x1) - (cutArea2 * x2)) /
0355                       (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0356         double yMag = ((-5 * cellX_[k] / 42.0) * totalArea - (cutArea1 * y1) - (cutArea2 * y2)) /
0357                       (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0358 
0359         std::array<double, 6> tempOffsetX = {{(-sqrt3By2_ * xMag - 0.5 * yMag),
0360                                               (-sqrt3By2_ * xMag + 0.5 * yMag),
0361                                               yMag,
0362                                               (sqrt3By2_ * xMag + 0.5 * yMag),
0363                                               (sqrt3By2_ * xMag - 0.5 * yMag),
0364                                               -yMag}};
0365         std::array<double, 6> tempOffsetY = {{(0.5 * xMag - sqrt3By2_ * yMag),
0366                                               (-sqrt3By2_ * yMag - 0.5 * xMag),
0367                                               -xMag,
0368                                               (-0.5 * xMag + sqrt3By2_ * yMag),
0369                                               (0.5 * xMag + sqrt3By2_ * yMag),
0370                                               xMag}};
0371 
0372         for (int i = 0; i < 6; ++i) {
0373           offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetX[i];
0374           offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetY[i];
0375         }
0376       } else if (j == (HGCalCell::LDPartial0714Cell)) {
0377         if (k == 1) {
0378           double totalArea = (9.0 * sqrt3_ / 4.0) * std::pow(cellX_[k], 2);
0379           double cutArea1 =
0380               (3 * cellX_[k] * sqrt3By2_ * guardRingOffset_) - (std::pow(guardRingOffset_, 2) / (2 * sqrt3_));
0381           double cutArea2 = (3 * cellX_[k] * sqrt3By2_ * guardRingOffset_);
0382           double cutArea3 = sqrt3_ * std::pow((mouseBiteCut_ - (guardRingOffset_ / sqrt3By2_)), 2) / 2;
0383           double x1_0 = ((3.375 * cellX_[k] * cellX_[k]) - (cellX_[k] * 0.75 * guardRingOffset_) +
0384                          (std::pow(guardRingOffset_, 2) / 18)) /
0385                         ((3 * cellX_[k] * sqrt3By2_) - (guardRingOffset_ / (2 * sqrt3_)));
0386           double y1_0 =
0387               ((3 * cellX_[k] * sqrt3By2_ * guardRingOffset_ / 2) - (std::pow(guardRingOffset_, 2) / (6 * sqrt3_))) /
0388               ((3 * cellX_[k] * sqrt3By2_) - (guardRingOffset_ / (2 * sqrt3_)));
0389 
0390           double x2_0 = (3 * sqrt3By2_ * cellX_[k] / 2);
0391           double y2_0 = guardRingOffset_ / 2;
0392 
0393           double x1 = (cellX_[k] / 2 - guardRingOffset_) * sqrt3By2_ + x1_0 * 0.5 + y1_0 * sqrt3By2_;
0394           double y1 = cellX_[k] + (cellX_[k] / 2 - guardRingOffset_) * 0.5 - x1_0 * sqrt3By2_ + y1_0 * 0.5;
0395 
0396           double x2 = x2_0 - sqrt3By2_ * cellX_[k];
0397           double y2 = -(cellX_[k] - y2_0);
0398 
0399           double x3 = sqrt3_ * cellX_[k] - mouseBiteCut_ + (mouseBiteCut_ - (guardRingOffset_ / sqrt3By2_)) / 3;
0400           double y3 = -(cellX_[k] - sqrt3_ * (mouseBiteCut_ - (guardRingOffset_ / sqrt3By2_)) / 3 - guardRingOffset_);
0401 
0402           cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = totalArea - cutArea1 - cutArea2 - cutArea3;
0403           double xMag = ((sqrt3_ * cellX_[k] / 8) * totalArea - (cutArea1 * x1) - (cutArea2 * x2) - (cutArea3 * x3)) /
0404                         (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0405           double yMag = ((-1 * cellX_[k] / 8) * totalArea - (cutArea1 * y1) - (cutArea2 * y2) - (cutArea3 * y3)) /
0406                         (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0407 
0408           std::array<double, 6> tempOffsetX = {{(-sqrt3By2_ * xMag - 0.5 * yMag),
0409                                                 (-sqrt3By2_ * xMag + 0.5 * yMag),
0410                                                 yMag,
0411                                                 (sqrt3By2_ * xMag + 0.5 * yMag),
0412                                                 (sqrt3By2_ * xMag - 0.5 * yMag),
0413                                                 -yMag}};
0414           std::array<double, 6> tempOffsetY = {{(0.5 * xMag - sqrt3By2_ * yMag),
0415                                                 (-sqrt3By2_ * yMag - 0.5 * xMag),
0416                                                 -xMag,
0417                                                 (-0.5 * xMag + sqrt3By2_ * yMag),
0418                                                 (0.5 * xMag + sqrt3By2_ * yMag),
0419                                                 xMag}};
0420 
0421           for (int i = 0; i < 6; ++i) {
0422             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetX[i];
0423             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetY[i];
0424           }
0425         } else {
0426           cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = 0.0;
0427           for (int i = 0; i < 6; ++i) {
0428             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0429             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0430           }
0431         }
0432       } else if (j == (HGCalCell::LDPartial0209Cell)) {
0433         if (k == 1) {
0434           double totalArea = (23.0 * sqrt3_ / 8.0) * std::pow(cellX_[k], 2);
0435           double cutArea1 =
0436               (5 * cellX_[k] * sqrt3By2_ * guardRingOffset_) - (std::pow(guardRingOffset_, 2) / (2 * sqrt3_));
0437           double cutArea2 = (4 * cellX_[k] * guardRingOffset_);
0438           double cutArea3 = std::pow(mouseBiteCut_, 2) / sqrt3_;
0439 
0440           double x1_0 = (9.375 * cellX_[k] * cellX_[k] - (cellX_[k] * 1.25 * guardRingOffset_) +
0441                          (std::pow(guardRingOffset_, 2) / 18)) /
0442                         ((5 * cellX_[k] * sqrt3By2_) - (guardRingOffset_ / (2 * sqrt3_)));
0443           double y1_0 =
0444               ((5 * cellX_[k] * sqrt3By2_ * guardRingOffset_ / 2) - (std::pow(guardRingOffset_, 2) / (6 * sqrt3_))) /
0445               ((5 * cellX_[k] * sqrt3By2_) - (guardRingOffset_ / (2 * sqrt3_)));
0446 
0447           double x1 = (1.5 * cellX_[k]) * sqrt3By2_ - x1_0 * 0.5 - y1_0 * sqrt3By2_;
0448           double y1 = -0.25 * cellX_[k] + x1_0 * sqrt3By2_ - y1_0 * 0.5;
0449           double x2 = -(sqrt3By2_ * cellX_[k] - 0.5 * guardRingOffset_);
0450           double y2 = 1.5 * cellX_[k];
0451           double x3 = -(sqrt3By2_ * cellX_[k] - mouseBiteCut_ / 3);
0452           double y3 = 3.5 * cellX_[k] - (5 * mouseBiteCut_) / 3 * sqrt3_;
0453 
0454           cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = totalArea - cutArea1 - cutArea2 - cutArea3;
0455           double xMag =
0456               ((-9 * cellX_[k] / (sqrt3_ * 92)) * totalArea - (cutArea1 * x1) - (cutArea2 * x2) - (cutArea3 * x3)) /
0457               (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0458           double yMag =
0459               ((199 * cellX_[k] / (sqrt3_ * 276)) * totalArea - (cutArea1 * y1) - (cutArea2 * y2) - (cutArea3 * y3)) /
0460               (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0461 
0462           std::array<double, 6> tempOffsetX = {{(-sqrt3By2_ * xMag - 0.5 * yMag),
0463                                                 (-sqrt3By2_ * xMag + 0.5 * yMag),
0464                                                 yMag,
0465                                                 (sqrt3By2_ * xMag + 0.5 * yMag),
0466                                                 (sqrt3By2_ * xMag - 0.5 * yMag),
0467                                                 -yMag}};
0468           std::array<double, 6> tempOffsetY = {{(0.5 * xMag - sqrt3By2_ * yMag),
0469                                                 (-sqrt3By2_ * yMag - 0.5 * xMag),
0470                                                 -xMag,
0471                                                 (-0.5 * xMag + sqrt3By2_ * yMag),
0472                                                 (0.5 * xMag + sqrt3By2_ * yMag),
0473                                                 xMag}};
0474           for (int i = 0; i < 6; ++i) {
0475             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetX[i];
0476             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetY[i];
0477           }
0478         } else {
0479           cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = 0.0;
0480           for (int i = 0; i < 6; ++i) {
0481             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0482             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0483           }
0484         }
0485       } else if (j == (HGCalCell::LDPartial0007Cell)) {
0486         if (k == 1) {
0487           double totalArea = (5.0 * sqrt3_ / 4.0) * std::pow(cellX_[k], 2);
0488           double cutArea1 = (cellX_[k] * guardRingOffset_);
0489           double cutArea2 = (sqrt3_ * cellX_[k] * guardRingOffset_);
0490           double h = cellX_[k] - (sqrt3By2_ * cellX_[k] - mouseBiteCut_) / sqrt3By2_;
0491           double cutArea3 = sqrt3_ * std::pow(h, 2) / 2;
0492 
0493           double x1 = cellX_[k] * sqrt3By2_ - guardRingOffset_ / 2;
0494           double y1 = 0;
0495           double x2 = 0;
0496           double y2 = 0.5 * cellX_[k] - guardRingOffset_ / 2;
0497           double x3 = sqrt3By2_ * cellX_[k] - guardRingOffset_ - h / sqrt3_;
0498           double y3 = 0.5 * cellX_[k] - guardRingOffset_ - h / 3;
0499 
0500           cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = totalArea - cutArea1 - cutArea2 - cutArea3;
0501           double xMag = ((0.0) * totalArea - (cutArea1 * x1) - (cutArea2 * x2) - (cutArea3 * x3)) /
0502                         (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0503           double yMag = ((-2 * cellX_[k] / 15) * totalArea - (cutArea1 * y1) - (cutArea2 * y2) - (cutArea3 * y3)) /
0504                         (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0505 
0506           std::array<double, 6> tempOffsetX = {{(-sqrt3By2_ * xMag - 0.5 * yMag),
0507                                                 (-sqrt3By2_ * xMag + 0.5 * yMag),
0508                                                 yMag,
0509                                                 (sqrt3By2_ * xMag + 0.5 * yMag),
0510                                                 (sqrt3By2_ * xMag - 0.5 * yMag),
0511                                                 -yMag}};
0512           std::array<double, 6> tempOffsetY = {{(0.5 * xMag - sqrt3By2_ * yMag),
0513                                                 (-sqrt3By2_ * yMag - 0.5 * xMag),
0514                                                 -xMag,
0515                                                 (-0.5 * xMag + sqrt3By2_ * yMag),
0516                                                 (0.5 * xMag + sqrt3By2_ * yMag),
0517                                                 xMag}};
0518           for (int i = 0; i < 6; ++i) {
0519             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetX[i];
0520             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetY[i];
0521           }
0522         } else {
0523           cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = 0.0;
0524           for (int i = 0; i < 6; ++i) {
0525             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0526             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0527           }
0528         }
0529       } else if (j == (HGCalCell::LDPartial0815Cell)) {
0530         if (k == 1) {
0531           double totalArea = sqrt3_ * std::pow(cellX_[k], 2);
0532           double cutArea1 = (sqrt3_ * cellX_[k] * guardRingOffset_);
0533           double cutArea2 = (sqrt3_ * cellX_[k] * guardRingOffset_) - std::pow(guardRingOffset_, 2) / (2 * sqrt3_);
0534           double cutArea3 = sqrt3_ * std::pow((mouseBiteCut_ - guardRingOffset_ / sqrt3By2_), 2) / 2;
0535 
0536           double x2_0 = (1.5 * cellX_[k] * cellX_[k] - (0.5 * cellX_[k] * guardRingOffset_) +
0537                          std::pow(guardRingOffset_, 2) / 18) /
0538                         (sqrt3_ * cellX_[k] - guardRingOffset_ / (2 * sqrt3_));
0539           double y2_0 = (sqrt3By2_ * cellX_[k] * guardRingOffset_ - std::pow(guardRingOffset_, 2) / (sqrt3_ * 3)) /
0540                         (sqrt3_ * cellX_[k] - guardRingOffset_ / (2 * sqrt3_));
0541           double x1 = 0;
0542           double y1 = 0.5 * cellX_[k] - guardRingOffset_ / 2;
0543           double x2 = x2_0 * 0.5 - y2_0 * sqrt3By2_;
0544           double y2 = -(cellX_[k] - (x2_0 * sqrt3By2_ + y2_0 * 0.5));
0545           double x3 = sqrt3By2_ * cellX_[k] - mouseBiteCut_ + (mouseBiteCut_ - guardRingOffset_ / sqrt3By2_) / 3;
0546           double y3 = cellX_[k] - (mouseBiteCut_ - guardRingOffset_ / sqrt3By2_) / sqrt3_ - guardRingOffset_;
0547 
0548           cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = totalArea - cutArea1 - cutArea2 - cutArea3;
0549           double xMag = -((-sqrt3_ * cellX_[k] / 9) * totalArea - (cutArea1 * x1) - (cutArea2 * x2) - (cutArea3 * x3)) /
0550                         (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0551           double yMag = ((-cellX_[k] / 15) * totalArea - (cutArea1 * y1) - (cutArea2 * y2) - (cutArea3 * y3)) /
0552                         (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0553 
0554           std::array<double, 6> tempOffsetX = {{(-sqrt3By2_ * xMag - 0.5 * yMag),
0555                                                 (-sqrt3By2_ * xMag + 0.5 * yMag),
0556                                                 yMag,
0557                                                 (sqrt3By2_ * xMag + 0.5 * yMag),
0558                                                 (sqrt3By2_ * xMag - 0.5 * yMag),
0559                                                 -yMag}};
0560           std::array<double, 6> tempOffsetY = {{(0.5 * xMag - sqrt3By2_ * yMag),
0561                                                 (-sqrt3By2_ * yMag - 0.5 * xMag),
0562                                                 -xMag,
0563                                                 (-0.5 * xMag + sqrt3By2_ * yMag),
0564                                                 (0.5 * xMag + sqrt3By2_ * yMag),
0565                                                 xMag}};
0566           for (int i = 0; i < 6; ++i) {
0567             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetX[i];
0568             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetY[i];
0569           }
0570         } else {
0571           for (int i = 0; i < 6; ++i) {
0572             cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = 0.0;
0573             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0574             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0575           }
0576         }
0577       } else if (j == (HGCalCell::LDPartial1415Cell)) {
0578         if (k == 1) {
0579           double totalArea = 7 * sqrt3_ * std::pow(cellX_[k], 2) / 4;
0580           double cutArea1 = (3 * cellX_[k] * guardRingOffset_);
0581           double cutArea2 = (2 * sqrt3_ * cellX_[k] * guardRingOffset_) - std::pow(guardRingOffset_, 2) * sqrt3By2_;
0582           double cutArea3 = std::pow((mouseBiteCut_ - guardRingOffset_), 2) / sqrt3_;
0583 
0584           double x2_0 = (6 * cellX_[k] * cellX_[k] - std::pow(guardRingOffset_, 2)) /
0585                         (2 * sqrt3_ * cellX_[k] - guardRingOffset_ * sqrt3By2_);
0586           double y2_0 = (sqrt3_ * cellX_[k] * guardRingOffset_ - std::pow(guardRingOffset_, 2) / sqrt3_) /
0587                         (2 * sqrt3_ * cellX_[k] - guardRingOffset_ * sqrt3By2_);
0588           double x1 = -sqrt3By2_ * cellX_[k] + guardRingOffset_ / 2;
0589           double y1 = -cellX_[k];
0590           double x2 = sqrt3By2_ * cellX_[k] - x2_0 * 0.5 - y2_0 * sqrt3By2_;
0591           double y2 = 0.5 * cellX_[k] - x2_0 * sqrt3By2_ + y2_0 * 0.5;
0592           double h = (mouseBiteCut_ - guardRingOffset_) / sqrt3By2_;
0593           double x3 = -(cellX_[k] - h / 3 - guardRingOffset_) * sqrt3By2_;
0594           double y3 = 5 * h / 6 - 5 * cellX_[k] / 2;
0595 
0596           cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = totalArea - cutArea1 - cutArea2 - cutArea3;
0597           double xMag =
0598               ((-2 * cellX_[k] / (7 * sqrt3_)) * totalArea - (cutArea1 * x1) - (cutArea2 * x2) - (cutArea3 * x3)) /
0599               (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0600           double yMag = ((-cellX_[k] / 3) * totalArea - (cutArea1 * y1) - (cutArea2 * y2) - (cutArea3 * y3)) /
0601                         (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0602 
0603           std::array<double, 6> tempOffsetX = {{(-sqrt3By2_ * xMag - 0.5 * yMag),
0604                                                 (-sqrt3By2_ * xMag + 0.5 * yMag),
0605                                                 yMag,
0606                                                 (sqrt3By2_ * xMag + 0.5 * yMag),
0607                                                 (sqrt3By2_ * xMag - 0.5 * yMag),
0608                                                 -yMag}};
0609           std::array<double, 6> tempOffsetY = {{(0.5 * xMag - sqrt3By2_ * yMag),
0610                                                 (-sqrt3By2_ * yMag - 0.5 * xMag),
0611                                                 -xMag,
0612                                                 (-0.5 * xMag + sqrt3By2_ * yMag),
0613                                                 (0.5 * xMag + sqrt3By2_ * yMag),
0614                                                 xMag}};
0615           for (int i = 0; i < 6; ++i) {
0616             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetX[i];
0617             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetY[i];
0618           }
0619         } else {
0620           for (int i = 0; i < 6; ++i) {
0621             cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = 0.0;
0622             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0623             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0624           }
0625         }
0626       } else if (j == (HGCalCell::LDPartial1515Cell)) {
0627         if (k == 1) {
0628           double totalArea = 7 * sqrt3_ * std::pow(cellX_[k], 2) / 8;
0629           double cutArea1 = (2 * cellX_[k] * guardRingOffset_);
0630           double cutArea2 = (sqrt3By2_ * cellX_[k] * guardRingOffset_);
0631           double cutArea3 = cellX_[k] * (mouseBiteCut_ - guardRingOffset_) - (sqrt3_ * cellX_[k] * cellX_[k] / 8);
0632 
0633           double x1 = -guardRingOffset_ / 2;
0634           double y1 = 0;
0635           double x2 = -(sqrt3By2_ * cellX_[k] / 2);
0636           double y2 = -(cellX_[k] - 0.5 * guardRingOffset_);
0637           double x3 = (cellX_[k] * cellX_[k] / 8 - sqrt3_ * cellX_[k] * (mouseBiteCut_ - guardRingOffset_) / 4) /
0638                       ((mouseBiteCut_ - guardRingOffset_) - sqrt3_ * cellX_[k] / 8);
0639           double y3 =
0640               (std::pow((mouseBiteCut_ - guardRingOffset_), 2) / sqrt3_ -
0641                (1.25 * cellX_[k] * (mouseBiteCut_ - guardRingOffset_)) + 7 * sqrt3_ * cellX_[k] * cellX_[k] / 48) /
0642               ((mouseBiteCut_ - guardRingOffset_) - sqrt3_ * cellX_[k] / 8);
0643 
0644           cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = totalArea - cutArea1 - cutArea2 - cutArea3;
0645           double xMag = (-(cellX_[k] / (sqrt3_)) * totalArea - (cutArea1 * x1) - (cutArea2 * x2) - (cutArea3 * x3)) /
0646                         (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0647           double yMag = ((-5 * cellX_[k] / 42) * totalArea - (cutArea1 * y1) - (cutArea2 * y2) - (cutArea3 * y3)) /
0648                         (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0649 
0650           std::array<double, 6> tempOffsetX = {{(-sqrt3By2_ * xMag - 0.5 * yMag),
0651                                                 (-sqrt3By2_ * xMag + 0.5 * yMag),
0652                                                 yMag,
0653                                                 (sqrt3By2_ * xMag + 0.5 * yMag),
0654                                                 (sqrt3By2_ * xMag - 0.5 * yMag),
0655                                                 -yMag}};
0656           std::array<double, 6> tempOffsetY = {{(0.5 * xMag - sqrt3By2_ * yMag),
0657                                                 (-sqrt3By2_ * yMag - 0.5 * xMag),
0658                                                 -xMag,
0659                                                 (-0.5 * xMag + sqrt3By2_ * yMag),
0660                                                 (0.5 * xMag + sqrt3By2_ * yMag),
0661                                                 xMag}};
0662           for (int i = 0; i < 6; ++i) {
0663             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetX[i];
0664             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetY[i];
0665           }
0666         } else {
0667           for (int i = 0; i < 6; ++i) {
0668             cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = 0.0;
0669             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0670             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0671           }
0672         }
0673       } else if (j == (HGCalCell::HDPartial0920Cell)) {
0674         if (k == 0) {
0675           double totalArea = 37 * sqrt3_ * std::pow(cellX_[k], 2) / 24;
0676           double cutArea1 = (4 * cellX_[k] * guardRingOffset_) / sqrt3_;
0677           double cutArea2 =
0678               (7 * cellX_[k] * guardRingOffset_) / (2 * sqrt3_) - std::pow(guardRingOffset_, 2) / (2 * sqrt3_);
0679 
0680           double x1 = cellX_[k] / (2 * sqrt3_);
0681           double y1 = -(0.5 * cellX_[k] - 0.5 * guardRingOffset_);
0682           double x2_0 = ((2.041 * cellX_[k] * cellX_[k]) - (cellX_[k] * 0.583 * guardRingOffset_) +
0683                          (std::pow(guardRingOffset_, 2) / 18)) /
0684                         ((7 * cellX_[k] / (2 * sqrt3_)) - (guardRingOffset_ / (2 * sqrt3_)));
0685           double y2_0 =
0686               ((7 * cellX_[k] * guardRingOffset_ / (4 * sqrt3_)) - std::pow(guardRingOffset_, 2) / (6 * sqrt3_)) /
0687               ((7 * cellX_[k] / (2 * sqrt3_)) - (guardRingOffset_ / (2 * sqrt3_)));
0688 
0689           double x2 = (0.5 * x2_0) - (sqrt3By2_ * y2_0) + (cellX_[k] * 0.5 * sqrt3By2_);
0690           double y2 = -(0.5 * y2_0) - (sqrt3By2_ * x2_0) + (cellX_[k] * 1.25);
0691           cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = totalArea - cutArea1 - cutArea2;
0692           double xMag = ((25 * sqrt3_ * cellX_[k] / 148) * totalArea - (cutArea1 * x1) - (cutArea2 * x2)) /
0693                         (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0694           double yMag = ((73 * cellX_[k] / 444) * totalArea - (cutArea1 * y1) - (cutArea2 * y2)) /
0695                         (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0696 
0697           std::array<double, 6> tempOffsetX = {{(-sqrt3By2_ * xMag - 0.5 * yMag),
0698                                                 (-sqrt3By2_ * xMag + 0.5 * yMag),
0699                                                 yMag,
0700                                                 (sqrt3By2_ * xMag + 0.5 * yMag),
0701                                                 (sqrt3By2_ * xMag - 0.5 * yMag),
0702                                                 -yMag}};
0703           std::array<double, 6> tempOffsetY = {{(0.5 * xMag - sqrt3By2_ * yMag),
0704                                                 (-sqrt3By2_ * yMag - 0.5 * xMag),
0705                                                 -xMag,
0706                                                 (-0.5 * xMag + sqrt3By2_ * yMag),
0707                                                 (0.5 * xMag + sqrt3By2_ * yMag),
0708                                                 xMag}};
0709           for (int i = 0; i < 6; ++i) {
0710             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetX[i];
0711             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetY[i];
0712           }
0713         } else {
0714           for (int i = 0; i < 6; ++i) {
0715             cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = 0.0;
0716             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0717             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0718           }
0719         }
0720       } else if (j == (HGCalCell::HDPartial1021Cell)) {
0721         if (k == 0) {
0722           double totalArea = 11 * sqrt3_ * std::pow(cellX_[k], 2) / 6;
0723           double cutArea1 = (5 * cellX_[k] * guardRingOffset_) / (2 * sqrt3_);
0724           double cutArea2 =
0725               (5 * cellX_[k] * guardRingOffset_) / (2 * sqrt3_) - std::pow(guardRingOffset_, 2) / (2 * sqrt3_);
0726 
0727           double x1 = -cellX_[k] / (4 * sqrt3_);
0728           double y1 = cellX_[k] - 0.5 * guardRingOffset_;
0729           double x2_0 = ((1.041 * cellX_[k] * cellX_[k]) - (cellX_[k] * 0.416 * guardRingOffset_) +
0730                          (std::pow(guardRingOffset_, 2) / 18.0)) /
0731                         ((5.0 * cellX_[k] / (2.0 * sqrt3_)) - (guardRingOffset_ / (2.0 * sqrt3_)));
0732           double y2_0 =
0733               ((5.0 * cellX_[k] * guardRingOffset_ / (4.0 * sqrt3_)) - std::pow(guardRingOffset_, 2) / (6 * sqrt3_)) /
0734               ((5.0 * cellX_[k] / (2.0 * sqrt3_)) - (guardRingOffset_ / (2.0 * sqrt3_)));
0735 
0736           double x2 = -(0.5 * x2_0) + (sqrt3By2_ * y2_0) + (cellX_[k] * 1.5 * sqrt3By2_);
0737           double y2 = -(0.5 * y2_0) + (sqrt3By2_ * x2_0) - cellX_[k];
0738           cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = totalArea - cutArea1 - cutArea2;
0739           double xMag = ((47.0 * cellX_[k] / (528.0 * sqrt3_)) * totalArea - (cutArea1 * x1) - (cutArea2 * x2)) /
0740                         (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0741           double yMag = ((47.0 * cellX_[k] / 528.0) * totalArea - (cutArea1 * y1) - (cutArea2 * y2)) /
0742                         (cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset]);
0743 
0744           std::array<double, 6> tempOffsetX = {{(-sqrt3By2_ * xMag - 0.5 * yMag),
0745                                                 (-sqrt3By2_ * xMag + 0.5 * yMag),
0746                                                 yMag,
0747                                                 (sqrt3By2_ * xMag + 0.5 * yMag),
0748                                                 (sqrt3By2_ * xMag - 0.5 * yMag),
0749                                                 -yMag}};
0750           std::array<double, 6> tempOffsetY = {{(0.5 * xMag - sqrt3By2_ * yMag),
0751                                                 (-sqrt3By2_ * yMag - 0.5 * xMag),
0752                                                 -xMag,
0753                                                 (-0.5 * xMag + sqrt3By2_ * yMag),
0754                                                 (0.5 * xMag + sqrt3By2_ * yMag),
0755                                                 xMag}};
0756           for (int i = 0; i < 6; ++i) {
0757             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetX[i];
0758             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = tempOffsetY[i];
0759           }
0760         } else {
0761           for (int i = 0; i < 6; ++i) {
0762             cellAreaPartial[k][j - HGCalCell::partiaclWaferCellsOffset] = 0.0;
0763             offsetPartialX[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0764             offsetPartialY[k][j - HGCalCell::partiaclWaferCellsOffset][i] = 0.0;
0765           }
0766         }
0767       }
0768     }
0769   }
0770 
0771 #ifdef EDM_ML_DEBUG
0772   edm::LogVerbatim("HGCalGeom") << "HGCalCellOffset initialized with waferSize " << waferSize << " number of cells "
0773                                 << nFine << ":" << nCoarse << " Guardring offset " << guardRingOffset_ << " Mousebite "
0774                                 << mouseBiteCut_;
0775 #endif
0776 }
0777 
0778 std::pair<double, double> HGCalCellOffset::cellOffsetUV2XY1(int32_t u, int32_t v, int32_t placementIndex, int32_t type) {
0779   if (type != 0)
0780     type = 1;
0781   double x_off(0), y_off(0);
0782   std::pair<int, int> cell = hgcalcell_->cellType(u, v, ncell_[type], placementIndex);
0783   int cellPos = cell.first;
0784   int cellType = cell.second;
0785   if (cellType == HGCalCell::truncatedCell || cellType == HGCalCell::extendedCell) {
0786     x_off = offsetX[type][cellType][cellPos - HGCalCell::bottomLeftEdge];
0787     y_off = offsetY[type][cellType][cellPos - HGCalCell::bottomLeftEdge];
0788   } else if ((cellType == HGCalCell::cornerCell) || (cellType == HGCalCell::truncatedMBCell) ||
0789              (cellType == HGCalCell::extendedMBCell)) {
0790     // The offset fo corner cells, is flipped along y-axis for 60 degree rotation of wafer
0791     // and from forward to backward wafers
0792     if (((placementIndex >= HGCalCell::cellPlacementExtra) && (placementIndex % 2 == 0)) ||
0793         ((placementIndex < HGCalCell::cellPlacementExtra) && (placementIndex % 2 == 1))) {
0794       cellPos = HGCalCell::bottomCorner + (6 + HGCalCell::bottomCorner - cellPos) % 6;
0795     }
0796     x_off = offsetX[type][cellType][cellPos - HGCalCell::bottomCorner];
0797     y_off = offsetY[type][cellType][cellPos - HGCalCell::bottomCorner];
0798     if (((placementIndex >= HGCalCell::cellPlacementExtra) && (placementIndex % 2 == 0)) ||
0799         ((placementIndex < HGCalCell::cellPlacementExtra) && (placementIndex % 2 == 1))) {
0800       x_off = -1 * x_off;
0801     }
0802   }
0803   return std::make_pair(x_off, y_off);
0804 }
0805 
0806 std::pair<double, double> HGCalCellOffset::cellOffsetUV2XY1(
0807     int32_t u, int32_t v, int32_t placementIndex, int32_t type, int32_t partialType) {
0808   if (type != 0)
0809     type = 1;
0810   std::pair<double, double> offset = HGCalCellOffset::cellOffsetUV2XY1(u, v, placementIndex, type);
0811   double x_off = offset.first;
0812   double y_off = offset.second;
0813   std::pair<int, int> cell = hgcalcell_->cellType(u, v, ncell_[type], placementIndex, partialType);
0814   int cellPos = cell.first;
0815   int cellType = cell.second;
0816   if ((cellType >= HGCalCell::partiaclWaferCellsOffset) || (cellPos >= HGCalCell::partiaclCellsPosOffset)) {
0817     if (cellType == HGCalCell::truncatedCell || cellType == HGCalCell::extendedCell) {
0818       if (cellPos == HGCalCell::topCell) {
0819         int Pos(0);
0820         Pos = (placementIndex + HGCalCell::topRightEdge - HGCalCell::bottomLeftEdge) % HGCalCell::cellPlacementExtra;
0821         x_off = (placementIndex >= HGCalCell::cellPlacementExtra) ? -offsetX[type][cellType][Pos]
0822                                                                   : offsetX[type][cellType][Pos];
0823         y_off = offsetY[type][cellType][Pos];
0824       } else if (cellPos == HGCalCell::bottomCell) {
0825         int Pos(0);
0826         Pos = (placementIndex) % HGCalCell::cellPlacementExtra;
0827         x_off = (placementIndex >= HGCalCell::cellPlacementExtra) ? -offsetX[type][cellType][Pos]
0828                                                                   : offsetX[type][cellType][Pos];
0829         y_off = offsetY[type][cellType][Pos];
0830       }
0831     } else if ((cellType == HGCalCell::halfCell) || (cellType == HGCalCell::halfTrunCell) ||
0832                (cellType == HGCalCell::halfExtCell) || (cellType == HGCalCell::LDPartial0714Cell) ||
0833                (cellType == HGCalCell::LDPartial0815Cell) || (cellType == HGCalCell::HDPartial0920Cell) ||
0834                (cellType == HGCalCell::HDPartial1021Cell)) {
0835       int cellType1 = cellType - HGCalCell::partiaclWaferCellsOffset;
0836       if (cellType == HGCalCell::halfCell) {
0837         std::cout << u << ":" << v << " 2" << std::endl;
0838       }
0839       if (cellPos == HGCalCell::leftCell) {
0840         int placeIndex = placementIndex % HGCalCell::cellPlacementExtra;
0841         x_off = offsetPartialX[type][cellType1][placeIndex];
0842         y_off = offsetPartialY[type][cellType1][placeIndex];
0843       } else if (cellPos == HGCalCell::rightCell) {
0844         int placeIndex = (HGCalCell::cellPlacementExtra - placementIndex) % HGCalCell::cellPlacementExtra;
0845         x_off = -offsetPartialX[type][cellType1][placeIndex];
0846         y_off = offsetPartialY[type][cellType1][placeIndex];
0847       }
0848       x_off = placementIndex < HGCalCell::cellPlacementExtra ? x_off : -x_off;
0849     } else if ((cellType == HGCalCell::LDPartial0209Cell) || (cellType == HGCalCell::LDPartial0007Cell) ||
0850                (cellType == HGCalCell::LDPartial1415Cell) || (cellType == HGCalCell::LDPartial1515Cell)) {
0851       int cellType1 = cellType - HGCalCell::partiaclWaferCellsOffset;
0852       int placeIndex = placementIndex % HGCalCell::cellPlacementExtra;
0853       x_off = offsetPartialX[type][cellType1][placeIndex];
0854       y_off = offsetPartialY[type][cellType1][placeIndex];
0855       x_off = placementIndex < HGCalCell::cellPlacementExtra ? x_off : -x_off;
0856     }
0857   }
0858   return std::make_pair(x_off, y_off);
0859 }
0860 
0861 double HGCalCellOffset::cellAreaUV(int32_t u, int32_t v, int32_t placementIndex, int32_t type, bool reco) {
0862   if (type != 0)
0863     type = 1;
0864   double area(0);
0865   std::pair<int, int> cell = hgcalcell_->cellType(u, v, ncell_[type], placementIndex);
0866   int cellType = cell.second;
0867   area = reco ? cellArea[type][cellType] : HGCalParameters::k_ScaleToDDD2 * cellArea[type][cellType];
0868   return area;
0869 }
0870 
0871 double HGCalCellOffset::cellAreaUV(
0872     int32_t u, int32_t v, int32_t placementIndex, int32_t type, int32_t partialType, bool reco) {
0873   if (type != 0)
0874     type = 1;
0875   double area(0);
0876   area = cellAreaUV(u, v, placementIndex, type, reco);
0877   std::pair<int, int> cell = hgcalcell_->cellType(u, v, ncell_[type], placementIndex, partialType);
0878   int cellPos = cell.first;
0879   int cellType = cell.second;
0880   if ((cellType >= HGCalCell::partiaclWaferCellsOffset) || (cellPos >= HGCalCell::partiaclCellsPosOffset)) {
0881     if (cellType == HGCalCell::truncatedCell || cellType == HGCalCell::extendedCell) {
0882       area = reco ? cellArea[type][cellType] : HGCalParameters::k_ScaleToDDD2 * cellArea[type][cellType];
0883     } else {
0884       area = reco ? cellAreaPartial[type][cellType - HGCalCell::partiaclWaferCellsOffset]
0885                   : HGCalParameters::k_ScaleToDDD2 * cellArea[type][cellType - HGCalCell::partiaclWaferCellsOffset];
0886     }
0887   }
0888   return area;
0889 }