Back to home page

EIC code displayed by LXR

 
 

    


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

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 "Acts/Material/MaterialMapper.hpp"
0010 
0011 Acts::MaterialMapper::MaterialMapper(const Config& cfg,
0012                                      std::unique_ptr<const Logger> mlogger)
0013     : m_cfg(cfg), m_logger(std::move(mlogger)) {
0014   if (m_cfg.assignmentFinder == nullptr) {
0015     throw std::invalid_argument("The assignment finder is not set");
0016   }
0017   if (m_cfg.surfaceMaterialAccumulater == nullptr) {
0018     throw std::invalid_argument("The surface material accumulater is not set");
0019   }
0020 }
0021 
0022 std::unique_ptr<Acts::MaterialMapper::State> Acts::MaterialMapper::createState()
0023     const {
0024   // Create the state
0025   auto state = std::make_unique<State>();
0026   // Create the surface material accumulater state
0027   state->surfaceMaterialAccumulaterState =
0028       m_cfg.surfaceMaterialAccumulater->createState();
0029   // Return the state object
0030   return state;
0031 }
0032 
0033 std::pair<Acts::RecordedMaterialTrack, Acts::RecordedMaterialTrack>
0034 Acts::MaterialMapper::mapMaterial(State& state, const GeometryContext& gctx,
0035                                   const MagneticFieldContext& mctx,
0036                                   const RecordedMaterialTrack& rmTrack,
0037                                   const Options& options) const {
0038   // The recorded material track
0039   const auto& [starDir, recordedMaterial] = rmTrack;
0040   const auto& [position, direction] = starDir;
0041   auto [surfaceAssignments, volumeAssignments] =
0042       m_cfg.assignmentFinder->assignmentCandidates(gctx, mctx, position,
0043                                                    direction);
0044 
0045   // The mapped and unmapped material
0046   RecordedMaterialTrack mappedMaterial = {starDir, {}};
0047   RecordedMaterialTrack unmappedMaterial = {starDir, {}};
0048   // Assign the surface interactions
0049   auto [assigned, unassigned, emptyBinSurfaces] =
0050       MaterialInteractionAssignment::assign(
0051           gctx, recordedMaterial.materialInteractions, surfaceAssignments,
0052           options.assignmentOptions);
0053 
0054   // Record the assigned ones - as mapped ones
0055   mappedMaterial.second.materialInteractions.insert(
0056       mappedMaterial.second.materialInteractions.end(), assigned.begin(),
0057       assigned.end());
0058 
0059   // Record the unassigned ones - as unmapped ones
0060   unmappedMaterial.second.materialInteractions.insert(
0061       unmappedMaterial.second.materialInteractions.end(), unassigned.begin(),
0062       unassigned.end());
0063 
0064   // The material interactions
0065   m_cfg.surfaceMaterialAccumulater->accumulate(
0066       *state.surfaceMaterialAccumulaterState.get(), assigned, emptyBinSurfaces);
0067 
0068   // The function to calculate the total material before returning
0069   auto calculateTotalMaterial = [](RecordedMaterialTrack& rTrack) -> void {
0070     for (const auto& mi : rTrack.second.materialInteractions) {
0071       rTrack.second.materialInX0 += mi.materialSlab.thicknessInX0();
0072       rTrack.second.materialInL0 += mi.materialSlab.thicknessInL0();
0073     }
0074   };
0075   // Fill the totals to the material tracks (useful for debugging)
0076   calculateTotalMaterial(mappedMaterial);
0077   calculateTotalMaterial(unmappedMaterial);
0078   // Return the mapped and unmapped material
0079   return {mappedMaterial, unmappedMaterial};
0080 }
0081 
0082 Acts::MaterialMapper::DetectorMaterialMaps Acts::MaterialMapper::finalizeMaps(
0083     const State& state) const {
0084   // The final maps
0085   DetectorMaterialMaps detectorMaterialMaps;
0086   // The surface maps
0087   detectorMaterialMaps.first =
0088       m_cfg.surfaceMaterialAccumulater->finalizeMaterial(
0089           *state.surfaceMaterialAccumulaterState.get());
0090 
0091   return detectorMaterialMaps;
0092 }