Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MaterialSlab.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MaterialSlab.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
12 
13 #include <limits>
14 #include <ostream>
15 #include <stdexcept>
16 
17 static constexpr auto eps = 2 * std::numeric_limits<float>::epsilon();
18 
19 Acts::MaterialSlab::MaterialSlab(float thickness) : m_thickness(thickness) {}
20 
22  : m_material(material),
23  m_thickness(thickness),
24  m_thicknessInX0((eps < material.X0()) ? (thickness / material.X0()) : 0),
25  m_thicknessInL0((eps < material.L0()) ? (thickness / material.L0()) : 0) {
26  if (thickness < 0) {
27  throw std::runtime_error("thickness < 0");
28  }
29 }
30 
31 Acts::MaterialSlab::MaterialSlab(const std::vector<MaterialSlab>& layers)
32  : MaterialSlab() {
33  // NOTE 2020-08-26 msmk
34  // the reduce work best (in the numerical stability sense) if the input
35  // layers are sorted by thickness/mass density. then, the later terms
36  // of the averaging are only small corrections to the large average of
37  // the initial layers. this could be enforced by sorting the layers first,
38  // but I am not sure if this is actually a problem.
39  // NOTE yes, this loop is exactly like std::reduce which apparently does not
40  // exist on gcc 8 although it is required by C++17.
41  for (const auto& layer : layers) {
42  *this = detail::combineSlabs(*this, layer);
43  }
44 }
45 
47  if (scale < 0) {
48  throw std::runtime_error("scale < 0");
49  }
50 
51  m_thickness *= scale;
52  m_thicknessInX0 *= scale;
53  m_thicknessInL0 *= scale;
54 }
55 
56 std::ostream& Acts::operator<<(std::ostream& os,
57  const MaterialSlab& materialSlab) {
58  os << materialSlab.material() << "|t=" << materialSlab.thickness();
59  return os;
60 }