File indexing completed on 2024-04-06 11:59:46
0001 #ifndef CalibTracker_SiStripCommon_TkDetMap_h
0002 #define CalibTracker_SiStripCommon_TkDetMap_h
0003
0004 #include <vector>
0005 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
0006 #include <cstdint>
0007
0008 class TrackerTopology;
0009
0010 class TkLayerMap {
0011 public:
0012 struct XYbin {
0013 XYbin(int16_t _ix = -999, int16_t _iy = -999, float _x = -999., float _y = -999.)
0014 : ix(_ix), iy(_iy), x(_x), y(_y) {}
0015 int16_t ix, iy;
0016 float x, y;
0017 };
0018
0019 enum TkLayerEnum {
0020 INVALID = 0,
0021 TIB_L1,
0022 TIB_L2,
0023 TIB_L3,
0024 TIB_L4,
0025 TIDM_D1,
0026 TIDM_D2,
0027 TIDM_D3,
0028 TIDP_D1,
0029 TIDP_D2,
0030 TIDP_D3,
0031 TOB_L1,
0032 TOB_L2,
0033 TOB_L3,
0034 TOB_L4,
0035 TOB_L5,
0036 TOB_L6,
0037 TECM_W1,
0038 TECM_W2,
0039 TECM_W3,
0040 TECM_W4,
0041 TECM_W5,
0042 TECM_W6,
0043 TECM_W7,
0044 TECM_W8,
0045 TECM_W9,
0046 TECP_W1,
0047 TECP_W2,
0048 TECP_W3,
0049 TECP_W4,
0050 TECP_W5,
0051 TECP_W6,
0052 TECP_W7,
0053 TECP_W8,
0054 TECP_W9,
0055 NUMLAYERS
0056 };
0057
0058 TkLayerMap() {}
0059
0060 TkLayerMap(int layer,
0061 std::size_t nchX,
0062 double lowX,
0063 double highX,
0064 std::size_t nchY,
0065 double lowY,
0066 double highY,
0067 const TrackerTopology* tTopo,
0068 const std::vector<uint32_t>& tkDetIdList,
0069 const std::vector<uint32_t>& singleExtString = {},
0070 const std::vector<uint32_t>& modulesInRingFront = {},
0071 const std::vector<uint32_t>& modulesInRingBack = {},
0072 const std::vector<uint32_t>& binForRing = {},
0073 uint32_t nstring_ext = 0,
0074 uint32_t nrod = 0)
0075 : layer_(layer),
0076 nchX_(nchX),
0077 lowX_(lowX),
0078 highX_(highX),
0079 nchY_(nchY),
0080 lowY_(lowY),
0081 highY_(highY),
0082 tTopo_(tTopo),
0083 singleExtStr_(singleExtString),
0084 modulesInRingFront_(modulesInRingFront),
0085 modulesInRingBack_(modulesInRingBack),
0086 binForRing_(binForRing),
0087 nStringExt_(nstring_ext),
0088 nRod_(nrod),
0089 binToDet_(std::vector<DetId>(std::size_t(nchX * nchY), 0)) {
0090 initMap(tkDetIdList);
0091 }
0092
0093 TkLayerMap(int layer,
0094 std::size_t nchX,
0095 double lowX,
0096 double highX,
0097 std::size_t nchY,
0098 double lowY,
0099 double highY,
0100 const TrackerTopology* tTopo,
0101 const std::vector<uint32_t>& tkDetIdList,
0102 std::vector<uint32_t>&& singleExtString = {},
0103 std::vector<uint32_t>&& modulesInRingFront = {},
0104 std::vector<uint32_t>&& modulesInRingBack = {},
0105 std::vector<uint32_t>&& binForRing = {},
0106 uint32_t nstring_ext = 0,
0107 uint32_t nrod = 0)
0108 : layer_(layer),
0109 nchX_(nchX),
0110 lowX_(lowX),
0111 highX_(highX),
0112 nchY_(nchY),
0113 lowY_(lowY),
0114 highY_(highY),
0115 tTopo_(tTopo),
0116 singleExtStr_(singleExtString),
0117 modulesInRingFront_(modulesInRingFront),
0118 modulesInRingBack_(modulesInRingBack),
0119 binForRing_(binForRing),
0120 nStringExt_(nstring_ext),
0121 nRod_(nrod),
0122 binToDet_(std::vector<DetId>(std::size_t(nchX * nchY), 0)) {
0123 initMap(tkDetIdList);
0124 }
0125
0126 void initMap(const std::vector<uint32_t>& tkDetIdList);
0127
0128 private:
0129 void initMap_TIB(const std::vector<uint32_t>& tkDetIdList);
0130 void initMap_TOB(const std::vector<uint32_t>& tkDetIdList);
0131 void initMap_TID(const std::vector<uint32_t>& tkDetIdList);
0132 void initMap_TEC(const std::vector<uint32_t>& tkDetIdList);
0133
0134 std::size_t bin(std::size_t ix, std::size_t iy) const { return (ix - 1) + nchX_ * (iy - 1); }
0135
0136 public:
0137 static const int16_t layerSearch(DetId detid, const TrackerTopology* tTopo);
0138
0139 std::size_t get_nchX() const { return nchX_; }
0140 std::size_t get_nchY() const { return nchY_; }
0141 double get_lowX() const { return lowX_; }
0142 double get_highX() const { return highX_; }
0143 double get_lowY() const { return lowY_; }
0144 double get_highY() const { return highY_; }
0145 const std::vector<DetId>& getBinToDet() const { return binToDet_; }
0146
0147 DetId getDetFromBin(int ix, int iy) const {
0148 const auto idx = bin(ix, iy);
0149 return (idx < nchX_ * nchY_) ? binToDet_[idx] : DetId(0);
0150 }
0151
0152 const XYbin getXY(DetId detid, int layerEnumNb = TkLayerMap::INVALID) const;
0153
0154 private:
0155 XYbin getXY_TIB(DetId detid) const;
0156 XYbin getXY_TOB(DetId detid) const;
0157 XYbin getXY_TID(DetId detid) const;
0158 XYbin getXY_TEC(DetId detid) const;
0159
0160 private:
0161 int layer_;
0162 std::size_t nchX_;
0163 double lowX_, highX_;
0164 std::size_t nchY_;
0165 double lowY_, highY_;
0166 const TrackerTopology* tTopo_;
0167
0168 std::vector<uint32_t> singleExtStr_;
0169 std::vector<uint32_t> modulesInRingFront_, modulesInRingBack_, binForRing_;
0170 uint32_t nStringExt_, nRod_;
0171
0172 std::vector<DetId> binToDet_;
0173 };
0174
0175 class TkDetMap {
0176 public:
0177 TkDetMap(const TrackerTopology* tTopo) : tTopo_(tTopo) {
0178 TkMap.resize(TkLayerMap::NUMLAYERS);
0179 }
0180
0181
0182 void setLayerMap(int layer, const TkLayerMap& lyrMap) { TkMap[layer] = lyrMap; }
0183 void setLayerMap(int layer, TkLayerMap&& lyrMap) { TkMap[layer] = lyrMap; }
0184
0185
0186 static std::string getLayerName(int in);
0187 static int getLayerNum(const std::string& in);
0188
0189 static void getSubDetLayerSide(int in, SiStripDetId::SubDetector&, uint32_t& layer, uint32_t& side);
0190
0191 DetId getDetFromBin(int layer, int ix, int iy) const { return TkMap[layer].getDetFromBin(ix, iy); }
0192 DetId getDetFromBin(const std::string& layerName, int ix, int iy) const {
0193 return getDetFromBin(getLayerNum(layerName), ix, iy);
0194 }
0195
0196 std::vector<DetId> getDetsForLayer(int layer) const {
0197 return TkMap[layer].getBinToDet();
0198 }
0199
0200
0201 const TkLayerMap::XYbin& getXY(DetId detid,
0202 DetId& cached_detid,
0203 int16_t& cached_layer,
0204 TkLayerMap::XYbin& cached_XYbin) const;
0205 int16_t findLayer(DetId detid, DetId& cached_detid, int16_t& cached_layer, TkLayerMap::XYbin& cached_XYbin) const;
0206 void getComponents(int layer, int& nchX, double& lowX, double& highX, int& nchY, double& lowY, double& highY) const;
0207
0208 private:
0209 std::vector<TkLayerMap> TkMap;
0210 const TrackerTopology* tTopo_;
0211 };
0212
0213 #endif