File indexing completed on 2025-01-18 09:11:26
0001
0002
0003
0004
0005
0006
0007
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
0025 auto state = std::make_unique<State>();
0026
0027 state->surfaceMaterialAccumulaterState =
0028 m_cfg.surfaceMaterialAccumulater->createState();
0029
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
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
0046 RecordedMaterialTrack mappedMaterial = {starDir, {}};
0047 RecordedMaterialTrack unmappedMaterial = {starDir, {}};
0048
0049 auto [assigned, unassigned, emptyBinSurfaces] =
0050 MaterialInteractionAssignment::assign(
0051 gctx, recordedMaterial.materialInteractions, surfaceAssignments,
0052 options.assignmentOptions);
0053
0054
0055 mappedMaterial.second.materialInteractions.insert(
0056 mappedMaterial.second.materialInteractions.end(), assigned.begin(),
0057 assigned.end());
0058
0059
0060 unmappedMaterial.second.materialInteractions.insert(
0061 unmappedMaterial.second.materialInteractions.end(), unassigned.begin(),
0062 unassigned.end());
0063
0064
0065 m_cfg.surfaceMaterialAccumulater->accumulate(
0066 *state.surfaceMaterialAccumulaterState.get(), assigned, emptyBinSurfaces);
0067
0068
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
0076 calculateTotalMaterial(mappedMaterial);
0077 calculateTotalMaterial(unmappedMaterial);
0078
0079 return {mappedMaterial, unmappedMaterial};
0080 }
0081
0082 Acts::MaterialMapper::DetectorMaterialMaps Acts::MaterialMapper::finalizeMaps(
0083 const State& state) const {
0084
0085 DetectorMaterialMaps detectorMaterialMaps;
0086
0087 detectorMaterialMaps.first =
0088 m_cfg.surfaceMaterialAccumulater->finalizeMaterial(
0089 *state.surfaceMaterialAccumulaterState.get());
0090
0091 return detectorMaterialMaps;
0092 }