Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-20 00:21:40

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