Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 08:19:15

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/Material/BinnedSurfaceMaterial.hpp"
0010 
0011 #include "Acts/Material/MaterialSlab.hpp"
0012 #include "Acts/Utilities/AxisDefinitions.hpp"
0013 
0014 #include <ostream>
0015 #include <utility>
0016 #include <vector>
0017 
0018 namespace Acts {
0019 
0020 BinnedSurfaceMaterial::BinnedSurfaceMaterial(const BinUtility& binUtility,
0021                                              MaterialSlabVector materialVector,
0022                                              double splitFactor,
0023                                              MappingType mappingType)
0024     : ISurfaceMaterial(splitFactor, mappingType), m_binUtility(binUtility) {
0025   if (binUtility.dimensions() != 1) {
0026     throw std::invalid_argument(
0027         "BinnedSurfaceMaterial with material vector only supports 1D binning.");
0028   }
0029   if (binUtility.binningData()[0].bins() != materialVector.size()) {
0030     throw std::invalid_argument(
0031         "BinnedSurfaceMaterial: number of material bins does not match the "
0032         "number of provided material slabs.");
0033   }
0034   m_fullMaterial.push_back(std::move(materialVector));
0035 }
0036 
0037 BinnedSurfaceMaterial::BinnedSurfaceMaterial(const BinUtility& binUtility,
0038                                              MaterialSlabMatrix materialMatrix,
0039                                              double splitFactor,
0040                                              MappingType mappingType)
0041     : ISurfaceMaterial(splitFactor, mappingType),
0042       m_binUtility(binUtility),
0043       m_fullMaterial(std::move(materialMatrix)) {
0044   if (binUtility.dimensions() != 1 && binUtility.dimensions() != 2) {
0045     throw std::invalid_argument(
0046         "BinnedSurfaceMaterial with material matrix only supports 1D and 2D "
0047         "binning.");
0048   }
0049   if (binUtility.dimensions() == 1) {
0050     if (m_fullMaterial.size() != 1) {
0051       throw std::invalid_argument(
0052           "BinnedSurfaceMaterial with material matrix only supports 1D binning "
0053           "if the material matrix has exactly one row.");
0054     }
0055     if (binUtility.binningData()[0].bins() != m_fullMaterial[0].size()) {
0056       throw std::invalid_argument(
0057           "BinnedSurfaceMaterial: number of material bins does not match the "
0058           "number of provided material slabs.");
0059     }
0060   } else if (binUtility.dimensions() == 2) {
0061     if (binUtility.binningData()[1].bins() != m_fullMaterial.size()) {
0062       throw std::invalid_argument(
0063           "BinnedSurfaceMaterial: number of material bins in the first "
0064           "dimension does not match the number of provided material rows.");
0065     }
0066     for (const auto& materialVector : m_fullMaterial) {
0067       if (binUtility.binningData()[0].bins() != materialVector.size()) {
0068         throw std::invalid_argument(
0069             "BinnedSurfaceMaterial: number of material bins in the second "
0070             "dimension does not match the number of provided material slabs in "
0071             "each row.");
0072       }
0073     }
0074   }
0075 }
0076 
0077 BinnedSurfaceMaterial& BinnedSurfaceMaterial::scale(double factor) {
0078   for (auto& materialVector : m_fullMaterial) {
0079     for (auto& materialBin : materialVector) {
0080       materialBin.scaleThickness(factor);
0081     }
0082   }
0083   return *this;
0084 }
0085 
0086 const MaterialSlab& BinnedSurfaceMaterial::materialSlab(
0087     const Vector2& lp) const {
0088   const std::size_t ibin0 = m_binUtility.bin(lp[0], 0);
0089   const std::size_t ibin1 = m_binUtility.bin(lp[1], 1);
0090   return m_fullMaterial[ibin1][ibin0];
0091 }
0092 
0093 std::vector<AxisDirection> BinnedSurfaceMaterial::localAxisDirections() const {
0094   std::vector<AxisDirection> axisDirs;
0095   for (const auto& bd : m_binUtility.binningData()) {
0096     axisDirs.push_back(bd.binvalue);
0097   }
0098   return axisDirs;
0099 }
0100 
0101 const MaterialSlab& BinnedSurfaceMaterial::materialSlab(
0102     const Vector3& gp) const {
0103   const std::size_t ibin0 = m_binUtility.bin(gp, 0);
0104   const std::size_t ibin1 = m_binUtility.bin(gp, 1);
0105   return m_fullMaterial[ibin1][ibin0];
0106 }
0107 
0108 std::ostream& BinnedSurfaceMaterial::toStream(std::ostream& sl) const {
0109   sl << "BinnedSurfaceMaterial : " << std::endl;
0110   sl << "   - Number of Material bins [0,1] : " << m_binUtility.max(0) + 1
0111      << " / " << m_binUtility.max(1) + 1 << std::endl;
0112   sl << "   - Parse full update material    : " << std::endl;  //
0113   // output  the full material
0114   unsigned int imat1 = 0;
0115   for (auto& materialVector : m_fullMaterial) {
0116     unsigned int imat0 = 0;
0117     // the vector iterator
0118     for (auto& materialBin : materialVector) {
0119       sl << " Bin [" << imat1 << "][" << imat0 << "] - " << (materialBin);
0120       ++imat0;
0121     }
0122     ++imat1;
0123   }
0124   sl << "  - BinUtility: " << m_binUtility << std::endl;
0125   return sl;
0126 }
0127 
0128 }  // namespace Acts