Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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