249 throw std::runtime_error(
"ITkPixel manager not available");
256 std::vector<std::shared_ptr<ActsDetectorElement>> elements;
259 for (
const auto* element :
263 if (siDetElement ==
nullptr) {
265 throw std::runtime_error{
"Corrupt detector element collection"};
267 elements.push_back(std::make_shared<ActsDetectorElement>(*siDetElement));
273 elements.begin(), elements.end());
276 node.addMaterial(
"InnerPixelMaterial", [&](
auto&
mat) {
277 mat.configureFace(OuterCylinder, {AxisRPhi, Bound, 20}, {AxisZ, Bound, 20});
279 auto& innerPixelContainer =
mat.addCylinderContainer(
"InnerPixel", AxisZ);
282 auto& barrelGeoId = innerPixelContainer.withGeometryIdentifier();
283 barrelGeoId.setAllVolumeIdsTo(s_innerPixelVolumeId)
284 .incrementLayerIds(1)
285 .sortBy([](
auto&
a,
auto&
b) {
287 dynamic_cast<const Acts::CylinderVolumeBounds&
>(
a.volumeBounds());
289 dynamic_cast<const Acts::CylinderVolumeBounds&
>(
b.volumeBounds());
291 using enum Acts::CylinderVolumeBounds::BoundValues;
292 double aMidR = (boundsA.get(eMinR) + boundsA.get(eMaxR)) / 2.0;
293 double bMidR = (boundsB.get(eMinR) + boundsB.get(eMaxR)) / 2.0;
295 return aMidR < bMidR;
298 auto&
barrel = barrelGeoId.addCylinderContainer(
"InnerPixel_Brl", AxisR);
299 barrel.setAttachmentStrategy(AttachmentStrategy::Gap);
300 barrel.setResizeStrategy(ResizeStrategy::Gap);
302 std::map<int, std::vector<std::shared_ptr<Acts::Surface>>>
layers{};
304 for (
auto& element : elements) {
310 if (
id.layer_disk() >= 2) {
315 layers[elementLayer].push_back(element->surface().getSharedPtr());
320 for (
const auto& [ilayer, surfaces] :
layers) {
321 ATH_MSG_DEBUG(
"- Layer " << ilayer <<
" has " << surfaces.size()
325 std::format(
"InnerPixel_Brl_{}_Material", ilayer), [&](
auto& lmat) {
327 lmat.configureFace(OuterCylinder, {AxisRPhi, Bound, 40},
332 lmat.addLayer(
std::format(
"InnerPixel_Brl_{}", ilayer));
335 layer.setNavigationPolicyFactory(
336 Acts::NavigationPolicyFactory{}
337 .add<Acts::SurfaceArrayNavigationPolicy>(
338 Acts::SurfaceArrayNavigationPolicy::Config{
341 .add<Acts::TryAllNavigationPolicy>(
342 Acts::TryAllNavigationPolicy::Config{.sensitives =
346 layer.setSurfaces(surfaces);
347 layer.setEnvelope(Acts::ExtentEnvelope{{
355 for (
int bec : {-2, 2}) {
356 std::string
s =
bec > 0 ?
"p" :
"n";
357 auto& ecGeoId = innerPixelContainer.withGeometryIdentifier();
358 ecGeoId.setAllVolumeIdsTo(s_innerPixelVolumeId + std::floor(
bec / 2))
359 .incrementLayerIds(1);
360 auto& ec = ecGeoId.addCylinderContainer(
"InnerPixel_" +
s +
"EC", AxisZ);
361 ec.setAttachmentStrategy(AttachmentStrategy::Gap);
362 ec.setResizeStrategy(ResizeStrategy::Expand);
364 std::map<std::tuple<int, int, int>,
365 std::vector<std::shared_ptr<Acts::Surface>>>
368 for (
auto& element : elements) {
370 if (
id.
bec() *
bec <= 0) {
374 if (
id.layer_disk() >= 3) {
378 std::tuple<int, int, int>
key{
id.bec(),
id.layer_disk(),
380 initialLayers[
key].push_back(element->surface().getSharedPtr());
384 <<
" initial layers to InnerPixel " <<
s <<
"EC");
387 std::vector<LayerData> protoLayers;
388 protoLayers.reserve(initialLayers.size());
390 for (
const auto& [
key, surfaces] : initialLayers) {
391 auto&
layer = protoLayers.emplace_back(gctx, surfaces);
392 layer.protoLayer.envelope[AxisR] = {2_mm, 2_mm};
393 layer.protoLayer.envelope[AxisZ] = {1_mm, 1_mm};
397 std::ranges::sort(protoLayers,
398 [](
const LayerData&
a,
const LayerData&
b) {
399 return std::abs(
a.protoLayer.medium(AxisZ)) <
400 std::abs(
b.protoLayer.medium(AxisZ));
403 ATH_MSG_DEBUG(
"Found " << protoLayers.size() <<
" initial layers");
406 std::vector<LayerData> mergedLayers;
408 mergedLayers = mergeLayers(gctx, std::move(protoLayers));
410 mergedLayers = std::move(protoLayers);
413 ATH_MSG_DEBUG(
"After merging: " << mergedLayers.size() <<
" layers");
416 for (
const auto [
key, pl] : Acts::enumerate(mergedLayers)) {
420 pl.protoLayer.medium(AxisZ);
428 layer.setNavigationPolicyFactory(
429 Acts::NavigationPolicyFactory{}
430 .add<Acts::SurfaceArrayNavigationPolicy>(
431 Acts::SurfaceArrayNavigationPolicy::Config{
434 .add<Acts::TryAllNavigationPolicy>(
435 Acts::TryAllNavigationPolicy::Config{.sensitives =
false})
438 layer.setSurfaces(pl.surfaces);
439 layer.setEnvelope(Acts::ExtentEnvelope{{
446 <<
key <<
" / " << mergedLayers.size()
447 <<
" at z = " << pl.protoLayer.medium(AxisZ));
448 if (
key < mergedLayers.size() - 1) {
451 ec.addMaterial(layerName +
"_Material", [&](
auto& lmat) {
453 lmat.configureFace(
bec < 0 ? NegativeDisc : PositiveDisc,
454 {AxisR, Bound, 40}, {AxisPhi, Bound, 40});
465 node.addMaterial(
"OuterPixelMaterial", [&](
auto&
mat) {
466 mat.configureFace(OuterCylinder, {AxisRPhi, Bound, 20}, {AxisZ, Bound, 20});
468 auto& outerPixelContainer =
mat.addCylinderContainer(
"OuterPixel", AxisZ);
471 auto& barrelGeoId = outerPixelContainer.withGeometryIdentifier();
472 barrelGeoId.setAllVolumeIdsTo(s_outerPixelVolumeId).incrementLayerIds(1);
474 auto&
barrel = barrelGeoId.addCylinderContainer(
"OuterPixel_Brl", AxisR);
475 barrel.setAttachmentStrategy(AttachmentStrategy::Gap);
476 barrel.setResizeStrategy(ResizeStrategy::Gap);
478 std::map<int, std::vector<std::shared_ptr<Acts::Surface>>>
layers{};
480 for (
auto& element : elements) {
486 if (
id.layer_disk() <= 1) {
491 layers[elementLayer].push_back(element->surface().getSharedPtr());
496 for (
const auto& [ilayer, surfaces] :
layers) {
497 ATH_MSG_DEBUG(
"- Layer " << ilayer <<
" has " << surfaces.size()
501 std::format(
"OuterPixel_Brl_{}_Material", ilayer), [&](
auto& lmat) {
503 lmat.configureFace(OuterCylinder, {AxisRPhi, Bound, 40},
511 layer.setNavigationPolicyFactory(
512 Acts::NavigationPolicyFactory{}
513 .add<Acts::SurfaceArrayNavigationPolicy>(
514 Acts::SurfaceArrayNavigationPolicy::Config{
517 .add<Acts::TryAllNavigationPolicy>(
518 Acts::TryAllNavigationPolicy::Config{.sensitives =
522 layer.setSurfaces(surfaces);
523 layer.setEnvelope(Acts::ExtentEnvelope{{
530 constexpr
static auto addEndcapLayer = [](
auto&
parent,
const auto&
name,
531 const auto& surfaces) {
533 layer.setNavigationPolicyFactory(
534 Acts::NavigationPolicyFactory{}
535 .add<Acts::SurfaceArrayNavigationPolicy>(
536 Acts::SurfaceArrayNavigationPolicy::Config{
537 .layerType =
Disc, .bins = {30, 30}})
538 .add<Acts::TryAllNavigationPolicy>(
539 Acts::TryAllNavigationPolicy::Config{.sensitives =
false})
542 layer.setSurfaces(surfaces);
547 for (
int bec : {-2, 2}) {
548 const std::string
s =
bec > 0 ?
"p" :
"n";
552 auto& ec_outer_geoId = outerPixelContainer.withGeometryIdentifier();
554 .setAllVolumeIdsTo(s_outerPixelVolumeId + std::floor(
bec / 2))
555 .incrementLayerIds(1);
558 ec_outer_geoId.addCylinderContainer(
"OuterPixel_" +
s +
"EC", AxisR);
561 std::array diskGroups{std::pair{3, 4}, std::pair{6, 5}, std::pair{7, 8}};
563 for (
size_t idx = 0;
idx < diskGroups.size(); ++
idx) {
564 auto [disk1, disk2] = diskGroups[
idx];
566 auto& ec_stack = ec_outer.addCylinderContainer(
569 ec_stack.setAttachmentStrategy(AttachmentStrategy::Gap);
570 ec_stack.setResizeStrategy(ResizeStrategy::Expand);
573 std::map<std::tuple<int, int>,
574 std::vector<std::shared_ptr<Acts::Surface>>>
577 for (
auto& element : elements) {
580 (
id.layer_disk() != disk1 &&
id.layer_disk() != disk2)) {
583 std::tuple<int, int>
key{
id.layer_disk(),
id.eta_module()};
584 eta_rings[
key].push_back(element->surface().getSharedPtr());
587 ATH_MSG_DEBUG(
"Found " << eta_rings.size() <<
" eta rings in group "
591 std::vector<std::vector<std::shared_ptr<Acts::Surface>>> sorted_rings;
592 sorted_rings.reserve(eta_rings.size());
593 for (
const auto& [
key, surfaces] : eta_rings) {
594 sorted_rings.push_back(surfaces);
597 std::ranges::sort(sorted_rings, [&gctx](
const auto&
a,
const auto&
b) {
598 Acts::ProtoLayer pl_a(gctx, makeConstPtrVector(
a));
599 Acts::ProtoLayer pl_b(gctx, makeConstPtrVector(
b));
600 return std::abs(pl_a.min(AxisZ)) < std::abs(pl_b.min(AxisZ));
604 for (
size_t i = 0;
i < sorted_rings.size(); ++
i) {
605 const auto& surfaces = sorted_rings[
i];
609 if (
i < sorted_rings.size() - 1) {
610 ec_stack.addMaterial(layerName +
"_Material", [&](
auto&
mat) {
611 mat.configureFace(
bec > 0 ? PositiveDisc : NegativeDisc,
612 {AxisR, Bound, 20}, {AxisPhi, Bound, 40});
613 addEndcapLayer(
mat, layerName, surfaces);
616 addEndcapLayer(ec_stack, layerName, surfaces);