ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AccumulatedMaterialProperties.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AccumulatedMaterialProperties.hpp
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 
9 #pragma once
10 
12 
13 namespace Acts {
14 
35  public:
38 
41 
45  default;
46 
50 
54  const AccumulatedMaterialProperties& amp) = default;
55 
59  AccumulatedMaterialProperties&& amp) = default;
60 
74  void accumulate(const MaterialProperties& amp, double pathCorrection = 1.);
75 
79  void trackAverage(bool emptyHit = false);
80 
91  std::pair<MaterialProperties, unsigned int> totalAverage();
92 
93  private:
94  double m_eventPathInX0{0.};
95  double m_eventPathInL0{0.};
96  double m_eventAr{0.};
97  double m_eventZ{0.};
98  double m_eventRho{0.};
99  double m_eventPath{0.};
101 
102  double m_totalPathInX0{0.};
103  double m_totalPathInL0{0.};
104  double m_totalAr{0.};
105  double m_totalZ{0.};
106  double m_totalRho{0.};
107 
108  unsigned int m_totalEvents{0};
109 };
110 
112  const MaterialProperties& amp, double pathCorrection) {
115  double t = amp.thickness();
116  double r = amp.material().massDensity();
117  m_eventPath += t;
118  m_eventRho += r * t;
119 
120  m_eventAr += amp.material().Ar() * r * t;
121  m_eventZ += amp.material().Z() * r * t;
122 
123  m_eventPathCorrection += pathCorrection * t;
124 }
125 
127  // Increase the total event count either for empty hit or by touched hit
128  if (emptyHit || m_eventPath > 0.) {
129  ++m_totalEvents;
130  }
131 
132  // Average the event quantities
133  if (m_eventPath > 0. && m_eventRho > 0.) {
139  m_totalRho += (m_eventRho);
140  }
141  m_eventPathInX0 = 0.;
142  m_eventPathInL0 = 0.;
143  m_eventAr = 0.;
144  m_eventZ = 0.;
145  m_eventRho = 0.;
146  m_eventPath = 0.;
148 }
149 
150 inline std::pair<MaterialProperties, unsigned int>
152  if (m_totalEvents > 0 && m_totalPathInX0 > 0.) {
153  double eventScalor = 1. / m_totalEvents;
154  m_totalPathInX0 *= eventScalor;
155  m_totalPathInL0 *= eventScalor;
156  m_totalRho *= eventScalor;
157  m_totalAr *= eventScalor;
158  m_totalZ *= eventScalor;
159  // Create the material
160  double X0 = 1. / m_totalPathInX0;
161  double L0 = 1. / m_totalPathInL0;
162  // Create the material properties - fixed to unit path length
163  MaterialProperties averageMat(X0, L0, m_totalAr, m_totalZ, m_totalRho, 1.);
164  return std::pair<MaterialProperties, unsigned int>(std::move(averageMat),
165  m_totalEvents);
166  }
167  return std::pair<MaterialProperties, unsigned int>(
169 }
170 
171 } // end of namespace Acts