ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
Acts
ActsMaterial
src
Acts/ActsMaterial/src/MaterialValidation.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 "
MaterialValidation.h
"
6
#include "
AthenaKernel/RNGWrapper.h
"
7
#include "CLHEP/Random/RandomEngine.h"
8
#include "GaudiKernel/IInterface.h"
9
#include "
ActsInterop/Logger.h
"
10
#include "Acts/Geometry/TrackingGeometry.hpp"
11
#include "Acts/Material/IntersectionMaterialAssigner.hpp"
12
13
ActsTrk::MaterialValidation::MaterialValidation
(
const
std::string& name, ISvcLocator* pSvcLocator) :
14
AthReentrantAlgorithm
(name, pSvcLocator)
15
{}
16
17
ActsTrk::MaterialValidation::~MaterialValidation
()
18
{}
19
20
StatusCode
ActsTrk::MaterialValidation::initialize
()
21
{
22
ATH_CHECK
(
m_materialTrackCollectionKey
.initialize());
23
ATH_CHECK
(
m_rndmGenSvc
.retrieve());
24
ATH_CHECK
(
m_trackingGeometrySvc
.retrieve());
25
26
// Retrieve the material surfaces
27
std::vector<const Acts::Surface*> materialSurfaces = {};
28
29
auto
surfaceSelector = [&](
const
Acts::Surface* surface) {
30
if
(surface->surfaceMaterial() !=
nullptr
&&
31
std::ranges::find(materialSurfaces, surface) == materialSurfaces.end()) {
32
materialSurfaces.push_back(surface);
33
}
34
};
35
36
// Visit all surfaces (second argument = if true only sensitive surfaces are visited)
37
m_trackingGeometrySvc
->trackingGeometry()->visitSurfaces(surfaceSelector,
false
);
38
39
// The material intersection assigner
40
Acts::IntersectionMaterialAssigner::Config assingerConfig;
41
assingerConfig.surfaces = std::move(materialSurfaces);
42
auto
materialAssigner = std::make_shared<Acts::IntersectionMaterialAssigner>(assingerConfig,
43
makeActsAthenaLogger
(
this
,
"MaterialAssigner"
));
44
46
Acts::MaterialValidator::Config validatorConfig;
47
validatorConfig.materialAssigner = materialAssigner;
48
m_materialValidator
= std::make_shared<Acts::MaterialValidator> (validatorConfig,
49
makeActsAthenaLogger
(
this
,
"MaterialValidator"
));
50
51
return
StatusCode::SUCCESS;
52
}
53
54
StatusCode
55
ActsTrk::MaterialValidation::execute
(
const
EventContext& ctx)
const
56
{
57
// Write to the collection to the EventStore
58
SG::WriteHandle<ActsTrk::RecordedMaterialTrackCollection>
materialTracks(
m_materialTrackCollectionKey
, ctx);
59
60
// Record the collection once per event if not already there
61
if
(!materialTracks.
isPresent
()) {
62
auto
coll = std::make_unique<ActsTrk::RecordedMaterialTrackCollection>();
63
ATH_CHECK
(materialTracks.
record
(std::move(coll)));
64
}
65
66
// Add the track to the recorded collection
67
auto
* coll = materialTracks.
ptr
();
68
if
(!coll) {
69
ATH_MSG_ERROR
(
"RecordedMaterialTrackCollection ptr() is null for key "
70
<<
m_materialTrackCollectionKey
.key());
71
return
StatusCode::FAILURE;
72
}
73
74
// Some useful parameters to be used later
75
Acts::Vector3 startPosition(0., 0., 0.);
76
const
ActsTrk::GeometryContext
& geoContext{
m_trackingGeometrySvc
->getNominalContext()};
77
Acts::MagneticFieldContext magFieldContext;
78
79
ATHRNG::RNGWrapper
*wrapper =
m_rndmGenSvc
->getEngine(
this
);
80
wrapper->
setSeed
(name(), ctx);
81
CLHEP::HepRandomEngine *rndmEngine = wrapper->
getEngine
(ctx);
82
83
// Loop over the number of tracks
84
for
(std::size_t iTrack = 0; iTrack <
m_nTracks
; ++iTrack) {
85
// Generate a random phi and eta
86
double
phi
= rndmEngine->flat() * 2 *
M_PI
-
M_PI
;
87
double
eta
= rndmEngine->flat() * std::abs(
m_etaRange
.value().second -
m_etaRange
.value().first) +
m_etaRange
.value().first;
88
double
theta
= 2 * std::atan(std::exp(-
eta
));
89
Acts::Vector3 direction(std::cos(
phi
) * std::sin(
theta
),
90
std::sin(
phi
) * std::sin(
theta
), std::cos(
theta
));
91
92
// Record the material
93
auto
rmTrack =
m_materialValidator
->recordMaterial(geoContext.
context
(),
94
magFieldContext,
95
startPosition,
96
direction);
97
98
// filling the collection
99
coll->push_back(std::move(rmTrack));
100
101
}
102
103
return
StatusCode::SUCCESS;
104
105
}
106
107
M_PI
#define M_PI
Definition
ActiveFraction.h:14
MaterialValidation.h
eta
Scalar eta() const
pseudorapidity method
Definition
AmgMatrixBasePlugin.h:83
phi
Scalar phi() const
phi method
Definition
AmgMatrixBasePlugin.h:67
theta
Scalar theta() const
theta method
Definition
AmgMatrixBasePlugin.h:75
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
RNGWrapper.h
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
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition
RNGWrapper.h:56
ATHRNG::RNGWrapper::setSeed
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition
RNGWrapper.h:154
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition
RNGWrapper.h:108
ActsTrk::GeometryContext
Definition
GeometryContext.h:30
ActsTrk::GeometryContext::context
Acts::GeometryContext context() const
Definition
GeometryContext.h:48
ActsTrk::MaterialValidation::initialize
virtual StatusCode initialize() override
Definition
Acts/ActsMaterial/src/MaterialValidation.cxx:20
ActsTrk::MaterialValidation::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
Acts/ActsMaterial/src/MaterialValidation.cxx:55
ActsTrk::MaterialValidation::m_rndmGenSvc
ServiceHandle< IAthRNGSvc > m_rndmGenSvc
The random number service.
Definition
Acts/ActsMaterial/src/MaterialValidation.h:38
ActsTrk::MaterialValidation::m_materialTrackCollectionKey
SG::WriteHandleKey< RecordedMaterialTrackCollection > m_materialTrackCollectionKey
The RecordedMaterialTrackCollection to write.
Definition
Acts/ActsMaterial/src/MaterialValidation.h:48
ActsTrk::MaterialValidation::~MaterialValidation
virtual ~MaterialValidation()
Definition
Acts/ActsMaterial/src/MaterialValidation.cxx:17
ActsTrk::MaterialValidation::MaterialValidation
MaterialValidation(const std::string &name, ISvcLocator *pSvcLocator)
Definition
Acts/ActsMaterial/src/MaterialValidation.cxx:13
ActsTrk::MaterialValidation::m_etaRange
Gaudi::Property< std::pair< double, double > > m_etaRange
The eta range for track generation.
Definition
Acts/ActsMaterial/src/MaterialValidation.h:42
ActsTrk::MaterialValidation::m_trackingGeometrySvc
ServiceHandle< ActsTrk::ITrackingGeometrySvc > m_trackingGeometrySvc
The tracking geometry service to retrive the geometry context and material surfaces.
Definition
Acts/ActsMaterial/src/MaterialValidation.h:45
ActsTrk::MaterialValidation::m_materialValidator
std::shared_ptr< Acts::MaterialValidator > m_materialValidator
The material validator from the ACTS core components.
Definition
Acts/ActsMaterial/src/MaterialValidation.h:36
ActsTrk::MaterialValidation::m_nTracks
Gaudi::Property< size_t > m_nTracks
The number of tracks to use per event.
Definition
Acts/ActsMaterial/src/MaterialValidation.h:40
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
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.
Generated on
for ATLAS Offline Software by
1.17.0