Skip to content

Commit

Permalink
Merge pull request #43449 from bsunanda/Phase2-hgx350
Browse files Browse the repository at this point in the history
Phase2-hgx350 Make modifications for the HGCal version V18 in the case of mouse bite, guard rings, ...
  • Loading branch information
cmsbuild authored Dec 4, 2023
2 parents 7c07693 + f4294f0 commit 1ef0ff5
Show file tree
Hide file tree
Showing 9 changed files with 529 additions and 43 deletions.
16 changes: 14 additions & 2 deletions Geometry/HGCalCommonData/interface/HGCalCellUV.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

#ifndef Geometry_HGCalCommonData_HGCalCellUV_h
#define Geometry_HGCalCommonData_HGCalCellUV_h

#include <cstdint>
#include <iterator>
#include <map>
#include <memory>
#include "Geometry/HGCalCommonData/interface/HGCalCell.h"

class HGCalCellUV {
Expand All @@ -16,6 +18,15 @@ class HGCalCellUV {
std::pair<int32_t, int32_t> cellUVFromXY2(
double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug) const;

std::pair<int32_t, int32_t> cellUVFromXY2( // for v18
double xloc,
double yloc,
int32_t placement,
int32_t type,
int32_t partial,
bool extend,
bool debug) const;

std::pair<int32_t, int32_t> cellUVFromXY3(
double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug) const;

Expand All @@ -41,9 +52,10 @@ class HGCalCellUV {
static constexpr double sin60_ = 0.5 * sqrt3_;
static constexpr double cos60_ = 0.5;

const double waferSize_;
int32_t ncell_[2];
double cellX_[2], cellY_[2], cellXTotal_[2], cellYTotal_[2], waferSize;

double cellX_[2], cellY_[2], cellXTotal_[2], cellYTotal_[2];
std::unique_ptr<HGCalCell> hgcalcell_;
std::map<std::pair<int32_t, int32_t>, std::pair<double, double> > cellPosFine_[HGCalCell::cellPlacementTotal],
cellPosCoarse_[HGCalCell::cellPlacementTotal];
};
Expand Down
2 changes: 2 additions & 0 deletions Geometry/HGCalCommonData/interface/HGCalTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class HGCalTypes {
static constexpr int32_t WaferOut = 99;
static constexpr int32_t WaferPartLDOffset = 11;
static constexpr int32_t WaferPartHDOffset = 21;
static constexpr int32_t WaferPartLDCount = 6;
static constexpr int32_t WaferPartHDCount = 5;
static constexpr int32_t WaferTypeOffset[3] = {0, 5, 11};

static constexpr int32_t WaferOrient0 = 0;
Expand Down
9 changes: 9 additions & 0 deletions Geometry/HGCalCommonData/interface/HGCalWaferMask.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <cmath>
#include <vector>
#include <array>

class HGCalWaferMask {
public:
Expand Down Expand Up @@ -68,11 +69,19 @@ class HGCalWaferMask {
const double& ypos,
const bool& v17);

static std::array<double, 4> maskCut(
const int& part, const int& place, const double& waferSize, const double& offset, const bool& v17OrLess);

private:
static constexpr double sqrt3_ = 1.732050807568877; // std::sqrt(3.0) in double precision
static constexpr double sin_60_ = 0.5 * sqrt3_;
static constexpr double cos_60_ = 0.5;
static constexpr double tan_60_ = sqrt3_;
static constexpr std::array<double, 12> tan_1 = {
{-sqrt3_, sqrt3_, 0.0, -sqrt3_, sqrt3_, 0.0, sqrt3_, -sqrt3_, 0.0, sqrt3_, -sqrt3_, 0.0}};
static constexpr std::array<double, 12> cos_1 = {{0.5, -0.5, -1.0, -0.5, 0.5, 1.0, -0.5, 0.5, 1.0, 0.5, -0.5, -1.0}};
static constexpr std::array<double, 12> cot_1 = {
{sqrt3_, -sqrt3_, 0.0, sqrt3_, -sqrt3_, 0.0, -sqrt3_, sqrt3_, 0.0, -sqrt3_, sqrt3_, 0.0}};
};

#endif
158 changes: 129 additions & 29 deletions Geometry/HGCalCommonData/src/HGCalCellUV.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "Geometry/HGCalCommonData/interface/HGCalCellUV.h"
#include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
#include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <iostream>
#include <array>
#include <algorithm>
#include <cassert>

HGCalCellUV::HGCalCellUV(double waferSize, double separation, int32_t nFine, int32_t nCoarse) {
HGCalCell hgcalcell(waferSize, nFine, nCoarse);
HGCalCellUV::HGCalCellUV(double waferSize, double separation, int32_t nFine, int32_t nCoarse) : waferSize_(waferSize) {
hgcalcell_ = std::make_unique<HGCalCell>(waferSize, nFine, nCoarse);
assert(nFine > 0 && nCoarse > 0);
ncell_[0] = nFine;
ncell_[1] = nCoarse;
Expand All @@ -17,7 +18,6 @@ HGCalCellUV::HGCalCellUV(double waferSize, double separation, int32_t nFine, int
cellXTotal_[k] = (waferSize + separation) / (3 * ncell_[k]);
cellYTotal_[k] = 0.5 * sqrt3_ * cellXTotal_[k];
}

// Fill up the placement vectors
for (int placement = 0; placement < HGCalCell::cellPlacementTotal; ++placement) {
// Fine cells
Expand All @@ -26,7 +26,7 @@ HGCalCellUV::HGCalCellUV(double waferSize, double separation, int32_t nFine, int
int u = (placement < HGCalCell::cellPlacementExtra) ? iv : iu;
int v = (placement < HGCalCell::cellPlacementExtra) ? iu : iv;
if (((v - u) < ncell_[0]) && (u - v) <= ncell_[0]) {
cellPosFine_[placement][std::pair<int, int>(u, v)] = hgcalcell.cellUV2XY1(u, v, placement, 0);
cellPosFine_[placement][std::pair<int, int>(u, v)] = hgcalcell_->cellUV2XY1(u, v, placement, 0);
}
}
}
Expand All @@ -36,7 +36,7 @@ HGCalCellUV::HGCalCellUV(double waferSize, double separation, int32_t nFine, int
int u = (placement < HGCalCell::cellPlacementExtra) ? iv : iu;
int v = (placement < HGCalCell::cellPlacementExtra) ? iu : iv;
if (((v - u) < ncell_[1]) && (u - v) <= ncell_[1]) {
cellPosCoarse_[placement][std::pair<int, int>(u, v)] = hgcalcell.cellUV2XY1(u, v, placement, 1);
cellPosCoarse_[placement][std::pair<int, int>(u, v)] = hgcalcell_->cellUV2XY1(u, v, placement, 1);
}
}
}
Expand Down Expand Up @@ -129,25 +129,25 @@ std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY2(
//--- Taking care of extending cells
if (v == -1) {
if (y < (2 * u - v - ncell) * r) {
v += 1;
++v;
} else {
u += 1;
v += 1;
++u;
++v;
}
}
if (v - u == ncell) {
if ((y + sqrt3_ * x) < ((u + v - 2 * ncell + 1) * 2 * r)) {
v += -1;
--v;
} else {
u += 1;
++u;
}
}
if (u == 2 * ncell) {
if ((y - sqrt3_ * x) < ((u - 2 * v + ncell - 1) * 2 * r)) {
u += -1;
--u;
} else {
u += -1;
v += -1;
--u;
--v;
}
}
if (debug)
Expand Down Expand Up @@ -200,25 +200,25 @@ std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY3(
double ycell = (v + u - 2 * ncell_[type] + 1) * cellY;
if (v == -1) {
if ((yprime - sqrt3_ * xprime) < (ycell - sqrt3_ * xcell)) {
v += 1;
++v;
} else {
u += 1;
v += 1;
++u;
++v;
}
}
if (v - u == ncell_[type]) {
if (yprime < ycell) {
v += -1;
--v;
} else {
u += 1;
++u;
}
}
if (u == 2 * ncell_[type]) {
if ((yprime + sqrt3_ * xprime) > (ycell + sqrt3_ * xcell)) {
u += -1;
--u;
} else {
u += -1;
v += -1;
--u;
--v;
}
}

Expand Down Expand Up @@ -278,8 +278,14 @@ std::pair<int, int> HGCalCellUV::cellUVFromXY4(double xloc,
return uv;
}

std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY1(
double xloc, double yloc, int32_t placement, int32_t type, int32_t partial, bool extend, bool debug) const {
std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY1( // for v17
double xloc,
double yloc,
int32_t placement,
int32_t type,
int32_t partial,
bool extend,
bool debug) const {
if (type != 0)
type = 1;
double cellX = (extend) ? cellXTotal_[type] : cellX_[type];
Expand All @@ -298,12 +304,12 @@ std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY1(
double xcell = -1 * (1.5 * (v - u) + 0.5) * cellX;
double ycell = (v + u - 2 * ncell_[type] + 1) * cellY;
if ((yprime - sqrt3_ * xprime) > (ycell - sqrt3_ * xcell)) {
u += -1;
--u;
if ((v - u) >= ncell_[1])
--v;
} else {
u += -1;
v += -1;
--u;
--v;
v = std::max(v, 0);
}
}
Expand All @@ -319,10 +325,104 @@ std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY1(
double xcell = -1 * (1.5 * (v - u) + 0.5) * cellX;
double ycell = (v + u - 2 * ncell_[type] + 1) * cellY;
if ((yprime - sqrt3_ * xprime) > (ycell - sqrt3_ * xcell)) {
u += 1;
v += 1;
++u;
++v;
} else {
u += 1;
++u;
}
}
}
if (debug)
edm::LogVerbatim("HGCalGeom") << "cellUVFromXY5: Input " << xloc << ":" << yloc << ":" << extend << " Output " << u
<< ":" << v;
return std::make_pair(u, v);
}

std::pair<int32_t, int32_t> HGCalCellUV::cellUVFromXY2( // for v18
double xloc,
double yloc,
int32_t placement,
int32_t type,
int32_t partial,
bool extend,
bool debug) const {
if (type != 0)
type = 1;
std::pair<int, int> uv = HGCalCellUV::cellUVFromXY1(xloc, yloc, placement, type, extend, debug);
int u = uv.first;
int v = uv.second;
if ((partial != HGCalTypes::WaferFull) && (type == 1)) {
if (u == 1 && v == 8) {
std::array<double, 4> criterion =
HGCalWaferMask::maskCut(HGCalTypes::WaferLDThree, placement, waferSize_, 0.0, false);
if ((criterion[0] * yloc) + (criterion[1] * xloc) < -criterion[2]) {
++u;
++v;
}
}
if (u == 15 && v == 15) {
std::array<double, 4> criterion =
HGCalWaferMask::maskCut(HGCalTypes::WaferLDThree, placement, waferSize_, 0.0, false);
if ((criterion[0] * yloc) + (criterion[1] * xloc) < -criterion[2]) {
--u;
}
}
if (u * HGCalTypes::edgeWaferLDTop[0] + v * HGCalTypes::edgeWaferLDTop[1] == HGCalTypes::edgeWaferLDTop[2] + 1) {
std::array<double, 4> criterion =
HGCalWaferMask::maskCut(HGCalTypes::WaferLDTop, placement, waferSize_, 0.0, false);
if ((criterion[0] * yloc) + (criterion[1] * xloc) < -criterion[2]) {
std::pair<double, double> xy1 = hgcalcell_->cellUV2XY1(u, v, placement, 1);
std::pair<double, double> xy2 = hgcalcell_->cellUV2XY1(u - 2, v - 1, placement, 1);
if (((placement >= HGCalCell::cellPlacementExtra) &&
((((xloc - xy1.first) / (xy2.first - xy1.first)) - ((yloc - xy1.second) / (xy2.second - xy1.second))) >
0.0)) ||
((placement < HGCalCell::cellPlacementExtra) &&
((((xloc - xy1.first) / (xy2.first - xy1.first)) - ((yloc - xy1.second) / (xy2.second - xy1.second))) <
0.0))) {
--u;
if ((v - u) >= ncell_[1])
--v;
} else {
--u;
--v;
v = std::max(v, 0);
}
}
}
} else if ((partial != HGCalTypes::WaferFull) && (type == 0)) {
if (u == 10 && v == 0) {
std::array<double, 4> criterion =
HGCalWaferMask::maskCut(HGCalTypes::WaferHDTop, placement, waferSize_, 0.0, false);
if ((criterion[0] * yloc) + (criterion[1] * xloc) < -criterion[2]) {
--u;
}
}
if (u == 10 && v == 21) {
std::array<double, 4> criterion =
HGCalWaferMask::maskCut(HGCalTypes::WaferHDTop, placement, waferSize_, 0.0, false);
if ((criterion[0] * yloc) + (criterion[1] * xloc) < -criterion[2]) {
--u;
--v;
}
}
if (u * HGCalTypes::edgeWaferHDBottom[0] + v * HGCalTypes::edgeWaferHDBottom[1] ==
HGCalTypes::edgeWaferHDBottom[2] + 1) {
std::array<double, 4> criterion =
HGCalWaferMask::maskCut(HGCalTypes::WaferHDBottom, placement, waferSize_, 0.0, false);
if ((criterion[0] * yloc) + (criterion[1] * xloc) < -criterion[2]) {
std::pair<double, double> xy1 = hgcalcell_->cellUV2XY1(u, v, placement, 0);
std::pair<double, double> xy2 = hgcalcell_->cellUV2XY1(u - 2, v - 1, placement, 0);
if (((placement >= HGCalCell::cellPlacementExtra) &&
((((xloc - xy1.first) / (xy2.first - xy1.first)) - ((yloc - xy1.second) / (xy2.second - xy1.second))) >
0.0)) ||
((placement < HGCalCell::cellPlacementExtra) &&
((((xloc - xy1.first) / (xy2.first - xy1.first)) - ((yloc - xy1.second) / (xy2.second - xy1.second))) <
0.0))) {
++u;
++v;
} else {
++u;
}
}
}
}
Expand Down
Loading

0 comments on commit 1ef0ff5

Please sign in to comment.