Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-06-09 22:19:18

0001 #ifndef HGCalCommonData_HGCalDDDConstants_h
0002 #define HGCalCommonData_HGCalDDDConstants_h
0003 
0004 /** \class HGCalDDDConstants
0005  *
0006  * this class reads the constant section of the numbering
0007  * xml-files of the  high granulairy calorimeter
0008  *
0009  *  $Date: 2014/03/20 00:06:50 $
0010  * \author Sunanda Banerjee, SINP <sunanda.banerjee@cern.ch>
0011  *
0012  */
0013 
0014 #include "DataFormats/DetId/interface/DetId.h"
0015 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0016 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0017 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0018 #include "Geometry/HGCalCommonData/interface/HGCalCassette.h"
0019 #include "Geometry/HGCalCommonData/interface/HGCalCell.h"
0020 #include "Geometry/HGCalCommonData/interface/HGCalCellOffset.h"
0021 #include "Geometry/HGCalCommonData/interface/HGCalCellUV.h"
0022 #include "Geometry/HGCalCommonData/interface/HGCalGeometryMode.h"
0023 #include "Geometry/HGCalCommonData/interface/HGCalGeomTools.h"
0024 #include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
0025 #include "Geometry/HGCalCommonData/interface/HGCalTileIndex.h"
0026 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0027 #include "Geometry/HGCalCommonData/interface/HGCalWaferIndex.h"
0028 #include <CLHEP/Geometry/Point3D.h>
0029 
0030 #include <array>
0031 #include <memory>
0032 #include <string>
0033 #include <vector>
0034 #include <unordered_map>
0035 
0036 class HGCalDDDConstants {
0037 public:
0038   HGCalDDDConstants(const HGCalParameters* hp, const std::string& name);
0039   ~HGCalDDDConstants() = default;
0040 
0041   std::pair<int, int> assignCell(float x, float y, int lay, int subSec, bool reco) const;
0042   std::array<int, 5> assignCellHex(float x, float y, int zside, int lay, bool reco, bool extend, bool debug) const;
0043   std::array<int, 3> assignCellTrap(float x, float y, float z, int lay, bool reco) const;
0044   std::vector<int> calibCells(bool hd, bool full) const {
0045     if (hd) {
0046       return (full ? hgpar_->calibCellFullHD_ : hgpar_->calibCellPartHD_);
0047     } else {
0048       return (full ? hgpar_->calibCellFullLD_ : hgpar_->calibCellPartLD_);
0049     }
0050   }
0051   double calibCellRad(bool hd) const { return (hd ? hgpar_->calibCellRHD_ : hgpar_->calibCellRLD_); }
0052   bool cassetteMode() const {
0053     return ((mode_ == HGCalGeometryMode::Hexagon8Cassette) || (mode_ == HGCalGeometryMode::TrapezoidCassette) ||
0054             (mode_ == HGCalGeometryMode::Hexagon8CalibCell) || (mode_ == HGCalGeometryMode::Hexagon8FineCell) ||
0055             (mode_ == HGCalGeometryMode::TrapezoidFineCell));
0056   }
0057   bool cassetteShiftScintillator(int zside, int layer, int iphi) const;
0058   bool cassetteShiftSilicon(int zside, int layer, int waferU, int waferV) const;
0059   int cassetteTile(int iphi) const {
0060     return (HGCalTileIndex::tileCassette(iphi, hgpar_->phiOffset_, hgpar_->nphiCassette_, hgpar_->cassettes_));
0061   }
0062   double cellArea(const HGCSiliconDetId&, bool) const;
0063   std::pair<double, double> cellEtaPhiTrap(int type, int irad) const;
0064   bool cellInLayer(int waferU, int waferV, int cellU, int cellV, int lay, int zside, bool reco) const;
0065   const HGCalCellOffset* cellOffset() const { return cellOffset_.get(); }
0066   double cellSizeHex(int type) const;
0067   inline std::pair<double, double> cellSizeTrap(int type, int irad) const {
0068     return std::make_pair(hgpar_->radiusLayer_[type][irad - 1], hgpar_->radiusLayer_[type][irad]);
0069   }
0070   double cellThickness(int layer, int waferU, int waferV) const;
0071   int32_t cellType(int type, int waferU, int waferV, int iz, int fwdBack, int orient) const;
0072   double distFromEdgeHex(double x, double y, double z) const;
0073   double distFromEdgeTrap(double x, double y, double z) const;
0074   void etaPhiFromPosition(const double x,
0075                           const double y,
0076                           const double z,
0077                           const int layer,
0078                           int& ieta,
0079                           int& iphi,
0080                           int& type,
0081                           double& wt) const;
0082   inline int firstLayer() const { return hgpar_->firstLayer_; }
0083   inline HGCalGeometryMode::GeometryMode geomMode() const { return mode_; }
0084   int getLayer(double z, bool reco) const;
0085   int getLayerOffset() const { return hgpar_->layerOffset_; }
0086   HGCalParameters::hgtrap getModule(unsigned int k, bool hexType, bool reco) const;
0087   std::vector<HGCalParameters::hgtrap> getModules() const;
0088   inline const HGCalParameters* getParameter() const { return hgpar_; }
0089   int getPhiBins(int lay) const;
0090   std::pair<double, double> getRangeR(int, bool reco) const;
0091   std::pair<int, int> getREtaRange(int lay) const;
0092   inline const std::vector<double>& getRadiusLayer(int layer) const {
0093     return hgpar_->radiusLayer_[(tileTrapezoid() ? hgpar_->scintType(layer) : 0)];
0094   }
0095   inline HGCalParameters::hgtrform getTrForm(unsigned int k) const { return hgpar_->getTrForm(k); }
0096   inline unsigned int getTrFormN() const { return hgpar_->trformIndex_.size(); }
0097   std::vector<HGCalParameters::hgtrform> getTrForms() const;
0098   int getTypeTrap(int layer) const;
0099   int getTypeHex(int layer, int waferU, int waferV) const;
0100   std::pair<double, double> getXY(int layer, double x, double y, bool forwd) const;
0101   inline int getUVMax(int type) const { return ((type == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_); }
0102   double guardRingOffset(bool reco) const;
0103   bool isHalfCell(int waferType, int cell) const;
0104   bool isValidHex(int lay, int mod, int cell, bool reco) const;
0105   bool isValidHex8(int lay, int waferU, int waferV, bool fullAndPart) const;
0106   bool isValidHex8(int lay, int modU, int modV, int cellU, int cellV, bool fullAndPart) const;
0107   bool isValidTrap(int zside, int lay, int ieta, int iphi) const;
0108   int lastLayer(bool reco) const;
0109   int layerIndex(int lay, bool reco) const;
0110   unsigned int layers(bool reco) const;
0111   unsigned int layersInit(bool reco) const;
0112   inline int layerType(int lay) const {
0113     return ((hgpar_->layerType_.empty()) ? HGCalTypes::WaferCenter : hgpar_->layerType_[lay - hgpar_->firstLayer_]);
0114   }
0115   std::pair<float, float> localToGlobal8(
0116       int zside, int lay, int waferU, int waferV, double localX, double localY, bool reco, bool debug) const;
0117   std::pair<float, float> locateCell(int cell, int lay, int type, bool reco) const;
0118   std::pair<float, float> locateCell(int zside,
0119                                      int lay,
0120                                      int waferU,
0121                                      int waferV,
0122                                      int cellU,
0123                                      int cellV,
0124                                      bool reco,
0125                                      bool all,
0126                                      bool norot,
0127                                      bool cog,
0128                                      bool debug) const;
0129   std::pair<float, float> locateCell(const HGCSiliconDetId&, bool cog, bool debug) const;
0130   std::pair<float, float> locateCell(const HGCScintillatorDetId&, bool debug) const;
0131   std::pair<float, float> locateCellHex(int cell, int wafer, bool reco) const;
0132   std::pair<float, float> locateCellTrap(int zside, int lay, int ieta, int iphi, bool reco, bool debug) const;
0133   inline int levelTop(int ind = 0) const { return hgpar_->levelT_[ind]; }
0134   bool maskCell(const DetId& id, int corners) const;
0135   inline int maxCellUV() const { return (tileTrapezoid() ? hgpar_->nCellsFine_ : 2 * hgpar_->nCellsFine_); }
0136   int maxCells(bool reco) const;
0137   int maxCells(int lay, bool reco) const;
0138   inline int maxModules() const { return modHalf_; }
0139   inline int maxModulesPerLayer() const { return maxWafersPerLayer_; }
0140   int maxRows(int lay, bool reco) const;
0141   inline double minSlope() const { return hgpar_->slopeMin_[0]; }
0142   int modifyUV(int uv, int type1, int type2) const;
0143   int modules(int lay, bool reco) const;
0144   int modulesInit(int lay, bool reco) const;
0145   double mouseBite(bool reco) const;
0146   int numberCells(bool reco) const;
0147   std::vector<int> numberCells(int lay, bool reco) const;
0148   int numberCellsHexagon(int wafer) const;
0149   int numberCellsHexagon(int lay, int waferU, int waferV, bool flag) const;
0150   inline int partialWaferType(int lay, int waferU, int waferV) const {
0151     int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV);
0152     auto ktr = hgpar_->waferInfoMap_.find(indx);
0153     int part = (ktr != hgpar_->waferInfoMap_.end()) ? (ktr->second).part : HGCalTypes::WaferFull;
0154     return part;
0155   }
0156   int32_t placementIndex(const HGCSiliconDetId&) const;
0157   std::pair<double, double> rangeR(double z, bool reco) const;
0158   std::pair<double, double> rangeRLayer(int lay, bool reco) const;
0159   std::pair<double, double> rangeZ(bool reco) const;
0160   std::pair<int, int> rowColumnWafer(const int wafer) const;
0161   bool scintFine(int layer) const { return (hgpar_->scintFine(layer - hgpar_->firstLayer_)); }
0162   inline int sectors() const { return hgpar_->nSectors_; }
0163   double sensorSizeOffset(bool reco) const;
0164   std::pair<int, int> simToReco(int cell, int layer, int mod, bool half) const;
0165   int tileCount(int layer, int ring) const;
0166   bool tileExist(int zside, int layer, int ring, int phi) const;
0167   HGCalParameters::tileInfo tileInfo(int zside, int layer, int ring) const;
0168   bool tilePhiEdge(double phi, int layer, int iphi) const;
0169   bool tileRingEdge(double rho, int layer, int ring) const;
0170   std::pair<int, int> tileRings(int layer) const;
0171   inline int tileSiPM(int sipm) const { return ((sipm > 0) ? HGCalTypes::SiPMSmall : HGCalTypes::SiPMLarge); }
0172   bool tileTrapezoid() const {
0173     return ((mode_ == HGCalGeometryMode::Trapezoid) || (mode_ == HGCalGeometryMode::TrapezoidFile) ||
0174             (mode_ == HGCalGeometryMode::TrapezoidModule) || (mode_ == HGCalGeometryMode::TrapezoidCassette) ||
0175             (mode_ == HGCalGeometryMode::TrapezoidFineCell));
0176   }
0177   std::pair<int, int> tileType(int layer, int ring, int phi) const;
0178   inline bool trapezoidFile() const {
0179     return ((mode_ == HGCalGeometryMode::TrapezoidFile) || (mode_ == HGCalGeometryMode::TrapezoidModule) ||
0180             (mode_ == HGCalGeometryMode::TrapezoidCassette) || (mode_ == HGCalGeometryMode::TrapezoidFineCell));
0181   }
0182   inline bool v16OrLess() const { return (mode_ < HGCalGeometryMode::Hexagon8Cassette); }
0183   inline bool v17OrLess() const { return (mode_ < HGCalGeometryMode::Hexagon8CalibCell); }
0184   inline bool v18OrLess() const { return (mode_ < HGCalGeometryMode::Hexagon8FineCell); }
0185   inline unsigned int volumes() const { return hgpar_->moduleLayR_.size(); }
0186   int waferFromCopy(int copy) const;
0187   void waferFromPosition(const double x, const double y, int& wafer, int& icell, int& celltyp) const;
0188   void waferFromPosition(const double x,
0189                          const double y,
0190                          const int zside,
0191                          const int layer,
0192                          int& waferU,
0193                          int& waferV,
0194                          int& cellU,
0195                          int& cellV,
0196                          int& celltype,
0197                          double& wt,
0198                          bool extend,
0199                          bool debug) const;
0200   inline bool waferHexagon6() const {
0201     return ((mode_ == HGCalGeometryMode::Hexagon) || (mode_ == HGCalGeometryMode::HexagonFull));
0202   }
0203   inline bool waferHexagon8() const {
0204     return ((mode_ == HGCalGeometryMode::Hexagon8) || (mode_ == HGCalGeometryMode::Hexagon8Full) ||
0205             (mode_ == HGCalGeometryMode::Hexagon8File) || (mode_ == HGCalGeometryMode::Hexagon8Module) ||
0206             (mode_ == HGCalGeometryMode::Hexagon8Cassette) || (mode_ == HGCalGeometryMode::Hexagon8CalibCell) ||
0207             (mode_ == HGCalGeometryMode::Hexagon8FineCell));
0208   }
0209   inline bool waferHexagon8Calib() const {
0210     return ((mode_ == HGCalGeometryMode::Hexagon8CalibCell) || (mode_ == HGCalGeometryMode::Hexagon8FineCell));
0211   }
0212   inline bool waferHexagon8Cassette() const {
0213     return ((mode_ == HGCalGeometryMode::Hexagon8Cassette) || (mode_ == HGCalGeometryMode::Hexagon8CalibCell) ||
0214             (mode_ == HGCalGeometryMode::Hexagon8FineCell));
0215   }
0216   inline bool waferHexagon8File() const {
0217     return ((mode_ == HGCalGeometryMode::Hexagon8File) || (mode_ == HGCalGeometryMode::Hexagon8Module) ||
0218             (mode_ == HGCalGeometryMode::Hexagon8Cassette) || (mode_ == HGCalGeometryMode::Hexagon8CalibCell) ||
0219             (mode_ == HGCalGeometryMode::Hexagon8FineCell));
0220   }
0221   inline bool waferHexagon8Fine() const { return ((mode_ == HGCalGeometryMode::Hexagon8FineCell)); }
0222   inline bool waferHexagon8Module() const {
0223     return ((mode_ == HGCalGeometryMode::Hexagon8Module) || (mode_ == HGCalGeometryMode::Hexagon8Cassette) ||
0224             (mode_ == HGCalGeometryMode::Hexagon8CalibCell) || (mode_ == HGCalGeometryMode::Hexagon8FineCell));
0225   }
0226   bool waferInLayer(int wafer, int lay, bool reco) const;
0227   bool waferFullInLayer(int wafer, int lay, bool reco) const;
0228   inline int waferCount(const int type) const { return ((type == 0) ? waferMax_[2] : waferMax_[3]); }
0229   HGCalParameters::waferInfo waferInfo(int lay, int waferU, int waferV) const;
0230   inline int waferMax() const { return waferMax_[1]; }
0231   inline int waferMin() const { return waferMax_[0]; }
0232   std::pair<double, double> waferParameters(bool reco) const;
0233   std::pair<double, double> waferPosition(int wafer, bool reco) const;
0234   std::pair<double, double> waferPosition(int lay, int waferU, int waferV, bool reco, bool debug) const;
0235   std::pair<double, double> waferPositionWithCshift(
0236       int lay, int waferU, int waferV, bool norot, bool reco, bool debug) const;
0237   inline unsigned int waferFileSize() const { return hgpar_->waferInfoMap_.size(); }
0238   int waferFileIndex(unsigned int kk) const;
0239   std::tuple<int, int, int, int> waferFileInfo(unsigned int kk) const;
0240   std::tuple<int, int, int, int> waferFileInfoFromIndex(int kk) const;
0241   inline bool waferFileInfoExist(int kk) const {
0242     return (hgpar_->waferInfoMap_.find(kk) != hgpar_->waferInfoMap_.end());
0243   }
0244   GlobalPoint waferLocal2Global(
0245       HepGeom::Point3D<float>& loc, const DetId& id, bool useWafer, bool reco, bool debug) const;
0246   inline double waferSepar(bool reco) const {
0247     return (reco ? hgpar_->sensorSeparation_ : HGCalParameters::k_ScaleToDDD * hgpar_->sensorSeparation_);
0248   }
0249   inline double waferSize(bool reco) const {
0250     return (reco ? hgpar_->waferSize_ : HGCalParameters::k_ScaleToDDD * hgpar_->waferSize_);
0251   }
0252   int wafers() const;
0253   int wafers(int layer, int type) const;
0254   inline int waferToCopy(int wafer) const {
0255     return ((wafer >= 0) && (wafer < static_cast<int>(hgpar_->waferCopy_.size())))
0256                ? hgpar_->waferCopy_[wafer]
0257                : static_cast<int>(hgpar_->waferCopy_.size());
0258   }
0259   // wafer transverse thickness classification (2 = coarse, 1 = fine)
0260   inline int waferTypeT(int wafer) const {
0261     return ((wafer >= 0) && (wafer < static_cast<int>(hgpar_->waferTypeT_.size()))) ? hgpar_->waferTypeT_[wafer] : 0;
0262   }
0263   // wafer longitudinal thickness classification (1 = 100um, 2 = 200um, 3=300um)
0264   inline int waferTypeL(int wafer) const {
0265     return ((wafer >= 0) && (wafer < static_cast<int>(hgpar_->waferTypeL_.size()))) ? hgpar_->waferTypeL_[wafer] : 0;
0266   }
0267   int waferType(DetId const& id, bool fromFile) const;
0268   int waferType(int layer, int waferU, int waferV, bool fromFile) const;
0269   std::tuple<int, int, int> waferType(HGCSiliconDetId const& id, bool fromFile) const;
0270   std::pair<int, int> waferTypeRotation(int layer, int waferU, int waferV, bool fromFile, bool debug) const;
0271   inline int waferUVMax() const { return hgpar_->waferUVMax_; }
0272   bool waferVirtual(int layer, int waferU, int waferV) const;
0273   double waferZ(int layer, bool reco) const;
0274 
0275 private:
0276   int cellHex(double xx,
0277               double yy,
0278               const double& cellR,
0279               const std::vector<double>& posX,
0280               const std::vector<double>& posY) const;
0281   void cellHex(
0282       double xloc, double yloc, int cellType, int place, int part, int& cellU, int& cellV, bool extend, bool debug)
0283       const;
0284   std::pair<int, float> getIndex(int lay, bool reco) const;
0285   int layerFromIndex(int index, bool reco) const;
0286   bool isValidCell(int layindex, int wafer, int cell) const;
0287   bool isValidCell8(int lay, int waferU, int waferV, int cellU, int cellV, int type) const;
0288   int32_t waferIndex(int wafer, int index) const;
0289   bool waferInLayerTest(int wafer, int lay, bool full) const;
0290   std::pair<double, double> waferPositionNoRot(int lay, int waferU, int waferV, bool reco, bool debug) const;
0291   std::pair<double, double> waferPosition(int waferU, int waferV, bool reco) const;
0292 
0293   HGCalCassette hgcassette_;
0294   std::unique_ptr<HGCalCell> hgcell_;
0295   std::unique_ptr<HGCalCellUV> hgcellUV_;
0296   std::unique_ptr<HGCalCellOffset> cellOffset_;
0297   HGCalGeomTools geomTools_;
0298   constexpr static double k_horizontalShift = 1.0;
0299   constexpr static float dPhiMin = 0.02;
0300   typedef std::array<std::vector<int32_t>, 2> Simrecovecs;
0301   typedef std::array<int, 3> HGCWaferParam;
0302   const HGCalParameters* hgpar_;
0303   constexpr static double tan30deg_ = 0.5773502693;
0304   constexpr static double tol_ = 0.001;
0305   const double sqrt3_;
0306   const HGCalGeometryMode::GeometryMode mode_;
0307   const bool fullAndPart_;
0308   double rmax_, hexside_;
0309   double rmaxT_, hexsideT_;
0310   int32_t tot_wafers_, modHalf_;
0311   std::array<uint32_t, 2> tot_layers_;
0312   Simrecovecs max_modules_layer_;
0313   int32_t maxWafersPerLayer_;
0314   std::map<int, HGCWaferParam> waferLayer_;
0315   std::array<int, 4> waferMax_;
0316   std::unordered_map<int32_t, bool> waferIn_;
0317 };
0318 
0319 #endif