Skip to content

Commit

Permalink
Bug fix for wrongly classifying good Hits as invalid in HGCal V16/V17…
Browse files Browse the repository at this point in the history
… geometries (backport of #40208)
  • Loading branch information
Sunanda committed Dec 2, 2022
1 parent 8e05ec5 commit 39ac597
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Geometry/HGCalCommonData/interface/HGCalTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class HGCalTypes {
static constexpr std::array<int, 3> edgeWaferLDThree = {{1, -2, -15}};
static constexpr std::array<int, 3> edgeWaferHDTop = {{1, 0, 9}};
static constexpr std::array<int, 3> edgeWaferHDBottom = {{-1, 0, -10}};
static constexpr std::array<int, 3> edgeWaferHDLeft = {{-1, 2, 4}};
static constexpr std::array<int, 3> edgeWaferHDLeft = {{-1, 2, 5}};
static constexpr std::array<int, 3> edgeWaferHDRight = {{1, -2, -18}};
static constexpr std::array<int, 3> edgeWaferHDFive = {{-1, 2, 18}};

Expand Down
66 changes: 52 additions & 14 deletions Geometry/HGCalCommonData/src/HGCalDDDConstants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -530,35 +530,60 @@ bool HGCalDDDConstants::isValidHex8(int layer, int modU, int modV, bool fullAndP
edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants::isValidHex8:WaferType " << layer << ":" << modU << ":" << modV
<< ":" << indx << " Test " << (itr != hgpar_->typesInLayers_.end());
#endif
if (itr == hgpar_->typesInLayers_.end())
if (itr == hgpar_->typesInLayers_.end()) {
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
<< " in wadferIndex";
#endif
return false;
}

if (fullAndPart_) {
auto ktr = hgpar_->waferInfoMap_.find(indx);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants::isValidHex8:WaferInfoMap " << layer << ":" << modU << ":"
<< modV << ":" << indx << " Test " << (ktr != hgpar_->waferInfoMap_.end());
#endif
if (ktr == hgpar_->waferInfoMap_.end())
if (ktr == hgpar_->waferInfoMap_.end()) {
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
<< " in wadferInfoMap";
#endif
return false;
}
} else {
auto jtr = waferIn_.find(indx);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants::isValidHex8:WaferIn " << jtr->first << ":" << jtr->second;
#endif
if (!(jtr->second))
if (!(jtr->second)) {
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
<< " in wadferIn";
#endif
return false;
}
}

if (fullAndPart || fullAndPart_) {
auto ktr = hgpar_->waferTypes_.find(indx);
if (ktr != hgpar_->waferTypes_.end()) {
if (hgpar_->waferMaskMode_ > 0) {
if (ktr->second.first == HGCalTypes::WaferOut)
if (ktr->second.first == HGCalTypes::WaferOut) {
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
<< " due to WaferOut";
#endif
return false;
}
} else {
if (ktr->second.first < HGCalTypes::WaferCornerMin)
if (ktr->second.first < HGCalTypes::WaferCornerMin) {
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
<< " due to WaferCornerMin";
#endif
return false;
}
}
}
}
Expand All @@ -582,11 +607,22 @@ bool HGCalDDDConstants::isValidHex8(int layer, int modU, int modV, int cellU, in
<< " Tests " << (cellU >= 0) << ":" << (cellU < 2 * N) << ":" << (cellV >= 0) << ":"
<< (cellV < 2 * N) << ":" << ((cellV - cellU) < N) << ":" << ((cellU - cellV) <= N);
#endif
if ((cellU < 0) || (cellU >= 2 * N) || (cellV < 0) || (cellV >= 2 * N))
return false;
if (((cellV - cellU) >= N) || ((cellU - cellV) > N))
return false;

if (mode_ != HGCalGeometryMode::Hexagon8Cassette) {
if ((cellU < 0) || (cellU >= 2 * N) || (cellV < 0) || (cellV >= 2 * N)) {
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot statisfy Cell 1 condition " << cellU << ":" << cellV
<< ":" << N;
#endif
return false;
}
if (((cellV - cellU) >= N) || ((cellU - cellV) > N)) {
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot statisfy Cell 2 condition " << cellU << ":" << cellV
<< ":" << N;
#endif
return false;
}
}
return isValidCell8(layer, modU, modV, cellU, cellV, type);
}

Expand Down Expand Up @@ -1851,7 +1887,7 @@ bool HGCalDDDConstants::isValidCell8(int lay, int waferU, int waferV, int cellU,
result = HGCalWaferMask::goodCell(cellU, cellV, partn.first);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "Input " << lay << ":" << waferU << ":" << waferV << ":" << cellU << ":" << cellV
<< " Result " << result;
<< " Result " << result << " from goodCell";
#endif
} else {
float x(0), y(0);
Expand Down Expand Up @@ -1885,19 +1921,21 @@ bool HGCalDDDConstants::isValidCell8(int lay, int waferU, int waferV, int cellU,
#endif
double rr = sqrt(x * x + y * y);
int ll = lay - hgpar_->firstLayer_;
result = ((rr >= hgpar_->rMinLayHex_[ll]) && (rr <= hgpar_->rMaxLayHex_[ll]));
double tol = waferHexagon8File() ? 0.5 : 0.0;
result = (((rr + tol) >= hgpar_->rMinLayHex_[ll]) && (rr <= hgpar_->rMaxLayHex_[ll]));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "Input " << lay << ":" << ll << ":" << waferU << ":" << waferV << ":" << cellU
<< ":" << cellV << " Position " << x << ":" << y << ":" << rr << " Compare Limits "
<< hgpar_->rMinLayHex_[ll] << ":" << hgpar_->rMaxLayHex_[ll] << " Flag " << result;
<< hgpar_->rMinLayHex_[ll] << ":" << hgpar_->rMaxLayHex_[ll] << " Flag " << result
<< " from Radius Limits";
#endif
if (result && waferHexagon8File()) {
int N = (type == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
result = HGCalWaferMask::goodCell(cellU, cellV, N, partn.first, partn.second);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HGCalGeom") << "Input " << lay << ":" << waferU << ":" << waferV << ":" << cellU << ":" << cellV
<< " N " << N << " part " << partn.first << ":" << partn.second << " Result "
<< result;
<< result << " from goodCell";
#endif
}
}
Expand Down
46 changes: 23 additions & 23 deletions Geometry/HGCalCommonData/src/HGCalWaferMask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,30 @@ bool HGCalWaferMask::goodCell(int u, int v, int n, int type, int rotn) {
switch (rotn) {
case (HGCalTypes::WaferCorner0): {
int u2 = u / 2;
good = ((v - u2) < n);
good = ((v - u2) <= n);
break;
}
case (HGCalTypes::WaferCorner1): {
good = ((v + u) < (3 * n - 1));
good = ((v + u) < (3 * n));
break;
}
case (HGCalTypes::WaferCorner2): {
int v2 = (v + 1) / 2;
good = ((u - v2) < n);
good = ((u - v2) <= n);
break;
}
case (HGCalTypes::WaferCorner3): {
int u2 = (u + 1) / 2;
int u2 = (u - 1) / 2;
good = (u2 <= v);
break;
}
case (HGCalTypes::WaferCorner4): {
good = ((v + u) >= n);
good = ((v + u) >= n - 1);
break;
}
default: {
int v2 = v / 2;
good = (u > v2);
good = (u >= v2);
break;
}
}
Expand All @@ -168,7 +168,7 @@ bool HGCalWaferMask::goodCell(int u, int v, int n, int type, int rotn) {
break;
}
case (HGCalTypes::WaferCorner4): {
good = (u >= n2);
good = (u >= n2 - 1);
break;
}
default: {
Expand All @@ -185,23 +185,23 @@ bool HGCalWaferMask::goodCell(int u, int v, int n, int type, int rotn) {
break;
}
case (HGCalTypes::WaferCorner1): {
good = (u < (5 * n4));
good = (u <= (5 * n4));
break;
}
case (HGCalTypes::WaferCorner2): {
good = ((u - v) <= n4);
break;
}
case (HGCalTypes::WaferCorner3): {
good = (v >= (3 * n4));
good = (v >= (3 * n4 - 1));
break;
}
case (HGCalTypes::WaferCorner4): {
good = (u >= (3 * n4));
break;
}
default: {
good = ((v - u) < n4);
good = ((v - u) <= n4);
break;
}
}
Expand All @@ -214,23 +214,23 @@ bool HGCalWaferMask::goodCell(int u, int v, int n, int type, int rotn) {
break;
}
case (HGCalTypes::WaferCorner1): {
good = (u < n);
good = (u <= n);
break;
}
case (HGCalTypes::WaferCorner2): {
good = (v >= u);
break;
}
case (HGCalTypes::WaferCorner3): {
good = (v >= n);
good = (v >= n - 1);
break;
}
case (HGCalTypes::WaferCorner4): {
good = (u >= n);
break;
}
default: {
good = (u > v);
good = (u >= v);
break;
}
}
Expand Down Expand Up @@ -301,28 +301,28 @@ bool HGCalWaferMask::goodCell(int u, int v, int n, int type, int rotn) {
case (HGCalTypes::WaferSemi2): { //WaferSemi2
switch (rotn) {
case (HGCalTypes::WaferCorner0): {
good = ((u + v) < (4 * n3));
good = ((u + v) <= (4 * n3 + 1));
break;
}
case (HGCalTypes::WaferCorner1): {
good = ((2 * u - v) < n2);
good = ((2 * u - v) <= n2);
break;
}
case (HGCalTypes::WaferCorner2): {
int u2 = ((u + 1) / 2);
good = ((v - u2) >= (3 * n4));
good = ((v - u2) >= (3 * n4 - 1));
break;
}
case (HGCalTypes::WaferCorner3): {
good = ((u + v) >= (5 * n2));
good = ((u + v) >= (5 * n2 - 1));
break;
}
case (HGCalTypes::WaferCorner4): {
good = ((2 * u - v) > (3 * n2));
good = ((2 * u - v) >= (3 * n2));
break;
}
default: {
int u2 = ((n == 8) ? ((u + 1) / 2) : (u / 2));
int u2 = (u + 1) / 2;
good = ((v - u2) < n4);
break;
}
Expand Down Expand Up @@ -365,19 +365,19 @@ bool HGCalWaferMask::goodCell(int u, int v, int n, int type, int rotn) {
break;
}
case (HGCalTypes::WaferCorner1): {
good = (u < (3 * n4));
good = (u <= (3 * n4));
break;
}
case (HGCalTypes::WaferCorner2): {
good = ((v - u) >= n4);
good = ((v - u) >= n4 - 1);
break;
}
case (HGCalTypes::WaferCorner3): {
good = (v >= (5 * n4));
good = (v >= (5 * n4 - 1));
break;
}
case (HGCalTypes::WaferCorner4): {
good = (u >= (5 * n4));
good = (u >= (5 * n4 - 1));
break;
}
default: {
Expand Down

0 comments on commit 39ac597

Please sign in to comment.