Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-02-02 23:24:15

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