File indexing completed on 2024-11-25 02:29:39
0001 #ifndef HGCalCommonData_HGCalDDDConstants_h
0002 #define HGCalCommonData_HGCalDDDConstants_h
0003
0004
0005
0006
0007
0008
0009
0010
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 inline int sectors() const { return hgpar_->nSectors_; }
0162 double sensorSizeOffset(bool reco) const;
0163 std::pair<int, int> simToReco(int cell, int layer, int mod, bool half) const;
0164 int tileCount(int layer, int ring) const;
0165 bool tileExist(int zside, int layer, int ring, int phi) const;
0166 HGCalParameters::tileInfo tileInfo(int zside, int layer, int ring) const;
0167 bool tilePhiEdge(double phi, int layer, int iphi) const;
0168 bool tileRingEdge(double rho, int layer, int ring) const;
0169 std::pair<int, int> tileRings(int layer) const;
0170 inline int tileSiPM(int sipm) const { return ((sipm > 0) ? HGCalTypes::SiPMSmall : HGCalTypes::SiPMLarge); }
0171 bool tileTrapezoid() const {
0172 return ((mode_ == HGCalGeometryMode::Trapezoid) || (mode_ == HGCalGeometryMode::TrapezoidFile) ||
0173 (mode_ == HGCalGeometryMode::TrapezoidModule) || (mode_ == HGCalGeometryMode::TrapezoidCassette) ||
0174 (mode_ == HGCalGeometryMode::TrapezoidFineCell));
0175 }
0176 std::pair<int, int> tileType(int layer, int ring, int phi) const;
0177 inline bool trapezoidFile() const {
0178 return ((mode_ == HGCalGeometryMode::TrapezoidFile) || (mode_ == HGCalGeometryMode::TrapezoidModule) ||
0179 (mode_ == HGCalGeometryMode::TrapezoidCassette) || (mode_ == HGCalGeometryMode::TrapezoidFineCell));
0180 }
0181 inline bool v17OrLess() const { return (mode_ < HGCalGeometryMode::Hexagon8CalibCell); }
0182 inline unsigned int volumes() const { return hgpar_->moduleLayR_.size(); }
0183 int waferFromCopy(int copy) const;
0184 void waferFromPosition(const double x, const double y, int& wafer, int& icell, int& celltyp) const;
0185 void waferFromPosition(const double x,
0186 const double y,
0187 const int zside,
0188 const int layer,
0189 int& waferU,
0190 int& waferV,
0191 int& cellU,
0192 int& cellV,
0193 int& celltype,
0194 double& wt,
0195 bool extend,
0196 bool debug) const;
0197 inline bool waferHexagon6() const {
0198 return ((mode_ == HGCalGeometryMode::Hexagon) || (mode_ == HGCalGeometryMode::HexagonFull));
0199 }
0200 inline bool waferHexagon8() const {
0201 return ((mode_ == HGCalGeometryMode::Hexagon8) || (mode_ == HGCalGeometryMode::Hexagon8Full) ||
0202 (mode_ == HGCalGeometryMode::Hexagon8File) || (mode_ == HGCalGeometryMode::Hexagon8Module) ||
0203 (mode_ == HGCalGeometryMode::Hexagon8Cassette) || (mode_ == HGCalGeometryMode::Hexagon8CalibCell) ||
0204 (mode_ == HGCalGeometryMode::Hexagon8FineCell));
0205 }
0206 inline bool waferHexagon8File() const {
0207 return ((mode_ == HGCalGeometryMode::Hexagon8File) || (mode_ == HGCalGeometryMode::Hexagon8Module) ||
0208 (mode_ == HGCalGeometryMode::Hexagon8Cassette) || (mode_ == HGCalGeometryMode::Hexagon8CalibCell) ||
0209 (mode_ == HGCalGeometryMode::Hexagon8FineCell));
0210 }
0211 inline bool waferHexagon8Fine() const { return ((mode_ == HGCalGeometryMode::Hexagon8FineCell)); }
0212 inline bool waferHexagon8Module() const {
0213 return ((mode_ == HGCalGeometryMode::Hexagon8Module) || (mode_ == HGCalGeometryMode::Hexagon8Cassette) ||
0214 (mode_ == HGCalGeometryMode::Hexagon8CalibCell) || (mode_ == HGCalGeometryMode::Hexagon8FineCell));
0215 }
0216 bool waferInLayer(int wafer, int lay, bool reco) const;
0217 bool waferFullInLayer(int wafer, int lay, bool reco) const;
0218 inline int waferCount(const int type) const { return ((type == 0) ? waferMax_[2] : waferMax_[3]); }
0219 HGCalParameters::waferInfo waferInfo(int lay, int waferU, int waferV) const;
0220 inline int waferMax() const { return waferMax_[1]; }
0221 inline int waferMin() const { return waferMax_[0]; }
0222 std::pair<double, double> waferParameters(bool reco) const;
0223 std::pair<double, double> waferPosition(int wafer, bool reco) const;
0224 std::pair<double, double> waferPosition(int lay, int waferU, int waferV, bool reco, bool debug) const;
0225 inline unsigned int waferFileSize() const { return hgpar_->waferInfoMap_.size(); }
0226 int waferFileIndex(unsigned int kk) const;
0227 std::tuple<int, int, int, int> waferFileInfo(unsigned int kk) const;
0228 std::tuple<int, int, int, int> waferFileInfoFromIndex(int kk) const;
0229 inline bool waferFileInfoExist(int kk) const {
0230 return (hgpar_->waferInfoMap_.find(kk) != hgpar_->waferInfoMap_.end());
0231 }
0232 GlobalPoint waferLocal2Global(
0233 HepGeom::Point3D<float>& loc, const DetId& id, bool useWafer, bool reco, bool debug) const;
0234 inline double waferSepar(bool reco) const {
0235 return (reco ? hgpar_->sensorSeparation_ : HGCalParameters::k_ScaleToDDD * hgpar_->sensorSeparation_);
0236 }
0237 inline double waferSize(bool reco) const {
0238 return (reco ? hgpar_->waferSize_ : HGCalParameters::k_ScaleToDDD * hgpar_->waferSize_);
0239 }
0240 int wafers() const;
0241 int wafers(int layer, int type) const;
0242 inline int waferToCopy(int wafer) const {
0243 return ((wafer >= 0) && (wafer < static_cast<int>(hgpar_->waferCopy_.size())))
0244 ? hgpar_->waferCopy_[wafer]
0245 : static_cast<int>(hgpar_->waferCopy_.size());
0246 }
0247
0248 inline int waferTypeT(int wafer) const {
0249 return ((wafer >= 0) && (wafer < static_cast<int>(hgpar_->waferTypeT_.size()))) ? hgpar_->waferTypeT_[wafer] : 0;
0250 }
0251
0252 inline int waferTypeL(int wafer) const {
0253 return ((wafer >= 0) && (wafer < static_cast<int>(hgpar_->waferTypeL_.size()))) ? hgpar_->waferTypeL_[wafer] : 0;
0254 }
0255 int waferType(DetId const& id, bool fromFile) const;
0256 int waferType(int layer, int waferU, int waferV, bool fromFile) const;
0257 std::tuple<int, int, int> waferType(HGCSiliconDetId const& id, bool fromFile) const;
0258 std::pair<int, int> waferTypeRotation(int layer, int waferU, int waferV, bool fromFile, bool debug) const;
0259 inline int waferUVMax() const { return hgpar_->waferUVMax_; }
0260 bool waferVirtual(int layer, int waferU, int waferV) const;
0261 double waferZ(int layer, bool reco) const;
0262
0263 private:
0264 int cellHex(double xx,
0265 double yy,
0266 const double& cellR,
0267 const std::vector<double>& posX,
0268 const std::vector<double>& posY) const;
0269 void cellHex(
0270 double xloc, double yloc, int cellType, int place, int part, int& cellU, int& cellV, bool extend, bool debug)
0271 const;
0272 std::pair<int, float> getIndex(int lay, bool reco) const;
0273 int layerFromIndex(int index, bool reco) const;
0274 bool isValidCell(int layindex, int wafer, int cell) const;
0275 bool isValidCell8(int lay, int waferU, int waferV, int cellU, int cellV, int type) const;
0276 int32_t waferIndex(int wafer, int index) const;
0277 bool waferInLayerTest(int wafer, int lay, bool full) const;
0278 std::pair<double, double> waferPositionNoRot(int lay, int waferU, int waferV, bool reco, bool debug) const;
0279 std::pair<double, double> waferPosition(int waferU, int waferV, bool reco) const;
0280
0281 HGCalCassette hgcassette_;
0282 std::unique_ptr<HGCalCell> hgcell_;
0283 std::unique_ptr<HGCalCellUV> hgcellUV_;
0284 std::unique_ptr<HGCalCellOffset> cellOffset_;
0285 HGCalGeomTools geomTools_;
0286 constexpr static double k_horizontalShift = 1.0;
0287 constexpr static float dPhiMin = 0.02;
0288 typedef std::array<std::vector<int32_t>, 2> Simrecovecs;
0289 typedef std::array<int, 3> HGCWaferParam;
0290 const HGCalParameters* hgpar_;
0291 constexpr static double tan30deg_ = 0.5773502693;
0292 constexpr static double tol_ = 0.001;
0293 const double sqrt3_;
0294 const HGCalGeometryMode::GeometryMode mode_;
0295 const bool fullAndPart_;
0296 double rmax_, hexside_;
0297 double rmaxT_, hexsideT_;
0298 int32_t tot_wafers_, modHalf_;
0299 std::array<uint32_t, 2> tot_layers_;
0300 Simrecovecs max_modules_layer_;
0301 int32_t maxWafersPerLayer_;
0302 std::map<int, HGCWaferParam> waferLayer_;
0303 std::array<int, 4> waferMax_;
0304 std::unordered_map<int32_t, bool> waferIn_;
0305 };
0306
0307 #endif