Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:14:08

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