Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-11-02 03:11:11

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