26 : hgpar_(hp), sqrt3_(
std::
sqrt(3.0)) {
45 for (
int simreco = 0; simreco < 2; ++simreco) {
48 for (
unsigned int layer = 1; layer <=
tot_layers_[simreco]; ++layer) {
66 <<
"HGCalDDDConstants initialized for " << name <<
" with " 76 int wminT(9999999), wmaxT(-9999999), kount1(0), kount2(0);
79 int wmin(9999999), wmax(-9999999), kount(0);
80 for (
int wafer = 0; wafer <
sectors(); ++wafer) {
95 if (waferU < wmin) wmin = waferU;
96 if (waferU > wmax) wmax = waferU;
100 if (wminT > wmin) wminT = wmin;
101 if (wmaxT < wmax) wmaxT = wmax;
102 if (kount1 < kount) kount1 = kount;
105 int lay1 =
getIndex(lay0,
true).first;
107 <<
"Index " <<
i <<
" Layer " << lay0 <<
":" << lay1 <<
" Wafer " 108 << wmin <<
":" << wmax <<
":" << kount;
113 waferMax_ = std::array<int, 4>{{wminT, wmaxT, kount1, kount2}};
116 <<
"Overall wafer statistics: " << wminT <<
":" << wmaxT <<
":" 117 << kount1 <<
":" << kount2;
125 int subSec,
bool reco)
const {
127 if (
index.first < 0)
return std::make_pair(-1, -1);
137 <<
"Wafer no. out of bound for " << wafer <<
":" 140 return std::make_pair(-1, -1);
146 return std::make_pair(wafer,
152 return std::make_pair(
159 return std::make_pair(-1, -1);
165 int waferU(0), waferV(0),
waferType(-1), cellU(0), cellV(0);
173 return std::array<int, 5>{{waferU, waferV,
waferType, cellU, cellV}};
179 int irad(-1), iphi(-1),
type(-1);
180 const auto& indx =
getIndex(layer, reco);
181 if (indx.first < 0)
return std::array<int, 3>{{irad, iphi, type}};
182 double xx = (z > 0) ? x : -x;
186 double phi = (r == 0. ? 0. : std::atan2(y, xx));
187 if (phi < 0) phi += (2.0 *
M_PI);
194 iphi = 1 + (
int)(phi / indx.second);
197 <<
"assignCellTrap Input " << x <<
":" << y <<
":" << z <<
":" << layer
198 <<
":" << reco <<
" x|r " << xx <<
":" << r <<
" phi " << phi <<
" o/p " 199 << irad <<
":" << iphi <<
":" <<
type;
201 return std::array<int, 3>{{irad, iphi, type}};
214 return std::make_pair(
dr,df);
218 int cellV,
int lay,
bool reco)
const {
219 const auto& indx =
getIndex(lay,
true);
220 if (indx.first >= 0) {
227 ?
locateCell(lay, waferU, waferV, cellU, cellV,
230 double rpos =
sqrt(
xy.first *
xy.first +
xy.second *
xy.second);
232 (rpos <= hgpar_->rMaxLayHex_[indx.first]));
257 thick = 100.0 *
type;
265 ? ((type >= 1) ? 1 : 0)
266 : ((type == 1) ? 1 : 0));
282 else if (cellV - cellU == N - 1)
286 }
else if (cellV == 0) {
287 if (cellU - cellV == N)
291 }
else if (cellU - cellV == N) {
292 if (cellU == 2 * N - 1)
296 }
else if (cellU == 2 * N - 1) {
297 if (cellV == 2 * N - 1)
301 }
else if (cellV == 2 * N - 1) {
302 if (cellV - cellU == N - 1)
306 }
else if (cellV - cellU == N - 1) {
308 }
else if ((cellU > 2 * N - 1) || (cellV > 2 * N - 1) ||
309 (cellV >= (cellU + N)) || (cellU > (cellV + N))) {
327 for (
int k = 0;
k < sizew; ++
k) {
352 <<
"DistFromEdgeHex: Local " << xx <<
":" << yy <<
" wafer " << wafer
353 <<
" flag " << (wafer < sizew) <<
" Distance " <<
rmax_ <<
":" 364 double xx = (z < 0) ? -x : x;
367 double phi = (r == 0. ? 0. : std::atan2(y, xx));
368 if (phi < 0) phi += (2.0 *
M_PI);
376 if (irad < hgpar_->iradMinBH_[indx])
380 int iphi = 1 + (
int)(phi / cell);
387 <<
"DistFromEdgeTrap: Global " << x <<
":" << y <<
":" << z <<
" Layer " 388 << lay <<
" Index " << indx <<
":" << type <<
" xx " << xx <<
" R " << r
391 <<
":" << (iphi - 0.5) * cell <<
" cell " << cell <<
" Dphi " << dphi
392 <<
" Dist " << dist <<
":" << r * dphi;
403 auto itr = std::find_if(zLayerHex.begin() + 1, zLayerHex.end(),
404 [&
k, &
zz, &zLayerHex](
double zLayer) {
406 return zz < 0.5 * (zLayerHex[k-1] + zLayerHex[
k]);
408 int lay = (itr == zLayerHex.end()) ? static_cast<int>(zLayerHex.size()) : k;
427 <<
"Wafer no. out bound for index " << indx <<
":" 432 if (type > 0) --
type;
441 std::vector<HGCalParameters::hgtrap> mytrs;
453 int irmin(0), irmax(0);
461 return std::make_pair(irmin, irmax);
465 std::vector<HGCalParameters::hgtrform> mytrs;
495 if (waferType < 1 || cell < 0)
return false;
503 bool result(
false), resultMod(
false);
510 const int32_t lay_idx = reco ? (lay - 1) * 3 + 1 : lay;
512 auto moditr = the_modules.find(copyNumber);
513 result = resultMod = (moditr != the_modules.end());
517 <<
"HGCalDDDConstants: Layer " << lay <<
":" << lay_idx <<
" Copy " 518 << copyNumber <<
":" << mod <<
" Flag " <<
result;
521 if (moditr->second >= 0) {
524 <<
"Module no. out of bound for " << mod
526 <<
" ***** ERROR *****";
530 result = (cell >= 0 && cell <= cellmax);
541 <<
"HGCalDDDConstants: Layer " << lay <<
":" 542 << (lay > 0 && (lay <= (
int)(
layers(reco)))) <<
" Module " << mod <<
":" 543 << resultMod <<
" Cell " << cell <<
":" << cellmax <<
":" 544 << (cell >= 0 && cell <= cellmax) <<
":" <<
maxCells(reco);
556 <<
"HGCalDDDConstants::isValidHex8:WaferType " << layer <<
":" << modU
557 <<
":" << modV <<
":" << indx <<
" Test " 564 << jtr->first <<
":" << jtr->second;
566 if (!(jtr->second))
return false;
571 <<
"HGCalDDDConstants::isValidHex8:Cell " << cellU <<
":" << cellV <<
":" 572 << N <<
" Tests " << (cellU >= 0) <<
":" << (cellU < 2 * N) <<
":" 573 << (cellV >= 0) <<
":" << (cellV < 2 * N) <<
":" << ((cellV - cellU) < N)
574 <<
":" << ((cellU - cellV) <= N);
576 if ((cellU >= 0) && (cellU < 2 * N) && (cellV >= 0) && (cellV < 2 * N)) {
577 return (((cellV - cellU) <
N) && ((cellU - cellV) <=
N));
585 const auto& indx =
getIndex(layer,
true);
586 if (indx.first < 0)
return false;
588 (irad <= hgpar_->iradMaxBH_[indx.first]) && (iphi > 0) &&
589 (iphi <= hgpar_->scintCells(layer)));
620 float x(999999.),
y(999999.);
623 if (i < 0)
return std::make_pair(
x, y);
640 return std::make_pair(
x, y);
644 int waferV,
int cellU,
645 int cellV,
bool reco,
662 <<
"LocateCell " << lay <<
":" << waferU <<
":" << waferV <<
":" << indx
665 int kndx = cellV * 100 + cellU;
675 <<
"Fine " << cellU <<
":" << cellV <<
":" << kndx <<
":" <<
x <<
":" 687 <<
"Coarse " << cellU <<
":" << cellV <<
":" << kndx <<
":" <<
x 702 <<
xy.first <<
":" <<
xy.second;
705 return std::make_pair(
x, y);
722 return std::make_pair(
x, y);
729 const auto& indx =
getIndex(lay, reco);
730 if (indx.first >= 0) {
733 double phi = (iphi - 0.5) * indx.second;
737 std::pair<double, double> range =
rangeR(z,
true);
741 if (irad < 0)
x = -
x;
747 return std::make_pair(
x, y);
755 int N(0), layer(0), waferU(0), waferV(0), u(0),
v(0);
760 waferU =
id.waferU();
761 waferV =
id.waferV();
768 waferU =
id.waferU();
769 waferV =
id.waferV();
777 <<
"MaskCell: Layer " << layer <<
" Wafer " << waferU <<
":" << waferV
781 int ncor = (itr->second).
first;
782 int fcor = (itr->second).
second;
783 if (ncor < corners) {
817 mask = !((u > 2 *
v) && (v <
N));
819 mask = ((u >=
N) && (v >=
N) && ((u +
v) > (3 *
N - 2)));
825 mask = !((u +
v) <
N);
827 mask = ((u >=
N) && (u > v) && ((2 * u -
v) > 2 *
N));
833 mask = !((u < N) && (v > u) && (v > (2 * u - 1)));
835 mask = ((u > 2 *
v) && (v <
N));
841 mask = !((v >= u) && ((2 * v - u) > (2 *
N - 2)));
843 mask = ((u +
v) <
N);
849 mask = !((u >=
N) && (v >=
N) && ((u +
v) > (3 *
N - 2)));
851 mask = ((u < N) && (v > u) && (v > (2 * u - 1)));
857 mask = !((u >=
N) && (u > v) && ((2 * u -
v) > 2 *
N));
859 mask = ((v >= u) && ((2 * v - u) > (2 *
N - 2)));
867 <<
"Corners: " << ncor <<
":" << fcor <<
" N " <<
N <<
" u " << u
868 <<
" v " << v <<
" Mask " <<
mask;
879 for (
unsigned int i = 0;
i <
layers(reco); ++
i) {
888 if (
index.first < 0)
return 0;
891 unsigned int cells(0);
897 if (cell > cells) cells = cell;
928 if (i < 0)
return kymax;
934 if (ky > kymax) kymax = ky;
946 return (((type1 == type2) || (type1 * type2 != 0))
948 : ((type1 == 0) ? (2 * uv + 1) / 3 : (3 * uv) / 2));
961 if (
index.first < 0)
return nmod;
981 for (
unsigned k = 0;
k < nlayer; ++
k) {
982 std::vector<int> ncells =
984 cells = std::accumulate(ncells.begin(), ncells.end(),
cells);
992 std::vector<int> ncell;
1001 ncell.emplace_back((
int)(cell));
1007 ncell.emplace_back(nphi);
1014 ncell.emplace_back(cell);
1048 double rmin(0), rmax(0),
zz(0);
1078 << zz <<
" R " << rmin <<
":" << rmax;
1080 return std::make_pair(rmin, rmax);
1088 edm::LogVerbatim(
"HGCalGeom") <<
"HGCalDDDConstants:rangeZ: " << zmin <<
":" 1095 return std::make_pair(zmin, zmax);
1103 if ((copy / 10000) % 10 != 0) col = -col;
1104 row = (copy / 100) % 100;
1105 if ((copy / 100000) % 10 != 0) row = -row;
1107 return std::make_pair(row, col);
1114 return std::make_pair(cell, lay);
1120 <<
"Wrong Layer # " << lay <<
" not in the list ***** ERROR *****";
1121 return std::make_pair(-1, -1);
1125 <<
"Invalid Wafer # " << mod <<
"should be < " 1127 return std::make_pair(-1, -1);
1134 }
else if (type == 2) {
1139 return std::make_pair(kx, depth);
1147 for (
int k = 0;
k < ncopies; ++
k) {
1158 <<
"Cannot find " << copy <<
" in a list of " << ncopies <<
" members";
1159 for (
int k = 0;
k < ncopies; ++
k)
1168 int& wafer,
int& icell,
1169 int& celltyp)
const {
1175 for (
int k = 0;
k < size_; ++
k) {
1188 if (wafer < size_) {
1200 edm::LogWarning(
"HGCalGeom") <<
"Cannot get wafer type corresponding to " 1201 << x <<
":" << y <<
" " << xx <<
":" <<
yy;
1206 <<
"Position " << x <<
":" << y <<
" Wafer " << wafer <<
":" << size_
1207 <<
" XX " << xx <<
":" << yy <<
" Cell " << icell <<
" Type " << celltyp;
1212 const int layer,
int& waferU,
1213 int& waferV,
int& cellU,
int& cellV,
1214 int& celltype,
double& wt,
1239 <<
"WaferFromPosition:: Input " << xx <<
":" << yy
1244 << waferU <<
":" << waferV <<
":" << celltype;
1253 cellHex(xx, yy, celltype, cellU, cellV
1259 wt = ((celltype < 2)
1272 <<
"waferFromPosition: Bad type for X " << x <<
":" << x1 <<
":" << xx
1273 <<
" Y " << y <<
":" << y1 <<
":" << yy <<
" Wafer " << waferU <<
":" 1274 << waferV <<
" Cell " << cellU <<
":" << cellV;
1289 const auto& indx =
getIndex(lay, reco);
1290 if (indx.first < 0)
return false;
1295 const auto& indx =
getIndex(lay, reco);
1296 if (indx.first < 0)
return false;
1302 double xx(0),
yy(0);
1311 return std::make_pair(
xx, yy);
1317 double xx(0),
yy(0);
1328 return std::make_pair(
xx, yy);
1360 if (
index.first < 0)
1371 for (
unsigned int i = 0;
i <
layers(
true); ++
i) {
1386 unsigned ity = (type > 0 && type <= 2) ? type : 0;
1387 wafer = (itr->second)[ity];
1398 const std::vector<double>&
posX,
1399 const std::vector<double>&
posY)
const {
1401 const double tol(0.00001);
1403 for (
unsigned int k = 0;
k < posX.size(); ++
k) {
1406 if (dx <= (cellR + tol) && dy <= (cellY + tol)) {
1407 double xmax = (dy <= 0.5 * cellY)
1409 : (cellR - (dy - 0.5 * cellY) /
tan30deg_);
1410 if (dx <= (xmax + tol)) {
1420 int& cellU,
int& cellV,
1427 double Rc = 2 *
rmax_ / (3 * N);
1428 double rc = 0.5 * Rc *
sqrt3_;
1429 double v0 = ((xloc / Rc - 1.0) / 1.5);
1430 int cv0 = (v0 > 0) ? (N + (
int)(v0 + 0.5)) : (N - (
int)(-v0 + 0.5));
1431 double u0 = (0.5 * yloc / rc + 0.5 * cv0);
1432 int cu0 = (u0 > 0) ? (N / 2 + (
int)(u0 + 0.5)) : (N / 2 - (
int)(-u0 + 0.5));
1435 if (cv0 - cu0 >= N) cv0 = cu0 + N - 1;
1439 <<
"cellHex: input " << xloc <<
":" << yloc <<
":" << cellType
1440 <<
" parameter " << rc <<
":" << Rc <<
" u0 " << u0 <<
":" << cu0
1441 <<
" v0 " << v0 <<
":" << cv0;
1444 static const int shift[3] = {0, 1, -1};
1445 for (
int i1 = 0; i1 < 3; ++i1) {
1446 cellU = cu0 + shift[i1];
1447 for (
int i2 = 0; i2 < 3; ++i2) {
1448 cellV = cv0 + shift[i2];
1449 if (((cellV - cellU) < N) && ((cellU - cellV) <= N) && (cellU >= 0) &&
1450 (cellV >= 0) && (cellU < 2 * N) && (cellV < 2 * N)) {
1451 double xc = (1.5 * (cellV -
N) + 1.0) * Rc;
1452 double yc = (2 * cellU - cellV -
N) * rc;
1454 ((
std::abs(xloc - xc) <= 0.5 * Rc) ||
1459 <<
"cellHex: local " << xc <<
":" << yc <<
" difference " 1461 << sqrt3_ * (Rc -
std::abs(yloc - yc)) <<
" comparator " << rc
1462 <<
":" << Rc <<
" (u,v) = (" << cellU <<
"," << cellV <<
")";
1479 if (indx < 0)
return std::make_pair(-1, 0);
1492 return std::make_pair(indx, cell);
1507 double rr =
sqrt(x * x + y * y);
1509 (rr <= hgpar_->rMaxLayHex_[lay - 1]) &&
1514 <<
"Input " << lay <<
":" << wafer <<
":" << cell <<
" Position " << x
1515 <<
":" << y <<
":" << rr <<
" Compare Limits " 1530 bool in = (full ? (corner.first > 0)
1534 <<
"WaferInLayerTest: Layer " << lay <<
" wafer " << wafer <<
" R-limits " 1536 <<
" Corners " << corner.first <<
":" << corner.second <<
" In " <<
in;
std::vector< int > iradMaxBH_
bool isHalfCell(int waferType, int cell) const
std::vector< double > waferPosY_
std::vector< int > layer_
std::vector< int > depthLayerF_
bool isValidTrap(int lay, int ieta, int iphi) const
std::vector< int > depth_
std::vector< double > zFrontMin_
std::vector< double > moduleCellR_
int getTypeTrap(int layer) const
layer_map copiesInLayers_
int getLayer(double z, bool reco) const
std::vector< HGCalParameters::hgtrap > getModules() const
std::vector< bool > cellCoarseHalf_
std::vector< bool > cellFineHalf_
int scintType(const int layer) const
void waferFromPosition(const double x, const double y, int &wafer, int &icell, int &celltyp) const
int type() const
get the type
std::vector< int > moduleLayR_
double cellSizeHex(int type) const
int32_t maxWafersPerLayer_
HGCalParameters::hgtrform getTrForm(unsigned int k) const
Simrecovecs max_modules_layer_
int lastLayer(bool reco) const
double cellThickness(int layer, int waferU, int waferV) const
unsigned int layersInit(bool reco) const
static int32_t waferV(const int32_t index)
Sin< T >::type sin(const T &t)
bool cellInLayer(int waferU, int waferV, int cellU, int cellV, int lay, bool reco) const
int maxRows(int lay, bool reco) const
int getTypeHex(int layer, int waferU, int waferV) const
std::vector< double > cellFineY_
bool waferInLayerTest(int wafer, int lay, bool full) const
std::unordered_map< int32_t, bool > waferIn_
int modulesInit(int lay, bool reco) const
std::pair< float, float > locateCell(int cell, int lay, int type, bool reco) const
std::vector< uint32_t > trformIndex_
bool isValidHex(int lay, int mod, int cell, bool reco) const
std::vector< int > layerGroupM_
HGCalGeometryMode::GeometryMode mode_
HGCalGeometryMode::GeometryMode mode_
double scintCellSize(const int layer) const
int cellHex(double xx, double yy, const double &cellR, const std::vector< double > &posX, const std::vector< double > &posY) const
int layerIndex(int lay, bool reco) const
wafer_map wafersInLayers_
std::pair< float, float > locateCellHex(int cell, int wafer, bool reco) const
U second(std::pair< T, U > const &p)
std::vector< double > cellCoarseX_
std::pair< double, double > rangeR(double z, bool reco) const
std::map< int, HGCWaferParam > waferLayer_
int modules(int lay, bool reco) const
std::vector< int > firstModule_
std::pair< int, int > simToReco(int cell, int layer, int mod, bool half) const
unsigned int getTrFormN() const
double distFromEdgeTrap(double x, double y, double z) const
std::pair< double, double > rangeZ(bool reco) const
unsigned int layers(bool reco) const
bool isValidHex8(int lay, int modU, int modV, int cellU, int cellV) const
int numberCellsHexagon(int wafer) const
std::vector< double > cellSize_
std::vector< int > waferUVMaxLayer_
std::vector< HGCalParameters::hgtrform > getTrForms() const
std::pair< double, double > cellEtaPhiTrap(int type, int irad) const
std::vector< int > layerIndex_
double mouseBite(bool reco) const
hgtrform getTrForm(unsigned int k) const
int type() const
get the type
std::pair< int, float > getIndex(int lay, bool reco) const
static double k_ScaleFromDDD
HGCalDDDConstants(const HGCalParameters *hp, const std::string &name)
std::pair< float, float > locateCellTrap(int lay, int ieta, int iphi, bool reco) const
std::vector< double > rMaxFront_
Cos< T >::type cos(const T &t)
int scintCells(const int layer) const
hgtrap getModule(unsigned int k, bool reco) const
CellType cellType(int type, int waferU, int waferV) const
Abs< T >::type abs(const T &t)
std::vector< double > slopeTop_
static int32_t waferU(const int32_t index)
bool isValidCell(int layindex, int wafer, int cell) const
int waferTypeL(int wafer) const
int getPhiBins(int lay) const
std::vector< double > rMinLayHex_
static int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV, bool old=false)
std::pair< int, int > getREtaRange(int lay) const
std::pair< int, int > rowColumnWafer(const int wafer) const
std::vector< double > zLayerHex_
double waferZ(int layer, bool reco) const
#define TYPELOOKUP_DATA_REG(_dataclass_)
int waferType(DetId const &id) const
bool waferVirtual(int layer, int waferU, int waferV) const
std::vector< double > rMaxLayHex_
static uint32_t k_CornerSize
std::vector< double > slopeMin_
std::vector< int > lastModule_
std::array< int, 4 > waferMax_
int waferFromCopy(int copy) const
std::vector< double > radiusMixBoundary_
std::vector< double > cellThickness_
std::vector< int > layerGroup_
std::vector< double > moduleCellS_
static double k_ScaleToDDD
bool maskCell(const DetId &id, int corners) const
int numberCells(bool reco) const
wafer_map cellCoarseIndex_
bool waferFullInLayer(int wafer, int lay, bool reco) const
std::vector< double > rMinFront_
std::vector< int > iradMinBH_
std::vector< double > cellFineX_
std::vector< int > layerGroupO_
std::array< int, 5 > assignCellHex(float x, float y, int lay, bool reco) const
std::array< int, 3 > HGCWaferParam
std::vector< int > waferCopy_
static unsigned int const shift
std::vector< int > depthIndex_
std::pair< double, double > waferPosition(int wafer, bool reco) const
std::pair< int, int > assignCell(float x, float y, int lay, int subSec, bool reco) const
std::array< int, 3 > assignCellTrap(float x, float y, float z, int lay, bool reco) const
std::vector< double > zFrontTop_
std::vector< double > radiusLayer_[2]
std::array< uint32_t, 2 > tot_layers_
std::vector< int > waferTypeT_
std::vector< double > cellCoarseY_
HGCalParameters::hgtrap getModule(unsigned int k, bool hexType, bool reco) const
const HGCalParameters * hgpar_
int maxCells(bool reco) const
std::vector< double > waferPosX_
int modifyUV(int uv, int type1, int type2) const
T mod(const T &a, const T &b)
std::vector< int > waferTypeL_
int getUVMax(int type) const
double distFromEdgeHex(double x, double y, double z) const
bool waferInLayer(int wafer, int lay, bool reco) const
constexpr Detector det() const
get the detector field from this detid