ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
Acts
ActsMaterial
src
Acts/ActsMaterial/src/MaterialMapping.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
MaterialMapping.h
"
6
#include "GaudiKernel/IInterface.h"
7
#include "
ActsInterop/Logger.h
"
8
#include "Acts/Geometry/TrackingGeometry.hpp"
9
#include "Acts/Material/IntersectionMaterialAssigner.hpp"
10
#include "Acts/Material/BinnedSurfaceMaterialAccumulator.hpp"
11
#include "Acts/Material/TrackingGeometryMaterial.hpp"
12
13
ActsTrk::MaterialMapping::MaterialMapping
(
const
std::string& name, ISvcLocator* pSvcLocator) :
14
AthReentrantAlgorithm
(name, pSvcLocator)
15
{}
16
17
ActsTrk::MaterialMapping::~MaterialMapping
()
18
{}
19
20
StatusCode
ActsTrk::MaterialMapping::initialize
()
21
{
22
ATH_CHECK
(
m_materialTrackCollectionKey
.initialize());
23
ATH_CHECK
(
m_mappedMaterialTrackCollectionKey
.initialize());
24
ATH_CHECK
(
m_unmappedMaterialTrackCollectionKey
.initialize());
25
26
ATH_CHECK
(
m_trackingGeometrySvc
.retrieve());
27
28
ATH_CHECK
(
m_materialMapWriters
.retrieve());
29
30
// Retrieve the material surfaces
31
std::vector<const Acts::Surface*> materialSurfaces = {};
32
33
auto
surfaceSelector = [&](
const
Acts::Surface* surface) {
34
if
(surface->surfaceMaterial() !=
nullptr
&&
35
std::ranges::find(materialSurfaces, surface) == materialSurfaces.end()) {
36
materialSurfaces.push_back(surface);
37
}
38
};
39
40
// Visit all surfaces (second argument = if true only sensitive surfaces are visited)
41
m_trackingGeometrySvc
->trackingGeometry()->visitSurfaces(surfaceSelector,
false
);
42
43
// The material intersection assigner
44
Acts::IntersectionMaterialAssigner::Config assingerConfig;
45
assingerConfig.surfaces = materialSurfaces;
46
auto
materialAssigner = std::make_shared<Acts::IntersectionMaterialAssigner>(assingerConfig,
47
makeActsAthenaLogger
(
this
,
"MaterialAssigner"
));
48
49
// The binned surface material accumulator
50
Acts::BinnedSurfaceMaterialAccumulator::Config accumulatorConfig;
51
accumulatorConfig.materialSurfaces = std::move(materialSurfaces);
52
auto
materialAccumulator = std::make_shared<Acts::BinnedSurfaceMaterialAccumulator>(accumulatorConfig,
53
makeActsAthenaLogger
(
this
,
"MaterialAccumulator"
));
54
56
Acts::MaterialMapper::Config mapperConfig;
57
mapperConfig.assignmentFinder = materialAssigner;
58
mapperConfig.surfaceMaterialAccumulator = materialAccumulator;
59
m_materialMapper
= std::make_shared<Acts::MaterialMapper> (mapperConfig,
60
makeActsAthenaLogger
(
this
,
"MaterialMapper"
));
61
62
// Create the state object
63
const
ActsTrk::GeometryContext
& geoContext{
m_trackingGeometrySvc
->getNominalContext()};
64
m_mappingState =
m_materialMapper
->createState(geoContext.
context
());
65
66
return
StatusCode::SUCCESS;
67
}
68
69
StatusCode
ActsTrk::MaterialMapping::finalize
()
70
{
71
const
ActsTrk::GeometryContext
& geoContext{
m_trackingGeometrySvc
->getNominalContext()};
72
Acts::TrackingGeometryMaterial detectorMaterial =
m_materialMapper
->finalizeMaps(*m_mappingState, geoContext.
context
());
73
74
// Loop over the available writers and write the maps
75
for
(
auto
& materialWriter :
m_materialMapWriters
) {
76
materialWriter->writeMaterial(geoContext, detectorMaterial);
77
}
78
79
return
StatusCode::SUCCESS;
80
}
81
82
StatusCode
83
ActsTrk::MaterialMapping::execute
(
const
EventContext& ctx)
const
84
{
85
// Read the collection to the EventStore
86
SG::ReadHandle<ActsTrk::RecordedMaterialTrackCollection>
materialTracks(
m_materialTrackCollectionKey
, ctx);
87
// Check if all is fine
88
if
(!materialTracks.
isValid
()) {
89
ATH_MSG_ERROR
(
"Failed to read "
<<
m_materialTrackCollectionKey
.key());
90
return
StatusCode::FAILURE;
91
}
92
93
// Write to the collection to the EventStore
94
SG::WriteHandle<ActsTrk::RecordedMaterialTrackCollection>
unmappedMaterialTracks(
m_unmappedMaterialTrackCollectionKey
, ctx);
95
SG::WriteHandle<ActsTrk::RecordedMaterialTrackCollection>
mappedMaterialTracks(
m_mappedMaterialTrackCollectionKey
, ctx);
96
97
// Record the collection once per event if not already there
98
// You do it once for the unmapped material tracks ...
99
if
(!unmappedMaterialTracks.
isPresent
()) {
100
auto
coll = std::make_unique<ActsTrk::RecordedMaterialTrackCollection>();
101
ATH_CHECK
(unmappedMaterialTracks.
record
(std::move(coll)));
102
}
103
auto
* unmappedColl = unmappedMaterialTracks.
ptr
();
104
if
(!unmappedColl) {
105
ATH_MSG_ERROR
(
"RecordedMaterialTrackCollection ptr() is null for key "
106
<<
m_unmappedMaterialTrackCollectionKey
.key());
107
return
StatusCode::FAILURE;
108
}
109
// ... and then for the mapped material tracks
110
if
(!mappedMaterialTracks.
isPresent
()) {
111
auto
coll = std::make_unique<ActsTrk::RecordedMaterialTrackCollection>();
112
ATH_CHECK
(mappedMaterialTracks.
record
(std::move(coll)));
113
}
114
auto
* mappedColl = mappedMaterialTracks.
ptr
();
115
if
(!mappedColl) {
116
ATH_MSG_ERROR
(
"RecordedMaterialTrackCollection ptr() is null for key "
117
<<
m_mappedMaterialTrackCollectionKey
.key());
118
return
StatusCode::FAILURE;
119
}
120
121
auto
mappingState =
const_cast<
Acts::MaterialMapper::State*
>
(m_mappingState.get());
122
123
const
ActsTrk::GeometryContext
& geoContext{
m_trackingGeometrySvc
->getNominalContext()};
124
Acts::MagneticFieldContext magFieldContext;
125
126
// Loop over the material tracks and map them on the surfaces
127
for
(
const
auto
& materialTrack : *materialTracks) {
128
auto
[
mapped
,
unmapped
] =
m_materialMapper
->mapMaterial(
129
*mappingState, geoContext.
context
(), magFieldContext, materialTrack);
130
// collect mapped and unmapped states
131
mappedColl->push_back(
mapped
);
132
unmappedColl->push_back(
unmapped
);
133
}
134
135
return
StatusCode::SUCCESS;
136
137
}
138
139
MaterialMapping.h
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
HitType::unmapped
@ unmapped
Definition
FPGATrackSimHit.h:39
Logger.h
makeActsAthenaLogger
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
Definition
Logger.cxx:64
ActsTrk::GeometryContext
Definition
GeometryContext.h:30
ActsTrk::GeometryContext::context
Acts::GeometryContext context() const
Definition
GeometryContext.h:48
ActsTrk::MaterialMapping::m_mappedMaterialTrackCollectionKey
SG::WriteHandleKey< RecordedMaterialTrackCollection > m_mappedMaterialTrackCollectionKey
The mapped and unmapped material tracks.
Definition
Acts/ActsMaterial/src/MaterialMapping.h:53
ActsTrk::MaterialMapping::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
Acts/ActsMaterial/src/MaterialMapping.cxx:83
ActsTrk::MaterialMapping::m_unmappedMaterialTrackCollectionKey
SG::WriteHandleKey< RecordedMaterialTrackCollection > m_unmappedMaterialTrackCollectionKey
Definition
Acts/ActsMaterial/src/MaterialMapping.h:54
ActsTrk::MaterialMapping::m_materialTrackCollectionKey
SG::ReadHandleKey< RecordedMaterialTrackCollection > m_materialTrackCollectionKey
The RecordedMaterialTrackCollection to read.
Definition
Acts/ActsMaterial/src/MaterialMapping.h:51
ActsTrk::MaterialMapping::m_materialMapper
std::shared_ptr< Acts::MaterialMapper > m_materialMapper
The material mapper from the ACTS core components.
Definition
Acts/ActsMaterial/src/MaterialMapping.h:42
ActsTrk::MaterialMapping::m_trackingGeometrySvc
ServiceHandle< ActsTrk::ITrackingGeometrySvc > m_trackingGeometrySvc
The tracking geometry service to retrive the geometry context and material surfaces.
Definition
Acts/ActsMaterial/src/MaterialMapping.h:48
ActsTrk::MaterialMapping::~MaterialMapping
virtual ~MaterialMapping()
Definition
Acts/ActsMaterial/src/MaterialMapping.cxx:17
ActsTrk::MaterialMapping::m_materialMapWriters
ToolHandleArray< IMaterialWriterTool > m_materialMapWriters
The material map writes.
Definition
Acts/ActsMaterial/src/MaterialMapping.h:39
ActsTrk::MaterialMapping::MaterialMapping
MaterialMapping(const std::string &name, ISvcLocator *pSvcLocator)
Definition
Acts/ActsMaterial/src/MaterialMapping.cxx:13
ActsTrk::MaterialMapping::initialize
virtual StatusCode initialize() override
Definition
Acts/ActsMaterial/src/MaterialMapping.cxx:20
ActsTrk::MaterialMapping::finalize
virtual StatusCode finalize() override
Definition
Acts/ActsMaterial/src/MaterialMapping.cxx:69
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::VarHandleBase::isPresent
bool isPresent() const
Is the referenced object present in SG?
Definition
StoreGate/src/VarHandleBase.cxx:400
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
mapped
std::vector< std::string > mapped
Definition
hcg.cxx:56
Generated on
for ATLAS Offline Software by
1.17.0