EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Material.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Material.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019-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 
11 #include "Acts/Utilities/Units.hpp"
12 
13 #include <cmath>
14 #include <ostream>
15 
16 namespace {
18  eRadiationLength = 0,
19  eInteractionLength = 1,
20  eRelativeAtomicMass = 2,
21  eNuclearCharge = 3,
22  eMolarDensity = 4,
23 };
24 
25 // Avogadro constant
26 constexpr double kAvogadro = 6.02214076e23 / Acts::UnitConstants::mol;
27 } // namespace
28 
29 Acts::Material Acts::Material::fromMassDensity(float x0, float l0, float ar,
30  float z, float massRho) {
31  using namespace Acts::UnitLiterals;
32 
33  Material mat;
34  mat.m_x0 = x0;
35  mat.m_l0 = l0;
36  mat.m_ar = ar;
37  mat.m_z = z;
38  // mass density is defined as
39  //
40  // mass-density = atomic-mass * number-of-atoms / volume
41  // = atomic-mass * molar-density * avogadro-constant
42  // -> molar-density = mass-density / (atomic-mass * avogadro-constant)
43  //
44  // with the atomic mass given by
45  //
46  // atomic-mass = relative-atomic-mass * atomic-mass-unit
47  //
48  // perform computations in double precision to avoid loss of precision
49  const double atomicMass = static_cast<double>(ar) * 1_u;
50  mat.m_molarRho = static_cast<double>(massRho) / (atomicMass * kAvogadro);
51  return mat;
52 }
53 
54 Acts::Material Acts::Material::fromMolarDensity(float x0, float l0, float ar,
55  float z, float molarRho) {
56  Material mat;
57  mat.m_x0 = x0;
58  mat.m_l0 = l0;
59  mat.m_ar = ar;
60  mat.m_z = z;
61  mat.m_molarRho = molarRho;
62  return mat;
63 }
64 
66  : m_x0(parameters[eRadiationLength]),
67  m_l0(parameters[eInteractionLength]),
68  m_ar(parameters[eRelativeAtomicMass]),
69  m_z(parameters[eNuclearCharge]),
70  m_molarRho(parameters[eMolarDensity]) {}
71 
73  using namespace Acts::UnitLiterals;
74 
75  // perform computations in double precision to avoid loss of precision
76  const double atomicMass = static_cast<double>(m_ar) * 1_u;
77  const double numberDensity = static_cast<double>(m_molarRho) * kAvogadro;
78  return atomicMass * numberDensity;
79 }
80 
82  using namespace Acts::UnitLiterals;
83 
84  // use approximative computation as defined in ATL-SOFT-PUB-2008-003
85  return 16_eV * std::pow(m_z, 0.9f);
86 }
87 
90  parameters[eRadiationLength] = m_x0;
91  parameters[eInteractionLength] = m_l0;
92  parameters[eRelativeAtomicMass] = m_ar;
93  parameters[eNuclearCharge] = m_z;
94  parameters[eMolarDensity] = m_molarRho;
95  return parameters;
96 }
97 
98 std::ostream& Acts::operator<<(std::ostream& os, const Material& material) {
99  if (!material) {
100  os << "vacuum";
101  } else {
102  os << "X0=" << material.X0();
103  os << "|L0=" << material.L0();
104  os << "|Ar=" << material.Ar();
105  os << "|Z=" << material.Z();
106  os << "|MolarRho=" << material.molarDensity();
107  }
108  return os;
109 }