Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:10:16

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