|
| 1 | +#include "FWCore/MessageLogger/interface/MessageLogger.h" |
| 2 | +#include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h" |
| 3 | +#include "Geometry/HGCalCommonData/interface/HGCalWaferType.h" |
| 4 | +#include "Geometry/HGCalCommonData/interface/HGCGuardRing.h" |
| 5 | +#include <iostream> |
| 6 | + |
| 7 | +//#define EDM_ML_DEBUG |
| 8 | + |
| 9 | +HGCGuardRing::HGCGuardRing(const HGCalDDDConstants& hgc) |
| 10 | + : hgcons_(hgc), |
| 11 | + modeUV_(hgcons_.geomMode()), |
| 12 | + v17OrLess_(hgcons_.v17OrLess()), |
| 13 | + waferSize_(hgcons_.waferSize(false)), |
| 14 | + sensorSizeOffset_(hgcons_.sensorSizeOffset(false)), |
| 15 | + guardRingOffset_(hgcons_.guardRingOffset(false)) { |
| 16 | + offset_ = sensorSizeOffset_ + guardRingOffset_; |
| 17 | + offsetPartial_ = guardRingOffset_; |
| 18 | + xmax_ = 0.5 * waferSize_ - offset_; |
| 19 | + ymax_ = xmax_ / sqrt3_; |
| 20 | + c22_ = (v17OrLess_) ? HGCalTypes::c22O : HGCalTypes::c22; |
| 21 | + c27_ = (v17OrLess_) ? HGCalTypes::c27O : HGCalTypes::c27; |
| 22 | +#ifdef EDM_ML_DEBUG |
| 23 | + edm::LogVerbatim("HGCSim") << "Creating HGCGuardRing with wafer size " << waferSize_ << ", Offsets " << sensorSizeOffset_ << ":" << guardRingOffset_ << ":" << offset_ << ":" << offsetPartial_ << ", mode " << modeUV_ << ", xmax|ymax " << xmax_ << ":" << ymax_ << " and c22:c77 " << c22_ << ":" << c77_; |
| 24 | +#endif |
| 25 | +} |
| 26 | + |
| 27 | +bool HGCGuardRing::exclude(G4ThreeVector& point, int zside, int frontBack, int layer, int waferU, int waferV) { |
| 28 | + bool check(false); |
| 29 | + if (hgcons_.waferHexagon8Module()) { |
| 30 | + int index = HGCalWaferIndex::waferIndex(layer, waferU, waferV); |
| 31 | + int partial = HGCalWaferType::getPartial(index, hgcons_.getParameter()->waferInfoMap_); |
| 32 | +#ifdef EDM_ML_DEBUG |
| 33 | + edm::LogVerbatim("HGCSim") << "HGCGuardRing::exclude: Layer " << layer << " wafer " << waferU << ":" << waferV << " index " << index << " partial " << partial; |
| 34 | +#endif |
| 35 | + if (partial == HGCalTypes::WaferFull) { |
| 36 | + double dx = std::abs(point.x()); |
| 37 | + double dy = std::abs(point.y()); |
| 38 | + if (dx > xmax_) { |
| 39 | + check = true; |
| 40 | + } else if (dy > (2 * ymax_)) { |
| 41 | + check = true; |
| 42 | + } else { |
| 43 | + check = (dx > (sqrt3_ * (2 * ymax_ - dy))); |
| 44 | + } |
| 45 | +#ifdef EDM_ML_DEBUG |
| 46 | + edm::LogVerbatim("HGCSim") << "HGCGuardRing::exclude: Point " << point << " zside " << zside << " layer " << layer << " wafer " << waferU << ":" << waferV << " partial type " << partial << ":" << HGCalTypes::WaferFull << " x " << dx << ":" << xmax_ << " y " << dy << ":" << ymax_ |
| 47 | + << " check " << check; |
| 48 | +#endif |
| 49 | + } else if (partial > 0) { |
| 50 | + int orient = HGCalWaferType::getOrient(index, hgcons_.getParameter()->waferInfoMap_); |
| 51 | +#ifdef EDM_ML_DEBUG |
| 52 | + edm::LogVerbatim("HGCSim") << "HGCGuardRing::exclude: Orient " << orient << " Mode " << modeUV_; |
| 53 | +#endif |
| 54 | + if (hgcons_.v16OrLess()) { |
| 55 | + std::vector<std::pair<double, double> > wxy = |
| 56 | + HGCalWaferMask::waferXY(partial, orient, zside, waferSize_, offset_, 0.0, 0.0, v17OrLess_); |
| 57 | + check = !(insidePolygon(point.x(), point.y(), wxy)); |
| 58 | +#ifdef EDM_ML_DEBUG |
| 59 | + std::ostringstream st1; |
| 60 | + st1 << "HGCGuardRing::exclude: Point " << point << " Partial/orient/zside/size/offset " << partial << ":" << orient << ":" << zside << ":" << waferSize_ << offset_ << " with " << wxy.size() << " points:"; |
| 61 | + for (unsigned int k = 0; k < wxy.size(); ++k) |
| 62 | + st1 << " (" << wxy[k].first << ", " << wxy[k].second << ")"; |
| 63 | + edm::LogVerbatim("HGCSim") << st1.str(); |
| 64 | +#endif |
| 65 | + } else { |
| 66 | + int placement = HGCalCell::cellPlacementIndex(zside, frontBack, orient); |
| 67 | + std::vector<std::pair<double, double> > wxy = |
| 68 | + HGCalWaferMask::waferXY(partial, placement, waferSize_, offset_, 0.0, 0.0, v17OrLess_); |
| 69 | + check = !(insidePolygon(point.x(), point.y(), wxy)); |
| 70 | +#ifdef EDM_ML_DEBUG |
| 71 | + std::ostringstream st1; |
| 72 | + st1 << "HGCGuardRing::exclude: Point " << point << " Partial/frontback/orient/zside/placeemnt/size/offset " << partial << ":" << frontBack << ":" << orient << ":" << zside << ":" << placement << ":" << waferSize_ << offset_ << " with " << wxy.size() << " points:"; |
| 73 | + for (unsigned int k = 0; k < wxy.size(); ++k) |
| 74 | + st1 << " (" << wxy[k].first << ", " << wxy[k].second << ")"; |
| 75 | + edm::LogVerbatim("HGCSim") << st1.str(); |
| 76 | +#endif |
| 77 | + } |
| 78 | + } else { |
| 79 | + check = true; |
| 80 | + } |
| 81 | + } |
| 82 | + return check; |
| 83 | +} |
| 84 | + |
| 85 | +bool HGCGuardRing::excludePartial(G4ThreeVector& point, int zside, int frontBack, int layer, int waferU, int waferV) { |
| 86 | + bool check(false); |
| 87 | + if (hgcons_.waferHexagon8Cassette()) { |
| 88 | + int index = HGCalWaferIndex::waferIndex(layer, waferU, waferV); |
| 89 | + int partial = HGCalWaferType::getPartial(index, hgcons_.getParameter()->waferInfoMap_); |
| 90 | + int type = HGCalWaferType::getType(index, hgcons_.getParameter()->waferInfoMap_); |
| 91 | +#ifdef EDM_ML_DEBUG |
| 92 | + edm::LogVerbatim("HGCSim") << "HGCGuardRing::excludePartial: Layer " << layer << " wafer " << waferU << ":" << waferV << " index " << index << " partial " << partial << " type " << type; |
| 93 | +#endif |
| 94 | + if (partial == HGCalTypes::WaferFull) { |
| 95 | + return (check); |
| 96 | + } else if (partial < 0) { |
| 97 | + return true; |
| 98 | + } else { |
| 99 | + int orient = HGCalWaferType::getOrient(index, hgcons_.getParameter()->waferInfoMap_); |
| 100 | + int placement = HGCalCell::cellPlacementIndex(zside, frontBack, orient); |
| 101 | + double dx = point.x(); |
| 102 | + double dy = point.y(); |
| 103 | +#ifdef EDM_ML_DEBUG |
| 104 | + edm::LogVerbatim("HGCSim") << "HGCGuardRing::excludePartial: zside " << zside << " frontBack " << frontBack << " orient " << orient << " placement " << placement << " dx " << dx << " dy " << dy; |
| 105 | +#endif |
| 106 | + if (type > 0) { |
| 107 | + for (int ii = HGCalTypes::WaferPartLDOffset; |
| 108 | + ii < (HGCalTypes::WaferPartLDOffset + HGCalTypes::WaferPartLDCount); |
| 109 | + ii++) { |
| 110 | + std::array<double, 4> criterion = HGCalWaferMask::maskCut(ii, placement, waferSize_, offsetPartial_, v17OrLess_); |
| 111 | + check |= std::abs(criterion[0] * dy + criterion[1] * dx + criterion[2]) < criterion[3]; |
| 112 | + } |
| 113 | + } else { |
| 114 | + for (int ii = HGCalTypes::WaferPartHDOffset; |
| 115 | + ii < (HGCalTypes::WaferPartHDOffset + HGCalTypes::WaferPartHDCount); |
| 116 | + ii++) { |
| 117 | + std::array<double, 4> criterion = HGCalWaferMask::maskCut(ii, placement, waferSize_, offsetPartial_, v17OrLess_); |
| 118 | + check |= std::abs(criterion[0] * dy + criterion[1] * dx + criterion[2]) < criterion[3]; |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | +#ifdef EDM_ML_DEBUG |
| 123 | + edm::LogVerbatim("HGCSim") << "HGCGuardRing::excludePartial: Point " << point << " zside " << zside << " layer " << layer << " wafer " << waferU << ":" << waferV << " partial type " << partial << " type " << type << " check " << check; |
| 124 | +#endif |
| 125 | + } |
| 126 | + return check; |
| 127 | +} |
| 128 | + |
| 129 | +bool HGCGuardRing::insidePolygon(double x, double y, const std::vector<std::pair<double, double> >& xyv) { |
| 130 | + int counter(0); |
| 131 | + double x1(xyv[0].first), y1(xyv[0].second); |
| 132 | + for (unsigned i1 = 1; i1 <= xyv.size(); i1++) { |
| 133 | + unsigned i2 = (i1 % xyv.size()); |
| 134 | + double x2(xyv[i2].first), y2(xyv[i2].second); |
| 135 | + if (y > std::min(y1, y2)) { |
| 136 | + if (y <= std::max(y1, y2)) { |
| 137 | + if (x <= std::max(x1, x2)) { |
| 138 | + if (y1 != y2) { |
| 139 | + double xinter = (y - y1) * (x2 - x1) / (y2 - y1) + x1; |
| 140 | + if ((x1 == x2) || (x <= xinter)) |
| 141 | + ++counter; |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | + x1 = x2; |
| 147 | + y1 = y2; |
| 148 | + } |
| 149 | + |
| 150 | + if (counter % 2 == 0) |
| 151 | + return false; |
| 152 | + else |
| 153 | + return true; |
| 154 | +} |
0 commit comments