Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-13 08:18:06

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 "ActsPlugins/DD4hep/DD4hepMaterialHelpers.hpp"
0010 
0011 #include "Acts/Geometry/ApproachDescriptor.hpp"
0012 #include "Acts/Geometry/Layer.hpp"
0013 #include "Acts/Surfaces/Surface.hpp"
0014 #include "Acts/Utilities/BinUtility.hpp"
0015 #include "Acts/Utilities/BinningType.hpp"
0016 #include "ActsPlugins/DD4hep/DD4hepConversionHelpers.hpp"
0017 
0018 #include <cstddef>
0019 #include <numbers>
0020 #include <ostream>
0021 
0022 #include <boost/foreach.hpp>
0023 #include <boost/tokenizer.hpp>
0024 
0025 using namespace Acts;
0026 
0027 std::shared_ptr<ProtoSurfaceMaterial> ActsPlugins::createProtoMaterial(
0028     const dd4hep::rec::VariantParameters& params, const std::string& valueTag,
0029     const std::vector<std::pair<const std::string, BinningOption> >& binning,
0030     const Logger& logger) {
0031   using namespace std::string_literals;
0032 
0033   // Create the bin utility
0034   BinUtility bu;
0035   // Loop over the bins
0036   for (auto& bin : binning) {
0037     AxisDirection bval = axisDirectionFromName(bin.first);
0038     BinningOption bopt = bin.second;
0039     double min = 0.;
0040     double max = 0.;
0041     if (bopt == closed) {
0042       min = -std::numbers::pi;
0043       max = std::numbers::pi;
0044     }
0045     int bins = params.get<int>(valueTag + "_"s + bin.first);
0046     ACTS_VERBOSE("  - material binning for " << bin.first << " on " << valueTag
0047                                              << ": " << bins);
0048     if (bins >= 1) {
0049       bu += BinUtility(bins, min, max, bopt, bval);
0050     }
0051   }
0052   return std::make_shared<ProtoSurfaceMaterial>(bu);
0053 }
0054 
0055 void ActsPlugins::addLayerProtoMaterial(
0056     const dd4hep::rec::VariantParameters& params, Layer& layer,
0057     const std::vector<std::pair<const std::string, BinningOption> >& binning,
0058     const Logger& logger) {
0059   ACTS_VERBOSE("addLayerProtoMaterial");
0060   // Start with the representing surface
0061   std::vector<std::string> materialOptions = {"layer_material_representing"};
0062   std::vector<const Surface*> materialSurfaces = {
0063       &(layer.surfaceRepresentation())};
0064   // Now fill (optionally) with the approach surfaces
0065   auto aDescriptor = layer.approachDescriptor();
0066   if (aDescriptor != nullptr && aDescriptor->containedSurfaces().size() >= 2) {
0067     // Add the inner and outer approach surface
0068     const std::vector<const Surface*>& aSurfaces =
0069         aDescriptor->containedSurfaces();
0070     materialOptions.push_back("layer_material_inner");
0071     materialSurfaces.push_back(aSurfaces[0]);
0072     materialOptions.push_back("layer_material_outer");
0073     materialSurfaces.push_back(aSurfaces[1]);
0074   }
0075 
0076   // Now loop over it and create the ProtoMaterial
0077   for (unsigned int is = 0; is < materialOptions.size(); ++is) {
0078     // if (actsExtension.hasValue(materialOptions[is])) {
0079     ACTS_VERBOSE(" - checking material for: " << materialOptions[is]);
0080     if (params.contains(materialOptions[is])) {
0081       ACTS_VERBOSE(" - have material");
0082       // Create the material and assign it
0083       auto psMaterial =
0084           createProtoMaterial(params, materialOptions[is], binning, logger);
0085       // const_cast (ugly - to be changed after internal geometry stored
0086       // non-const)
0087       Surface* surface = const_cast<Surface*>(materialSurfaces[is]);
0088       surface->assignSurfaceMaterial(psMaterial);
0089     }
0090   }
0091 }
0092 
0093 void ActsPlugins::addCylinderLayerProtoMaterial(dd4hep::DetElement detElement,
0094                                                 Layer& cylinderLayer,
0095                                                 const Logger& logger) {
0096   ACTS_VERBOSE(
0097       "Translating DD4hep material into Acts material for CylinderLayer : "
0098       << detElement.name());
0099   if (hasParams(detElement)) {
0100     ACTS_VERBOSE(" params: " << getParams(detElement));
0101   } else {
0102     ACTS_VERBOSE(" NO params");
0103   }
0104   if (getParamOr<bool>("layer_material", detElement, false)) {
0105     addLayerProtoMaterial(getParams(detElement), cylinderLayer,
0106                           {{"binPhi", closed}, {"binZ", open}}, logger);
0107   }
0108 }
0109 
0110 void ActsPlugins::addDiscLayerProtoMaterial(dd4hep::DetElement detElement,
0111                                             Layer& discLayer,
0112                                             const Logger& logger) {
0113   ACTS_VERBOSE("Translating DD4hep material into Acts material for DiscLayer : "
0114                << detElement.name());
0115 
0116   if (hasParams(detElement)) {
0117     ACTS_VERBOSE(" params: " << getParams(detElement));
0118   } else {
0119     ACTS_VERBOSE(" NO params");
0120   }
0121   if (getParamOr<bool>("layer_material", detElement, false)) {
0122     addLayerProtoMaterial(getParams(detElement), discLayer,
0123                           {{"binPhi", closed}, {"binR", open}}, logger);
0124   }
0125 }