Skip to content

Commit

Permalink
Merge pull request #36723 from bsunanda/Phase2-hgx298
Browse files Browse the repository at this point in the history
Phase2-hgx298 Add first algo to get x,y of cell from u,v in rotated wafers
  • Loading branch information
cmsbuild authored Feb 2, 2022
2 parents fa0723a + 7f678e5 commit e4a7ec2
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Geometry/HGCalCommonData/interface/HGCalCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef Geometry_HGCalCommonData_HGCalCell_h
#define Geometry_HGCalCommonData_HGCalCell_h

#include <cmath>
#include <cstdint>

class HGCalCell {
public:
HGCalCell(double waferSize, int32_t nFine, int32_t nCoarse);

static constexpr int32_t waferOrient0 = 0;
static constexpr int32_t waferOrient1 = 1;
static constexpr int32_t waferOrient2 = 2;
static constexpr int32_t waferOrient3 = 3;
static constexpr int32_t waferOrient4 = 4;
static constexpr int32_t waferOrient5 = 5;

static constexpr int32_t cellPlacementIndex0 = 0;
static constexpr int32_t cellPlacementIndex1 = 1;
static constexpr int32_t cellPlacementIndex2 = 2;
static constexpr int32_t cellPlacementIndex3 = 3;
static constexpr int32_t cellPlacementIndex4 = 4;
static constexpr int32_t cellPlacementIndex5 = 5;
static constexpr int32_t cellPlacementIndex6 = 6;
static constexpr int32_t cellPlacementIndex7 = 7;
static constexpr int32_t cellPlacementIndex8 = 8;
static constexpr int32_t cellPlacementIndex9 = 9;
static constexpr int32_t cellPlacementIndex10 = 10;
static constexpr int32_t cellPlacementIndex11 = 11;

static constexpr int32_t cellPlacementExtra = 6;
static constexpr int32_t cellPlacementOld = 7;
static constexpr int32_t cellPlacementTotal = 12;

static constexpr int32_t fullCell = 0;
static constexpr int32_t cornerCell = 1;
static constexpr int32_t truncatedCell = 2;
static constexpr int32_t extendedCell = 3;

std::pair<double, double> HGCalCellUV2XY1(int32_t u, int32_t v, int32_t placementIndex, int32_t type);
std::pair<double, double> HGCalCellUV2XY2(int32_t u, int32_t v, int32_t placementIndex, int32_t type);
std::pair<int32_t, int32_t> HGCalCellUV2Cell(int32_t u, int32_t v, int32_t placementIndex, int32_t type);
static int32_t HGCalCellPlacementIndex(int32_t iz, int32_t fwdBack, int32_t orient);

private:
const double sqrt3By2_ = (0.5 * std::sqrt(3.0));
int32_t ncell_[2];
double cellX_[2], cellY_[2];
};

#endif
1 change: 1 addition & 0 deletions Geometry/HGCalCommonData/interface/HGCalGeometryMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace HGCalGeometryMode {
TrapezoidFile = 7,
Hexagon8Module = 8,
TrapezoidModule = 9,
Hexagon8ModuleOrient = 10,
};
enum WaferMode { Polyhedra = 0, ExtrudedPolygon = 1 };
} // namespace HGCalGeometryMode
Expand Down
233 changes: 233 additions & 0 deletions Geometry/HGCalCommonData/src/HGCalCell.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
#include "Geometry/HGCalCommonData/interface/HGCalCell.h"
#include <vector>

HGCalCell::HGCalCell(double waferSize, int32_t nFine, int32_t nCoarse) {
ncell_[0] = nFine;
ncell_[1] = nCoarse;
for (int k = 0; k < 2; ++k) {
cellX_[k] = waferSize / (3 * ncell_[k]);
cellY_[k] = sqrt3By2_ * cellX_[k];
}
}

std::pair<double, double> HGCalCell::HGCalCellUV2XY1(int32_t u, int32_t v, int32_t placementIndex, int32_t type) {
if (type != 0)
type = 1;
double x(0), y(0);
switch (placementIndex) {
case (HGCalCell::cellPlacementIndex6):
x = (1.5 * (v - u) + 0.5) * cellX_[type];
y = (v + u - 2 * ncell_[type] + 1) * cellY_[type];
break;
case (HGCalCell::cellPlacementIndex7):
x = (1.5 * (v - ncell_[type]) + 1.0) * cellX_[type];
y = (2 * u - v - ncell_[type]) * cellY_[type];
break;
case (HGCalCell::cellPlacementIndex8):
x = (1.5 * (u - ncell_[type]) + 0.5) * cellX_[type];
y = -(2 * v - u - ncell_[type] + 1) * cellY_[type];
break;
case (HGCalCell::cellPlacementIndex9):
x = -(1.5 * (v - u) + 0.5) * cellX_[type];
y = -(v + u - 2 * ncell_[type] + 1) * cellY_[type];
break;
case (HGCalCell::cellPlacementIndex10):
x = -(1.5 * (v - ncell_[type]) + 1) * cellX_[type];
y = -(2 * u - v - ncell_[type]) * cellY_[type];
break;
case (HGCalCell::cellPlacementIndex11):
x = -(1.5 * (u - ncell_[type]) + 0.5) * cellX_[type];
y = (2 * v - u - ncell_[type] + 1) * cellY_[type];
break;
case (HGCalCell::cellPlacementIndex0):
x = (1.5 * (u - v) - 0.5) * cellX_[type];
y = (v + u - 2 * ncell_[type] + 1) * cellY_[type];
break;
case (HGCalCell::cellPlacementIndex1):
x = -(1.5 * (v - ncell_[type]) + 1.0) * cellX_[type];
y = (2 * u - v - ncell_[type]) * cellY_[type];
break;
case (HGCalCell::cellPlacementIndex2):
x = -(1.5 * (u - ncell_[type]) + 0.5) * cellX_[type];
y = -(2 * v - u - ncell_[type] + 1) * cellY_[type];
break;
case (HGCalCell::cellPlacementIndex3):
x = -(1.5 * (u - v) - 0.5) * cellX_[type];
y = -(v + u - 2 * ncell_[type] + 1) * cellY_[type];
break;
case (HGCalCell::cellPlacementIndex4):
x = (1.5 * (v - ncell_[type]) + 1) * cellX_[type];
y = -(2 * u - v - ncell_[type]) * cellY_[type];
break;
default:
x = (1.5 * (u - ncell_[type]) + 0.5) * cellX_[type];
y = (2 * v - u - ncell_[type] + 1) * cellY_[type];
break;
}
return std::make_pair(x, y);
}

std::pair<double, double> HGCalCell::HGCalCellUV2XY2(int32_t u, int32_t v, int32_t placementIndex, int32_t type) {
if (type != 0)
type = 1;
double x(0), y(0);
if (placementIndex < HGCalCell::cellPlacementExtra) {
double x0 = (1.5 * (u - v) - 0.5) * cellX_[type];
double y0 = (u + v - 2 * ncell_[type] + 1) * cellY_[type];
const std::vector<double> fcos = {1.0, 0.5, -0.5, -1.0, -0.5, 0.5};
const std::vector<double> fsin = {0.0, sqrt3By2_, sqrt3By2_, 0.0, -sqrt3By2_, -sqrt3By2_};
x = x0 * fcos[placementIndex] - y0 * fsin[placementIndex];
y = x0 * fsin[placementIndex] + y0 * fcos[placementIndex];
} else {
double x0 = (1.5 * (v - ncell_[type]) + 1.0) * cellX_[type];
double y0 = (2 * u - v - ncell_[type]) * cellY_[type];
const std::vector<double> fcos = {0.5, 1.0, 0.5, -0.5, -1.0, -0.5};
const std::vector<double> fsin = {sqrt3By2_, 0.0, -sqrt3By2_, -sqrt3By2_, 0.0, sqrt3By2_};
x = x0 * fcos[placementIndex - HGCalCell::cellPlacementExtra] -
y0 * fsin[placementIndex - HGCalCell::cellPlacementExtra];
y = x0 * fsin[placementIndex - HGCalCell::cellPlacementExtra] +
y0 * fcos[placementIndex - HGCalCell::cellPlacementExtra];
}
return std::make_pair(x, y);
}

std::pair<int, int> HGCalCell::HGCalCellUV2Cell(int32_t u, int32_t v, int32_t placementIndex, int32_t type) {
if (type != 0)
type = 1;
int cell(0), cellx(0), cellt(HGCalCell::fullCell);
if (placementIndex >= HGCalCell::cellPlacementExtra) {
const std::vector<int> itype0 = {0, 7, 8, 9, 10, 11, 6, 3, 4, 5, 4, 5, 3};
const std::vector<int> itype1 = {0, 0, 1, 2, 3, 4, 5, 0, 1, 2, 0, 1, 2};
const std::vector<int> itype2 = {0, 11, 6, 7, 8, 9, 10, 5, 3, 4, 3, 4, 5};
const std::vector<int> itype3 = {0, 4, 5, 0, 1, 2, 3, 2, 0, 1, 2, 0, 1};
const std::vector<int> itype4 = {0, 9, 10, 11, 6, 7, 8, 4, 5, 3, 5, 3, 4};
const std::vector<int> itype5 = {0, 2, 3, 4, 5, 0, 1, 1, 2, 0, 1, 2, 0};
if (u == 0 && v == 0) {
cellx = 1;
cellt = HGCalCell::cornerCell;
} else if (u == 0 && (v - u) == (ncell_[type] - 1)) {
cellx = 2;
cellt = HGCalCell::cornerCell;
} else if ((v - u) == (ncell_[type] - 1) && v == (2 * ncell_[type] - 1)) {
cellx = 3;
cellt = HGCalCell::cornerCell;
} else if (u == (2 * ncell_[type] - 1) && v == (2 * ncell_[type] - 1)) {
cellx = 4;
cellt = HGCalCell::cornerCell;
} else if (u == (2 * ncell_[type] - 1) && (u - v) == ncell_[type]) {
cellx = 5;
cellt = HGCalCell::cornerCell;
} else if ((u - v) == ncell_[type] && v == 0) {
cellx = 6;
cellt = HGCalCell::cornerCell;
} else if (u == 0) {
cellx = 7;
cellt = HGCalCell::truncatedCell;
} else if ((v - u) == (ncell_[type] - 1)) {
cellx = 10;
cellt = HGCalCell::extendedCell;
} else if (v == (2 * ncell_[type] - 1)) {
cellx = 8;
cellt = HGCalCell::truncatedCell;
} else if (u == (2 * ncell_[type] - 1)) {
cellx = 11;
cellt = HGCalCell::extendedCell;
} else if ((u - v) == ncell_[type]) {
cellx = 9;
cellt = HGCalCell::truncatedCell;
} else if (v == 0) {
cellx = 12;
cellt = HGCalCell::extendedCell;
}
switch (placementIndex) {
case (HGCalCell::cellPlacementIndex6):
cell = itype0[cellx];
break;
case (HGCalCell::cellPlacementIndex7):
cell = itype1[cellx];
break;
case (HGCalCell::cellPlacementIndex8):
cell = itype2[cellx];
break;
case (HGCalCell::cellPlacementIndex9):
cell = itype3[cellx];
break;
case (HGCalCell::cellPlacementIndex10):
cell = itype4[cellx];
break;
default:
cell = itype5[cellx];
break;
}
} else {
const std::vector<int> itype0 = {0, 1, 2, 3, 4, 5, 0, 1, 2, 0, 0, 1, 2};
const std::vector<int> itype1 = {0, 8, 9, 10, 11, 6, 7, 4, 5, 3, 4, 5, 3};
const std::vector<int> itype2 = {0, 3, 4, 5, 0, 1, 2, 2, 0, 1, 1, 2, 0};
const std::vector<int> itype3 = {0, 10, 11, 6, 7, 8, 9, 5, 3, 4, 5, 3, 4};
const std::vector<int> itype4 = {0, 5, 0, 1, 2, 3, 4, 0, 1, 2, 2, 0, 1};
const std::vector<int> itype5 = {0, 6, 7, 8, 9, 10, 11, 3, 4, 5, 3, 4, 5};
if (u == 0 && v == 0) {
cellx = 1;
cellt = HGCalCell::cornerCell;
} else if (v == 0 && (u - v) == (ncell_[type])) {
cellx = 2;
cellt = HGCalCell::cornerCell;
} else if ((u - v) == (ncell_[type]) && u == (2 * ncell_[type] - 1)) {
cellx = 3;
cellt = HGCalCell::cornerCell;
} else if (u == (2 * ncell_[type] - 1) && v == (2 * ncell_[type] - 1)) {
cellx = 4;
cellt = HGCalCell::cornerCell;
} else if (v == (2 * ncell_[type] - 1) && (v - u) == (ncell_[type] - 1)) {
cellx = 5;
cellt = HGCalCell::cornerCell;
} else if ((v - u) == (ncell_[type] - 1) && u == 0) {
cellx = 6;
cellt = HGCalCell::cornerCell;
} else if (v == 0) {
cellx = 10;
cellt = HGCalCell::extendedCell;
} else if ((u - v) == ncell_[type]) {
cellx = 7;
cellt = HGCalCell::truncatedCell;
} else if (u == (2 * ncell_[type] - 1)) {
cellx = 11;
cellt = HGCalCell::extendedCell;
} else if (v == (2 * ncell_[type] - 1)) {
cellx = 8;
cellt = HGCalCell::truncatedCell;
} else if ((v - u) == (ncell_[type] - 1)) {
cellx = 12;
cellt = HGCalCell::extendedCell;
} else if (u == 0) {
cellx = 9;
cellt = HGCalCell::truncatedCell;
}
switch (placementIndex) {
case (HGCalCell::cellPlacementIndex0):
cell = itype0[cellx];
break;
case (HGCalCell::cellPlacementIndex1):
cell = itype1[cellx];
break;
case (HGCalCell::cellPlacementIndex2):
cell = itype2[cellx];
break;
case (HGCalCell::cellPlacementIndex3):
cell = itype3[cellx];
break;
case (HGCalCell::cellPlacementIndex4):
cell = itype4[cellx];
break;
default:
cell = itype5[cellx];
break;
}
}
return std::make_pair(cell, cellt);
}

int HGCalCell::HGCalCellPlacementIndex(int32_t iz, int32_t fwdBack, int32_t orient) {
int32_t indx = ((iz * fwdBack) > 0) ? orient : (orient + HGCalCell::cellPlacementExtra);
return indx;
}
1 change: 1 addition & 0 deletions Geometry/HGCalCommonData/src/HGCalGeometryMode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ HGCalStringToEnumParser<HGCalGeometryMode::GeometryMode>::HGCalStringToEnumParse
enumMap["HGCalGeometryMode::TrapezoidFile"] = HGCalGeometryMode::TrapezoidFile;
enumMap["HGCalGeometryMode::Hexagon8Module"] = HGCalGeometryMode::Hexagon8Module;
enumMap["HGCalGeometryMode::TrapezoidModule"] = HGCalGeometryMode::TrapezoidModule;
enumMap["HGCalGeometryMode::Hexagon8ModuleOrient"] = HGCalGeometryMode::Hexagon8ModuleOrient;
}

template <>
Expand Down
Loading

0 comments on commit e4a7ec2

Please sign in to comment.