EIC 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 <climits>
14 #include <limits>
15 #include <ostream>
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 }
27 
28 Acts::MaterialSlab::MaterialSlab(const std::vector<MaterialSlab>& layers)
29  : MaterialSlab() {
30  // NOTE 2020-08-26 msmk
31  // the reduce work best (in the numerical stability sense) if the input
32  // layers are sorted by thickness/mass density. then, the later terms
33  // of the averaging are only small corrections to the large average of
34  // the initial layers. this could be enforced by sorting the layers first,
35  // but i am not sure if this is actually a problem.
36  // NOTE yes, this loop is exactly like std::reduce which apparently does not
37  // exist on gcc 8 although it is required by C++17.
38  for (const auto& layer : layers) {
39  *this = detail::combineSlabs(*this, layer);
40  }
41 }
42 
44  m_thickness *= scale;
45  m_thicknessInX0 *= scale;
46  m_thicknessInL0 *= scale;
47 }
48 
49 std::ostream& Acts::operator<<(std::ostream& os,
50  const MaterialSlab& materialSlab) {
51  os << materialSlab.material() << "|t=" << materialSlab.thickness();
52  return os;
53 }