51 std::map<LayerKey, std::vector<ModuleEntry>> hashMap;
56 for (
int hash = 0; hash < static_cast<int>(
m_pixelId->wafer_hash_max());
63 const short barrelEc =
m_pixelId->barrel_ec(offlineId);
64 if (std::abs(barrelEc) > 2) {
68 const short phiIndex =
m_pixelId->phi_module(offlineId);
69 const short etaIndex =
m_pixelId->eta_module(offlineId);
70 const int layerDisk =
m_pixelId->layer_disk(offlineId);
71 const int etaModule =
m_pixelId->eta_module(offlineId);
76 }
else if (barrelEc == -2) {
78 }
else if (barrelEc == 2) {
84 if (volId == 7 || volId == 9) {
85 newVol = 10 * volId + layerDisk;
87 }
else if (volId == 8) {
88 newVol = 10 * volId + layerDisk;
92 const LayerKey key{barrelEc == 0 ? kBarrelSideKey : barrelEc, kPixel,
93 static_cast<short>(newVol),
static_cast<short>(newLay)};
94 hashMap[key].push_back(
ModuleEntry{phiIndex, etaIndex, hash});
98 for (
int hash = 0; hash < static_cast<int>(
m_stripId->wafer_hash_max());
101 if (offlineId == 0) {
105 const short barrelEc =
m_stripId->barrel_ec(offlineId);
106 const short phiIndex =
m_stripId->phi_module(offlineId);
107 const short etaIndex =
m_stripId->eta_module(offlineId);
117 const int layerDisk =
m_stripId->layer_disk(offlineId);
119 const LayerKey key{barrelEc == 0 ? kBarrelSideKey : barrelEc, kStrip,
120 static_cast<short>(volId),
121 static_cast<short>(layerDisk)};
122 hashMap[key].push_back(
ModuleEntry{phiIndex, etaIndex, hash});
130 std::ofstream geometryStream;
141 std::set<Acts::Experimental::GbtsExperimentLayerId> layerIds;
143 short layerIndex = 0;
144 for (
const auto& [key, modules] : hashMap) {
145 const auto& [sideKey, technology, volId, layId] = key;
147 const short barrelEc = sideKey == kBarrelSideKey ? 0 : sideKey;
148 const auto combinedId =
149 static_cast<Acts::Experimental::GbtsExperimentLayerId
>(volId) * 1000 +
150 static_cast<Acts::Experimental::GbtsExperimentLayerId
>(layId);
152 if (!layerIds.insert(combinedId).second) {
154 << combinedId <<
": this detector does not fit the layer "
156 return StatusCode::FAILURE;
159 float refCoordSum = 0.f;
161 double minZ = 100000.0;
162 double maxZ = -100000.0;
163 double minR = 100000.0;
164 double maxR = -100000.0;
168 if (technology == kPixel) {
175 if (element ==
nullptr) [[
unlikely]] {
180 minZ = std::min(minZ, element->
zMin());
181 maxZ = std::max(maxZ, element->
zMax());
182 minR = std::min(minR, element->
rMin());
183 maxR = std::max(maxR, element->
rMax());
188 refCoordSum += barrelEc == 0
189 ? std::hypot(centre(0), centre(1))
195 ATH_MSG_ERROR(
"GBTS layer " << combinedId <<
" has no modules.");
196 return StatusCode::FAILURE;
199 Acts::Experimental::GbtsLayerDescription& layer =
201 layer.id = combinedId;
202 layer.type = barrelEc == 0 ? Acts::Experimental::GbtsLayerType::Barrel
203 : Acts::Experimental::GbtsLayerType::Endcap;
204 layer.technology = technology == kPixel
205 ? Acts::Experimental::GbtsLayerTechnology::Pixel
206 : Acts::Experimental::GbtsLayerTechnology::Strip;
207 layer.refCoord = refCoordSum / nModules;
208 layer.layerThickness = barrelEc == 0 ? maxR-minR : maxZ-minZ;
210 layer.minBound = barrelEc == 0 ? minZ : minR;
211 layer.maxBound = barrelEc == 0 ? maxZ : maxR;
214 geometryStream << minR <<
" " << maxR <<
" " << minZ <<
" " << maxZ <<
" "
215 << combinedId <<
"\n";
219 <<
") : reference coordinate = " << layer.refCoord
220 <<
" boundaries: " << layer.minBound <<
" "
221 << layer.maxBound <<
" type=" << barrelEc
223 << (technology == kPixel ?
"pixel" :
"strip"));
228 return StatusCode::SUCCESS;
232 const std::vector<Acts::Experimental::GbtsLayerDescription>& layers,
233 std::vector<Acts::Experimental::GbtsLayerConnection>& connections,
234 float& etaBinWidth, std::string connectorInputFile,
bool usePixel,
bool useStrip)
const
236 std::ifstream connectionStream(connectorInputFile);
237 if (!connectionStream.is_open()) {
239 << connectorInputFile);
240 return StatusCode::FAILURE;
245 table =
read(connectionStream);
246 }
catch (
const std::exception& e) {
249 return StatusCode::FAILURE;
253 std::unordered_map<Acts::Experimental::GbtsExperimentLayerId,
254 Acts::Experimental::GbtsLayerTechnology>
256 layerTechnologies.reserve(layers.size());
257 for (
const Acts::Experimental::GbtsLayerDescription& layer : layers) {
258 layerTechnologies.emplace(layer.id, layer.technology);
261 etaBinWidth = table.etaBinWidth;
264 std::vector<std::pair<std::uint32_t, Acts::Experimental::GbtsLayerConnection>> staged;
265 staged.reserve(table.connections.size());
267 std::size_t nOtherTechnology = 0;
268 std::size_t nUnknownLayer = 0;
272 const auto src = layerTechnologies.find(connection.
src);
273 const auto dst = layerTechnologies.find(connection.
dst);
274 if (src == layerTechnologies.end() || dst == layerTechnologies.end()) {
279 const bool wanted = src->second == dst->second &&
280 (src->second == Acts::Experimental::GbtsLayerTechnology::Pixel
281 ? usePixel : useStrip);
288 staged.emplace_back(connection.
stage,
289 Acts::Experimental::GbtsLayerConnection{connection.src,
293 std::ranges::stable_sort(staged, {}, [](
const auto& entry) {
return entry.first; });
296 connections.reserve(staged.size());
297 for (
const auto& entry : staged) {
298 connections.push_back(entry.second);
300 const std::size_t nKept = connections.size();
302 if (nUnknownLayer != 0) {
304 << connectorInputFile <<
" name no GBTS layer "
309 << connectorInputFile <<
" are usable: the table "
310 "does not match the detector this job is reconstructing");
311 return StatusCode::FAILURE;
313 ATH_MSG_DEBUG(
"Kept " << nKept <<
" GBTS layer connections, dropping "
314 << nOtherTechnology <<
" of a technology not asked for, eta bin width "
317 return StatusCode::SUCCESS;
321 std::istream& inputStream)
const {
324 std::uint32_t nConnections{};
325 std::uint32_t iConnection{};
327 const auto fail = [&nConnections, &iConnection](
const std::string& what) {
328 throw std::runtime_error(
"GBTS connection table: cannot read " + what +
329 " at connection " + std::to_string(iConnection) +
330 " of " + std::to_string(nConnections));
333 if (!(inputStream >> nConnections >> result.etaBinWidth)) {
334 throw std::runtime_error(
335 "GBTS connection table: cannot read the connection count and the eta "
339 for (; iConnection < nConnections; ++iConnection) {
340 std::uint32_t
index{};
341 std::uint32_t height{};
342 std::uint32_t
width{};
343 std::uint32_t nEntries{};
346 if (!(inputStream >>
index >> connection.
stage >> connection.
src >>
347 connection.
dst >> height >>
width >> nEntries)) {
352 const std::uint64_t nBins = std::uint64_t{height} *
width;
353 for (std::uint64_t
bin = 0;
bin < nBins; ++
bin) {
355 if (!(inputStream >>
unused)) {
356 fail(
"the bin table");
360 result.connections.push_back(connection);