EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AccumulatedSurfaceMaterial.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AccumulatedSurfaceMaterial.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-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 
13 
14 // Default Constructor - for homogeneous material
16  : m_splitFactor(splitFactor) {
18  m_accumulatedMaterial = {{accMat}};
19 }
20 
21 // Binned Material constructor with split factor
23  const BinUtility& binUtility, double splitFactor)
24  : m_binUtility(binUtility), m_splitFactor(splitFactor) {
25  size_t bins0 = m_binUtility.bins(0);
26  size_t bins1 = m_binUtility.bins(1);
29 }
30 
31 // Assign a material properites object
33  const Vector2D& lp, const MaterialSlab& mp, double pathCorrection) {
34  if (m_binUtility.dimensions() == 0) {
35  m_accumulatedMaterial[0][0].accumulate(mp, pathCorrection);
36  return {0, 0, 0};
37  }
38  size_t bin0 = m_binUtility.bin(lp, 0);
39  size_t bin1 = m_binUtility.bin(lp, 1);
40  m_accumulatedMaterial[bin1][bin0].accumulate(mp, pathCorrection);
41  return {bin0, bin1, 0};
42 }
43 
44 // Assign a material properites object
46  const Vector3D& gp, const MaterialSlab& mp, double pathCorrection) {
47  if (m_binUtility.dimensions() == 0) {
48  m_accumulatedMaterial[0][0].accumulate(mp, pathCorrection);
49  return {0, 0, 0};
50  }
51  std::array<size_t, 3> bTriple = m_binUtility.binTriple(gp);
52  m_accumulatedMaterial[bTriple[1]][bTriple[0]].accumulate(mp, pathCorrection);
53  return bTriple;
54 }
55 
56 // Void average for vacuum assignment
58  bool emptyHit) {
59  if (m_binUtility.dimensions() == 0) {
60  m_accumulatedMaterial[0][0].trackAverage();
61  }
62  std::array<size_t, 3> bTriple = m_binUtility.binTriple(gp);
63  std::vector<std::array<size_t, 3>> trackBins = {bTriple};
64  trackAverage(trackBins, emptyHit);
65 }
66 
67 // Average the information accumulated during one event
69  const std::vector<std::array<size_t, 3>>& trackBins, bool emptyHit) {
70  // the homogeneous material case
71  if (m_binUtility.dimensions() == 0) {
72  m_accumulatedMaterial[0][0].trackAverage(emptyHit);
73  return;
74  }
75 
76  // The touched bins are known, so you can access them directly
77  if (not trackBins.empty()) {
78  for (auto bin : trackBins) {
79  m_accumulatedMaterial[bin[1]][bin[0]].trackAverage(emptyHit);
80  }
81  } else {
82  // Touched bins are not known: Run over all bins
83  for (auto& matVec : m_accumulatedMaterial) {
84  for (auto& mat : matVec) {
85  mat.trackAverage(emptyHit);
86  }
87  }
88  }
89 }
90 
92 std::unique_ptr<const Acts::ISurfaceMaterial>
94  if (m_binUtility.bins() == 1) {
95  // Return HomogeneousSurfaceMaterial
96  return std::make_unique<HomogeneousSurfaceMaterial>(
97  m_accumulatedMaterial[0][0].totalAverage().first, m_splitFactor);
98  }
99  // Create the properties matrix
100  MaterialSlabMatrix mpMatrix(
101  m_binUtility.bins(1),
102  MaterialSlabVector(m_binUtility.bins(0), MaterialSlab()));
103  // Loop over and fill
104  for (size_t ib1 = 0; ib1 < m_binUtility.bins(1); ++ib1) {
105  for (size_t ib0 = 0; ib0 < m_binUtility.bins(0); ++ib0) {
106  mpMatrix[ib1][ib0] = m_accumulatedMaterial[ib1][ib0].totalAverage().first;
107  }
108  }
109  // Now return the BinnedSurfaceMaterial
110  return std::make_unique<const BinnedSurfaceMaterial>(
111  m_binUtility, std::move(mpMatrix), m_splitFactor);
112 }