ATLAS Offline Software
ActsMaterialMapping.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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  ISvcLocator *pSvcLocator)
42  : AthAlgorithm(name, pSvcLocator),
43  m_materialTrackWriterSvc("ActsMaterialTrackWriterSvc", name),
44  m_mappingState(m_gctx,m_mctx),
45  m_mappingStateVol(m_gctx,m_mctx)
46 {}
47 
49  ATH_MSG_DEBUG(name() << "::" << __FUNCTION__);
50 
51  if(!m_mapSurfaces && !m_mapVolumes){
52  ATH_MSG_ERROR("No element to map onto defined.");
53  return StatusCode::FAILURE;
54  }
55 
58  if(m_mapSurfaces){
59  ATH_CHECK(m_surfaceMappingTool.retrieve() );
60  m_mappingState = m_surfaceMappingTool->mappingState();
61  }
62  if(m_mapVolumes){
63  ATH_CHECK(m_volumeMappingTool.retrieve() );
64  m_mappingStateVol = m_volumeMappingTool->mappingState();
65  }
68  return StatusCode::SUCCESS;
69 }
70 
72  ATH_MSG_DEBUG(name() << "::" << __FUNCTION__);
73  const EventContext& ctx = Gaudi::Hive::currentContext();
75 
76  if (materialStepCollection.isValid() and not materialStepCollection->empty()) {
77  Acts::RecordedMaterialTrack mTrack = m_materialStepConverterTool->convertToMaterialTrack(*materialStepCollection);
78 
79  if(m_mapSurfaces){
80  auto context = m_surfaceMappingTool->trackingGeometryTool()->getNominalGeometryContext().context();
81  std::reference_wrapper<const Acts::GeometryContext> geoContext(context);
82  m_mappingState.geoContext = geoContext;
83  m_surfaceMappingTool->mapper()->mapMaterialTrack(m_mappingState, mTrack);
84  }
85  if(m_mapVolumes){
86  auto context = m_volumeMappingTool->trackingGeometryTool()->getNominalGeometryContext().context();
87  std::reference_wrapper<const Acts::GeometryContext> geoContext(context);
88  m_mappingStateVol.geoContext = geoContext;
89  m_volumeMappingTool->mapper()->mapMaterialTrack(m_mappingStateVol, mTrack);
90  }
91  m_materialTrackWriterSvc->write(mTrack);
92  }
93  return StatusCode::SUCCESS;
94 }
95 
97  ATH_MSG_DEBUG(name() << "::" << __FUNCTION__);
98  Acts::DetectorMaterialMaps detectorMaterial;
99 
100  // Finalize all the maps using the cached state
102  m_surfaceMappingTool->mapper()->finalizeMaps(m_mappingState);
103  m_volumeMappingTool->mapper()->finalizeMaps(m_mappingStateVol);
104  // Loop over the state, and collect the maps for surfaces
105  for (auto& [key, value] : m_mappingState.surfaceMaterial) {
106  detectorMaterial.first.insert({key, std::move(value)});
107  }
108  // Loop over the state, and collect the maps for volumes
109  for (auto& [key, value] : m_mappingStateVol.volumeMaterial) {
110  detectorMaterial.second.insert({key, std::move(value)});
111  }
112  }
113  else{
114  if(m_mapSurfaces){
115  m_surfaceMappingTool->mapper()->finalizeMaps(m_mappingState);
116  // Loop over the state, and collect the maps for surfaces
117  for (auto& [key, value] : m_mappingState.surfaceMaterial) {
118  detectorMaterial.first.insert({key, std::move(value)});
119  }
120  // Loop over the state, and collect the maps for volumes
121  for (auto& [key, value] : m_mappingState.volumeMaterial) {
122  detectorMaterial.second.insert({key, std::move(value)});
123  }
124  }
125  if(m_mapVolumes){
126  m_volumeMappingTool->mapper()->finalizeMaps(m_mappingStateVol);
127  // Loop over the state, and collect the maps for surfaces
128  for (auto& [key, value] : m_mappingStateVol.surfaceMaterial) {
129  detectorMaterial.first.insert({key, std::move(value)});
130  }
131  // Loop over the state, and collect the maps for volumes
132  for (auto& [key, value] : m_mappingStateVol.volumeMaterial) {
133  detectorMaterial.second.insert({key, std::move(value)});
134  }
135  }
136  }
137 
138  auto context = m_surfaceMappingTool->trackingGeometryTool()->getNominalGeometryContext();
139  m_materialJsonWriterTool->write(context, detectorMaterial);
140 
141  return StatusCode::SUCCESS;
142 
143 }
IActsSurfaceMappingTool.h
IActsVolumeMappingTool.h
ActsMaterialMapping::m_materialStepConverterTool
ToolHandle< IActsMaterialStepConverterTool > m_materialStepConverterTool
Definition: ActsMaterialMapping.h:63
ActsGeometryContext.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ActsMaterialMapping::finalize
virtual StatusCode finalize() override
Definition: ActsMaterialMapping.cxx:96
ActsMaterialMapping::m_materialJsonWriterTool
ToolHandle< IActsMaterialJsonWriterTool > m_materialJsonWriterTool
Definition: ActsMaterialMapping.h:67
Acts::RecordedMaterialTrack
std::pair< std::pair< Acts::Vector3, Acts::Vector3 >, RecordedMaterial > RecordedMaterialTrack
Recorded material track.
Definition: ActsExtrapolationAlg.cxx:43
ActsMaterialMapping::m_volumeMappingTool
ToolHandle< IActsVolumeMappingTool > m_volumeMappingTool
Definition: ActsMaterialMapping.h:66
athena.value
value
Definition: athena.py:124
ActsMaterialMapping::initialize
virtual StatusCode initialize() override
Definition: ActsMaterialMapping.cxx:48
Acts::DetectorMaterialMaps
std::pair< SurfaceMaterialMap, VolumeMaterialMap > DetectorMaterialMaps
Definition: ActsMaterialMapping.h:42
ActsMaterialMapping.h
IActsMaterialStepConverterTool.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ActsMaterialMapping::ActsMaterialMapping
ActsMaterialMapping(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ActsMaterialMapping.cxx:40
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
ActsMaterialMapping::m_mapVolumes
Gaudi::Property< bool > m_mapVolumes
Definition: ActsMaterialMapping.h:62
ActsMaterialMapping::m_surfaceMappingTool
ToolHandle< IActsSurfaceMappingTool > m_surfaceMappingTool
Definition: ActsMaterialMapping.h:65
IActsPropStepRootWriterSvc.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsMaterialMapping::m_mappingState
Acts::SurfaceMaterialMapper::State m_mappingState
Definition: ActsMaterialMapping.h:71
ActsMaterialMapping::m_inputMaterialStepCollection
SG::ReadHandleKey< Trk::MaterialStepCollection > m_inputMaterialStepCollection
Definition: ActsMaterialMapping.h:64
ActsMaterialMapping::m_mapSurfaces
Gaudi::Property< bool > m_mapSurfaces
Definition: ActsMaterialMapping.h:61
ActsMaterialMapping::m_mappingStateVol
Acts::VolumeMaterialMapper::State m_mappingStateVol
Definition: ActsMaterialMapping.h:72
ActsMaterialMapping::m_materialTrackWriterSvc
ServiceHandle< IActsMaterialTrackWriterSvc > m_materialTrackWriterSvc
Definition: ActsMaterialMapping.h:60
IActsMaterialJsonWriterTool.h
ActsMaterialMapping::execute
virtual StatusCode execute() override
Definition: ActsMaterialMapping.cxx:71
Logger.h
IActsMaterialTrackWriterSvc.h
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
IActsTrackingGeometryTool.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37