251 throw std::runtime_error(
"ITkPixel manager not available");
258 std::vector<std::shared_ptr<ActsDetectorElement>> elements;
261 for (
const auto* element :
265 if (siDetElement ==
nullptr) {
267 throw std::runtime_error{
"Corrupt detector element collection"};
269 elements.push_back(std::make_shared<ActsDetectorElement>(*siDetElement));
275 elements.begin(), elements.end());
278 node.addMaterial(
"InnerPixelMaterial", [&](
auto&
mat) {
279 mat.configureFace(OuterCylinder, {AxisRPhi, Bound, 20}, {AxisZ, Bound, 20});
281 auto& innerPixelContainer =
mat.addCylinderContainer(
"InnerPixel", AxisZ);
284 auto& barrelGeoId = innerPixelContainer.withGeometryIdentifier();
285 barrelGeoId.setAllVolumeIdsTo(s_innerPixelVolumeId)
286 .incrementLayerIds(1)
287 .sortBy([](
auto&
a,
auto&
b) {
289 dynamic_cast<const Acts::CylinderVolumeBounds&
>(
a.volumeBounds());
291 dynamic_cast<const Acts::CylinderVolumeBounds&
>(
b.volumeBounds());
293 using enum Acts::CylinderVolumeBounds::BoundValues;
294 double aMidR = (boundsA.get(eMinR) + boundsA.get(eMaxR)) / 2.0;
295 double bMidR = (boundsB.get(eMinR) + boundsB.get(eMaxR)) / 2.0;
297 return aMidR < bMidR;
300 auto&
barrel = barrelGeoId.addCylinderContainer(
"InnerPixel_Brl", AxisR);
301 barrel.setAttachmentStrategy(AttachmentStrategy::Gap);
302 barrel.setResizeStrategy(ResizeStrategy::Gap);
304 std::map<int, std::vector<std::shared_ptr<Acts::Surface>>>
layers{};
306 for (
auto& element : elements) {
312 if (
id.layer_disk() >= 2) {
317 layers[elementLayer].push_back(element->surface().getSharedPtr());
322 for (
const auto& [ilayer, surfaces] :
layers) {
323 ATH_MSG_DEBUG(
"- Layer " << ilayer <<
" has " << surfaces.size()
327 std::format(
"InnerPixel_Brl_{}_Material", ilayer), [&](
auto& lmat) {
329 lmat.configureFace(OuterCylinder, {AxisRPhi, Bound, 40},
334 lmat.addLayer(
std::format(
"InnerPixel_Brl_{}", ilayer));
337 layer.setNavigationPolicyFactory(
338 Acts::NavigationPolicyFactory{}
339 .add<Acts::SurfaceArrayNavigationPolicy>(
340 Acts::SurfaceArrayNavigationPolicy::Config{
343 .add<Acts::TryAllNavigationPolicy>(
344 Acts::TryAllNavigationPolicy::Config{.sensitives =
348 layer.setSurfaces(surfaces);
349 layer.setEnvelope(Acts::ExtentEnvelope{{
357 for (
int bec : {-2, 2}) {
358 std::string
s =
bec > 0 ?
"p" :
"n";
359 auto& ecGeoId = innerPixelContainer.withGeometryIdentifier();
360 ecGeoId.setAllVolumeIdsTo(s_innerPixelVolumeId + std::floor(
bec / 2))
361 .incrementLayerIds(1);
362 auto& ec = ecGeoId.addCylinderContainer(
"InnerPixel_" +
s +
"EC", AxisZ);
363 ec.setAttachmentStrategy(AttachmentStrategy::Gap);
364 ec.setResizeStrategy(ResizeStrategy::Expand);
366 std::map<std::tuple<int, int, int>,
367 std::vector<std::shared_ptr<Acts::Surface>>>
370 for (
auto& element : elements) {
372 if (
id.
bec() *
bec <= 0) {
376 if (
id.layer_disk() >= 3) {
380 std::tuple<int, int, int>
key{
id.bec(),
id.layer_disk(),
382 initialLayers[
key].push_back(element->surface().getSharedPtr());
386 <<
" initial layers to InnerPixel " <<
s <<
"EC");
389 std::vector<LayerData> protoLayers;
390 protoLayers.reserve(initialLayers.size());
392 for (
const auto& [
key, surfaces] : initialLayers) {
393 auto&
layer = protoLayers.emplace_back(gctx, surfaces);
394 layer.protoLayer.envelope[AxisR] = {2_mm, 2_mm};
395 layer.protoLayer.envelope[AxisZ] = {1_mm, 1_mm};
399 std::ranges::sort(protoLayers,
400 [](
const LayerData&
a,
const LayerData&
b) {
401 return std::abs(
a.protoLayer.medium(AxisZ)) <
402 std::abs(
b.protoLayer.medium(AxisZ));
405 ATH_MSG_DEBUG(
"Found " << protoLayers.size() <<
" initial layers");
408 std::vector<LayerData> mergedLayers;
410 mergedLayers = mergeLayers(gctx, std::move(protoLayers));
412 mergedLayers = std::move(protoLayers);
415 ATH_MSG_DEBUG(
"After merging: " << mergedLayers.size() <<
" layers");
418 for (
const auto [
key, pl] : Acts::enumerate(mergedLayers)) {
422 pl.protoLayer.medium(AxisZ);
430 layer.setNavigationPolicyFactory(
431 Acts::NavigationPolicyFactory{}
432 .add<Acts::SurfaceArrayNavigationPolicy>(
433 Acts::SurfaceArrayNavigationPolicy::Config{
436 .add<Acts::TryAllNavigationPolicy>(
437 Acts::TryAllNavigationPolicy::Config{.sensitives =
false})
440 layer.setSurfaces(pl.surfaces);
441 layer.setEnvelope(Acts::ExtentEnvelope{{
448 <<
key <<
" / " << mergedLayers.size()
449 <<
" at z = " << pl.protoLayer.medium(AxisZ));
450 if (
key < mergedLayers.size() - 1) {
453 ec.addMaterial(layerName +
"_Material", [&](
auto& lmat) {
455 lmat.configureFace(
bec < 0 ? NegativeDisc : PositiveDisc,
456 {AxisR, Bound, 40}, {AxisPhi, Bound, 40});
467 node.addMaterial(
"OuterPixelMaterial", [&](
auto&
mat) {
468 mat.configureFace(OuterCylinder, {AxisRPhi, Bound, 20}, {AxisZ, Bound, 20});
470 auto& outerPixelContainer =
mat.addCylinderContainer(
"OuterPixel", AxisZ);
473 auto& barrelGeoId = outerPixelContainer.withGeometryIdentifier();
474 barrelGeoId.setAllVolumeIdsTo(s_outerPixelVolumeId).incrementLayerIds(1);
476 auto&
barrel = barrelGeoId.addCylinderContainer(
"OuterPixel_Brl", AxisR);
477 barrel.setAttachmentStrategy(AttachmentStrategy::Gap);
478 barrel.setResizeStrategy(ResizeStrategy::Gap);
480 std::map<int, std::vector<std::shared_ptr<Acts::Surface>>>
layers{};
482 for (
auto& element : elements) {
488 if (
id.layer_disk() <= 1) {
493 layers[elementLayer].push_back(element->surface().getSharedPtr());
498 for (
const auto& [ilayer, surfaces] :
layers) {
499 ATH_MSG_DEBUG(
"- Layer " << ilayer <<
" has " << surfaces.size()
503 std::format(
"OuterPixel_Brl_{}_Material", ilayer), [&](
auto& lmat) {
505 lmat.configureFace(OuterCylinder, {AxisRPhi, Bound, 40},
513 layer.setNavigationPolicyFactory(
514 Acts::NavigationPolicyFactory{}
515 .add<Acts::SurfaceArrayNavigationPolicy>(
516 Acts::SurfaceArrayNavigationPolicy::Config{
519 .add<Acts::TryAllNavigationPolicy>(
520 Acts::TryAllNavigationPolicy::Config{.sensitives =
524 layer.setSurfaces(surfaces);
525 layer.setEnvelope(Acts::ExtentEnvelope{{
532 constexpr
static auto addEndcapLayer = [](
auto&
parent,
const auto&
name,
533 const auto& surfaces) {
535 layer.setNavigationPolicyFactory(
536 Acts::NavigationPolicyFactory{}
537 .add<Acts::SurfaceArrayNavigationPolicy>(
538 Acts::SurfaceArrayNavigationPolicy::Config{
539 .layerType =
Disc, .bins = {30, 30}})
540 .add<Acts::TryAllNavigationPolicy>(
541 Acts::TryAllNavigationPolicy::Config{.sensitives =
false})
544 layer.setSurfaces(surfaces);
549 for (
int bec : {-2, 2}) {
550 const std::string
s =
bec > 0 ?
"p" :
"n";
554 auto& ec_outer_geoId = outerPixelContainer.withGeometryIdentifier();
556 .setAllVolumeIdsTo(s_outerPixelVolumeId + std::floor(
bec / 2))
557 .incrementLayerIds(1);
560 ec_outer_geoId.addCylinderContainer(
"OuterPixel_" +
s +
"EC", AxisR);
563 std::array diskGroups{std::pair{3, 4}, std::pair{6, 5}, std::pair{7, 8}};
565 for (
size_t idx = 0;
idx < diskGroups.size(); ++
idx) {
566 auto [disk1, disk2] = diskGroups[
idx];
568 auto& ec_stack = ec_outer.addCylinderContainer(
571 ec_stack.setAttachmentStrategy(AttachmentStrategy::Gap);
572 ec_stack.setResizeStrategy(ResizeStrategy::Expand);
575 std::map<std::tuple<int, int>,
576 std::vector<std::shared_ptr<Acts::Surface>>>
579 for (
auto& element : elements) {
582 (
id.layer_disk() != disk1 &&
id.layer_disk() != disk2)) {
585 std::tuple<int, int>
key{
id.layer_disk(),
id.eta_module()};
586 eta_rings[
key].push_back(element->surface().getSharedPtr());
589 ATH_MSG_DEBUG(
"Found " << eta_rings.size() <<
" eta rings in group "
593 std::vector<std::vector<std::shared_ptr<Acts::Surface>>> sorted_rings;
594 sorted_rings.reserve(eta_rings.size());
595 for (
const auto& [
key, surfaces] : eta_rings) {
596 sorted_rings.push_back(surfaces);
599 std::ranges::sort(sorted_rings, [&gctx](
const auto&
a,
const auto&
b) {
600 Acts::ProtoLayer pl_a(gctx, makeConstPtrVector(
a));
601 Acts::ProtoLayer pl_b(gctx, makeConstPtrVector(
b));
602 return std::abs(pl_a.min(AxisZ)) < std::abs(pl_b.min(AxisZ));
606 for (
size_t i = 0;
i < sorted_rings.size(); ++
i) {
607 const auto& surfaces = sorted_rings[
i];
611 if (
i < sorted_rings.size() - 1) {
612 ec_stack.addMaterial(layerName +
"_Material", [&](
auto&
mat) {
613 mat.configureFace(
bec > 0 ? PositiveDisc : NegativeDisc,
614 {AxisR, Bound, 20}, {AxisPhi, Bound, 40});
615 addEndcapLayer(
mat, layerName, surfaces);
618 addEndcapLayer(ec_stack, layerName, surfaces);