25 : m_layerThickness(0.),
26 m_binUtility(nullptr),
32 m_emptyHitCase(false),
44 double thickness,
const BinUtility* binutils,
double minfraction,
46 : m_layerThickness(thickness),
47 m_binUtility(binutils ? binutils->
clone() : nullptr),
48 m_bins0(binutils ? (binutils->
max(0) + 1) : 1),
49 m_bins1(binutils && binutils->dimensions() > 1 ? (binutils->
max(1) + 1)
51 m_minFraction(minfraction),
54 m_emptyHitCase(false),
63 const auto zeroedVectorDbl = std::vector<double>(
m_bins0, 0.);
64 const auto zeroedVectorUInt = std::vector<unsigned int>(
m_bins0, 0);
65 const auto zeroedVectorVector3D = std::vector<Amg::Vector3D>(
m_bins0,
m_pos);
66 using Element_t = std::map<unsigned int, double>;
67 const auto zeroedVectorElements =
68 std::vector<Element_t>(
m_bins0, Element_t());
69 for (
int ibin = 0; ibin <
m_bins1; ++ibin) {
71 m_run_pos.push_back(zeroedVectorVector3D);
73 m_run_s.push_back(zeroedVectorDbl);
76 m_run_a.push_back(zeroedVectorDbl);
77 m_run_z.push_back(zeroedVectorDbl);
85 : m_layerThickness(lmr.m_layerThickness),
86 m_binUtility(lmr.m_binUtility ? lmr.m_binUtility->
clone() : nullptr),
89 m_minFraction(lmr.m_minFraction),
92 m_emptyHitCase(lmr.m_emptyHitCase),
94 m_s_in_x0(lmr.m_s_in_x0),
95 m_s_in_l0(lmr.m_s_in_l0),
99 m_elements(lmr.m_elements),
100 m_assoc(lmr.m_assoc),
101 m_run_events(lmr.m_run_events),
102 m_run_pos(lmr.m_run_pos),
103 m_run_s(lmr.m_run_s),
104 m_run_s_in_x0(lmr.m_run_s_in_x0),
105 m_run_s_in_l0(lmr.m_run_s_in_l0),
106 m_run_a(lmr.m_run_a),
107 m_run_z(lmr.m_run_z),
108 m_run_rho(lmr.m_run_rho),
109 m_run_elements(lmr.m_run_elements) {
163 m_s_in_x0 +=
s /
mat.X0;
164 m_s_in_l0 +=
s /
mat.L0;
166 m_rho +=
mat.rho *
s;
174 for (
auto&
it : (*mComposition)) {
179 auto eIter = m_elements.find(Z);
180 if (eIter == m_elements.end())
181 m_elements[Z] = fraction *
s /
mat.L0;
183 m_elements[Z] += fraction *
s /
mat.L0;
190 m_emptyHitCase =
true;
199 if (m_emptyHitCase) {
201 int rBin0 = m_binUtility ? m_binUtility->bin(m_pos, 0) : 0;
202 int rBin1 = (m_binUtility && m_binUtility->dimensions() > 1)
203 ? m_binUtility->bin(m_pos, 1)
206 m_run_events[rBin1][rBin0]++;
208 }
else if (m_steps) {
213 hitPosition, hitPosition));
215 int rBin0 = m_binUtility ? m_binUtility->bin(hitPosition, 0) : 0;
216 int rBin1 = (m_binUtility && m_binUtility->dimensions() > 1)
217 ? m_binUtility->bin(hitPosition, 1)
221 m_run_events[rBin1][rBin0]++;
222 m_run_s[rBin1][rBin0] += m_s;
223 m_run_pos[rBin1][rBin0] += hitPosition;
224 m_run_s_in_x0[rBin1][rBin0] += m_s_in_x0 * corrFactorInv;
225 m_run_s_in_l0[rBin1][rBin0] += m_s_in_l0 * corrFactorInv;
227 m_run_a[rBin1][rBin0] += m_a / m_rho;
228 m_run_z[rBin1][rBin0] += m_z / m_rho;
230 m_run_rho[rBin1][rBin0] += m_rho * corrFactorInv / m_layerThickness;
233 for (
auto& eIter : m_elements) {
235 double nef = eIter.second * corrFactorInv / m_s_in_l0;
236 if (m_run_elements[rBin1][rBin0].
find(eIter.first) ==
237 m_run_elements[rBin1][rBin0].end())
238 m_run_elements[rBin1][rBin0][eIter.first] = nef;
240 m_run_elements[rBin1][rBin0][eIter.first] += nef;
246 double eventNorm = 1. /
double(m_run_events[rBin1][rBin0]);
250 double a = m_run_a[rBin1][rBin0] * eventNorm;
251 double z = m_run_z[rBin1][rBin0] * eventNorm;
252 double rho = m_run_rho[rBin1][rBin0] * eventNorm;
256 double s_in_x0 = m_run_s_in_x0[rBin1][rBin0] * eventNorm;
257 double s_in_l0 = m_run_s_in_l0[rBin1][rBin0] * eventNorm;
260 double x0 = m_layerThickness / s_in_x0;
261 double l0 = m_layerThickness / s_in_l0;
265 hitPosition, m_run_s[rBin1][rBin0] * eventNorm, x0,
l0,
a,
z,
rho,
271 m_emptyHitCase =
false;
282 return fullHitMaterial;
286 m_associatedLayerMaterial.reserve(m_bins1);
288 for (
int ibin1 = 0; ibin1 < m_bins1; ++ibin1) {
291 matVector.reserve(m_bins0);
293 for (
int ibin0 = 0; ibin0 < m_bins0; ++ibin0) {
295 if (m_run_events[ibin1][ibin0]) {
297 double eventNorm = 1. /
double(m_run_events[ibin1][ibin0]);
301 m_run_a[ibin1][ibin0] *= eventNorm;
302 m_run_z[ibin1][ibin0] *= eventNorm;
303 m_run_rho[ibin1][ibin0] *= eventNorm;
307 m_run_s_in_x0[ibin1][ibin0] *= eventNorm;
308 m_run_s_in_l0[ibin1][ibin0] *= eventNorm;
311 double x0 = m_layerThickness / m_run_s_in_x0[ibin1][ibin0];
312 double l0 = m_layerThickness / m_run_s_in_l0[ibin1][ibin0];
316 if (recordElements) {
318 double preTotalFraction = 0.;
319 std::map<unsigned int, double> binElements =
320 m_run_elements[ibin1][ibin0];
321 for (
auto& peIter : binElements) {
323 peIter.second *= eventNorm;
324 preTotalFraction += peIter.second;
327 std::map<double, unsigned int> probabilityOrdered;
328 double totalFraction = 0.;
329 for (
auto& eIter : binElements) {
331 double eFraction = eIter.second / preTotalFraction;
332 if (eFraction < m_minFraction)
continue;
333 probabilityOrdered[eIter.second] = eIter.first;
334 totalFraction += eIter.second;
337 std::vector<Trk::ElementFraction> elementFractions;
338 elementFractions.reserve(binElements.size());
339 for (
auto& poEl : probabilityOrdered) {
340 double fracEl = poEl.first / totalFraction;
341 unsigned int fracEluChar = fracEl * UCHAR_MAX;
342 elementFractions.emplace_back(poEl.second, fracEluChar);
345 std::reverse(elementFractions.begin(), elementFractions.end());
350 m_run_z[ibin1][ibin0], m_run_rho[ibin1][ibin0],
355 matVector.push_back(binMaterial);
357 m_associatedLayerMaterial.push_back(matVector);
363 m_associatedLayerMaterial.begin();
365 m_associatedLayerMaterial.end();
366 for (; matMatrixIter != matMatrixIterEnd; ++matMatrixIter) {
369 (*matMatrixIter).begin();
371 (*matMatrixIter).end();
372 for (; matIter != matIterEnd; ++matIter)
delete (*matIter);
374 m_associatedLayerMaterial.clear();
380 m_associatedLayerMaterial.clear();
382 Trk::MaterialPropertiesMatrix::const_iterator matMatrixIter =
383 materialMatrix.begin();
384 Trk::MaterialPropertiesMatrix::const_iterator matMatrixIterEnd =
385 materialMatrix.end();
386 for (; matMatrixIter != matMatrixIterEnd; ++matMatrixIter) {
389 std::vector<const Trk::MaterialProperties*>::const_iterator matIter =
390 (*matMatrixIter).begin();
391 std::vector<const Trk::MaterialProperties*>::const_iterator matIterEnd =
392 (*matMatrixIter).end();
393 for (; matIter != matIterEnd; ++matIter) {
395 matProp.push_back(((*matIter) ? (*matIter)->clone() :
nullptr));
398 m_associatedLayerMaterial.push_back(matProp);