ECCE @ 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 
12 
13 // Default Constructor - for homogeneous material
15  : m_splitFactor(splitFactor) {
17  m_accumulatedMaterial = {{accMat}};
18 }
19 
20 // Binned Material constructor with split factor
22  const BinUtility& binUtility, double splitFactor)
23  : m_binUtility(binUtility), m_splitFactor(splitFactor) {
24  size_t bins0 = m_binUtility.bins(0);
25  size_t bins1 = m_binUtility.bins(1);
28 }
29 
30 // Assign a material properites object
32  const Vector2D& lp, const MaterialProperties& mp, double pathCorrection) {
33  if (m_binUtility.dimensions() == 0) {
34  m_accumulatedMaterial[0][0].accumulate(mp, pathCorrection);
35  return {0, 0, 0};
36  }
37  size_t bin0 = m_binUtility.bin(lp, 0);
38  size_t bin1 = m_binUtility.bin(lp, 1);
39  m_accumulatedMaterial[bin1][bin0].accumulate(mp, pathCorrection);
40  return {bin0, bin1, 0};
41 }
42 
43 // Assign a material properites object
45  const Vector3D& gp, const MaterialProperties& mp, double pathCorrection) {
46  if (m_binUtility.dimensions() == 0) {
47  m_accumulatedMaterial[0][0].accumulate(mp, pathCorrection);
48  return {0, 0, 0};
49  }
50  std::array<size_t, 3> bTriple = m_binUtility.binTriple(gp);
51  m_accumulatedMaterial[bTriple[1]][bTriple[0]].accumulate(mp, pathCorrection);
52  return bTriple;
53 }
54 
55 // Void average for vacuum assignment
57  bool emptyHit) {
58  if (m_binUtility.dimensions() == 0) {
59  m_accumulatedMaterial[0][0].trackAverage();
60  }
61  std::array<size_t, 3> bTriple = m_binUtility.binTriple(gp);
62  std::vector<std::array<size_t, 3>> trackBins = {bTriple};
63  trackAverage(trackBins, emptyHit);
64 }
65 
66 // Average the information accumulated during one event
68  const std::vector<std::array<size_t, 3>>& trackBins, bool emptyHit) {
69  // the homogeneous material case
70  if (m_binUtility.dimensions() == 0) {
71  m_accumulatedMaterial[0][0].trackAverage(emptyHit);
72  return;
73  }
74 
75  // The touched bins are known, so you can access them directly
76  if (not trackBins.empty()) {
77  for (auto bin : trackBins) {
78  m_accumulatedMaterial[bin[1]][bin[0]].trackAverage(emptyHit);
79  }
80  } else {
81  // Touched bins are not known: Run over all bins
82  for (auto& matVec : m_accumulatedMaterial) {
83  for (auto& mat : matVec) {
84  mat.trackAverage(emptyHit);
85  }
86  }
87  }
88 }
89 
91 std::unique_ptr<const Acts::ISurfaceMaterial>
93  if (m_binUtility.bins() == 1) {
94  // Return HomogeneousSurfaceMaterial
95  return std::make_unique<HomogeneousSurfaceMaterial>(
96  m_accumulatedMaterial[0][0].totalAverage().first, m_splitFactor);
97  }
98  // Create the properties matrix
99  MaterialPropertiesMatrix mpMatrix(
100  m_binUtility.bins(1),
101  MaterialPropertiesVector(m_binUtility.bins(0), MaterialProperties()));
102  // Loop over and fill
103  for (size_t ib1 = 0; ib1 < m_binUtility.bins(1); ++ib1) {
104  for (size_t ib0 = 0; ib0 < m_binUtility.bins(0); ++ib0) {
105  mpMatrix[ib1][ib0] = m_accumulatedMaterial[ib1][ib0].totalAverage().first;
106  }
107  }
108  // Now return the BinnedSurfaceMaterial
109  return std::make_unique<const BinnedSurfaceMaterial>(
110  m_binUtility, std::move(mpMatrix), m_splitFactor);
111 }