Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:38

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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   // Prepare the I/O collections
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   // Create the state object
0035   m_mappingState = m_cfg.materialMapper->createState();
0036 }
0037 
0038 CoreMaterialMapping::~CoreMaterialMapping() {
0039   Acts::DetectorMaterialMaps detectorMaterial =
0040       m_cfg.materialMapper->finalizeMaps(*m_mappingState);
0041   // Loop over the available writers and write the maps
0042   for (auto& imw : m_cfg.materiaMaplWriters) {
0043     imw->writeMaterial(detectorMaterial);
0044   }
0045 }
0046 
0047 ProcessCode CoreMaterialMapping::execute(
0048     const AlgorithmContext& context) const {
0049   // Take the collection from the EventStore: input collection
0050   std::unordered_map<std::size_t, Acts::RecordedMaterialTrack>
0051       mtrackCollection = m_inputMaterialTracks(context);
0052 
0053   // Write the output collections to the Event store : mapped and unmapped
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   // To make it work with the framework needs a lock guard
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   // Write the mapped and unmapped material tracks to the output
0075   m_outputMappedMaterialTracks(context, std::move(mappedTrackCollection));
0076   m_outputUnmappedMaterialTracks(context, std::move(unmappedTrackCollection));
0077 
0078   return ProcessCode::SUCCESS;
0079 }
0080 
0081 }  // namespace ActsExamples