Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-03 00:59:05

0001 #ifndef Geometry_CaloTopology_HGCalTopology_h
0002 #define Geometry_CaloTopology_HGCalTopology_h 1
0003 
0004 #include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
0005 #include "DataFormats/DetId/interface/DetId.h"
0006 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
0007 #include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
0008 #include "Geometry/HGCalCommonData/interface/HGCalGeometryMode.h"
0009 #include <vector>
0010 #include <iostream>
0011 
0012 class HGCalTopology : public CaloSubdetectorTopology {
0013 public:
0014   /// create a new Topology
0015   HGCalTopology(const HGCalDDDConstants& hdcons, int subdet);
0016 
0017   /// virtual destructor
0018   ~HGCalTopology() override = default;
0019 
0020   /// move the Topology north (increment iy)
0021   DetId goNorth(const DetId& id) const override { return changeXY(id, 0, +1); }
0022   std::vector<DetId> north(const DetId& id) const override {
0023     DetId nextId = goNorth(id);
0024     std::vector<DetId> vNeighborsDetId;
0025     if (!(nextId == DetId(0)))
0026       vNeighborsDetId.emplace_back(nextId);
0027     return vNeighborsDetId;
0028   }
0029 
0030   /// move the Topology south (decrement iy)
0031   DetId goSouth(const DetId& id) const override { return changeXY(id, 0, -1); }
0032   std::vector<DetId> south(const DetId& id) const override {
0033     DetId nextId = goSouth(id);
0034     std::vector<DetId> vNeighborsDetId;
0035     if (!(nextId == DetId(0)))
0036       vNeighborsDetId.emplace_back(nextId);
0037     return vNeighborsDetId;
0038   }
0039 
0040   /// move the Topology east (positive ix)
0041   DetId goEast(const DetId& id) const override { return changeXY(id, +1, 0); }
0042   std::vector<DetId> east(const DetId& id) const override {
0043     DetId nextId = goEast(id);
0044     std::vector<DetId> vNeighborsDetId;
0045     if (!(nextId == DetId(0)))
0046       vNeighborsDetId.emplace_back(nextId);
0047     return vNeighborsDetId;
0048   }
0049 
0050   /// move the Topology west (negative ix)
0051   DetId goWest(const DetId& id) const override { return changeXY(id, -1, 0); }
0052   std::vector<DetId> west(const DetId& id) const override {
0053     DetId nextId = goWest(id);
0054     std::vector<DetId> vNeighborsDetId;
0055     if (!(nextId == DetId(0)))
0056       vNeighborsDetId.emplace_back(nextId);
0057     return vNeighborsDetId;
0058   }
0059 
0060   std::vector<DetId> up(const DetId& id) const override {
0061     DetId nextId = changeZ(id, +1);
0062     std::vector<DetId> vNeighborsDetId;
0063     if (!(nextId == DetId(0)))
0064       vNeighborsDetId.emplace_back(nextId);
0065     return vNeighborsDetId;
0066   }
0067 
0068   std::vector<DetId> down(const DetId& id) const override {
0069     DetId nextId = changeZ(id, -1);
0070     std::vector<DetId> vNeighborsDetId;
0071     if (!(nextId == DetId(0)))
0072       vNeighborsDetId.emplace_back(nextId);
0073     return vNeighborsDetId;
0074   }
0075 
0076   std::vector<DetId> neighbors(const DetId& id) const;
0077 
0078   ///Geometry mode
0079   HGCalGeometryMode::GeometryMode geomMode() const { return mode_; }
0080 
0081   ///Dense indexing
0082   uint32_t detId2denseId(const DetId& id) const override;
0083   DetId denseId2detId(uint32_t denseId) const override;
0084   virtual uint32_t detId2denseGeomId(const DetId& id) const;
0085 
0086   ///Is this a valid cell id
0087   bool valid(const DetId& id) const override;
0088   bool valid(const DetId& id, int cornerMin) const;
0089   bool validHashIndex(uint32_t ix) const { return (ix < kSizeForDenseIndexing); }
0090   bool validModule(const DetId& id, int cornerMin) const;
0091 
0092   unsigned int totalModules() const { return kSizeForDenseIndexing; }
0093   unsigned int totalGeomModules() const { return (unsigned int)(2 * kHGeomHalf_); }
0094   unsigned int allGeomModules() const;
0095 
0096   bool maskCell(const DetId& id, int corners = 3) const { return dddConstants().maskCell(id, corners); }
0097 
0098   const HGCalDDDConstants& dddConstants() const { return hdcons_; }
0099 
0100   /** returns a new DetId offset by nrStepsX and nrStepsY (can be negative),
0101    * returns DetId(0) if invalid */
0102   DetId offsetBy(const DetId startId, int nrStepsX, int nrStepsY) const;
0103   DetId switchZSide(const DetId startId) const;
0104 
0105   /// Use subSector in square mode as wafer type in hexagon mode
0106   static const int subSectors_ = 2;
0107 
0108   struct DecodedDetId {
0109     DecodedDetId() : iCell1(0), iCell2(0), iLay(0), iSec1(0), iSec2(0), iType(0), zSide(0), det(0) {}
0110     int iCell1, iCell2, iLay, iSec1, iSec2, iType, zSide, det;
0111   };
0112 
0113   DecodedDetId geomDenseId2decId(const uint32_t& hi) const;
0114   DecodedDetId decode(const DetId& id) const;
0115   DetId encode(const DecodedDetId& id_) const;
0116 
0117   DetId::Detector detector() const { return det_; }
0118   ForwardSubdetector subDetector() const { return subdet_; }
0119   bool detectorType() const { return false; }
0120   bool isHFNose() const {
0121     return (((det_ == DetId::Forward) && (subdet_ == ForwardSubdetector::HFNose)) ? true : false);
0122   }
0123 
0124   bool tileTrapezoid() const { return hdcons_.tileTrapezoid(); }
0125   bool waferHexagon6() const { return hdcons_.waferHexagon6(); }
0126   bool waferHexagon8() const { return hdcons_.waferHexagon8(); }
0127 
0128 private:
0129   /// add DetId of Scintillator and Silicon type if valid
0130   void addHGCSCintillatorId(std::vector<DetId>& ids, int zside, int type, int lay, int iradius, int iphi) const;
0131   void addHGCSiliconId(
0132       std::vector<DetId>& ids, int det, int zside, int type, int lay, int waferU, int waferV, int cellU, int cellV)
0133       const;
0134 
0135   /// move the nagivator along x, y
0136   DetId changeXY(const DetId& id, int nrStepsX, int nrStepsY) const;
0137 
0138   /// move the nagivator along z
0139   DetId changeZ(const DetId& id, int nrStepsZ) const;
0140 
0141   const HGCalDDDConstants& hdcons_;
0142   HGCalGeometryMode::GeometryMode mode_;
0143 
0144   DetId::Detector det_;
0145   ForwardSubdetector subdet_;
0146   int sectors_, layers_, cells_, types_;
0147   int firstLay_, cellMax_, waferOff_, waferMax_;
0148   int kHGhalf_, kHGeomHalf_, kHGhalfType_;
0149   unsigned int kSizeForDenseIndexing;
0150 };
0151 
0152 #endif