Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-13 08:14:05

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