ATLAS Offline Software
Loading...
Searching...
No Matches
ActsMaterialMapping.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7// ATHENA
8#include "Acts/Surfaces/PerigeeSurface.hpp"
9#include "Acts/Utilities/Logger.hpp"
11#include "GaudiKernel/EventContext.h"
12#include "GaudiKernel/ISvcLocator.h"
13
14// ACTS
15#include "Acts/Propagator/detail/SteppingLogger.hpp"
16#include "Acts/Utilities/Helpers.hpp"
17#include "Acts/Definitions/Units.hpp"
18
19// PACKAGE
20#include "ActsInterop/Logger.h"
28
29// STL
30#include <fstream>
31#include <string>
32
33//TEST
34#include "Acts/EventData/TrackParameters.hpp"
35#include "Acts/Propagator/Navigator.hpp"
36#include "Acts/Propagator/Propagator.hpp"
37#include "Acts/Propagator/StandardAborters.hpp"
38#include "Acts/Propagator/StraightLineStepper.hpp"
39
41 ATH_MSG_DEBUG(name() << "::" << __FUNCTION__);
42
44 ATH_MSG_ERROR("No element to map onto defined.");
45 return StatusCode::FAILURE;
46 }
50 if(m_mapSurfaces){
52 m_mappingState = m_surfaceMappingTool->mappingState();
53 }
54 if(m_mapVolumes){
55 ATH_CHECK(m_volumeMappingTool.retrieve() );
56 m_mappingStateVol = m_volumeMappingTool->mappingState();
57 }
60 return StatusCode::SUCCESS;
61}
62
64 ATH_MSG_DEBUG(name() << "::" << __FUNCTION__);
65 const EventContext& ctx = Gaudi::Hive::currentContext();
67
68 if (materialStepCollection.isValid() and not materialStepCollection->empty()) {
69 Acts::RecordedMaterialTrack mTrack = m_materialStepConverterTool->convertToMaterialTrack(*materialStepCollection);
70
71 if(m_mapSurfaces){
72 auto context = m_trackingGeometryTool->getNominalGeometryContext().context();
73 std::reference_wrapper<const Acts::GeometryContext> geoContext(context);
74 m_mappingState.geoContext = geoContext;
75 m_surfaceMappingTool->mapper()->mapMaterialTrack(m_mappingState, mTrack);
76 }
77 if(m_mapVolumes){
78 auto context = m_trackingGeometryTool->getNominalGeometryContext().context();
79 std::reference_wrapper<const Acts::GeometryContext> geoContext(context);
80 m_mappingStateVol.geoContext = geoContext;
81 m_volumeMappingTool->mapper()->mapMaterialTrack(m_mappingStateVol, mTrack);
82 }
83 m_materialTrackWriterSvc->write(mTrack);
84 }
85 return StatusCode::SUCCESS;
86}
87
89 ATH_MSG_DEBUG(name() << "::" << __FUNCTION__);
90 Acts::DetectorMaterialMaps detectorMaterial;
91
92 // Finalize all the maps using the cached state
94 m_surfaceMappingTool->mapper()->finalizeMaps(m_mappingState);
95 m_volumeMappingTool->mapper()->finalizeMaps(m_mappingStateVol);
96 // Loop over the state, and collect the maps for surfaces
97 for (auto& [key, value] : m_mappingState.surfaceMaterial) {
98 detectorMaterial.first.insert({key, std::move(value)});
99 }
100 // Loop over the state, and collect the maps for volumes
101 for (auto& [key, value] : m_mappingStateVol.volumeMaterial) {
102 detectorMaterial.second.insert({key, std::move(value)});
103 }
104 }
105 else{
106 if(m_mapSurfaces){
107 m_surfaceMappingTool->mapper()->finalizeMaps(m_mappingState);
108 // Loop over the state, and collect the maps for surfaces
109 for (auto& [key, value] : m_mappingState.surfaceMaterial) {
110 detectorMaterial.first.insert({key, std::move(value)});
111 }
112 // Loop over the state, and collect the maps for volumes
113 for (auto& [key, value] : m_mappingState.volumeMaterial) {
114 detectorMaterial.second.insert({key, std::move(value)});
115 }
116 }
117 if(m_mapVolumes){
118 m_volumeMappingTool->mapper()->finalizeMaps(m_mappingStateVol);
119 // Loop over the state, and collect the maps for surfaces
120 for (auto& [key, value] : m_mappingStateVol.surfaceMaterial) {
121 detectorMaterial.first.insert({key, std::move(value)});
122 }
123 // Loop over the state, and collect the maps for volumes
124 for (auto& [key, value] : m_mappingStateVol.volumeMaterial) {
125 detectorMaterial.second.insert({key, std::move(value)});
126 }
127 }
128 }
129
130 const auto & context = m_trackingGeometryTool->getNominalGeometryContext();
131 m_materialJsonWriterTool->write(context, detectorMaterial);
132
133 return StatusCode::SUCCESS;
134
135}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
ToolHandle< IActsSurfaceMappingTool > m_surfaceMappingTool
ServiceHandle< IActsMaterialTrackWriterSvc > m_materialTrackWriterSvc
virtual StatusCode finalize() override
Acts::SurfaceMaterialMapper::State m_mappingState
virtual StatusCode initialize() override
ToolHandle< IActsMaterialStepConverterTool > m_materialStepConverterTool
SG::ReadHandleKey< Trk::MaterialStepCollection > m_inputMaterialStepCollection
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
ToolHandle< IActsMaterialJsonWriterTool > m_materialJsonWriterTool
Acts::VolumeMaterialMapper::State m_mappingStateVol
ToolHandle< IActsVolumeMappingTool > m_volumeMappingTool
Gaudi::Property< bool > m_mapVolumes
Gaudi::Property< bool > m_mapSurfaces
virtual StatusCode execute() override
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::pair< SurfaceMaterialMap, VolumeMaterialMap > DetectorMaterialMaps
std::pair< std::pair< Acts::Vector3, Acts::Vector3 >, RecordedMaterial > RecordedMaterialTrack
Recorded material track.