Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-31 23:46:11

0001 #include "DataFormats/ForwardDetId/interface/HFNoseDetId.h"
0002 #include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
0003 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0004 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "Geometry/HGCalCommonData/interface/HGCalCell.h"
0007 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0008 #include "Geometry/CaloTopology/interface/HGCalTopology.h"
0009 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0010 
0011 //#define EDM_ML_DEBUG
0012 
0013 HGCalTopology::HGCalTopology(const HGCalDDDConstants& hdcons, int det) : hdcons_(hdcons) {
0014   sectors_ = hdcons_.sectors();
0015   layers_ = hdcons_.layers(true);
0016   cells_ = hdcons_.maxCells(true);
0017   mode_ = hdcons_.geomMode();
0018   cellMax_ = hdcons_.maxCellUV();
0019   waferOff_ = hdcons_.waferUVMax();
0020   waferMax_ = 2 * waferOff_ + 1;
0021   kHGhalf_ = sectors_ * layers_ * cells_;
0022   firstLay_ = hdcons_.firstLayer();
0023   if (waferHexagon6()) {
0024     det_ = DetId::Forward;
0025     subdet_ = (ForwardSubdetector)(det);
0026     kHGeomHalf_ = sectors_ * layers_;
0027     types_ = 2;
0028   } else if (det == (int)(DetId::Forward)) {
0029     det_ = DetId::Forward;
0030     subdet_ = HFNose;
0031     kHGeomHalf_ = sectors_ * layers_;
0032     types_ = 3;
0033   } else if (tileTrapezoid()) {
0034     det_ = (DetId::Detector)(det);
0035     subdet_ = ForwardEmpty;
0036     kHGeomHalf_ = sectors_ * layers_ * cellMax_;
0037     types_ = 3;
0038   } else {
0039     det_ = (DetId::Detector)(det);
0040     subdet_ = ForwardEmpty;
0041     kHGeomHalf_ = sectors_ * layers_;
0042     types_ = 3;
0043   }
0044   kHGhalfType_ = sectors_ * layers_ * cells_ * types_;
0045   kSizeForDenseIndexing = static_cast<unsigned int>(2 * kHGhalf_);
0046 #ifdef EDM_ML_DEBUG
0047   edm::LogVerbatim("HGCalGeom") << "HGCalTopology initialized for detector " << det << ":" << det_ << ":" << subdet_
0048                                 << " having " << sectors_ << " Sectors, " << layers_ << " Layers from " << firstLay_
0049                                 << ", " << cells_ << " cells and total channels " << kSizeForDenseIndexing << ":"
0050                                 << (2 * kHGeomHalf_);
0051 #endif
0052 }
0053 
0054 unsigned int HGCalTopology::allGeomModules() const {
0055   return (tileTrapezoid() ? (unsigned int)(2 * hdcons_.numberCells(true)) : (unsigned int)(2 * hdcons_.wafers()));
0056 }
0057 
0058 std::vector<DetId> HGCalTopology::neighbors(const DetId& idin) const {
0059   std::vector<DetId> ids;
0060   HGCalTopology::DecodedDetId id = decode(idin);
0061   if (waferHexagon8()) {
0062     int celltype = hdcons_.cellType(
0063         id.iType, id.iCell1, id.iCell2, id.zSide, 1, -1);  // Temporary fix - later for v17 define fwd back and orient
0064 #ifdef EDM_ML_DEBUG
0065     edm::LogVerbatim("HGCalGeom") << "Type:WaferU:WaferV " << id.iType << ":" << id.iCell1 << ":" << id.iCell2
0066                                   << " CellType " << celltype;
0067 #endif
0068     switch (celltype) {
0069       case (HGCalCell::centralCell): {
0070         // cell within the wafer
0071 #ifdef EDM_ML_DEBUG
0072         edm::LogVerbatim("HGCalGeom") << "Cell Type 0";
0073 #endif
0074         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
0075         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
0076         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
0077         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
0078         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
0079         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
0080         break;
0081       }
0082       case (HGCalCell::bottomLeftEdge): {
0083         // bottom left edge
0084         int wu1(id.iSec1), wv1(id.iSec2 - 1);
0085         int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
0086         int N1 = hdcons_.getUVMax(t1);
0087         int v1 = hdcons_.modifyUV(id.iCell2, id.iType, t1);
0088 #ifdef EDM_ML_DEBUG
0089         edm::LogVerbatim("HGCalGeom") << "Cell Type 1 "
0090                                       << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << v1;
0091 #endif
0092         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
0093         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
0094         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, 2 * N1 - 1, v1 + N1 - 1);
0095         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, 2 * N1 - 1, v1 + N1);
0096         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
0097         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
0098         break;
0099       }
0100       case (HGCalCell::leftEdge): {
0101         // left edege
0102         int wu1(id.iSec1 + 1), wv1(id.iSec2);
0103         int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
0104         int N1 = hdcons_.getUVMax(t1);
0105         int u1 = hdcons_.modifyUV(id.iCell1, id.iType, t1);
0106 #ifdef EDM_ML_DEBUG
0107         edm::LogVerbatim("HGCalGeom") << "Cell Type 2 "
0108                                       << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << u1;
0109 #endif
0110         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
0111         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 + N1, 2 * N1 - 1);
0112         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 + N1 - 1, 2 * N1 - 1);
0113         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
0114         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
0115         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
0116         break;
0117       }
0118       case (HGCalCell::topLeftEdge): {
0119         // top left edge
0120         int wu1(id.iSec1 + 1), wv1(id.iSec2 + 1);
0121         int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
0122         int N1 = hdcons_.getUVMax(t1);
0123         int v1 = hdcons_.modifyUV(id.iCell2, id.iType, t1);
0124 #ifdef EDM_ML_DEBUG
0125         edm::LogVerbatim("HGCalGeom") << "Cell Type 3 "
0126                                       << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << v1;
0127 #endif
0128         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, v1 + 1, v1 + N1);
0129         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, v1, v1 + N1 - 1);
0130         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
0131         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
0132         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
0133         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
0134         break;
0135       }
0136       case (HGCalCell::topRightEdge): {
0137         // top right edge
0138         int wu1(id.iSec1), wv1(id.iSec2 + 1);
0139         int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
0140         int N1 = hdcons_.getUVMax(t1);
0141         int v1 = hdcons_.modifyUV(id.iCell2, id.iType, t1);
0142 #ifdef EDM_ML_DEBUG
0143         edm::LogVerbatim("HGCalGeom") << "Cell Type 4 "
0144                                       << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << v1;
0145 #endif
0146         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, 0, v1 - N1);
0147         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
0148         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
0149         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
0150         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
0151         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, 0, v1 - N1 + 1);
0152         break;
0153       }
0154       case (HGCalCell::rightEdge): {
0155         // right edge
0156         int wu1(id.iSec1 - 1), wv1(id.iSec2);
0157         int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
0158         int N1 = hdcons_.getUVMax(t1);
0159         int u1 = hdcons_.modifyUV(id.iCell1, id.iType, t1);
0160 #ifdef EDM_ML_DEBUG
0161         edm::LogVerbatim("HGCalGeom") << "Cell Type 5 "
0162                                       << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << u1;
0163 #endif
0164         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
0165         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
0166         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
0167         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
0168         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 - N1, 0);
0169         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 - N1 + 1, 0);
0170         break;
0171       }
0172       case (HGCalCell::bottomRightEdge): {
0173         // bottom right edge
0174         int wu1(id.iSec1 - 1), wv1(id.iSec2 - 1);
0175         int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
0176         int N1 = hdcons_.getUVMax(t1);
0177         int u1 = hdcons_.modifyUV(id.iCell1, id.iType, t1);
0178 #ifdef EDM_ML_DEBUG
0179         edm::LogVerbatim("HGCalGeom") << "Cell Type 6 "
0180                                       << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << u1;
0181 #endif
0182         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
0183         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
0184         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
0185         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 + N1 - 1, u1 - 1);
0186         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 + N1, u1);
0187         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
0188         break;
0189       }
0190       case (HGCalCell::bottomCorner): {
0191         // bottom corner
0192         int wu1(id.iSec1), wv1(id.iSec2 - 1);
0193         int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
0194         int N1 = hdcons_.getUVMax(t1);
0195         int v1 = hdcons_.modifyUV(id.iCell2, id.iType, t1);
0196         int wu2(id.iSec1 - 1), wv2(id.iSec2 - 1);
0197         int t2 = hdcons_.getTypeHex(id.iLay, wu2, wv2);
0198         int N2 = hdcons_.getUVMax(t2);
0199         int u2 = hdcons_.modifyUV(id.iCell1, id.iType, t2);
0200 #ifdef EDM_ML_DEBUG
0201         edm::LogVerbatim("HGCalGeom") << "Cell Type 11 "
0202                                       << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << v1 << ":" << t2
0203                                       << ":" << N2 << ":" << u2;
0204 #endif
0205         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
0206         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
0207         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, 2 * N1 - 1, v1 + N1 - 1);
0208         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, 2 * N1 - 1, v1 + N1);
0209         addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, u2 + N2, u2);
0210         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
0211         break;
0212       }
0213       case (HGCalCell::bottomLeftCorner): {
0214         // bottom left corner
0215         int wu1(id.iSec1 + 1), wv1(id.iSec2);
0216         int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
0217         int N1 = hdcons_.getUVMax(t1);
0218         int u1 = hdcons_.modifyUV(id.iCell1, id.iType, t1);
0219         int wu2(id.iSec1), wv2(id.iSec2 - 1);
0220         int t2 = hdcons_.getTypeHex(id.iLay, wu2, wv2);
0221         int N2 = hdcons_.getUVMax(t2);
0222         int v2 = hdcons_.modifyUV(id.iCell2, id.iType, t2);
0223 #ifdef EDM_ML_DEBUG
0224         edm::LogVerbatim("HGCalGeom") << "Cell Type 12 "
0225                                       << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << u1 << ":" << t2
0226                                       << ":" << N2 << ":" << v2;
0227 #endif
0228         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
0229         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 + N1, 2 * N1 - 1);
0230         addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, 2 * N2 - 1, v2 + N2 - 1);
0231         addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, 2 * N2 - 1, v2 + N2);
0232         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
0233         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
0234         break;
0235       }
0236       case (HGCalCell::topLeftCorner): {
0237         // top left corner
0238         int wu1(id.iSec1 + 1), wv1(id.iSec2 + 1);
0239         int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
0240         int N1 = hdcons_.getUVMax(t1);
0241         int v1 = hdcons_.modifyUV(id.iCell2, id.iType, t1);
0242         int wu2(id.iSec1 + 1), wv2(id.iSec2);
0243         int t2 = hdcons_.getTypeHex(id.iLay, wu2, wv2);
0244         int N2 = hdcons_.getUVMax(t2);
0245         int u2 = hdcons_.modifyUV(id.iCell1, id.iType, t2);
0246 #ifdef EDM_ML_DEBUG
0247         edm::LogVerbatim("HGCalGeom") << "Cell Type 13 "
0248                                       << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << v1 << ":" << t2
0249                                       << ":" << N2 << ":" << u2;
0250 #endif
0251         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, v1 + 1, N1 + v1);
0252         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, v1, N1 + v1 - 1);
0253         addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, u2 + N2 - 1, 2 * N2 - 1);
0254         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
0255         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
0256         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
0257         break;
0258       }
0259       case (HGCalCell::topCorner): {
0260         // top corner
0261         int wu1(id.iSec1 + 1), wv1(id.iSec2 + 1);
0262         int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
0263         int N1 = hdcons_.getUVMax(t1);
0264         int v1 = hdcons_.modifyUV(id.iCell2, id.iType, t1);
0265         int wu2(id.iSec1), wv2(id.iSec2 + 1);
0266         int t2 = hdcons_.getTypeHex(id.iLay, wu2, wv2);
0267         int N2 = hdcons_.getUVMax(t2);
0268         int v2 = hdcons_.modifyUV(id.iCell2, id.iType, t2);
0269 #ifdef EDM_ML_DEBUG
0270         edm::LogVerbatim("HGCalGeom") << "Cell Type 14 "
0271                                       << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << v1 << ":" << t2
0272                                       << ":" << N2 << ":" << v2;
0273 #endif
0274         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, v1 + 1, v1 + N1);
0275         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, v1, v1 + N1 - 1);
0276         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
0277         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
0278         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
0279         addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, 0, v2 - N2 + 1);
0280         break;
0281       }
0282       case (HGCalCell::topRightCorner): {
0283         // top right corner
0284         int wu1(id.iSec1), wv1(id.iSec2 + 1);
0285         int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
0286         int N1 = hdcons_.getUVMax(t1);
0287         int v1 = hdcons_.modifyUV(id.iCell2, id.iType, t1);
0288         int wu2(id.iSec1 - 1), wv2(id.iSec2);
0289         int t2 = hdcons_.getTypeHex(id.iLay, wu2, wv2);
0290         int N2 = hdcons_.getUVMax(t2);
0291         int u2 = hdcons_.modifyUV(id.iCell1, id.iType, t2);
0292 #ifdef EDM_ML_DEBUG
0293         edm::LogVerbatim("HGCalGeom") << "Cell Type 15 "
0294                                       << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << v1 << ":" << t2
0295                                       << ":" << N2 << ":" << u2;
0296 #endif
0297         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, 0, v1 - N1);
0298         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
0299         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
0300         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
0301         addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, u2 - N2, 0);
0302         addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, u2 - N2 + 1, 0);
0303         break;
0304       }
0305       case (HGCalCell::bottomRightCorner): {
0306         // bottom right corner
0307         int wu1(id.iSec1 - 1), wv1(id.iSec2 - 1);
0308         int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
0309         int N1 = hdcons_.getUVMax(t1);
0310         int u1 = hdcons_.modifyUV(id.iCell1, id.iType, t1);
0311         int wu2(id.iSec1 - 1), wv2(id.iSec2);
0312         int t2 = hdcons_.getTypeHex(id.iLay, wu2, wv2);
0313         int N2 = hdcons_.getUVMax(t2);
0314         int u2 = hdcons_.modifyUV(id.iCell1, id.iType, t2);
0315 #ifdef EDM_ML_DEBUG
0316         edm::LogVerbatim("HGCalGeom") << "Cell Type 16 "
0317                                       << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << u1 << ":" << t2
0318                                       << ":" << N2 << ":" << u2;
0319 #endif
0320         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
0321         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
0322         addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
0323         addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 + N1 - 1, u1 - 1);
0324         addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, u2 - N2, 0);
0325         addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, u2 - N2 + 1, 0);
0326         break;
0327       }
0328       default:
0329         // Not valid u, v
0330         int N = hdcons_.getUVMax(id.iType);
0331         edm::LogWarning("HGCalGeom") << "u:v " << id.iCell1 << ":" << id.iCell2 << " Tests " << (id.iCell1 > 2 * N - 1)
0332                                      << ":" << (id.iCell2 > 2 * N - 1) << ":" << (id.iCell2 >= (id.iCell1 + N)) << ":"
0333                                      << (id.iCell1 > (id.iCell2 + N)) << " ERROR";
0334     }
0335   } else if (tileTrapezoid()) {
0336     int iphi1 = (id.iCell1 > 1) ? id.iCell1 - 1 : hdcons_.getUVMax(id.iType);
0337     int iphi2 = (id.iCell1 < hdcons_.getUVMax(id.iType)) ? id.iCell1 + 1 : 1;
0338     addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1 - 1, id.iCell1);
0339     addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1 - 1, iphi1);
0340     addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1, iphi1);
0341     addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1 + 1, iphi1);
0342     addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1 + 1, id.iCell1);
0343     addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1 + 1, iphi2);
0344     addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1, iphi2);
0345     addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1 - 1, iphi2);
0346   }
0347   return ids;
0348 }
0349 
0350 uint32_t HGCalTopology::detId2denseId(const DetId& idin) const {
0351   HGCalTopology::DecodedDetId id = decode(idin);
0352   uint32_t idx;
0353   if (waferHexagon6()) {
0354     int type = (id.iType > 0) ? 1 : 0;
0355     idx = (uint32_t)(((id.zSide > 0) ? kHGhalfType_ : 0) +
0356                      ((((id.iCell1 - 1) * layers_ + id.iLay - 1) * sectors_ + id.iSec1) * types_ + type));
0357 #ifdef EDM_ML_DEBUG
0358     edm::LogVerbatim("HGCalGeom") << "Input Hex " << id.zSide << ":" << id.iLay << ":" << id.iSec1 << ":" << id.iCell1
0359                                   << ":" << id.iType << " Constants " << kHGeomHalf_ << ":" << layers_ << ":"
0360                                   << sectors_ << ":" << types_ << " o/p " << idx;
0361 #endif
0362   } else if (tileTrapezoid()) {
0363     idx =
0364         (uint32_t)(((id.zSide > 0) ? kHGhalfType_ : 0) +
0365                    ((((id.iCell1 - 1) * layers_ + id.iLay - firstLay_) * sectors_ + id.iSec1 - 1) * types_ + id.iType));
0366 #ifdef EDM_ML_DEBUG
0367     edm::LogVerbatim("HGCalGeom") << "Input Trap " << id.zSide << ":" << id.iLay << ":" << id.iSec1 << ":" << id.iCell1
0368                                   << ":" << id.iType << " Constants " << kHGeomHalf_ << ":" << layers_ << ":"
0369                                   << sectors_ << ":" << types_ << " o/p " << idx;
0370 #endif
0371   } else {
0372     idx =
0373         (uint32_t)(((id.zSide > 0) ? kHGhalfType_ : 0) +
0374                    (((((id.iCell1 * cellMax_ + id.iCell2) * layers_ + id.iLay - 1) * waferMax_ + id.iSec1 + waferOff_) *
0375                          waferMax_ +
0376                      id.iSec2 + waferOff_) *
0377                         types_ +
0378                     id.iType));
0379 #ifdef EDM_ML_DEBUG
0380     edm::LogVerbatim("HGCalGeom") << "Input Hex8 " << id.zSide << ":" << id.iLay << ":" << id.iSec1 << ":" << id.iSec2
0381                                   << ":" << id.iCell1 << ":" << id.iCell2 << ":" << id.iType << " Constants "
0382                                   << kHGeomHalf_ << ":" << cellMax_ << ":" << layers_ << ":" << waferMax_ << ":"
0383                                   << waferOff_ << ":" << types_ << " o/p " << idx;
0384 #endif
0385   }
0386   return idx;
0387 }
0388 
0389 DetId HGCalTopology::denseId2detId(uint32_t hi) const {
0390   HGCalTopology::DecodedDetId id;
0391   if (validHashIndex(hi)) {
0392     id.zSide = ((int)(hi) < kHGhalfType_ ? -1 : 1);
0393     int di = ((int)(hi) % kHGhalfType_);
0394     if (waferHexagon6()) {
0395       int type = (di % types_);
0396       id.iType = (type == 0 ? -1 : 1);
0397       id.iSec1 = (((di - type) / types_) % sectors_);
0398       id.iLay = (((((di - type) / types_) - id.iSec1 + 1) / sectors_) % layers_ + 1);
0399       id.iCell1 = (((((di - type) / types_) - id.iSec1 + 1) / sectors_ - id.iLay + 1) / layers_ + 1);
0400 #ifdef EDM_ML_DEBUG
0401       edm::LogVerbatim("HGCalGeom") << "Input Hex " << hi << " o/p " << id.zSide << ":" << id.iLay << ":" << id.iType
0402                                     << ":" << id.iSec1 << ":" << id.iCell1;
0403 #endif
0404     } else if (tileTrapezoid()) {
0405       int type = (di % types_);
0406       id.iType = type;
0407       id.iSec1 = (((di - type) / types_) % sectors_) + 1;
0408       id.iLay = (((((di - type) / types_) - id.iSec1 + 1) / sectors_) % layers_ + firstLay_);
0409       id.iCell1 = (((((di - type) / types_) - id.iSec1 + 1) / sectors_ - id.iLay + firstLay_) / layers_ + 1);
0410 #ifdef EDM_ML_DEBUG
0411       edm::LogVerbatim("HGCalGeom") << "Input Trap " << hi << " o/p " << id.zSide << ":" << id.iLay << ":" << id.iType
0412                                     << ":" << id.iSec1 << ":" << id.iCell1;
0413 #endif
0414     } else {
0415       int type = (di % types_);
0416       id.iType = type;
0417       di = (di - type) / types_;
0418       id.iSec2 = (di % waferMax_) - waferOff_;
0419       di = (di - id.iSec2 - waferOff_) / waferMax_;
0420       id.iSec1 = (di % waferMax_) - waferOff_;
0421       di = (di - id.iSec1 - waferOff_) / waferMax_;
0422       id.iLay = (di % layers_) + 1;
0423       di = (di - id.iLay + 1) / layers_;
0424       id.iCell2 = (di % cellMax_);
0425       id.iCell1 = (di - id.iCell2) / cellMax_;
0426 #ifdef EDM_ML_DEBUG
0427       edm::LogVerbatim("HGCalGeom") << "Input Hex8 " << hi << " o/p " << id.zSide << ":" << id.iLay << ":" << id.iType
0428                                     << ":" << id.iSec1 << ":" << id.iSec2 << ":" << id.iCell1 << ":" << id.iCell2;
0429 #endif
0430     }
0431   }
0432   return encode(id);
0433 }
0434 
0435 uint32_t HGCalTopology::detId2denseGeomId(const DetId& idin) const {
0436   HGCalTopology::DecodedDetId id = decode(idin);
0437   uint32_t idx;
0438   if (waferHexagon6()) {
0439     idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) + (id.iLay - 1) * sectors_ + id.iSec1);
0440 #ifdef EDM_ML_DEBUG
0441     edm::LogVerbatim("HGCalGeom") << "Geom Hex I/P " << id.zSide << ":" << id.iLay << ":" << id.iSec1 << ":" << id.iType
0442                                   << " Constants " << kHGeomHalf_ << ":" << layers_ << ":" << sectors_ << " o/p "
0443                                   << idx;
0444 #endif
0445   } else if (tileTrapezoid()) {
0446     idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) +
0447                      (((id.iLay - firstLay_) * sectors_ + id.iSec1 - 1) * cellMax_ + id.iCell1 - 1));
0448 #ifdef EDM_ML_DEBUG
0449     edm::LogVerbatim("HGCalGeom") << "Geom Trap I/P " << id.zSide << ":" << id.iLay << ":" << id.iSec1 << ":"
0450                                   << id.iCell1 << ":" << id.iType << " Constants " << kHGeomHalf_ << ":" << layers_
0451                                   << ":" << firstLay_ << ":" << sectors_ << ":" << cellMax_ << " o/p " << idx;
0452 #endif
0453   } else {
0454     idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) +
0455                      (((id.iLay - 1) * waferMax_ + id.iSec1 + waferOff_) * waferMax_ + id.iSec2 + waferOff_));
0456 #ifdef EDM_ML_DEBUG
0457     edm::LogVerbatim("HGCalGeom") << "Geom Hex8 I/P " << id.zSide << ":" << id.iLay << ":" << id.iSec1 << ":"
0458                                   << id.iSec2 << ":" << id.iType << " Constants " << kHGeomHalf_ << ":" << layers_
0459                                   << ":" << waferMax_ << ":" << waferOff_ << " o/p " << idx;
0460 #endif
0461   }
0462   return idx;
0463 }
0464 
0465 bool HGCalTopology::valid(const DetId& idin) const {
0466   HGCalTopology::DecodedDetId id = decode(idin);
0467   bool flag;
0468   if (waferHexagon6()) {
0469     flag = (idin.det() == det_ && idin.subdetId() == (int)(subdet_) && id.iCell1 >= 0 && id.iCell1 < cells_ &&
0470             id.iLay > 0 && id.iLay <= layers_ && id.iSec1 >= 0 && id.iSec1 <= sectors_);
0471     if (flag)
0472       flag = hdcons_.isValidHex(id.iLay, id.iSec1, id.iCell1, true);
0473   } else if (tileTrapezoid()) {
0474     flag = ((idin.det() == det_) && hdcons_.isValidTrap(id.iLay, id.iSec1, id.iCell1));
0475   } else {
0476     flag = ((idin.det() == det_) && hdcons_.isValidHex8(id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2));
0477   }
0478   return flag;
0479 }
0480 
0481 bool HGCalTopology::valid(const DetId& idin, int cornerMin) const {
0482   if (waferHexagon8()) {
0483     HGCalTopology::DecodedDetId id = decode(idin);
0484     bool mask = (cornerMin < HGCalTypes::WaferCornerMin) ? false : hdcons_.maskCell(idin, cornerMin);
0485     bool flag = ((idin.det() == det_) &&
0486                  hdcons_.isValidHex8(
0487                      id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, (cornerMin >= HGCalTypes::WaferCornerMin)));
0488     return (flag && (!mask));
0489   } else {
0490     return valid(idin);
0491   }
0492 }
0493 
0494 bool HGCalTopology::validModule(const DetId& idin, int cornerMin) const {
0495   if (idin.det() != det_) {
0496     return false;
0497   } else if ((idin.det() == DetId::HGCalEE) || (idin.det() == DetId::HGCalHSi)) {
0498     HGCalTopology::DecodedDetId id = decode(idin);
0499     return hdcons_.isValidHex8(id.iLay, id.iSec1, id.iSec2, (cornerMin >= HGCalTypes::WaferCornerMin));
0500   } else {
0501     return valid(idin);
0502   }
0503 }
0504 
0505 DetId HGCalTopology::offsetBy(const DetId startId, int nrStepsX, int nrStepsY) const {
0506   if (startId.det() == DetId::Forward && startId.subdetId() == (int)(subdet_)) {
0507     DetId id = changeXY(startId, nrStepsX, nrStepsY);
0508     if (valid(id))
0509       return id;
0510   }
0511   return DetId(0);
0512 }
0513 
0514 DetId HGCalTopology::switchZSide(const DetId startId) const {
0515   HGCalTopology::DecodedDetId id_ = decode(startId);
0516   id_.zSide = -id_.zSide;
0517   DetId id = encode(id_);
0518   if (valid(id))
0519     return id;
0520   else
0521     return DetId(0);
0522 }
0523 
0524 HGCalTopology::DecodedDetId HGCalTopology::geomDenseId2decId(const uint32_t& hi) const {
0525   HGCalTopology::DecodedDetId id;
0526   if (hi < totalGeomModules()) {
0527     id.zSide = ((int)(hi) < kHGeomHalf_ ? -1 : 1);
0528     int di = ((int)(hi) % kHGeomHalf_);
0529     if (waferHexagon6()) {
0530       id.iSec1 = (di % sectors_);
0531       di = (di - id.iSec1) / sectors_;
0532       id.iLay = (di % layers_) + 1;
0533       id.iType = ((di - id.iLay + 1) / layers_ == 0) ? -1 : 1;
0534 #ifdef EDM_ML_DEBUG
0535       edm::LogVerbatim("HGCalGeom") << "Geom Hex I/P " << hi << " O/P " << id.zSide << ":" << id.iType << ":" << id.iLay
0536                                     << ":" << id.iSec1;
0537 #endif
0538     } else if (tileTrapezoid()) {
0539       id.iCell1 = (di % cellMax_) + 1;
0540       di = (di - id.iCell1 + 1) / cellMax_;
0541       id.iSec1 = (di % sectors_) + 1;
0542       di = (di - id.iSec1 + 1) / sectors_;
0543       id.iLay = (di % layers_) + firstLay_;
0544       id.iType = (di - id.iLay + firstLay_) / layers_;
0545 #ifdef EDM_ML_DEBUG
0546       edm::LogVerbatim("HGCalGeom") << "Geom Trap I/P " << hi << " O/P " << id.zSide << ":" << id.iType << ":"
0547                                     << id.iLay << ":" << id.iSec1 << ":" << id.iCell1;
0548 #endif
0549     } else {
0550       id.iSec2 = (di % waferMax_) - waferOff_;
0551       di = (di - id.iSec2 - waferOff_) / waferMax_;
0552       id.iSec1 = (di % waferMax_) - waferOff_;
0553       di = (di - id.iSec1 - waferOff_) / waferMax_;
0554       id.iLay = (di % layers_) + 1;
0555       id.iType = (di - id.iLay + 1) / layers_;
0556 #ifdef EDM_ML_DEBUG
0557       edm::LogVerbatim("HGCalGeom") << "Geom Hex8 I/P " << hi << " O/P " << id.zSide << ":" << id.iType << ":"
0558                                     << id.iLay << ":" << id.iSec1 << ":" << id.iSec2;
0559 #endif
0560     }
0561   }
0562   return id;
0563 }
0564 
0565 void HGCalTopology::addHGCSCintillatorId(
0566     std::vector<DetId>& ids, int zside, int type, int lay, int iradius, int iphi) const {
0567 #ifdef EDM_ML_DEBUG
0568   edm::LogVerbatim("HGCalGeom") << "addHGCSCintillatorId " << zside << ":" << type << ":" << lay << ":" << iradius
0569                                 << ":" << iphi << " ==> Validity " << hdcons_.isValidTrap(lay, iradius, iphi);
0570 #endif
0571   if (hdcons_.isValidTrap(lay, iradius, iphi)) {
0572     HGCScintillatorDetId id(type, lay, zside * iradius, iphi);
0573     ids.emplace_back(DetId(id));
0574   }
0575 }
0576 
0577 void HGCalTopology::addHGCSiliconId(
0578     std::vector<DetId>& ids, int det, int zside, int type, int lay, int waferU, int waferV, int cellU, int cellV) const {
0579 #ifdef EDM_ML_DEBUG
0580   edm::LogVerbatim("HGCalGeom") << "addHGCSiliconId " << det << ":" << zside << ":" << type << ":" << lay << ":"
0581                                 << waferU << ":" << waferV << ":" << cellU << ":" << cellV << " ==> Validity "
0582                                 << hdcons_.isValidHex8(lay, waferU, waferV, cellU, cellV);
0583 #endif
0584   if (hdcons_.isValidHex8(lay, waferU, waferV, cellU, cellV)) {
0585     HGCSiliconDetId id((DetId::Detector)(det), zside, type, lay, waferU, waferV, cellU, cellV);
0586     ids.emplace_back(DetId(id));
0587   }
0588 }
0589 
0590 HGCalTopology::DecodedDetId HGCalTopology::decode(const DetId& startId) const {
0591   HGCalTopology::DecodedDetId idx;
0592   if (waferHexagon6()) {
0593     HGCalDetId id(startId);
0594     idx.iCell1 = id.cell();
0595     idx.iCell2 = 0;
0596     idx.iLay = id.layer();
0597     idx.iSec1 = id.wafer();
0598     idx.iSec2 = 0;
0599     idx.iType = id.waferType();
0600     idx.zSide = id.zside();
0601     idx.det = id.subdetId();
0602   } else if (tileTrapezoid()) {
0603     HGCScintillatorDetId id(startId);
0604     idx.iCell1 = id.iphi();
0605     idx.iCell2 = 0;
0606     idx.iLay = id.layer();
0607     idx.iSec1 = id.ietaAbs();
0608     idx.iSec2 = 0;
0609     idx.iType = id.type();
0610     idx.zSide = id.zside();
0611     idx.det = (int)(id.subdet());
0612   } else if (det_ == DetId::Forward && subdet_ == ForwardSubdetector::HFNose) {
0613     HFNoseDetId id(startId);
0614     idx.iCell1 = id.cellU();
0615     idx.iCell2 = id.cellV();
0616     idx.iLay = id.layer();
0617     idx.iSec1 = id.waferU();
0618     idx.iSec2 = id.waferV();
0619     idx.iType = id.type();
0620     idx.zSide = id.zside();
0621     idx.det = (int)(id.subdet());
0622   } else {
0623     HGCSiliconDetId id(startId);
0624     idx.iCell1 = id.cellU();
0625     idx.iCell2 = id.cellV();
0626     idx.iLay = id.layer();
0627     idx.iSec1 = id.waferU();
0628     idx.iSec2 = id.waferV();
0629     idx.iType = id.type();
0630     idx.zSide = id.zside();
0631     idx.det = (int)(id.subdet());
0632   }
0633   return idx;
0634 }
0635 
0636 DetId HGCalTopology::encode(const HGCalTopology::DecodedDetId& idx) const {
0637   DetId id;
0638 #ifdef EDM_ML_DEBUG
0639   edm::LogVerbatim("HGCalGeomX") << "Encode " << idx.det << ":" << idx.zSide << ":" << idx.iType << ":" << idx.iLay
0640                                  << ":" << idx.iSec1 << ":" << idx.iSec2 << ":" << idx.iCell1 << ":" << idx.iCell2;
0641 #endif
0642   if (waferHexagon6()) {
0643     id =
0644         HGCalDetId((ForwardSubdetector)(idx.det), idx.zSide, idx.iLay, ((idx.iType > 0) ? 1 : 0), idx.iSec1, idx.iCell1)
0645             .rawId();
0646   } else if (tileTrapezoid()) {
0647     HGCScintillatorDetId hid(idx.iType, idx.iLay, idx.zSide * idx.iSec1, idx.iCell1);
0648     std::pair<int, int> typm = hdcons_.tileType(hid.layer(), hid.ring(), 0);
0649     if (typm.first >= 0) {
0650       hid.setType(typm.first);
0651       hid.setSiPM(typm.second);
0652     }
0653     id = hid.rawId();
0654   } else if (det_ == DetId::Forward && subdet_ == ForwardSubdetector::HFNose) {
0655     id = HFNoseDetId(idx.zSide, idx.iType, idx.iLay, idx.iSec1, idx.iSec2, idx.iCell1, idx.iCell2).rawId();
0656   } else {
0657     id = HGCSiliconDetId(
0658              (DetId::Detector)(idx.det), idx.zSide, idx.iType, idx.iLay, idx.iSec1, idx.iSec2, idx.iCell1, idx.iCell2)
0659              .rawId();
0660   }
0661   return id;
0662 }
0663 
0664 DetId HGCalTopology::changeXY(const DetId& id, int nrStepsX, int nrStepsY) const { return DetId(); }
0665 
0666 DetId HGCalTopology::changeZ(const DetId& id, int nrStepsZ) const { return DetId(); }
0667 
0668 #include "FWCore/Utilities/interface/typelookup.h"
0669 
0670 TYPELOOKUP_DATA_REG(HGCalTopology);