14 #include "Acts/Definitions/Algebra.hpp"
15 #include "Acts/Definitions/Units.hpp"
16 #include "Acts/Geometry/ApproachDescriptor.hpp"
17 #include "Acts/Geometry/GenericApproachDescriptor.hpp"
18 #include "Acts/Geometry/GeometryContext.hpp"
19 #include "Acts/Geometry/LayerCreator.hpp"
20 #include "Acts/Geometry/ProtoLayer.hpp"
21 #include "Acts/Material/ProtoSurfaceMaterial.hpp"
22 #include "Acts/Surfaces/CylinderSurface.hpp"
23 #include "Acts/Surfaces/DiscSurface.hpp"
24 #include "Acts/Utilities/BinningType.hpp"
25 #include "Acts/Surfaces/AnnulusBounds.hpp"
27 #include "Acts/Visualization/GeometryView3D.hpp"
28 #include "Acts/Visualization/ObjVisualization3D.hpp"
31 #include <unordered_map>
35 using Acts::Transform3;
36 using Acts::Translation3;
38 using namespace Acts::UnitLiterals;
41 std::unique_ptr<const Acts::Logger>
logger)
43 m_logger(std::move(
logger))
46 throw std::invalid_argument(
"ALB mode is undefined");
50 const Acts::LayerVector
52 ACTS_VERBOSE(
"Building negative layers");
53 Acts::LayerVector nVector;
58 const Acts::LayerVector
60 ACTS_VERBOSE(
"Building central layers");
61 Acts::LayerVector cVector;
66 const Acts::LayerVector
68 ACTS_VERBOSE(
"Building positive layers");
69 Acts::LayerVector pVector;
74 std::vector<std::shared_ptr<const ActsDetectorElement>>
76 ACTS_VERBOSE(
"Retrieving detector elements from detector manager");
78 ACTS_ERROR(
"Manager is null");
79 throw std::runtime_error{
"Detector manager is null"};
82 ACTS_VERBOSE(
"Detector manager has "
84 siDetMng->getDetectorElementEnd())
87 std::vector<std::shared_ptr<const ActsDetectorElement>> elements;
89 InDetDD::SiDetectorElementCollection::const_iterator iter;
90 for (iter = siDetMng->getDetectorElementBegin();
91 iter != siDetMng->getDetectorElementEnd(); ++iter) {
94 if (siDetElement ==
nullptr) {
95 ACTS_ERROR(
"Detector element was nullptr");
96 throw std::runtime_error{
"Corrupt detector element collection"};
99 std::make_shared<const ActsDetectorElement>(*siDetElement));
101 ACTS_VERBOSE(
"Retrieved " << elements.size() <<
" elements");
107 Acts::LayerVector &layersOutput)
const {
109 ACTS_VERBOSE(
"Build layers: BARREL");
110 std::vector<std::shared_ptr<const ActsDetectorElement>> elements =
113 std::map<int, std::vector<std::shared_ptr<const Acts::Surface>>>
layers{};
115 for (
const auto &element : elements) {
122 if(
id.layer_disk() >= 2)
continue;
125 if(
id.layer_disk() <= 1)
continue;
131 elementLayer =
id.layer_disk();
133 layers[elementLayer].push_back(element->surface().getSharedPtr());
139 for (
auto &[
key, layerSurfaces] :
layers) {
141 std::stringstream
name;
145 name <<
"obj/" <<
m_cfg.
mode <<
"_brl_" << std::setfill(
'0') << std::setw(2)
149 std::ofstream ofs{
name.str()};
150 Acts::ObjVisualization3D vis{};
151 Acts::ViewConfig vc = Acts::s_viewSensitive;
152 vc.quarterSegments = 200;
153 for (
const auto &surface : layerSurfaces) {
154 Acts::GeometryView3D::drawSurface(vis, *surface, gctx,
155 Acts::Transform3::Identity(), vc);
162 ACTS_VERBOSE(
"Found " <<
layers.size() <<
" barrel layers");
166 for (
const auto &[
key, surfaces] :
layers) {
167 Acts::ProtoLayer pl(gctx, surfaces);
168 ACTS_VERBOSE(
"Layer #" <<
n <<
" with layerKey: (" <<
key <<
")");
178 for (
const auto &[
key, surfaces] :
layers) {
180 std::unique_ptr<Acts::ApproachDescriptor> approachDescriptor =
nullptr;
181 std::shared_ptr<const Acts::ProtoSurfaceMaterial> materialProxy =
nullptr;
184 Acts::ProtoLayer pl(gctx, surfaces);
191 Acts::Transform3
transform(Translation3(0., 0., -layerZ));
194 std::shared_ptr<Acts::CylinderSurface> innerBoundary =
195 Acts::Surface::makeShared<Acts::CylinderSurface>(
198 std::shared_ptr<Acts::CylinderSurface> outerBoundary =
199 Acts::Surface::makeShared<Acts::CylinderSurface>(
202 std::shared_ptr<Acts::CylinderSurface> centralSurface =
203 Acts::Surface::makeShared<Acts::CylinderSurface>(
212 materialBinUtil += Acts::BinUtility(
binsZ, -layerHalfZ, layerHalfZ,
216 std::make_shared<const Acts::ProtoSurfaceMaterial>(materialBinUtil);
218 ACTS_VERBOSE(
"[L] Layer is marked to carry support material on Surface ( "
219 "inner=0 / center=1 / outer=2 ) : "
221 ACTS_VERBOSE(
"with binning: [" << binsPhi <<
", " <<
binsZ <<
"]");
223 ACTS_VERBOSE(
"Created ApproachSurfaces for cylinder layer at:");
230 innerBoundary->assignSurfaceMaterial(materialProxy);
232 std::vector<std::shared_ptr<const Acts::Surface>> aSurfaces;
233 aSurfaces.push_back(std::move(innerBoundary));
234 aSurfaces.push_back(std::move(centralSurface));
235 aSurfaces.push_back(std::move(outerBoundary));
238 std::make_unique<Acts::GenericApproachDescriptor>(std::move(aSurfaces));
241 auto phiEqual = [
this](
const Acts::Surface &
a,
242 const Acts::Surface &
b) {
243 Acts::GeometryContext gctx;
248 auto zEqual = [
this](
const Acts::Surface &
a,
249 const Acts::Surface &
b) {
250 Acts::GeometryContext gctx;
257 auto& xsurfaces = surfaces;
258 auto countKey = [&xsurfaces](
auto equal) ->
size_t {
259 std::vector<const Acts::Surface *> keySurfaces;
260 for (
const auto &surface : xsurfaces) {
262 for (
const auto* existing : keySurfaces) {
263 if (
equal(*surface, *existing)) {
269 keySurfaces.push_back(surface.get());
272 return keySurfaces.size();
275 size_t nModPhi = countKey(phiEqual);
276 size_t nModZ = countKey(zEqual);
278 ACTS_VERBOSE(
"Found " << nModPhi <<
" modules in phi " << nModZ
281 std::shared_ptr<Acts::Layer>
layer;
289 size_t nBinsPhi = nModPhi /
f;
290 size_t nBinsZ = nModZ /
f;
293 std::move(approachDescriptor));
300 size_t nBinsPhi = nModPhi /
f;
301 size_t nBinsZ = nModZ /
f;
304 std::move(approachDescriptor));
308 std::move(approachDescriptor));
311 layersOutput.push_back(
layer);
316 Acts::LayerVector &layersOutput,
int type)
const
319 ACTS_VERBOSE(
"Build layers: " << (
type < 0 ?
"NEGATIVE" :
"POSITIVE")
321 std::vector<std::shared_ptr<const ActsDetectorElement>> elements =
323 std::map<std::tuple<int, int, int>, std::vector<const Acts::Surface *>>
326 for (
const auto &element : elements) {
334 if(
id.layer_disk() >= 3)
continue;
337 if(
id.layer_disk() <= 2)
continue;
342 std::tuple<int, int, int>
key{
id.bec(),
id.layer_disk(),
id.eta_module()};
344 initialLayers[
key].push_back(&element->surface());
347 ACTS_VERBOSE(
"Found " << initialLayers.size() <<
" "
348 << (
type < 0 ?
"NEGATIVE" :
"POSITIVE")
349 <<
" ENDCAP inital layers");
351 std::vector<Acts::ProtoLayer> protoLayers;
352 protoLayers.reserve(initialLayers.size());
354 for (
const auto &[
key, surfaces] : initialLayers) {
355 auto &pl = protoLayers.emplace_back(gctx, surfaces);
361 std::sort(protoLayers.begin(), protoLayers.end(),
362 [
type](
const Acts::ProtoLayer &
a,
const Acts::ProtoLayer &
b) {
363 double midA = (a.min(Acts::BinningValue::binZ) + a.max(Acts::BinningValue::binZ)) / 2.0;
364 double midB = (b.min(Acts::BinningValue::binZ) + b.max(Acts::BinningValue::binZ)) / 2.0;
372 auto plPrintZ = [](
const auto &pl) -> std::string {
373 std::stringstream
ss;
380 for (
const auto &pl : protoLayers) {
382 ACTS_VERBOSE(
" -> at < zMin | zMid | zMax >: " << plPrintZ(pl));
389 std::vector<Acts::ProtoLayer> mergedProtoLayers;
391 if (m_cfg.doEndcapLayerMerging) {
392 mergedProtoLayers.push_back(protoLayers.front());
393 std::vector<const Acts::Surface *> surfaces;
394 for (
size_t i = 1;
i < protoLayers.size();
i++) {
395 auto &pl = protoLayers[
i];
396 auto &pl_prev = mergedProtoLayers.back();
398 ACTS_VERBOSE(
"Compare: " << plPrintZ(pl_prev) <<
" and " << plPrintZ(pl));
401 ACTS_VERBOSE(
" -> overlap? " << (overlap ?
"yes" :
"no"));
403 ACTS_VERBOSE(
" ===> merging");
405 surfaces.reserve(pl.surfaces().size() + pl_prev.surfaces().size());
406 surfaces.insert(surfaces.end(), pl.surfaces().begin(),
407 pl.surfaces().end());
408 surfaces.insert(surfaces.end(), pl_prev.surfaces().begin(),
409 pl_prev.surfaces().end());
410 mergedProtoLayers.pop_back();
412 mergedProtoLayers.emplace_back(gctx, std::move(surfaces));
416 mergedProtoLayers.push_back(std::move(pl));
420 ACTS_VERBOSE(
"" << mergedProtoLayers.size() <<
" "
421 << (
type < 0 ?
"NEGATIVE" :
"POSITIVE")
422 <<
" ENDCAP layers remain after merging");
424 mergedProtoLayers = protoLayers;
427 if (m_cfg.objDebugOutput) {
428 for (
size_t i = 0;
i < mergedProtoLayers.size();
i++) {
430 std::stringstream
ss;
431 ss <<
"obj/" << m_cfg.mode <<
"_" << (
type < 0 ?
"neg" :
"pos")
432 <<
"_disk_" << std::setfill(
'0') << std::setw(2) <<
i <<
".obj";
434 std::ofstream ofs{
ss.str()};
435 Acts::ObjVisualization3D vis{};
436 Acts::ViewConfig vc = Acts::s_viewSensitive;
437 vc.quarterSegments = 200;
438 for (
const auto &surface : mergedProtoLayers[
i].surfaces()) {
439 Acts::GeometryView3D::drawSurface(vis, *surface, gctx,
440 Acts::Transform3::Identity(), vc);
447 std::vector<std::shared_ptr<const Surface>> ownedSurfaces;
448 for (
const auto &pl : mergedProtoLayers) {
450 std::unique_ptr<Acts::ApproachDescriptor> approachDescriptor =
nullptr;
451 std::shared_ptr<const Acts::ProtoSurfaceMaterial> materialProxy =
nullptr;
457 double layerZInner = layerZ - layerHalfZ;
458 double layerZOuter = layerZ + layerHalfZ;
460 if (std::abs(layerZInner) > std::abs(layerZOuter))
463 std::vector<std::shared_ptr<const Acts::Surface>> aSurfaces;
465 Acts::Transform3 transformNominal(Translation3(0., 0., layerZ));
466 Acts::Transform3 transformInner(Translation3(0., 0., layerZInner));
467 Acts::Transform3 transformOuter(Translation3(0., 0., layerZOuter));
469 std::shared_ptr<Acts::DiscSurface> innerBoundary =
470 Acts::Surface::makeShared<Acts::DiscSurface>(
472 aSurfaces.push_back(innerBoundary);
474 std::shared_ptr<Acts::DiscSurface> nominalSurface =
475 Acts::Surface::makeShared<Acts::DiscSurface>(
477 aSurfaces.push_back(nominalSurface);
479 std::shared_ptr<Acts::DiscSurface> outerBoundary =
480 Acts::Surface::makeShared<Acts::DiscSurface>(
482 aSurfaces.push_back(outerBoundary);
484 if(layerThickness > 2_mm) {
485 ACTS_VERBOSE(
"Wide disc layer ("<< layerThickness <<
") => adding cylinder like approach surfaces");
486 Acts::Transform3
trf{Translation3{0, 0, layerZ}};
488 Acts::Surface::makeShared<Acts::CylinderSurface>(
490 aSurfaces.push_back(cylinderInner);
493 Acts::Surface::makeShared<Acts::CylinderSurface>(
495 aSurfaces.push_back(cylinderOuter);
499 size_t matBinsPhi = m_cfg.endcapMaterialBins.first;
500 size_t matBinsR = m_cfg.endcapMaterialBins.second;
509 std::make_shared<const Acts::ProtoSurfaceMaterial>(materialBinUtil);
511 ACTS_VERBOSE(
"[L] Layer is marked to carry support material on Surface ( "
512 "inner=0 / center=1 / outer=2 ) : "
514 ACTS_VERBOSE(
"with binning: [" << matBinsPhi <<
", " << matBinsR <<
"]");
516 ACTS_VERBOSE(
"Created ApproachSurfaces for disc layer at:");
517 ACTS_VERBOSE(
" - inner: Z=" << layerZInner);
518 ACTS_VERBOSE(
" - central: Z=" << layerZ);
519 ACTS_VERBOSE(
" - outer: Z=" << layerZOuter);
522 innerBoundary->assignSurfaceMaterial(materialProxy);
526 bool isITk = m_cfg.mode == Mode::ITkPixelInner ||
527 m_cfg.mode == Mode::ITkPixelOuter ||
528 m_cfg.mode == Mode::ITkStrip;
530 std::map<int, std::set<int>> phiModuleByRing;
533 for (
const auto &srf : pl.surfaces()) {
535 srf->associatedDetectorElement());
539 if(m_cfg.mode == Mode::ITkStrip || !isITk) {
543 ring_number =
id.layer_disk();
545 phiModuleByRing[ring_number].insert(
id.phi_module());
549 for(
const auto& [ring, phiModules] : phiModuleByRing) {
550 nModPhi =
std::min(nModPhi, phiModules.size());
553 size_t nModR = phiModuleByRing.size();
555 ACTS_VERBOSE(
"Identifier reports: " << nModPhi <<
" is lowest for " << nModR
558 size_t nBinsPhi = nModPhi;
559 size_t nBinsR = nModR;
569 if(m_cfg.mode == Mode::ITkStrip) {
574 ACTS_VERBOSE(
"Creating r x phi binned layer with " << nBinsR <<
" x "
575 << nBinsPhi <<
" bins");
579 std::make_unique<Acts::GenericApproachDescriptor>(aSurfaces);
582 ownedSurfaces.clear();
583 ownedSurfaces.reserve(pl.surfaces().size());
585 std::back_inserter(ownedSurfaces),
586 [](
const auto &
s) { return s->getSharedPtr(); });
588 auto layer = m_cfg.layerCreator->discLayer(gctx, ownedSurfaces, nBinsR,
589 nBinsPhi, pl, transformNominal,
590 std::move(approachDescriptor));
592 layersOutput.push_back(
layer);
612 case Mode::ITkPixelInner:
613 os <<
"ITkPixelInner";
615 case Mode::ITkPixelOuter:
616 os <<
"ITkPixelOuter";