File indexing completed on 2025-12-13 09:21:25
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Seeding/GbtsDataStorage.hpp"
0010
0011 #include <algorithm>
0012 #include <cmath>
0013 #include <cstring>
0014 #include <numbers>
0015 namespace Acts::Experimental {
0016
0017 GbtsEtaBin::GbtsEtaBin() {
0018 m_in.clear();
0019 m_vn.clear();
0020 m_params.clear();
0021 m_vn.reserve(1000);
0022 }
0023
0024 GbtsEtaBin::~GbtsEtaBin() {
0025 m_in.clear();
0026 m_vn.clear();
0027 m_params.clear();
0028 }
0029
0030 void GbtsEtaBin::sortByPhi() {
0031 std::vector<std::pair<float, const GbtsNode*> > phiBuckets[32];
0032
0033 int nBuckets = 31;
0034
0035 for (const auto& n : m_vn) {
0036 int bIdx = static_cast<int>(
0037 0.5 * nBuckets *
0038 (n->phi() / static_cast<float>(std::numbers::pi) + 1.0f));
0039 phiBuckets[bIdx].push_back(std::make_pair(n->phi(), n));
0040 }
0041
0042 for (auto& b : phiBuckets) {
0043 std::sort(b.begin(), b.end());
0044 }
0045
0046 int idx = 0;
0047 for (const auto& b : phiBuckets) {
0048 for (const auto& p : b) {
0049 m_vn[idx++] = p.second;
0050 }
0051 }
0052 }
0053
0054 void GbtsEtaBin::initializeNodes() {
0055 if (m_vn.empty()) {
0056 return;
0057 }
0058
0059 m_params.resize(m_vn.size());
0060
0061 m_in.resize(m_vn.size());
0062 for (auto& v : m_in) {
0063 v.reserve(50);
0064 }
0065
0066 std::transform(
0067 m_vn.begin(), m_vn.end(), m_params.begin(), [](const GbtsNode* pN) {
0068 std::array<float, 5> a = {-100.0, 100.0, pN->phi(), pN->r(), pN->z()};
0069 return a;
0070 });
0071
0072 auto [min_iter, max_iter] = std::minmax_element(
0073 m_vn.begin(), m_vn.end(),
0074 [](const GbtsNode* s, const GbtsNode* s1) { return (s->r() < s1->r()); });
0075 m_maxRadius = (*max_iter)->r();
0076 m_minRadius = (*min_iter)->r();
0077 }
0078
0079 void GbtsEtaBin::generatePhiIndexing(float dphi) {
0080 for (unsigned int nIdx = 0; nIdx < m_vn.size(); nIdx++) {
0081 float phi = m_params[nIdx][2];
0082 if (phi <= std::numbers::pi - dphi) {
0083 continue;
0084 }
0085 m_vPhiNodes.push_back(
0086 std::pair<float, unsigned int>(phi - 2 * std::numbers::pi, nIdx));
0087 }
0088
0089 for (unsigned int nIdx = 0; nIdx < m_vn.size(); nIdx++) {
0090 float phi = m_params[nIdx][2];
0091 m_vPhiNodes.push_back(std::pair<float, unsigned int>(phi, nIdx));
0092 }
0093
0094 for (unsigned int nIdx = 0; nIdx < m_vn.size(); nIdx++) {
0095 float phi = m_params[nIdx][2];
0096 if (phi >= -std::numbers::pi + dphi) {
0097 break;
0098 }
0099 m_vPhiNodes.push_back(
0100 std::pair<float, unsigned int>(phi + 2 * std::numbers::pi, nIdx));
0101 }
0102 }
0103
0104 GbtsDataStorage::GbtsDataStorage(const GbtsGeometry& g) : m_geo(g) {
0105 m_etaBins.resize(g.num_bins());
0106 }
0107
0108 GbtsDataStorage::~GbtsDataStorage() = default;
0109
0110 int GbtsDataStorage::loadPixelGraphNodes(short layerIndex,
0111 const std::vector<GbtsNode>& coll,
0112 bool useML) {
0113 int nLoaded = 0;
0114
0115 const GbtsLayer* pL = m_geo.getGbtsLayerByIndex(layerIndex);
0116
0117 if (pL == nullptr) {
0118 return -1;
0119 }
0120
0121 bool isBarrel = (pL->m_layer.m_type == 0);
0122
0123 for (const auto& node : coll) {
0124 int binIndex = pL->getEtaBin(node.z(), node.r());
0125
0126 if (binIndex == -1) {
0127 continue;
0128 }
0129
0130 if (isBarrel) {
0131 m_etaBins.at(binIndex).m_vn.push_back(&node);
0132 } else {
0133 if (useML) {
0134 float cluster_width = node.pixelClusterWidth();
0135 if (cluster_width > 0.2) {
0136 continue;
0137 }
0138 }
0139 m_etaBins.at(binIndex).m_vn.push_back(&node);
0140 }
0141
0142 nLoaded++;
0143 }
0144
0145 return nLoaded;
0146 }
0147
0148 int GbtsDataStorage::loadStripGraphNodes(short layerIndex,
0149 const std::vector<GbtsNode>& coll) {
0150 int nLoaded = 0;
0151
0152 const GbtsLayer* pL = m_geo.getGbtsLayerByIndex(layerIndex);
0153
0154 if (pL == nullptr) {
0155 return -1;
0156 }
0157
0158 for (const auto& node : coll) {
0159 int binIndex = pL->getEtaBin(node.z(), node.r());
0160
0161 if (binIndex == -1) {
0162 continue;
0163 }
0164
0165 m_etaBins.at(binIndex).m_vn.push_back(&node);
0166 nLoaded++;
0167 }
0168
0169 return nLoaded;
0170 }
0171
0172 unsigned int GbtsDataStorage::numberOfNodes() const {
0173 unsigned int n = 0;
0174
0175 for (const auto& b : m_etaBins) {
0176 n += b.m_vn.size();
0177 }
0178 return n;
0179 }
0180
0181 void GbtsDataStorage::sortByPhi() {
0182 for (auto& b : m_etaBins) {
0183 b.sortByPhi();
0184 }
0185 }
0186
0187 void GbtsDataStorage::initializeNodes(bool useML) {
0188 for (auto& b : m_etaBins) {
0189 b.initializeNodes();
0190 }
0191
0192 if (!useML) {
0193 return;
0194 }
0195
0196 unsigned int nL = m_geo.num_layers();
0197
0198 for (unsigned int layerIdx = 0; layerIdx < nL; layerIdx++) {
0199 const GbtsLayer* pL = m_geo.getGbtsLayerByIndex(layerIdx);
0200
0201 if (pL->m_layer.m_subdet <
0202 20000) {
0203 continue;
0204 }
0205
0206 bool isBarrel = (pL->m_layer.m_type == 0);
0207
0208 if (!isBarrel) {
0209 continue;
0210 }
0211
0212 int nBins = pL->m_bins.size();
0213
0214 for (int b = 0; b < nBins; b++) {
0215
0216 GbtsEtaBin& B = m_etaBins.at(pL->m_bins.at(b));
0217
0218 if (B.empty()) {
0219 continue;
0220 }
0221
0222 for (unsigned int nIdx = 0; nIdx < B.m_vn.size(); nIdx++) {
0223 float cluster_width = B.m_vn[nIdx]->pixelClusterWidth();
0224
0225
0226 float min_tau = 6.7 * (cluster_width - 0.2);
0227 float max_tau =
0228 1.6 + 0.15 / (cluster_width + 0.2) +
0229 6.1 * (cluster_width -
0230 0.2);
0231
0232 B.m_params[nIdx][0] = min_tau;
0233 B.m_params[nIdx][1] = max_tau;
0234 }
0235 }
0236 }
0237 }
0238
0239 void GbtsDataStorage::generatePhiIndexing(float dphi) {
0240 for (auto& b : m_etaBins) {
0241 b.generatePhiIndexing(dphi);
0242 }
0243 }
0244
0245 }