Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-05 08:11:32

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/MaterialSlab.hpp"
0010 
0011 #include "Acts/Material/detail/AverageMaterials.hpp"
0012 
0013 #include <ostream>
0014 #include <stdexcept>
0015 
0016 namespace Acts {
0017 
0018 MaterialSlab::MaterialSlab(const Material& material, float thickness)
0019     : MaterialSlab(material, thickness, false) {
0020   if (thickness < 0) {
0021     throw std::runtime_error("thickness < 0");
0022   }
0023 }
0024 
0025 MaterialSlab MaterialSlab::combineLayers(const MaterialSlab& layerA,
0026                                          const MaterialSlab& layerB) {
0027   return detail::combineSlabs(layerA, layerB);
0028 }
0029 
0030 MaterialSlab MaterialSlab::combineLayers(
0031     const std::vector<MaterialSlab>& layers) {
0032   // NOTE 2020-08-26 msmk
0033   //   the reduce work best (in the numerical stability sense) if the input
0034   //   layers are sorted by thickness/mass density. then, the later terms
0035   //   of the averaging are only small corrections to the large average of
0036   //   the initial layers. this could be enforced by sorting the layers first,
0037   //   but I am not sure if this is actually a problem.
0038   // NOTE yes, this loop is exactly like std::reduce which apparently does not
0039   //   exist on gcc 8 although it is required by C++17.
0040   MaterialSlab result = MaterialSlab::Nothing();
0041   for (const auto& layer : layers) {
0042     result = detail::combineSlabs(result, layer);
0043   }
0044   return result;
0045 }
0046 
0047 void MaterialSlab::scaleThickness(float scale) {
0048   if (scale < 0) {
0049     throw std::runtime_error("scale < 0");
0050   }
0051 
0052   m_thickness *= scale;
0053   m_thicknessInX0 *= scale;
0054   m_thicknessInL0 *= scale;
0055 }
0056 
0057 std::ostream& operator<<(std::ostream& os, const MaterialSlab& materialSlab) {
0058   os << materialSlab.material() << "|t=" << materialSlab.thickness();
0059   return os;
0060 }
0061 
0062 }  // namespace Acts