File indexing completed on 2025-12-13 09:21:25
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Seeding/GbtsGeometry.hpp"
0010
0011 #include <cmath>
0012 #include <cstring>
0013 #include <iostream>
0014
0015 namespace Acts::Experimental {
0016
0017 GbtsLayer::GbtsLayer(const TrigInDetSiLayer& ls, float ew, int bin0)
0018 : m_layer(ls), m_etaBinWidth(ew) {
0019 if (m_layer.m_type == 0) {
0020 m_r1 = m_layer.m_refCoord;
0021 m_r2 = m_layer.m_refCoord;
0022 m_z1 = m_layer.m_minBound;
0023 m_z2 = m_layer.m_maxBound;
0024 } else {
0025 m_r1 = m_layer.m_minBound;
0026 m_r2 = m_layer.m_maxBound;
0027 m_z1 = m_layer.m_refCoord;
0028 m_z2 = m_layer.m_refCoord;
0029 }
0030
0031 float t1 = m_z1 / m_r1;
0032 float eta1 = -std::log(std::sqrt(1 + t1 * t1) - t1);
0033
0034 float t2 = m_z2 / m_r2;
0035 float eta2 = -std::log(std::sqrt(1 + t2 * t2) - t2);
0036
0037 m_minEta = eta1;
0038 m_maxEta = eta2;
0039
0040 if (m_maxEta < m_minEta) {
0041 m_minEta = eta2;
0042 m_maxEta = eta1;
0043 }
0044
0045 m_maxEta += 1e-6;
0046 m_minEta -= 1e-6;
0047
0048 float deltaEta = m_maxEta - m_minEta;
0049
0050 int binCounter = bin0;
0051
0052 if (deltaEta < m_etaBinWidth) {
0053 m_nBins = 1;
0054 m_bins.push_back(binCounter++);
0055 m_etaBin = deltaEta;
0056 if (m_layer.m_type == 0) {
0057 m_minRadius.push_back(m_layer.m_refCoord - 2.0);
0058 m_maxRadius.push_back(m_layer.m_refCoord + 2.0);
0059 m_minBinCoord.push_back(m_layer.m_minBound);
0060 m_maxBinCoord.push_back(m_layer.m_maxBound);
0061 } else {
0062 m_minRadius.push_back(m_layer.m_minBound - 2.0);
0063 m_maxRadius.push_back(m_layer.m_maxBound + 2.0);
0064 m_minBinCoord.push_back(m_layer.m_minBound);
0065 m_maxBinCoord.push_back(m_layer.m_maxBound);
0066 }
0067 } else {
0068 int nB = static_cast<int>(deltaEta / m_etaBinWidth);
0069 m_nBins = nB;
0070 if (deltaEta - m_etaBinWidth * nB > 0.5 * m_etaBinWidth) {
0071 m_nBins++;
0072 }
0073
0074 m_etaBin = deltaEta / m_nBins;
0075
0076 if (m_nBins == 1) {
0077 m_bins.push_back(binCounter++);
0078 if (m_layer.m_type == 0) {
0079 m_minRadius.push_back(m_layer.m_refCoord - 2.0);
0080 m_maxRadius.push_back(m_layer.m_refCoord + 2.0);
0081 m_minBinCoord.push_back(m_layer.m_minBound);
0082 m_maxBinCoord.push_back(m_layer.m_maxBound);
0083 } else {
0084 m_minRadius.push_back(m_layer.m_minBound - 2.0);
0085 m_maxRadius.push_back(m_layer.m_maxBound + 2.0);
0086 m_minBinCoord.push_back(m_layer.m_minBound);
0087 m_maxBinCoord.push_back(m_layer.m_maxBound);
0088 }
0089 } else {
0090 float eta = m_minEta + 0.5 * m_etaBin;
0091
0092 for (int i = 1; i <= m_nBins; i++) {
0093 m_bins.push_back(binCounter++);
0094
0095 float e1 = eta - 0.5 * m_etaBin;
0096 float e2 = eta + 0.5 * m_etaBin;
0097
0098 if (m_layer.m_type == 0) {
0099 m_minRadius.push_back(m_layer.m_refCoord - 2.0);
0100 m_maxRadius.push_back(m_layer.m_refCoord + 2.0);
0101 float z1 = m_layer.m_refCoord * std::sinh(e1);
0102 m_minBinCoord.push_back(z1);
0103 float z2 = m_layer.m_refCoord * std::sinh(e2);
0104 m_maxBinCoord.push_back(z2);
0105 } else {
0106 float r = m_layer.m_refCoord / std::sinh(e1);
0107 m_minBinCoord.push_back(r);
0108 m_minRadius.push_back(r - 2.0);
0109 r = m_layer.m_refCoord / std::sinh(e2);
0110 m_maxBinCoord.push_back(r);
0111 m_maxRadius.push_back(r + 2.0);
0112 }
0113
0114 eta += m_etaBin;
0115 }
0116 }
0117 }
0118 }
0119
0120 bool GbtsLayer::verifyBin(const GbtsLayer* pL, int b1, int b2, float min_z0,
0121 float max_z0) const {
0122 float z1min = m_minBinCoord.at(b1);
0123 float z1max = m_maxBinCoord.at(b1);
0124 float r1 = m_layer.m_refCoord;
0125
0126 if (m_layer.m_type == 0 && pL->m_layer.m_type == 0) {
0127
0128 const float tol = 5.0;
0129
0130 float min_b2 = pL->m_minBinCoord.at(b2);
0131 float max_b2 = pL->m_maxBinCoord.at(b2);
0132
0133 float r2 = pL->m_layer.m_refCoord;
0134
0135 float A = r2 / (r2 - r1);
0136 float B = r1 / (r2 - r1);
0137
0138 float z0_min = z1min * A - max_b2 * B;
0139 float z0_max = z1max * A - min_b2 * B;
0140
0141 if (z0_max < min_z0 - tol || z0_min > max_z0 + tol) {
0142 return false;
0143 }
0144
0145 return true;
0146 }
0147
0148 if (m_layer.m_type == 0 && pL->m_layer.m_type != 0) {
0149
0150 const float tol = 10.0;
0151
0152 float z2 = pL->m_layer.m_refCoord;
0153 float r2max = pL->m_maxBinCoord.at(b2);
0154 float r2min = pL->m_minBinCoord.at(b2);
0155
0156 if (r2max <= r1) {
0157 return false;
0158 }
0159
0160 if (r2min <= r1) {
0161 r2min = r1 + 1e-3;
0162 }
0163
0164 float z0_max = 0.0;
0165 float z0_min = 0.0;
0166
0167 if (z2 > 0) {
0168 z0_max = (z1max * r2max - z2 * r1) / (r2max - r1);
0169 z0_min = (z1min * r2min - z2 * r1) / (r2min - r1);
0170 } else {
0171 z0_max = (z1max * r2min - z2 * r1) / (r2min - r1);
0172 z0_min = (z1min * r2max - z2 * r1) / (r2max - r1);
0173 }
0174
0175 if (z0_max < min_z0 - tol || z0_min > max_z0 + tol) {
0176 return false;
0177 }
0178 return true;
0179 }
0180
0181 return true;
0182 }
0183
0184 int GbtsLayer::getEtaBin(float zh, float rh) const {
0185 if (m_bins.size() == 1) {
0186 return m_bins.at(0);
0187 }
0188
0189 float t1 = zh / rh;
0190 float eta = -std::log(std::sqrt(1 + t1 * t1) - t1);
0191
0192 int idx = static_cast<int>((eta - m_minEta) / m_etaBin);
0193
0194 if (idx < 0) {
0195 idx = 0;
0196 }
0197 if (idx >= static_cast<int>(m_bins.size())) {
0198 idx = static_cast<int>(m_bins.size()) - 1;
0199 }
0200
0201 return m_bins.at(idx);
0202 }
0203
0204 float GbtsLayer::getMinBinRadius(int idx) const {
0205 if (idx >= static_cast<int>(m_minRadius.size())) {
0206 idx = idx - 1;
0207 }
0208 if (idx < 0) {
0209 idx = 0;
0210 }
0211
0212 return m_minRadius.at(idx);
0213 }
0214
0215 float GbtsLayer::getMaxBinRadius(int idx) const {
0216 if (idx >= static_cast<int>(m_maxRadius.size())) {
0217 idx = idx - 1;
0218 }
0219 if (idx < 0) {
0220 idx = 0;
0221 }
0222
0223 return m_maxRadius.at(idx);
0224 }
0225
0226 GbtsLayer::~GbtsLayer() {
0227 m_bins.clear();
0228 }
0229
0230 GbtsGeometry::GbtsGeometry(const std::vector<TrigInDetSiLayer>& layers,
0231 const std::unique_ptr<GbtsConnector>& conn) {
0232 const float min_z0 = -168.0;
0233 const float max_z0 = 168.0;
0234
0235 m_etaBinWidth = conn->m_etaBin;
0236
0237 for (const auto& layer : layers) {
0238 const GbtsLayer* pL = addNewLayer(layer, m_nEtaBins);
0239 m_nEtaBins += pL->num_bins();
0240 }
0241
0242
0243
0244
0245 int lastBin1 = -1;
0246
0247 for (std::map<int, std::vector<GbtsConnection*> >::const_iterator it =
0248 conn->m_connMap.begin();
0249 it != conn->m_connMap.end(); ++it) {
0250 const std::vector<GbtsConnection*>& vConn = (*it).second;
0251
0252 for (std::vector<GbtsConnection*>::const_iterator cIt = vConn.begin();
0253 cIt != vConn.end(); ++cIt) {
0254 unsigned int src = (*cIt)->m_src;
0255 unsigned int dst = (*cIt)->m_dst;
0256
0257 const GbtsLayer* pL1 = getGbtsLayerByKey(dst);
0258 const GbtsLayer* pL2 = getGbtsLayerByKey(src);
0259
0260 if (pL1 == nullptr) {
0261 std::cout << " skipping invalid dst layer " << dst << std::endl;
0262 continue;
0263 }
0264 if (pL2 == nullptr) {
0265 std::cout << " skipping invalid src layer " << src << std::endl;
0266 continue;
0267 }
0268 int nSrcBins = pL2->m_bins.size();
0269 int nDstBins = pL1->m_bins.size();
0270
0271 (*cIt)->m_binTable.resize(nSrcBins * nDstBins, 0);
0272
0273 for (int b1 = 0; b1 < nDstBins; b1++) {
0274 for (int b2 = 0; b2 < nSrcBins; b2++) {
0275 if (!pL1->verifyBin(pL2, b1, b2, min_z0, max_z0)) {
0276 continue;
0277 }
0278 int address = b1 + b2 * nDstBins;
0279 (*cIt)->m_binTable.at(address) = 1;
0280
0281 int bin1_idx = pL1->m_bins.at(b1);
0282 int bin2_idx = pL2->m_bins.at(b2);
0283
0284 if (bin1_idx != lastBin1) {
0285
0286 std::vector<int> v2(1, bin2_idx);
0287 m_binGroups.push_back(std::make_pair(bin1_idx, v2));
0288 lastBin1 = bin1_idx;
0289
0290 } else {
0291 (*m_binGroups.rbegin()).second.push_back(bin2_idx);
0292 }
0293 }
0294 }
0295 }
0296 }
0297 }
0298
0299 GbtsGeometry::~GbtsGeometry() {
0300 for (std::vector<GbtsLayer*>::iterator it = m_layArray.begin();
0301 it != m_layArray.end(); ++it) {
0302 delete (*it);
0303 }
0304 m_layMap.clear();
0305 m_layArray.clear();
0306 }
0307
0308 const GbtsLayer* GbtsGeometry::getGbtsLayerByKey(unsigned int key) const {
0309 std::map<unsigned int, GbtsLayer*>::const_iterator it = m_layMap.find(key);
0310 if (it == m_layMap.end()) {
0311 return nullptr;
0312 }
0313 return (*it).second;
0314 }
0315
0316 const GbtsLayer* GbtsGeometry::getGbtsLayerByIndex(int idx) const {
0317 return m_layArray.at(idx);
0318 }
0319
0320 const GbtsLayer* GbtsGeometry::addNewLayer(const TrigInDetSiLayer& l,
0321 int bin0) {
0322 unsigned int layerKey = l.m_subdet;
0323
0324 float ew = m_etaBinWidth;
0325
0326 GbtsLayer* pHL = new GbtsLayer(l, ew, bin0);
0327
0328 m_layMap.insert(std::pair<unsigned int, GbtsLayer*>(layerKey, pHL));
0329 m_layArray.push_back(pHL);
0330 return pHL;
0331 }
0332
0333 }