Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-16 22:52:24

0001 /* for High Granularity Calorimeter
0002  * This geometry is essentially driven by topology, 
0003  * which is thus encapsulated in this class. 
0004  * This makes this geometry not suitable to be loaded
0005  * by regular CaloGeometryLoader<T>
0006  */
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 #include "DataFormats/GeometrySurface/interface/Plane.h"
0010 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0011 #include "Geometry/CaloGeometry/interface/CaloGenericDetId.h"
0012 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0013 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0014 #include "TrackingTools/GeomPropagators/interface/AnalyticalPropagator.h"
0015 
0016 #include <cmath>
0017 
0018 #include <Math/Transform3D.h>
0019 #include <Math/EulerAngles.h>
0020 
0021 typedef CaloCellGeometry::Tr3D Tr3D;
0022 typedef std::vector<float> ParmVec;
0023 
0024 //#define EDM_ML_DEBUG
0025 
0026 const bool debugLocate = false;
0027 
0028 HGCalGeometry::HGCalGeometry(const HGCalTopology& topology_)
0029     : m_topology(topology_),
0030       m_validGeomIds(topology_.totalGeomModules()),
0031       m_det(topology_.detector()),
0032       m_subdet(topology_.subDetector()),
0033       twoBysqrt3_(2.0 / std::sqrt(3.0)) {
0034   if (m_det == DetId::HGCalHSc) {
0035     m_cellVec2 = CellVec2(topology_.totalGeomModules());
0036   } else {
0037     m_cellVec = CellVec(topology_.totalGeomModules());
0038   }
0039   m_validIds.reserve(m_topology.totalModules());
0040 #ifdef EDM_ML_DEBUG
0041   edm::LogVerbatim("HGCalGeom") << "Expected total # of Geometry Modules " << m_topology.totalGeomModules();
0042 #endif
0043 }
0044 
0045 void HGCalGeometry::fillNamedParams(DDFilteredView fv) {}
0046 
0047 void HGCalGeometry::initializeParms() {}
0048 
0049 void HGCalGeometry::localCorners(Pt3DVec& lc, const CCGFloat* pv, unsigned int i, Pt3D& ref) {
0050   if (m_det == DetId::HGCalHSc) {
0051     FlatTrd::localCorners(lc, pv, ref);
0052   } else {
0053     FlatHexagon::localCorners(lc, pv, ref);
0054   }
0055 }
0056 
0057 void HGCalGeometry::newCell(
0058     const GlobalPoint& f1, const GlobalPoint& f2, const GlobalPoint& f3, const CCGFloat* parm, const DetId& detId) {
0059   DetId geomId = getGeometryDetId(detId);
0060   int cells(0);
0061   HGCalTopology::DecodedDetId id = m_topology.decode(detId);
0062   if (m_topology.waferHexagon6()) {
0063     cells = m_topology.dddConstants().numberCellsHexagon(id.iSec1);
0064 #ifdef EDM_ML_DEBUG
0065     edm::LogVerbatim("HGCalGeom") << "NewCell " << HGCalDetId(detId) << " GEOM " << HGCalDetId(geomId);
0066 #endif
0067   } else if (m_topology.tileTrapezoid()) {
0068     cells = 1;
0069 #ifdef EDM_ML_DEBUG
0070     edm::LogVerbatim("HGCalGeom") << "NewCell " << HGCScintillatorDetId(detId) << " GEOM "
0071                                   << HGCScintillatorDetId(geomId);
0072 #endif
0073   } else {
0074     cells = m_topology.dddConstants().numberCellsHexagon(id.iLay, id.iSec1, id.iSec2, false);
0075 #ifdef EDM_ML_DEBUG
0076     if (detId.det() == DetId::Forward)
0077       edm::LogVerbatim("HGCalGeom") << "NewCell " << HFNoseDetId(detId) << " GEOM " << HFNoseDetId(geomId);
0078     else
0079       edm::LogVerbatim("HGCalGeom") << "NewCell " << HGCSiliconDetId(detId) << " GEOM " << HGCSiliconDetId(geomId);
0080 #endif
0081   }
0082   const uint32_t cellIndex(m_topology.detId2denseGeomId(geomId));
0083 
0084   if (m_det == DetId::HGCalHSc) {
0085     m_cellVec2.at(cellIndex) = FlatTrd(cornersMgr(), f1, f2, f3, parm);
0086   } else {
0087     m_cellVec.at(cellIndex) = FlatHexagon(cornersMgr(), f1, f2, f3, parm);
0088   }
0089   m_validGeomIds.at(cellIndex) = geomId;
0090 
0091 #ifdef EDM_ML_DEBUG
0092   edm::LogVerbatim("HGCalGeom") << "Store for DetId " << std::hex << detId.rawId() << " GeomId " << geomId.rawId()
0093                                 << std::dec << " Index " << cellIndex << " cells " << cells;
0094   unsigned int nOld = m_validIds.size();
0095 #endif
0096   if (m_topology.waferHexagon6()) {
0097     for (int cell = 0; cell < cells; ++cell) {
0098       id.iCell1 = cell;
0099       DetId idc = m_topology.encode(id);
0100       if (m_topology.valid(idc)) {
0101         m_validIds.emplace_back(idc);
0102 #ifdef EDM_ML_DEBUG
0103         edm::LogVerbatim("HGCalGeom") << "Valid Id [" << cell << "] " << HGCalDetId(idc);
0104 #endif
0105       }
0106     }
0107   } else if (m_topology.tileTrapezoid()) {
0108     DetId idc = m_topology.encode(id);
0109     if (m_topology.valid(idc)) {
0110       HGCScintillatorDetId hid(idc);
0111       std::pair<int, int> typm = m_topology.dddConstants().tileType(hid.layer(), hid.ring(), 0);
0112       if (typm.first >= 0) {
0113         hid.setType(typm.first);
0114         hid.setSiPM(typm.second);
0115         idc = static_cast<DetId>(hid);
0116       }
0117       m_validIds.emplace_back(idc);
0118 #ifdef EDM_ML_DEBUG
0119       edm::LogVerbatim("HGCalGeom") << "Valid Id [0] " << HGCScintillatorDetId(idc);
0120 #endif
0121     } else {
0122       edm::LogWarning("HGCalGeom") << "Check " << HGCScintillatorDetId(idc) << " from " << HGCScintillatorDetId(detId)
0123                                    << " ERROR ???";
0124     }
0125   } else {
0126 #ifdef EDM_ML_DEBUG
0127     unsigned int cellAll(0), cellSelect(0);
0128 #endif
0129     for (int u = 0; u < 2 * cells; ++u) {
0130       for (int v = 0; v < 2 * cells; ++v) {
0131         if (((v - u) < cells) && (u - v) <= cells) {
0132           id.iCell1 = u;
0133           id.iCell2 = v;
0134           DetId idc = m_topology.encode(id);
0135 #ifdef EDM_ML_DEBUG
0136           ++cellAll;
0137 #endif
0138           if (m_topology.dddConstants().cellInLayer(id.iSec1, id.iSec2, u, v, id.iLay, id.zSide, true)) {
0139             m_validIds.emplace_back(idc);
0140 #ifdef EDM_ML_DEBUG
0141             ++cellSelect;
0142             if (idc.det() == DetId::Forward)
0143               edm::LogVerbatim("HGCalGeom") << "Valid Id [" << u << ", " << v << "] " << HFNoseDetId(idc);
0144             else
0145               edm::LogVerbatim("HGCalGeom") << "Valid Id [" << u << ", " << v << "] " << HGCSiliconDetId(idc);
0146 #endif
0147           }
0148         }
0149       }
0150     }
0151 #ifdef EDM_ML_DEBUG
0152     edm::LogVerbatim("HGCalGeom") << "HGCalGeometry keeps " << cellSelect << " out of " << cellAll << " for wafer "
0153                                   << id.iSec1 << ":" << id.iSec2 << " in "
0154                                   << " layer " << id.iLay;
0155 #endif
0156   }
0157 #ifdef EDM_ML_DEBUG
0158   if (m_det == DetId::HGCalHSc) {
0159     edm::LogVerbatim("HGCalGeom") << "HGCalGeometry::newCell-> [" << cellIndex << "]"
0160                                   << " front:" << f1.x() << '/' << f1.y() << '/' << f1.z() << " back:" << f2.x() << '/'
0161                                   << f2.y() << '/' << f2.z() << " eta|phi " << m_cellVec2[cellIndex].etaPos() << ":"
0162                                   << m_cellVec2[cellIndex].phiPos();
0163   } else {
0164     edm::LogVerbatim("HGCalGeom") << "HGCalGeometry::newCell-> [" << cellIndex << "]"
0165                                   << " front:" << f1.x() << '/' << f1.y() << '/' << f1.z() << " back:" << f2.x() << '/'
0166                                   << f2.y() << '/' << f2.z() << " eta|phi " << m_cellVec[cellIndex].etaPos() << ":"
0167                                   << m_cellVec[cellIndex].phiPos();
0168   }
0169   unsigned int nNew = m_validIds.size();
0170   if (m_topology.waferHexagon6()) {
0171     edm::LogVerbatim("HGCalGeom") << "ID: " << HGCalDetId(detId) << " with valid DetId from " << nOld << " to " << nNew;
0172   } else if (m_topology.tileTrapezoid()) {
0173     edm::LogVerbatim("HGCalGeom") << "ID: " << HGCScintillatorDetId(detId) << " with valid DetId from " << nOld
0174                                   << " to " << nNew;
0175   } else if (m_topology.isHFNose()) {
0176     edm::LogVerbatim("HGCalGeom") << "ID: " << HFNoseDetId(detId) << " with valid DetId from " << nOld << " to "
0177                                   << nNew;
0178   } else {
0179     edm::LogVerbatim("HGCalGeom") << "ID: " << HGCSiliconDetId(detId) << " with valid DetId from " << nOld << " to "
0180                                   << nNew;
0181   }
0182   edm::LogVerbatim("HGCalGeom") << "Cell[" << cellIndex << "] " << std::hex << geomId.rawId() << ":"
0183                                 << m_validGeomIds[cellIndex].rawId() << std::dec;
0184 #endif
0185 }
0186 
0187 std::shared_ptr<const CaloCellGeometry> HGCalGeometry::getGeometry(const DetId& detId) const {
0188   if (detId == DetId())
0189     return nullptr;  // nothing to get
0190   DetId geomId = getGeometryDetId(detId);
0191   const uint32_t cellIndex(m_topology.detId2denseGeomId(geomId));
0192   const GlobalPoint pos = (detId != geomId) ? getPosition(detId, false) : GlobalPoint();
0193   return cellGeomPtr(cellIndex, pos);
0194 }
0195 
0196 bool HGCalGeometry::present(const DetId& detId) const {
0197   if (detId == DetId())
0198     return false;
0199   DetId geomId = getGeometryDetId(detId);
0200   const uint32_t index(m_topology.detId2denseGeomId(geomId));
0201   return (nullptr != getGeometryRawPtr(index));
0202 }
0203 
0204 GlobalPoint HGCalGeometry::getPosition(const DetId& detid, bool debug) const {
0205   return getPosition(detid, false, debug);
0206 }
0207 
0208 GlobalPoint HGCalGeometry::getPosition(const DetId& detid, bool cog, bool debug) const {
0209   unsigned int cellIndex = indexFor(detid);
0210   GlobalPoint glob;
0211   unsigned int maxSize = (m_topology.tileTrapezoid() ? m_cellVec2.size() : m_cellVec.size());
0212   if (cellIndex < maxSize) {
0213     HGCalTopology::DecodedDetId id = m_topology.decode(detid);
0214     std::pair<float, float> xy;
0215     if (m_topology.waferHexagon6()) {
0216       xy = m_topology.dddConstants().locateCellHex(id.iCell1, id.iSec1, true);
0217       const HepGeom::Point3D<float> lcoord(xy.first, xy.second, 0);
0218       glob = m_cellVec[cellIndex].getPosition(lcoord);
0219       if (debug)
0220         edm::LogVerbatim("HGCalGeom") << "getPosition:: index " << cellIndex << " Local " << lcoord.x() << ":"
0221                                       << lcoord.y() << " ID " << id.iCell1 << ":" << id.iSec1 << " Global " << glob;
0222     } else if (m_topology.tileTrapezoid()) {
0223       const HepGeom::Point3D<float> lcoord(0, 0, 0);
0224       glob = m_cellVec2[cellIndex].getPosition(lcoord);
0225       if (debug)
0226         edm::LogVerbatim("HGCalGeom") << "getPositionTrap:: index " << cellIndex << " Local " << lcoord.x() << ":"
0227                                       << lcoord.y() << " ID " << id.iLay << ":" << id.iSec1 << ":" << id.iCell1
0228                                       << " Global " << glob;
0229     } else {
0230       if (debug) {
0231         if (detid.det() == DetId::Forward)
0232           edm::LogVerbatim("HGCalGeom") << "getPosition for " << HFNoseDetId(detid) << " Layer " << id.iLay << " Wafer "
0233                                         << id.iSec1 << ":" << id.iSec2 << " Cell " << id.iCell1 << ":" << id.iCell2;
0234         else
0235           edm::LogVerbatim("HGCalGeom") << "getPosition for " << HGCSiliconDetId(detid) << " Layer " << id.iLay
0236                                         << " Wafer " << id.iSec1 << ":" << id.iSec2 << " Cell " << id.iCell1 << ":"
0237                                         << id.iCell2;
0238       }
0239       xy = m_topology.dddConstants().locateCell(
0240           id.zSide, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true, true, true, cog, debug);
0241       double xx = id.zSide * xy.first;
0242       double zz = id.zSide * m_topology.dddConstants().waferZ(id.iLay, true);
0243       glob = GlobalPoint(xx, xy.second, zz);
0244       if (debug)
0245         edm::LogVerbatim("HGCalGeom") << "getPositionWafer:: index " << cellIndex << " Local " << xy.first << ":"
0246                                       << xy.second << " ID " << id.iLay << ":" << id.iSec1 << ":" << id.iSec2 << ":"
0247                                       << id.iCell1 << ":" << id.iCell2 << " Global " << glob;
0248     }
0249   } else {
0250     edm::LogVerbatim("HGCalGeom") << "Cannot recognize " << std::hex << detid.rawId() << " cellIndex " << cellIndex
0251                                   << ":" << maxSize << " Type " << m_topology.tileTrapezoid();
0252   }
0253   return glob;
0254 }
0255 
0256 GlobalPoint HGCalGeometry::getWaferPosition(const DetId& detid) const {
0257   unsigned int cellIndex = indexFor(detid);
0258   GlobalPoint glob;
0259   unsigned int maxSize = (m_topology.tileTrapezoid() ? m_cellVec2.size() : m_cellVec.size());
0260   if (cellIndex < maxSize) {
0261     const HepGeom::Point3D<float> lcoord(0, 0, 0);
0262     if (m_topology.tileTrapezoid()) {
0263       glob = m_cellVec2[cellIndex].getPosition(lcoord);
0264     } else {
0265       glob = m_cellVec[cellIndex].getPosition(lcoord);
0266     }
0267 #ifdef EDM_ML_DEBUG
0268     edm::LogVerbatim("HGCalGeom") << "getPositionTrap:: ID " << std::hex << detid.rawId() << std::dec << " index "
0269                                   << cellIndex << " Global " << glob;
0270 #endif
0271   }
0272   return glob;
0273 }
0274 
0275 double HGCalGeometry::getArea(const DetId& detid) const {
0276   HGCalGeometry::CornersVec corners = getNewCorners(detid);
0277   double area(0);
0278   if (corners.size() > 1) {
0279     int n = corners.size() - 1;
0280     int j = n - 1;
0281     for (int i = 0; i < n; ++i) {
0282       area += ((corners[j].x() + corners[i].x()) * (corners[i].y() - corners[j].y()));
0283       j = i;
0284     }
0285   }
0286   return std::abs(0.5 * area);
0287 }
0288 
0289 HGCalGeometry::CornersVec HGCalGeometry::getCorners(const DetId& detid) const {
0290   unsigned int ncorner = ((m_det == DetId::HGCalHSc) ? FlatTrd::ncorner_ : FlatHexagon::ncorner_);
0291   HGCalGeometry::CornersVec co(ncorner, GlobalPoint(0, 0, 0));
0292   unsigned int cellIndex = indexFor(detid);
0293   HGCalTopology::DecodedDetId id = m_topology.decode(detid);
0294   if (cellIndex < m_cellVec2.size() && m_det == DetId::HGCalHSc) {
0295     GlobalPoint v = getPosition(detid, false);
0296     int type = std::min(id.iType, 1);
0297     std::pair<double, double> rr = m_topology.dddConstants().cellSizeTrap(type, id.iSec1);
0298     float dr = k_half * (rr.second - rr.first);
0299     float dfi = m_cellVec2[cellIndex].param()[FlatTrd::k_Cell];
0300     float dz = id.zSide * m_cellVec2[cellIndex].param()[FlatTrd::k_dZ];
0301     float r = v.perp();
0302     float fi = v.phi();
0303     static const int signr[] = {1, 1, -1, -1, 1, 1, -1, -1};
0304     static const int signf[] = {-1, 1, 1, -1, -1, 1, 1, -1};
0305     static const int signz[] = {-1, -1, -1, -1, 1, 1, 1, 1};
0306     for (unsigned int i = 0; i < ncorner; ++i) {
0307       co[i] = GlobalPoint((r + signr[i] * dr) * cos(fi + signf[i] * dfi),
0308                           (r + signr[i] * dr) * sin(fi + signf[i] * dfi),
0309                           (v.z() + signz[i] * dz));
0310     }
0311   } else if (cellIndex < m_cellVec.size() && m_det != DetId::HGCalHSc) {
0312     std::pair<float, float> xy;
0313     if (m_topology.waferHexagon6()) {
0314       xy = m_topology.dddConstants().locateCellHex(id.iCell1, id.iSec1, true);
0315       float dx = m_cellVec[cellIndex].param()[FlatHexagon::k_r];
0316       float dy = k_half * m_cellVec[cellIndex].param()[FlatHexagon::k_R];
0317       float dz = m_cellVec[cellIndex].param()[FlatHexagon::k_dZ];
0318       static const int signx[] = {0, -1, -1, 0, 1, 1, 0, -1, -1, 0, 1, 1};
0319       static const int signy[] = {-2, -1, 1, 2, 1, -1, -2, -1, 1, 2, 1, -1};
0320       static const int signz[] = {-1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1};
0321       for (unsigned int i = 0; i < ncorner; ++i) {
0322         const HepGeom::Point3D<float> lcoord(xy.first + signx[i] * dx, xy.second + signy[i] * dy, signz[i] * dz);
0323         co[i] = m_cellVec[cellIndex].getPosition(lcoord);
0324       }
0325     } else {
0326       xy = m_topology.dddConstants().locateCell(
0327           id.zSide, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true, false, true, false, debugLocate);
0328       float zz = m_topology.dddConstants().waferZ(id.iLay, true);
0329       float dx = k_fac2 * m_cellVec[cellIndex].param()[FlatHexagon::k_r];
0330       float dy = k_fac1 * m_cellVec[cellIndex].param()[FlatHexagon::k_R];
0331       float dz = -id.zSide * m_cellVec[cellIndex].param()[FlatHexagon::k_dZ];
0332       static const int signx[] = {1, -1, -2, -1, 1, 2, 1, -1, -2, -1, 1, 2};
0333       static const int signy[] = {1, 1, 0, -1, -1, 0, 1, 1, 0, -1, -1, 0};
0334       static const int signz[] = {-1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1};
0335       for (unsigned int i = 0; i < ncorner; ++i) {
0336         auto xyglob = m_topology.dddConstants().localToGlobal8(
0337             id.zSide, id.iLay, id.iSec1, id.iSec2, (xy.first + signx[i] * dx), (xy.second + signy[i] * dy), true, false);
0338         double xx = id.zSide * xyglob.first;
0339         co[i] = GlobalPoint(xx, xyglob.second, id.zSide * (zz + signz[i] * dz));
0340       }
0341     }
0342   }
0343   return co;
0344 }
0345 
0346 HGCalGeometry::CornersVec HGCalGeometry::get8Corners(const DetId& detid) const {
0347   unsigned int ncorner = FlatTrd::ncorner_;
0348   HGCalGeometry::CornersVec co(ncorner, GlobalPoint(0, 0, 0));
0349   unsigned int cellIndex = indexFor(detid);
0350   HGCalTopology::DecodedDetId id = m_topology.decode(detid);
0351   if (cellIndex < m_cellVec2.size() && m_det == DetId::HGCalHSc) {
0352     GlobalPoint v = getPosition(detid, false);
0353     int type = std::min(id.iType, 1);
0354     std::pair<double, double> rr = m_topology.dddConstants().cellSizeTrap(type, id.iSec1);
0355     float dr = k_half * (rr.second - rr.first);
0356     float dfi = m_cellVec2[cellIndex].param()[FlatTrd::k_Cell];
0357     float dz = id.zSide * m_cellVec2[cellIndex].param()[FlatTrd::k_dZ];
0358     float r = v.perp();
0359     float fi = v.phi();
0360     static const int signr[] = {1, 1, -1, -1, 1, 1, -1, -1};
0361     static const int signf[] = {-1, 1, 1, -1, -1, 1, 1, -1};
0362     static const int signz[] = {-1, -1, -1, -1, 1, 1, 1, 1};
0363     for (unsigned int i = 0; i < ncorner; ++i) {
0364       co[i] = GlobalPoint((r + signr[i] * dr) * cos(fi + signf[i] * dfi),
0365                           (r + signr[i] * dr) * sin(fi + signf[i] * dfi),
0366                           (v.z() + signz[i] * dz));
0367     }
0368   } else if (cellIndex < m_cellVec.size() && m_det != DetId::HGCalHSc) {
0369     std::pair<float, float> xy;
0370     float dx(0);
0371     static const int signx[] = {-1, -1, 1, 1, -1, -1, 1, 1};
0372     static const int signy[] = {-1, 1, 1, -1, -1, 1, 1, -1};
0373     static const int signz[] = {-1, -1, -1, -1, 1, 1, 1, 1};
0374     if (m_topology.waferHexagon6()) {
0375       xy = m_topology.dddConstants().locateCellHex(id.iCell1, id.iSec1, true);
0376       dx = m_cellVec[cellIndex].param()[FlatHexagon::k_r];
0377       float dz = m_cellVec[cellIndex].param()[FlatHexagon::k_dZ];
0378       for (unsigned int i = 0; i < ncorner; ++i) {
0379         const HepGeom::Point3D<float> lcoord(xy.first + signx[i] * dx, xy.second + signy[i] * dx, signz[i] * dz);
0380         co[i] = m_cellVec[cellIndex].getPosition(lcoord);
0381       }
0382     } else {
0383       xy = m_topology.dddConstants().locateCell(
0384           id.zSide, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true, false, true, false, debugLocate);
0385       dx = k_fac2 * m_cellVec[cellIndex].param()[FlatHexagon::k_r];
0386       float dy = k_fac1 * m_cellVec[cellIndex].param()[FlatHexagon::k_R];
0387       float dz = -id.zSide * m_cellVec[cellIndex].param()[FlatHexagon::k_dZ];
0388       float zz = m_topology.dddConstants().waferZ(id.iLay, true);
0389       for (unsigned int i = 0; i < ncorner; ++i) {
0390         auto xyglob = m_topology.dddConstants().localToGlobal8(
0391             id.zSide, id.iLay, id.iSec1, id.iSec2, (xy.first + signx[i] * dx), (xy.second + signy[i] * dy), true, false);
0392         double xx = id.zSide * xyglob.first;
0393         co[i] = GlobalPoint(xx, xyglob.second, id.zSide * (zz + signz[i] * dz));
0394       }
0395     }
0396   }
0397   return co;
0398 }
0399 
0400 HGCalGeometry::CornersVec HGCalGeometry::getNewCorners(const DetId& detid, bool debug) const {
0401   unsigned int ncorner = (m_det == DetId::HGCalHSc) ? 5 : 7;
0402   HGCalGeometry::CornersVec co(ncorner, GlobalPoint(0, 0, 0));
0403   unsigned int cellIndex = indexFor(detid);
0404   HGCalTopology::DecodedDetId id = m_topology.decode(detid);
0405   if (debug)
0406     edm::LogVerbatim("HGCalGeom") << "NewCorners for Layer " << id.iLay << " Wafer " << id.iSec1 << ":" << id.iSec2
0407                                   << " Cell " << id.iCell1 << ":" << id.iCell2;
0408   if (cellIndex < m_cellVec2.size() && m_det == DetId::HGCalHSc) {
0409     GlobalPoint v = getPosition(detid, false);
0410     int type = std::min(id.iType, 1);
0411     std::pair<double, double> rr = m_topology.dddConstants().cellSizeTrap(type, id.iSec1);
0412     float dr = k_half * (rr.second - rr.first);
0413     float dfi = m_cellVec2[cellIndex].param()[FlatTrd::k_Cell];
0414     float dz = -id.zSide * m_cellVec2[cellIndex].param()[FlatTrd::k_dZ];
0415     float r = v.perp();
0416     float fi = v.phi();
0417     static const int signr[] = {1, 1, -1, -1};
0418     static const int signf[] = {-1, 1, 1, -1};
0419     for (unsigned int i = 0; i < ncorner - 1; ++i) {
0420       co[i] = GlobalPoint(
0421           (r + signr[i] * dr) * cos(fi + signf[i] * dfi), (r + signr[i] * dr) * sin(fi + signf[i] * dfi), (v.z() + dz));
0422     }
0423     // Used to pass downstream the thickness of this cell
0424     co[ncorner - 1] = GlobalPoint(0, 0, -2 * dz);
0425   } else if (cellIndex < m_cellVec.size() && m_det != DetId::HGCalHSc) {
0426     std::pair<float, float> xy;
0427     float dx = k_fac2 * m_cellVec[cellIndex].param()[FlatHexagon::k_r];
0428     float dy = k_fac1 * m_cellVec[cellIndex].param()[FlatHexagon::k_R];
0429     float dz = -id.zSide * m_cellVec[cellIndex].param()[FlatHexagon::k_dZ];
0430     static const int signx[] = {1, -1, -2, -1, 1, 2};
0431     static const int signy[] = {1, 1, 0, -1, -1, 0};
0432 #ifdef EDM_ML_DEBUG
0433     if (debug)
0434       edm::LogVerbatim("HGCalGeom") << "kfac " << k_fac1 << ":" << k_fac2 << " dx:dy:dz " << dx << ":" << dy << ":"
0435                                     << dz;
0436 #endif
0437     if (m_topology.waferHexagon6()) {
0438       xy = m_topology.dddConstants().locateCellHex(id.iCell1, id.iSec1, true);
0439       for (unsigned int i = 0; i < ncorner - 1; ++i) {
0440         const HepGeom::Point3D<float> lcoord(xy.first + signx[i] * dx, xy.second + signy[i] * dy, dz);
0441         co[i] = m_cellVec[cellIndex].getPosition(lcoord);
0442       }
0443     } else {
0444       xy = m_topology.dddConstants().locateCell(
0445           id.zSide, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, true, false, true, false, debug);
0446       float zz = m_topology.dddConstants().waferZ(id.iLay, true);
0447       for (unsigned int i = 0; i < ncorner; ++i) {
0448         double xloc = xy.first + signx[i] * dx;
0449         double yloc = xy.second + signy[i] * dy;
0450 #ifdef EDM_ML_DEBUG
0451         if (debug)
0452           edm::LogVerbatim("HGCalGeom") << "Corner " << i << " x " << xy.first << ":" << xloc << " y " << xy.second
0453                                         << ":" << yloc << " z " << zz << ":" << id.zSide * (zz + dz);
0454 #endif
0455         auto xyglob =
0456             m_topology.dddConstants().localToGlobal8(id.zSide, id.iLay, id.iSec1, id.iSec2, xloc, yloc, true, debug);
0457         double xx = id.zSide * xyglob.first;
0458         co[i] = GlobalPoint(xx, xyglob.second, id.zSide * (zz + dz));
0459       }
0460     }
0461     // Used to pass downstream the thickness of this cell
0462     co[ncorner - 1] = GlobalPoint(0, 0, -2 * dz);
0463   }
0464   return co;
0465 }
0466 
0467 DetId HGCalGeometry::neighborZ(const DetId& idin, const GlobalVector& momentum) const {
0468   DetId idnew;
0469   HGCalTopology::DecodedDetId id = m_topology.decode(idin);
0470   int lay = ((momentum.z() * id.zSide > 0) ? (id.iLay + 1) : (id.iLay - 1));
0471 #ifdef EDM_ML_DEBUG
0472   edm::LogVerbatim("HGCalGeom") << "neighborz1:: ID " << id.iLay << ":" << id.iSec1 << ":" << id.iSec2 << ":"
0473                                 << id.iCell1 << ":" << id.iCell2 << " New Layer " << lay << " Range "
0474                                 << m_topology.dddConstants().firstLayer() << ":"
0475                                 << m_topology.dddConstants().lastLayer(true) << " pz " << momentum.z();
0476 #endif
0477   if ((lay >= m_topology.dddConstants().firstLayer()) && (lay <= m_topology.dddConstants().lastLayer(true)) &&
0478       (momentum.z() != 0.0)) {
0479     GlobalPoint v = getPosition(idin, false);
0480     double z = id.zSide * m_topology.dddConstants().waferZ(lay, true);
0481     double grad = (z - v.z()) / momentum.z();
0482     GlobalPoint p(v.x() + grad * momentum.x(), v.y() + grad * momentum.y(), z);
0483     double r = p.perp();
0484     auto rlimit = topology().dddConstants().rangeR(z, true);
0485     if (r >= rlimit.first && r <= rlimit.second)
0486       idnew = getClosestCell(p);
0487 #ifdef EDM_ML_DEBUG
0488     edm::LogVerbatim("HGCalGeom") << "neighborz1:: Position " << v << " New Z " << z << ":" << grad << " new position "
0489                                   << p << " r-limit " << rlimit.first << ":" << rlimit.second;
0490 #endif
0491   }
0492   return idnew;
0493 }
0494 
0495 DetId HGCalGeometry::neighborZ(const DetId& idin,
0496                                const MagneticField* bField,
0497                                int charge,
0498                                const GlobalVector& momentum) const {
0499   DetId idnew;
0500   HGCalTopology::DecodedDetId id = m_topology.decode(idin);
0501   int lay = ((momentum.z() * id.zSide > 0) ? (id.iLay + 1) : (id.iLay - 1));
0502 #ifdef EDM_ML_DEBUG
0503   edm::LogVerbatim("HGCalGeom") << "neighborz2:: ID " << id.iLay << ":" << id.iSec1 << ":" << id.iSec2 << ":"
0504                                 << id.iCell1 << ":" << id.iCell2 << " New Layer " << lay << " Range "
0505                                 << m_topology.dddConstants().firstLayer() << ":"
0506                                 << m_topology.dddConstants().lastLayer(true) << " pz " << momentum.z();
0507 #endif
0508   if ((lay >= m_topology.dddConstants().firstLayer()) && (lay <= m_topology.dddConstants().lastLayer(true)) &&
0509       (momentum.z() != 0.0)) {
0510     GlobalPoint v = getPosition(idin, false);
0511     double z = id.zSide * m_topology.dddConstants().waferZ(lay, true);
0512     FreeTrajectoryState fts(v, momentum, charge, bField);
0513     Plane::PlanePointer nPlane = Plane::build(Plane::PositionType(0, 0, z), Plane::RotationType());
0514     AnalyticalPropagator myAP(bField, alongMomentum, 2 * M_PI);
0515     TrajectoryStateOnSurface tsos = myAP.propagate(fts, *nPlane);
0516     GlobalPoint p;
0517     auto rlimit = topology().dddConstants().rangeR(z, true);
0518     if (tsos.isValid()) {
0519       p = tsos.globalPosition();
0520       double r = p.perp();
0521       if (r >= rlimit.first && r <= rlimit.second)
0522         idnew = getClosestCell(p);
0523     }
0524 #ifdef EDM_ML_DEBUG
0525     edm::LogVerbatim("HGCalGeom") << "neighborz2:: Position " << v << " New Z " << z << ":" << charge << ":"
0526                                   << tsos.isValid() << " new position " << p << " r limits " << rlimit.first << ":"
0527                                   << rlimit.second;
0528 #endif
0529   }
0530   return idnew;
0531 }
0532 
0533 DetId HGCalGeometry::getClosestCell(const GlobalPoint& r) const {
0534   unsigned int cellIndex = getClosestCellIndex(r);
0535   if ((cellIndex < m_cellVec.size() && m_det != DetId::HGCalHSc) ||
0536       (cellIndex < m_cellVec2.size() && m_det == DetId::HGCalHSc)) {
0537     HGCalTopology::DecodedDetId id = m_topology.decode(m_validGeomIds[cellIndex]);
0538     if (id.det == 0)
0539       id.det = static_cast<int>(m_topology.detector());
0540     HepGeom::Point3D<float> local;
0541     if (r.z() > 0) {
0542       local = HepGeom::Point3D<float>(r.x(), r.y(), 0);
0543       id.zSide = 1;
0544     } else {
0545       local = HepGeom::Point3D<float>(-r.x(), r.y(), 0);
0546       id.zSide = -1;
0547     }
0548     if (m_topology.waferHexagon6()) {
0549       const auto& kxy = m_topology.dddConstants().assignCell(local.x(), local.y(), id.iLay, id.iType, true);
0550       id.iCell1 = kxy.second;
0551       id.iSec1 = kxy.first;
0552       id.iType = m_topology.dddConstants().waferTypeT(kxy.first);
0553       if (id.iType != 1)
0554         id.iType = -1;
0555     } else if (m_topology.tileTrapezoid()) {
0556       id.iLay = m_topology.dddConstants().getLayer(r.z(), true);
0557       const auto& kxy = m_topology.dddConstants().assignCellTrap(r.x(), r.y(), r.z(), id.iLay, true);
0558       id.iSec1 = kxy[0];
0559       id.iCell1 = kxy[1];
0560       id.iType = kxy[2];
0561     } else {
0562       id.iLay = m_topology.dddConstants().getLayer(r.z(), true);
0563       int zside = (r.z() > 0) ? 1 : -1;
0564 #ifdef EDM_ML_DEBUG
0565       edm::LogVerbatim("HGCalGeom") << "ZZ " << r.z() << ":" << zside << " Layer " << id.iLay << " Global " << r
0566                                     << "  Local " << local;
0567 #endif
0568       const auto& kxy =
0569           m_topology.dddConstants().assignCellHex(local.x(), local.y(), zside, id.iLay, true, false, true);
0570       id.iSec1 = kxy[0];
0571       id.iSec2 = kxy[1];
0572       id.iType = kxy[2];
0573       id.iCell1 = kxy[3];
0574       id.iCell2 = kxy[4];
0575     }
0576 #ifdef EDM_ML_DEBUG
0577     edm::LogVerbatim("HGCalGeom") << "getClosestCell: local " << local << " Id " << id.det << ":" << id.zSide << ":"
0578                                   << id.iLay << ":" << id.iSec1 << ":" << id.iSec2 << ":" << id.iType << ":"
0579                                   << id.iCell1 << ":" << id.iCell2;
0580 #endif
0581 
0582     //check if returned cell is valid
0583     if (id.iCell1 >= 0)
0584       return m_topology.encode(id);
0585   }
0586 
0587   //if not valid or out of bounds return a null DetId
0588   return DetId();
0589 }
0590 
0591 DetId HGCalGeometry::getClosestCellHex(const GlobalPoint& r, bool extend) const {
0592   unsigned int cellIndex = getClosestCellIndex(r);
0593   if (cellIndex < m_cellVec.size() && m_det != DetId::HGCalHSc) {
0594     HGCalTopology::DecodedDetId id = m_topology.decode(m_validGeomIds[cellIndex]);
0595     if (id.det == 0)
0596       id.det = static_cast<int>(m_topology.detector());
0597     HepGeom::Point3D<float> local;
0598     if (r.z() > 0) {
0599       local = HepGeom::Point3D<float>(r.x(), r.y(), 0);
0600       id.zSide = 1;
0601     } else {
0602       local = HepGeom::Point3D<float>(-r.x(), r.y(), 0);
0603       id.zSide = -1;
0604     }
0605     if (m_topology.waferHexagon8()) {
0606       id.iLay = m_topology.dddConstants().getLayer(r.z(), true);
0607       int zside = (r.z() > 0) ? 1 : -1;
0608 #ifdef EDM_ML_DEBUG
0609       edm::LogVerbatim("HGCalGeom") << "ZZ " << r.z() << ":" << zside << " Layer " << id.iLay << " Global " << r
0610                                     << "  Local " << local;
0611 #endif
0612       const auto& kxy =
0613           m_topology.dddConstants().assignCellHex(local.x(), local.y(), zside, id.iLay, true, extend, true);
0614       id.iSec1 = kxy[0];
0615       id.iSec2 = kxy[1];
0616       id.iType = kxy[2];
0617       id.iCell1 = kxy[3];
0618       id.iCell2 = kxy[4];
0619     }
0620 #ifdef EDM_ML_DEBUG
0621     edm::LogVerbatim("HGCalGeom") << "getClosestCell: local " << local << " Id " << id.det << ":" << id.zSide << ":"
0622                                   << id.iLay << ":" << id.iSec1 << ":" << id.iSec2 << ":" << id.iType << ":"
0623                                   << id.iCell1 << ":" << id.iCell2;
0624 #endif
0625 
0626     //check if returned cell is valid
0627     if (id.iCell1 >= 0)
0628       return m_topology.encode(id);
0629   }
0630 
0631   //if not valid or out of bounds return a null DetId
0632   return DetId();
0633 }
0634 
0635 HGCalGeometry::DetIdSet HGCalGeometry::getCells(const GlobalPoint& r, double dR) const {
0636   HGCalGeometry::DetIdSet dss;
0637   return dss;
0638 }
0639 
0640 std::string HGCalGeometry::cellElement() const {
0641   if (m_subdet == HGCEE || m_det == DetId::HGCalEE)
0642     return "HGCalEE";
0643   else if (m_subdet == HGCHEF || m_det == DetId::HGCalHSi)
0644     return "HGCalHEFront";
0645   else if (m_subdet == HGCHEB || m_det == DetId::HGCalHSc)
0646     return "HGCalHEBack";
0647   else
0648     return "Unknown";
0649 }
0650 
0651 unsigned int HGCalGeometry::indexFor(const DetId& detId) const {
0652   unsigned int cellIndex = ((m_det == DetId::HGCalHSc) ? m_cellVec2.size() : m_cellVec.size());
0653   if (detId != DetId()) {
0654     DetId geomId = getGeometryDetId(detId);
0655     cellIndex = m_topology.detId2denseGeomId(geomId);
0656 #ifdef EDM_ML_DEBUG
0657     edm::LogVerbatim("HGCalGeom") << "indexFor " << std::hex << detId.rawId() << ":" << geomId.rawId() << std::dec
0658                                   << " index " << cellIndex;
0659 #endif
0660   }
0661   return cellIndex;
0662 }
0663 
0664 unsigned int HGCalGeometry::sizeForDenseIndex() const { return m_topology.totalGeomModules(); }
0665 
0666 const CaloCellGeometry* HGCalGeometry::getGeometryRawPtr(uint32_t index) const {
0667   // Modify the RawPtr class
0668   if (m_det == DetId::HGCalHSc) {
0669     if (m_cellVec2.size() < index)
0670       return nullptr;
0671     const CaloCellGeometry* cell(&m_cellVec2[index]);
0672     return (nullptr == cell->param() ? nullptr : cell);
0673   } else {
0674     if (m_cellVec.size() < index)
0675       return nullptr;
0676     const CaloCellGeometry* cell(&m_cellVec[index]);
0677     return (nullptr == cell->param() ? nullptr : cell);
0678   }
0679 }
0680 
0681 std::shared_ptr<const CaloCellGeometry> HGCalGeometry::cellGeomPtr(uint32_t index) const {
0682   if ((index >= m_cellVec.size() && m_det != DetId::HGCalHSc) ||
0683       (index >= m_cellVec2.size() && m_det == DetId::HGCalHSc) || (m_validGeomIds[index].rawId() == 0))
0684     return nullptr;
0685   static const auto do_not_delete = [](const void*) {};
0686   if (m_det == DetId::HGCalHSc) {
0687     auto cell = std::shared_ptr<const CaloCellGeometry>(&m_cellVec2[index], do_not_delete);
0688     if (nullptr == cell->param())
0689       return nullptr;
0690     return cell;
0691   } else {
0692     auto cell = std::shared_ptr<const CaloCellGeometry>(&m_cellVec[index], do_not_delete);
0693     if (nullptr == cell->param())
0694       return nullptr;
0695     return cell;
0696   }
0697 }
0698 
0699 std::shared_ptr<const CaloCellGeometry> HGCalGeometry::cellGeomPtr(uint32_t index, const GlobalPoint& pos) const {
0700   if ((index >= m_cellVec.size() && m_det != DetId::HGCalHSc) ||
0701       (index >= m_cellVec2.size() && m_det == DetId::HGCalHSc) || (m_validGeomIds[index].rawId() == 0))
0702     return nullptr;
0703   if (pos == GlobalPoint())
0704     return cellGeomPtr(index);
0705   if (m_det == DetId::HGCalHSc) {
0706     auto cell = std::make_shared<FlatTrd>(m_cellVec2[index]);
0707     cell->setPosition(pos);
0708 #ifdef EDM_ML_DEBUG
0709     edm::LogVerbatim("HGCalGeom") << "cellGeomPtr " << index << ":" << cell;
0710 #endif
0711     if (nullptr == cell->param())
0712       return nullptr;
0713     return cell;
0714   } else {
0715     auto cell = std::make_shared<FlatHexagon>(m_cellVec[index]);
0716     cell->setPosition(pos);
0717 #ifdef EDM_ML_DEBUG
0718     edm::LogVerbatim("HGCalGeom") << "cellGeomPtr " << index << ":" << cell;
0719 #endif
0720     if (nullptr == cell->param())
0721       return nullptr;
0722     return cell;
0723   }
0724 }
0725 
0726 void HGCalGeometry::addValidID(const DetId& id) {
0727   edm::LogError("HGCalGeom") << "HGCalGeometry::addValidID is not implemented";
0728 }
0729 
0730 unsigned int HGCalGeometry::getClosestCellIndex(const GlobalPoint& r) const {
0731   return ((m_det == DetId::HGCalHSc) ? getClosestCellIndex(r, m_cellVec2) : getClosestCellIndex(r, m_cellVec));
0732 }
0733 
0734 template <class T>
0735 unsigned int HGCalGeometry::getClosestCellIndex(const GlobalPoint& r, const std::vector<T>& vec) const {
0736   float phip = r.phi();
0737   float zp = r.z();
0738   float dzmin(9999), dphimin(9999), dphi10(0.175);
0739   unsigned int cellIndex = vec.size();
0740   for (unsigned int k = 0; k < vec.size(); ++k) {
0741     float dphi = phip - vec[k].phiPos();
0742     while (dphi > M_PI)
0743       dphi -= 2 * M_PI;
0744     while (dphi <= -M_PI)
0745       dphi += 2 * M_PI;
0746     if (std::abs(dphi) < dphi10) {
0747       float dz = std::abs(zp - vec[k].getPosition().z());
0748       if (dz < (dzmin + 0.001)) {
0749         dzmin = dz;
0750         if (std::abs(dphi) < (dphimin + 0.01)) {
0751           cellIndex = k;
0752           dphimin = std::abs(dphi);
0753         } else {
0754           if (cellIndex >= vec.size())
0755             cellIndex = k;
0756         }
0757       }
0758     }
0759   }
0760 #ifdef EDM_ML_DEBUG
0761   edm::LogVerbatim("HGCalGeom") << "getClosestCellIndex::Input " << zp << ":" << phip << " Index " << cellIndex;
0762   if (cellIndex < vec.size())
0763     edm::LogVerbatim("HGCalGeom") << " Cell z " << vec[cellIndex].getPosition().z() << ":" << dzmin << " phi "
0764                                   << vec[cellIndex].phiPos() << ":" << dphimin;
0765 #endif
0766   return cellIndex;
0767 }
0768 
0769 // FIXME: Change sorting algorithm if needed
0770 namespace {
0771   struct rawIdSort {
0772     bool operator()(const DetId& a, const DetId& b) { return (a.rawId() < b.rawId()); }
0773   };
0774 }  // namespace
0775 
0776 void HGCalGeometry::sortDetIds(void) {
0777   m_validIds.shrink_to_fit();
0778   std::sort(m_validIds.begin(), m_validIds.end(), rawIdSort());
0779 }
0780 
0781 void HGCalGeometry::getSummary(CaloSubdetectorGeometry::TrVec& trVector,
0782                                CaloSubdetectorGeometry::IVec& iVector,
0783                                CaloSubdetectorGeometry::DimVec& dimVector,
0784                                CaloSubdetectorGeometry::IVec& dinsVector) const {
0785   unsigned int numberOfCells = m_topology.totalGeomModules();  // total Geom Modules both sides
0786   unsigned int numberOfShapes = k_NumberOfShapes;
0787   unsigned int numberOfParametersPerShape = ((m_det == DetId::HGCalHSc) ? (unsigned int)(k_NumberOfParametersPerTrd)
0788                                                                         : (unsigned int)(k_NumberOfParametersPerHex));
0789 
0790   trVector.reserve(numberOfCells * numberOfTransformParms());
0791   iVector.reserve(numberOfCells);
0792   dimVector.reserve(numberOfShapes * numberOfParametersPerShape);
0793   dinsVector.reserve(numberOfCells);
0794 
0795   for (unsigned itr = 0; itr < m_topology.dddConstants().getTrFormN(); ++itr) {
0796     HGCalParameters::hgtrform mytr = m_topology.dddConstants().getTrForm(itr);
0797     int layer = mytr.lay;
0798 
0799     if (m_topology.waferHexagon6()) {
0800       for (int wafer = 0; wafer < m_topology.dddConstants().sectors(); ++wafer) {
0801         if (m_topology.dddConstants().waferInLayer(wafer, layer, true)) {
0802           HGCalParameters::hgtrap vol = m_topology.dddConstants().getModule(wafer, true, true);
0803           ParmVec params(numberOfParametersPerShape, 0);
0804           params[FlatHexagon::k_dZ] = vol.dz;
0805           params[FlatHexagon::k_r] = vol.cellSize;
0806           params[FlatHexagon::k_R] = twoBysqrt3_ * params[FlatHexagon::k_r];
0807           dimVector.insert(dimVector.end(), params.begin(), params.end());
0808         }
0809       }
0810     } else if (m_topology.tileTrapezoid()) {
0811       int indx = m_topology.dddConstants().layerIndex(layer, true);
0812       for (int md = m_topology.dddConstants().getParameter()->firstModule_[indx];
0813            md <= m_topology.dddConstants().getParameter()->lastModule_[indx];
0814            ++md) {
0815         HGCalParameters::hgtrap vol = m_topology.dddConstants().getModule(md, true, true);
0816         ParmVec params(numberOfParametersPerShape, 0);
0817         params[FlatTrd::k_dZ] = vol.dz;
0818         params[FlatTrd::k_Theta] = params[FlatTrd::k_Phi] = 0;
0819         params[FlatTrd::k_dY1] = params[FlatTrd::k_dY2] = vol.h;
0820         params[FlatTrd::k_dX1] = params[FlatTrd::k_dX3] = vol.bl;
0821         params[FlatTrd::k_dX2] = params[FlatTrd::k_dX4] = vol.tl;
0822         params[FlatTrd::k_Alp1] = params[FlatTrd::k_Alp2] = vol.alpha;
0823         params[FlatTrd::k_Cell] = vol.cellSize;
0824         dimVector.insert(dimVector.end(), params.begin(), params.end());
0825       }
0826     } else {
0827       for (int wafer = 0; wafer < m_topology.dddConstants().sectors(); ++wafer) {
0828         if (m_topology.dddConstants().waferInLayer(wafer, layer, true)) {
0829           HGCalParameters::hgtrap vol = m_topology.dddConstants().getModule(wafer, true, true);
0830           ParmVec params(numberOfParametersPerShape, 0);
0831           params[FlatHexagon::k_dZ] = vol.dz;
0832           params[FlatHexagon::k_r] = vol.cellSize;
0833           params[FlatHexagon::k_R] = twoBysqrt3_ * params[FlatHexagon::k_r];
0834           dimVector.insert(dimVector.end(), params.begin(), params.end());
0835         }
0836       }
0837     }
0838   }
0839 
0840   for (unsigned int i(0); i < numberOfCells; ++i) {
0841     DetId detId = m_validGeomIds[i];
0842     int layer(0);
0843     if (m_topology.waferHexagon6()) {
0844       layer = HGCalDetId(detId).layer();
0845     } else if (m_topology.tileTrapezoid()) {
0846       layer = HGCScintillatorDetId(detId).layer();
0847     } else if (m_topology.isHFNose()) {
0848       layer = HFNoseDetId(detId).layer();
0849     } else {
0850       layer = HGCSiliconDetId(detId).layer();
0851     }
0852     dinsVector.emplace_back(m_topology.detId2denseGeomId(detId));
0853     iVector.emplace_back(layer);
0854 
0855     Tr3D tr;
0856     auto ptr = cellGeomPtr(i);
0857     if (nullptr != ptr) {
0858       ptr->getTransform(tr, (Pt3DVec*)nullptr);
0859 
0860       if (Tr3D() == tr) {  // there is no rotation
0861         const GlobalPoint& gp(ptr->getPosition());
0862         tr = HepGeom::Translate3D(gp.x(), gp.y(), gp.z());
0863       }
0864 
0865       const CLHEP::Hep3Vector tt(tr.getTranslation());
0866       trVector.emplace_back(tt.x());
0867       trVector.emplace_back(tt.y());
0868       trVector.emplace_back(tt.z());
0869       if (6 == numberOfTransformParms()) {
0870         const CLHEP::HepRotation rr(tr.getRotation());
0871         const ROOT::Math::Transform3D rtr(
0872             rr.xx(), rr.xy(), rr.xz(), tt.x(), rr.yx(), rr.yy(), rr.yz(), tt.y(), rr.zx(), rr.zy(), rr.zz(), tt.z());
0873         ROOT::Math::EulerAngles ea;
0874         rtr.GetRotation(ea);
0875         trVector.emplace_back(ea.Phi());
0876         trVector.emplace_back(ea.Theta());
0877         trVector.emplace_back(ea.Psi());
0878       }
0879     }
0880   }
0881 }
0882 
0883 DetId HGCalGeometry::getGeometryDetId(DetId detId) const {
0884   DetId geomId;
0885   if (m_topology.waferHexagon6()) {
0886     geomId = static_cast<DetId>(HGCalDetId(detId).geometryCell());
0887   } else if (m_topology.tileTrapezoid()) {
0888     geomId = static_cast<DetId>(HGCScintillatorDetId(detId).geometryCell());
0889   } else if (m_topology.isHFNose()) {
0890     geomId = static_cast<DetId>(HFNoseDetId(detId).geometryCell());
0891   } else {
0892     geomId = static_cast<DetId>(HGCSiliconDetId(detId).geometryCell());
0893   }
0894   return geomId;
0895 }
0896 
0897 #include "FWCore/Utilities/interface/typelookup.h"
0898 
0899 TYPELOOKUP_DATA_REG(HGCalGeometry);