Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:23:41

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/GenericDetector/LayerBuilder.hpp"
0010 
0011 #include <span>
0012 
0013 namespace ActsExamples::Generic {
0014 
0015 namespace {
0016 std::vector<std::shared_ptr<const Acts::Surface>> makeConstSurfaces(
0017     std::span<const std::shared_ptr<Acts::Surface>> surfaces) {
0018   std::vector<std::shared_ptr<const Acts::Surface>> constSurfaces;
0019   constSurfaces.reserve(surfaces.size());
0020   for (const auto& surface : surfaces) {
0021     constSurfaces.push_back(surface);
0022   }
0023   return constSurfaces;
0024 }
0025 }  // namespace
0026 
0027 const Acts::LayerVector LayerBuilder::centralLayers(
0028     const Acts::GeometryContext& gctx) const {
0029   // create the vector
0030   Acts::LayerVector cLayers;
0031   cLayers.reserve(m_cfg.centralProtoLayers.size());
0032   // the layer counter
0033   std::size_t icl = 0;
0034   for (auto& cpl : m_cfg.centralProtoLayers) {
0035     // create the layer actually
0036     Acts::ProtoLayer constProtoLayer{cpl.protoLayer};
0037     Acts::MutableLayerPtr cLayer = m_cfg.layerCreator->cylinderLayer(
0038         gctx, makeConstSurfaces(cpl.surfaces), cpl.bins0, cpl.bins1,
0039         constProtoLayer);
0040 
0041     // the layer is built let's see if it needs material
0042     if (!m_cfg.centralLayerMaterial.empty()) {
0043       std::shared_ptr<const Acts::ISurfaceMaterial> layerMaterialPtr =
0044           m_cfg.centralLayerMaterial.at(icl);
0045       // central material
0046       if (m_cfg.centralLayerMaterialConcentration.at(icl) == 0.) {
0047         // the layer surface is the material surface
0048         cLayer->surfaceRepresentation().assignSurfaceMaterial(layerMaterialPtr);
0049         ACTS_VERBOSE("- and material at central layer surface.");
0050       } else {
0051         // approach surface material
0052         // get the approach descriptor - at this stage we know that the
0053         // approachDescriptor exists
0054         auto approachSurfaces =
0055             cLayer->approachDescriptor()->containedSurfaces();
0056         if (m_cfg.centralLayerMaterialConcentration.at(icl) > 0) {
0057           auto mutableOuterSurface =
0058               const_cast<Acts::Surface*>(approachSurfaces.at(1));
0059           mutableOuterSurface->assignSurfaceMaterial(layerMaterialPtr);
0060           ACTS_VERBOSE("- and material at outer approach surface");
0061         } else {
0062           auto mutableInnerSurface =
0063               const_cast<Acts::Surface*>(approachSurfaces.at(0));
0064           mutableInnerSurface->assignSurfaceMaterial(layerMaterialPtr);
0065           ACTS_VERBOSE("- and material at inner approach surface");
0066         }
0067       }
0068     }
0069     // push it into the layer vector
0070     cLayers.push_back(cLayer);
0071     ++icl;
0072   }
0073   return cLayers;
0074 }
0075 
0076 const Acts::LayerVector LayerBuilder::negativeLayers(
0077     const Acts::GeometryContext& gctx) const {
0078   return constructEndcapLayers(gctx, -1);
0079 }
0080 
0081 const Acts::LayerVector LayerBuilder::positiveLayers(
0082     const Acts::GeometryContext& gctx) const {
0083   return constructEndcapLayers(gctx, 1);
0084 }
0085 
0086 LayerBuilder::LayerBuilder(const Config& cfg,
0087                            std::unique_ptr<const Acts::Logger> log)
0088     : Acts::ILayerBuilder(), m_cfg(cfg), m_logger(std::move(log)) {}
0089 
0090 const Acts::LayerVector LayerBuilder::constructEndcapLayers(
0091     const Acts::GeometryContext& gctx, int side) const {
0092   // The from negative or positive proto layers
0093   const auto& protoLayers =
0094       (side < 0) ? m_cfg.negativeProtoLayers : m_cfg.positiveProtoLayers;
0095 
0096   // create the vector
0097   Acts::LayerVector eLayers;
0098   eLayers.reserve(protoLayers.size());
0099 
0100   // the layer counter
0101   std::size_t ipnl = 0;
0102   // loop over the proto layers and create the actual layers
0103   for (auto& ple : protoLayers) {
0104     /// the layer is created
0105     Acts::ProtoLayer constProtoLayer{ple.protoLayer};
0106     Acts::MutableLayerPtr eLayer =
0107         m_cfg.layerCreator->discLayer(gctx, makeConstSurfaces(ple.surfaces),
0108                                       ple.bins0, ple.bins1, constProtoLayer);
0109 
0110     // the layer is built let's see if it needs material
0111     if (!m_cfg.posnegLayerMaterial.empty()) {
0112       std::shared_ptr<const Acts::ISurfaceMaterial> layerMaterialPtr =
0113           m_cfg.posnegLayerMaterial[ipnl];
0114       // central material
0115       if (m_cfg.posnegLayerMaterialConcentration.at(ipnl) == 0.) {
0116         // assign the surface material - the layer surface is the material
0117         // surface
0118         eLayer->surfaceRepresentation().assignSurfaceMaterial(layerMaterialPtr);
0119         ACTS_VERBOSE("- and material at central layer surface.");
0120       } else {
0121         // approach surface material
0122         // get the approach descriptor - at this stage we know that the
0123         // approachDescriptor exists
0124         auto approachSurfaces =
0125             eLayer->approachDescriptor()->containedSurfaces();
0126         if (m_cfg.posnegLayerMaterialConcentration.at(ipnl) > 0.) {
0127           int sf = side < 0 ? 0 : 1;
0128           auto mutableInnerSurface =
0129               const_cast<Acts::Surface*>(approachSurfaces.at(sf));
0130           mutableInnerSurface->assignSurfaceMaterial(layerMaterialPtr);
0131           ACTS_VERBOSE("- and material at outer approach surfaces.");
0132         } else {
0133           int sf = side < 0 ? 1 : 0;
0134           auto mutableOuterSurface =
0135               const_cast<Acts::Surface*>(approachSurfaces.at(sf));
0136           mutableOuterSurface->assignSurfaceMaterial(layerMaterialPtr);
0137           ACTS_VERBOSE("- and material at inner approach surfaces.");
0138         }
0139       }
0140     }
0141     // push it into the layer vector
0142     eLayers.push_back(eLayer);
0143     ++ipnl;
0144   }
0145   return eLayers;
0146 }
0147 
0148 }  // namespace ActsExamples::Generic