Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MaterialMapping.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MaterialMapping.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-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 
14 
15 #include <iostream>
16 #include <stdexcept>
17 #include <unordered_map>
18 
19 namespace ActsExamples {
20 struct AlgorithmContext;
21 } // namespace ActsExamples
22 
26  : ActsExamples::IAlgorithm("MaterialMapping", level),
27  m_cfg(cfg),
28  m_mappingState(cfg.geoContext, cfg.magFieldContext),
29  m_mappingStateVol(cfg.geoContext, cfg.magFieldContext) {
31  throw std::invalid_argument("Missing material mapper");
32  } else if (!m_cfg.trackingGeometry) {
33  throw std::invalid_argument("Missing tracking geometry");
34  }
35 
38 
39  ACTS_INFO("This algorithm requires inter-event information, "
40  << "run in single-threaded mode!");
41 
43  // Generate and retrieve the central cache object
46  }
48  // Generate and retrieve the central cache object
51  }
52 }
53 
55  Acts::DetectorMaterialMaps detectorMaterial;
56 
57  if (m_cfg.materialSurfaceMapper && m_cfg.materialVolumeMapper) {
58  // Finalize all the maps using the cached state
59  m_cfg.materialSurfaceMapper->finalizeMaps(m_mappingState);
60  m_cfg.materialVolumeMapper->finalizeMaps(m_mappingStateVol);
61  // Loop over the state, and collect the maps for surfaces
62  for (auto& [key, value] : m_mappingState.surfaceMaterial) {
63  detectorMaterial.first.insert({key, std::move(value)});
64  }
65  // Loop over the state, and collect the maps for volumes
66  for (auto& [key, value] : m_mappingStateVol.volumeMaterial) {
67  detectorMaterial.second.insert({key, std::move(value)});
68  }
69  } else {
70  if (m_cfg.materialSurfaceMapper) {
71  // Finalize all the maps using the cached state
72  m_cfg.materialSurfaceMapper->finalizeMaps(m_mappingState);
73  // Loop over the state, and collect the maps for surfaces
74  for (auto& [key, value] : m_mappingState.surfaceMaterial) {
75  detectorMaterial.first.insert({key, std::move(value)});
76  }
77  // Loop over the state, and collect the maps for volumes
78  for (auto& [key, value] : m_mappingState.volumeMaterial) {
79  detectorMaterial.second.insert({key, std::move(value)});
80  }
81  }
82  if (m_cfg.materialVolumeMapper) {
83  // Finalize all the maps using the cached state
84  m_cfg.materialVolumeMapper->finalizeMaps(m_mappingStateVol);
85  // Loop over the state, and collect the maps for surfaces
86  for (auto& [key, value] : m_mappingStateVol.surfaceMaterial) {
87  detectorMaterial.first.insert({key, std::move(value)});
88  }
89  // Loop over the state, and collect the maps for volumes
90  for (auto& [key, value] : m_mappingStateVol.volumeMaterial) {
91  detectorMaterial.second.insert({key, std::move(value)});
92  }
93  }
94  }
95  // Loop over the available writers and write the maps
96  for (auto& imw : m_cfg.materialWriters) {
97  imw->writeMaterial(detectorMaterial);
98  }
99 }
100 
102  const ActsExamples::AlgorithmContext& context) const {
103  // Take the collection from the EventStore
104  std::unordered_map<size_t, Acts::RecordedMaterialTrack> mtrackCollection =
105  m_inputMaterialTracks(context);
106 
107  if (m_cfg.materialSurfaceMapper) {
108  // To make it work with the framework needs a lock guard
109  auto mappingState =
110  const_cast<Acts::SurfaceMaterialMapper::State*>(&m_mappingState);
111  for (auto& [idTrack, mTrack] : mtrackCollection) {
112  // Map this one onto the geometry
113  m_cfg.materialSurfaceMapper->mapMaterialTrack(*mappingState, mTrack);
114  }
115  }
116  if (m_cfg.materialVolumeMapper) {
117  // To make it work with the framework needs a lock guard
118  auto mappingState =
119  const_cast<Acts::VolumeMaterialMapper::State*>(&m_mappingStateVol);
120 
121  for (auto& [idTrack, mTrack] : mtrackCollection) {
122  // Map this one onto the geometry
123  m_cfg.materialVolumeMapper->mapMaterialTrack(*mappingState, mTrack);
124  }
125  }
126  // Write take the collection to the EventStore
127  m_outputMaterialTracks(context, std::move(mtrackCollection));
129 }
130 
131 std::vector<std::pair<double, int>>
133  std::vector<std::pair<double, int>> scoringParameters;
134 
135  if (m_cfg.materialSurfaceMapper) {
136  auto surfaceAccumulatedMaterial = m_mappingState.accumulatedMaterial.find(
137  Acts::GeometryIdentifier(surfaceID));
138 
139  if (surfaceAccumulatedMaterial !=
140  m_mappingState.accumulatedMaterial.end()) {
141  auto matrixMaterial =
142  surfaceAccumulatedMaterial->second.accumulatedMaterial();
143  for (const auto& vectorMaterial : matrixMaterial) {
144  for (const auto& AccumulatedMaterial : vectorMaterial) {
145  auto totalVariance = AccumulatedMaterial.totalVariance();
146  scoringParameters.push_back(
147  {totalVariance.first, totalVariance.second});
148  }
149  }
150  }
151  }
152  return scoringParameters;
153 }