File indexing completed on 2025-01-18 09:11:38
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/MaterialMapping/CoreMaterialMapping.hpp"
0010
0011 #include "Acts/Material/AccumulatedMaterialSlab.hpp"
0012 #include "Acts/Material/AccumulatedSurfaceMaterial.hpp"
0013 #include "ActsExamples/MaterialMapping/IMaterialWriter.hpp"
0014
0015 #include <stdexcept>
0016 #include <unordered_map>
0017
0018 namespace ActsExamples {
0019
0020 CoreMaterialMapping::CoreMaterialMapping(const CoreMaterialMapping::Config& cfg,
0021 Acts::Logging::Level level)
0022 : IAlgorithm("CoreMaterialMapping", level), m_cfg(cfg) {
0023
0024 m_inputMaterialTracks.initialize(m_cfg.inputMaterialTracks);
0025 m_outputMappedMaterialTracks.initialize(m_cfg.mappedMaterialTracks);
0026 m_outputUnmappedMaterialTracks.initialize(m_cfg.unmappedMaterialTracks);
0027
0028 ACTS_INFO("This algorithm requires inter-event information, "
0029 << "run in single-threaded mode!");
0030
0031 if (m_cfg.materialMapper == nullptr) {
0032 throw std::invalid_argument("Missing material mapper");
0033 }
0034
0035 m_mappingState = m_cfg.materialMapper->createState();
0036 }
0037
0038 CoreMaterialMapping::~CoreMaterialMapping() {
0039 Acts::DetectorMaterialMaps detectorMaterial =
0040 m_cfg.materialMapper->finalizeMaps(*m_mappingState);
0041
0042 for (auto& imw : m_cfg.materiaMaplWriters) {
0043 imw->writeMaterial(detectorMaterial);
0044 }
0045 }
0046
0047 ProcessCode CoreMaterialMapping::execute(
0048 const AlgorithmContext& context) const {
0049
0050 std::unordered_map<std::size_t, Acts::RecordedMaterialTrack>
0051 mtrackCollection = m_inputMaterialTracks(context);
0052
0053
0054 std::unordered_map<std::size_t, Acts::RecordedMaterialTrack>
0055 mappedTrackCollection;
0056
0057 std::unordered_map<std::size_t, Acts::RecordedMaterialTrack>
0058 unmappedTrackCollection;
0059
0060
0061 auto mappingState =
0062 const_cast<Acts::MaterialMapper::State*>(m_mappingState.get());
0063
0064 for (auto& [idTrack, mTrack] : mtrackCollection) {
0065 auto [mapped, unmapped] = m_cfg.materialMapper->mapMaterial(
0066 *mappingState, context.geoContext, context.magFieldContext, mTrack);
0067
0068 mappedTrackCollection.emplace_hint(mappedTrackCollection.end(), idTrack,
0069 mapped);
0070 unmappedTrackCollection.emplace_hint(unmappedTrackCollection.end(), idTrack,
0071 unmapped);
0072 }
0073
0074
0075 m_outputMappedMaterialTracks(context, std::move(mappedTrackCollection));
0076 m_outputUnmappedMaterialTracks(context, std::move(unmappedTrackCollection));
0077
0078 return ProcessCode::SUCCESS;
0079 }
0080
0081 }